Skip to content
This repository has been archived by the owner on Aug 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #339 from fqutishat/update
Browse files Browse the repository at this point in the history
feat: add ECDSASecp256k1IEEEP1363 to aws service
  • Loading branch information
fqutishat authored Sep 27, 2022
2 parents 06e5709 + 05fc013 commit 412f152
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkg/aws/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,16 @@ func (s *Service) Sign(msg []byte, kh interface{}) ([]byte, error) {
return nil, err
}

describeKey, err := s.client.DescribeKey(&kms.DescribeKeyInput{KeyId: &keyID})
if err != nil {
return nil, err
}

input := &kms.SignInput{
KeyId: aws.String(keyID),
Message: msg,
MessageType: aws.String("RAW"),
SigningAlgorithm: aws.String("ECDSA_SHA_256"),
SigningAlgorithm: describeKey.KeyMetadata.SigningAlgorithms[0],
}

result, err := s.client.Sign(input)
Expand Down Expand Up @@ -158,12 +163,17 @@ func (s *Service) Verify(signature, msg []byte, kh interface{}) error {
return err
}

describeKey, err := s.client.DescribeKey(&kms.DescribeKeyInput{KeyId: &keyID})
if err != nil {
return err
}

input := &kms.VerifyInput{
KeyId: aws.String(keyID),
Message: msg,
MessageType: aws.String("RAW"),
Signature: signature,
SigningAlgorithm: aws.String("ECDSA_SHA_256"),
SigningAlgorithm: describeKey.KeyMetadata.SigningAlgorithms[0],
}

_, err = s.client.Verify(input)
Expand All @@ -184,6 +194,8 @@ func (s *Service) Create(kt arieskms.KeyType) (string, interface{}, error) {
keySpec = kms.KeySpecEccNistP384
case arieskms.ECDSAP521DER, arieskms.NISTP521ECDHKW:
keySpec = kms.KeySpecEccNistP521
case arieskms.ECDSASecp256k1IEEEP1363:
keySpec = kms.KeySpecEccSecgP256k1
default:
return "", nil, fmt.Errorf("key not supported %s", kt)
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/aws/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func TestSign(t *testing.T) {
return &kms.SignOutput{
Signature: []byte("data"),
}, nil
}, describeKeyFunc: func(input *kms.DescribeKeyInput) (*kms.DescribeKeyOutput, error) {
return &kms.DescribeKeyOutput{
KeyMetadata: &kms.KeyMetadata{
SigningAlgorithms: []*string{aws.String("ECDSA_SHA_256")},
},
}, nil
}}

signature, err := svc.Sign([]byte("msg"),
Expand All @@ -59,6 +65,12 @@ func TestSign(t *testing.T) {

svc.client = &mockAWSClient{signFunc: func(input *kms.SignInput) (*kms.SignOutput, error) {
return nil, fmt.Errorf("failed to sign")
}, describeKeyFunc: func(input *kms.DescribeKeyInput) (*kms.DescribeKeyOutput, error) {
return &kms.DescribeKeyOutput{
KeyMetadata: &kms.KeyMetadata{
SigningAlgorithms: []*string{aws.String("ECDSA_SHA_256")},
},
}, nil
}}

_, err = svc.Sign([]byte("msg"),
Expand Down Expand Up @@ -316,6 +328,12 @@ func TestVerify(t *testing.T) {

svc.client = &mockAWSClient{verifyFunc: func(input *kms.VerifyInput) (*kms.VerifyOutput, error) {
return &kms.VerifyOutput{}, nil
}, describeKeyFunc: func(input *kms.DescribeKeyInput) (*kms.DescribeKeyOutput, error) {
return &kms.DescribeKeyOutput{
KeyMetadata: &kms.KeyMetadata{
SigningAlgorithms: []*string{aws.String("ECDSA_SHA_256")},
},
}, nil
}}

err = svc.Verify([]byte("sign"), []byte("data"),
Expand All @@ -336,6 +354,12 @@ func TestVerify(t *testing.T) {

svc.client = &mockAWSClient{verifyFunc: func(input *kms.VerifyInput) (*kms.VerifyOutput, error) {
return nil, fmt.Errorf("failed to verify")
}, describeKeyFunc: func(input *kms.DescribeKeyInput) (*kms.DescribeKeyOutput, error) {
return &kms.DescribeKeyOutput{
KeyMetadata: &kms.KeyMetadata{
SigningAlgorithms: []*string{aws.String("ECDSA_SHA_256")},
},
}, nil
}}

err = svc.Verify([]byte("data"), []byte("msg"),
Expand Down

0 comments on commit 412f152

Please sign in to comment.