66 "bytes"
77 "crypto"
88 "crypto/ecdsa"
9+ "crypto/ed25519"
910 "crypto/rsa"
1011 "crypto/tls"
1112 "crypto/x509"
@@ -555,7 +556,7 @@ func (b *Bundler) fetchIntermediates(certs []*x509.Certificate) (err error) {
555556
556557// Bundle takes an X509 certificate (already in the
557558// Certificate structure), a private key as crypto.Signer in one of the appropriate
558- // formats (i.e. *rsa.PrivateKey or *ecdsa.PrivateKey, or even a opaque key), using them to
559+ // formats (i.e. *rsa.PrivateKey, *ecdsa.PrivateKey or ed25519 .PrivateKey, or even a opaque key), using them to
559560// build a certificate bundle.
560561func (b * Bundler ) Bundle (certs []* x509.Certificate , key crypto.Signer , flavor BundleFlavor ) (* Bundle , error ) {
561562 log .Infof ("bundling certificate for %+v" , certs [0 ].Subject )
@@ -576,7 +577,6 @@ func (b *Bundler) Bundle(certs []*x509.Certificate, key crypto.Signer, flavor Bu
576577 if key != nil {
577578 switch {
578579 case cert .PublicKeyAlgorithm == x509 .RSA :
579-
580580 var rsaPublicKey * rsa.PublicKey
581581 if rsaPublicKey , ok = key .Public ().(* rsa.PublicKey ); ! ok {
582582 return nil , errors .New (errors .PrivateKeyError , errors .KeyMismatch )
@@ -592,15 +592,24 @@ func (b *Bundler) Bundle(certs []*x509.Certificate, key crypto.Signer, flavor Bu
592592 if cert .PublicKey .(* ecdsa.PublicKey ).X .Cmp (ecdsaPublicKey .X ) != 0 {
593593 return nil , errors .New (errors .PrivateKeyError , errors .KeyMismatch )
594594 }
595+ case cert .PublicKeyAlgorithm == x509 .Ed25519 :
596+ var ed25519PublicKey ed25519.PublicKey
597+ if ed25519PublicKey , ok = key .Public ().(ed25519.PublicKey ); ! ok {
598+ return nil , errors .New (errors .PrivateKeyError , errors .KeyMismatch )
599+ }
600+ if ! (bytes .Equal (cert .PublicKey .(ed25519.PublicKey ), ed25519PublicKey )) {
601+ return nil , errors .New (errors .PrivateKeyError , errors .KeyMismatch )
602+ }
595603 default :
596- return nil , errors .New (errors .PrivateKeyError , errors .NotRSAOrECC )
604+ return nil , errors .New (errors .PrivateKeyError , errors .NotRSAOrECCOrEd25519 )
597605 }
598606 } else {
599607 switch {
600608 case cert .PublicKeyAlgorithm == x509 .RSA :
601609 case cert .PublicKeyAlgorithm == x509 .ECDSA :
610+ case cert .PublicKeyAlgorithm == x509 .Ed25519 :
602611 default :
603- return nil , errors .New (errors .PrivateKeyError , errors .NotRSAOrECC )
612+ return nil , errors .New (errors .PrivateKeyError , errors .NotRSAOrECCOrEd25519 )
604613 }
605614 }
606615
0 commit comments