Repository navigation
fix #803 - rsa_import_pkcs1: reject unknown versions - #814
Open
dlazobnaKocka wants to merge 1 commit into
Open
dlazobnaKocka wants to merge 1 commit into
dlazobnaKocka wants to merge 1 commit into
Conversation
rsa_import_pkcs1() returned CRYPT_OK without decoding any key components in two cases: - the RSAPrivateKey version was not 0 or 1 - the SEQUENCE contained only the version INTEGER Reject both with an error.
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 #803
rsa_import_pkcs1()could returnCRYPT_OKwithout decoding any key components. There were two ways to get there:err = CRYPT_OK. This is the case reported in RSA key import can succeed with an invalid/undefined version #803.30 03 02 01 00. The first decode then returnsCRYPT_OKinstead ofCRYPT_INPUT_TOO_LONG, and the "couldn't decode the version" check passes thatCRYPT_OKstraight back to the caller.In both cases
rsa_import()reported success with an empty modulus, andkey->typewas never set.Changes:
CRYPT_OKfrom the version-only decode likeCRYPT_INPUT_TOO_LONG, so the input goes through the normal version check. A version-only SEQUENCE then fails in the full private key decode.version == 1branch into a plainelse, so version 1 (multi-prime) and any unknown version both returnCRYPT_PK_INVALID_TYPE.The
elsebranch suggested in #803 covers case 1 on its own. Case 2 needs the first change too.Tests: added
s_rsa_issue_803()totests/rsa_test.c, which imports both inputs and expects an error. Without the fix, the test fails on the first import. With only theelsebranch, it fails on the second import. With the full fix,test-ltcpasses with LTM, andhelper.pl --check-allis clean.Thanks to @headscott for the report and the suggested fix in #803.