Skip to content

Commit 1b7fb4b

Browse files
authored
chore: Update KMS Api v1.0.0 (#12)
1 parent fdfca4e commit 1b7fb4b

File tree

14 files changed

+787
-95
lines changed

14 files changed

+787
-95
lines changed

.github/codegen/schemas/swagger.json

+533-38
Large diffs are not rendered by default.

.github/codegen/schemas/version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.9.18 (manually patched)
1+
1.0.0 (manually patched)

apis.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type DataKeyApi interface {
4747
// SignatureApi is the client interface used to sign data and verify signatures using a remote asymmetric key-pair.
4848
type SignatureApi interface {
4949
// Sign signs the given message with the remote private key having the ID `keyId`. The message can be pre-hashed or not.
50-
Sign(ctx context.Context, keyId uuid.UUID, alg types.DigitalSignatureAlgorithms, preHashed bool, msg []byte) (string, error)
50+
Sign(ctx context.Context, keyId uuid.UUID, format *types.SignatureFormats, alg types.DigitalSignatureAlgorithms, preHashed bool, msg []byte) (string, error)
5151
// Verify checks the signature of given message against the remote public key having the ID `keyId`. The message can be pre-hashed or not.
5252
Verify(ctx context.Context, keyId uuid.UUID, alg types.DigitalSignatureAlgorithms, preHashed bool, msg []byte, sig string) (bool, error)
5353
}

client.go

+29-9
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (client *Client) GenerateECKeyPair(ctx context.Context, curve types.Curves,
9898
return client.CreateImportServiceKey(ctx, nil, body)
9999
}
100100

101-
func (client *Client) importJWK(ctx context.Context, jwk types.JsonWebKey, name, keyCtx string, ops ...types.CryptographicUsages) (*types.GetServiceKeyResponse, error) {
101+
func (client *Client) importJWK(ctx context.Context, jwk types.JsonWebKeyRequest, name, keyCtx string, ops ...types.CryptographicUsages) (*types.GetServiceKeyResponse, error) {
102102
var keyContext *string
103103
if keyCtx != "" {
104104
keyContext = &keyCtx
@@ -107,7 +107,7 @@ func (client *Client) importJWK(ctx context.Context, jwk types.JsonWebKey, name,
107107
Context: keyContext,
108108
Name: name,
109109
Operations: &ops,
110-
Keys: &[]types.JsonWebKey{jwk},
110+
Keys: &[]types.JsonWebKeyRequest{jwk},
111111
}
112112
format := types.Jwk
113113
return client.CreateImportServiceKey(ctx, &format, req)
@@ -122,16 +122,33 @@ func (client *Client) importJWK(ctx context.Context, jwk types.JsonWebKey, name,
122122
// - []byte for importing symmetric keys.
123123
func (client *Client) ImportKey(ctx context.Context, key any, name, keyCtx string, ops ...types.CryptographicUsages) (*types.GetServiceKeyResponse, error) {
124124
switch k := key.(type) {
125-
case types.JsonWebKey:
125+
case types.JsonWebKeyRequest:
126126
return client.importJWK(ctx, k, name, keyCtx, ops...)
127-
case *types.JsonWebKey:
127+
case *types.JsonWebKeyRequest:
128128
return client.importJWK(ctx, *k, name, keyCtx, ops...)
129129
}
130130
jwk, err := types.NewJsonWebKey(key, ops, name)
131131
if err != nil {
132132
return nil, err
133133
}
134-
return client.importJWK(ctx, jwk, name, keyCtx, ops...)
134+
jwkRequest := types.JsonWebKeyRequest{
135+
Kid: &jwk.Kid,
136+
KeyOps: jwk.KeyOps,
137+
Kty: jwk.Kty,
138+
D: jwk.D,
139+
E: jwk.E,
140+
N: jwk.N,
141+
P: jwk.P,
142+
Q: jwk.Q,
143+
Dp: jwk.Dp,
144+
Dq: jwk.Dq,
145+
Qi: jwk.Qi,
146+
X: jwk.X,
147+
Y: jwk.Y,
148+
Crv: jwk.Crv,
149+
K: jwk.K,
150+
}
151+
return client.importJWK(ctx, jwkRequest, name, keyCtx, ops...)
135152
}
136153

137154
// ImportKeyPairPEM imports a PEM formated key into the KMS. keyCtx can be left empty if not needed.
@@ -166,8 +183,8 @@ func (client *Client) ImportKeyPairPEM(ctx context.Context, privateKeyPem []byte
166183
return client.ImportKey(ctx, k, name, keyCtx, ops...)
167184
}
168185

169-
// ExportJwkPublicKey returns the public part of a key pair ans a Json Web Key.
170-
func (client *Client) ExportJwkPublicKey(ctx context.Context, keyID uuid.UUID) (*types.JsonWebKey, error) {
186+
// ExportJwkPublicKey returns the public part of a key pair as a Json Web Key.
187+
func (client *Client) ExportJwkPublicKey(ctx context.Context, keyID uuid.UUID) (*types.JsonWebKeyResponse, error) {
171188
format := types.Jwk
172189
k, err := client.GetServiceKey(ctx, keyID, &format)
173190
if err != nil {
@@ -460,13 +477,16 @@ func (client *apiClient) Encrypt(ctx context.Context, keyId uuid.UUID, keyCtx st
460477
}
461478

462479
// Sign signs the given message with the remote private key having the ID `keyId`. The message can be pre-hashed or not.
463-
func (client *apiClient) Sign(ctx context.Context, keyId uuid.UUID, alg types.DigitalSignatureAlgorithms, preHashed bool, msg []byte) (string, error) {
480+
func (client *apiClient) Sign(ctx context.Context, keyId uuid.UUID, format *types.SignatureFormats, alg types.DigitalSignatureAlgorithms, preHashed bool, msg []byte) (string, error) {
464481
req := types.SignRequest{
465482
Alg: alg,
466483
Isdigest: &preHashed,
467484
Message: msg,
468485
}
469-
r, err := mapRestErr(client.inner.SignWithResponse(ctx, keyId, nil, req)) // TODO: Make the format param customizable
486+
param := &types.SignParams{
487+
Format: format,
488+
}
489+
r, err := mapRestErr(client.inner.SignWithResponse(ctx, keyId, param, req))
470490
if err != nil {
471491
return "", err
472492
}

example_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ func ExampleClient_CreateImportServiceKey_generateECDSA() {
107107
func ExampleClient_Sign() {
108108
var kmsClient *okms.Client // Initialize client
109109
data := "Hello World !!!" // Data to sign
110-
signResponse, err := kmsClient.Sign(context.Background(), uuid.MustParse("2dab95dc-d7d3-482b-a07b-6b4dfae89d58"), types.ES256, false, []byte(data))
110+
format := types.Raw
111+
signResponse, err := kmsClient.Sign(context.Background(), uuid.MustParse("2dab95dc-d7d3-482b-a07b-6b4dfae89d58"), &format, types.ES256, false, []byte(data))
111112
if err != nil {
112113
panic(err)
113114
}

examples/sign_verify.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ func signVerify(ctx context.Context, kmsClient *okms.Client) {
2929
}
3030

3131
data := "Hello World !!!" // Data to sign
32-
signResponse, err := kmsClient.Sign(context.Background(), respECDSA.Id, types.ES256, false, []byte(data))
32+
format := types.Jws
33+
signResponse, err := kmsClient.Sign(context.Background(), respECDSA.Id, &format, types.ES256, false, []byte(data))
3334
if err != nil {
3435
panic(err)
3536
}
@@ -42,7 +43,7 @@ func signVerify(ctx context.Context, kmsClient *okms.Client) {
4243
fmt.Println("Is valid:", result)
4344

4445
// You can also instantiate an stdlib crypto.Signer
45-
signer, err := kmsClient.NewSigner(ctx, respECDSA.Id)
46+
signer, err := kmsClient.NewSigner(ctx, respECDSA.Id, &format)
4647
if err != nil {
4748
panic(err)
4849
}

0 commit comments

Comments
 (0)