|
4 | 4 | "context" |
5 | 5 | "crypto/ecdsa" |
6 | 6 | "crypto/elliptic" |
| 7 | + "crypto/x509" |
7 | 8 | "encoding/asn1" |
8 | 9 | "encoding/hex" |
9 | 10 | "encoding/pem" |
@@ -47,40 +48,20 @@ func newMockKMSSigner(t *testing.T) *KMSSigner { |
47 | 48 | } |
48 | 49 |
|
49 | 50 | func (m *mockKMSClient) GetPublicKey(ctx context.Context, req *kmspb.GetPublicKeyRequest) (*kmspb.PublicKey, error) { |
50 | | - spki := struct { |
51 | | - Algorithm struct { |
52 | | - Algorithm asn1.ObjectIdentifier |
53 | | - Parameters asn1.ObjectIdentifier |
54 | | - } |
55 | | - PublicKey asn1.BitString |
56 | | - }{ |
57 | | - Algorithm: struct { |
58 | | - Algorithm asn1.ObjectIdentifier |
59 | | - Parameters asn1.ObjectIdentifier |
60 | | - }{ |
61 | | - Algorithm: asn1.ObjectIdentifier{1, 2, 840, 10045, 2, 1}, |
62 | | - Parameters: asn1.ObjectIdentifier{1, 3, 132, 0, 10}, |
63 | | - }, |
64 | | - } |
65 | | - |
66 | | - pubKeyBytes := crypto.FromECDSAPub(&m.privateKey.PublicKey) |
67 | | - spki.PublicKey = asn1.BitString{ |
68 | | - Bytes: pubKeyBytes, |
69 | | - BitLength: 8 * len(pubKeyBytes), |
70 | | - } |
71 | | - |
72 | | - der, err := asn1.Marshal(spki) |
| 51 | + |
| 52 | + x509EncodedPub, err := x509.MarshalPKIXPublicKey(&m.privateKey.PublicKey) |
73 | 53 | if err != nil { |
74 | | - return nil, fmt.Errorf("failed to marshal SPKI: %w", err) |
| 54 | + return nil, fmt.Errorf("failed to marshal public key to X.509: %w", err) |
75 | 55 | } |
76 | | - |
| 56 | + |
77 | 57 | pemBytes := pem.EncodeToMemory(&pem.Block{ |
78 | 58 | Type: "PUBLIC KEY", |
79 | | - Bytes: der, |
| 59 | + Bytes: x509EncodedPub, |
80 | 60 | }) |
81 | | - |
| 61 | + |
82 | 62 | return &kmspb.PublicKey{ |
83 | 63 | Pem: string(pemBytes), |
| 64 | + Algorithm: kmspb.CryptoKeyVersion_EC_SIGN_SECP256K1_SHA256, |
84 | 65 | }, nil |
85 | 66 | } |
86 | 67 |
|
|
0 commit comments