FileDocCategorySizeDatePackage
Extensions.javaAPI DocAndroid 1.5 API13342Wed May 06 22:41:06 BST 2009org.apache.harmony.security.x509

Extensions

public class Extensions extends Object
The class encapsulates the ASN.1 DER encoding/decoding work with the Extensions part of X.509 certificate (as specified in RFC 3280 - Internet X.509 Public Key Infrastructure. Certificate and Certificate Revocation List (CRL) Profile. http://www.ietf.org/rfc/rfc3280.txt):
Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension

Fields Summary
private static List
SUPPORTED_CRITICAL
private List
extensions
private Set
critical
private Set
noncritical
private boolean
hasUnsupported
private HashMap
oidMap
private byte[]
encoding
public static final org.apache.harmony.security.asn1.ASN1Type
ASN1
Custom X.509 Extensions decoder.
Constructors Summary
public Extensions()
Constructs an object representing the value of Extensions.

    
                 
      
public Extensions(List extensions)
TODO

param
extensions: List

        this.extensions = extensions;
    
Methods Summary
public voidaddExtension(Extension extn)
TODO

param
extn: Extension
return

        encoding = null;
        if (extensions == null) {
            extensions = new ArrayList();
        }
        extensions.add(extn);
        if (oidMap != null) {
            oidMap.put(extn.getExtnID(), extn);
        }
        if (critical != null) {
            String oid = extn.getExtnID();
            if (extn.getCritical()) {
                if (!SUPPORTED_CRITICAL.contains(oid)) {
                    hasUnsupported = true;
                }
                critical.add(oid);
            } else {
                noncritical.add(oid);
            }
        }
    
public voiddumpValue(java.lang.StringBuffer buffer, java.lang.String prefix)
Places the string representation into the StringBuffer object.

        if (extensions == null) {
            return;
        }
        int num = 1;
        for (Extension extension: extensions) {
            buffer.append('\n").append(prefix)
                .append('[").append(num++).append("]: "); //$NON-NLS-1$
            extension.dumpValue(buffer, prefix);
        }
    
public booleanequals(java.lang.Object exts)

        if (!(exts instanceof Extensions)) {
            return false;
        }
        Extensions extns = (Extensions) exts;
        return ((extensions == null) || (extensions.size() == 0) 
                    ? ((extns.extensions == null) 
                            || (extns.extensions.size() == 0))
                    : ((extns.extensions == null) 
                            || (extns.extensions.size() == 0))
                        ? false
                        : (extensions.containsAll(extns.extensions)
                            && (extensions.size() == extns.extensions.size()))
                );
    
public java.util.SetgetCriticalExtensions()
Returns the list of critical extensions.

return
extensions

        if (critical == null) {
            makeOidsLists();
        }
        return critical;
    
public byte[]getEncoded()
Returns ASN.1 encoded form of this X.509 Extensions value.

return
a byte array containing ASN.1 encode form.

        if (encoding == null) {
            encoding = ASN1.encode(this);
        }
        return encoding;
    
public ExtensiongetExtensionByOID(java.lang.String oid)
Returns the values of extensions.

param
oid - the OID of needed extension.
return
extensions

        if (extensions == null) {
            return null;
        }
        if (oidMap == null) {
            oidMap = new HashMap();
            Iterator it = extensions.iterator();
            while (it.hasNext()) {
                Extension extn = (Extension) it.next();
                oidMap.put(extn.getExtnID(), extn);
            }
        }
        return (Extension) oidMap.get(oid);
    
public java.util.ListgetExtensions()
Returns the values of extensions.

return
extensions

        return extensions;
    
public java.util.SetgetNonCriticalExtensions()
Returns the list of critical extensions.

return
extensions

        if (noncritical == null) {
            makeOidsLists();
        }
        return noncritical;
    
public booleanhasUnsupportedCritical()

        if (critical == null) {
            makeOidsLists();
        }
        return hasUnsupported;
    
private voidmakeOidsLists()

        if (extensions == null) {
            return;
        }
        int size = extensions.size();
        critical = new HashSet(size);
        noncritical = new HashSet(size);
        for (int i=0; i<size; i++) {
            Extension extn = (Extension) extensions.get(i);
            String oid = extn.getExtnID();
            if (extn.getCritical()) {
                if (!SUPPORTED_CRITICAL.contains(oid)) {
                    hasUnsupported = true;
                }
                critical.add(oid);
            } else {
                noncritical.add(oid);
            }
        }
    
public intsize()

        return (extensions == null) 
                        ? 0
                        : extensions.size();
    
public intvalueOfBasicConstrains()
Returns the value of Basic Constraints Extension (OID = 2.5.29.19). The ASN.1 definition of Basic Constraints Extension is:
id-ce-basicConstraints OBJECT IDENTIFIER ::= { id-ce 19 }

BasicConstraints ::= SEQUENCE {
cA BOOLEAN DEFAULT FALSE,
pathLenConstraint INTEGER (0..MAX) OPTIONAL
}
(as specified in RFC 3280)

return
the value of pathLenConstraint field if extension presents, and Integer.MAX_VALUE if does not.

        Extension extn = getExtensionByOID("2.5.29.19"); //$NON-NLS-1$
        BasicConstraints bc = null;
        if ((extn == null) 
                || ((bc = extn.getBasicConstraintsValue()) == null)) {
            return Integer.MAX_VALUE;
        }
        return bc.getPathLenConstraint();
    
public javax.security.auth.x500.X500PrincipalvalueOfCertificateIssuerExtension()
Returns the value of Certificate Issuer Extension (OID = 2.5.29.29). It is a CRL entry extension and contains the GeneralNames describing the issuer of revoked certificate. Its ASN.1 notation is as follows:
id-ce-certificateIssuer OBJECT IDENTIFIER ::= { id-ce 29 }

certificateIssuer ::= GeneralNames
(as specified in RFC 3280)

return
the value of Certificate Issuer Extension

        Extension extn = getExtensionByOID("2.5.29.29"); //$NON-NLS-1$
        if (extn == null) {
            return null;
        }
        return ((CertificateIssuer) 
                extn.getDecodedExtensionValue()).getIssuer();
    
public java.util.ListvalueOfExtendedKeyUsage()
Returns the value of Extended Key Usage extension (OID == 2.5.29.37). The ASN.1 definition of Extended Key Usage Extension is:
id-ce-extKeyUsage OBJECT IDENTIFIER ::= { id-ce 37 }

ExtKeyUsageSyntax ::= SEQUENCE SIZE (1..MAX) OF KeyPurposeId

KeyPurposeId ::= OBJECT IDENTIFIER
(as specified in RFC 3280)

return
the list with string representations of KeyPurposeId's OIDs and null
throws
IOException if extension was incorrectly encoded.

        Extension extn = getExtensionByOID("2.5.29.37"); //$NON-NLS-1$
        if (extn == null) {
            return null;
        }
        return ((ExtendedKeyUsage) 
                extn.getDecodedExtensionValue()).getExtendedKeyUsage();
    
public java.util.ListvalueOfIssuerAlternativeName()
Returns the value of Issuer Alternative Name Extension (OID = 2.5.29.18). The ASN.1 definition for Issuer Alternative Name is:
id-ce-issuerAltName OBJECT IDENTIFIER ::= { id-ce 18 }

IssuerAltName ::= GeneralNames
(as specified in RFC 3280)

return
Returns the collection of pairs: (Integer (tag), Object (name value)) if extension presents, and null if does not.

        Extension extn = getExtensionByOID("2.5.29.18"); //$NON-NLS-1$
        if (extn == null) {
            return null;
        }
        return ((GeneralNames) 
                GeneralNames.ASN1.decode(extn.getExtnValue())).getPairsList();
    
public boolean[]valueOfKeyUsage()
Returns the value of Key Usage extension (OID == 2.5.29.15). The ASN.1 definition of Key Usage Extension is:
id-ce-keyUsage OBJECT IDENTIFIER ::= { id-ce 15 }

KeyUsage ::= BIT STRING {
digitalSignature (0),
nonRepudiation (1),
keyEncipherment (2),
dataEncipherment (3),
keyAgreement (4),
keyCertSign (5),
cRLSign (6),
encipherOnly (7),
decipherOnly (8)
}
(as specified in RFC 3280)

return
the value of Key Usage Extension if it is in the list, and null if there is no such extension or its value can not be decoded otherwise. Note, that the length of returned array can be greater than 9.

        Extension extn = getExtensionByOID("2.5.29.15"); //$NON-NLS-1$
        KeyUsage kUsage = null;
        if ((extn == null) || ((kUsage = extn.getKeyUsageValue()) == null)) {
            return null;
        }
        return kUsage.getKeyUsage();
    
public java.util.ListvalueOfSubjectAlternativeName()
Returns the value of Subject Alternative Name (OID = 2.5.29.17). The ASN.1 definition for Subject Alternative Name is:
id-ce-subjectAltName OBJECT IDENTIFIER ::= { id-ce 17 }

SubjectAltName ::= GeneralNames
(as specified in RFC 3280)

return
Returns the collection of pairs: (Integer (tag), Object (name value)) if extension presents, and null if does not.

        Extension extn = getExtensionByOID("2.5.29.17"); //$NON-NLS-1$
        if (extn == null) {
            return null;
        }
        return ((GeneralNames) GeneralNames.ASN1.decode(extn.getExtnValue()))
                .getPairsList();