public class C509Certificate
extends java.lang.Object
C509Certificate = [ TBSCertificate, issuerSignatureValue: any ]where the ten elements of the TBSCertificate group are inlined into the array, and for a natively signed certificate the signature is computed over their encoding as a CBOR sequence (RFC 8742).
Two certificate types are supported: natively signed C509 certificates
(TYPE_NATIVE), where the signature covers the CBOR itself, and CBOR
re-encoded X.509 v3 DER certificates (TYPE_REENCODED_X509), where the
signature is copied from the DER encoding and remains verifiable only over the
reconstructed DER, available from toX509Certificate().
All fields are validated and their X.509 views materialized at parse time, and only
deterministically encoded input in the forms this class itself produces is
accepted, so for every accepted encoding getInstance(enc).getEncoded() is
byte identical to enc. Conversion from X.509 with
fromX509Certificate(Certificate, C509ConversionOptions) is gated on exact
invertibility: if re-encoding the resulting C509 certificate does not reproduce the
input DER byte for byte, the conversion is refused rather than allowed to produce a
certificate whose signature could never verify.
| Modifier and Type | Field and Description |
|---|---|
static long |
NO_EXPIRATION_DATE
The validityNotAfter value standing for the GeneralizedTime 99991231235959Z,
"no well-defined expiration date" (RFC 5280 Section 4.1.2.5), carried in C509 as
the CBOR simple value null.
|
static int |
TYPE_NATIVE
Natively signed C509 certificate (c509CertificateType = 2).
|
static int |
TYPE_REENCODED_X509
CBOR re-encoded X.509 v3 DER certificate (c509CertificateType = 3).
|
| Modifier and Type | Method and Description |
|---|---|
static C509Certificate |
create(byte[] tbsCertificate,
byte[] signature)
Assemble a certificate from an encoded TBSCertificate (see
createTBSCertificate(int, java.math.BigInteger, org.bouncycastle.asn1.x509.AlgorithmIdentifier, org.bouncycastle.asn1.x500.X500Name, java.util.Date, java.util.Date, org.bouncycastle.asn1.x500.X500Name, org.bouncycastle.asn1.x509.SubjectPublicKeyInfo, org.bouncycastle.asn1.x509.Extensions, org.bouncycastle.cbor.c509.C509ConversionOptions)) and the newly created signature over it. |
static C509Certificate |
create(byte[] tbsCertificate,
byte[] signature,
C509ConversionOptions options)
Assemble a certificate from an encoded TBSCertificate and the newly created
signature over it, with the options controlling the ECDSA signature component
width.
|
static byte[] |
createTBSCertificate(int certificateType,
java.math.BigInteger serialNumber,
org.bouncycastle.asn1.x509.AlgorithmIdentifier issuerSignatureAlgorithm,
org.bouncycastle.asn1.x500.X500Name issuer,
java.util.Date notBefore,
java.util.Date notAfter,
org.bouncycastle.asn1.x500.X500Name subject,
org.bouncycastle.asn1.x509.SubjectPublicKeyInfo subjectPublicKeyInfo,
org.bouncycastle.asn1.x509.Extensions extensions,
C509ConversionOptions options)
Encode the TBSCertificate group for a certificate about to be signed.
|
boolean |
equals(java.lang.Object o) |
static C509Certificate |
fromX509Certificate(byte[] derEncoding)
Convert a DER-encoded X.509 v3 certificate to a CBOR re-encoded C509
certificate (type 3) using the default conversion options.
|
static C509Certificate |
fromX509Certificate(org.bouncycastle.asn1.x509.Certificate x509Certificate,
C509ConversionOptions options)
Convert a DER-encoded X.509 v3 certificate to a CBOR re-encoded C509
certificate (type 3).
|
int |
getCertificateType()
Return the certificate type (
TYPE_NATIVE or TYPE_REENCODED_X509). |
byte[] |
getEncoded()
Return the complete CBOR encoding of this certificate.
|
C509Extensions |
getExtensions()
Return the extensions.
|
static C509Certificate |
getInstance(byte[] encoding)
Parse a C509 certificate from its CBOR encoding.
|
org.bouncycastle.asn1.x500.X500Name |
getIssuer()
Return the issuer name.
|
C509AlgorithmIdentifier |
getIssuerSignatureAlgorithm()
Return the issuer signature algorithm.
|
long |
getNotAfter()
Return the end of validity, in POSIX seconds;
NO_EXPIRATION_DATE
stands for no well-defined expiration date. |
long |
getNotBefore()
Return the start of validity, in POSIX seconds.
|
java.math.BigInteger |
getSerialNumber()
Return the certificate serial number.
|
byte[] |
getSignature()
Return the signature value in its X.509 form: for an ECDSA style algorithm the
DER SEQUENCE of the two INTEGERs, for an RFC 6955 proof-of-possession algorithm
the DER DhSigStatic, otherwise the BIT STRING value field unchanged.
|
org.bouncycastle.asn1.x500.X500Name |
getSubject()
Return the subject name.
|
C509AlgorithmIdentifier |
getSubjectPublicKeyAlgorithm()
Return the subject public key algorithm.
|
org.bouncycastle.asn1.x509.SubjectPublicKeyInfo |
getSubjectPublicKeyInfo()
Return the subject public key.
|
byte[] |
getTBSCertificateEncoded()
Return the encoding of the TBSCertificate group as a CBOR sequence - for a
natively signed certificate, the exact bytes the signature covers.
|
int |
hashCode() |
boolean |
isSelfIssued()
Return true if the issuer field is carried as null, standing for an issuer
octet-for-octet identical to the subject (Section 3.1.4).
|
static java.util.Date |
toDate(long seconds)
Convert a C509 validity value in POSIX seconds, as returned by
getNotBefore() and getNotAfter(), to a Date. |
org.bouncycastle.asn1.x509.Certificate |
toX509Certificate()
Reconstruct the X.509 certificate a CBOR re-encoded C509 certificate stands
for.
|
public static final int TYPE_NATIVE
public static final int TYPE_REENCODED_X509
public static final long NO_EXPIRATION_DATE
public static C509Certificate getInstance(byte[] encoding) throws java.io.IOException
java.io.IOExceptionpublic static C509Certificate create(byte[] tbsCertificate, byte[] signature) throws java.io.IOException
createTBSCertificate(int, java.math.BigInteger, org.bouncycastle.asn1.x509.AlgorithmIdentifier, org.bouncycastle.asn1.x500.X500Name, java.util.Date, java.util.Date, org.bouncycastle.asn1.x500.X500Name, org.bouncycastle.asn1.x509.SubjectPublicKeyInfo, org.bouncycastle.asn1.x509.Extensions, org.bouncycastle.cbor.c509.C509ConversionOptions)) and the newly created signature over it.tbsCertificate - the encoding of the TBSCertificate CBOR sequence.signature - the signature value in its X.509 form (for ECDSA the DER
SEQUENCE of the two INTEGERs, as produced by a ContentSigner).java.io.IOExceptionpublic static C509Certificate create(byte[] tbsCertificate, byte[] signature, C509ConversionOptions options) throws java.io.IOException
java.io.IOExceptionpublic static java.util.Date toDate(long seconds)
getNotBefore() and getNotAfter(), to a Date.seconds - a validity value in POSIX seconds.java.lang.IllegalArgumentException - if the value lies outside the X.509 time domain,
which the validity values of a parsed or generated certificate cannot.public static byte[] createTBSCertificate(int certificateType,
java.math.BigInteger serialNumber,
org.bouncycastle.asn1.x509.AlgorithmIdentifier issuerSignatureAlgorithm,
org.bouncycastle.asn1.x500.X500Name issuer,
java.util.Date notBefore,
java.util.Date notAfter,
org.bouncycastle.asn1.x500.X500Name subject,
org.bouncycastle.asn1.x509.SubjectPublicKeyInfo subjectPublicKeyInfo,
org.bouncycastle.asn1.x509.Extensions extensions,
C509ConversionOptions options)
throws java.io.IOException
certificateType - TYPE_NATIVE or TYPE_REENCODED_X509.serialNumber - the certificate serial number, which must not be negative.issuerSignatureAlgorithm - the X.509 signature algorithm.issuer - the issuer name, or null when identical to the subject. An issuer is
carried as null only when its DER encoding is identical to the subject's.notBefore - start of validity.notAfter - end of validity, null standing for no well-defined expiration.subject - the subject name.subjectPublicKeyInfo - the subject public key.extensions - the certificate extensions, or null for none.java.io.IOExceptionpublic static C509Certificate fromX509Certificate(byte[] derEncoding) throws java.io.IOException
java.io.IOExceptionpublic static C509Certificate fromX509Certificate(org.bouncycastle.asn1.x509.Certificate x509Certificate, C509ConversionOptions options) throws java.io.IOException
The conversion is gated on exact invertibility: after converting, the X.509 certificate is reconstructed and compared byte for byte with the input, and any difference (a certificate that is not DER, or uses a construct the C509 profile cannot carry, such as a multi-valued RDN) fails the conversion with an IOException rather than producing a certificate whose copied signature could never verify.
java.io.IOExceptionpublic org.bouncycastle.asn1.x509.Certificate toX509Certificate()
java.lang.IllegalStateException - if this is a natively signed certificate - its
signature only covers the CBOR encoding, so no verifiable X.509 view of
it exists.public byte[] getEncoded()
throws java.io.IOException
java.io.IOExceptionpublic byte[] getTBSCertificateEncoded()
throws java.io.IOException
java.io.IOExceptionpublic int getCertificateType()
TYPE_NATIVE or TYPE_REENCODED_X509).public java.math.BigInteger getSerialNumber()
public C509AlgorithmIdentifier getIssuerSignatureAlgorithm()
public org.bouncycastle.asn1.x500.X500Name getIssuer()
public boolean isSelfIssued()
public long getNotBefore()
public long getNotAfter()
NO_EXPIRATION_DATE
stands for no well-defined expiration date.public org.bouncycastle.asn1.x500.X500Name getSubject()
public C509AlgorithmIdentifier getSubjectPublicKeyAlgorithm()
public org.bouncycastle.asn1.x509.SubjectPublicKeyInfo getSubjectPublicKeyInfo()
public C509Extensions getExtensions()
public byte[] getSignature()
public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object