Skip to content

Comments

APPS: simplify x509 cert generation; allow pubkey input options to read private key#19076

Closed
DDvO wants to merge 3 commits intoopenssl:masterfrom
siemens:simplify_x509_cert_gen
Closed

APPS: simplify x509 cert generation; allow pubkey input options to read private key#19076
DDvO wants to merge 3 commits intoopenssl:masterfrom
siemens:simplify_x509_cert_gen

Conversation

@DDvO
Copy link
Contributor

@DDvO DDvO commented Aug 27, 2022

When reviewing the addition to test/smime-certs/mksmime-certs.sh by #18567,
I noticed again that producing certs using openssl x509 is still needlessly cumbersome.
While there are already abbreviations for the case of self-issued (including self-signed) certs,
for other certs (produced with the -CA option) one is so far forced to generate a cert request first.
It turns out this was simply because is was not possible to combine the -key option with -CA.

Update: Due to the comments by @vdukhovni, changed the solution to allow reading a private key when a public key is expected. This enables conveniently using the -force_pubkey option with -CA.

This PR adds the missing feature and makes use of the simplification in mksmime-certs.sh.
It also adds a test case for the new feature in 25-test_x509.t.

On this occasion, also clean up the key input options of other apps such as pkey.

On this occasion it also cleans up mksmime-certs.sh, speeds up its cert generation by not freshly generating RSA and DSA keys, and fixes its generation of inconsistent key usages for non-RSA certs.

  • documentation is added or updated
  • tests are added or updated

@DDvO DDvO added branch: master Applies to master branch approval: review pending This pull request needs review by a committer approval: otc review pending triaged: bug The issue/pr is/fixes a bug triaged: feature The issue/pr requests/adds a feature triaged: refactor The issue/pr requests/implements refactoring triaged: cleanup The issue/pr deals with cleanup of comments/docs not altering code significantly labels Aug 27, 2022
@DDvO DDvO added this to the 3.1.0 milestone Aug 27, 2022
@t8m t8m added triaged: refactor The issue/pr requests/implements refactoring and removed triaged: bug The issue/pr is/fixes a bug triaged: refactor The issue/pr requests/implements refactoring triaged: cleanup The issue/pr deals with cleanup of comments/docs not altering code significantly labels Aug 29, 2022
@DDvO
Copy link
Contributor Author

DDvO commented Sep 20, 2022

Ping @openssl/committers for 2nd review.

Copy link
Contributor

@tmshort tmshort left a comment

Choose a reason for hiding this comment

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

Other than a wishy-washy word in the documentation, looks ok to me.

@t8m
Copy link
Member

t8m commented Sep 22, 2022

@tmshort please reconfirm

@tmshort tmshort 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 Sep 22, 2022
@tmshort
Copy link
Contributor

tmshort commented Sep 22, 2022

reconfirm

@vdukhovni
Copy link

With -CA, it seems that the only part of the -key file that is used is the public component. If so, it seems that this should support (or require) a public key, rather than a private key. After all, if a CA is signing a certificate, why should the subject's private key be required???

@DDvO
Copy link
Contributor Author

DDvO commented Sep 22, 2022

With -CA, it seems that the only part of the -key file that is used is the public component.

Right.

If so, it seems that this should support (or require) a public key, rather than a private key.
After all, if a CA is signing a certificate, why should the subject's private key be required???

It's still good to support a private key input because for many scenarios it is available anyway (and the public portion can be derived automatically from it) and it is typically easier to handle (at least at the openssl CLI level) than a file containing just a public key.

Yet good thought that we should offer also the possibility to directly provide a file with a public key.
In this case the existing -force_pubkey option could simply be reused.
If you like, I can provide a follow-up PR for this.

@beldmit
Copy link
Member

beldmit commented Sep 22, 2022

So don't we get a mixed semantics for the -key option in case when your patch is applied?

@vdukhovni
Copy link

Ideally, the -key option would load either a private key or public key whichever is provided, and then extract the public part if a private key is provided. In other words, make the "user experience" as seamless as possible.

In any case, think about what is the least surprising (most natural) interface, and do that. Sure, this could be a followup PR, if you don't want to reopen reviews of the work so far. I'd be tempted to just amend this one, it is not a large PR. Your (and the other reviewers') call.

@DDvO
Copy link
Contributor Author

DDvO commented Sep 22, 2022

So don't we get a mixed semantics for the -key option in case when your patch is applied?

With the current state of the PR, the -key argument must be a private key file.

Ideally, the -key option would load either a private key or public key whichever is provided, and then extract the public part if a private key is provided. In other words, make the "user experience" as seamless as possible.

Interesting idea.
Is there already any other openssl command option that supports reading a file that contains a public or private key?

In any case, think about what is the least surprising (most natural) interface, and do that. Sure, this could be a followup PR, if you don't want to reopen reviews of the work so far. I'd be tempted to just amend this one, it is not a large PR. Your (and the other reviewers') call.

I was concerned exactly with this point, since the approval is already done.
@t8m and @tmshort, what do you think?

@vdukhovni
Copy link

Interesting idea.
Is there already any other openssl command option that supports reading a file that contains a public or private key?

I can't think of one offhand, but in principle any command that expects a public key should be willing to read a private key instead, and extract the public key from that. That would be a general UI improvement.

@vdukhovni
Copy link

In this case, the option's expected data would depend on other options (-CA changes the semantics of -key). Is that natural or surprising? Should some other option actually be used, leaving -key as incompatible with -CA?

These questions perhaps mean that the PR should not immediately be merged. We should at least decide what the UI should look like long-term, and then perhaps merge this PR, with other PRs to follow, or amend it as seems best.

One way or another, when all we want is a public key, it should be possible to specify a file with just the public key. Whether that's a separate public-key-only option, or a combo option that sometimes wants a private key, and other times a public key.

Please think through what a user might expect in terms of behaviour, and what can be most clearly explained in the documentation, ...

@openssl-machine
Copy link
Collaborator

24 hours has passed since 'approval: done' was set, but as this PR has been updated in that time the label 'approval: ready to merge' is not being automatically set. Please review the updates and set the label manually.

@DDvO DDvO changed the title APPS: simplify x509 cert generation APPS: simplify x509 cert generation; allow pubkey input options to read private key Sep 24, 2022
@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 123 days ago

@t8m t8m removed this from the 3.1.0 milestone Jan 26, 2023
@DDvO DDvO added the tests: present The PR has suitable tests present label Feb 24, 2023
@DDvO DDvO force-pushed the simplify_x509_cert_gen branch from dc5f448 to a1d1fc7 Compare February 24, 2023 12:31
@DDvO
Copy link
Contributor Author

DDvO commented Feb 24, 2023

Rebased to fix merge conflicts.

@t8m can you reapprove?

@DDvO
Copy link
Contributor Author

DDvO commented Feb 24, 2023

There is an unrelated CI failure for doc-nits:

/usr/bin/perl ./util/find-doc-nits -c -n -l -e
doc/man3/CMS_add0_cert.pod:1: Section missing in CMS_sign_ex()
doc/man3/CMS_add0_cert.pod:1: Section missing in CMS_sign()
doc/man3/CMS_add0_cert.pod:1: Section missing in CMS_verify()
doc/man3/CMS_add0_cert.pod:1: Section missing in CMS_verify()

is unrelated; fix for that is in #20369.

@DDvO DDvO force-pushed the simplify_x509_cert_gen branch from a1d1fc7 to b33d756 Compare February 24, 2023 15:42
@DDvO DDvO requested a review from vdukhovni February 24, 2023 15:43
@DDvO
Copy link
Contributor Author

DDvO commented Feb 27, 2023

Rebased again, just to get rid of the above unrelated CI failure message.

@t8m t8m requested a review from beldmit March 6, 2023 19:08
@beldmit
Copy link
Member

beldmit commented Mar 6, 2023

LGTM

@DDvO
Copy link
Contributor Author

DDvO commented Mar 9, 2023

LGTM

Thank you @beldmit for this statement.
Can you please make it formal and accordingly set approval:done ?

@beldmit beldmit 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 9, 2023
@beldmit
Copy link
Member

beldmit commented Mar 9, 2023

Sorry, missed it

@t8m
Copy link
Member

t8m commented Mar 9, 2023

Sorry, missed it

It would be nice to also do the formal approval on review changes tab.

Copy link
Member

@beldmit beldmit left a comment

Choose a reason for hiding this comment

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

LGTM

@beldmit
Copy link
Member

beldmit commented Mar 9, 2023

@t8m done

@openssl-machine
Copy link
Collaborator

24 hours has passed since 'approval: done' was set, but as this PR has been updated in that time the label 'approval: ready to merge' is not being automatically set. Please review the updates and set the label manually.

@DDvO DDvO 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 13, 2023
openssl-machine pushed a commit that referenced this pull request Mar 14, 2023
Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Dmitry Belyavskiy <[email protected]>
Reviewed-by: David von Oheimb <[email protected]>
(Merged from #19076)
openssl-machine pushed a commit that referenced this pull request Mar 14, 2023
…t generation

Also remove inconsistent key usages from non-RSA certs.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Dmitry Belyavskiy <[email protected]>
Reviewed-by: David von Oheimb <[email protected]>
(Merged from #19076)
openssl-machine pushed a commit that referenced this pull request Mar 14, 2023
Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Dmitry Belyavskiy <[email protected]>
Reviewed-by: David von Oheimb <[email protected]>
(Merged from #19076)
@DDvO
Copy link
Contributor Author

DDvO commented Mar 14, 2023

Merged - thanks @t8m, @tmshort, @vdukhovni, and @beldmit for your reviews and approvals.

@DDvO DDvO closed this Mar 14, 2023
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 tests: present The PR has suitable tests present triaged: feature The issue/pr requests/adds a feature triaged: refactor The issue/pr requests/implements refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants