Repository navigation
Require PEM armor for string keys in the python-ecdsa backend - #430
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.
|
We independently reproduced this class on python-jose 3.5.0 (default install, python-ecdsa backend, cryptography not installed) while testing the CVE-2024-33663 fix. In addition to the unarmored and EC PUBLIC KEY forms described above, a PEM label with non-canonical spacing is also loaded by the EC backend and not recognized by is_pem_format(), so it is accepted as an HMAC secret. We ran that variant against this branch at b6f97fe: it is rejected, 5 of 5 runs, where 3.5.0 accepts it 5 of 5. This change closes it. We did not test the cryptography backend. SettleBridge Cyber Lab |
|
That variant goes through the same path: python-ecdsa only skips the dash lines, so any label is_pem_format doesn't match still loads. A lowercase BEGIN label behaves the same way. The check here requires is_pem_format rather than enumerating forms, which keeps the invariant that every key the EC loader accepts is one HMACKey refuses. I re-ran your spacing case and the lowercase one against the branch and both are rejected; on 3.5.0 both load as an EC key and as an HMAC secret. |
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).