Skip to content

Commit fbd41e1

Browse files
Arpan0995dghgit
authored andcommitted
ITS: take the explicit certificate signature choice from the content signer's curve rather than the verification key indicator, incorporating github PR #2463.
1 parent 23f3b26 commit fbd41e1

4 files changed

Lines changed: 154 additions & 31 deletions

File tree

‎CONTRIBUTORS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ We also wish to acknowledge financial and collaborative support from [CISCO](htt
542542
- jmeeder \<https://github.com/jmeeder\> - reporting that RFC 4998 evidence-record generation rejected time stamps from an authority naming the digest with NULL parameters where BC names it with them absent, both of which RFC 5754 requires a receiver to accept (issue #2379).
543543
- rimuln \<https://github.com/rimuln\> - diagnosis and fix for PKCS12 getCertificateAlias returning the alias of an unrelated certificate, tracing it to the alias and certificate enumerations of the keystore's certs table diverging in order once keys() enumerated a copy (issue #2384, PR #2385).
544544
- Yu Bao \<yubao&#064;paypal.com\> - reporting an API gap, on behalf of the PayPal Cyber Security Team, that the high-level OpenPGP message API (OpenPGPMessageProcessor / OpenPGPMessageInputStream) gave a caller no way to bound how far a compressed data packet expands, where the low-level PGPCompressedData it wraps has carried a bounded getDataStream(long) overload all along, and that OpenPGPPolicy exposed no equivalent property to set. Suggesting a protocol whitelist for CRL Distribution Point fetching, which is now the org.bouncycastle.x509.CRLDP_protocols property, and suggesting that an OCSP response was read up to the length the responder declared for itself, now capped by org.bouncycastle.ocsp.max_response_size, and suggesting bounds on the OpenPGP ASCII armor headers, now capped by org.bouncycastle.openpgp.max_armor_header_length and org.bouncycastle.openpgp.max_armor_headers.
545-
- Arpan Sharma \<https://github.com/Arpan0995\> - initial audit of BCPQC provider consistency starting with HQC, which led to the exposure of a number of issues in the JCA provider service interfaces for other BCPQC algorithms. In-depth auditing of PQC signature algorithms in the provider leading to the correction of a number of JCA API compliance issues. Initial implementation of the guard that lets a signature context be set on the composite ML-DSA services before initSign / initVerify, the composite counterpart of the base-engine fix for issue #2396 (issue #2412). Audit of the LMS / HSS stateful private key decoder, establishing that the level count, the one-time index and the persisted tree cache were all accepted without validation (issue #2414); that issue was also the inspiration for the further investigation which found the HSS and XMSS^MT decoders accepting a private key whose declared index disagreed with the traversal state stored beside it, allowing a one-time key to be used twice. Audit of the high-level OpenPGP API (org.bouncycastle.openpgp, org.bouncycastle.openpgp.api) and the bcpg packet layer beneath it, spanning certificate evaluation, message verification, decryption and signature subpacket parsing, which found certificates being used without the certifications RFC 9580 requires of them, malformed but signed content reaching ordinary reader code as unchecked exceptions, a truncated message being read as a clean end of message, and unverified plaintext being released ahead of the integrity check (issues #2417, #2424, #2426). Audit of the recipient side of the CMS RFC 9629 KEMRecipientInfo path, which found three sender-controlled fields leaving methods declared to throw CMSException as unchecked exceptions and the kekLength never being confirmed against the wrap algorithm, and which led to the same translation being added to the neighbouring AuthEnvelopedData constructor and the two streaming parsers (issue #2422). Audit of RSA-PSS parameter handling in the provider, which found Signature.setParameter reporting a rejected trailer field as an unchecked exception and leaving the rejected spec half-applied, so that the parameters reported for a signature were not the ones it had been made with (issue #2421). Audit of the PKCS#12 key store entry-setting boundary, which found setKeyEntry reporting a certificate whose public key the provider cannot resolve as an unchecked exception rather than the KeyStoreException it declares, and which led to the same guard being applied to setCertificateEntry and to the RFC 9579 PBMAC1 store, and to the rejected entry no longer being left behind in the store (issue #2419). Further auditing of the verification and expiration paths of the high-level OpenPGP API, which found a configured algorithm policy not being applied to inline message verification, an expired primary key still offering its subkeys, and a data signature being reported valid past its own expiration time. CMS SignedData and PKIX certification path test coverage for the eighteen Composite ML-DSA parameter sets, which had been reachable through the CMS and cert-path signature algorithm finders with no test exercising either (PR #2437). Identification and fix of the output offset in the AEAD stream cipher data operator that made Grain-128AEAD return corrupted plaintext from a decryption driven in chunks, with the streamed decryption coverage that had been missing (PR #2447). Identification and fix of the RFC 9709 content-encryption algorithm being left wrapped at the CMS recipient key-size, allowed-algorithm and tag-size checks, so that none of them applied to the algorithm the content was encrypted under (PR #2446). Identification and fix of the YubiKey OpenPGP smart-card decryptor factories zeroizing the user PIN array belonging to the KeyPassphraseProvider that supplied it, which left the next private-key operation presenting an all-zero PIN to the card (PR #2444). Identification and fix of the TupleHash element length prefix being computed in int arithmetic, which left an element of 2^28 bytes or more either not returning from the length encoding loop or carrying the prefix of an empty element, and of the same loop not returning on a negative output length (PR #2462).
545+
- Arpan Sharma \<https://github.com/Arpan0995\> - initial audit of BCPQC provider consistency starting with HQC, which led to the exposure of a number of issues in the JCA provider service interfaces for other BCPQC algorithms. In-depth auditing of PQC signature algorithms in the provider leading to the correction of a number of JCA API compliance issues. Initial implementation of the guard that lets a signature context be set on the composite ML-DSA services before initSign / initVerify, the composite counterpart of the base-engine fix for issue #2396 (issue #2412). Audit of the LMS / HSS stateful private key decoder, establishing that the level count, the one-time index and the persisted tree cache were all accepted without validation (issue #2414); that issue was also the inspiration for the further investigation which found the HSS and XMSS^MT decoders accepting a private key whose declared index disagreed with the traversal state stored beside it, allowing a one-time key to be used twice. Audit of the high-level OpenPGP API (org.bouncycastle.openpgp, org.bouncycastle.openpgp.api) and the bcpg packet layer beneath it, spanning certificate evaluation, message verification, decryption and signature subpacket parsing, which found certificates being used without the certifications RFC 9580 requires of them, malformed but signed content reaching ordinary reader code as unchecked exceptions, a truncated message being read as a clean end of message, and unverified plaintext being released ahead of the integrity check (issues #2417, #2424, #2426). Audit of the recipient side of the CMS RFC 9629 KEMRecipientInfo path, which found three sender-controlled fields leaving methods declared to throw CMSException as unchecked exceptions and the kekLength never being confirmed against the wrap algorithm, and which led to the same translation being added to the neighbouring AuthEnvelopedData constructor and the two streaming parsers (issue #2422). Audit of RSA-PSS parameter handling in the provider, which found Signature.setParameter reporting a rejected trailer field as an unchecked exception and leaving the rejected spec half-applied, so that the parameters reported for a signature were not the ones it had been made with (issue #2421). Audit of the PKCS#12 key store entry-setting boundary, which found setKeyEntry reporting a certificate whose public key the provider cannot resolve as an unchecked exception rather than the KeyStoreException it declares, and which led to the same guard being applied to setCertificateEntry and to the RFC 9579 PBMAC1 store, and to the rejected entry no longer being left behind in the store (issue #2419). Further auditing of the verification and expiration paths of the high-level OpenPGP API, which found a configured algorithm policy not being applied to inline message verification, an expired primary key still offering its subkeys, and a data signature being reported valid past its own expiration time. CMS SignedData and PKIX certification path test coverage for the eighteen Composite ML-DSA parameter sets, which had been reachable through the CMS and cert-path signature algorithm finders with no test exercising either (PR #2437). Identification and fix of the output offset in the AEAD stream cipher data operator that made Grain-128AEAD return corrupted plaintext from a decryption driven in chunks, with the streamed decryption coverage that had been missing (PR #2447). Identification and fix of the RFC 9709 content-encryption algorithm being left wrapped at the CMS recipient key-size, allowed-algorithm and tag-size checks, so that none of them applied to the algorithm the content was encrypted under (PR #2446). Identification and fix of the YubiKey OpenPGP smart-card decryptor factories zeroizing the user PIN array belonging to the KeyPassphraseProvider that supplied it, which left the next private-key operation presenting an all-zero PIN to the card (PR #2444). Identification and fix of the TupleHash element length prefix being computed in int arithmetic, which left an element of 2^28 bytes or more either not returning from the length encoding loop or carrying the prefix of an empty element, and of the same loop not returning on a negative output length (PR #2462). Identification and fix of the ITS explicit certificate builder choosing the certificate's signature type from the verification key indicator rather than the signing key's curve, which mislabelled brainpoolP256r1 signatures and implicit-issuer P-256 signatures and left brainpoolP384r1 keys unable to sign a certificate (PR #2463).
546546
- Flowdalic \<https://github.com/Flowdalic\> - initial implementation of an AnimalSniffer-based Android API-level compatibility check for the Gradle build (PR #336).
547547
- hannesa2 \<https://github.com/hannesa2\> - initial Dependabot configuration for the Gradle and GitHub Actions ecosystems (PR #883).
548548
- vladhuma \<https://github.com/vladhuma\> - initial implementation of server-side OCSP stapling for the BCJSSE provider, on behalf of Thales Group (PR #1740).

‎docs/releasenotes.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ Date: 2026, TBD
8585

8686
- CRL.isRevoked() on the provider's CRLs threw ClassCastException for a certificate whose type is "X.509" but which is not a java.security.cert.X509Certificate, although the method checks only the type and goes on to handle exactly that case: it cast the certificate to X509Certificate for its serial number before looking at any entry, so the branch that reads the issuer from the certificate's encoding could never be reached. Such a certificate now has both its serial number and its issuer read from its encoding, in the provider's X509CRL and in the legacy org.bouncycastle.jce.provider.X509CRLObject alike.
8787

88+
- ITSExplicitCertificateBuilder chose the certificate's Signature CHOICE from the VerificationKeyIndicator CHOICE rather than from the signing key's curve, so brainpoolP256r1 signatures were labelled as NIST P-256 and rejected by BC's own verifier, brainpoolP384r1 keys could not sign a certificate at all, and a P-256 signature under an implicit issuer was labelled as brainpoolP256r1. The signature type is now taken from the content signer's curve (github PR #2463).
89+
8890
### 2.1.3 Additional Features and Functionality
8991

9092
- The CRMF certificate request message controls now include the RFC 4211 sec. 6.6 protocolEncrKey control, which names the key a CA is to encrypt its response with: org.bouncycastle.cert.crmf.ProtocolEncrKeyControl carries the SubjectPublicKeyInfo the control is defined to take, and CertificateRequestMessage.getControl() recognises id-regCtrl-protocolEncrKey alongside the regToken, authenticator and pkiArchiveOptions controls it already returned (github PR #2443).

‎pkix/src/main/java/org/bouncycastle/its/ITSExplicitCertificateBuilder.java‎

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
77
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
8-
import org.bouncycastle.asn1.sec.SECObjectIdentifiers;
9-
import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers;
108
import org.bouncycastle.its.operator.ECDSAEncoder;
119
import org.bouncycastle.its.operator.ITSContentSigner;
1210
import org.bouncycastle.oer.OEREncoder;
@@ -16,7 +14,6 @@
1614
import org.bouncycastle.oer.its.ieee1609dot2.basetypes.HashAlgorithm;
1715
import org.bouncycastle.oer.its.ieee1609dot2.basetypes.HashedId8;
1816
import org.bouncycastle.oer.its.ieee1609dot2.IssuerIdentifier;
19-
import org.bouncycastle.oer.its.ieee1609dot2.basetypes.PublicVerificationKey;
2017
import org.bouncycastle.oer.its.ieee1609dot2.basetypes.Signature;
2118
import org.bouncycastle.oer.its.ieee1609dot2.ToBeSignedCertificate;
2219
import org.bouncycastle.oer.its.ieee1609dot2.VerificationKeyIndicator;
@@ -62,18 +59,6 @@ public ITSCertificate build(CertificateId certificateId, ITSPublicVerificationKe
6259

6360
ToBeSignedCertificate tbsCertificate = tbsBldr.createToBeSignedCertificate();
6461

65-
ToBeSignedCertificate signerCert = null;
66-
VerificationKeyIndicator verificationKeyIndicator;
67-
if (signer.isForSelfSigning())
68-
{
69-
verificationKeyIndicator = tbsCertificate.getVerifyKeyIndicator();
70-
}
71-
else
72-
{
73-
signerCert = signer.getAssociatedCertificate().toASN1Structure().getToBeSigned();
74-
verificationKeyIndicator = signerCert.getVerifyKeyIndicator();
75-
}
76-
7762
OutputStream sOut = signer.getOutputStream();
7863

7964
try
@@ -87,21 +72,8 @@ public ITSCertificate build(CertificateId certificateId, ITSPublicVerificationKe
8772
throw new IllegalArgumentException("cannot produce certificate signature");
8873
}
8974

90-
Signature sig = null; // TODO: signature actually optional.
91-
switch (verificationKeyIndicator.getChoice())
92-
{
93-
case PublicVerificationKey.ecdsaNistP256:
94-
sig = ECDSAEncoder.toITS(SECObjectIdentifiers.secp256r1, signer.getSignature());
95-
break;
96-
case PublicVerificationKey.ecdsaBrainpoolP256r1:
97-
sig = ECDSAEncoder.toITS(TeleTrusTObjectIdentifiers.brainpoolP256r1, signer.getSignature());
98-
break;
99-
case PublicVerificationKey.ecdsaBrainpoolP384r1:
100-
sig = ECDSAEncoder.toITS(TeleTrusTObjectIdentifiers.brainpoolP384r1, signer.getSignature());
101-
break;
102-
default:
103-
throw new IllegalStateException("unknown key type");
104-
}
75+
// TODO: signature actually optional.
76+
Signature sig = ECDSAEncoder.toITS(signer.getCurveID(), signer.getSignature());
10577

10678
CertificateBase.Builder baseBldr = new CertificateBase.Builder();
10779

0 commit comments

Comments
 (0)