Skip to content

Comments

Implement domparam and key generation#10289

Merged
openssl-machine merged 5 commits intoopenssl:masterfrom
levitte:300-keygen
Mar 12, 2020
Merged

Implement domparam and key generation#10289
openssl-machine merged 5 commits intoopenssl:masterfrom
levitte:300-keygen

Conversation

@levitte
Copy link
Member

@levitte levitte commented Oct 29, 2019

This turned out to be a fairly big ordeal. To begin with, our libcrypto<->provider interface couldn't support the way things are done in the EVP_PKEY API in a sane manner, so this needed to be redesigned a bit.

Furthermore, domparam and key generation use an application callback to give the user some feedback when the key is created, and that support needs to be extended to providers. However, it would be very unsafe to just pass some random function pointer directly to the provider methods, so with some inspiration from BN_GENCB, I created a new callback type that is used by libcrypto to pass the necessary data to the provider, which then ends up calling an upcall that knows exactly how to handle that structure.

Please read the individual commits for more information.

NOTE: apart from making a key that can be used immediately, this functionality is of little use because we have no way of extracting key data to create PEM files from. That's a matter for another PR, and is also the reason why this PR is currently WIP / draft.

@mattcaswell mattcaswell self-assigned this Nov 1, 2019
@levitte levitte marked this pull request as ready for review November 1, 2019 10:06
@levitte levitte changed the title WIP: Implement domparam and key generation [Pending on other work] Implement domparam and key generation Nov 1, 2019
@levitte levitte changed the title [Pending on other work] Implement domparam and key generation [Pending on future work] Implement domparam and key generation Nov 1, 2019
@levitte levitte mentioned this pull request Nov 7, 2019
2 tasks
@levitte levitte changed the title [Pending on future work] Implement domparam and key generation [Pending #10390 + other upcoming work] Implement domparam and key generation Nov 8, 2019
@levitte levitte changed the title [Pending #10390 + other upcoming work] Implement domparam and key generation [Pending #10390, #10394 Implement domparam and key generation Nov 9, 2019
@levitte levitte changed the title [Pending #10390, #10394 Implement domparam and key generation [Pending #10390, #10394] Implement domparam and key generation Nov 9, 2019
@levitte levitte changed the title [Pending #10390, #10394] Implement domparam and key generation [Pending #10390, #10391, #10394] Implement domparam and key generation Nov 9, 2019
@levitte
Copy link
Member Author

levitte commented Nov 9, 2019

I just tried a merge of this with #10390, #10391 and #10394, and finally got what I wanted, provider backed key generation, as well as PEM output (through provided serializer):

: ; ./util/shlib_wrap.sh apps/openssl genpkey -algorithm rsa -pkeyopt rsa_keygen_bits:1024
...........................................................................................++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
........................................................................++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-----BEGIN PRIVATE KEY-----
MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANNFTX0F9zuojCSV
P1e2LKhLKaUMnicUWp4h9DR25jrfRczCeWVEFqFcKbYLxcr8VBuIiAdBRXgKSpfK
              [... protect the innocent ...]
Yg8osCBBb0s0e/M7qd6IrBr2MH7f7eaFEt5tgYnQMIk2wkyK5MRSgVIYSslCSBuc
tM60JFO49FJrFqo=
-----END PRIVATE KEY-----

@richsalz
Copy link
Contributor

richsalz commented Nov 9, 2019

That is very very cool!

@levitte levitte changed the title [Pending #10390, #10391, #10394] Implement domparam and key generation [Pending #10412, #10414, #10394] Implement domparam and key generation Nov 13, 2019
@levitte
Copy link
Member Author

levitte commented Nov 13, 2019

This is now adapted to depend on #10412 and #10414 instead of #10390 and #10391

@levitte levitte changed the title [Pending #10412, #10414, #10394] Implement domparam and key generation [Pending #10394] Implement domparam and key generation Nov 14, 2019
@levitte levitte changed the title [Pending #10394] Implement domparam and key generation [WIP, Pending #10394] Implement domparam and key generation Nov 19, 2019
@levitte
Copy link
Member Author

levitte commented Nov 19, 2019

I put this back in WIP. It needs DH and DSA implementations as well to be somewhat complete.

@levitte levitte added the branch: master Applies to master branch label Nov 21, 2019
slontis
slontis previously approved these changes Mar 10, 2020
@levitte levitte added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Mar 10, 2020
@slontis
Copy link
Member

slontis commented Mar 10, 2020

Something bad has happened in travis.

@richsalz
Copy link
Contributor

Something bad has happened in travis.

That sounds like the title for a great horror movie. :)

@slontis
Copy link
Member

slontis commented Mar 11, 2020

It is just a generated file issue with libcrypto.num.
EVP_PKEY_gen_set_params needs to be removed.
Should not require reapproval for this..

@slontis slontis mentioned this pull request Mar 11, 2020
2 tasks
@levitte levitte removed the approval: done This pull request has the required number of approvals label Mar 11, 2020
@levitte levitte changed the title Implement domparam and key generation [WIP] Implement domparam and key generation Mar 11, 2020
@levitte levitte changed the title [WIP] Implement domparam and key generation Implement domparam and key generation Mar 11, 2020
@levitte levitte added the approval: review pending This pull request needs review by a committer label Mar 11, 2020
@levitte levitte requested a review from slontis March 11, 2020 08:53
@levitte levitte dismissed slontis’s stale review March 11, 2020 08:54

Re-approval needed

@levitte
Copy link
Member Author

levitte commented Mar 11, 2020

@slontis, try #11303, with the slight mod I suggested there, on top of what's here now.

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.

LGTM

@levitte
Copy link
Member Author

levitte commented Mar 11, 2020

Even Travis seems happy

@levitte levitte added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Mar 12, 2020
@slontis slontis 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 Mar 12, 2020
levitte added 5 commits March 12, 2020 10:43
We introduce these dispatched functions:

-   OP_keymgmt_gen_init() to initialize the key object generation.
-   OP_keymgmt_gen_set_template() to set a template for key object
    generation.  The template is another key object, for example one
    with domain parameters.
-   OP_keymgmt_gen_set_params() to set other key object generation
    parameters.
-   OP_keymgmt_gen_settable_params() to find out what settable
    parameters there are.
-   OP_keymgmt_gen() to perform the key object generation.
-   OP_keymgmt_gen_cleanup() to clean up the key object generation.

Internal function for easy and consistent use of these ddispatched
functions are added.

Reviewed-by: Shane Lontis <[email protected]>
(Merged from openssl#10289)
The following functions are added:

EVP_PKEY_gen_set_params(), replacing the older EVP_PKEY_CTX_ctrl()
EVP_PKEY_gen(), replacing both EVP_PKEY_keygen() and EVP_PKEY_paramgen()

These functions are made to work together with already existing domparams
and key generation functionality: EVP_PKEY_CTX_new_provided(),
EVP_PKEY_paramgen_init(), EVP_PKEY_keygen_init(), etc.

Reviewed-by: Shane Lontis <[email protected]>
(Merged from openssl#10289)
This includes added support in legacy controls

Reviewed-by: Shane Lontis <[email protected]>
(Merged from openssl#10289)
There was a misunderstanding what it should return.  It should return
0 on internal error, but 1 even if the thing it tests fails (the error
is determined by |t->err|).

Reviewed-by: Shane Lontis <[email protected]>
(Merged from openssl#10289)
@openssl-machine openssl-machine merged commit f11a74e into openssl:master Mar 12, 2020
@levitte levitte deleted the 300-keygen branch March 12, 2020 09:46
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.

7 participants