rsa: verify PUBKEY_ENC_UNKNOWN via the raw compare path (fixes gpg/apt RSA verify)#29
Open
MarkAtwood wants to merge 1 commit into
Conversation
GnuPG's OpenPGP RSA signature verification supplies the full pre-encoded PKCS#1 v1.5 message and leaves ctx.encoding == PUBKEY_ENC_UNKNOWN. wc_rsa_verify()'s switch only handled the named encodings and routed UNKNOWN to default -> GPG_ERR_BAD_SIGNATURE, so every GnuPG/apt RSA signature verification failed (keys reported "Unusable", "1 bad signature"). Stock libgcrypt performs the raw mpi_cmp for all non-PSS encodings; route UNKNOWN into the existing wc_RsaDirect + mpi_cmp path. Verified: gpg --check-sigs goes from "1 bad signature" to clean. Fixes wolfSSL#28
There was a problem hiding this comment.
Pull request overview
This PR fixes RSA signature verification failures in the wolfCrypt-backed wc_rsa_verify() path when the libgcrypt encoding context is PUBKEY_ENC_UNKNOWN, which is commonly encountered during GnuPG OpenPGP RSA verification (and thus impacts apt signature verification via gpg/libgcrypt).
Changes:
- Route
PUBKEY_ENC_UNKNOWNthrough the same “raw public operation +mpi_cmp” verification path used for other non-PSS encodings, instead of treating it as a bad signature.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #28.
wc_rsa_verify()rejected every RSA signature whose libgcrypt encoding contextis
PUBKEY_ENC_UNKNOWN, because theswitch (ctx.encoding)only handled thenamed encodings (PSS / PKCS1 / PKCS1_RAW / RAW / OAEP) and routed everything else
to
default: rc = GPG_ERR_BAD_SIGNATURE.GnuPG's OpenPGP RSA verification supplies the full pre-encoded PKCS#1 v1.5
message and leaves
ctx.encoding == PUBKEY_ENC_UNKNOWN, so all GnuPG/apt RSAsignature verification failed (keys "Unusable", "1 bad signature"). Stock
libgcrypt performs the raw
mpi_cmp(result, data)for all non-PSS encodings;this PR routes
PUBKEY_ENC_UNKNOWNinto the samewc_RsaDirect+mpi_cmpgroup.
Test
Notes
signature verifies through native wolfCrypt with the key loaded via
wc_RsaPublicKeyDecodeRaw+wc_RsaDirect(RSA_PUBLIC_DECRYPT)(recovered EM isbyte-for-byte correct). Only the shim's encoding dispatch was wrong.
default:case perform the rawcompare (matching stock libgcrypt) instead of adding an explicit case — happy
to switch to that form if preferred.