mirror of
https://github.com/tailscale/tailscale.git
synced 2026-12-04 23:52:20 -08:00
feature/acme: generate ECDSA P-384 keys for ACME certificates and accounts
Migrate newly generated TLS certificate keys, TLS-ALPN-01 challenge keys, and ACME account keys from ECDSA P-256 to ECDSA P-384, following Chrome and Let's Encrypt recommendations to move away from P-256. Existing persisted P-256 ACME account keys continue to load unchanged. Updates #22893 Signed-off-by: James Tucker <[email protected]> Change-Id: I99a1e80c4a6ae35e17ceb42c16b9f843b06946de
This commit is contained in:
1 parent
aeb0f740f5
commit
4a83542d84
4 files changed
+70
-4
No files matched your search
@@ -542,7 +542,11 @@ func (e *extension) issueACMECert(ctx context.Context, b *ipnlocal.LocalBackend,
|
||||
if ch == nil {
|
||||
return nil, errors.New("tls-alpn-01 challenge not offered")
|
||||
}
|
||||
cert, err := ac.TLSALPN01ChallengeCert(ch.Token, az.Identifier.Value)
|
||||
challengeKey, err := ecdsa.GenerateKey(elliptic.P384(), rand.Reader)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("generating TLS-ALPN-01 challenge key: %w", err)
|
||||
}
|
||||
cert, err := ac.TLSALPN01ChallengeCert(ch.Token, az.Identifier.Value, xacme.WithKey(challengeKey))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("TLSALPN01ChallengeCert: %w", err)
|
||||
}
|
||||
@@ -595,7 +599,7 @@ func (e *extension) issueACMECert(ctx context.Context, b *ipnlocal.LocalBackend,
|
||||
}
|
||||
args.traceACME(order)
|
||||
|
||||
certPrivKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||
certPrivKey, err := ecdsa.GenerateKey(elliptic.P384(), rand.Reader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1384,6 +1384,13 @@ func TestAcmeKey_ConcurrentFirstCall(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("parsing persisted key: %v", err)
|
||||
}
|
||||
ecKey, ok := want.(*ecdsa.PrivateKey)
|
||||
if !ok {
|
||||
t.Fatalf("persisted key type = %T, want *ecdsa.PrivateKey", want)
|
||||
}
|
||||
if ecKey.Curve != elliptic.P384() {
|
||||
t.Errorf("persisted account key curve = %s, want P-384", ecKey.Curve.Params().Name)
|
||||
}
|
||||
wantPub, err := x509.MarshalPKIXPublicKey(want.Public())
|
||||
if err != nil {
|
||||
t.Fatalf("marshaling persisted pubkey: %v", err)
|
||||
@@ -1398,3 +1405,34 @@ func TestAcmeKey_ConcurrentFirstCall(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestAcmeKey_PreservesExistingP256 verifies that an existing persisted
|
||||
// P-256 ACME account key continues to be loaded without error or replacement.
|
||||
func TestAcmeKey_PreservesExistingP256(t *testing.T) {
|
||||
e := &extension{}
|
||||
cs := certStateStore{StateStore: new(mem.Store)}
|
||||
|
||||
p256Key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||
if err != nil {
|
||||
t.Fatalf("GenerateKey: %v", err)
|
||||
}
|
||||
var pemBuf bytes.Buffer
|
||||
if err := encodeECDSAKey(&pemBuf, p256Key); err != nil {
|
||||
t.Fatalf("encodeECDSAKey: %v", err)
|
||||
}
|
||||
if err := cs.WriteACMEKey(pemBuf.Bytes()); err != nil {
|
||||
t.Fatalf("WriteACMEKey: %v", err)
|
||||
}
|
||||
|
||||
got, err := e.acmeKey(cs)
|
||||
if err != nil {
|
||||
t.Fatalf("acmeKey: %v", err)
|
||||
}
|
||||
gotEC, ok := got.(*ecdsa.PrivateKey)
|
||||
if !ok {
|
||||
t.Fatalf("acmeKey returned %T, want *ecdsa.PrivateKey", got)
|
||||
}
|
||||
if !gotEC.Equal(p256Key) {
|
||||
t.Errorf("acmeKey returned a different key than the persisted P-256 key")
|
||||
}
|
||||
}
|
||||
@@ -380,7 +380,7 @@ func (e *extension) acmeKey(cs certStore) (crypto.Signer, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
privKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||
privKey, err := ecdsa.GenerateKey(elliptic.P384(), rand.Reader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"crypto/ecdsa"
|
||||
"crypto/elliptic"
|
||||
"crypto/rand"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
@@ -33,7 +34,7 @@ import (
|
||||
|
||||
func newTestACMEClient(t *testing.T, s *acmetest.Server) *xacme.Client {
|
||||
t.Helper()
|
||||
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||
key, err := ecdsa.GenerateKey(elliptic.P384(), rand.Reader)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -118,6 +119,29 @@ func TestIssueACMECertValidAuthorization(t *testing.T) {
|
||||
if _, err := cs.Read(domain, time.Now()); err != nil {
|
||||
t.Errorf("stored certificate does not read back: %v", err)
|
||||
}
|
||||
|
||||
tlsCert, err := tls.X509KeyPair(pair.CertPEM, pair.KeyPEM)
|
||||
if err != nil {
|
||||
t.Fatalf("X509KeyPair: %v", err)
|
||||
}
|
||||
ecPriv, ok := tlsCert.PrivateKey.(*ecdsa.PrivateKey)
|
||||
if !ok {
|
||||
t.Fatalf("private key type = %T, want *ecdsa.PrivateKey", tlsCert.PrivateKey)
|
||||
}
|
||||
if ecPriv.Curve != elliptic.P384() {
|
||||
t.Errorf("private key curve = %s, want P-384", ecPriv.Curve.Params().Name)
|
||||
}
|
||||
leaf, err := x509.ParseCertificate(tlsCert.Certificate[0])
|
||||
if err != nil {
|
||||
t.Fatalf("ParseCertificate: %v", err)
|
||||
}
|
||||
ecPub, ok := leaf.PublicKey.(*ecdsa.PublicKey)
|
||||
if !ok {
|
||||
t.Fatalf("leaf public key type = %T, want *ecdsa.PublicKey", leaf.PublicKey)
|
||||
}
|
||||
if ecPub.Curve != elliptic.P384() {
|
||||
t.Errorf("leaf public key curve = %s, want P-384", ecPub.Curve.Params().Name)
|
||||
}
|
||||
}
|
||||
|
||||
// TestIssueACMECertRetriesWithoutReplaces checks that a renewal order the
|
||||
|
||||
Reference in new issue
Block a user