FileDocCategorySizeDatePackage
X509Certificate.javaAPI DocAndroid 1.5 API14005Wed May 06 22:41:06 BST 2009javax.security.cert

X509Certificate

public abstract class X509Certificate extends Certificate
Abstract base class for X.509 certificates.

This represents a standard way for accessing the attributes of X.509 v1 certificates.

Note: This package is provided only for compatibility reasons. It contains a simplified version of the java.security.cert package that was previously used by JSSE (Java SSL package). All applications that do not have to be compatible with older versions of JSSE (that is before Java SDK 1.5) should only use java.security.cert.

since
Android 1.0

Fields Summary
private static Constructor
constructor
Constructors Summary
public X509Certificate()
Creates a new {@code X509Certificate}.

since
Android 1.0

        try {
            String classname = (String) AccessController.doPrivileged(
                new java.security.PrivilegedAction() {
                    public Object run() {
                        return Security.getProperty("cert.provider.x509v1"); //$NON-NLS-1$
                    }
                }
            );
            Class cl = Class.forName(classname);
            constructor =
                cl.getConstructor(new Class[] {InputStream.class});
        } catch (Throwable e) {
        }
    
        super();
    
Methods Summary
public abstract voidcheckValidity()
Checks whether the certificate is currently valid.

The validity defined in ASN.1:

validity Validity

Validity ::= SEQUENCE {
notBefore CertificateValidityDate,
notAfter CertificateValidityDate }

CertificateValidityDate ::= CHOICE {
utcTime UTCTime,
generalTime GeneralizedTime }

throws
CertificateExpiredException if the certificate has expired.
throws
CertificateNotYetValidException if the certificate is not yet valid.
since
Android 1.0

public abstract voidcheckValidity(java.util.Date date)
Checks whether the certificate is valid at the specified date.

param
date the date to check the validity against.
throws
CertificateExpiredException if the certificate has expired.
throws
CertificateNotYetValidException if the certificate is not yet valid.
see
#checkValidity()
since
Android 1.0

public static final javax.security.cert.X509CertificategetInstance(java.io.InputStream inStream)
Creates a new {@code X509Certificate} and initializes it from the specified input stream.

param
inStream input stream containing data to initialize the certificate.
return
the certificate initialized from the specified input stream
throws
CertificateException if the certificate cannot be created or initialized.
since
Android 1.0

        if (inStream == null) {
            throw new CertificateException(Messages.getString("security.87")); //$NON-NLS-1$
        }
        if (constructor != null) {
            try {
                return (X509Certificate) 
                    constructor.newInstance(new Object[] {inStream});
            } catch (Throwable e) {
                throw new CertificateException(e.getMessage());
            }
        }

        final java.security.cert.X509Certificate cert;
        try {
            CertificateFactory cf = CertificateFactory.getInstance("X.509"); //$NON-NLS-1$
            cert = (java.security.cert.X509Certificate)
                                            cf.generateCertificate(inStream);
        } catch (java.security.cert.CertificateException e) {
            throw new CertificateException(e.getMessage());
        }

        return new X509Certificate() {

            public byte[] getEncoded() throws CertificateEncodingException {
                try {
                    return cert.getEncoded();
                } catch (java.security.cert.CertificateEncodingException e) {
                    throw new CertificateEncodingException(e.getMessage());
                }
            }

            public void verify(PublicKey key) throws CertificateException,
                                NoSuchAlgorithmException, InvalidKeyException,
                                NoSuchProviderException, SignatureException {
                try {
                    cert.verify(key);
                } catch (java.security.cert.CertificateException e) {
                    throw new CertificateException(e.getMessage());
                }
            }

            public void verify(PublicKey key, String sigProvider)
                            throws CertificateException,
                                NoSuchAlgorithmException, InvalidKeyException,
                                NoSuchProviderException, SignatureException {
                try {
                    cert.verify(key, sigProvider);
                } catch (java.security.cert.CertificateException e) {
                    throw new CertificateException(e.getMessage());
                }
            }

            public String toString() {
                return cert.toString();
            }

            public PublicKey getPublicKey() {
                return cert.getPublicKey();
            }

            public void checkValidity() throws CertificateExpiredException,
                                   CertificateNotYetValidException {
                try {
                    cert.checkValidity();
                } catch (java.security.cert.CertificateNotYetValidException e) {
                    throw new CertificateNotYetValidException(e.getMessage());
                } catch (java.security.cert.CertificateExpiredException e) {
                    throw new CertificateExpiredException(e.getMessage());
                }
            }

            public void checkValidity(Date date) 
                            throws CertificateExpiredException,
                                   CertificateNotYetValidException {
                try {
                    cert.checkValidity(date);
                } catch (java.security.cert.CertificateNotYetValidException e) {
                    throw new CertificateNotYetValidException(e.getMessage());
                } catch (java.security.cert.CertificateExpiredException e) {
                    throw new CertificateExpiredException(e.getMessage());
                }
            }

            public int getVersion() {
                return 2;
            }

            public BigInteger getSerialNumber() {
                return cert.getSerialNumber();
            }

            public Principal getIssuerDN() {
                return cert.getIssuerDN();
            }

            public Principal getSubjectDN() {
                return cert.getSubjectDN();
            }

            public Date getNotBefore() {
                return cert.getNotBefore();
            }

            public Date getNotAfter() {
                return cert.getNotAfter();
            }

            public String getSigAlgName() {
                return cert.getSigAlgName();
            }

            public String getSigAlgOID() {
                return cert.getSigAlgOID();
            }

            public byte[] getSigAlgParams() {
                return cert.getSigAlgParams();
            }
        };
    
public static final javax.security.cert.X509CertificategetInstance(byte[] certData)
Creates a new {@code X509Certificate} and initializes it from the specified byte array.

param
certData byte array containing data to initialize the certificate.
return
the certificate initialized from the specified byte array
throws
CertificateException if the certificate cannot be created or initialized.
since
Android 1.0

        if (certData == null) {
            throw new CertificateException(Messages.getString("security.88")); //$NON-NLS-1$
        }
        ByteArrayInputStream bais = new ByteArrayInputStream(certData);
        return getInstance(bais);
    
public abstract java.security.PrincipalgetIssuerDN()
Returns the {@code issuer} (issuer distinguished name) as an implementation specific {@code Principal} object.

The ASN.1 definition of {@code issuer}:

issuer Name

Name ::= CHOICE {
RDNSequence }

RDNSequence ::= SEQUENCE OF RelativeDistinguishedName

RelativeDistinguishedName ::= SET OF AttributeTypeAndValue

AttributeTypeAndValue ::= SEQUENCE {
type AttributeType,
value AttributeValue }

AttributeType ::= OBJECT IDENTIFIER

AttributeValue ::= ANY DEFINED BY AttributeType

return
the {@code issuer} as an implementation specific {@code Principal}.
since
Android 1.0

public abstract java.util.DategetNotAfter()
Returns the {@code notAfter} date of the validity period of the certificate.

return
the end of the validity period.
since
Android 1.0

public abstract java.util.DategetNotBefore()
Returns the {@code notBefore} date from the validity period of the certificate.

return
the start of the validity period.
since
Android 1.0

public abstract java.math.BigIntegergetSerialNumber()
Returns the {@code serialNumber} of the certificate.

The ASN.1 definition of {@code serialNumber}:

CertificateSerialNumber ::= INTEGER

return
the serial number.
since
Android 1.0

public abstract java.lang.StringgetSigAlgName()
Returns the name of the algorithm for the certificate signature.

return
the signature algorithm name.
since
Android 1.0

public abstract java.lang.StringgetSigAlgOID()
Returns the OID of the signature algorithm from the certificate.

return
the OID of the signature algorithm.
since
Android 1.0

public abstract byte[]getSigAlgParams()
Returns the parameters of the signature algorithm in DER-encoded format.

return
the parameters of the signature algorithm, or null if none are used.
since
Android 1.0

public abstract java.security.PrincipalgetSubjectDN()
Returns the {@code subject} (subject distinguished name) as an implementation specific {@code Principal} object.

The ASN.1 definition of {@code subject}:

subject Name

Name ::= CHOICE {
RDNSequence }

RDNSequence ::= SEQUENCE OF RelativeDistinguishedName

RelativeDistinguishedName ::= SET OF AttributeTypeAndValue

AttributeTypeAndValue ::= SEQUENCE {
type AttributeType,
value AttributeValue }

AttributeType ::= OBJECT IDENTIFIER

AttributeValue ::= ANY DEFINED BY AttributeType

return
the {@code subject} (subject distinguished name).
since
Android 1.0

public abstract intgetVersion()
Returns the certificates {@code version} (version number).

The version defined is ASN.1:

Version ::= INTEGER { v1(0), v2(1), v3(2) }

return
the version number.
since
Android 1.0