Skip to content

[Pending #11074] EVP: Adapt EVP_PKEY checking, comparing and copying for provider keys, take 2#11025

Closed
levitte wants to merge 8 commits intoopenssl:masterfrom
levitte:provider-key-check+cmp+dup-take2
Closed

[Pending #11074] EVP: Adapt EVP_PKEY checking, comparing and copying for provider keys, take 2#11025
levitte wants to merge 8 commits intoopenssl:masterfrom
levitte:provider-key-check+cmp+dup-take2

Conversation

@levitte
Copy link
Member

@levitte levitte commented Feb 6, 2020

This is an adaptation of the following functions for provided keys:

  • EVP_PKEY_copy_parameters()
  • EVP_PKEY_missing_parameters()
  • EVP_PKEY_cmp_parameters()
  • EVP_PKEY_cmp()

This also adds the necessary EVP_KEYMGMT interfaces to support those functions, and the implementations for RSA, DSA and DH.

This replaces #10807 and is built on top of #11006

@levitte levitte added the branch: master Applies to master branch label Feb 6, 2020
@levitte
Copy link
Member Author

levitte commented Feb 6, 2020

The commits from #11006 are here as well, but will disappear as soon as that one is merged and this gets rebased. This PR will remain a draft until that happens.

Feel free to roam around in the last 6 commits and comment on those here.

@slontis
Copy link
Member

slontis commented Feb 7, 2020

I dont think I am going to review this until it is rebased.
Looking through > 50 files (36 commits) takes quite a while :)

@levitte
Copy link
Member Author

levitte commented Feb 7, 2020

It is possible to look at one commit at a time... But yeah, I get it, the combo is massive

@levitte levitte force-pushed the provider-key-check+cmp+dup-take2 branch from fa3c304 to e5db8ce Compare February 7, 2020 08:53
@levitte
Copy link
Member Author

levitte commented Feb 7, 2020

Rebase done, now that #11006 is in

@levitte levitte marked this pull request as ready for review February 7, 2020 08:57
@levitte
Copy link
Member Author

levitte commented Feb 7, 2020

Please make initial reviews. I'm still keeping it WIP for a little bit more while investigating what happens in a merge with #10797, but I suspect I'm pretty much done...

@levitte
Copy link
Member Author

levitte commented Feb 7, 2020

(at the very least, I like this take much more than #10807)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a tendency to think we should have a different return code for "unknown"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally had that idea for #11006, actually. so was basically thinking that we could have these possible return values for all of EVP_KEYMGMT:

# define EVP_KEYMGMT_FAILURE        0
# define EVP_KEYMGMT_FALSE          0
# define EVP_KEYMGMT_SUCCESS        1
# define EVP_KEYMGMT_TRUE           1
# define EVP_KEYMGMT_UNSUPPORTED   -1

That would leave it to the caller to decide how to handle unknown / unsupported cases.

I'm not sure if such a change belongs in this PR, though...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the finder doesn't return true, is there any point in going around the inner loop?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The idea is that it may be sufficient if either of the EVP_PKEYs have a keymgmt for which finder returns true.
The next step will be prepare_binary_op, which does a cross-wise export and should end up finding the most suitable keymgmt to use.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably I'm misunderstanding something here. If finder doesn't return true here, then when we get to the inner loop one of the following is true:

  1. tmp_keymgmt1 and tmpkeydata1 are both NULL - which means the "bigbreak" condition will never be hit in that case
    or
  2. tmp_keymgmt1 and tmpkeydata1 have the same values as the last time we went around the outer loop. So if we didn't find a match in the inner loop last time - why go around it again?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this question needs to wait for #11074, as conditions are changing with that one. Basically, when that one lands, any EVP_PKEY with pkeys[0].keymgmt == NULL is to be considered unassigned as far as this file goes (legacy export is taken care of in evp_pkey_make_provided()).

@levitte levitte changed the title [WIP] EVP: Adapt EVP_PKEY checking, comparing and copying for provider keys, take 2 [WIP, Pending #11074] EVP: Adapt EVP_PKEY checking, comparing and copying for provider keys, take 2 Feb 12, 2020
@levitte
Copy link
Member Author

levitte commented Feb 12, 2020

This is now pending on #11074

@levitte levitte force-pushed the provider-key-check+cmp+dup-take2 branch 2 times, most recently from 328ec0f to a5cd9b8 Compare February 13, 2020 08:30
@levitte levitte changed the title [WIP, Pending #11074] EVP: Adapt EVP_PKEY checking, comparing and copying for provider keys, take 2 [Pending #11074] EVP: Adapt EVP_PKEY checking, comparing and copying for provider keys, take 2 Feb 13, 2020
@levitte
Copy link
Member Author

levitte commented Feb 13, 2020

This is not WIP any more, but still pending on #11074. Early reviews are welcome

@levitte levitte force-pushed the provider-key-check+cmp+dup-take2 branch 2 times, most recently from 3b6593b to e79072e Compare February 17, 2020 15:32
This adds evp_keymgmt_util_match() and affects EVP_PKEY_cmp() and
EVP_PKEY_cmp_parameters().

The word 'match' was used for the new routines because many associate
'cmp' with comparison functions that allows sorting, i.e. return -1, 0
or 1 depending on the order in which the two compared elements should
be sorted.  EVP_PKEY_cmp() and EVP_PKEY_cmp_parameters() don't quite
do that.
This adds evp_keymgmt_util_copy() and affects EVP_PKEY_copy_parameters()
@levitte levitte force-pushed the provider-key-check+cmp+dup-take2 branch from e79072e to bce9191 Compare February 18, 2020 12:08
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably I'm misunderstanding something here. If finder doesn't return true here, then when we get to the inner loop one of the following is true:

  1. tmp_keymgmt1 and tmpkeydata1 are both NULL - which means the "bigbreak" condition will never be hit in that case
    or
  2. tmp_keymgmt1 and tmpkeydata1 have the same values as the last time we went around the outer loop. So if we didn't find a match in the inner loop last time - why go around it again?

Copy link
Member

@slontis slontis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a ec_match

* do this check, after having exported either of them that isn't
* provided.
*/
if (!(evp_pkey_is_pure_provided(to) && evp_pkey_is_pure_provided(from))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic doesnt match the comment does it? Dont you want !X && !Y
You are currently testing is either key a legacy key?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I'll have another look in the morning...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers, I have just about finished reviewing.. I dont want you being held up. Is there any other PR's you need to be reviewed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need #11074 in place before tackling this one


if (from->ameth && from->ameth->param_copy)
/*
* Only use the routine for provided keys if either key is purely provided.
Copy link
Member

@slontis slontis Feb 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment also doesn't match the logic below (which is both keys)
Looks like you mean to use ||

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need #11074 in place before tackling this one

static int implements_copy_and_export(EVP_KEYMGMT *keymgmt)
{
return keymgmt->copy != NULL
&& (keymgmt->import == NULL || keymgmt->export != NULL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you mean keymgmt->import == NULL ?
Below it says 'only implement |copy|, but must also implement |export| if it
* implements |import|'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but must also implement |export| if it implements |import|

That translates into: "it's ok if |import| isn't implemented, then we don't care about checking for |export|. However, if |import| is implemented, then so must |export|"

In logical terms:

  1. IF |import| == NULL THEN True
  2. OTHERWISE, IF |export| != NULL THEN True
  3. OTHERWISE False

Makes sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand. A provider can do import-only or export-only or both. Is that concept not supported by this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, good question. I'll have a look again.

@levitte
Copy link
Member Author

levitte commented Feb 24, 2020

This one is closed in favor of #11158

@levitte levitte closed this Feb 24, 2020
@levitte levitte deleted the provider-key-check+cmp+dup-take2 branch February 24, 2020 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch: master Applies to master branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants