Package java.security.cert
Class X509Certificate
java.lang.Object
java.security.cert.Certificate
java.security.cert.X509Certificate
- All Implemented Interfaces:
Serializable,X509Extension
- Direct Known Subclasses:
OpenSSLX509Certificate,X509CertificateObject,X509CertImpl
public abstract class X509Certificate extends Certificate implements X509Extension
Abstract base class for X.509 certificates.
This represents a standard way for accessing the attributes of X.509 certificates.
The basic X.509 v3 format described in ASN.1:
Certificate ::= SEQUENCE {
tbsCertificate TBSCertificate,
signatureAlgorithm AlgorithmIdentifier,
signature BIT STRING }
TBSCertificate ::= SEQUENCE {
version [0] EXPLICIT Version DEFAULT v1,
serialNumber CertificateSerialNumber,
signature AlgorithmIdentifier,
issuer Name,
validity Validity,
subject Name,
subjectPublicKeyInfo SubjectPublicKeyInfo,
issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL,
-- If present, version must be v2 or v3
subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL,
-- If present, version must be v2 or v3
extensions [3] EXPLICIT Extensions OPTIONAL
-- If present, version must be v3
}
For more information consult RFC 2459 "Internet X.509 Public Key Infrastructure Certificate and CRL Profile" at http://www.ietf.org/rfc/rfc2459.txt .
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from class java.security.cert.Certificate
Certificate.CertificateRep -
Constructor Summary
Constructors Modifier Constructor Description protectedX509Certificate()Creates a newX509Certificate. -
Method Summary
Modifier and Type Method Description abstract voidcheckValidity()Checks whether the certificate is currently valid.abstract voidcheckValidity(Date date)Checks whether the certificate is valid at the specified date.abstract intgetBasicConstraints()Returns the path length of the certificate constraints from theBasicContraintsextension.List<String>getExtendedKeyUsage()Returns a read-only list of OID strings representing theExtKeyUsageSyntaxfield of the extended key usage extension.Collection<List<?>>getIssuerAlternativeNames()Returns a read-only list of the issuer alternative names from theIssuerAltNameextension.abstract PrincipalgetIssuerDN()Returns theissuer(issuer distinguished name) as an implementation specificPrincipalobject.abstract boolean[]getIssuerUniqueID()Returns theissuerUniqueIDfrom the certificate.X500PrincipalgetIssuerX500Principal()Returns theissuer(issuer distinguished name) as anX500Principal.abstract boolean[]getKeyUsage()Returns theKeyUsageextension as abooleanarray.abstract DategetNotAfter()Returns thenotAfterdate of the validity period of the certificate.abstract DategetNotBefore()Returns thenotBeforedate from the validity period of the certificate.abstract BigIntegergetSerialNumber()Returns theserialNumberof the certificate.abstract StringgetSigAlgName()Returns the name of the algorithm for the certificate signature.abstract StringgetSigAlgOID()Returns the OID of the signature algorithm from the certificate.abstract byte[]getSigAlgParams()Returns the parameters of the signature algorithm in DER-encoded format.abstract byte[]getSignature()Returns the raw signature bits from the certificate.Collection<List<?>>getSubjectAlternativeNames()Returns a read-only list of the subject alternative names from theSubjectAltNameextension.abstract PrincipalgetSubjectDN()Returns thesubject(subject distinguished name) as an implementation specificPrincipalobject.abstract boolean[]getSubjectUniqueID()Returns thesubjectUniqueIDfrom the certificate.X500PrincipalgetSubjectX500Principal()Returns thesubject(subject distinguished name) as anX500Principal.abstract byte[]getTBSCertificate()Returns thetbsCertificateinformation from this certificate in DER-encoded format.abstract intgetVersion()Returns the certificatesversion(version number).Methods inherited from class java.security.cert.Certificate
equals, getEncoded, getPublicKey, getType, hashCode, toString, verify, verify, writeReplaceMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.security.cert.X509Extension
getCriticalExtensionOIDs, getExtensionValue, getNonCriticalExtensionOIDs, hasUnsupportedCriticalExtension
-
Constructor Details
-
X509Certificate
protected X509Certificate()Creates a newX509Certificate.
-
-
Method Details
-
checkValidity
public abstract void checkValidity() throws CertificateExpiredException, CertificateNotYetValidExceptionChecks 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.CertificateNotYetValidException- if the certificate is not yet valid.
-
checkValidity
public abstract void checkValidity(Date date) throws CertificateExpiredException, CertificateNotYetValidExceptionChecks whether the certificate is valid at the specified date.- Parameters:
date- the date to check the validity against.- Throws:
CertificateExpiredException- if the certificate has expired.CertificateNotYetValidException- if the certificate is not yet valid.- See Also:
checkValidity()
-
getVersion
public abstract int getVersion()Returns the certificatesversion(version number).The version defined is ASN.1:
Version ::= INTEGER { v1(0), v2(1), v3(2) }- Returns:
- the version number.
-
getSerialNumber
Returns theserialNumberof the certificate.The ASN.1 definition of
serialNumber:CertificateSerialNumber ::= INTEGER
- Returns:
- the serial number.
-
getIssuerDN
Returns theissuer(issuer distinguished name) as an implementation specificPrincipalobject.The ASN.1 definition of
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 AttributeTypereplaced by:getIssuerX500Principal().- Returns:
- the
issueras an implementation specificPrincipal.
-
getIssuerX500Principal
Returns theissuer(issuer distinguished name) as anX500Principal.- Returns:
- the
issuer(issuer distinguished name).
-
getSubjectDN
Returns thesubject(subject distinguished name) as an implementation specificPrincipalobject.The ASN.1 definition of
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 AttributeTypereplaced by:
getSubjectX500Principal().- Returns:
- the
subject(subject distinguished name).
-
getSubjectX500Principal
Returns thesubject(subject distinguished name) as anX500Principal.- Returns:
- the
subject(subject distinguished name)
-
getNotBefore
Returns thenotBeforedate from the validity period of the certificate.- Returns:
- the start of the validity period.
-
getNotAfter
Returns thenotAfterdate of the validity period of the certificate.- Returns:
- the end of the validity period.
-
getTBSCertificate
Returns thetbsCertificateinformation from this certificate in DER-encoded format.- Returns:
- the DER-encoded certificate information.
- Throws:
CertificateEncodingException- if an error occurs in encoding
-
getSignature
public abstract byte[] getSignature()Returns the raw signature bits from the certificate.- Returns:
- the raw signature bits from the certificate.
-
getSigAlgName
Returns the name of the algorithm for the certificate signature.- Returns:
- the signature algorithm name.
-
getSigAlgOID
Returns the OID of the signature algorithm from the certificate.- Returns:
- the OID of the signature algorithm.
-
getSigAlgParams
public abstract byte[] getSigAlgParams()Returns the parameters of the signature algorithm in DER-encoded format.- Returns:
- the parameters of the signature algorithm, or
nullif none are used.
-
getIssuerUniqueID
public abstract boolean[] getIssuerUniqueID()Returns theissuerUniqueIDfrom the certificate.- Returns:
- the
issuerUniqueIDornullif there's none in the certificate.
-
getSubjectUniqueID
public abstract boolean[] getSubjectUniqueID()Returns thesubjectUniqueIDfrom the certificate.- Returns:
- the
subjectUniqueIDor null if there's none in the certificate.
-
getKeyUsage
public abstract boolean[] getKeyUsage()Returns theKeyUsageextension as abooleanarray.The ASN.1 definition of
KeyUsage:KeyUsage ::= BIT STRING { digitalSignature (0), nonRepudiation (1), keyEncipherment (2), dataEncipherment (3), keyAgreement (4), keyCertSign (5), cRLSign (6), encipherOnly (7), decipherOnly (8) }- Returns:
- the
KeyUsageextension ornullif there's none in the certificate.
-
getExtendedKeyUsage
Returns a read-only list of OID strings representing theExtKeyUsageSyntaxfield of the extended key usage extension.- Returns:
- the extended key usage extension, or
nullif there's none in the certificate. - Throws:
CertificateParsingException- if the extension decoding fails.
-
getBasicConstraints
public abstract int getBasicConstraints()Returns the path length of the certificate constraints from theBasicContraintsextension. If the certificate has no basic constraints or is not a certificate authority,-1is returned. If the certificate is a certificate authority without a path length,Integer.MAX_VALUEis returned. Otherwise, the certificate authority's path length is returned. -
getSubjectAlternativeNames
Returns a read-only list of the subject alternative names from theSubjectAltNameextension.The ASN.1 definition of
SubjectAltName:SubjectAltName ::= GeneralNames GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName GeneralName ::= CHOICE { otherName [0] AnotherName, rfc822Name [1] IA5String, dNSName [2] IA5String, x400Address [3] ORAddress, directoryName [4] Name, ediPartyName [5] EDIPartyName, uniformResourceIdentifier [6] IA5String, iPAddress [7] OCTET STRING, registeredID [8] OBJECT IDENTIFIER }- Returns:
- the subject alternative names or
nullif there are none in the certificate. - Throws:
CertificateParsingException- if decoding of the extension fails.
-
getIssuerAlternativeNames
Returns a read-only list of the issuer alternative names from theIssuerAltNameextension.The ASN.1 definition of
IssuerAltName:IssuerAltName ::= GeneralNames GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName GeneralName ::= CHOICE { otherName [0] AnotherName, rfc822Name [1] IA5String, dNSName [2] IA5String, x400Address [3] ORAddress, directoryName [4] Name, ediPartyName [5] EDIPartyName, uniformResourceIdentifier [6] IA5String, iPAddress [7] OCTET STRING, registeredID [8] OBJECT IDENTIFIER }- Returns:
- the issuer alternative names of
nullif there are none in the certificate. - Throws:
CertificateParsingException- if decoding of the extension fails.
-