-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix invalid RSA private key PKCS8 encoding #120
Conversation
…mpatibility between backends
jose/backends/rsa_backend.py
Outdated
This is incorrect parsing and only works because the legacy PKCS1-to-PKCS8 | ||
encoding was also incorrect. | ||
""" | ||
return der_key[len(LEGACY_INVALID_PKCS8_RSA_HEADER):] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a check that the prefix of this invalid key is, in fact, equal to LEGACY_INVALID_PKCS8_RSA_HEADER
, else reject.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check added looking for the legacy header followed immediately by an ASN1 sequence identifier. That will protect against the case where an otherwise-invalid key is processed here, since for 2048-bit keys the legacy prefix is actually correct, but incomplete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
… for known legacy prefix in legacy parsing
Codecov Report
@@ Coverage Diff @@
## backend-explicit-tests #120 +/- ##
===========================================================
- Coverage 96.86% 68.99% -27.88%
===========================================================
Files 13 13
Lines 1022 1032 +10
===========================================================
- Hits 990 712 -278
- Misses 32 320 +288
Continue to review full report at Codecov.
|
Other than the merge conflict, this LGTM. |
Merge conflict resolved, and since it did a full branch merge, all the tests should actually pass now. :) |
This addresses #119 to fix the way that the
rsa_backend
module was converting PKCS1 keys to PKCS8. I left a fallback on read to attempt the old methodology if the valid parsing fails, but writes will only every use the valid encoding.NOTE: The Firebase tests will still fail. That is addressed in #118. Also, some of the
pyca/cryptography
and compatibility tests will fail. Those are addressed in #116 and #117.