After all this time I had a chance to test your solution. I clone the actual state of the repository, where master was at "8d70594". However function wc_PKCS7_VerifySignedData_ex didn't work from the beginning with our detached pre-calculated hash. I had to recompile wolfssl with PKCS7_STREAM disabled. The problem is a missing "ret = 0" here:
index 3bcbfec6f..f4c7d596e 100644
--- a/wolfcrypt/src/pkcs7.c
+++ b/wolfcrypt/src/pkcs7.c
@@ -4679,7 +4679,7 @@ static int PKCS7_VerifySignedData(PKCS7* pkcs7, const byte* hashBuf,
idx = localIdx;
}
else {
-
+ ret = 0;
/* If either pkcs7->content and pkcs7->contentSz are set
* (detached signature where user has set content explicitly
* into pkcs7->content/contentSz) OR pkcs7->hashBuf and
Because the following code section checks for the exitence of an embedded data length information, which doesn't exist in the detached case. So the GetLength_Ex will fail, which is okay. But the ret value will be checked again in the next code section, which is guarded with #ifndef NO_PKCS7_STREAM, without beeing updated by a regular function call in between. So, we have to set it by ourselfs.
/* get length of content in case of single part */
if (ret == 0 && !multiPart) {
if (tag != ASN_OCTET_STRING)
ret = ASN_PARSE_E;
if (ret == 0 && GetLength_ex(pkiMsg, &localIdx,
&length, pkiMsgSz, NO_USER_CHECK) < 0)
ret = ASN_PARSE_E;
}
Do you agree?