Class BcPkixProvider
- All Implemented Interfaces:
PkixProvider
PkixProvider, implemented with BouncyCastle. This is the
single place in the codebase that a concrete cryptographic toolkit is used for
X.509/PKIX operations; it is confined to the lib module and reached only
through Pkix.-
Constructor Summary
ConstructorsConstructorDescriptionCreates the provider, ensuring the BouncyCastle security providers are registered. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]assembleCertificateOrCrl(byte[] tbs, byte[] signature, boolean crl) Reassembles a signed certificate or CRL from itstbsbytes and a raw signature, repeating the algorithm identifier embedded in thetbsas the outersignatureAlgorithm, and validates that the result parses.byte[]assembleOcspResponse(byte[] tbsResponseData, byte[] signatureAlgorithmDer, byte[] signature) Reassembles a successfulOCSPResponsewrapping aBasicOCSPResponsefrom itstbsResponseData, a DER-encoded signature algorithm identifier, and a raw signature, and validates that the result parses as successful.byte[]assembleOcspResponse(byte[] tbsResponseData, byte[] signatureAlgorithmDer, byte[] signature, List<X509Certificate> chain) Reassembles a successful OCSP response from unsignedResponseData, an encoded signature algorithm, a raw signature and an ordered certificate chain.buildPreCertificate(byte[] tbsCertificateDer, List<byte[]> issuerChainDer, ContentSigner signer) Builds a CT pre-certificate from an existingTBSCertificateby adding the CT poison extension (OID1.3.6.1.4.1.11129.2.4.3) and signing with the supplied signer.byte[]buildServerKeygenCsr(byte[] originalCsrDer, PublicKey generatedPublicKey, PrivateKey generatedPrivateKey) Builds a new DER-encoded PKCS#10 CSR using the supplied generated key pair, copying the subject DN and all attributes from the original CSR.byte[]buildSubjectPublicKeyInfo(AlgorithmIdentifier algorithm, byte[] publicKeyBits) Builds the DER of aSubjectPublicKeyInfofrom an algorithm identifier and the raw public-keyBIT STRINGcontents.Creates a new certificate builder.Creates a new certification-request builder.computeCertId(X509Certificate issuer, BigInteger serialNumber, String digestAlgorithmOid) Computes an OCSPCertIdfor a certificate under a given issuer.Creates a new CRL builder.distinguishedName(List<RelativeDistinguishedName> relativeNames) Builds a byte-exact distinguished name from typed relative distinguished names.distinguishedNameString(List<RelativeDistinguishedName> relativeNames) Renders a distinguished name, built from typed relative distinguished names, as its canonical string form (attribute short names, most-significant first).byte[]embedScts(byte[] tbsCertificateDer, List<SignedCertificateTimestamp> scts) Embeds a list of SCTs into aTBSCertificateas the SCT list extension (OID1.3.6.1.4.1.11129.2.4.2), producing a modifiedTBSCertificateDER ready for final signing.byte[]encodeAlgorithmIdentifier(AlgorithmIdentifier algorithm) Returns the DER encoding of an X.509AlgorithmIdentifier.byte[]encodeCertsOnly(List<X509Certificate> chain) Encodes a list of X.509 certificates as a CMS certs-only message (SignedDatawith no signers, only the certificate bag).byte[]encodeCsrAttrs(List<CsrAttribute> attributes) Encodes a list of CSR attributes as an RFC 7030CsrAttrsstructure (DER-encoded ASN.1 sequence of OIDs and optional attribute values).byte[]encryptPrivateKeyForRecipient(byte[] pkcs8PrivateKeyDer, X509Certificate recipientCertificate) Encrypts a PKCS#8 private key for a single recipient using CMSEnvelopedDatawith AES-256-GCM content encryption.id()Returns the stable provider identifier (for diagnostics and selection).Creates a new OCSP response builder.parseAlgorithmIdentifier(byte[] der) Parses a DER-encoded X.509AlgorithmIdentifier.parseCertificate(byte[] der) Parses a DER-encoded X.509 certificate.parseCertificationRequest(byte[] der) Parses a DER-encoded PKCS#10 certification request.parseCrl(byte[] der) Parses a DER-encoded X.509 CRL.parseDistinguishedName(byte[] nameDer) Parses a DER-encoded X.500Nameinto its ordered, single-valued relative distinguished names, preserving the ASN.1 string type of each value.Parses a distinguished-name string (as produced byPkixProvider.distinguishedNameString(java.util.List)) into its ordered, single-valued relative distinguished names, preserving the written order.parseExtensions(byte[] der) Parses a DER-encoded X.509Extensionssequence into typed extensions.parseGeneralNames(byte[] der) Parses a DER-encodedGeneralNamessequence into typed general names.parseOcspRequest(byte[] der) Parses a DER-encoded OCSP request.parseOcspResponse(byte[] der) Parses a DER-encoded OCSP response.parseSct(byte[] jsonResponseBody) Parses a Signed Certificate Timestamp from the JSON response body returned by a CT log'sadd-pre-chainoradd-chainendpoint.publicKeyFromSubjectPublicKeyInfo(byte[] subjectPublicKeyInfoDer) Recovers a public key from a DER-encodedSubjectPublicKeyInfo.signer(PrivateKey privateKey, AlgorithmIdentifier algorithm) Creates a content signer over a local private key.byte[]subjectKeyIdentifier(PublicKey publicKey) Computes the standard subject key identifier (SHA-1 of the SPKI) for a key.subjectPublicKeyAlgorithm(byte[] subjectPublicKeyInfoDer) Extracts the algorithm identifier from a DER-encodedSubjectPublicKeyInfo.byte[]subjectPublicKeyBytes(byte[] subjectPublicKeyInfoDer) Returns the raw contents of the public-keyBIT STRINGof a DER-encodedSubjectPublicKeyInfo(the bytes after the unused-bits octet).byte[]subjectPublicKeyInfo(X509Certificate certificate) Returns the exact DER of theSubjectPublicKeyInfoembedded in a certificate, byte-for-byte as encoded in the certificate.verifier(byte[] subjectPublicKeyInfoDer, AlgorithmIdentifier algorithm) Creates a content verifier over a DER-encodedSubjectPublicKeyInfoand a signature algorithm identifier, honouring any algorithm parameters (such as RSASSA-PSS parameters) carried by the identifier.verifier(PublicKey publicKey, AlgorithmIdentifier algorithm) Creates a content verifier over a public key.booleanverifyAlternativeSignature(X509Certificate certificate, PublicKey issuerAlternativeKey) Verifies only the standardized alternative signature using an explicit issuer alternative key.booleanverifySct(SignedCertificateTimestamp sct, PublicKey ctLogPublicKey, byte[] preCertDer) Verifies an SCT's digital signature against a known CT log public key.
-
Constructor Details
-
BcPkixProvider
public BcPkixProvider()Creates the provider, ensuring the BouncyCastle security providers are registered.
-
-
Method Details
-
verifyAlternativeSignature
public boolean verifyAlternativeSignature(X509Certificate certificate, PublicKey issuerAlternativeKey) Description copied from interface:PkixProviderVerifies only the standardized alternative signature using an explicit issuer alternative key. Missing or malformed alternative extensions fail closed. This operation performs no path, time or primary-signature checks.- Specified by:
verifyAlternativeSignaturein interfacePkixProvider- Parameters:
certificate- nonnull certificate with all three alternative extensionsissuerAlternativeKey- nonnull trusted issuer alternative public key- Returns:
- whether the alternative signature is valid
-
id
Description copied from interface:PkixProviderReturns the stable provider identifier (for diagnostics and selection).- Specified by:
idin interfacePkixProvider- Returns:
- the provider id
-
certificateBuilder
Description copied from interface:PkixProviderCreates a new certificate builder.- Specified by:
certificateBuilderin interfacePkixProvider- Returns:
- a fresh certificate builder
-
parseCertificate
Description copied from interface:PkixProviderParses a DER-encoded X.509 certificate.- Specified by:
parseCertificatein interfacePkixProvider- Parameters:
der- the certificate DER- Returns:
- the parsed certificate
-
certificationRequestBuilder
Description copied from interface:PkixProviderCreates a new certification-request builder.- Specified by:
certificationRequestBuilderin interfacePkixProvider- Returns:
- a fresh CSR builder
-
parseCertificationRequest
Description copied from interface:PkixProviderParses a DER-encoded PKCS#10 certification request.- Specified by:
parseCertificationRequestin interfacePkixProvider- Parameters:
der- the request DER- Returns:
- the parsed request
-
crlBuilder
Description copied from interface:PkixProviderCreates a new CRL builder.- Specified by:
crlBuilderin interfacePkixProvider- Returns:
- a fresh CRL builder
-
parseCrl
Description copied from interface:PkixProviderParses a DER-encoded X.509 CRL.- Specified by:
parseCrlin interfacePkixProvider- Parameters:
der- the CRL DER- Returns:
- the parsed CRL
-
ocspResponseBuilder
Description copied from interface:PkixProviderCreates a new OCSP response builder.- Specified by:
ocspResponseBuilderin interfacePkixProvider- Returns:
- a fresh OCSP response builder
-
parseOcspRequest
Description copied from interface:PkixProviderParses a DER-encoded OCSP request.- Specified by:
parseOcspRequestin interfacePkixProvider- Parameters:
der- the request DER- Returns:
- the parsed request
-
signer
Description copied from interface:PkixProviderCreates a content signer over a local private key.- Specified by:
signerin interfacePkixProvider- Parameters:
privateKey- the signing private keyalgorithm- the signature algorithm identifier- Returns:
- a content signer
-
verifier
Description copied from interface:PkixProviderCreates a content verifier over a public key.- Specified by:
verifierin interfacePkixProvider- Parameters:
publicKey- the verifying public keyalgorithm- the signature algorithm identifier- Returns:
- a content verifier
-
verifier
Description copied from interface:PkixProviderCreates a content verifier over a DER-encodedSubjectPublicKeyInfoand a signature algorithm identifier, honouring any algorithm parameters (such as RSASSA-PSS parameters) carried by the identifier.- Specified by:
verifierin interfacePkixProvider- Parameters:
subjectPublicKeyInfoDer- the SPKI DER of the verifying keyalgorithm- the signature algorithm identifier- Returns:
- a content verifier
-
subjectKeyIdentifier
Description copied from interface:PkixProviderComputes the standard subject key identifier (SHA-1 of the SPKI) for a key.- Specified by:
subjectKeyIdentifierin interfacePkixProvider- Parameters:
publicKey- the public key- Returns:
- the subject key identifier bytes
-
computeCertId
public CertId computeCertId(X509Certificate issuer, BigInteger serialNumber, String digestAlgorithmOid) Description copied from interface:PkixProviderComputes an OCSPCertIdfor a certificate under a given issuer.- Specified by:
computeCertIdin interfacePkixProvider- Parameters:
issuer- the issuer certificateserialNumber- the subject certificate serial numberdigestAlgorithmOid- the digest algorithm OID for the hashes- Returns:
- the computed cert id
-
distinguishedName
Description copied from interface:PkixProviderBuilds a byte-exact distinguished name from typed relative distinguished names.- Specified by:
distinguishedNamein interfacePkixProvider- Parameters:
relativeNames- the ordered relative distinguished names- Returns:
- the distinguished name
-
distinguishedNameString
Description copied from interface:PkixProviderRenders a distinguished name, built from typed relative distinguished names, as its canonical string form (attribute short names, most-significant first).- Specified by:
distinguishedNameStringin interfacePkixProvider- Parameters:
relativeNames- the ordered relative distinguished names- Returns:
- the string form of the distinguished name
-
parseAlgorithmIdentifier
Description copied from interface:PkixProviderParses a DER-encoded X.509AlgorithmIdentifier.- Specified by:
parseAlgorithmIdentifierin interfacePkixProvider- Parameters:
der- the algorithm-identifier DER- Returns:
- the parsed algorithm identifier
-
subjectPublicKeyAlgorithm
Description copied from interface:PkixProviderExtracts the algorithm identifier from a DER-encodedSubjectPublicKeyInfo.- Specified by:
subjectPublicKeyAlgorithmin interfacePkixProvider- Parameters:
subjectPublicKeyInfoDer- the SPKI DER- Returns:
- the subject public key algorithm identifier
-
publicKeyFromSubjectPublicKeyInfo
Description copied from interface:PkixProviderRecovers a public key from a DER-encodedSubjectPublicKeyInfo.- Specified by:
publicKeyFromSubjectPublicKeyInfoin interfacePkixProvider- Parameters:
subjectPublicKeyInfoDer- the SPKI DER- Returns:
- the public key
-
parseOcspResponse
Description copied from interface:PkixProviderParses a DER-encoded OCSP response.- Specified by:
parseOcspResponsein interfacePkixProvider- Parameters:
der- the response DER- Returns:
- the parsed response
-
parseDistinguishedName
Description copied from interface:PkixProviderParses a DER-encoded X.500Nameinto its ordered, single-valued relative distinguished names, preserving the ASN.1 string type of each value.- Specified by:
parseDistinguishedNamein interfacePkixProvider- Parameters:
nameDer- the DER encoding of an X.500Name- Returns:
- the ordered relative distinguished names
-
parseDistinguishedNameString
Description copied from interface:PkixProviderParses a distinguished-name string (as produced byPkixProvider.distinguishedNameString(java.util.List)) into its ordered, single-valued relative distinguished names, preserving the written order.- Specified by:
parseDistinguishedNameStringin interfacePkixProvider- Parameters:
name- the distinguished-name string- Returns:
- the ordered relative distinguished names
-
subjectPublicKeyBytes
public byte[] subjectPublicKeyBytes(byte[] subjectPublicKeyInfoDer) Description copied from interface:PkixProviderReturns the raw contents of the public-keyBIT STRINGof a DER-encodedSubjectPublicKeyInfo(the bytes after the unused-bits octet).- Specified by:
subjectPublicKeyBytesin interfacePkixProvider- Parameters:
subjectPublicKeyInfoDer- the SPKI DER- Returns:
- the public-key bit-string content bytes
-
subjectPublicKeyInfo
Description copied from interface:PkixProviderReturns the exact DER of theSubjectPublicKeyInfoembedded in a certificate, byte-for-byte as encoded in the certificate.- Specified by:
subjectPublicKeyInfoin interfacePkixProvider- Parameters:
certificate- the certificate- Returns:
- the exact SPKI DER
-
buildSubjectPublicKeyInfo
Description copied from interface:PkixProviderBuilds the DER of aSubjectPublicKeyInfofrom an algorithm identifier and the raw public-keyBIT STRINGcontents.- Specified by:
buildSubjectPublicKeyInfoin interfacePkixProvider- Parameters:
algorithm- the subject public-key algorithm identifierpublicKeyBits- the raw public-key bit-string content bytes- Returns:
- the SPKI DER
-
parseExtensions
Description copied from interface:PkixProviderParses a DER-encoded X.509Extensionssequence into typed extensions.- Specified by:
parseExtensionsin interfacePkixProvider- Parameters:
der- the DER of anExtensionssequence- Returns:
- the parsed extensions in order
-
assembleCertificateOrCrl
public byte[] assembleCertificateOrCrl(byte[] tbs, byte[] signature, boolean crl) Description copied from interface:PkixProviderReassembles a signed certificate or CRL from itstbsbytes and a raw signature, repeating the algorithm identifier embedded in thetbsas the outersignatureAlgorithm, and validates that the result parses.- Specified by:
assembleCertificateOrCrlin interfacePkixProvider- Parameters:
tbs- thetbsCertificateortbsCertListDERsignature- the raw signature bytescrl-truefor a CRL,falsefor a certificate- Returns:
- the DER of the assembled signed object
-
assembleOcspResponse
public byte[] assembleOcspResponse(byte[] tbsResponseData, byte[] signatureAlgorithmDer, byte[] signature) Description copied from interface:PkixProviderReassembles a successfulOCSPResponsewrapping aBasicOCSPResponsefrom itstbsResponseData, a DER-encoded signature algorithm identifier, and a raw signature, and validates that the result parses as successful.- Specified by:
assembleOcspResponsein interfacePkixProvider- Parameters:
tbsResponseData- thetbsResponseDataDERsignatureAlgorithmDer- the DER of the signatureAlgorithmIdentifiersignature- the raw signature bytes- Returns:
- the DER of the assembled OCSP response
-
assembleOcspResponse
public byte[] assembleOcspResponse(byte[] tbsResponseData, byte[] signatureAlgorithmDer, byte[] signature, List<X509Certificate> chain) Description copied from interface:PkixProviderReassembles a successful OCSP response from unsignedResponseData, an encoded signature algorithm, a raw signature and an ordered certificate chain. Certificates are embedded in the supplied order without sorting or trust validation. An empty chain omits the optionalcertsfield, matching the three-argument overload. No signer is invoked and the raw signature is not cryptographically verified by assembly.Inputs remain caller-owned and are not retained. The returned DER array is independent. Time and auxiliary memory are linear in response-data, algorithm, signature and total embedded-certificate bytes. No aggregate live-response size limit is introduced.
- Specified by:
assembleOcspResponsein interfacePkixProvider- Parameters:
tbsResponseData- nonnull DER-encoded unsignedResponseDatasignatureAlgorithmDer- nonnull DER-encoded signatureAlgorithmIdentifiersignature- nonnull raw signature byteschain- nonnull certificate list in exact embedding order, with no null elements- Returns:
- freshly encoded successful OCSP response DER
-
encodeAlgorithmIdentifier
Description copied from interface:PkixProviderReturns the DER encoding of an X.509AlgorithmIdentifier.- Specified by:
encodeAlgorithmIdentifierin interfacePkixProvider- Parameters:
algorithm- the algorithm identifier- Returns:
- the DER encoding
-
parseGeneralNames
Description copied from interface:PkixProviderParses a DER-encodedGeneralNamessequence into typed general names.- Specified by:
parseGeneralNamesin interfacePkixProvider- Parameters:
der- the DER of aGeneralNamessequence- Returns:
- the parsed general names in order
-
encodeCertsOnly
Description copied from interface:PkixProviderEncodes a list of X.509 certificates as a CMS certs-only message (SignedDatawith no signers, only the certificate bag).The returned bytes are the DER-encoded
ContentInfowrapping theSignedData. The encoding is suitable for use as the body of an EST/cacertsor/simpleenrollresponse.- Specified by:
encodeCertsOnlyin interfacePkixProvider- Parameters:
chain- ordered certificate list; must not be null or empty- Returns:
- DER-encoded CMS certs-only
ContentInfo
-
encodeCsrAttrs
Description copied from interface:PkixProviderEncodes a list of CSR attributes as an RFC 7030CsrAttrsstructure (DER-encoded ASN.1 sequence of OIDs and optional attribute values).- Specified by:
encodeCsrAttrsin interfacePkixProvider- Parameters:
attributes- the CSR attributes to encode; must not be null- Returns:
- DER-encoded
CsrAttrssequence
-
buildServerKeygenCsr
public byte[] buildServerKeygenCsr(byte[] originalCsrDer, PublicKey generatedPublicKey, PrivateKey generatedPrivateKey) Builds a new DER-encoded PKCS#10 CSR using the supplied generated key pair, copying the subject DN and all attributes from the original CSR.The self-signature over the rebuilt CSR uses SHA-256withECDSA for EC keys and SHA-256withRSA for RSA keys, determined from the generated private key type.
- Specified by:
buildServerKeygenCsrin interfacePkixProvider- Parameters:
originalCsrDer- DER-encoded original PKCS#10 CSR (source of subject and attributes)generatedPublicKey- server-generated public key to embedgeneratedPrivateKey- server-generated private key used to self-sign- Returns:
- DER-encoded PKCS#10 CSR signed with the generated key
- Throws:
UnsupportedRoleException- if the private key uses LMS/XMSS; rejection precedes CSR parsing and signing-engine initialization
-
encryptPrivateKeyForRecipient
public byte[] encryptPrivateKeyForRecipient(byte[] pkcs8PrivateKeyDer, X509Certificate recipientCertificate) Description copied from interface:PkixProviderEncrypts a PKCS#8 private key for a single recipient using CMSEnvelopedDatawith AES-256-GCM content encryption.The recipient is identified by the public key in the supplied certificate. The key is wrapped using RSA-OAEP (for RSA keys) or ECDH-KDF (for EC keys) depending on the recipient certificate's public key algorithm.
- Specified by:
encryptPrivateKeyForRecipientin interfacePkixProvider- Parameters:
pkcs8PrivateKeyDer- DER-encoded PKCS#8 private key to encryptrecipientCertificate- the recipient's certificate (public key used for wrap)- Returns:
- DER-encoded CMS
ContentInfowrapping theEnvelopedData
-
buildPreCertificate
public PreCertificateResult buildPreCertificate(byte[] tbsCertificateDer, List<byte[]> issuerChainDer, ContentSigner signer) Description copied from interface:PkixProviderBuilds a CT pre-certificate from an existingTBSCertificateby adding the CT poison extension (OID1.3.6.1.4.1.11129.2.4.3) and signing with the supplied signer.The pre-certificate is submitted to CT logs; logs return SCTs that are later embedded in the final certificate via
PkixProvider.embedScts(byte[], List).- Specified by:
buildPreCertificatein interfacePkixProvider- Parameters:
tbsCertificateDer- DER-encodedTBSCertificatewithout the poison extensionissuerChainDer- DER-encoded issuer chain (issuer first, root last)signer- configured signer for the issuing CA key- Returns:
- pre-certificate DER and its chain, ready for CT log submission
-
embedScts
Description copied from interface:PkixProviderEmbeds a list of SCTs into aTBSCertificateas the SCT list extension (OID1.3.6.1.4.1.11129.2.4.2), producing a modifiedTBSCertificateDER ready for final signing.If the
TBSCertificatealready carries a poison extension (OID1.3.6.1.4.1.11129.2.4.3), it is replaced by the SCT list extension. Any pre-existing SCT list extension is also replaced.- Specified by:
embedSctsin interfacePkixProvider- Parameters:
tbsCertificateDer- DER-encodedTBSCertificatescts- verified SCTs to embed; must contain at least one entry- Returns:
- modified DER-encoded
TBSCertificatewith the SCT list extension
-
parseSct
Description copied from interface:PkixProviderParses a Signed Certificate Timestamp from the JSON response body returned by a CT log'sadd-pre-chainoradd-chainendpoint.Expected JSON fields:
sct_version,id(base64 log ID),timestamp(epoch milliseconds),extensions(base64, may be empty),signature(base64-encoded TLSDigitallySignedstructure).- Specified by:
parseSctin interfacePkixProvider- Parameters:
jsonResponseBody- raw response body bytes; must not benull- Returns:
- the parsed SCT
-
verifySct
public boolean verifySct(SignedCertificateTimestamp sct, PublicKey ctLogPublicKey, byte[] preCertDer) Description copied from interface:PkixProviderVerifies an SCT's digital signature against a known CT log public key.The signed data covers the SCT fields (version, log ID, timestamp, extensions) concatenated with a SHA-256 hash of the pre-certificate DER, as a simplified verification approach. Returns
falseif the signature is invalid; throws only on algorithmic or key errors.- Specified by:
verifySctin interfacePkixProvider- Parameters:
sct- the SCT to verify; must not benullctLogPublicKey- EC or RSA public key of the CT log; must not benullpreCertDer- DER-encoded pre-certificate that was submitted; must not benull- Returns:
trueif the signature is valid
-