Skip to content

Commit 245d260

Browse files
committed
wolfcrypt/src/pkcs7.c: Fix PKCS#7 verification for digestAlgorithm.parameters = NULL
RFC 8017 hardcodes DER serialization samples of DigestInfo, where the parameter part is always NULL (05 00) for known hash algorithm [1]. This value does thus *not* depend on SignerInfo.digestAlgorithm.parameters. Starting with 75c3030 ("Add option for absent hash params in PKCS7"), wolfSSL wrongly assumed and implemented such a dependency. This non-conformance caused an interoperability bug with OpenSSL: A signature created with openssl cms could not be verified in WolfSSL. OpenSSL correctly leaves SignerInfo.digestAlgorithm.parameters absent and adds explicit NULL to DigestInfo. WolfSSL saw the absence and wrongly inferred DigestInfo would also have no explicit NULL - but it has - leading to size mismatch. Fix it by constructing the expected DigestInfo always with NULL (05 00). 4f21117 ("tests: Add PKCS#7 verification interoperability test") and 8d8170e (".github: Test PKCS7 interoperability for OpenSSL and GnuTLS") can be used to reproduce the bug and to demonstrate this commit fixes it. [1] https://www.rfc-editor.org/rfc/rfc8017#section-9.2
1 parent 34c2c72 commit 245d260

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

wolfcrypt/src/pkcs7.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4779,9 +4779,7 @@ static int wc_PKCS7_BuildSignedDataDigest(wc_PKCS7* pkcs7, byte* signedAttrib,
47794779
}
47804780
}
47814781

4782-
/* Set algoID, match whatever was input to match either NULL or absent */
4783-
algoIdSz = SetAlgoIDEx(pkcs7->hashOID, algoId, oidHashType,
4784-
0, pkcs7->hashParamsAbsent);
4782+
algoIdSz = SetAlgoID(pkcs7->hashOID, algoId, oidHashType, 0);
47854783

47864784
digestStrSz = SetOctetString(hashSz, digestStr);
47874785
digestInfoSeqSz = SetSequence(algoIdSz + digestStrSz + hashSz,

0 commit comments

Comments
 (0)