Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
feat: support secp256k1 curve in KMS (#3411)
Browse files Browse the repository at this point in the history
This change adds secp256k1 keys support in the kms for the IEEE-P1363 format only.
DER format is not supported because the x509 package does not support this curve.
The framework does support the creation of an secp256k1 key with DER format, however storing it in the KMS is not supported.

closes #3410

Signed-off-by: Baha Shaaban <baha.shaaban@securekey.com>

Signed-off-by: Baha Shaaban <baha.shaaban@securekey.com>
  • Loading branch information
baha-ai committed Oct 21, 2022
1 parent 8b3a49f commit 368f53b
Show file tree
Hide file tree
Showing 31 changed files with 2,746 additions and 88 deletions.
33 changes: 33 additions & 0 deletions pkg/crypto/tinkcrypto/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/composite/ecdh"
"github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/composite/keyio"
ecdhpb "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/proto/ecdh_aead_go_proto"
"github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/secp256k1"
)

const testMessage = "test message"
Expand Down Expand Up @@ -238,6 +239,38 @@ func TestCrypto_SignVerify(t *testing.T) {
err = c.Verify(s, msg, badKH)
require.Error(t, err)
})

t.Run("test with secp256k1 signature", func(t *testing.T) {
derTemplate, err := secp256k1.DERKeyTemplate()
require.NoError(t, err)

kh, err := keyset.NewHandle(derTemplate)
require.NoError(t, err)

badKH, err := keyset.NewHandle(tinkaead.KMSEnvelopeAEADKeyTemplate("babdUrl", nil))
require.NoError(t, err)

c := Crypto{}
msg := []byte(testMessage)
s, err := c.Sign(msg, kh)
require.NoError(t, err)

// get corresponding public key handle to verify
pubKH, err := kh.Public()
require.NoError(t, err)

err = c.Verify(s, msg, pubKH)
require.NoError(t, err)

// verify with nil key handle - should fail
err = c.Verify(s, msg, nil)
require.Error(t, err)
require.Equal(t, errBadKeyHandleFormat, err)

// verify with bad key handle - should fail
err = c.Verify(s, msg, badKH)
require.Error(t, err)
})
}

func TestCrypto_ComputeMAC(t *testing.T) {
Expand Down
Loading

0 comments on commit 368f53b

Please sign in to comment.