Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pki: select appropriate hash algorithm for ecdsa signed certificates #11006

Closed
oncilla opened this issue Feb 25, 2021 · 10 comments · Fixed by #11216
Closed

pki: select appropriate hash algorithm for ecdsa signed certificates #11006

oncilla opened this issue Feb 25, 2021 · 10 comments · Fixed by #11216

Comments

@oncilla
Copy link
Contributor

oncilla commented Feb 25, 2021

Is your feature request related to a problem? Please describe.

Currently, when issuing certificates, vault always sets the signature algorithm to ECDSAWithSHA256 if an ecdsa key is used.
The key length is not taken into consideration:

case ECPrivateKey:
certTemplate.SignatureAlgorithm = x509.ECDSAWithSHA256

case "ec":
certTemplate.SignatureAlgorithm = x509.ECDSAWithSHA256

The BSI recommendations (section 4.2) are to use a hash size of the same length as the key size.

The Mozilla root store policy (section 5.1.2) even forbids ECDSAWithSHA256 for a key of length 384.

Describe the solution you'd like

Instead of setting the SignatureAlgorithm explicitly in the certificate template, vault should leave the SignatureAlgorithm unspecified. The x509 library will select the appropriate algorithm:

https://github.com/golang/go/blob/37ca84a9cd6a8a76dfe91263a17d2b92b17a24b3/src/crypto/x509/x509.go#L2024-L2038

Alternatively, the pki engine could be extended to take the hash algorithm as input, similar to transit

Describe alternatives you've considered

N/A

Explain any additional use-cases

I would like to be able to issue certificates with a p384 or a p521 key and use the appropriate hash algorithm.

Additional context

BSI:

image

Mozilla:

image

oncilla added a commit to oncilla/vault that referenced this issue Mar 26, 2021
Select the appropriate signature algorithm for certificates signed
with an ECDSA private key.

The algorithm is selected based on the curve:

- P-256 -> x509.ECDSAWithSHA256
- P-384 -> x509.ECDSAWithSHA384
- P-521 -> x509.ECDSAWithSHA512
- Other -> x509.ECDSAWithSHA256

fixes hashicorp#11006
@vikramchhibber
Copy link

Hi,

Do we have any update on this? My certificate is getting signed using ecdsa-with-SHA256 and I don't know how to set it to ecdsa-with-SHA384.

The intermediate certificate that I have written to vault is using ecdsa-with-SHA384.

I am using vault version 1.8.0.

Thanks

@oncilla
Copy link
Contributor Author

oncilla commented Sep 24, 2021

@HridoyRoy @hsimon-hashicorp How can we proceed with this issue?

@hsimon-hashicorp
Copy link
Contributor

Hi @oncilla and @vikramchhibber - I am asking the engineering team for guidance on this issue. Thanks for your patience!

@vikramchhibber
Copy link

Thanks @HridoyRoy @hsimon-hashicorp.

We see that some changes related to this got merged recently
49c3db0#diff-fb3974bdeab0812abc491ff49b027b88330f4d357be89f7d9b227b3d39682326

Is it possible to have these changes in coming 1.9.x release?

Regards

@oncilla
Copy link
Contributor Author

oncilla commented Oct 6, 2021

That change allows to implement the correct behavior by explicitly setting the signature_bits for a subset of the endpoints.
But for example sign-certificate is not covered by this AFICT.

Furthermore, from a UX perspective, this is not very nice. If I create a CSR for a 384 bit ecdsa key, it should just use sha384 by default, as this is the only "reasonable" value in the first place.

@vikramchhibber
Copy link

Thanks @oncilla.
@hsimon-hashicorp do you have any update?

oncilla added a commit to oncilla/vault that referenced this issue Oct 19, 2021
Select the appropriate signature algorithm for certificates signed
with an ECDSA private key.

The algorithm is selected based on the curve:

- P-256 -> x509.ECDSAWithSHA256
- P-384 -> x509.ECDSAWithSHA384
- P-521 -> x509.ECDSAWithSHA512
- Other -> x509.ECDSAWithSHA256

fixes hashicorp#11006
@oncilla
Copy link
Contributor Author

oncilla commented Oct 19, 2021

@vikramchhibber It looks like #11216 is finally progressing. 🤞 it will be part of a release soon.

oncilla added a commit to oncilla/vault that referenced this issue Nov 3, 2021
Select the appropriate signature algorithm for certificates signed
with an ECDSA private key.

The algorithm is selected based on the curve:

- P-256 -> x509.ECDSAWithSHA256
- P-384 -> x509.ECDSAWithSHA384
- P-521 -> x509.ECDSAWithSHA512
- Other -> x509.ECDSAWithSHA256

fixes hashicorp#11006
victorr pushed a commit that referenced this issue Nov 4, 2021
* certutil: select appropriate hash algorithm for ECDSA signature

Select the appropriate signature algorithm for certificates signed
with an ECDSA private key.

The algorithm is selected based on the curve:

- P-256 -> x509.ECDSAWithSHA256
- P-384 -> x509.ECDSAWithSHA384
- P-521 -> x509.ECDSAWithSHA512
- Other -> x509.ECDSAWithSHA256

fixes #11006
@victorr
Copy link
Contributor

victorr commented Nov 4, 2021

Hi @oncilla, I have merged the PR for your fix for this issue. I will make sure that the fix is included in the upcoming 1.9 release. I want to thank you for the great job you have done with this PR, it is very much appreciated.

I'm aware that you have at least one more PR in review, I will be taking a look at it soon.

@vikramchhibber
Copy link

Thank you @oncilla and @victorr . Really appreciated.

victorr pushed a commit that referenced this issue Nov 9, 2021
* certutil: select appropriate hash algorithm for ECDSA signature

Select the appropriate signature algorithm for certificates signed
with an ECDSA private key.

The algorithm is selected based on the curve:

- P-256 -> x509.ECDSAWithSHA256
- P-384 -> x509.ECDSAWithSHA384
- P-521 -> x509.ECDSAWithSHA512
- Other -> x509.ECDSAWithSHA256

fixes #11006
@victorr
Copy link
Contributor

victorr commented Nov 9, 2021

Please note that this fix did not make it into Vault 1.9.0-rc1, but it will likely make it to Vault 1.9.0.

victorr pushed a commit that referenced this issue Nov 9, 2021
* certutil: select appropriate hash algorithm for ECDSA signature

Select the appropriate signature algorithm for certificates signed
with an ECDSA private key.

The algorithm is selected based on the curve:

- P-256 -> x509.ECDSAWithSHA256
- P-384 -> x509.ECDSAWithSHA384
- P-521 -> x509.ECDSAWithSHA512
- Other -> x509.ECDSAWithSHA256

fixes #11006
victorr added a commit that referenced this issue Nov 9, 2021
…) (#13096)

* certutil: select appropriate hash algorithm for ECDSA signature

Select the appropriate signature algorithm for certificates signed
with an ECDSA private key.

The algorithm is selected based on the curve:

- P-256 -> x509.ECDSAWithSHA256
- P-384 -> x509.ECDSAWithSHA384
- P-521 -> x509.ECDSAWithSHA512
- Other -> x509.ECDSAWithSHA256

fixes #11006

Co-authored-by: Dominik Roos <domi.roos@gmail.com>
qk4l pushed a commit to qk4l/vault that referenced this issue Feb 4, 2022
…icorp#11216)

* certutil: select appropriate hash algorithm for ECDSA signature

Select the appropriate signature algorithm for certificates signed
with an ECDSA private key.

The algorithm is selected based on the curve:

- P-256 -> x509.ECDSAWithSHA256
- P-384 -> x509.ECDSAWithSHA384
- P-521 -> x509.ECDSAWithSHA512
- Other -> x509.ECDSAWithSHA256

fixes hashicorp#11006
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants