Fix invalid RSA private key PKCS8 encoding#120
Fix invalid RSA private key PKCS8 encoding#120mpdavis merged 9 commits intompdavis:backend-explicit-testsfrom
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.
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.
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.
… 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_backendmodule 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/cryptographyand compatibility tests will fail. Those are addressed in #116 and #117.