FileDocCategorySizeDatePackage
ACSlot.javaAPI DocphoneME MR2 API (J2ME)11715Wed May 02 18:00:38 BST 2007com.sun.satsa.acl

ACSlot

public class ACSlot extends Object
This class represent the ACL Card slot abstraction

Fields Summary
private static com.sun.midp.security.SecurityToken
classSecurityToken
This class has a different security domain than the MIDlet suite
private byte[]
ACIFOID
Value of OID from the spceification (A.4.2.1 Location of Access Control Files)
short[]
ODF
Path to ODF.
public static final short[]
PrKDF
Path to PrKDF.
public static final short[]
PuKDF
Path to PuKDF.
public static final short[]
TPuKDF
Path to Trusted PuKDF.
public static final short[]
SeKDF
Path to SeKDF.
public static final short[]
CDF
Path to PuKDF.
public static final short[]
TrCDF
Path to CDF for trusted certificates.
public static final short[]
UsCDF
Path to CDF for useful certificates.
public static final short[]
DODF
Path to DODF.
public static final short[]
AODF
Path to AODF.
public static final short[]
ACIFILE
Path to ACIF
public static final short[]
ACFILE
path to the first ACF
static byte[]
selectPKCSApp
Command for the PKCS15 application select
static byte[]
selectMF
Command for the MF select
static byte[]
selectDIR
Command for the DIR file select
static short
FILE_NOT_FOUND
File not found return code
private Vector
ACLists
The list of ACL objects.
private Vector
PINAttrs
The list of PIN data objects.
private AclFileSystem
files
File system object.
private static Connection
apdu
Connection object.
private boolean
allGranted
Indicates if all permissions granted
private boolean
allRevoked
Indicates if all permissions revoked
Constructors Summary
public ACSlot()
Constructs an instance of an access control file object.

                  
      
    
private ACSlot(Connection apdu)
Creates new ACSlot object for pointed connection.

param
apdu Connection Required connection.
throws
IOException any IO exception

        this.apdu = apdu;
        files = new AclFileSystem(apdu);
    
private ACSlot(boolean allGranted)
Creates new ACSlot object with pointed state of permissions.

param
allGranted boolean state of all permissions: true - all permissions granted, false - all permissions revoked.

        this.allGranted = allGranted;
        this.allRevoked = !allGranted;
    
Methods Summary
ACLPermissionsgetACLPermissions(boolean isAPDU, byte[] selectAPDU, java.lang.String root)
Returns object that should be used for access control verification.

param
isAPDU true for APDU connection, false for JCRMI.
param
selectAPDU SELECT APDU command data.
param
root name of CA that authorized the suite.
return
object that can be used to check permissions.


        Vector permissions = new Vector();
        Vector pins = new Vector();
        boolean found = false;
        boolean allow = false;

        ACLPermissions perm;

        if (isAPDU) {
            perm = new APDUPermissions(this);
        } else {
            perm = new JCRMIPermissions(this);
        }

        if (allGranted) {
            /* Previously was decided to grant all permissions */
            perm.setType(ACLPermissions.ALLOW);
            return perm;
        }
        if (allRevoked) {
            /* Previously was decided to revoke all permissions */
            perm.setType(ACLPermissions.DISALLOW);
            return perm;
        }

        for (int i = 0; i < ACLists.size(); i++) {
            ACList acl = (ACList) ACLists.elementAt(i);
            if (!acl.match(selectAPDU)) {
                continue;
            }
            found = true;
            ACEntry ace = acl.getACEntries();
            if (ace == null) {
                /*
                 * Case when there is the aid identifies the application in the
                 * ACIF file, but an ACF related to the application is absent
                 * in this case the application does not have access to the card
                 */
                continue;
            }
            acl.getPINs(isAPDU, pins);
            if (!ace.verifyPrincipal(root)) {
                continue;
            }
            if (!ace.hasPermissions()) {
                allow = true;
                continue;
            }
            ace.getPermissions(isAPDU, permissions);
        }

        if (pins.size() != 0) {
            PINData[] data = new PINData[pins.size()];
            pins.copyInto(data);
            perm.setPINData(data);
        }

        if (!found || allow) {
            perm.setType(ACLPermissions.ALLOW);
        } else {
            if (permissions.size() == 0) {
                throw new SecurityException("Access denied.");
            } else {
                perm.setPermissions(permissions);
                perm.setType(ACLPermissions.CHECK);
            }
        }
        return perm;
    
PINAttributesgetPINAttributes(int id)
Return PIN attributes.

param
id PIN identifier.
return
PIN attributes.


        for (int j = 0; j < PINAttrs.size(); j++) {

            PINAttributes p = (PINAttributes) PINAttrs.elementAt(j);
            if (p.id == id) {
                return p;
            }
        }
        return null;
    
private voidinit(boolean dirIsUsed)
Initializes ACSlot object.

param
dirIsUsed boolean indicates if the card file system and DIR file is used
throws
IOException any IO exception
throws
TLVException any TLV exception

        if (dirIsUsed) {
            int res = files.DIR.setPKCSRoot();
            if (res < 0) {
                throw new IOException("Wrong DIR file");
            }
            allGranted = (res == files.DIR.AID_NOT_FOUND);
            allRevoked = (res == files.DIR.ROOT_NOT_SELECTED);
        }
        ODF odf = new ODF(files);
        odf.load();
        Vector ACIFs = odf.getDOFs(ACIFOID);
        for (int i = 0; i < ACIFs.size(); i++) {
            ACIF acif = new ACIF(files.pathToLocation((TLV) ACIFs.elementAt(i)),
                                 files);
            acif.load();
            for (int j = 0; j < acif.getACFCount(); j++) {
                ACLists.addElement(new ACList(acif.getAID(j),
                                              acif.getACFPath(j), files));
            }
        }
        /*  loadPINs(); */
        for (int i = 0; i < odf.getAODFCount(); i++) {
            AODF aodf = new AODF(odf.getAODFPath(i), files);
            aodf.load();
            for (int j = 0; j < aodf.getEntryCount(); j++) {
                PINAttrs.addElement(new PINAttributes(aodf.getEntry(j)));
            }
        }
    
public static com.sun.satsa.acl.ACSlotload(int slotNumber)
Load access control information.

param
slotNumber card slot number.
return
object that contains access control information or null if this information doesn't exist or contains errors.

        Handle h;
        boolean isDIR = false;
        try {
            /* attempt to select the MF file */
            h = APDUManager.openACLConnection(selectMF, slotNumber,
                    classSecurityToken);
            byte[] res = APDUManager.exchangeAPDU(h, selectDIR);
            if (Utils.getShort(res, 0) == FILE_NOT_FOUND) {
                throw new ConnectionNotFoundException("DIR is not found");
            }
            isDIR = true;
        } catch (ConnectionNotFoundException ce) {
            /* DIR is not found */
            try {
                /* attempt to select the PKCS15 application */
                h = APDUManager.openACLConnection(selectPKCSApp,
                        slotNumber, classSecurityToken);
                isDIR = false;
            } catch (ConnectionNotFoundException ce1) {
                /* PKCS15Application is not found */
                return null;  /* DIR & PKCS15App are not found => */
                              /* all permissions granted */
            } catch (Exception ie) { 
                /* Something wrong during ACL treatment => */
                /* all permissions revoked */
                ACSlot s = new ACSlot(false);
                return s;
            }
        } catch (Exception e) { /* Something wrong during ACL treatment => */
                                /* all permissions revoked */
            ACSlot s = new ACSlot(false);
            return s;
        }

        try {
            Connection con = new Connection(h);
            ACSlot s = new ACSlot(con);
            s.init(isDIR);
            con.done();
            return s;
        } catch (Exception e) { /* Something wrong during ACL treatment => */
                                /* all permissions revoked */
            ACSlot s = new ACSlot(false);
            return s;
        }