Skip to content

Fix PKCS#7 verification of signature created with OpenSSL#10099

Open
haxtibal wants to merge 3 commits intowolfSSL:masterfrom
haxtibal:tdmg/fix_digestinfo_rfc8017
Open

Fix PKCS#7 verification of signature created with OpenSSL#10099
haxtibal wants to merge 3 commits intowolfSSL:masterfrom
haxtibal:tdmg/fix_digestinfo_rfc8017

Conversation

@haxtibal
Copy link
Copy Markdown

@haxtibal haxtibal commented Mar 29, 2026

Description

RFC 8017 hardcodes DER serialization samples of DigestInfo, where the parameter part is always NULL (05 00) for known hash algorithm. This value does thus not depend on SignerInfo.digestAlgorithm.parameters. Starting with 75c3030, 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).

The PR further adds an optional unit test to verify externally provided DER signature samples. A new CI job uses this to verify signatures created with OpenSSL and GnuTLS.

Testing

This was originally found, discussed and tested at Debian via a swugenerator autopkgtest. Pipelines in my wolfSSL fork run the newly added tests:

  • failed without the proposed fix
  • pass with the proposed fix

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@wolfSSL-Bot
Copy link
Copy Markdown

Can one of the admins verify this patch?

@haxtibal haxtibal force-pushed the tdmg/fix_digestinfo_rfc8017 branch from 517efc3 to 55b85a6 Compare March 29, 2026 17:56
@dgarske
Copy link
Copy Markdown
Contributor

dgarske commented Apr 5, 2026

@haxtibal please resolve merge conflicts. For external contributions we need a signed contributor agreement. You can email support at wolfssl dot com to get that process started. Please reference the PR and tell us more about your project. Thanks, David Garske, wolfSSL

@haxtibal haxtibal force-pushed the tdmg/fix_digestinfo_rfc8017 branch 2 times, most recently from a66c6c2 to d8709e9 Compare April 6, 2026 19:24
haxtibal added 3 commits April 7, 2026 10:53
Intention is to verify PKCS#7 / CMS signatures produced by third party
tools.

The optional test is enabled by providing a comma separated list of
external DER files that have previously been signed with a third party
tool to configure --with-pkcs7-test-signed-data.

Usage:

 openssl cms -sign -in <(echo -n "openssl cms interop test message") \
   -signer certs/client-cert.pem -inkey certs/client-key.pem \
   -md sha256 -nodetach -outform DER -out /tmp/cms.der
 openssl smime -sign -in <(echo -n "openssl smime interop test message") \
   -signer certs/client-cert.pem -inkey certs/client-key.pem \
   -md sha256 -binary -nodetach -outform DER -out /tmp/smime.der
 ./configure --enable-pkcs7 --enable-certext --enable-examples \
   --with-pkcs7-test-signed-data=/tmp/cms.der,/tmp/smime.der
 make -j$(nproc)
 tests/unit.test -test_wc_PKCS7_VerifySignedData_interop
…rameters = 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
@haxtibal haxtibal force-pushed the tdmg/fix_digestinfo_rfc8017 branch from d8709e9 to 245d260 Compare April 7, 2026 08:54
@haxtibal
Copy link
Copy Markdown
Author

haxtibal commented Apr 7, 2026

@haxtibal please resolve merge conflicts. For external contributions we need a signed contributor agreement. You can email support at wolfssl dot com to get that process started. Please reference the PR and tell us more about your project. Thanks, David Garske, wolfSSL

@dgarske Thanks, done. Let me know if something's missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants