FileDocCategorySizeDatePackage
X509CertPathImpl.javaAPI DocAndroid 1.5 API17408Wed May 06 22:41:06 BST 2009org.apache.harmony.security.provider.cert

X509CertPathImpl

public class X509CertPathImpl extends CertPath
This class is an implementation of X.509 CertPath. This implementation provides ability to create the instance of X.509 Certification Path by several means:
  1. It can be created over the list of X.509 certificates (implementations of X509Certificate class) provided in constructor.
  2. It can be created by means of getInstance methods on the base of the following ASN.1 DER encoded forms:
   - PkiPath as defined in ITU-T Recommendation X.509(2000) Corrigendum 1(2001) (can be seen at ftp://ftp.bull.com/pub/OSIdirectory/DefectResolution/TechnicalCorrigenda/ApprovedTechnicalCorrigendaToX.509/8%7CX.509-TC1(4th).pdf)
   - PKCS #7 SignedData object provided in the form of ContentInfo structure. CertPath object is generated on the base of certificates presented in certificates field of the SignedData object which in its turn is retrieved from ContentInfo structure. (see http://www.ietf.org/rfc/rfc2315.txt for more info on PKCS #7)
 

Fields Summary
private static final long
serialVersionUID
public static final int
PKI_PATH
public static final int
PKCS7
private static final String[]
encodingsArr
static final List
encodings
private final List
certificates
private byte[]
pkiPathEncoding
private byte[]
pkcs7Encoding
public static org.apache.harmony.security.asn1.ASN1SequenceOf
ASN1
ASN.1 DER Encoder/Decoder for PkiPath structure.
private static final org.apache.harmony.security.asn1.ASN1Sequence
ASN1_SIGNED_DATA
private static final org.apache.harmony.security.asn1.ASN1Sequence
PKCS7_SIGNED_DATA_OBJECT
Constructors Summary
public X509CertPathImpl(List certs)
Creates an instance of X.509 Certification Path over the specified list of certificates.

throws
CertificateException if some of the object in the list is not an instance of subclass of X509Certificate.


                                        
         
        super("X.509"); //$NON-NLS-1$
        int size = certs.size();
        certificates = new ArrayList(size);
        for (int i=0; i<size; i++) {
            Object cert = certs.get(i);
            if (!(cert instanceof X509Certificate) ) {
                throw new CertificateException(
                        Messages.getString("security.15D")); //$NON-NLS-1$
            }
            certificates.add(cert);
        }
    
private X509CertPathImpl(List certs, int type, byte[] encoding)

        super("X.509"); //$NON-NLS-1$
        if (type == PKI_PATH) {
            this.pkiPathEncoding = encoding;
        } else { // PKCS7
            this.pkcs7Encoding = encoding;
        }
        // We do not need the type check and list cloning here,
        // because it has been done during decoding.
        certificates = certs;
    
Methods Summary
public java.util.ListgetCertificates()

see
java.security.cert.CertPath#getCertificates() method documentation for more info

        return Collections.unmodifiableList(certificates);
    
public byte[]getEncoded()

see
java.security.cert.CertPath#getEncoded() method documentation for more info

        if (pkiPathEncoding == null) {
            pkiPathEncoding = ASN1.encode(this);
        }
        byte[] result = new byte[pkiPathEncoding.length];
        System.arraycopy(pkiPathEncoding, 0, result, 0, pkiPathEncoding.length);
        return result;
    
public byte[]getEncoded(java.lang.String encoding)

see
java.security.cert.CertPath#getEncoded(String) method documentation for more info

        if (!encodings.contains(encoding)) {
            throw new CertificateEncodingException(
                    Messages.getString("security.15F", encoding)); //$NON-NLS-1$
        }
        if (encodingsArr[0].equals(encoding)) {
            // PkiPath encoded form
            return getEncoded();
        } else {
            // PKCS7 encoded form
            if (pkcs7Encoding == null) {
                pkcs7Encoding = PKCS7_SIGNED_DATA_OBJECT.encode(this);
            }
            byte[] result = new byte[pkcs7Encoding.length];
            System.arraycopy(pkcs7Encoding, 0, result, 0,
                                        pkcs7Encoding.length);
            return result;
        }
    
public java.util.IteratorgetEncodings()

see
java.security.cert.CertPath#getEncodings() method documentation for more info

        return encodings.iterator();
    
public static org.apache.harmony.security.provider.cert.X509CertPathImplgetInstance(java.io.InputStream in)
Generates certification path object on the base of PkiPath encoded form provided via input stream.

throws
CertificateException if some problems occurred during the decoding.

        try {
            return (X509CertPathImpl) ASN1.decode(in);
        } catch (IOException e) {
            throw new CertificateException(Messages.getString("security.15E", //$NON-NLS-1$
                    e.getMessage()));
        }
    
public static org.apache.harmony.security.provider.cert.X509CertPathImplgetInstance(java.io.InputStream in, java.lang.String encoding)
Generates certification path object on the base of encoding provided via input stream. The format of provided encoded form is specified by parameter encoding.

throws
CertificateException if specified encoding form is not supported, or some problems occurred during the decoding.

        if (!encodings.contains(encoding)) {
            throw new CertificateException(
                    Messages.getString("security.15F", encoding)); //$NON-NLS-1$
        }
        try {
            if (encodingsArr[0].equals(encoding)) {
                // generate the object from PkiPath encoded form
                return (X509CertPathImpl) ASN1.decode(in);
            } else {
                // generate the object from PKCS #7 encoded form
                ContentInfo ci = (ContentInfo) ContentInfo.ASN1.decode(in);
                SignedData sd = ci.getSignedData();
                if (sd == null) {
                    throw new CertificateException(
                        Messages.getString("security.160")); //$NON-NLS-1$
                }
                List certs = sd.getCertificates();
                if (certs == null) {
                    // empty chain of certificates
                    certs = new ArrayList();
                }
                List result = new ArrayList();
                for (int i=0; i<certs.size(); i++) {
                    result.add(new X509CertImpl((Certificate) certs.get(i)));
                }
                return new X509CertPathImpl(result, PKCS7, ci.getEncoded());
            }
        } catch (IOException e) {
            throw new CertificateException(Messages.getString("security.15E", //$NON-NLS-1$
                    e.getMessage()));
        }
    
public static org.apache.harmony.security.provider.cert.X509CertPathImplgetInstance(byte[] in)
Generates certification path object on the base of PkiPath encoded form provided via array of bytes.

throws
CertificateException if some problems occurred during the decoding.

        try {
            return (X509CertPathImpl) ASN1.decode(in);
        } catch (IOException e) {
            throw new CertificateException(Messages.getString("security.15E", //$NON-NLS-1$
                    e.getMessage()));
        }
    
public static org.apache.harmony.security.provider.cert.X509CertPathImplgetInstance(byte[] in, java.lang.String encoding)
Generates certification path object on the base of encoding provided via array of bytes. The format of provided encoded form is specified by parameter encoding.

throws
CertificateException if specified encoding form is not supported, or some problems occurred during the decoding.

        if (!encodings.contains(encoding)) {
            throw new CertificateException(
                    Messages.getString("security.15F", encoding)); //$NON-NLS-1$
        }
        try {
            if (encodingsArr[0].equals(encoding)) {
                // generate the object from PkiPath encoded form
                return (X509CertPathImpl) ASN1.decode(in);
            } else {
                // generate the object from PKCS #7 encoded form
                ContentInfo ci = (ContentInfo) ContentInfo.ASN1.decode(in);
                SignedData sd = ci.getSignedData();
                if (sd == null) {
                    throw new CertificateException(
                        Messages.getString("security.160")); //$NON-NLS-1$
                }
                List certs = sd.getCertificates();
                if (certs == null) {
                    certs = new ArrayList();
                }
                List result = new ArrayList();
                for (int i=0; i<certs.size(); i++) {
                    result.add(new X509CertImpl((Certificate) certs.get(i)));
                }
                return new X509CertPathImpl(result, PKCS7, ci.getEncoded());
            }
        } catch (IOException e) {
            throw new CertificateException(Messages.getString("security.15E", //$NON-NLS-1$
                    e.getMessage()));
        }