Unexpected success from EVP_PKEY_fromdata
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 30.8k
- Forks
- 11.5k
- Avg merge
- 10m
- Merged PRs (30d)
- 1
Description
The function EVP_PKEY_fromdata will return success even in instances where it has failed to import a key successfully.
In this email to openssl-users the OP reports an instance where EVP_PKEY_fromdata indicates success when importing a public key:
https://mta.openssl.org/pipermail/openssl-users/2021-October/014479.html
The same report goes on to describe a subsequent crash which is fixed by #16911.
The problem with the EVP_PKEY_fromdata call is that the OP attempted to import a public key using OSSL_PKEY_PARAM_EC_PUB_X and OSSL_PKEY_PARAM_EC_PUB_Y which are only supported as "getters", i.e. not for import. Since the OP explicitly indicates EVP_PKEY_PUBLIC_KEY in the EVP_PKEY_fromdata call I would expect it to fail since a public key was not imported. However this is not the case. Instead it simply imports the parameters, ignores the unknown public key params and returns success, having created a parameters only key.
This seems quite unexpected.
However fixing this is quite tricky. In order to indicate an attempt to import a private key you might be expected to use EVP_PKEY_KEYPAIR as the selection parameter (there is no EVP_PKEY_PRIVATE_KEY - although if it did exist it would be the same as OSSL_KEYMGMT_SELECT_PRIVATE_KEY). However EVP_PKEY_KEYPAIR actually indicates both the public and private key are present - but in some key types (including EC) the import is deliberately tolerant of a private key without a public key. So it doesn't seem to be as simple as saying "if EVP_PKEY_PUBLIC_KEY is specified and no public key is present then fail" since in the EVP_PKEY_KEYPAIR case, EVP_PKEY_PUBLIC_KEY is incorporated but it is valid to have no public key.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing EVP_PKEY_fromdata and the handling of OSSL_PKEY_PARAM_EC_PUB_X and OSSL_PKEY_PARAM_EC_PUB_Y, using the linked openssl-users report as the reproduction context. Compare EVP_PKEY_PUBLIC_KEY with EVP_PKEY_KEYPAIR, including EC imports that omit a public key. Done means unsuccessful public-key imports no longer report success while valid tolerant imports remain supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- cryptography, security
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100