EVP: Adapt EVP_PKEY checking, comparing and copying for provider keys#10807
EVP: Adapt EVP_PKEY checking, comparing and copying for provider keys#10807levitte wants to merge 12 commits intoopenssl:masterfrom
Conversation
adbe04e to
bda8501
Compare
|
There was a small fixup needed, but other than that, at least my personal tests go through. Final review? |
crypto/evp/keymgmt_lib.c
Outdated
There was a problem hiding this comment.
What is the purpose of the assignment to i here?
There was a problem hiding this comment.
Must be old cruft. Removing.
There was a problem hiding this comment.
Doesn't seem to have been removed.
There was a problem hiding this comment.
Nope, but if you read the comment a couple of lines up, I think the reason will become clear 😉
There was a problem hiding this comment.
Wouldnt if (!ossl_assert())
return 0;
be better?
|
Travis failures also look relevant. |
|
After all the excellent remarks from @mattcaswell, I've had the time to rethink this PR, and have refactored it quite a bit.
|
3870a24 to
f069026
Compare
f7604a9 to
b980b8c
Compare
64341d5 to
890ea03
Compare
|
I believe this PR got the last little nudge it needed to be complete enough. |
crypto/evp/keymgmt_lib.c
Outdated
There was a problem hiding this comment.
Doesn't seem to have been removed.
crypto/evp/keymgmt_lib.c
Outdated
There was a problem hiding this comment.
This doesn's seem to quite make sense...why do we check provdata2 == NULL? I would have expected:
if (provdata1 != NULL && provdata2 != NULL)
crypto/evp/keymgmt_lib.c
Outdated
There was a problem hiding this comment.
Wouldn't this up ref be better inside the if block below? That way you don't have to then down-ref it in the else block. Or alternatively place it immediately before the final assignment to->pkeys[0].keymgmt = keymgmt_to
There was a problem hiding this comment.
I'll have another look. Thanks for the heads up
crypto/evp/keymgmt_meth.c
Outdated
There was a problem hiding this comment.
So iskey, cmpkey and dupkey are mandatory?
crypto/evp/p_lib.c
Outdated
There was a problem hiding this comment.
The NULL here for the libctx parameter seems wrong
There was a problem hiding this comment.
I'm quite confused by what you are trying to do here...we just seem to be trying to export the key data to "whatever", regardless of whether the key already exists in a provider?
There was a problem hiding this comment.
Not "whatever". To a keymgmt that corresponds to the type of the from key, and only if it's not already exported to the keymgmt of that key.
There was a problem hiding this comment.
What libctx would you pass to evp_pkey_make_provided?
There was a problem hiding this comment.
I'm not sure, but this is problematic. If you're trying to copy parameters from one key to another for a key type that does not exist in the default provider (but does in some other libctx) then its not going to work.
crypto/evp/p_lib.c
Outdated
There was a problem hiding this comment.
So a copy parameters operation frees any pre-existing key data? Is that the correct semantics?
There was a problem hiding this comment.
frees any pre-existing key data
Just the legacy bits, and only if from doesn't have any legacy bits... but I need to have another look at the evp_pkey_make_provided call...
crypto/evp/p_lib.c
Outdated
There was a problem hiding this comment.
Again, I'm concerned about the use of the default libctx here. What if the default libctx doesn't have a provider for this type of key loaded?
doc/man7/provider-keymgmt.pod
Outdated
There was a problem hiding this comment.
"is or contains"...I'm not sure I understand this. Please explain?
890ea03 to
4e77c05
Compare
crypto/evp/keymgmt_lib.c
Outdated
There was a problem hiding this comment.
Do all entries in pk->pkeys[i] have the same domainparams setting?
If they do then maybe it should not be stored in the array.
If they dont then this logic is incorrect.
There was a problem hiding this comment.
When I designed this cache, I did intend for it to be able to hold a mixture, but that turned out difficult / flawed. That's why you see these indicators on a per cache item basis, and you're right, it can be taken out from there. I think that's a topic for a separate PR, though...
crypto/evp/keymgmt_lib.c
Outdated
There was a problem hiding this comment.
I really dislike this being called _cmp()
cmp() to me means return 0 if equal.
There was a problem hiding this comment.
The public name will not change, obviously, but feel free to suggest a better name for this function.
crypto/evp/p_lib.c
Outdated
There was a problem hiding this comment.
The old code checked for ameth == NULL (Maybe put that back in just in case)
doc/man7/provider-keymgmt.pod
Outdated
doc/man7/provider-keymgmt.pod
Outdated
There was a problem hiding this comment.
Not sure why you need these null checks : BN_cmp returns 0 if both NULL or if they are equal otherwise it returns -1 or 1 dependent on a < b.. So the cmp()==0 should be sufficient.
There was a problem hiding this comment.
I hadn't looked at BN_cmp's behavior. Thanks for the heads up
There was a problem hiding this comment.
If we can set keys up via setparams would it be possible to only have the private key bit?
There was a problem hiding this comment.
The general assumption with openssl is that a valid key pair always has the public half. A lot will fall apart if that doesn't hold true.
There was a problem hiding this comment.
hmm this is an interesting check... Are we only interested in the public key comparison here?
There was a problem hiding this comment.
I basically copied the code from dh_ameth.c. Interestingly enough, the legacy function pointer is called pub_cmp, so it's a bit more explicit. I was thinking that it would be up to the provider to decide exactly how detailed the comparison should be. In this implementation, I chose to do like we did before. For some implementations where the private half is hidden (typically HSMs), this would be the only possible comparison.
With the assumption that the private half actually corresponds to the public part, this comparison is enough. I suppose that key validation will ensure this validity?
There was a problem hiding this comment.
OR...
return BN_cmp() == 0
&& BN_cmp() == 0...
4e77c05 to
3e3cd5b
Compare
This applies both to domain parameters and actual keys
This affects the following function, which can now deal with provider side domain parameters and keys: - EVP_PKEY_copy_parameters() - EVP_PKEY_missing_parameters() - EVP_PKEY_cmp_parameters() - EVP_PKEY_cmp() -
With ex_data support in DSA keys gone for the FIPS module, there's no need to create a key with a library context as input, i.e. we can go back to normal DSA_new(). Also, we avoid using DSAparams_dup(), as that does a lot of ASN.1 magic that we don't actually need. Just duplicate P, G and Q.
- DSA_get0_p() - DSA_get0_q() - DSA_get0_g() - DSA_get0_pub_key() - DSA_get0_priv_key()
…er keys This helps in some cases where it's not terribly important if the provider data is a set of domain parameters or a keypair. -1 is used by EVP_PKEY_copy_parameters(), which allows copying from provider data that's a keypair just as well as domain parameters. This means that providers can't really have a strict separation between keypairs and domain parameters, as the former is increasingly assumed to contain the latter.
3e3cd5b to
b2eb8e3
Compare
|
I've realized that this needs reworking on a deeper level than I thought. Most of all, functions like Thank you all for the feedback here, it will absolutely work as valuable input for the redesign. PR coming up! |
|
PR took a little longer than I expected. However, I've raised an issue, see #10979 |
|
#11006 is the new KEYMGMT design. I'll work that one into this one. |
|
Killing this in favor of #11025 |
This affects the following function, which can now deal with provider
side domain parameters and keys:
This also adds the necessary EVP_KEYMGMT interfaces to support those functions, and the implementations for RSA, DSA and DH.