Closed mugz3m closed 8 months ago
Thanks for the report, I think this is now fixed. The current snapshot at https://www.bouncycastle.org/betas includes the patches.
We have checked the snapshot with patches and could not reproduce the error. Thanks!
Environment
9279d29588e52d8f0260c2ce5e730c773c247569
Description
When generating a certificate using the GOST 34.10 R 2012 algorithm with a key length of 256 and parameters
id-tc26-gost-3410-2012-256-paramSetB
via Bouncy Castle we have two parameters in theparameters
field of theSubjectPublicKeyInfo
structure:publicKeyParamSet
: 1.2.643.7.1.2.1.1.2 equal toid-tc26-gost-3410-12-256-paramSetB
;digestParamSet
: 1.2.643.7.1.1.2.2 equal toid-tc26-gost3411-12-256
.On verifying a CMS GOST 34.10 R 2012 signature with only one parameter
publicKeyParamSet
equal toid-tc26-gost-3410-12-256-paramSetB
in theparameters
field of the certificate'sSubjectPublicKeyInfo
ArrayIndexOutOfBoundsException exception is thrown as Bouncy Castle ALWAYS expects at least two parameters to be present:publicKeyParamSet
anddigestParamSet
.Stacktrace:
Class GOST3410PublicKeyAlgParameters.java requires
digestParamSet
parameter in it's constructors or expects that ASN1Sequence parameter must always have an object at the index 1 indicatingdigestParamSet
.The library's current behavior doesn't comply with RFC 9215. According to section 4.2:
Expected behavior
The expected behavior in this case is that Bouncy Castle supports the conditions described in section 4.2 of RFC 9215:
Verification of CMS GOST 34.10 R 2012 signature without
digestParamSet
parameter in certificate'sSubjectPublicKeyInfo
should not throw exception.Objects generated via Bouncy Castle using the GOST 34.10 R 2012 algorithm with a key length of 256 bits and a value
publicKeyParamSet
equal to:must have only one parameter
publicKeyParamSet
inparameters
. ThedigestParamSet
parameter should be omitted.Link to samples
https://drive.google.com/file/d/1Zyo8qcPF-LCBGMNEXRANgr22KGKH4NwX/view?usp=share_link
CmsSignVerifyDetachedGOSTR3410_2012_256
sample tries to verify detached CMS signature with signer certificate created by rtpkcs11ecp library and fails with exception mentioned aboveGenerateCertificateGOSTR3410_2012_256
sample generates certificate (GOST 34.10 R 2012 algorithm with a key length of 256 bits and id-tc26-gost-3410-2012-256-paramSetB) and shows SubjectPublicKeyInfo parameters including unnecessarydigestParamSet