-
Notifications
You must be signed in to change notification settings - Fork 3
/
keys_generated.go
1151 lines (1077 loc) · 37.4 KB
/
keys_generated.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (c) Fortanix, Inc.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package sdkms
import (
"context"
"encoding/json"
"fmt"
"net/http"
"strings"
"github.com/pkg/errors"
)
// Request to copy a security object.
type CopySobjectRequest struct {
// Unique identifier of the security object to be copied.
Key SobjectDescriptor `json:"key"`
// Properties for the new security object.
Dest SobjectRequest `json:"dest"`
}
func (x CopySobjectRequest) MarshalJSON() ([]byte, error) {
m := make(map[string]interface{})
{ // x.Dest is flattened
b, err := json.Marshal(&x.Dest)
if err != nil {
return nil, err
}
f := make(map[string]interface{})
if err := json.Unmarshal(b, &f); err != nil {
return nil, err
}
for k, v := range f {
m[k] = v
}
}
m["key"] = x.Key
return json.Marshal(&m)
}
func (x *CopySobjectRequest) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, &x.Dest); err != nil {
return err
}
var r struct {
Key SobjectDescriptor `json:"key"`
}
if err := json.Unmarshal(data, &r); err != nil {
return err
}
x.Key = r.Key
return nil
}
// Export security object by components response.
type ExportComponentsResponse struct {
// Key components
Components []SobjectComponent `json:"components"`
// Initialization vector
Iv *Blob `json:"iv,omitempty"`
// Tag, if required by the encryption mode.
Tag *Blob `json:"tag,omitempty"`
// KCV for the exported key
KeyKcv *string `json:"key_kcv,omitempty"`
// Description of the exported key
Description *string `json:"description,omitempty"`
}
// Request to Export a security object by components
type ExportSobjectComponentsRequest struct {
// Unique identifier of the security object
Key SobjectDescriptor `json:"key"`
// Details of wrapping key
WrapKeyParams *WrapKeyParams `json:"wrap_key_params,omitempty"`
// Key holder identifier
Custodians []Principal `json:"custodians"`
// Splitting method
Method *SplittingMethod `json:"method,omitempty"`
// Description of the exported security object
Description *string `json:"description,omitempty"`
}
// Parameters to show sobject details.
type GetSobjectParams struct {
// Response data encoding
View *SobjectEncoding `json:"view,omitempty"`
// Show destroyed security object(s).
ShowDestroyed *bool `json:"show_destroyed,omitempty"`
// Show deleted security object(s).
ShowDeleted *bool `json:"show_deleted,omitempty"`
// Show value of security object(s).
ShowValue *bool `json:"show_value,omitempty"`
// Show public key of security objects(s) if present.
ShowPubKey *bool `json:"show_pub_key,omitempty"`
}
func (x GetSobjectParams) urlEncode(v map[string][]string) error {
if x.View != nil {
v["view"] = []string{fmt.Sprintf("%v", *x.View)}
}
if x.ShowDestroyed != nil {
v["show_destroyed"] = []string{fmt.Sprintf("%v", *x.ShowDestroyed)}
}
if x.ShowDeleted != nil {
v["show_deleted"] = []string{fmt.Sprintf("%v", *x.ShowDeleted)}
}
if x.ShowValue != nil {
v["show_value"] = []string{fmt.Sprintf("%v", *x.ShowValue)}
}
if x.ShowPubKey != nil {
v["show_pub_key"] = []string{fmt.Sprintf("%v", *x.ShowPubKey)}
}
return nil
}
// Request to import a security object by components.
type ImportSobjectComponentsRequest struct {
// Properties of the imported security object
Key SobjectRequest `json:"key"`
// Details of unwrapping key, if components are wrapped.
UnwrapKeyParams *UnwrapKeyParams `json:"unwrap_key_params,omitempty"`
// Key holder identifier
Custodians []Principal `json:"custodians"`
// Key material by parts
Components *[]SobjectComponent `json:"components,omitempty"`
// Description of the imported security object
Description *string `json:"description,omitempty"`
// Splitting method used to join the key components
Method *SplittingMethod `json:"method,omitempty"`
// Authentication requirements for approval requests
AuthConfig *ApprovalAuthConfig `json:"auth_config,omitempty"`
}
// KCV of a key
type KeyCheckValueResponse struct {
// UUID, only for persistent keys.
Kid *UUID `json:"kid,omitempty"`
// Key Checksum Value
Kcv string `json:"kcv"`
}
// Response structure from list security objects query
type ListSobjectsResponse struct {
// Metadata indicating filtered and total count.
Md Metadata `json:"metadata,omitempty"`
// List of security objects matching the filtering parameters.
Items []Sobject `json:"items,omitempty"`
}
// Request parameters for filtering and listing security objects.
type ListSobjectsParams struct {
// Filter security object(s) by group ID.
GroupID *UUID `json:"group_id,omitempty"`
// Filter security object(s) by a particular creator.
Creator *UUID `json:"creator,omitempty"`
// Filter security object(s) by name.
Name *string `json:"name,omitempty"`
// Filter security object(s) by PKCS11 label.
Pkcs11Label *string `json:"pkcs11_label,omitempty"`
// Filter security object(s) by PKCS11 unique identifier.
Pkcs11ID *Blob `json:"pkcs11_id,omitempty"`
// Filter security object(s) by object type.
ObjType *ObjectType `json:"obj_type,omitempty"`
// Set max security objects in returned in response (default: 1000).
Limit *uint `json:"limit,omitempty"`
// Skip first n (offset) matches.
Offset *uint `json:"offset,omitempty"`
// Sorting method for listed security objects.
Sort *SobjectSort `json:"sort,omitempty"`
// Only show security objects complying with group and account policies.
CompliantWithPolicies *bool `json:"compliant_with_policies,omitempty"`
// Filter security object(s) by custom_metadata fields.
CustomMetadata *CustomMetadata `json:"custom_metadata,omitempty"`
// Display query metadata in response, containing information on total objects
// and number of objects skipped.
WithMetadata *bool `json:"with_metadata,omitempty"`
// Show destroyed security object(s).
ShowDestroyed *bool `json:"show_destroyed,omitempty"`
// Show deleted security object(s).
ShowDeleted *bool `json:"show_deleted,omitempty"`
// Show non-sensitive key material of security object(s).
ShowValue *bool `json:"show_value,omitempty"`
// Show public key of security objects(s) if present.
ShowPubKey *bool `json:"show_pub_key,omitempty"`
// Show key check value for security object(s).
ShowKcv *bool `json:"show_kcv,omitempty"`
// Provide custom filtering query.
Filter *string `json:"filter,omitempty"`
}
func (x ListSobjectsParams) urlEncode(v map[string][]string) error {
if x.GroupID != nil {
v["group_id"] = []string{fmt.Sprintf("%v", *x.GroupID)}
}
if x.Creator != nil {
v["creator"] = []string{fmt.Sprintf("%v", *x.Creator)}
}
if x.Name != nil {
v["name"] = []string{fmt.Sprintf("%v", *x.Name)}
}
if x.Pkcs11Label != nil {
v["pkcs11_label"] = []string{fmt.Sprintf("%v", *x.Pkcs11Label)}
}
if x.Pkcs11ID != nil {
v["pkcs11_id"] = []string{fmt.Sprintf("%v", *x.Pkcs11ID)}
}
if x.ObjType != nil {
v["obj_type"] = []string{fmt.Sprintf("%v", *x.ObjType)}
}
if x.Limit != nil {
v["limit"] = []string{fmt.Sprintf("%v", *x.Limit)}
}
if x.Offset != nil {
v["offset"] = []string{fmt.Sprintf("%v", *x.Offset)}
}
if err := x.Sort.urlEncode(v); err != nil {
return err
}
if x.CompliantWithPolicies != nil {
v["compliant_with_policies"] = []string{fmt.Sprintf("%v", *x.CompliantWithPolicies)}
}
if err := x.CustomMetadata.urlEncode(v); err != nil {
return err
}
if x.WithMetadata != nil {
v["with_metadata"] = []string{fmt.Sprintf("%v", *x.WithMetadata)}
}
if x.ShowDestroyed != nil {
v["show_destroyed"] = []string{fmt.Sprintf("%v", *x.ShowDestroyed)}
}
if x.ShowDeleted != nil {
v["show_deleted"] = []string{fmt.Sprintf("%v", *x.ShowDeleted)}
}
if x.ShowValue != nil {
v["show_value"] = []string{fmt.Sprintf("%v", *x.ShowValue)}
}
if x.ShowPubKey != nil {
v["show_pub_key"] = []string{fmt.Sprintf("%v", *x.ShowPubKey)}
}
if x.ShowKcv != nil {
v["show_kcv"] = []string{fmt.Sprintf("%v", *x.ShowKcv)}
}
if x.Filter != nil {
v["filter"] = []string{fmt.Sprintf("%v", *x.Filter)}
}
return nil
}
// Request to compute digest of a key.
type ObjectDigestRequest struct {
// Uniquely identifies a security object.
Key SobjectDescriptor `json:"key"`
// Digest algorithm
Alg DigestAlgorithm `json:"alg"`
}
// Digest of a key.
type ObjectDigestResponse struct {
// UUID, only displayed for persistent keys.
Kid *UUID `json:"kid,omitempty"`
// Digest value
Digest Blob `json:"digest"`
}
// Request to persist a transient key.
type PersistTransientKeyRequest struct {
// Intended activation date of the security object.
ActivationDate *Time `json:"activation_date,omitempty"`
// Intended deactivation date of the security object.
DeactivationDate *Time `json:"deactivation_date,omitempty"`
// Name of the persisted security object. Security object names must be unique within an account.
Name string `json:"name"`
// User-defined readable description
Description *string `json:"description,omitempty"`
// User-defined metadata for the persisted key stored as key-value pairs.
CustomMetadata *map[string]string `json:"custom_metadata,omitempty"`
// Whether the new security object should be enabled. Disabled security objects may not perform cryptographic operations.
Enabled *bool `json:"enabled,omitempty"`
// Group ID of the security group that the persisted key should belong to. The user or
// application creating this security object must be a member of this group. If no group is
// specified, the default group for the requesting application will be used.
GroupID *UUID `json:"group_id,omitempty"`
// Intended initial state of the key
State *SobjectState `json:"state,omitempty"`
// Transient key to persist
TransientKey Blob `json:"transient_key"`
}
type RevertRequest struct {
Ids []UUID `json:"ids"`
}
// Component of security object, held by a custodian.
type SobjectComponent struct {
// Key component
Component Blob `json:"component"`
// Key component KCV
ComponentKcv *string `json:"component_kcv,omitempty"`
// Component custodian
Custodian Principal `json:"custodian"`
}
// Uniquely identifies a persisted sobject.
type SobjectDescriptorPersisted struct {
Kid *UUID
Name *string
}
func (x SobjectDescriptorPersisted) MarshalJSON() ([]byte, error) {
if err := checkEnumPointers(
"SobjectDescriptorPersisted",
[]bool{x.Kid != nil,
x.Name != nil}); err != nil {
return nil, err
}
var obj struct {
Kid *UUID `json:"kid,omitempty"`
Name *string `json:"name,omitempty"`
}
obj.Kid = x.Kid
obj.Name = x.Name
return json.Marshal(obj)
}
func (x *SobjectDescriptorPersisted) UnmarshalJSON(data []byte) error {
x.Kid = nil
x.Name = nil
var obj struct {
Kid *UUID `json:"kid,omitempty"`
Name *string `json:"name,omitempty"`
}
if err := json.Unmarshal(data, &obj); err != nil {
return err
}
x.Kid = obj.Kid
x.Name = obj.Name
return nil
}
// Response data encoding.
type SobjectEncoding string
// List of supported SobjectEncoding values
const (
// JSON format
SobjectEncodingJson SobjectEncoding = "json"
// Value format
SobjectEncodingValue SobjectEncoding = "value"
)
// Request to rekey a security object.
type SobjectRekeyRequest struct {
// If set to true, the old key is deactivated on rekey.
DeactivateRotatedKey *bool `json:"deactivate_rotated_key,omitempty"`
// Parameters for the new security object.
Dest SobjectRequest `json:"dest"`
}
func (x SobjectRekeyRequest) MarshalJSON() ([]byte, error) {
m := make(map[string]interface{})
{ // x.Dest is flattened
b, err := json.Marshal(&x.Dest)
if err != nil {
return nil, err
}
f := make(map[string]interface{})
if err := json.Unmarshal(b, &f); err != nil {
return nil, err
}
for k, v := range f {
m[k] = v
}
}
if x.DeactivateRotatedKey != nil {
m["deactivate_rotated_key"] = x.DeactivateRotatedKey
}
return json.Marshal(&m)
}
func (x *SobjectRekeyRequest) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, &x.Dest); err != nil {
return err
}
var r struct {
DeactivateRotatedKey *bool `json:"deactivate_rotated_key,omitempty"`
}
if err := json.Unmarshal(data, &r); err != nil {
return err
}
x.DeactivateRotatedKey = r.DeactivateRotatedKey
return nil
}
// Request to rotate a security object to an existing security object.
type SobjectReplaceRequest struct {
// Security object that will be replaced as part of this operation.
Replaced SobjectDescriptorPersisted `json:"replaced"`
// New name for the replaced security object.
ReplacedNewName string `json:"replaced_new_name"`
// Security object that will become the replacement of the security object
// that has to be replaced.
Replacement SobjectDescriptorPersisted `json:"replacement"`
}
type SobjectRequest struct {
// Activation date of security object in seconds since EPOCH.
ActivationDate *Time `json:"activation_date,omitempty"`
// AES specific options.
Aes *AesOptions `json:"aes,omitempty"`
// Whether the sign operation response contains hash or data as output.
AllowSignHash *bool `json:"allow_sign_hash,omitempty"`
// ARIA specific options.
Aria *AriaOptions `json:"aria,omitempty"`
// BIP32 specific options.
Bip32 *Bip32Options `json:"bip32,omitempty"`
// BLS specific options.
Bls *BlsOptions `json:"bls,omitempty"`
// User managed field for adding custom metadata to the security object.
CustomMetadata *map[string]string `json:"custom_metadata,omitempty"`
// Deactivation date of security object in seconds since EPOCH.
DeactivationDate *Time `json:"deactivation_date,omitempty"`
// DES specific options.
Des *DesOptions `json:"des,omitempty"`
// DES3 specific options.
Des3 *Des3Options `json:"des3,omitempty"`
// Description of the security object.
Description *string `json:"description,omitempty"`
// Optionally get deterministic signatures, if algorithm is EC or RSA.
DeterministicSignatures *bool `json:"deterministic_signatures,omitempty"`
// DSA specific options.
Dsa *DsaOptions `json:"dsa,omitempty"`
// ECKCDSA specific options.
Eckcdsa *EcKcdsaOptions `json:"eckcdsa,omitempty"`
// Identifies a standard elliptic curve.
EllipticCurve *EllipticCurve `json:"elliptic_curve,omitempty"`
// Whether this security object has cryptographic operations enabled.
Enabled *bool `json:"enabled,omitempty"`
// Information specific to an external KMS. Currently, it only has AWS related information.
External *ExternalKmsInfo `json:"external,omitempty"`
// FPE specific options.
Fpe *FpeOptions `json:"fpe,omitempty"`
// Key Access Justifications for GCP EKM.
// For more details: https://cloud.google.com/cloud-provider-access-management/key-access-justifications/docs/overview
GoogleAccessReasonPolicy *Removable[GoogleAccessReasonPolicy] `json:"google_access_reason_policy,omitempty"`
// KCDSA specific options.
Kcdsa *KcdsaOptions `json:"kcdsa,omitempty"`
// Key Checksum Value of the security object.
Kcv *string `json:"kcv,omitempty"`
// Operations allowed to be performed by a given key.
KeyOps *KeyOperations `json:"key_ops,omitempty"`
// Key size of the security object in bits.
KeySize *uint32 `json:"key_size,omitempty"`
// Linked security objects.
Links *KeyLinks `json:"links,omitempty"`
// LMS specific options.
Lms *LmsOptions `json:"lms,omitempty"`
// Name of the security object.
Name *string `json:"name,omitempty"`
// Type of security object.
ObjType *ObjectType `json:"obj_type,omitempty"`
// Public exponent
PubExponent *uint32 `json:"pub_exponent,omitempty"`
// If enabled, the public key will be available publicly (without authentication)
// through the GetPublicKey API.
PublishPublicKey *PublishPublicKeyConfig `json:"publish_public_key,omitempty"`
// Rotation policy of security objects.
RotationPolicy *RotationPolicy `json:"rotation_policy,omitempty"`
// RSA specific options.
Rsa *RsaOptions `json:"rsa,omitempty"`
// Seed options.
Seed *SeedOptions `json:"seed,omitempty"`
// Security object operational state.
State *SobjectState `json:"state,omitempty"`
// If set to true, the security object will cease to exist after session ends.
Transient *bool `json:"transient,omitempty"`
// Security object stored as byte array.
Value *Blob `json:"value,omitempty"`
// UUID of the group which the security object belongs to.
GroupID *UUID `json:"group_id,omitempty"`
}
// Sorting order on listed security objects.
type SobjectSort struct {
// Security object UUID
ByKid *SobjectSortByKid
// Security object name
ByName *SobjectSortByName
}
// Security object UUID
type SobjectSortByKid struct {
// Order of listing
Order Order `json:"order"`
// Initial security object UUID
Start *UUID `json:"start,omitempty"`
}
// Security object name
type SobjectSortByName struct {
// Order of listing
Order Order `json:"order"`
// Initial security object Name
Start *string `json:"start,omitempty"`
}
func (x SobjectSort) urlEncode(v map[string][]string) error {
if x.ByKid != nil && x.ByName != nil {
return errors.New("SobjectSort can be either ByKid or ByName")
}
if x.ByKid != nil {
v["sort"] = []string{"kid" + string(x.ByKid.Order)}
if x.ByKid.Start != nil {
v["start"] = []string{fmt.Sprintf("%v", *x.ByKid.Start)}
}
}
if x.ByName != nil {
v["sort"] = []string{"name" + string(x.ByName.Order)}
if x.ByName.Start != nil {
v["start"] = []string{fmt.Sprintf("%v", *x.ByName.Start)}
}
}
return nil
}
// Method used to split the key into multiple components.
type SplittingMethod string
// List of supported SplittingMethod values
const (
// Logical XOR operation
SplittingMethodXOR SplittingMethod = "XOR"
)
// Request to unwrap a security object
type UnwrapKeyParams struct {
// Unique identifier of the security object.
Key SobjectDescriptor `json:"key"`
// Cryptographic algorithm used for unwrapping.
Alg Algorithm `json:"alg"`
// Block cipher mode of operation, required for symmetric algorithms.
Mode *CryptMode `json:"mode,omitempty"`
// Initialization vector is required for symmetric algorithms.
Iv *Blob `json:"iv,omitempty"`
// Authenticated data is only applicable if mode is GCM.
Ad *Blob `json:"ad,omitempty"`
// Tag is required if mode is GCM.
Tag *Blob `json:"tag,omitempty"`
}
// Verify KCV of a key
type VerifyKcvRequest struct {
// Key Checksum Value
Kcv string `json:"kcv"`
// Key material
Value Blob `json:"value"`
// Type of Security object
ObjType ObjectType `json:"obj_type"`
}
// Key Checksum Value verification status.
type VerifyKcvResponse struct {
// Verification status
Verified bool `json:"verified"`
}
// Wrapping key parameters
type WrapKeyParams struct {
// Wrapping key
Key SobjectDescriptor `json:"key"`
// Cryptographic algorithm of security object
Alg Algorithm `json:"alg"`
// Block cipher mode of operation, required for symmetric algorithms.
Mode *CryptMode `json:"mode,omitempty"`
// Initialization vector is required for symmetric algorithms.
Iv *Blob `json:"iv,omitempty"`
// Authenticated data is only applicable if mode is GCM.
Ad *Blob `json:"ad,omitempty"`
// Tag length is required when mode is GCM.
TagLen *uint `json:"tag_len,omitempty"`
}
// Transition a security object to Active state.
func (c *Client) ActivateSobject(ctx context.Context, id string) error {
u := "/crypto/v1/keys/:id/activate"
u = strings.NewReplacer(":id", id).Replace(u)
if err := c.fetch(ctx, http.MethodPost, u, nil, nil); err != nil {
return err
}
return nil
}
// Batch sign with one or more private keys.
//
// The order of batch items in the response matches that of the request.
// An individual status code is returned for each batch item.
func (c *Client) BatchSign(ctx context.Context, body []SignRequest) ([]BatchSignResponseItem, error) {
u := "/crypto/v1/keys/batch/sign"
var r []BatchSignResponseItem
if err := c.fetch(ctx, http.MethodPost, u, &body, &r); err != nil {
return nil, err
}
return r, nil
}
func (c *Client) RequestApprovalToBatchSign(
ctx context.Context,
body []SignRequest,
description *string) (*ApprovalRequest, error) {
u := "/crypto/v1/keys/batch/sign"
req := ApprovalRequestRequest{
Method: someString(http.MethodPost),
Operation: &u,
Body: body,
Description: description,
}
return c.CreateApprovalRequest(ctx, req)
}
// Batch verify with one or more public keys.
//
// The order of batch items in the response matches that of the request.
// An individual status code is returned for each batch item.
func (c *Client) BatchVerify(ctx context.Context, body []VerifyRequest) ([]BatchVerifyResponseItem, error) {
u := "/crypto/v1/keys/batch/verify"
var r []BatchVerifyResponseItem
if err := c.fetch(ctx, http.MethodPost, u, &body, &r); err != nil {
return nil, err
}
return r, nil
}
// Make a copy of a security object.
//
// A new key will be created in the target group and will have the
// same key material as the original key. Links will be maintained
// between all copied keys and the source key.
// If the key is being copied to an externally linked group, it needs
// to be exportable.
//
// This can also be used to rotate an external key by copying the
// key material from a native DSM key. This key material will then
// finally be imported into the external KMS.
// For AWS KMS keys, after the rotation, the new key will have the
// original aliases and the old key's aliases will have
// (rotated at <timestamp>) appended in front of it.
func (c *Client) CopySobject(ctx context.Context, body CopySobjectRequest) (*Sobject, error) {
u := "/crypto/v1/keys/copy"
var r Sobject
if err := c.fetch(ctx, http.MethodPost, u, &body, &r); err != nil {
return nil, err
}
return &r, nil
}
func (c *Client) RequestApprovalToCopySobject(
ctx context.Context,
body CopySobjectRequest,
description *string) (*ApprovalRequest, error) {
u := "/crypto/v1/keys/copy"
req := ApprovalRequestRequest{
Method: someString(http.MethodPost),
Operation: &u,
Body: &body,
Description: description,
}
return c.CreateApprovalRequest(ctx, req)
}
// Generate a new security object.
//
// Generate a new security object (such as an RSA key pair or an AES key)
// of the requested size, elliptic curve, etc.
//
// By default, all key operations except for EXPORT that are implemented
// for that type of key will be enabled. These may be overridden by
// requesting specific operations in the key creation request.
//
// Objects of type Secret/Opaque may not be generated with this API.
// They must be imported via the import API.
//
// For AWS KMS keys, this generates the key material in AWS and a corresponding
// virtual key is created in DSM. Only 256-bit AES keys are supported.
func (c *Client) CreateSobject(ctx context.Context, body SobjectRequest) (*Sobject, error) {
u := "/crypto/v1/keys"
var r Sobject
if err := c.fetch(ctx, http.MethodPost, u, &body, &r); err != nil {
return nil, err
}
return &r, nil
}
// Delete the specified security object.
func (c *Client) DeleteSobject(ctx context.Context, id string) error {
u := "/crypto/v1/keys/:id"
u = strings.NewReplacer(":id", id).Replace(u)
if err := c.fetch(ctx, http.MethodDelete, u, nil, nil); err != nil {
return err
}
return nil
}
func (c *Client) RequestApprovalToDeleteSobject(
ctx context.Context,
id string,
description *string) (*ApprovalRequest, error) {
u := "/crypto/v1/keys/:id"
u = strings.NewReplacer(":id", id).Replace(u)
req := ApprovalRequestRequest{
Method: someString(http.MethodDelete),
Operation: &u,
Body: nil,
Description: description,
}
return c.CreateApprovalRequest(ctx, req)
}
// Transition a security object to Destroyed state. Objects in the
// `Destroyed` state cannot be used in any cryptographic operation.
// Their metadata however, remains accessible.
func (c *Client) DestroySobject(ctx context.Context, id string) error {
u := "/crypto/v1/keys/:id/destroy"
u = strings.NewReplacer(":id", id).Replace(u)
if err := c.fetch(ctx, http.MethodPost, u, nil, nil); err != nil {
return err
}
return nil
}
func (c *Client) RequestApprovalToDestroySobject(
ctx context.Context,
id string,
description *string) (*ApprovalRequest, error) {
u := "/crypto/v1/keys/:id/destroy"
u = strings.NewReplacer(":id", id).Replace(u)
req := ApprovalRequestRequest{
Method: someString(http.MethodPost),
Operation: &u,
Body: nil,
Description: description,
}
return c.CreateApprovalRequest(ctx, req)
}
// Retrieve the digest (hash) of the value of an exportable security object.
func (c *Client) DigestSobject(ctx context.Context, body ObjectDigestRequest) (*ObjectDigestResponse, error) {
u := "/crypto/v1/keys/digest"
var r ObjectDigestResponse
if err := c.fetch(ctx, http.MethodPost, u, &body, &r); err != nil {
return nil, err
}
return &r, nil
}
// Get the details and value of a particular exportable security object.
func (c *Client) ExportSobject(ctx context.Context, body SobjectDescriptor) (*Sobject, error) {
u := "/crypto/v1/keys/export"
var r Sobject
if err := c.fetch(ctx, http.MethodPost, u, &body, &r); err != nil {
return nil, err
}
return &r, nil
}
func (c *Client) RequestApprovalToExportSobject(
ctx context.Context,
body SobjectDescriptor,
description *string) (*ApprovalRequest, error) {
u := "/crypto/v1/keys/export"
req := ApprovalRequestRequest{
Method: someString(http.MethodPost),
Operation: &u,
Body: &body,
Description: description,
}
return c.CreateApprovalRequest(ctx, req)
}
// Exports the security object as components.
//
// Exports the security object as components. This API can only be called
// through an approval request and won't work if called directly. This
// requires a key custodian policy and quorum approval policy to be set at
// the group level. A new approval request needs to be created (see
// `POST /sys/v1/approval_requests`), then after getting the required approvals,
// the key custodians can fetch the result of this approval request
// (See `POST /sys/v1/approval_requests/:id/result`).
// Each key custodian will be able to get only their component.
//
// Only AES, DES, DES3 & HMAC objects are exportable by components.
//
// This is described in detail in the following article:
// https://support.fortanix.com/hc/en-us/articles/360043559332-User-s-Guide-Key-Components
func (c *Client) ExportSobjectComponents(ctx context.Context, body ExportSobjectComponentsRequest) (*ExportComponentsResponse, error) {
u := "/crypto/v1/keys/components/export"
var r ExportComponentsResponse
if err := c.fetch(ctx, http.MethodPost, u, &body, &r); err != nil {
return nil, err
}
return &r, nil
}
func (c *Client) RequestApprovalToExportSobjectComponents(
ctx context.Context,
body ExportSobjectComponentsRequest,
description *string) (*ApprovalRequest, error) {
u := "/crypto/v1/keys/components/export"
req := ApprovalRequestRequest{
Method: someString(http.MethodPost),
Operation: &u,
Body: &body,
Description: description,
}
return c.CreateApprovalRequest(ctx, req)
}
// Computes the KCV of the input and returns. This is
// only valid for AES, DES & DES3 keys.
func (c *Client) GetKcv(ctx context.Context, body SobjectDescriptor) (*KeyCheckValueResponse, error) {
u := "/crypto/v1/keys/kcv"
var r KeyCheckValueResponse
if err := c.fetch(ctx, http.MethodPost, u, &body, &r); err != nil {
return nil, err
}
return &r, nil
}
// Get public part of an asymmetric key.
//
// Returns the public part of an asymmetric key. This needs
// account id and key name as input. No auth is required for this.
// This works with RSA, EC and Certificate objects.
func (c *Client) GetPubkey(ctx context.Context, id string, name string) (map[string]Blob, error) {
u := "/crypto/v1/pubkey/:id/:name"
u = strings.NewReplacer(":id", id, ":name", name).Replace(u)
var r map[string]Blob
if err := c.fetch(ctx, http.MethodGet, u, nil, &r); err != nil {
return nil, err
}
return r, nil
}
// Lookup a security object.
func (c *Client) GetSobject(ctx context.Context, queryParameters *GetSobjectParams, body SobjectDescriptor) (*Sobject, error) {
u := "/crypto/v1/keys/info"
if queryParameters != nil {
q, err := encodeURLParams(queryParameters)
if err != nil {
return nil, err
}
u = fmt.Sprintf("%v?%v", u, q)
}
var r Sobject
if err := c.fetch(ctx, http.MethodPost, u, &body, &r); err != nil {
return nil, err
}
return &r, nil
}
// Import a security object.
//
// By default, all key operations that are implemented for that type of
// key will be enabled. These may be overridden by requesting specific
// operations in the key import request.
//
// For symmetric and asymmetric keys, value is base64-encoding of the
// key material in DER format.
//
// For AWS KMS keys, this imports the key material provided into the
// external KMS and a corresponding virtual key is created in DSM.
// Only AES 256 is supported for now.
func (c *Client) ImportSobject(ctx context.Context, body SobjectRequest) (*Sobject, error) {
u := "/crypto/v1/keys"
var r Sobject
if err := c.fetch(ctx, http.MethodPut, u, &body, &r); err != nil {
return nil, err
}
return &r, nil
}
// Import a security object by components.
//
// Import a security object by components. This API can only be called
// through an approval request and won't work if called directly. A key
// custodian and quorum policy needs to be set at the group level. After
// an import by components request has been made, key custodians will
// need to add their respective component via
// `POST /sys/v1/approval_requests/:id/approve`.
//
// Only AES, DES, DES3 & HMAC objects are importable by components.
//
// This is described in detail in the following article:
// https://support.fortanix.com/hc/en-us/articles/360043559332-User-s-Guide-Key-Components
func (c *Client) ImportSobjectByComponents(ctx context.Context, body ImportSobjectComponentsRequest) (*Sobject, error) {
u := "/crypto/v1/keys/components/import"
var r Sobject
if err := c.fetch(ctx, http.MethodPost, u, &body, &r); err != nil {
return nil, err
}
return &r, nil
}
func (c *Client) RequestApprovalToImportSobjectByComponents(
ctx context.Context,
body ImportSobjectComponentsRequest,
description *string) (*ApprovalRequest, error) {
u := "/crypto/v1/keys/components/import"
req := ApprovalRequestRequest{
Method: someString(http.MethodPost),
Operation: &u,
Body: &body,
Description: description,
}
return c.CreateApprovalRequest(ctx, req)
}
// Get all security objects accessible to the requester.
func (c *Client) ListSobjects(ctx context.Context, queryParameters *ListSobjectsParams) (*ListSobjectsResponse, error) {
u := "/crypto/v1/keys"
if queryParameters != nil {
q, err := encodeURLParams(queryParameters)
if err != nil {
return nil, err
}
u = fmt.Sprintf("%v?%v", u, q)
}
var r ListSobjectsResponse
if err := c.fetch(ctx, http.MethodGet, u, nil, &r); err != nil {
return nil, err
}
return &r, nil
}
// Persist a transient key.
//
// This API copies a transient key as a persisted security
// object. If the transient key's origin is "FortanixHSM",
// the origin of the persisted key will be "Transient". If the
// transient key's origin is "External", the origin of the persisted
// key will be "External".
func (c *Client) PersistTransientKey(ctx context.Context, body PersistTransientKeyRequest) (*Sobject, error) {
u := "/crypto/v1/keys/persist"
var r Sobject
if err := c.fetch(ctx, http.MethodPost, u, &body, &r); err != nil {
return nil, err
}
return &r, nil
}
// Destroy private half of an asymmetric key.
//
// Removes the private portion of an asymmetric key. After this
// operation is performed, operations that require the private key, such
// as encryption and generating signatures, can no longer be performed.
func (c *Client) RemovePrivate(ctx context.Context, id string) error {
u := "/crypto/v1/keys/:id/private"
u = strings.NewReplacer(":id", id).Replace(u)
if err := c.fetch(ctx, http.MethodDelete, u, nil, nil); err != nil {
return err
}
return nil
}
func (c *Client) RequestApprovalToRemovePrivate(
ctx context.Context,
id string,
description *string) (*ApprovalRequest, error) {
u := "/crypto/v1/keys/:id/private"
u = strings.NewReplacer(":id", id).Replace(u)
req := ApprovalRequestRequest{
Method: someString(http.MethodDelete),
Operation: &u,
Body: nil,
Description: description,
}
return c.CreateApprovalRequest(ctx, req)
}
// Rotate a security object to an existing security object.
//
// For two keys R and S, where R is the key to be replaced,
// and S is the intended replacement, this operation will
// - Rename R to the name provided in the request
// - Establish an replaced-replacement between R and S
// - Assign R's old name to S
//
// The metadata of S should be mostly same as that of R, and
// it is not possible to update any fields of S while
// performing this operation. If S does not have any custom
// metadata or a rotation policy, any corresponding values
// from R will be copied over to S.
// For now, this operation is not supported if R, S, or both
// are externally-backed keys.
func (c *Client) ReplaceSobject(ctx context.Context, body SobjectReplaceRequest) error {
u := "/crypto/v1/keys/replace"
if err := c.fetch(ctx, http.MethodPost, u, &body, nil); err != nil {
return err
}
return nil