|
|||||||||
| 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
|
+--codec.x509.X509Certificate
Implements a X.509v3 certificate according to the following ASN.1 data structure:
Certificate ::= SEQUENCE {
tbsCertificate TBSCertificate,
signatureAlgorithm AlgorithmIdentifier,
signatureValue BIT STRING
}
If you want to create a certificate, follow these steps:
X509TBSCertificate object and fill
it with sensible data
X509Certificate(X509TBSCertificate) constructor and
pass the tbsCertificate as an argument
setSignature with a pre-computed
signature of the tbsCertificate
getEncoded() will return the DER-encoded
certificate as a Byte array.
Example:
PrivateKey CASigningKey = ...;
X509Certificate CASignatureCert = ...;
PublicKey subjectPublicKey = ...;
Name issuerDN = new Name("cn=My CA, c=DE");
Name subjectDN = new Name("cn=Myself, c=DE");
Calendar validFrom = ...;
Calendar validUntil = ...;
X509TBSCertificate tbs = new X509TBSCertificate();
tbs.setSerialNumber(new BigInteger("1"));
tbs.setSubjectPublicKey(subjectPublicKey);
tbs.setSubjectDN(subjectDN);
tbs.setIssuerDN(issuerDN);
tbs.setNotBefore(validFrom);
tbs.setNotAfter(validUntil);
X509Certificate theCert = new X509Certificate(tbs);
Signature mySig = Signature.getInstance(...);
mySig.initSign(CASigningKey);
theCert.sign(mySig, CASignatureCert);
| Inner classes inherited from class java.security.cert.Certificate |
Certificate.CertificateRep |
| Constructor Summary | |
X509Certificate()
Constructor that builds the data structure |
|
X509Certificate(byte[] cert)
Contructor upon a DER-encoded Byte-Array |
|
X509Certificate(InputStream in)
Constructor upon an InputStream |
|
X509Certificate(X509TBSCertificate tbs)
Constructor upon a TBSCertificate. |
|
| Method Summary | |
void |
addExtension(X509Extension ext)
Adds an extension to this certificate. |
void |
checkConstraints()
From interface ASN1Type |
void |
checkValidity()
From java.security.cert.X509Certificate. |
void |
checkValidity(Calendar now)
Checks the validity period of this certificate against the given Calendar instance. |
void |
checkValidity(Date date)
From java.security.cert.X509Certificate. |
void |
decode(Decoder dec)
From interface ASN1Type |
void |
encode(Encoder enc)
From interface ASN1Type |
int |
getBasicConstraints()
From java.security.cert.X509Certificate. |
Constraint |
getConstraint()
From interface ASN1Type |
Set |
getCriticalExtensionOIDs()
From java.security.cert.X509Extension. |
byte[] |
getEncoded()
returns the DER-encoded bytearray of this certificate |
Collection |
getExtensions()
Returns a Collection containing all extensions |
byte[] |
getExtensionValue(String ex)
From java.security.cert.X509Extension. |
Principal |
getIssuerDN()
From java.security.cert.X509Certificate. |
boolean[] |
getIssuerUniqueID()
From java.security.cert.X509Certificate. |
boolean[] |
getKeyUsage()
From java.security.cert.X509Certificate. |
Set |
getNonCriticalExtensionOIDs()
From java.security.cert.X509Extension. |
Date |
getNotAfter()
From java.security.cert.X509Certificate. |
Date |
getNotBefore()
From java.security.cert.X509Certificate. |
PublicKey |
getPublicKey()
From java.security.cert.X509Certificate. |
BigInteger |
getSerialNumber()
From java.security.cert.X509Certificate. |
String |
getSigAlgName()
From java.security.cert.X509Certificate. |
String |
getSigAlgOID()
From java.security.cert.X509Certificate. |
byte[] |
getSigAlgParams()
From java.security.cert.X509Certificate. |
byte[] |
getSignature()
From java.security.cert.X509Certificate. |
Principal |
getSubjectDN()
From java.security.cert.X509Certificate. |
boolean[] |
getSubjectUniqueID()
From java.security.cert.X509Certificate. |
int |
getTag()
From interface ASN1Type |
int |
getTagClass()
From interface ASN1Type |
byte[] |
getTBSCertificate()
From java.security.cert.X509Certificate. |
byte[] |
getTBSCertificate(AlgorithmIdentifier sigalg)
Returns the to-be-signed (TBS) part of this certificate, meaning the byte-array that initializes the signature algorithm. |
Object |
getValue()
From interface ASN1Type |
int |
getVersion()
Returns the version of this X509 certificate (0=v1, 1=v2, 2=v3) |
X509TBSCertificate |
getX509TBSCertificate()
Returns tbe TBSCertificate Block as an Object. |
boolean |
hasUnsupportedCriticalExtension()
From java.security.cert.X509Extension. |
boolean |
isExplicit()
From interface ASN1Type |
boolean |
isOptional()
From interface ASN1Type |
boolean |
isType(int eins,
int zwei)
From interface ASN1Type |
void |
readExternal(ObjectInput s)
|
void |
setConstraint(Constraint c)
From interface ASN1Type |
void |
setExplicit(boolean ex)
From interface ASN1Type |
void |
setOptional(boolean opt)
From interface ASN1Type |
void |
setSignature(byte[] nsig)
Sets the signature |
void |
setSignatureAlgorithm(AlgorithmIdentifier aid)
sets the signature algorithm |
void |
setTBSCertificate(X509TBSCertificate tbs)
Sets the TBS ("to-be-signed") part of this certificate. |
void |
sign(Signature sig,
PublicKey signerPub)
This methods implements an easy way to sign your certificate. |
void |
sign(Signature sig,
X509Certificate cert)
This methods implements an easy way to sign your certificate. |
String |
toString()
human-readable String representation of this certificate |
void |
verify(PublicKey key)
with this method, the certificate can be verified in an easy, but less secure way. |
void |
verify(PublicKey key,
String pro)
with this method, the certificate can be verified in an easy, but less secure way. |
void |
writeExternal(ObjectOutput s)
|
| 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()
public X509Certificate(byte[] cert)
throws CertificateEncodingException
public X509Certificate(InputStream in) throws CertificateEncodingException
public X509Certificate(X509TBSCertificate tbs)
| Method Detail |
public void setConstraint(Constraint c)
setConstraint in interface ASN1Typecodec.asn1.ASN1Typeo - The constraint to set.public Constraint getConstraint()
getConstraint in interface ASN1Typecodec.asn1.ASN1Typenull.public void addExtension(X509Extension ext)
ext - the Extension to be added
public void checkConstraints()
throws ConstraintException
checkConstraints in interface ASN1Typecodec.asn1.ASN1TypeConstraint,
ConstraintCollection
public void checkValidity()
throws CertificateExpiredException,
CertificateNotYetValidException
checkValidity in class X509Certificatepublic void checkValidity(Date date) throws CertificateExpiredException, CertificateNotYetValidException
checkValidity in class X509Certificatedate - Date to be checked against the validity period of this
certificateCertificateExpiredException - if the certificate has expiredCertificateNotYetValidException - if the certificate is not valid yet.public void checkValidity(Calendar now) throws CertificateExpiredException, CertificateNotYetValidException
now - Calendar to be checked against the validity period of this
certificateCertificateExpiredException - if the certificate has expiredCertificateNotYetValidException - if the certificate is not valid yet.public void decode(Decoder dec) throws ASN1Exception, IOException
public void encode(Encoder enc) throws ASN1Exception, IOException
public int getBasicConstraints()
BasicConstraints ::= SEQUENCE {
cA BOOLEAN DEFAULT FALSE,
pathLenConstraint INTEGER (0..MAX) OPTIONAL
}
getBasicConstraints in class X509Certificatepublic Set getCriticalExtensionOIDs()
getCriticalExtensionOIDs in class X509Certificate
public byte[] getEncoded()
throws CertificateEncodingException
getEncoded in class Certificatepublic Collection getExtensions()
public byte[] getExtensionValue(String ex)
getExtensionValue in class X509Certificatepublic Principal getIssuerDN()
getIssuerDN in class X509Certificatepublic boolean[] getIssuerUniqueID()
getIssuerUniqueID in class X509Certificatepublic boolean[] getKeyUsage()
KeyUsage ::= BIT STRING {
digitalSignature (0),
nonRepudiation (1),
keyEncipherment (2),
dataEncipherment (3),
keyAgreement (4),
keyCertSign (5),
cRLSign (6),
encipherOnly (7),
decipherOnly (8)
}
getKeyUsage in class X509Certificatepublic Set getNonCriticalExtensionOIDs()
getNonCriticalExtensionOIDs in class X509Certificatepublic Date getNotAfter()
getNotAfter in class X509Certificatepublic Date getNotBefore()
getNotBefore in class X509Certificatepublic PublicKey getPublicKey()
getPublicKey in class Certificatepublic BigInteger getSerialNumber()
getSerialNumber in class X509Certificatepublic String getSigAlgName()
getSigAlgName in class X509Certificatepublic String getSigAlgOID()
getSigAlgOID in class X509Certificatepublic byte[] getSigAlgParams()
getSigAlgParams in class X509Certificatepublic byte[] getSignature()
getSignature in class X509Certificatepublic Principal getSubjectDN()
getSubjectDN in class X509Certificatepublic boolean[] getSubjectUniqueID()
getSubjectUniqueID in class X509Certificatepublic int getTag()
public int getTagClass()
getTagClass in interface ASN1Type
public byte[] getTBSCertificate()
throws CertificateEncodingException
getX509TBSCertificate instead.getTBSCertificate in class X509Certificatepublic X509TBSCertificate getX509TBSCertificate()
getTBSCertificate instead.public byte[] getTBSCertificate(AlgorithmIdentifier sigalg) throws CertificateEncodingException
sigalg - AlgorithmID of the signature algorithm or null (verify)CertificateEncodingException - if TBSCertificate could not be encodedpublic Object getValue()
public int getVersion()
getVersion in class X509Certificatepublic boolean hasUnsupportedCriticalExtension()
Currently, this function will always return false since extensions are managed in an abstract way.
hasUnsupportedCriticalExtension in class X509Certificatepublic boolean isExplicit()
isExplicit in interface ASN1Typepublic boolean isOptional()
isOptional in interface ASN1Type
public boolean isType(int eins,
int zwei)
codec.asn1.ASN1Typetag - The tag to match.tagclass - The tag class to match.true if this type matches the given tag and tag
class.public void setExplicit(boolean ex)
setExplicit in interface ASN1Typepublic void setTBSCertificate(X509TBSCertificate tbs)
public void setOptional(boolean opt)
setOptional in interface ASN1Typepublic void setSignature(byte[] nsig)
public void setSignatureAlgorithm(AlgorithmIdentifier aid)
aid - AlgorithmID of the signature algorithmpublic String toString()
toString in class Certificatepublic void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException
getTBSCertificate() and
getSignature() should be used along with external
verification code.verify in class Certificatekey - the issuer's public key to verify the TBS certificatepublic void verify(PublicKey key, String pro) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException
getTBSCertificate() and
getSignature() should be used along with an
external verification.verify in class Certificatekey - the issuer's public key to verify the TBS certificatepro - Provider to be used for signature mechanismpublic void sign(Signature sig, PublicKey signerPub) throws SignatureException, CertificateEncodingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException
sig - a Signature engine that is initialized for signing with
the appropriate private keysignerPub - the signer's public keySignatureException - if the signature could not be doneCertificateEncodingException - if an error occured during tbsCertificate encodingNoSuchAlgorithmException - if the Public key or is not available signature algorithmInvalidAlgorithmParameterException - if signature algorithm parameters could not be encoded
correctlypublic void sign(Signature sig, X509Certificate cert) throws SignatureException, CertificateEncodingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException
sig - a Signature engine that is initialized for signing with
the appropriate private keycert - the signer's signature certificateSignatureException - if the signature could not be doneCertificateEncodingException - if an error occured during tbsCertificate encodingNoSuchAlgorithmException - if the Public key or is not available signature algorithmInvalidAlgorithmParameterException - if signature algorithm parameters could not be encoded
correctlypublic void writeExternal(ObjectOutput s) throws IOException
writeExternal in interface Externalizablepublic void readExternal(ObjectInput s) throws IOException
readExternal in interface Externalizable
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||