Skip to content

Commit 0f83101

Browse files
authored
Use client-side digest computation for signing (#670)
This should not change anything functional in the signature but rather move the digest calculation from the API (i.e. server-side in Cloud KMS) to our code (i.e. client-side). Notably, there is an API constraint that content be <=64kB when using server-side hashing so we can allow for larger attestation payloads by moving that client-side.
1 parent dbd09c9 commit 0f83101

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pkg/kmsdsse/kmsdsse.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,17 @@ func (s *CloudKMSSignerVerifier) Public() crypto.PublicKey {
6262
}
6363

6464
func (s *CloudKMSSignerVerifier) Sign(ctx context.Context, data []byte) ([]byte, error) {
65-
// NOTE: We could pass Digest here instead to shrink the RPC size.
65+
var digest kmspb.Digest
66+
switch s.pubpb.Algorithm {
67+
case kmspb.CryptoKeyVersion_EC_SIGN_P256_SHA256:
68+
digestBytes := sha256.Sum256(data)
69+
digest.Digest = &kmspb.Digest_Sha256{Sha256: digestBytes[:]}
70+
default:
71+
return nil, errors.New("unsupported key type")
72+
}
6673
req := &kmspb.AsymmetricSignRequest{
67-
Name: s.keyName,
68-
Data: data,
74+
Name: s.keyName,
75+
Digest: &digest,
6976
}
7077
resp, err := s.client.AsymmetricSign(ctx, req)
7178
if err != nil {

0 commit comments

Comments
 (0)