X509Certificate

<p> Abstract class for X.509 certificates. This provides a standard way to access all the attributes of an X.509 certificate. <p> In June of 1996, the basic X.509 v3 format was completed by ISO/IEC and ANSI X9, which is described below in ASN.1: <pre> Certificate ::= SEQUENCE { tbsCertificate TBSCertificate, signatureAlgorithm AlgorithmIdentifier, signature BIT STRING } </pre> <p> These certificates are widely used to support authentication and other functionality in Internet security systems. Common applications include Privacy Enhanced Mail (PEM), Transport Layer Security (SSL), code signing for trusted software distribution, and Secure Electronic Transactions (SET). <p> These certificates are managed and vouched for by <em>Certificate Authorities</em> (CAs). CAs are services which create certificates by placing data in the X.509 standard format and then digitally signing that data. CAs act as trusted third parties, making introductions between principals who have no direct knowledge of each other. CA certificates are either signed by themselves, or by some other CA such as a "root" CA. <p> More information can be found in <a href="http://www.ietf.org/rfc/rfc3280.txt">RFC 3280: Internet X.509 Public Key Infrastructure Certificate and CRL Profile</a>. <p> The ASN.1 definition of {@code tbsCertificate} is: <pre> 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 } </pre> <p> Certificates are instantiated using a certificate factory. The following is an example of how to instantiate an X.509 certificate: <pre> try (InputStream inStream = new FileInputStream("fileName-of-cert")) { CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate)cf.generateCertificate(inStream); } </pre>

@author Hemma Prafullchandra

More...

Constructors

this
this()

Constructor for X.509 certificates.

Members

Functions

checkValidity
void checkValidity()

Checks that the certificate is currently valid. It is if the current date and time are within the validity period given in the certificate. <p> The validity period consists of two date/time values: the first and last dates (and times) on which the certificate is valid. It is defined in ASN.1 as: <pre> validity Validity

checkValidity
void checkValidity(Date date)

Checks that the given date is within the certificate's validity period. In other words, this determines whether the certificate would be valid at the given date/time.

getBasicConstraints
int getBasicConstraints()

Gets the certificate constraints path length from the critical {@code BasicConstraints} extension, (OID = 2.5.29.19). <p> The basic constraints extension identifies whether the subject of the certificate is a Certificate Authority (CA) and how deep a certification path may exist through that CA. The {@code pathLenConstraint} field (see below) is meaningful only if {@code cA} is set to TRUE. In this case, it gives the maximum number of CA certificates that may follow this certificate in a certification path. A value of zero indicates that only an end-entity certificate may follow in the path. <p> The ASN.1 definition for this is: <pre> BasicConstraints ::= SEQUENCE { cA BOOLEAN DEFAULT FALSE, pathLenConstraint INTEGER (0..MAX) OPTIONAL } </pre>

getIssuerDN
Principal getIssuerDN()

<strong>Denigrated</strong>, replaced by {@linkplain #getIssuerX500Principal()}. This method returns the {@code issuer} as an implementation specific Principal object, which should not be relied upon by portable code.

getIssuerUniqueID
bool[] getIssuerUniqueID()

Gets the {@code issuerUniqueID} value from the certificate. The issuer unique identifier is present in the certificate to handle the possibility of reuse of issuer names over time. RFC 3280 recommends that names not be reused and that conforming certificates not make use of unique identifiers. Applications conforming to that profile should be capable of parsing unique identifiers and making comparisons.

getIssuerX500Principal
X500Principal getIssuerX500Principal()

Returns the issuer (issuer distinguished name) value from the certificate as an {@code X500Principal}. <p> It is recommended that subclasses override this method.

getKeyUsage
bool[] getKeyUsage()

Gets a bool array representing bits of the {@code KeyUsage} extension, (OID = 2.5.29.15). The key usage extension defines the purpose (e.g., encipherment, signature, certificate signing) of the key contained in the certificate. The ASN.1 definition for this is: <pre> KeyUsage ::= BIT STRING { digitalSignature (0), nonRepudiation (1), keyEncipherment (2), dataEncipherment (3), keyAgreement (4), keyCertSign (5), cRLSign (6), encipherOnly (7), decipherOnly (8) } </pre> RFC 3280 recommends that when used, this be marked as a critical extension.

getNotAfter
Date getNotAfter()

Gets the {@code notAfter} date from the validity period of the certificate. See {@link #getNotBefore() getNotBefore} for relevant ASN.1 definitions.

getNotBefore
Date getNotBefore()

Gets the {@code notBefore} date from the validity period of the certificate. The relevant ASN.1 definitions are: <pre> validity Validity

getSerialNumber
BigInt getSerialNumber()

Gets the {@code serialNumber} value from the certificate. The serial number is an integer assigned by the certification authority to each certificate. It must be unique for each certificate issued by a given CA (i.e., the issuer name and serial number identify a unique certificate). The ASN.1 definition for this is: <pre> serialNumber CertificateSerialNumber

getSigAlgName
string getSigAlgName()

Gets the signature algorithm name for the certificate signature algorithm. An example is the string "SHA256withRSA". The ASN.1 definition for this is: <pre> signatureAlgorithm AlgorithmIdentifier

getSigAlgOID
string getSigAlgOID()

Gets the signature algorithm OID string from the certificate. An OID is represented by a set of nonnegative whole numbers separated by periods. For example, the string "1.2.840.10040.4.3" identifies the SHA-1 with DSA signature algorithm defined in <a href="http://www.ietf.org/rfc/rfc3279.txt">RFC 3279: Algorithms and Identifiers for the Internet X.509 Public Key Infrastructure Certificate and CRL Profile</a>.

getSigAlgParams
byte[] getSigAlgParams()

Gets the DER-encoded signature algorithm parameters from this certificate's signature algorithm. In most cases, the signature algorithm parameters are null; the parameters are usually supplied with the certificate's key. If access to individual parameter values is needed then use {@link java.security.AlgorithmParameters AlgorithmParameters} and instantiate with the name returned by {@link #getSigAlgName() getSigAlgName}.

getSignature
byte[] getSignature()

Gets the {@code signature} value (the raw signature bits) from the certificate. The ASN.1 definition for this is: <pre> signature BIT STRING </pre>

getSubjectDN
Principal getSubjectDN()

<strong>Denigrated</strong>, replaced by {@linkplain #getSubjectX500Principal()}. This method returns the {@code subject} as an implementation specific Principal object, which should not be relied upon by portable code.

getSubjectUniqueID
bool[] getSubjectUniqueID()

Gets the {@code subjectUniqueID} value from the certificate.

getSubjectX500Principal
X500Principal getSubjectX500Principal()

Returns the subject (subject distinguished name) value from the certificate as an {@code X500Principal}. If the subject value is empty, then the {@code getName()} method of the returned {@code X500Principal} object returns an empty string (""). <p> It is recommended that subclasses override this method.

getTBSCertificate
byte[] getTBSCertificate()

Gets the DER-encoded certificate information, the {@code tbsCertificate} from this certificate. This can be used to verify the signature independently.

getVersion
int getVersion()

Gets the {@code version} (version number) value from the certificate. The ASN.1 definition for this is: <pre> version [0] EXPLICIT Version DEFAULT v1

verify
void verify(PublicKey key, Provider sigProvider)

Verifies that this certificate was signed using the private key that corresponds to the specified key. This method uses the signature verification engine supplied by the specified provider. Note that the specified Provider object does not have to be registered in the provider list.

Inherited Members

From Certificate

getType
string getType()

Returns the type of this certificate.

opEquals
bool opEquals(Object other)

Compares this certificate for equality with the specified object. If the {@code other} object is an {@code instanceof} {@code Certificate}, then its encoded form is retrieved and compared with the encoded form of this certificate.

getEncoded
byte[] getEncoded()

Returns the encoded form of this certificate. It is assumed that each certificate type would have only a single form of encoding; for example, X.509 certificates would be encoded as ASN.1 DER.

verify
void verify(PublicKey key)

Verifies that this certificate was signed using the private key that corresponds to the specified key.

verify
void verify(PublicKey key, string sigProvider)

Verifies that this certificate was signed using the private key that corresponds to the specified key. This method uses the signature verification engine supplied by the specified provider.

verify
void verify(PublicKey key, Provider sigProvider)

Verifies that this certificate was signed using the private key that corresponds to the specified key. This method uses the signature verification engine supplied by the specified provider. Note that the specified Provider object does not have to be registered in the provider list.

getPublicKey
PublicKey getPublicKey()

Gets the key from this certificate.

CertificateRep
class CertificateRep

Alternate Certificate class for serialization. @since 1.3

From X509Extension

hasUnsupportedCriticalExtension
bool hasUnsupportedCriticalExtension()

Check if there is a critical extension that is not supported.

getCriticalExtensionOIDs
Set!string getCriticalExtensionOIDs()

Gets a Set of the OID strings for the extension(s) marked CRITICAL in the certificate/CRL managed by the object implementing this interface.

getNonCriticalExtensionOIDs
Set!string getNonCriticalExtensionOIDs()

Gets a Set of the OID strings for the extension(s) marked NON-CRITICAL in the certificate/CRL managed by the object implementing this interface.

getExtensionValue
byte[] getExtensionValue(string oid)

Gets the DER-encoded OCTET string for the extension value (<em>extnValue</em>) identified by the passed-in {@code oid} string. The {@code oid} string is represented by a set of nonnegative whole numbers separated by periods.

Detailed Description

@see Certificate @see CertificateFactory @see X509Extension

Meta