Skip to content

Commit be65809

Browse files
authored
Support Ed25519 signature algorithm (#248)
This adds support for the Ed25519 signature algorithm which is supported by Go, but was not fully plumbed through in go-spiffe. Signed-off-by: Lorenz Brun <[email protected]>
1 parent 16eb51c commit be65809

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

v2/internal/cryptoutil/keys.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package cryptoutil
22

33
import (
4+
"bytes"
45
"crypto"
56
"crypto/ecdsa"
7+
"crypto/ed25519"
68
"crypto/rsa"
79
"fmt"
810
)
@@ -15,6 +17,9 @@ func PublicKeyEqual(a, b crypto.PublicKey) (bool, error) {
1517
case *ecdsa.PublicKey:
1618
ecdsaPublicKey, ok := b.(*ecdsa.PublicKey)
1719
return ok && ECDSAPublicKeyEqual(a, ecdsaPublicKey), nil
20+
case ed25519.PublicKey:
21+
ed25519PublicKey, ok := b.(ed25519.PublicKey)
22+
return ok && bytes.Equal(a, ed25519PublicKey), nil
1823
default:
1924
return false, fmt.Errorf("unsupported public key type %T", a)
2025
}

v2/svid/jwtsvid/svid_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package jwtsvid_test
33
import (
44
"crypto"
55
"crypto/ecdsa"
6+
"crypto/ed25519"
67
"crypto/elliptic"
78
"crypto/rand"
89
"crypto/rsa"
@@ -502,6 +503,8 @@ func getSignerAlgorithm(signer crypto.Signer) (jose.SignatureAlgorithm, error) {
502503
default:
503504
return "", fmt.Errorf("unable to determine signature algorithm for EC public key size %d", params.BitSize)
504505
}
506+
case ed25519.PublicKey:
507+
return jose.EdDSA, nil
505508
default:
506509
return "", fmt.Errorf("unable to determine signature algorithm for public key type %T", publicKey)
507510
}

v2/svid/x509svid/svid.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package x509svid
22

33
import (
4+
"bytes"
45
"crypto"
56
"crypto/ecdsa"
7+
"crypto/ed25519"
68
"crypto/rsa"
79
"crypto/x509"
810
"os"
@@ -229,6 +231,9 @@ func keyMatches(privateKey crypto.PrivateKey, publicKey crypto.PublicKey) (bool,
229231
case *ecdsa.PrivateKey:
230232
ecdsaPublicKey, ok := publicKey.(*ecdsa.PublicKey)
231233
return ok && ecdsaPublicKeyEqual(&privateKey.PublicKey, ecdsaPublicKey), nil
234+
case ed25519.PrivateKey:
235+
ed25519PublicKey, ok := publicKey.(ed25519.PublicKey)
236+
return ok && bytes.Equal(privateKey.Public().(ed25519.PublicKey), ed25519PublicKey), nil
232237
default:
233238
return false, errs.New("unsupported private key type %T", privateKey)
234239
}

0 commit comments

Comments
 (0)