From f48e8e4d075f86fe2e3ab42fe5b45a7ac089d30d Mon Sep 17 00:00:00 2001 From: Stas Dm Date: Thu, 15 Feb 2024 20:19:50 +0100 Subject: [PATCH 1/3] fix: did rsa create --- pkg/jws/jwk.go | 5 +++++ pkg/jwsutil/jws_test.go | 13 +++++++++++++ pkg/jwsutil/signature_test.go | 3 ++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/jws/jwk.go b/pkg/jws/jwk.go index ce9d45e..0c2f8b4 100644 --- a/pkg/jws/jwk.go +++ b/pkg/jws/jwk.go @@ -14,6 +14,11 @@ type JWK struct { Crv string `json:"crv"` X string `json:"x"` Y string `json:"y"` + N string `json:"n"` + E string `json:"e"` + D string `json:"d"` + P string `json:"p"` + Q string `json:"q"` Nonce string `json:"nonce,omitempty"` } diff --git a/pkg/jwsutil/jws_test.go b/pkg/jwsutil/jws_test.go index c2bede0..65c1116 100644 --- a/pkg/jwsutil/jws_test.go +++ b/pkg/jwsutil/jws_test.go @@ -11,6 +11,7 @@ import ( "crypto/ed25519" "crypto/elliptic" "crypto/rand" + "crypto/rsa" "encoding/base64" "errors" "fmt" @@ -253,6 +254,18 @@ func TestParseJWS_ED25519(t *testing.T) { require.Equal(t, jws, parsedJWS) } +func TestParseJWS_RSA(t *testing.T) { + key, err := rsa.GenerateKey(rand.Reader, 2048) + require.NoError(t, err) + + jwk, err := getPublicKeyJWK(&key.PublicKey) + require.NoError(t, err) + + require.Equal(t, "RSA", jwk.Kty) + require.NotEmpty(t, jwk.E) + require.NotEmpty(t, jwk.N) +} + func TestIsCompactJWS(t *testing.T) { require.True(t, IsCompactJWS("a.b.c")) require.False(t, IsCompactJWS("a.b")) diff --git a/pkg/jwsutil/signature_test.go b/pkg/jwsutil/signature_test.go index e0b03fe..5959464 100644 --- a/pkg/jwsutil/signature_test.go +++ b/pkg/jwsutil/signature_test.go @@ -12,6 +12,7 @@ import ( "crypto/ed25519" "crypto/elliptic" "crypto/rand" + "crypto/rsa" "fmt" "reflect" "testing" @@ -257,7 +258,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 := pubKey.(*ecdsa.PublicKey) From 2f59072bc07d284eefe58d5148cca4e352c5cc63 Mon Sep 17 00:00:00 2001 From: Stas Dm Date: Thu, 15 Feb 2024 20:23:00 +0100 Subject: [PATCH 2/3] fix: delta --- pkg/jws/jwk.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/jws/jwk.go b/pkg/jws/jwk.go index 0c2f8b4..1a519e0 100644 --- a/pkg/jws/jwk.go +++ b/pkg/jws/jwk.go @@ -16,9 +16,6 @@ type JWK struct { Y string `json:"y"` N string `json:"n"` E string `json:"e"` - D string `json:"d"` - P string `json:"p"` - Q string `json:"q"` Nonce string `json:"nonce,omitempty"` } From f25c1c117a06dddd0115cf4cc43fc6a4e80c96cb Mon Sep 17 00:00:00 2001 From: Stas Dm Date: Thu, 15 Feb 2024 20:26:18 +0100 Subject: [PATCH 3/3] fix: op side --- pkg/jws/jwk.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/jws/jwk.go b/pkg/jws/jwk.go index 1a519e0..5790b72 100644 --- a/pkg/jws/jwk.go +++ b/pkg/jws/jwk.go @@ -14,8 +14,8 @@ type JWK struct { Crv string `json:"crv"` X string `json:"x"` Y string `json:"y"` - N string `json:"n"` - E string `json:"e"` + N string `json:"n,omitempty"` + E string `json:"e,omitempty"` Nonce string `json:"nonce,omitempty"` }