Repository navigation
Require PEM armor for string keys in the python-ecdsa backend - #430
Open
neeraj1235476 wants to merge 1 commit into
Open
neeraj1235476 wants to merge 1 commit into
neeraj1235476 wants to merge 1 commit into
Conversation
ecdsa.VerifyingKey.from_pem() ignores the armor lines and decodes bare base64 DER, so ECDSAECKey accepted EC public keys that HMACKey does not recognise as asymmetric. The same public key string could then be used as an HS256 secret to forge tokens. Only load PEM-armored keys, as the cryptography backend already does.
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.
With the default install (no
cryptography),ECDSAECKeyloads string keys throughecdsa.VerifyingKey.from_pem(), which drops every line starting with-----and base64-decodes the rest. An ES256 public key passed as bare base64 DER, or under a label such asEC PUBLIC KEY, loads and verifies tokens normally.HMACKeyonly refuses keys thatis_pem_format()/is_ssh_key()recognise, so the same public key string is also accepted as an HMAC secret. This is the HS256/public-key algorithm confusion from CVE-2024-33663, reached through a key format that check does not cover:The check sits in the EC loader because the cryptography backend already refuses unarmored keys, and requiring
is_pem_format()there means every key either EC backend accepts is oneHMACKeyrejects. The new test fails on master and passes with the change. With and withoutcryptography, the rest of the suite gives the same results as master. The one failure,test_incorrect_public_key_hmac_signing, also fails on master with cryptography 50 (TypeError: curve must be an EllipticCurve instance).