[WIP] PKCS#7 and CMS with provider side keys#11422
[WIP] PKCS#7 and CMS with provider side keys#11422levitte wants to merge 19 commits intoopenssl:masterfrom
Conversation
34bfb75 to
641193f
Compare
|
This is currently in WIP because I haven't yet modified the relevant provider implementations to respond to a requested algorithm identifier... let alone with key generation. |
|
Regardless of WIP or Travis failures, I'm interested in early comments on the ideas introduced in this PR |
crypto/cms/cms_env.c
Outdated
There was a problem hiding this comment.
So why #if 0 if its just going to be removed?
There was a problem hiding this comment.
This is my way to open that very question, i.e. comments, acclamations, etc welcome
There was a problem hiding this comment.
Probing seems reasonable. Again I'd like to hear from @beldmit.
There was a problem hiding this comment.
The approach proposed in the #else branch seems fine to me, we should probably just go ahead and drop this #if 0.
This is my way to open that very question, i.e. comments, acclamations, etc welcome
@levitte Hip hip hooray !!!
crypto/cms/cms_env.c
Outdated
There was a problem hiding this comment.
Sure.
New specification of Russian GOST allows more than one mechanism of the shared key transmission: KeyTransport, KeyAgreement, KeyEncryption. Not all of them are mandatory for implementation so this is a way to request whether the implementation used supports this mechanism.
There was a problem hiding this comment.
What I'm thinking is that each of these mechanisms use different methods, so probing with diverse inits should give just as good an answer, and releaves the need to keep details in sync for the provider author.
There was a problem hiding this comment.
It seems reasonable. @beldmit does this work for you?
e860355 to
2ca147b
Compare
|
https://tools.ietf.org/html/draft-housley-lamps-cms-update-alg-id-protect-00 (and list discussion thereof) may provide some additional clarity for the use of multiple algorithm IDs within CMS. |
|
Well. I have many failing tests for CMS. |
|
The diagnostics is |
|
I see two sets of problems for GOST.
Reordering the options (checking first for encryption, then for derivation) does the trick for GOST. Совместимые реализации, оперирующие сообщениями с типом данных «конверт данных», должны поддерживать следующий функционал при зашифровании и расшифровании: I'd suggest to leave it this way.
|
|
The 2nd problem is related to cms_pkey_is_ri_type_supported function. Now it returns the result of comparison with one exact value instead of checking for more than one in ctrl function. @levitte, feel free to ask for more information. I currently have a reasonable test installation for its work. |
4146d7a to
5558f2b
Compare
6ce64d3 to
1e3f62b
Compare
|
#11450 is in, I've rebased, now I just gotta finish up |
|
The travis failure seems relevant |
crypto/cms/cms_env.c
Outdated
There was a problem hiding this comment.
Should we raise some special error for this case?
There was a problem hiding this comment.
Because? Mind you, there are error codes to say that this and that other library had an error and serves as a trace... unfortunately, I recently discovered that those codes are messed up...
crypto/cms/cms_env.c
Outdated
There was a problem hiding this comment.
The approach proposed in the #else branch seems fine to me, we should probably just go ahead and drop this #if 0.
This is my way to open that very question, i.e. comments, acclamations, etc welcome
@levitte Hip hip hooray !!!
crypto/cms/cms_env.c
Outdated
crypto/cms/cms_sd.c
Outdated
There was a problem hiding this comment.
Should we raise a specific error for this case?
There was a problem hiding this comment.
This is a situation where we usually count on the called function to use that already...
|
Found the commands in history. |
Among others, this benefits PKCS#7 and CMS
This affects not only our SIGNATURE implementations, but also our KEYMGMT implementations.
ebc5472 to
05175ac
Compare
|
Is this still WIP? |
Yes. I'm currently testing it merged with #11328, I need to ensure that works first. |
|
However, please feel welcome to comment what you see! |
I had to do the same of thing with cms_RecipientInfo_kari_encrypt()
|
Oh... wow! The code that's in right now works flawlessly when merged with #11328 |
... heh, that says nothing. Since it's merged with EC key generation, and we only tell EC with key derivation, for which I've added an EVP_PKEY downgrade hack, it reduces the whole test suite to legacy key only. I wonder what happens if I merge in the DSA key generation PR, which is around, er, somewhere... yes, in #11303. |
There was one spot where this function would look at ctx->pmeth directly to determine if it's for RSASSA-PSS, which fails when presented with an EVP_PKEY_CTX holding a provider side key. Switching to use EVP_PKEY_is_a() should make things better.
slontis
left a comment
There was a problem hiding this comment.
Richard I am not going to block this PR,, but have some concerns about whether EVP_PKEY_get_params() should be public or even exist at all..
The one case where you are using it currently it uses a single parameter?
There were multiple reason(s) why I did not add it when I added the individual accessors.
(which I did send around in a mail when I was doing the work).
i.e:
- It has some issues related to BIGNUM's (to me this is a fairly significant issue).
- figuring out which params have been silently ignored may be important. The individual API's all set the return size internally. I see you have done this trick internally where you have used it. (A end user may not be so fortunate to understand this intricacy)
- When it fails it may be harder to figure out which entry failed.
|
I think we need to discuss the issues with OSSL_PARAM / BIGNUM elsewhere. Let's no hijack this PR (or any other PR) for that discussion. |
|
Elsewhere we have The BIGNUM concerns do need a separate discussion. Agreed that it will not happen here. BIGNUMs are difficult with the existing OSSL_PARAM framework. The framework mandates extra buffers of the right size before knowing what the actual values are. My opinion is that OSSL_PARAM is broken with respects to this :( I understand why we're byte reordering but it's pain for minimal benefit. Figuring out which OSSL_PARAMs have been used is a two directional affair, we will need to address this at some point, again not here. |
I think that sums it up. It comes down to lack of language support. |
|
... damnit. NOT hijack this PR, @levitte... |
We understood :) Time is too pressing to hold things up. |
|
Is this a topic for beta1...? |
|
Is this still relevant? IMO not. |
Provider side keys are a bit of a challenge for code that relies on being able to use EVP_PKEY_METHOD and EVP_PKEY_ASN1_METHOD functions directly.
However, it turns out that for the PKCS#7 and CMS, the controls and functions that existed specifically for them were all only used to create relevant
X509_ALGORwhen and where needed. This was mainly enabled by passinglibcryptostructures directly to the method code and letting them deal with those as they wish (potentially opening up for all sorts of more or less dirty hackery).With providers, it's not possible to share
libcryptointernal structures with the provider implementations, so we need another mechanism to achieve the objective, i.e. getting relevantX509_ALGORfor theEVP_PKEYor operation (via contexts) that's used.This mechanism was already introduced in 6f4b766, but wasn't explained in general terms (or at all), nor was it yet made for general use. The mechanism involves getting a DER encoded AlgorithmIdentifier from the provider implementation as an
OSSL_PARAMwith the name"algorithm-id"(macro OSSL_PKEY_PARAM_ALGORITHM_ID) and decoding it withd2i_X509_ALGOR()inlibcrypto. In this PR, we introduce general internal functionality to get theX509_ALGORfor any operation.Related to this is the question asked in #11413, where it turns out that CMS has its own set of standards for diverse cases when an
X509_ALGORis needed, which may or may not match what you'd normally get for X.509, so we need a different parameter name specifically for CMS; for the moment, I've chosen"algorithm-id:CMS"(macro OSSL_CMS_PARAM_ALGORITHM_ID). The CMS code is made to try that first, and uses the "normal" parameter name as a fallback (because some CMS standards have signature algorithms that match the X.509 standards, so might as well).Checklist