All Packages Class Hierarchy This Package Previous Next Index
Class sun.security.x509.X509Cert
java.lang.Object
|
+----sun.security.x509.X509Cert
- public class X509Cert
- extends Object
- implements Certificate, Serializable
The X509Cert class represents an X.509 certificate. 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 E-commerce Transactions (SET). There
is a commercial infrastructure ready to manage large scale deployments
of X.509 identity certificates.
These certificates are managed and vouched for by Certificate
Authorities (CAs). CAs are services which create certificates by
placing data in the X.509 standard format and then digitally signing
that data. Such signatures are quite difficult to forge. CAs act as
trusted third parties, making introductions between agents 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.
X.509 certificates have several mandatory data elements, including:
- The Subject Name, an X.500 Distinguished Name for
the entity (subject) for which the certificate was issued.
- The Subject Public Key, the public key of the subject.
This is one of the most important parts of the certificate.
- The Validity Period, a time period (e.g. six months)
within which the certificate is valid (unless revoked).
- The Issuer Name, an X.500 Distinguished Name for the
Certificate Authority (CA) which issued the certificate.
- A Serial Number assigned by the CA, for use in
certificate revocation and other applications.
RFC 1422 is very informative, though it does not describe much
of the recent work being done with X.509 certificates. That includes
a 1993 version (X.509v3) and a variety of enhancements being made to
facilitate an explosion of personal certificates used as "Internet
Drivers' Licences", or with SET for credit card transactions.
Note that at this time X.509 extension attributes are not yet
supported. That is, generated certificates are X.509v1 format, and
X.509v2/v3 extensions in imported certificates are ignored.
- See Also:
- CertAndKeyGen
-
algid
-
-
X509Cert()
- Construct a uninitialized X509 Cert on which
decode must later be called (or which may be deserialized).
-
X509Cert(byte[])
- Unmarshals a certificate from its encoded form, parsing the
encoded bytes.
-
X509Cert(byte[], int, int)
- Unmarshals a certificate from its encoded form, parsing the
encoded bytes.
-
X509Cert(DerValue)
- Unmarshal a certificate from its encoded form, parsing a DER value.
-
X509Cert(X500Name, X509Key, Date, Date)
- Partially constructs a certificate from descriptive parameters.
-
decode(InputStream)
- Decode an X.509 certificate from an input stream.
-
encode(OutputStream)
- Appends the certificate to an output stream.
-
encodeAndSign(BigInt, X500Signer)
- Creates an X.509 certificate, and signs it using the issuer
passed (associating a signature algorithm and an X.500 name).
-
equals(Object)
- Compares two certificates.
-
equals(X509Cert)
- Compares two certificates, returning false if any data
differs between the two.
-
getFormat()
- Returns the "X.509" format identifier.
-
getGuarantor()
- Returns getIssuerName
-
getIssuerAlgorithmId()
- Returns the algorithm used by the issuer to sign the certificate.
-
getIssuerName()
- Returns the certificate issuer's X.500 distinguished name.
-
getNotAfter()
- Returns the last time the certificate is valid.
-
getNotBefore()
- Returns the first time the certificate is valid.
-
getPrincipal()
- Returns getSubjectName
-
getPublicKey()
- Returns the subject's public key.
-
getSerialNumber()
- Returns the certificate's serial number.
-
getSignedCert()
- Return the signed X.509 certificate as a byte array.
-
getSigner(AlgorithmId, PrivateKey)
- Returns an X500Signer that may be used to create signatures.
-
getSubjectName()
- Returns the subject's X.500 distinguished name.
-
getVerifier(String)
- Returns a signature object that may be used to verify signatures
created using a specified signature algorithm and the public key
contained in this certificate.
-
getVersion()
- Returns the X.509 version number of this certificate, zero based.
-
hashCode()
- Calculates a hash code value for the object.
-
toString()
- Returns a printable representation of the certificate.
-
toString(boolean)
- Returns a printable representation of the certificate.
-
verify(PublicKey)
- Throws an exception if the certificate is invalid because it is
now outside of the certificate's validity period, or because it
was not signed using the verification key provided.
algid
protected AlgorithmId algid
X509Cert
public X509Cert()
- Construct a uninitialized X509 Cert on which
decode must later be called (or which may be deserialized).
X509Cert
public X509Cert(byte cert[]) throws IOException
- Unmarshals a certificate from its encoded form, parsing the
encoded bytes. This form of constructor is used by agents which
need to examine and use certificate contents. That is, this is
one of the more commonly used constructors. Note that the buffer
must include only a certificate, and no "garbage" may be left at
the end. If you need to ignore data at the end of a certificate,
use another constructor.
- Parameters:
- cert - the encoded bytes, with no terminatu (CONSUMED)
- Throws: IOException
- when the certificate is improperly encoded.
X509Cert
public X509Cert(byte buf[],
int offset,
int len) throws IOException
- Unmarshals a certificate from its encoded form, parsing the
encoded bytes. This form of constructor is used by agents which
need to examine and use certificate contents. That is, this is
one of the most commonly used constructors.
- Parameters:
- buf - the buffer holding the encoded bytes
- offset - the offset in the buffer where the bytes begin
- len - how many bytes of certificate exist
- Throws: IOException
- when the certificate is improperly encoded.
X509Cert
public X509Cert(DerValue derVal) throws IOException
- Unmarshal a certificate from its encoded form, parsing a DER value.
This form of constructor is used by agents which need to examine
and use certificate contents.
- Parameters:
- derVal - the der value containing the encoded cert.
- Throws: IOException
- when the certificate is improperly encoded.
X509Cert
public X509Cert(X500Name subjectName,
X509Key subjectPublicKey,
Date notBefore,
Date notAfter) throws CertException
- Partially constructs a certificate from descriptive parameters.
This constructor may be used by Certificate Authority (CA) code,
which later signs and encodes the
certificate. Also, self-signed certificates serve as CA certificates,
and are sometimes used as certificate requests.
Until the certificate has been signed and encoded, some of
the mandatory fields in the certificate will not be available
via accessor functions: the serial number, issuer name and signing
algorithm, and of course the signed certificate. The fields passed
to this constructor are available, and must be non-null.
Note that the public key being signed is generally independent of
the signature algorithm being used. So for example Diffie-Hellman
keys (which do not support signatures) can be placed in X.509
certificates when some other signature algorithm (e.g. DSS/DSA,
or one of the RSA based algorithms) is used.
- Parameters:
- subjectName - the X.500 distinguished name being certified
- subjectPublicKey - the public key being certified. This
must be an "X509Key" implementing the "PublicKey" interface.
- notBefore - the first time the certificate is valid
- notAfter - the last time the certificate is valid
- Throws: CertException
- if the public key is inappropriate
- See Also:
- CertAndKeyGen
decode
public void decode(InputStream in) throws IOException
- Decode an X.509 certificate from an input stream.
- Parameters:
- in - an input stream holding at least one certificate
- Throws: IOException
- when the certificate is improperly encoded.
encode
public void encode(OutputStream out) throws IOException
- Appends the certificate to an output stream.
- Parameters:
- out - an input stream to which the certificate is appended.
- Throws: IOException
- when appending fails.
equals
public boolean equals(Object other)
- Compares two certificates. This is false if the
certificates are not both X.509 certs, otherwise it
compares them as binary data.
- Parameters:
- other - the object being compared with this one
- Returns:
- true iff the certificates are equivalent
- Overrides:
- equals in class Object
equals
public boolean equals(X509Cert src)
- Compares two certificates, returning false if any data
differs between the two.
- Parameters:
- other - the object being compared with this one
- Returns:
- true iff the certificates are equivalent
getFormat
public String getFormat()
- Returns the "X.509" format identifier.
getGuarantor
public Principal getGuarantor()
- Returns getIssuerName
getPrincipal
public Principal getPrincipal()
- Returns getSubjectName
verify
public void verify(PublicKey issuerPublicKey) throws CertException
- Throws an exception if the certificate is invalid because it is
now outside of the certificate's validity period, or because it
was not signed using the verification key provided. Successfully
verifying a certificate does not indicate that one should
trust the entity which it represents.
Note that since this class represents only a single X.509
certificate, it cannot know anything about the certificate chain
which is used to provide the verification key and to establish trust.
Other code must manage and use those cert chains.
For now, you must walk the cert chain being used to verify any
given cert. Start at the root, which is a self-signed certificate;
verify it using the key inside the certificate. Then use that to
verify the next certificate in the chain, issued by that CA. In
this manner, verify each certificate until you reach the particular
certificate you wish to verify. You should not use a certificate
if any of the verification operations for its certificate chain
were unsuccessful.
- Parameters:
- issuerPublicKey - the public key of the issuing CA
- Throws: CertException
- when the certificate is not valid.
encodeAndSign
public byte[] encodeAndSign(BigInt serial,
X500Signer issuer) throws IOException, SignatureException
- Creates an X.509 certificate, and signs it using the issuer
passed (associating a signature algorithm and an X.500 name).
This operation is used to implement the certificate generation
functionality of a certificate authority.
- Parameters:
- serial - the serial number of the certificate (non-null)
- issuer - the certificate issuer (CA) (non-null)
- Returns:
- the signed certificate, as returned by getSignedCert
- Throws: IOException
- if any of the data could not be encoded,
or when any mandatory data was omitted
- Throws: SignatureException
- on signing failures
- See Also:
- getSignedCert, getSigner, CertAndKeyGen
getSigner
public X500Signer getSigner(AlgorithmId algorithmId,
PrivateKey privateKey) throws NoSuchAlgorithmException, InvalidKeyException
- Returns an X500Signer that may be used to create signatures. Those
signature may in turn be verified using this certificate (or a
copy of it).
NOTE: If the private key is by itself capable of
creating signatures, this fact may not be recognized at this time.
Specifically, the case of DSS/DSA keys which get their algorithm
parameters from higher in the certificate chain is not supportable
without using an X509CertChain API, and there is no current support
for other sources of algorithm parameters.
- Parameters:
- algorithm - the signature algorithm to be used. Note that a
given public/private key pair may support several such algorithms.
- privateKey - the private key used to create the signature,
which must correspond to the public key in this certificate
- Returns:
- the Signer object
- Throws: NoSuchAlgorithmException
- if the signature
algorithm is not supported
- Throws: InvalidKeyException
- if either the key in the certificate,
or the private key parameter, does not support the requested
signature algorithm
getVerifier
public Signature getVerifier(String algorithm) throws NoSuchAlgorithmException, InvalidKeyException
- Returns a signature object that may be used to verify signatures
created using a specified signature algorithm and the public key
contained in this certificate.
NOTE: If the public key in this certificate is not by
itself capable of verifying signatures, this may not be recognized
at this time. Specifically, the case of DSS/DSA keys which get
their algorithm parameters from higher in the certificate chain
is not supportable without using an X509CertChain API, and there
is no current support for other sources of algorithm parameters.
- Parameters:
- algorithm - the algorithm of the signature to be verified
- Returns:
- the Signature object
- Throws: NoSuchAlgorithmException
- if the signature
algorithm is not supported
- Throws: InvalidKeyException
- if the key in the certificate
does not support the requested signature algorithm
getSignedCert
public byte[] getSignedCert()
- Return the signed X.509 certificate as a byte array.
The bytes are in standard DER marshaled form.
Null is returned in the case of a partially constructed cert.
getSerialNumber
public BigInt getSerialNumber()
- Returns the certificate's serial number.
Null is returned in the case of a partially constructed cert.
getSubjectName
public X500Name getSubjectName()
- Returns the subject's X.500 distinguished name.
getIssuerName
public X500Name getIssuerName()
- Returns the certificate issuer's X.500 distinguished name.
Null is returned in the case of a partially constructed cert.
getIssuerAlgorithmId
public AlgorithmId getIssuerAlgorithmId()
- Returns the algorithm used by the issuer to sign the certificate.
Null is returned in the case of a partially constructed cert.
getNotBefore
public Date getNotBefore()
- Returns the first time the certificate is valid.
getNotAfter
public Date getNotAfter()
- Returns the last time the certificate is valid.
getPublicKey
public PublicKey getPublicKey()
- Returns the subject's public key. Note that some public key
algorithms support an optional certificate generation policy
where the keys in the certificates are not in themselves sufficient
to perform a public key operation. Those keys need to be augmented
by algorithm parameters, which the certificate generation policy
chose not to place in the certificate.
Two such public key algorithms are: DSS/DSA, where algorithm
parameters could be acquired from a CA certificate in the chain
of issuers; and Diffie-Hellman, with a similar solution although
the CA then needs both a Diffie-Hellman certificate and a signature
capable certificate.
getVersion
public int getVersion()
- Returns the X.509 version number of this certificate, zero based.
That is, "2" indicates an X.509 version 3 (1993) certificate,
and "0" indicates X.509v1 (1988).
Zero is returned in the case of a partially constructed cert.
hashCode
public int hashCode()
- Calculates a hash code value for the object. Objects
which are equal will also have the same hashcode.
- Overrides:
- hashCode in class Object
toString
public String toString()
- Returns a printable representation of the certificate. This does not
contain all the information available to distinguish this from any
other certificate. The certificate must be fully constructed
before this function may be called; in particular, if you are
creating certificates you must call encodeAndSign() before calling
this function.
- Overrides:
- toString in class Object
toString
public String toString(boolean detailed)
- Returns a printable representation of the certificate.
- Parameters:
- detailed - true iff lots of detail is requested
All Packages Class Hierarchy This Package Previous Next Index