diff --git a/pkg/util/pubkey/jwk.go b/pkg/util/pubkey/jwk.go index d8b5c82..f5c0cb2 100644 --- a/pkg/util/pubkey/jwk.go +++ b/pkg/util/pubkey/jwk.go @@ -9,6 +9,7 @@ package pubkey import ( "crypto/ecdsa" "crypto/ed25519" + "crypto/rsa" "errors" "fmt" "reflect" @@ -33,7 +34,7 @@ func GetPublicKeyJWK(pubKey interface{}) (*jws.JWK, error) { } switch key := pubKey.(type) { - case ed25519.PublicKey: + case ed25519.PublicKey, *rsa.PublicKey: // handled automatically by gojose case *ecdsa.PublicKey: ecdsaPubKey, ok := pubKey.(*ecdsa.PublicKey) diff --git a/pkg/util/pubkey/jwk_test.go b/pkg/util/pubkey/jwk_test.go index bc85ff0..527da11 100644 --- a/pkg/util/pubkey/jwk_test.go +++ b/pkg/util/pubkey/jwk_test.go @@ -11,6 +11,7 @@ import ( "crypto/ed25519" "crypto/elliptic" "crypto/rand" + "crypto/rsa" "testing" "github.com/btcsuite/btcd/btcec/v2" @@ -29,6 +30,17 @@ func TestGetPublicKeyJWK(t *testing.T) { require.Equal(t, "EC", jwk.Kty) }) + t.Run("success RSA-2048", func(t *testing.T) { + privateKey, err := rsa.GenerateKey(rand.Reader, 2048) + require.NoError(t, err) + + jwk, err := GetPublicKeyJWK(&privateKey.PublicKey) + require.NoError(t, err) + require.NotEmpty(t, jwk) + require.Equal(t, "", jwk.Crv) + require.Equal(t, "RSA", jwk.Kty) + }) + t.Run("success EC secp256k1 ", func(t *testing.T) { privateKey, err := ecdsa.GenerateKey(btcec.S256(), rand.Reader) require.NoError(t, err)