|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.security.cert.Certificate | +--java.security.cert.X509Certificate | +--iaik.x509.X509Certificate
This class represents a X.509 version 3 certificate, as specified by ISO/IEC and ANSI X9.
A certificate can be imagined as some kind of "digital identity card" attesting that a particular public key belongs to a particular entity. Certificates have a limited period of validity and are digitally signed by some trusted authority. Certificates can be verified by anyone having access to the signing authority´s public key. Each certification authority has to take care to label every handled certificate with a unique serial number for unequivocally identifying it. Certification authorities also have to maintain certification revocation lists of certificates that heve been expired for some reason and are no longer valid. Certification authorities (CAs) are organized in some tree-like structures, where certification authorities also are used for certifying other certification authorities. The certifcation authority being located at the highest level of such a tree, is called top-level or root certification authority and self-signs its public key with its own private key. Publicly available certification policies specify guidelines that may be referred by some entity for querying for the strategy a particular CA may follow for issuing and verifying certificates. Certification policy publishing CAs are called Policy Certification Authorities (PCAs) and prescribe the minimal policy requirements for all CAs located below in the CA-tree.
ITU-T X.509 defines a standard certificate format to be used along with the X.500 naming tree conventions. The first version has been published as X509v1 format in 1988, and has been extended in 1993 by version 2 about two fields for uniquely identifying certificate subject and issuer.
The X.509v3 certificate format extends its predecessor v2 format about the
extensions field for including some additional information (see PKIX
RFC 2459).
An extension may be a defined standard extension
(e.g. certificatePolicies
, keyUsage
, ...), or it
may be a private extension providing some community-specific information. If
an extension is marked as critical, but the certificate handling software
cannot parse this extension, the appertaining certifcate has to be rejected.
Non-Critical extensions can be ignored, if they cannot be handled (i.e. of
unknown state).
X.509 certificates are described platform-independently by using the Abstract Syntax Notation One (ASN.1) language (defined in the ITU-T X.208 standard). X.509 ASN.1 structures are encoded according to the Distinguished Encoding Rules (DER). The X.509v3 certificate format is defined as an ASN.1 SEQUENCE structure containing the following components:
Certificate ::= SEQUENCE { tbsCertificate TBSCertificate, signatureAlgorithm AlgorithmIdentifier, signatureValue BIT STRING }where signatureAlgorithm identifies the signature algorithm used by the signing certification authority for computing the digital signature upon the ASN.1 DER encoded
TBSCertificate
structure, which itself is expressed as ASN.1
SEQUENCE structure specifying the (distinguished) names of subject and issuer, the public key of the
subject, validity period, signature algorithm (the same as specified in Certificate
above), version and serial numbers, and optionally unique identifiers for subject and
issuer:
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 }
where:
Version ::= INTEGER { v1(0), v2(1), v3(2) }
CertificateSerialNumber ::= INTEGER
AlgorithmIdentifier ::= SEQUENCE { algorithm OBJECT IDENTIFIER, parameters ANY DEFINED BY algorithm OPTIONAL }
Name ::= CHOICE { RDNSequence }
RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
RelativeDistinguishedName ::= SET OF AttributeTypeAndValue
AttributeTypeAndValue ::= SEQUENCE { type AttributeType, value AttributeValue }
AttributeType ::= OBJECT IDENTIFIER
AttributeValue ::= ANY -- Directory string type --
DirectoryString ::= CHOICE { teletexString TeletexString (SIZE (1..maxSize), printableString PrintableString (SIZE (1..maxSize)), universalString UniversalString (SIZE (1..maxSize)), bmpString BMPString (SIZE(1..maxSIZE)) }
Validity ::= SEQUENCE { notBefore Time, notAfter Time }
Time ::= CHOICE { utcTime UTCTime, generalTime GeneralizedTime }
UniqueIdentifier ::= BIT STRING
SubjectPublicKeyInfo ::= SEQUENCE { algorithm AlgorithmIdentifier, subjectPublicKey BIT STRING }
Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension
Extension ::= SEQUENCE { extnID OBJECT IDENTIFIER, critical BOOLEAN DEFAULT FALSE, extnValue OCTET STRING }
For a detailled description of the several fields refer to RFC 2459.
For each value extists a set<Value>
and a get<Value>
method.
After creating a X509Certificate, the, for instance, validity period may be set to,
e.g. 6 month counting from the current date, by using the
setValidNotBefore
and
setValidNotAfter
methods:
X509Certificate X509cert = new X509Certificate(); GregorianCalendar date = (GregorianCalendar)Calendar.getInstance(); X509cert.setValidNotBefore(date.getTime()); date.add(Calendar.MONTH, 6); X509cert.setValidNotAfter(date.getTime());
Manipulating the extensions of a certificate is described in class
X509Extensions
.
For adding some extension to a X509Certificate use the addExtension(V3Extension e)
method, e.g:
BasicConstraints basicConstraints = new BasicConstraints(false); X509cert.addExtension(basicConstraints);
After creating a new certificate by means of the default constructor
, setting issuer
and
subject
names, specifying the subject´s
public key
, setting validity
period and serial number
, and
adding any extension
to be included,
finally sign
the
certificate with the private key of the issuer.
The X509Certificate(byte[])
and
X509Certificate(InputStream)
constructors
may be used for parsing an X509Certificate from its DER encoding.
X509Extensions
,
V3Extension
,
UnknownExtension
,
X509CRL
,
RevokedCertificate
,
Certificate
,
X509Certificate
, Serialized FormInner classes inherited from class java.security.cert.Certificate |
Certificate.CertificateRep |
Constructor Summary | |
X509Certificate()
Default constructor for creating a new empty X509 certificate. |
|
X509Certificate(byte[] array)
Creates a X509Certificate form a PEM or DER byte array. |
|
X509Certificate(InputStream is)
Creates a X509Certificate from an input stream. |
Method Summary | |
void |
addExtension(V3Extension e)
Adds the given X509v3 extension. |
void |
checkValidity()
Checks if this certificate currently is valid. |
void |
checkValidity(Date date)
Checks if this certificate would be valid at the given date value. |
int |
countExtensions()
Returns the number of extensions included into this certificate. |
void |
decode(ASN1Object obj)
Creates a X509Certificate from an ASN1Object. |
void |
decode(InputStream is)
Decodes a X509Certificate from an inputstream. |
int |
getBasicConstraints()
Returns the pathLenConstraint value of the BasicConstraints
extension, if included in this certificate.
|
Set |
getCriticalExtensionOIDs()
Returns a Set of the OID strings identifying the extension(s) that are marked CRITICAL in this certificate. |
byte[] |
getEncoded()
Returns this X509 certificate as DER encoded ASN.1 data structure |
V3Extension |
getExtension(ObjectID oid)
Returns a specific extension, identified by its object identifier. |
byte[] |
getExtensionValue(String oid)
Returns a byte array representing the DER encoding of the extension value identified by the passed-in OID string. |
byte[] |
getFingerprint()
Returns the fingerprint of this certificate. |
byte[] |
getFingerprint(String digestAlgorithm)
Returns the fingerprint of this certificate calculated with the given hash algorithm. |
byte[] |
getFingerprintSHA()
Get the SHA fingerprint of this certificate. |
Principal |
getIssuerDN()
Returns the Distinguished Name of the issuer of this certificate, as Principal . |
boolean[] |
getIssuerUniqueID()
Returns the issuer unique identifier of this certificate, or null if no
IssuerUniqueID is specified by this certificate.
|
boolean[] |
getKeyUsage()
Returns the bits representing the getKeyUsage extension, if
included in this certificate.
|
Set |
getNonCriticalExtensionOIDs()
Returns a Set of the OID strings for the extension(s) marked NON-CRITICAL in this certificate. |
Date |
getNotAfter()
Returns the notAfter date of this certificate.
|
Date |
getNotBefore()
Returns the notBefore date of this certificate.
|
PublicKey |
getPublicKey()
Returns the public key of this certificate. |
BigInteger |
getSerialNumber()
Returns the serial number of this certificate as BigInteger .
|
String |
getSigAlgName()
Returns the name of the signature algorithm used by the issuer for signing this certificate. |
String |
getSigAlgOID()
Returns the OID of the signature algorithm used by the issuer for signing this certificate. |
byte[] |
getSigAlgParams()
Returns the algorithm parameters associated with the signature algorithm used by the issuer for signing this certificate. |
byte[] |
getSignature()
Returns the signature of this certificate. |
AlgorithmID |
getSignatureAlgorithm()
Returns the signature algorithm of this certificate. |
Principal |
getSubjectDN()
Returns the Distinguished Name of the subject of this certificate, as Principal .
|
boolean[] |
getSubjectUniqueID()
Returns the subject unique identifier of this certificate, or null if no
SubjectUniqueID is specified by this certificate.
|
byte[] |
getTBSCertificate()
Returns the DER encoded TBSCertificate ASN.1 data structure specifying
all subject and issuer related information.
|
int |
getVersion()
Returns the version number of this certificate as int .
|
boolean |
hasExtensions()
Checks, if there are any extensions included into this certificate. |
boolean |
hasUnsupportedCriticalExtension()
Returns true if there are unsupported critical extensions. |
Enumeration |
listExtensions()
Returns an enumeration of all extensions included into this certificate. |
void |
removeAllExtensions()
Removes all extensions from this certificate. |
boolean |
removeExtension(ObjectID oid)
Removes the extension specified by its object identifier. |
void |
setIssuerDN(Principal issuer)
Sets the issuer of this certificate. |
void |
setIssuerUniqueID(boolean[] id)
Sets the issuer unique ID for this certificate. |
void |
setPublicKey(PublicKey publicKey)
Sets the public key of this certificate. |
void |
setSerialNumber(BigInteger serialNumber)
Sets the serial number of this certificate. |
void |
setSignature(byte[] signatureValue)
Sets the signature value of this certificate. |
void |
setSignatureAlgorithm(AlgorithmID signatureAlg)
Sets the signature algorithm to be used for signing. |
void |
setSubjectDN(Principal subject)
Sets the subject of this certificate. |
void |
setSubjectUniqueID(boolean[] id)
Sets the subject unique ID for this certificate. |
void |
setValidNotAfter(Date validNotAfter)
Sets the notAfter date of this certificate.
|
void |
setValidNotBefore(Date validNotBefore)
Sets the notBefore date of this certificate.
|
void |
sign(AlgorithmID signatureAlg,
PrivateKey issuerPK)
Signs the certificate with the private key of the issuer. |
void |
sign(AlgorithmID signatureAlg,
PrivateKey issuerPK,
String provider)
Signs the certificate with the private key of the issuer. |
ASN1Object |
toASN1Object()
Returns the certificate as an ASN1Object. |
byte[] |
toByteArray()
Returns the certificate as DER encoded ASN.1 data structure. |
String |
toString()
Returns a string that represents the contents of the certificate. |
String |
toString(boolean detailed)
Returns a string that represents the contents of the certificate. |
void |
verify()
Verifies a self signed certificate. |
void |
verify(PublicKey key)
Verifies a certificate using the given public key. |
void |
verify(PublicKey key,
AlgorithmParameterSpec params)
Uses the given public (EC)DSA key and (EC)DSA parameters to verify this certificate. |
void |
verify(PublicKey key,
String sigProvider)
Uses the given public key to verify a certificate based on a signature algorithm supplied by the specified provider. |
void |
writeTo(OutputStream os)
Writes the certificate DER encoded to the given output stream. |
Methods inherited from class java.security.cert.Certificate |
equals, getType, hashCode, writeReplace |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public X509Certificate()
Any value may be set using the corrseponding set<Value>
method.
The version number per default is set to 1
indicating a
Version 1
certificate. When including subjectUniqueID
or issuerUniqueID
, the version automatically
will be set to 2, and when adding
an extension increased to 3.
public X509Certificate(InputStream is) throws IOException, CertificateException
The supplied certificate can be in PEM or DER format.
This constructor reads a X509Certificate previously written with
method writeTo(OutputStream)
.
For instance:
InputStream fis = new FileInputStream("cert.der"); X509Certificate cert = new X509Certificate(fis); fis.close();
is
- InputStream from which to create the certificateIOException
- if the certificate could not be readCertificateException
- if there is a problem with the certificatepublic X509Certificate(byte[] array) throws CertificateException
This constructor may be used for parsing an already exisiting
X509Certifcate
ASN.1 object, supplied as DER encoded
byte array, which may have been created by calling the toByteArray
or the getEncoded
method.
array
- the byte array containing the DER encoded certificateCertificateException
- if the format of the cert is wrongMethod Detail |
public void decode(ASN1Object obj) throws CodingException
The given ASN1Object represents an already existing X509Certificate
which may have been created by calling the toASN1Object
method.
decode
in interface ASN1Type
obj
- the ASN1Object which contains the certificateCodingException
- if there is a problem when parsing the certificatepublic void decode(InputStream is) throws IOException, CertificateException
is
- the InputStream from where the certificate should be readIOException
- if something is wrong with the InputStreamCertificateException
- if the certificate is not properly initialized,
or data is missing, etc.public void sign(AlgorithmID signatureAlg, PrivateKey issuerPK) throws CertificateException, InvalidKeyException, NoSuchAlgorithmException
signatureAlg
- the AlgorithmID of the signature algorithmissuerPK
- the private key of the issuerCertificateException
- if the certificate could not be signedInvalidKeyException
- if the format of the key is wrongNoSuchAlgorithmException
- if there is no implementation for the
specified algorithmpublic void sign(AlgorithmID signatureAlg, PrivateKey issuerPK, String provider) throws CertificateException, InvalidKeyException, NoSuchAlgorithmException
signatureAlg
- the AlgorithmID of the signature algorithmissuerPK
- the private key of the issuerprovider
- the name of the provider supplying the Signature engine
to be usedCertificateException
- if the certificate could not be signedInvalidKeyException
- if the format of the key is wrongNoSuchAlgorithmException
- if there is no implementation for the
specified algorithmpublic void setSignature(byte[] signatureValue) throws CertificateException
This method provides an alternative to method sign
when
it is required to set the signature value from outside (e.g. calculated
by means of a smartcard):
X509Certificate cert = ...; ... // set issuer, subject, validity, ... ... // set the signature algorithm to be used for signing cert.setSignatureAlgorithm(AlgorithmID.sha1WithRSAEncryption); // get the to-be-signed value byte[] tbs = cert.getTBSCertificate(); // now calculate the signature over the tbs certificate byte[] signatureValue = calculateSignature(tbs); // and set the signatureValue cert.setSignature(signatureValue); // encode the certificate byte[] encodedCert = cert.getEncoded();
signatureValue
- the signature calculated outsideCertificateException
- if the certificate could not be signedpublic void checkValidity(Date date) throws CertificateExpiredException, CertificateNotYetValidException
notBefore
and notAfter
Time values.
This method just checks if the given date/time value lies between notBefore
and notAfter
and throws an exception if this does not come true.checkValidity
in class X509Certificate
CertificateExpiredException
- if the certificate alreay has expired or the
validNotAfter date yet has not been setCertificateNotYetValidException
- if the certificate yet is not valid or the
validNotBefore date yet has not been setcheckValidity(java.util.Date)
public void checkValidity() throws CertificateExpiredException, CertificateNotYetValidException
notBefore
and notAfter
Time values:
Validity ::= SEQUENCE { notBefore Time, notAfter Time }
Time ::= CHOICE { utcTime UTCTime, generalTime GeneralizedTime }
The X.509 Certificate and CRL Profile specified in RFC 2459 recommends to encode certificate validity dates through the year 2049 as UTCTime, and certificate validity dates in 2050 or later as GeneralizedTime.
The notBefore
and notAfter
time values can be set by using
the setValidNotBefore
and
setValidNotAfter
methods.
This checkValidity
method only calls checkValidity(Date)
with the current date to check if it lies between
the two time values specified by notBefore
and notAfter
.
checkValidity
in class X509Certificate
CertificateExpiredException
- if the certificate already has expiredCertificateNotYetValidException
- if the certificate is yet not validUTCTime
,
GeneralizedTime
public byte[] getEncoded() throws CertificateEncodingException
getEncoded
in class Certificate
CertificateEncodingException
- if the certificate cannot be encoded correctlypublic int getVersion()
int
.
The version number may specify a v1, v2, or v3 certificate.
ASN.1 definition:
Version ::= INTEGER { v1(0), v2(1), v3(2) }
getVersion
in class X509Certificate
int
,
1 for a v1 cert, 2 for a v2 cert, and 3 for a v3 certpublic BigInteger getSerialNumber()
BigInteger
.
Certificates are labelled with serial numbers by the issuing certification
authority for unequivocally identifying them:
ASN.1 definition:
CertificateSerialNumber ::= INTEGER
getSerialNumber
in class X509Certificate
BigInteger
public Principal getIssuerDN()
Principal
. A Distinguished Name is used to specify a path within a X.500 directory information tree. A distinguished name is defined as a sequence of relative distinguished names:
Name ::= CHOICE { RDNSequence }
RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
RelativeDistinguishedName ::= SET OF AttributeTypeAndValue
AttributeTypeAndValue ::= SEQUENCE { type AttributeType, value AttributeValue }
AttributeType ::= OBJECT IDENTIFIER
AttributeValue ::= ANY
The AttributeType
generally will be of ASN.1 type
DirectoryString
which either may be a PrintableString,
TeletexString, BMPString
, or an UniversalString
.
A name may consist of, for instance, the following Attribute Type/Value
"pairs" defining a path through a X.500 directory tree:
country: "AT" locality: "Graz" organization: "TU Graz" organizationalUnit: "IAIK" commonName: "IAIK TestCA"
CAs conforming to RFC 2459
have to ensure to only issue certificates having a non-empty distinguished
name (DN) in their issuer field. Additional identities about the issuer may
be included in the IssuerAltName
extension.
getIssuerDN
in class X509Certificate
Principal
Name
,
RDN
public Principal getSubjectDN()
Principal
.
The subject of the certificate is the entity the certificate belongs to.
A Distinguished Name is used to specify a path within a X.500 directory information tree. A distinguished name is defined as a sequence of relative distinguished names:
Name ::= CHOICE { RDNSequence }
RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
RelativeDistinguishedName ::= SET OF AttributeTypeAndValue
AttributeTypeAndValue ::= SEQUENCE { type AttributeType, value AttributeValue }
AttributeType ::= OBJECT IDENTIFIER
AttributeValue ::= ANY
The AttributeType
generally will be of ASN.1 type
DirectoryString
which either may be a PrintableString,
TeletexString, BMPString
, or an UniversalString
. A name
may consist of, for instance, the following Attribute Type/Value
"pairs" defining a path through a X.500 directory tree:
country: "AT" locality: "Graz" organization: "TU Graz" organizationalUnit: "IAIK" commonName: "TestUser"
The subject identity also may be specified by a subjectAltName
extension (e.g. as an e-mail address). If the subject identity only is
specified by an subjectAltName
extension, the subject
name field may be left an empty SEQUENCE and the subjectAltName
extension has to be marked to be critical (see RFC 2459).
getSubjectDN
in class X509Certificate
Principal
Name
,
RDN
public Date getNotBefore()
notBefore
date of this certificate.
The notBefore
value denotes the date on which the certificate
becomes valid and can be set using the setValidNotBefore
method.
getNotBefore
in class X509Certificate
null
if the notBefore date has yet not been setcheckValidity(java.util.Date)
public Date getNotAfter()
notAfter
date of this certificate.
The notAfter
value denotes the date on which
the certificate´s validity expires. The notAfter
date can be
set using the setValidNotAfter
method.
getNotAfter
in class X509Certificate
null
if the notAfter date has yet not been setcheckValidity(java.util.Date)
public byte[] getTBSCertificate() throws CertificateEncodingException
TBSCertificate
ASN.1 data structure specifying
all subject and issuer related information.
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 }
getTBSCertificate
in class X509Certificate
TBSCertificate
as DER encoded ASN.1 structureCertificateEncodingException
- if an encoding error occurspublic void setSignatureAlgorithm(AlgorithmID signatureAlg)
getTBSCertificate
before signing the cert. When using this fearure
an application itsself is responsible to ensure that the signature
algorithm specified by this method is equal to that supplied to
the sign(AlgorithmID, PrivateKey)
method when finally signing the certificate.signatureAlg
- the signature algorithm to be used for signingpublic byte[] getSignature()
getSignature
in class X509Certificate
public String getSigAlgName()
getSigAlgName
in class X509Certificate
null
if the signature algorithm yet has not been setpublic String getSigAlgOID()
getSigAlgOID
in class X509Certificate
null
if the signature algorithm yet has not been setObjectID
,
AlgorithmID
public byte[] getSigAlgParams()
getSigAlgParams
in class X509Certificate
null
if there are no parameters used or the signature algorithm
yet has been not setpublic boolean[] getIssuerUniqueID()
null
if no
IssuerUniqueID
is specified by this certificate.
Together with the SubjectUniqueID
the
issuer unique identifier field has been introduced by the X.509v2 certificate format
for providing the possibility of reusing subject and/or issuer names over time.
RFC 2459
recommends that names should not be reused and
that Internet certificates should not use unique identifiers.
Issuer and subject unique identifiers are defined as ASN.1 BIT STRING structure:
UniqueIdentifier ::= BIT STRING
This method scans the issuer unique identifier and returns it as an array of boolean values.
getIssuerUniqueID
in class X509Certificate
IssuerUniqueID
of this certificate as array of booleans, or
null
if no issuer unique identifier is speciifedpublic boolean[] getSubjectUniqueID()
null
if no
SubjectUniqueID
is specified by this certificate.
Together with the IssuerUniqueID
the
subject unique identifier field has been introduced by the X.509v2 certificate format
for providing the possibility of reusing issuer and/or subject names over time.
RFC 2459 recommends that names
should not be reused and that Internet certificates should not use unique
identifiers.
Issuer and subject unique identifiers are defined as ASN.1 BIT STRING structure:
UniqueIdentifier ::= BIT STRING
This method scans the subject unique identifier and returns it as an array of boolean values.
getSubjectUniqueID
in class X509Certificate
SubjectUniqueID
of this certificate as array of booleans, or
null
if no subject unique identifier is speciifedpublic boolean[] getKeyUsage()
getKeyUsage
extension, if
included in this certificate.
The KeyUsage
extension is a standard extension and defines
the purpose (e.g., encipherment, signature, certificate signing) of the
key contained in this certificate.
RFC 2459 recommends that when using this extension, it should be marked as being a critical one.
KeyUsage ::= BIT STRING { digitalSignature (0), nonRepudiation (1), keyEncipherment (2), dataEncipherment (3), keyAgreement (4), keyCertSign (5), cRLSign (6), encipherOnly (7), decipherOnly (8) }
The bits representing the KeyUsage
extension are returned as an
array of boolean
values.
getKeyUsage
in class X509Certificate
KeyUsage
extension, or null
if this extension included in this certificate.public int getBasicConstraints()
pathLenConstraint
value of the BasicConstraints
extension, if included in this certificate.
The BasicConstraints
extension is a standard extension specifying whether
the subject of this certificate is a CA and how deep a certification path may exist
through that CA.
BasicConstraints ::= SEQUENCE { cA BOOLEAN DEFAULT FALSE, pathLenConstraint INTEGER (0..MAX) OPTIONAL }
The pathLenConstraint
field is meaningful only if 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.
If the pathLenConstraint
value is set, it has to be greater than or
equal to zero
. If it is not set, the certification path may be of
any length.
RFC 2459
recommends to use the BasicConstraint
extension only in CA
certificates, where it should be marked as being critical
getBasicConstraints
in class X509Certificate
pathLenConstraint
value, specifying the maximum number of
CA certificates that may follow this certificate in a certification path if
the BasicConstraint
extension is included in this certitifcate
and cA
(true) and pathLenConstraint
values are set;
if only the cA
value is set to true
, but the
pathLenConstraint
value is not specified, this method returns
Integer.MAX_VALUE indicating that the certification path may have any length; if the
the BasicConstraint
extension is not included into this
certificate, this method also returns -1public void verify() throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException
This method only calls verify(PublicKey)
with the public key certified by this certificate. Since this certificate would
be a self-signed certificate, issuer and subject would be the same entities.
CertificateException
- if an encoding error occursNoSuchAlgorithmException
- if there is no implementation for the algorithm used to sign this certInvalidKeyException
- if the format of the public key is wrongNoSuchProviderException
- if there is no such providerSignatureException
- if the signature does not verifypublic void verify(PublicKey key, String sigProvider) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException
verify
in class Certificate
key
- the public key (of the issuer) to verify the certsigProvider
- the name of the provider supplying the signature algorithmCertificateException
- if an encoding error occursNoSuchAlgorithmException
- if there is no implementation for the algorithm used to sign this certInvalidKeyException
- if the format of the public key is wrongNoSuchProviderException
- if there is no such providerSignatureException
- if the signature does not verifypublic void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException
This method only calls verify(PublicKey, String)
setting the provider name to
null
for relying on the default provider signature architecture.
verify
in class Certificate
key
- the public key of the issuerCertificateException
- if an encoding error occursNoSuchAlgorithmException
- if there is no implementation for the algorithm used to sign this certInvalidKeyException
- if the format of the public key is wrongNoSuchProviderException
- if there is no default providerSignatureException
- if the signature does not verifypublic void verify(PublicKey key, AlgorithmParameterSpec params) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException
Attention! This method only may be used to verify a certificate that has been signed with the (EC)DSA algorithm and the public (EC)DSA key now used for verification does not contain the (EC)DSA parameters. Additionally this method only can be used with the IAIK provider.
key
- the public (EC)DSA key (of the issuer) to verify the certparams
- the (EC)DSA parameters provided by other meansCertificateException
- if an encoding error occursNoSuchAlgorithmException
- if there is no implementation for the algorithm used to sign this certInvalidKeyException
- if the format of the public key is wrongNoSuchProviderException
- if there is no such providerSignatureException
- if the signature does not verifypublic ASN1Object toASN1Object()
toASN1Object
in interface ASN1Type
public byte[] toByteArray()
public void writeTo(OutputStream os) throws IOException
try { OutputStream fos = new FileOutputStream("Cert.der"); cert.writeTo(fos); fos.close(); } catch (IOException ex) { System.out.println("IOException: " + ex.toString()); }
os
- the output stream where the certifiacte shall be written toIOException
- if an I/O error occurspublic void setSerialNumber(BigInteger serialNumber)
For instance:
cert.setSerialNumber(BigInteger.valueOf(0x1234L));
serialNumber
- the serial number of the certificate as BigIntegergetSerialNumber()
public void setIssuerDN(Principal issuer) throws IllegalArgumentException
The issuer is the identity which signs the certificate. It is specified by its X.500 distinguished name.
For instance:
Name issuer = new Name(); issuer.addRDN(ObjectID.country, "AT"); issuer.addRDN(ObjectID.organization ,"TU Graz"); issuer.addRDN(ObjectID.organizationalUnit ,"IAIK"); issuer.addRDN(ObjectID.commonName ,"IAIK Test CA"); cert.setIssuerDN(issuer);
issuer
- the Distinguished Name of issuer of the certificateIllegalArgumentException
- if the issuer is not an instance of namegetIssuerDN()
public void setValidNotBefore(Date validNotBefore)
notBefore
date of this certificate.
For instance:
GregorianCalendar date = (GregorianCalendar)Calendar.getInstance(); cert.setValidNotBefore(date.getTime());
The certificate is not valid before this Date.
validNotBefore
- Date when cert will become validgetNotBefore()
public void setValidNotAfter(Date validNotAfter)
notAfter
date of this certificate.
For instance:
GregorianCalendar date = (GregorianCalendar)Calendar.getInstance(); date.add(Calendar.MONTH, 6); cert.setValidNotAfter(date.getTime());
The certificate will expire at this Date.
validNotAfter
- Date on which the certificate will expiregetNotAfter()
public void setSubjectDN(Principal subject) throws IllegalArgumentException
For instance:
Name subject = new Name(); subject.addRDN(ObjectID.country, "AT"); subject.addRDN(ObjectID.organization ,"IAIK"); subject.addRDN(ObjectID.emailAddress ,"user@iaik.tu-graz.ac.at"); subject.addRDN(ObjectID.commonName ,"Test User"); cert.setSubjectDN(subject);
The subject is the entity claiming for certification of its public key.
subject
- the Distinguished Name of the subject of the certificateIllegalArgumentException
- if the subject is not an instance of namegetSubjectDN()
public void setPublicKey(PublicKey publicKey) throws InvalidKeyException
publicKey
- the public key of the subjectInvalidKeyException
- if the public key has an invalid encodinggetPublicKey()
public void setIssuerUniqueID(boolean[] id)
id
- the unique identifier of the issuer as array of boolean valuesgetIssuerUniqueID()
public void setSubjectUniqueID(boolean[] id)
id
- the unique identifier of the subject as array of boolean valuesgetSubjectUniqueID()
public AlgorithmID getSignatureAlgorithm()
AlgorithmID
public PublicKey getPublicKey()
getPublicKey
in class Certificate
public byte[] getFingerprint()
public byte[] getFingerprint(String digestAlgorithm) throws NoSuchAlgorithmException
digestAlgorithm
- the digest algorithm to be usedNoSuchAlgorithmException
- if the requested algorithm is not supportedpublic byte[] getFingerprintSHA()
public String toString()
toString
in class Certificate
public Set getCriticalExtensionOIDs()
getCriticalExtensionOIDs
in class X509Certificate
null
getNonCriticalExtensionOIDs()
public Set getNonCriticalExtensionOIDs()
getNonCriticalExtensionOIDs
in class X509Certificate
getCriticalExtensionOIDs()
public byte[] getExtensionValue(String oid)
The oid
string is represented by a set of positive whole numbers
separated by periods, e.g. "2.5.29.15" for the KeyUsage
extension.
In ASN.1, the Extensions
field is defined as a SEQUENCE of Extension:
Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension
Extension ::= SEQUENCE { extnID OBJECT IDENTIFIER, critical BOOLEAN DEFAULT FALSE, extnValue OCTET STRING }
where critical
specifies whether an extension has to be treated
as being critical or not; the default value is FALSE. An extension can be identified by
its object identifier, given in the extnID
field. The value of the extension
is represented as ASN.1 OCTET STRING data structure in the extnValue
field. Only one instance of a particular extension may be present in a particular
certificate.
The byte value returned by this method represents the DER encoding of the extnValue (OCTET_STRING) from above, and the value of this OCTET STRING represents the DER encoding of the specific extension´s ASN.1 representation itsself.
Attention: For compatibility reasons to the standard JCA certificate API this method has been changed to return the OCTET STRING value as described above. Prior versions of this class have returned the DER encoding of the specific extension´s ASN.1 representation itsself.
getExtensionValue
in class X509Certificate
oid
- the Object Identifier of the extension to be queried fornull
if it is not presentpublic void addExtension(V3Extension e) throws X509ExtensionException
The extension to be added shall be an implemented
V3Extension
.
Extensions are managed by the X509Extensions
class which maintaines two hashtables, one
for recording critical extensions, and the other for non-critical extensions.
This method only calls the addExtension
method of the X509Extensions
class for
putting the given extension into the proper hashtable. Note that only the DER
encoded extension value is written to the hashtable using the OID of the extension
as key. If an extension with the same object ID already exists, it is replaced.
For instance:
BasicConstraints bc = new BasicConstraints(true, 1); bc.setCritical(true); cert.addExtension(bc);
For reading back some extension from one of the hashtables, use the
getExtension(ObjectID)
method. Only at this time actually the appropriate implementation class is
created and initialized through the DER encoded extension value derived from
the corresponding hashtable.
e
- the X509v3 extension to add to the list of extensionsX509ExtensionException
- if an error occurs while DER encoding the extensionV3Extension
,
getBasicConstraints()
public boolean removeExtension(ObjectID oid)
objectID
- the object ID of the extension to removetrue
if the extension has been successfully removed,
false
otherwisepublic void removeAllExtensions()
public Enumeration listExtensions()
The returned enumeration may contain unknown extensions (instances of
UnknownExtension
if there are any extensions included in this certificate, for which there
exists no registered implementation, and it may contain error extensions
(instances of ErrorExtension
) indicating extensions which cannot be
parsed properly because of some kind of error.
Notice that this method only calls the
listExtensions()
method of the
X509Extensions
class for actually instantiating implementations for the included extensions and
initializing them with the appertaining extension values previously written to
proper hashtables. If any extension cannot be parsed properly, an ErrorExtension
is created from it and written
to the enumeration list returned by this method.
null
if there are no
extensions present at allpublic boolean hasExtensions()
true
if there are extensions, false
if notpublic boolean hasUnsupportedCriticalExtension()
hasUnsupportedCriticalExtension
in class X509Certificate
public int countExtensions()
public V3Extension getExtension(ObjectID oid) throws X509ExtensionInitException
This method only calls the getExtension(ObjectID)
method of the X509Extensions
class for actually instantiating an implementation
for the requested extension and initializing it with the appertaining extension
value previously written to a proper hashtable. If the extension cannot be initialized
for some reason, an X509ExtensionInitException is thrown. If the requested extension is
an unknown extension, which is not supported by a registered implementation,
this method creates and returns an UnknownExtension
which may be queried for obtaining as much information
as possible about the unknown extension.
objectID
- the object ID of the extensionnull
if the requested
extension is not presentX509ExtensionInitException
- if the extension can not be initializedX509Extensions.getExtension(iaik.asn1.ObjectID)
public String toString(boolean detailed)
detailed
- whether or not to give detailed information about the certificate.
|
This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |