Skip to content

Commit 517efc3

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. 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. 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 8d8170e commit 517efc3

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
@@ -4771,9 +4771,7 @@ static int wc_PKCS7_BuildSignedDataDigest(wc_PKCS7* pkcs7, byte* signedAttrib,
47714771
}
47724772
}
47734773

4774-
/* Set algoID, match whatever was input to match either NULL or absent */
4775-
algoIdSz = SetAlgoIDEx(pkcs7->hashOID, algoId, oidHashType,
4776-
0, pkcs7->hashParamsAbsent);
4774+
algoIdSz = SetAlgoID(pkcs7->hashOID, algoId, oidHashType, 0);
47774775

47784776
digestStrSz = SetOctetString(hashSz, digestStr);
47794777
digestInfoSeqSz = SetSequence(algoIdSz + digestStrSz + hashSz,

0 commit comments

Comments
 (0)