Skip to content

Commit d8709e9

Browse files
author
Tobias Deiminger
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 969e9bd commit d8709e9

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

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

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

0 commit comments

Comments
 (0)