Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node: add amazon kms and benchmark signers #4148

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion node/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ require (
require (
github.com/CosmWasm/wasmd v0.30.0
github.com/algorand/go-algorand-sdk v1.23.0
github.com/aws/aws-sdk-go v1.55.5
github.com/aws/aws-sdk-go-v2/config v1.15.1
github.com/aws/aws-sdk-go-v2/service/kms v1.37.2
github.com/benbjohnson/clock v1.3.5
github.com/blendle/zapdriver v1.3.1
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
Expand Down Expand Up @@ -84,7 +87,16 @@ require (
github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect
github.com/armon/go-metrics v0.4.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/aws/aws-sdk-go v1.44.187 // indirect
github.com/aws/aws-sdk-go-v2 v1.32.2 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.11.0 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.8 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.11.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.16.1 // indirect
github.com/aws/smithy-go v1.22.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/btcsuite/btcd v0.22.1 // indirect
Expand Down
35 changes: 30 additions & 5 deletions node/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -692,21 +692,49 @@ github.com/aws/aws-sdk-go v1.36.30/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2z
github.com/aws/aws-sdk-go v1.37.0/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/aws/aws-sdk-go v1.38.35/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/aws/aws-sdk-go v1.40.45/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q=
github.com/aws/aws-sdk-go v1.44.187 h1:D5CsRomPnlwDHJCanL2mtaLIcbhjiWxNh5j8zvaWdJA=
github.com/aws/aws-sdk-go v1.44.187/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/aws/aws-sdk-go-v2 v1.2.0/go.mod h1:zEQs02YRBw1DjK0PoJv3ygDYOFTre1ejlJWl8FwAuQo=
github.com/aws/aws-sdk-go-v2 v1.9.1/go.mod h1:cK/D0BBs0b/oWPIcX/Z/obahJK1TT7IPVjy53i/mX/4=
github.com/aws/aws-sdk-go-v2 v1.16.0/go.mod h1:lJYcuZZEHWNIb6ugJjbQY1fykdoobWbOS7kJYb4APoI=
github.com/aws/aws-sdk-go-v2 v1.32.2 h1:AkNLZEyYMLnx/Q/mSKkcMqwNFXMAvFto9bNsHqcTduI=
github.com/aws/aws-sdk-go-v2 v1.32.2/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo=
github.com/aws/aws-sdk-go-v2/config v1.1.1/go.mod h1:0XsVy9lBI/BCXm+2Tuvt39YmdHwS5unDQmxZOYe8F5Y=
github.com/aws/aws-sdk-go-v2/config v1.15.1 h1:hTIZFepYESYyowQUBo47lu69WSxsYqGUILY9Nu8+7pY=
github.com/aws/aws-sdk-go-v2/config v1.15.1/go.mod h1:MZHGbuW2WnqIOQQBKu2ZkhTjuutZSTnn56TDq4QyydE=
github.com/aws/aws-sdk-go-v2/credentials v1.1.1/go.mod h1:mM2iIjwl7LULWtS6JCACyInboHirisUUdkBPoTHMOUo=
github.com/aws/aws-sdk-go-v2/credentials v1.11.0 h1:gc4Uhs80s60nmLon5Z4JXWinX2BkAGT0YROoUT8h8U4=
github.com/aws/aws-sdk-go-v2/credentials v1.11.0/go.mod h1:EdV1ZFgtZ4XM5RDHWcRWK8H+xW5duNVBqWj2oLu7tRo=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.2/go.mod h1:3hGg3PpiEjHnrkrlasTfxFqUsZ2GCk/fMUn4CbKgSkM=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.1 h1:F9Je1nq5YXfMOv6451NHvMf6U0iTWeMnsG0MMIQoUmk=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.1/go.mod h1:Yph0XsTbQ5GGZ2+mO1a03P/SO9fdX3t1nejIp2tq79g=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.7/go.mod h1:oB9nZcxH1cGq7NPGurVJwxrO2vmJ9mmEBayCwcAlmT8=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21 h1:UAsR3xA31QGf79WzpG/ixT9FZvQlh5HY1NRqSHBNOCk=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21/go.mod h1:JNr43NFf5L9YaG3eKTm7HQzls9J+A9YYcGI5Quh1r2Y=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.1/go.mod h1:K4vz7lRYCyLYpYAMCLObODahFgARdD3YVa0MvQte9Co=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21 h1:6jZVETqmYCadGFvrYEQfC5fAQmlo80CeL5psbno6r0s=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21/go.mod h1:1SR0GbLlnN3QUmYaflZNiH1ql+1qrSiB2vwcJ+4UM60=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.8 h1:adr3PfiggFtqgFofAMUFCtdvwzpf3QxPES4ezK4M3iI=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.8/go.mod h1:wLbQYt36AJqaRZUQiCNXzbtkNigyPfKHrotHuIDiCy8=
github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.8.1/go.mod h1:CM+19rL1+4dFWnOQKwDc7H1KwXTz+h61oUSHyhV0b3o=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.2/go.mod h1:45MfaXZ0cNbeuT0KQ1XJylq8A6+OpVV2E5kvY/Kq+u8=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.1 h1:B/SPX7J+Y0Yrcjv60Nhbh1gC2uBN47SfN8JYre6Mp4M=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.1/go.mod h1:2Hhr9Eh1gJzDatwACX/ozAZ/ljq5vzvPRu5cdu25tzc=
github.com/aws/aws-sdk-go-v2/service/kms v1.37.2 h1:tfBABi5R6aSZlhgTWHxL+opYUDOnIGoNcJLwVYv0jLM=
github.com/aws/aws-sdk-go-v2/service/kms v1.37.2/go.mod h1:dZYFcQwuoh+cLOlFnZItijZptmyDhRIkOKWFO1CfzV8=
github.com/aws/aws-sdk-go-v2/service/route53 v1.1.1/go.mod h1:rLiOUrPLW/Er5kRcQ7NkwbjlijluLsrIbu/iyl35RO4=
github.com/aws/aws-sdk-go-v2/service/sso v1.1.1/go.mod h1:SuZJxklHxLAXgLTc1iFXbEWkXs7QRTQpCLGaKIprQW0=
github.com/aws/aws-sdk-go-v2/service/sso v1.11.1 h1:DyHctRsJIAWIvom1Itb4T84D2jwpIu+KIi3d0SFaswg=
github.com/aws/aws-sdk-go-v2/service/sso v1.11.1/go.mod h1:CvFTucADIx7U/M44vjLs/ZttpQHdpxwK+62+dUGhDeY=
github.com/aws/aws-sdk-go-v2/service/sts v1.1.1/go.mod h1:Wi0EBZwiz/K44YliU0EKxqTCJGUfYTWXrrBwkq736bM=
github.com/aws/aws-sdk-go-v2/service/sts v1.16.1 h1:xsOtPAvHqhvQvBza5ohaUcfq1LceH2lZKMUGZJKiZiM=
github.com/aws/aws-sdk-go-v2/service/sts v1.16.1/go.mod h1:Aq2/Qggh2oemSfyHH+EO4UBbgWG6zFCXLHYI4ILTY7w=
github.com/aws/smithy-go v1.1.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw=
github.com/aws/smithy-go v1.8.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E=
github.com/aws/smithy-go v1.11.1/go.mod h1:3xHYmszWVx2c0kIwQeEVf9uSm4fYZt67FBJnwub1bgM=
github.com/aws/smithy-go v1.22.0 h1:uunKnWlcoL3zO7q+gG2Pk53joueEOsnNB28QdMsmiMM=
github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod h1:q/89r3U2H7sSsE2t6Kca0lfwTK8JdoNGS/yzM/4iH5I=
github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
Expand Down Expand Up @@ -3524,7 +3552,6 @@ golang.org/x/net v0.0.0-20220726230323-06994584191e/go.mod h1:AaygXjzTFtRAg2ttMY
golang.org/x/net v0.0.0-20220909164309-bea034e7d591/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20221012135044-0b7e1fb9d458/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
Expand Down Expand Up @@ -3760,7 +3787,6 @@ golang.org/x/sys v0.0.0-20220727055044-e65921a090b8/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -3776,7 +3802,6 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ=
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
Expand Down
167 changes: 167 additions & 0 deletions node/pkg/guardiansigner/amazonkms.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package guardiansigner

import (
"bytes"
"context"
"crypto/ecdsa"
"encoding/asn1"
"errors"
"fmt"
"math/big"

"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/kms"
kms_types "github.com/aws/aws-sdk-go-v2/service/kms/types"
"github.com/aws/aws-sdk-go/aws"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
)

var (
secp256k1N = ethcrypto.S256().Params().N
secp256k1HalfN = new(big.Int).Div(secp256k1N, big.NewInt(2))
)

type asn1EcSig struct {
R asn1.RawValue
S asn1.RawValue
}

type asn1EcPublicKey struct {
EcPublicKeyInfo asn1EcPublicKeyInfo
PublicKey asn1.BitString
}

type asn1EcPublicKeyInfo struct {
Algorithm asn1.ObjectIdentifier
Parameters asn1.ObjectIdentifier
}

type AmazonKms struct {
KeyId string
Region string
svc *kms.Client
}

func NewAmazonKmsSigner(unsafeDevMode bool, keyPath string) (*AmazonKms, error) {
amazonKmsSigner := AmazonKms{
KeyId: keyPath,
}

cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion("eu-north-1"))
if err != nil {
return nil, errors.New("failed to load default config")
}

amazonKmsSigner.svc = kms.NewFromConfig(cfg)

return &amazonKmsSigner, nil
}

func (a *AmazonKms) Sign(hash []byte) (signature []byte, err error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry if I failed to flag this before, but i think it would be ideal if both Sign and Verify were to have a context.Context parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think I can just pass in the contexts that are available in the calling scope, and create a new one in scopes that don't have an existing context available?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better than having no Context so I'm good with it.


// request signing
res, err := a.svc.Sign(context.TODO(), &kms.SignInput{
KeyId: aws.String(a.KeyId),
Message: hash,
SigningAlgorithm: kms_types.SigningAlgorithmSpecEcdsaSha256,
MessageType: kms_types.MessageTypeDigest,
})

if err != nil {
return nil, fmt.Errorf("Signing failed: %w", err)
}

// decode r and s values
r, s := derSignatureToRS(res.Signature)

// if s is greater than secp256k1HalfN, we need to substract secp256k1N from it
sBigInt := new(big.Int).SetBytes(s)
if sBigInt.Cmp(secp256k1HalfN) > 0 {
s = new(big.Int).Sub(secp256k1N, sBigInt).Bytes()
}

// r and s need to be 32 bytes in size
r = adjustBufferSize(r)
s = adjustBufferSize(s)

// AWS KMS does not provide the recovery id. But that doesn't matter too much, since we can
// attempt recovery id's 0 and 1, and in the process ensure that the signature is valid.
expectedPublicKey := a.PublicKey()
signature = append(r, s...)

// try recovery id 0
ecSigWithRecid := append(signature, []byte{0}...)
pubkey, err := ethcrypto.SigToPub(hash[:], ecSigWithRecid)

Check failure on line 94 in node/pkg/guardiansigner/amazonkms.go

View workflow job for this annotation

GitHub Actions / node-lint

ineffectual assignment to err (ineffassign)
pleasew8t marked this conversation as resolved.
Show resolved Hide resolved

if bytes.Equal(ethcrypto.CompressPubkey(pubkey), ethcrypto.CompressPubkey(&expectedPublicKey)) {
return ecSigWithRecid, nil
}

ecSigWithRecid = append(signature, []byte{1}...)
pubkey, err = ethcrypto.SigToPub(hash[:], ecSigWithRecid)

Check failure on line 101 in node/pkg/guardiansigner/amazonkms.go

View workflow job for this annotation

GitHub Actions / node-lint

ineffectual assignment to err (ineffassign)
pleasew8t marked this conversation as resolved.
Show resolved Hide resolved

// try recovery id 1
if bytes.Equal(ethcrypto.CompressPubkey(pubkey), ethcrypto.CompressPubkey(&expectedPublicKey)) {
return ecSigWithRecid, nil
}

return nil, fmt.Errorf("Failed to generate signature")
}

func (a *AmazonKms) PublicKey() ecdsa.PublicKey {
pubKeyOutput, _ := a.svc.GetPublicKey(context.TODO(), &kms.GetPublicKeyInput{
KeyId: aws.String(a.KeyId),
})

var asn1Pubkey asn1EcPublicKey
_, _ = asn1.Unmarshal(pubKeyOutput.PublicKey, &asn1Pubkey)

ecdsaPubkey := ecdsa.PublicKey{
X: new(big.Int).SetBytes(asn1Pubkey.PublicKey.Bytes[1 : 1+32]),
Y: new(big.Int).SetBytes(asn1Pubkey.PublicKey.Bytes[1+32:]),
}

return ecdsaPubkey
}

func (a *AmazonKms) Verify(sig []byte, hash []byte) (bool, error) {
return true, nil
}

// https://bitcoin.stackexchange.com/questions/92680/what-are-the-der-signature-and-sec-format
// 1. 0x30 byte: header byte to indicate compound structure
// 2. one byte to encode the length of the following data
// 3. 0x02: header byte indicating an integer
// 4. one byte to encode the length of the following r value
// 5. the r value as a big-endian integer
// 6. 0x02: header byte indicating an integer
// 7. one byte to encode the length of the following s value
// 8. the s value as a big-endian integer
func derSignatureToRS(signature []byte) (rBytes []byte, sBytes []byte) {
var sigAsn1 asn1EcSig
_, err := asn1.Unmarshal(signature, &sigAsn1)

if err != nil {
panic(err)
pleasew8t marked this conversation as resolved.
Show resolved Hide resolved
}

return sigAsn1.R.Bytes, sigAsn1.S.Bytes
// return rBytes, sBytes
}

func adjustBufferSize(b []byte) []byte {
pleasew8t marked this conversation as resolved.
Show resolved Hide resolved
length := len(b)

if length == 32 {
return b
}

if length > 32 {
return b[length-32:]
}

tmp := make([]byte, 32)
copy(tmp[32-length:], b)

return tmp
}
59 changes: 59 additions & 0 deletions node/pkg/guardiansigner/benchmarksigner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package guardiansigner

import (
"crypto/ecdsa"
"fmt"
"time"
)

type BenchmarkSigner struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, document this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC this means we can benchmark AWS KMS signer by passing its configuration to a signer of type benchmark, correct?

innerSigner GuardianSigner
}

func NewBenchmarkSigner(unsafeDevMode bool, signerKeyPath string) (*BenchmarkSigner, error) {
innerSigner, err := NewGuardianSignerFromUri(signerKeyPath, unsafeDevMode)

if err != nil {
return nil, fmt.Errorf("failed to create benchmark signer: %w", err)
}

return &BenchmarkSigner{
innerSigner: innerSigner,
}, nil
}

func (b *BenchmarkSigner) Sign(hash []byte) ([]byte, error) {

start := time.Now()

sig, err := b.innerSigner.Sign(hash)

duration := time.Since(start)
fmt.Printf("Signing execution time: %v\n", duration)

return sig, err
}

func (b *BenchmarkSigner) PublicKey() ecdsa.PublicKey {

start := time.Now()

pubKey := b.innerSigner.PublicKey()

duration := time.Since(start)
fmt.Printf("Public key retrieval time: %v\n", duration)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be exposed through a Prometheus histogram.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's an example of the definition of an histogram

observationChanDelay = promauto.NewHistogram(
and how to observe latency
observationChanDelay.Observe(float64(time.Since(m.Timestamp).Microseconds()))


return pubKey
}

func (b *BenchmarkSigner) Verify(sig []byte, hash []byte) (bool, error) {

start := time.Now()

valid, err := b.innerSigner.Verify(sig, hash)

duration := time.Since(start)
fmt.Printf("Signature verification time: %v\n", duration)

return valid, err
}
12 changes: 12 additions & 0 deletions node/pkg/guardiansigner/guardiansigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const (
InvalidSignerType SignerType = iota
// file://<path-to-file>
FileSignerType
// amazonkms://<arn>
AmazonKmsSignerType
// benchmark://<uri>://<config>
BenchmarkSignerType
)

// GuardianSigner interface
Expand All @@ -40,6 +44,10 @@ func NewGuardianSignerFromUri(signerUri string, unsafeDevMode bool) (GuardianSig
switch signerType {
case FileSignerType:
return NewFileSigner(unsafeDevMode, signerKeyConfig)
case AmazonKmsSignerType:
return NewAmazonKmsSigner(unsafeDevMode, signerKeyConfig)
case BenchmarkSignerType:
return NewBenchmarkSigner(unsafeDevMode, signerKeyConfig)
default:
return nil, errors.New("unsupported guardian signer type")
}
Expand All @@ -62,6 +70,10 @@ func ParseSignerUri(signerUri string) (signerType SignerType, signerKeyConfig st
switch typeStr {
case "file":
return FileSignerType, keyConfig, nil
case "amazonkms":
return AmazonKmsSignerType, keyConfig, nil
case "benchmark":
return BenchmarkSignerType, keyConfig, nil
default:
return InvalidSignerType, "", fmt.Errorf("unsupported guardian signer type: %s", typeStr)
}
Expand Down
2 changes: 2 additions & 0 deletions node/pkg/guardiansigner/guardiansigner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func TestParseSignerUri(t *testing.T) {
{label: "FileUriNoSchemeSeparator", path: "filewhatever", expectedType: InvalidSignerType},
{label: "FileUriMultipleSchemeSeparators", path: "file://testing://this://", expectedType: FileSignerType},
{label: "FileUriTraversal", path: "file://../../../file", expectedType: FileSignerType},
// Amazon KMS
{label: "AmazonKmsURI", path: "amazonkms://some-arn", expectedType: AmazonKmsSignerType},
}

for _, testcase := range tests {
Expand Down
Loading