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

proposal: crypto/x509: support extracting X25519 public keys from certificates #70667

Open
EdSchouten opened this issue Dec 3, 2024 · 5 comments
Labels
Proposal Proposal-Crypto Proposal related to crypto packages or other security issues
Milestone

Comments

@EdSchouten
Copy link

EdSchouten commented Dec 3, 2024

Proposal Details

Even though X25519 key pairs (not to be confused with Ed25519 key pairs) can't be used to establish TLS connections, there are still cases in which you want to use them in combination with X.509 certificates. For example, if X25519 is used to perform public key authenticated encryption (e.g., NaCl's crypto_box), X.509 certificates may be used to authenticate the identity of the peer before encrypting/decrypting. RFC 8410 added the ability to embed X25519 public keys into X.509 certificates for such use cases.

Right now x509.ParseCertificate() completes successfully when presented with a certificate containing an X25519 public key. Unfortunately, it does end up discarding the public key, as Certificate.PublicKeyAlgorithm and Certificate.PublicKey will be set to UnknownPublicKeyAlgorithm and nil, respectively.

The proposal here is to actually let x509.ParseCertificate() extract the public key from the certificate and return it in the form of an *ecdh.PublicKey. The PublicKeyAlgorithm enumeration will be extended to include an additional element for this public key algorithm, which will simply be called X25519.

Code changes can be found here: https://go-review.googlesource.com/c/go/+/632875

@gabyhelp
Copy link

gabyhelp commented Dec 3, 2024

@gopherbot gopherbot added this to the Proposal milestone Dec 3, 2024
@ianlancetaylor ianlancetaylor added the Proposal-Crypto Proposal related to crypto packages or other security issues label Dec 3, 2024
@ianlancetaylor ianlancetaylor moved this to Incoming in Proposals Dec 3, 2024
@ianlancetaylor
Copy link
Member

CC @golang/security

@rolandshoemaker
Copy link
Member

Per the crypto/x509 package documentation "the primary goal of the package is to provide compatibility with the publicly trusted TLS certificate ecosystem and its policies and constraints".

Since X25519 is not supported by TLS, and X25519 keys are not allowed in certificates issued by publicly trusted CAs, per the CABF baseline requirements, I'm not sure there is a strong reason for us to add explicit support for these certificates.

As you say, ParseCertificate does parse these certificates. If you do need to use them for whatever purpose, you can still manually extract the key from the Certificate.RawSubjectPublicKeyInfo field and use it for your purposes. This is slightly more complex, but I think a worthwhile trade off to prevent people from accidentally misusing these certificates for purposes they are not intended for.

@FiloSottile
Copy link
Contributor

We could probably include an Example for how to use cryptobyte to extract a public key from RawSubjectPublicKeyInfo.

@EdSchouten
Copy link
Author

That sounds fine to me. That said, I am also interested in generating certificates. It looks like CreateCertificate() doesn’t respect RawSubjectPublicKeyInfo right now. Would it make sense to extend CreateCertificate() to do so?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Proposal Proposal-Crypto Proposal related to crypto packages or other security issues
Projects
Status: Incoming
Development

No branches or pull requests

6 participants