-
Notifications
You must be signed in to change notification settings - Fork 31
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
BERDecodeSubjectPublicKeyInfo failed to read an EC public key that explicitly contains EC parameters from a certificate #18
Comments
Thanks @roadicing, Out of curiosity, where did the certificate come from? If the certificate(s) are publicly available, then I would like to get some test cases setup, like https://github.com/noloader/cryptopp-pem/blob/master/pem_test.cxx#L379 and https://github.com/noloader/cryptopp-pem/blob/master/pem_test.cxx#L444. The certificate piqued my curiosity:
And:
|
Hi, the certificate I used was generated by using the command like:
|
Hello, is there any progress on the fix plan? @noloader |
When I use the following code to read an EC public key from a certificate that explicitly contains the EC parameters, the program fails to work as expected:
At first, I thought that the code for handling public keys that explicitly contains the EC parameters wasn't implemented in
cryptopp-pem
. However, later I realized that it seems to be implemented, but there are some issues with the implementation.The issue lies in the line 1231 in function
GetSubjectPublicKeyInfoOids
, due to the inconsistency in the structure between EC public key that explicitly contain EC parameters and normal EC public key, theGetSubjectPublicKeyInfoOids
function incorrectly parse the value offield
asNULL
after execution.The reason for incorrectly parsing
field
toNULL
lies in theGetSubjectPublicKeyInfoOids
function, which expects to setalgorithm
andfield
to their correspondingOIDs
through two separate decode operations in line 1279 and line 1282. This is because, in a normal public key as shown below,algorithm
andfield
occur consecutively, allowing them to be properly set as their correspondingOIDs
through this method:When an EC public key explicitly contains parameters, its public key structure becomes as follows:
It can be seen that, in this case, what directly follows the
algorithm
is no longer anOID
but aSEQUENCE
, andfield
resides within thisSEQUENCE
. Therefore, when attempting to setalgorithm
andfield
as their corresponding OIDs through two consecutive decode operations, the program incorrectly decodes theSEQUENCE
as anOID
. Clearly, this results in decoding failure, leading to the setting offield
asNULL
.Once field is set to
NULL
, this leads to subsequent functions inBERDecodeSubjectPublicKeyInfo
such asIsECPrimeFieldAlgorithm
orIsECBinaryFieldAlgorithm
, erroneously considering that the public key does not belong to an EC public key, thus terminating and reporting an error.fix
PR 19
The text was updated successfully, but these errors were encountered: