Skip to content

CORE & EVP: Adapt KEYEXCH, SIGNATURE and ASYM_CIPHER to handle key types better#10647

Closed
levitte wants to merge 5 commits intoopenssl:masterfrom
levitte:separate-keymgmt-type-take2
Closed

CORE & EVP: Adapt KEYEXCH, SIGNATURE and ASYM_CIPHER to handle key types better#10647
levitte wants to merge 5 commits intoopenssl:masterfrom
levitte:separate-keymgmt-type-take2

Conversation

@levitte
Copy link
Member

@levitte levitte commented Dec 18, 2019

The adaptation is to handle the case when key types and operations
that use these keys have different names. For example, EC keys can be
used for ECDSA and ECDH.

This also involves specifying OP_query_operation_name() for KEYMGMT

This will allow keymgmt implementation for key types that need it to
specify the names of the diverse operation algorithms it can be used
with. Currently, only one name per key type and operation is allowed.

@levitte levitte added branch: master Applies to master branch approval: review pending This pull request needs review by a committer labels Dec 18, 2019
@levitte levitte added this to the 3.0.0 milestone Dec 18, 2019
@levitte
Copy link
Member Author

levitte commented Dec 18, 2019

This is an alternative to #10636, which implements kind of the same thing, but the other way around. Instead of asking the operation implementations what key types they support, we ask the KEYMGMT for the key what operations it supports and by what name.

This should fit better with the way OpenSSL works with EVP_PKEY_CTX, where the key type governs what is being done.

Copy link
Member

@romen romen left a comment

Choose a reason for hiding this comment

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

Just a nit for now, but I will have to wait until later today for testing.

@romen
Copy link
Member

romen commented Dec 18, 2019

@levitte do you already have ideas of what could happen when we will have a "SM2:ec-PublicKey", sm2_keymgmt_functions entry?

The SM2 key type is serialized exactly like any other EC key type and differs only by the specific curve OID used inside the ASN1 structure, so both the EC and the SM2 keymgmt should intercept deserialization requests.

Do you think it would be possible to establish some priority order that works within a provider and across providers?

Ideally such a mechanism could allow to try to deserialize in the following scenario:

  1. External EC provider for P-256 hw module
  2. External EC provider for nation-specific EC (e.g. GOST)
  3. Default provider: try SM2
  4. Default provider: try EC

This order should be configurable by the user/system administrator and not coded inside the providers or libcrypto

@levitte
Copy link
Member Author

levitte commented Dec 18, 2019

I see two ways to handle EC vs SM2:

  1. Treat them as distinct key types. Deserializers will have to reject data that doesn't fit the criteria for the type, even if they can decode the incoming payload. Are SM2 keys identified with a distinct OID when wrapped in PKCS#8? In that case, this seems like the way to go, even if the internal structure used in our providers when operating on it is the same as for ECDSA et al.
    Incidently, this is what we already do in the legacy implementation of RSA-PSS.
  2. Treat them as the same, i.e see then as EC keys with some distinct parameters attached. This would be the choice if the PKCS#8 algorithm identifier is id-ecPublicKey for SM2 keys. Internally in the provider, we will still get a parameterised key structure, but the difference is that the operation algorithm will have to be able to support all variants.

The second choice makes me think that we might want to support recursive providers, i.e implementations that do their own fetching. Oh boy...

@levitte
Copy link
Member Author

levitte commented Dec 18, 2019

In the end, we need to look at PKCS#8 when looking at what types we face...

@romen
Copy link
Member

romen commented Dec 18, 2019

Unfortunately, SM2 keys use the same OID as EC keys.
But the approach in number 2 would mean that any provider capable of handling id-ecPubliKey keys must support every EC (or derived) algorithm.

For example if a user wants to load a provider to enable her shiny hw crypto accelerator (that only supports P-256) we don't want (unless configured otherwise) to lose the ability to handle other curves through the default provider or SM2, etc.

@levitte
Copy link
Member Author

levitte commented Dec 18, 2019

Oh, one thing that I'm forgetting here is that we currently don't have any provided deserializers. They will normally be used via the OSSL_STORE "file:" backend, and my plan is to do exactly what I think you request, to loop through all available deserializers until one successfully returns an unpacked object.

@romen
Copy link
Member

romen commented Dec 18, 2019

Same problem would arise if we carry on the plans to have national-based crypto in separate providers.

Let's say the brainpool curves are not in the default provider anymore but in a German specific provider, or the binary curves are moved to the legacy provider.

We really don't won't to repeat the mistake of having ENGINE/providers have to hijack the whole EC module for that!

@levitte
Copy link
Member Author

levitte commented Dec 18, 2019

It dawned on me that we're not as dependent on pkcs#8 as I was thinking, so we can choose to make SM2 keys a distinct key type for keymgmt, and teach our deserializers to check for specific parameters to decide if the payload is acceptable or not.
Thank you, your input also made it clearer how to treat RSA-PSS keys.

@levitte
Copy link
Member Author

levitte commented Dec 18, 2019

We really don't won't to repeat the mistake of having ENGINE/providers have to hijack the whole EC module for that!

Agreed. So I think that between the two choices in #10647 (comment), the first choice provides the possibility for distinct and less monolithic providers.

@levitte levitte mentioned this pull request Dec 21, 2019
22 tasks
@levitte levitte force-pushed the separate-keymgmt-type-take2 branch from 50b17a9 to 134cbaa Compare December 21, 2019 09:36
@levitte
Copy link
Member Author

levitte commented Dec 21, 2019

Rebased for better Travis results

@romen
Copy link
Member

romen commented Jan 5, 2020

Minus the nit mentioned in the previous review, the testing done so far in #10631 (comment) suggests everything seems to work fine in this PR.

@levitte levitte force-pushed the separate-keymgmt-type-take2 branch from 424e12a to 4332ef7 Compare January 5, 2020 18:21
@levitte
Copy link
Member Author

levitte commented Jan 5, 2020

Fixed, and rebased

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.

Apart from a small NIT it LGTM

This will allow keymgmt implementation for key types that need it to
specify the names of the diverse operation algorithms it can be used
with.  Currently, only one name per key type and operation is allowed.
The adaptation is to handle the case when key types and operations
that use these keys have different names.  For example, EC keys can be
used for ECDSA and ECDH.
This is very simply to allow the common case, where the KEYMGMT is
fetched first, and all names are needed at that time to secure that
they are found.
@levitte levitte force-pushed the separate-keymgmt-type-take2 branch from ee6b58f to 918e21e Compare January 7, 2020 08:35
@slontis slontis removed the approval: review pending This pull request needs review by a committer label Jan 7, 2020
@slontis slontis added the approval: done This pull request has the required number of approvals label Jan 7, 2020
@t8m t8m added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Jan 9, 2020
openssl-machine pushed a commit that referenced this pull request Jan 9, 2020
This will allow keymgmt implementation for key types that need it to
specify the names of the diverse operation algorithms it can be used
with.  Currently, only one name per key type and operation is allowed.

Reviewed-by: Shane Lontis <[email protected]>
(Merged from #10647)
openssl-machine pushed a commit that referenced this pull request Jan 9, 2020
The adaptation is to handle the case when key types and operations
that use these keys have different names.  For example, EC keys can be
used for ECDSA and ECDH.

Reviewed-by: Shane Lontis <[email protected]>
(Merged from #10647)
openssl-machine pushed a commit that referenced this pull request Jan 9, 2020
This is very simply to allow the common case, where the KEYMGMT is
fetched first, and all names are needed at that time to secure that
they are found.

Reviewed-by: Shane Lontis <[email protected]>
(Merged from #10647)
@levitte
Copy link
Member Author

levitte commented Jan 9, 2020

Merged.

e62a45b CORE & EVP: Specify OP_query_operation_name() for KEYMGMT
f23bc0b EVP: Adapt KEYEXCH, SIGNATURE and ASYM_CIPHER to handle key types better
2293032 PROV: Adjust the KEYMGMT name specs to include all names

@levitte levitte closed this Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Applies to master branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants