|
| 1 | +package keymgmt |
| 2 | + |
| 3 | +import "context" |
| 4 | + |
| 5 | +type KeyManager interface { |
| 6 | + CreateKey(ctx context.Context, req CreateKeyRequest) (*KeyDescriptor, error) |
| 7 | + GetKey(ctx context.Context, ref KeyReference) (*KeyDescriptor, error) |
| 8 | + RotateKey(ctx context.Context, ref KeyReference, req RotateKeyRequest) (*KeyDescriptor, error) |
| 9 | + DeleteKey(ctx context.Context, ref KeyReference) error |
| 10 | + Capabilities(ctx context.Context) CapabilitySet |
| 11 | +} |
| 12 | + |
| 13 | +type KeyClass string |
| 14 | + |
| 15 | +const ( |
| 16 | + KeyClassAsymmetricKEM KeyClass = "asymmetric_kem" |
| 17 | + KeyClassAsymmetricEncryption KeyClass = "asymmetric_encryption" |
| 18 | + KeyClassSymmetricWrapping KeyClass = "symmetric_wrapping" |
| 19 | +) |
| 20 | + |
| 21 | +type KeyPurpose string |
| 22 | + |
| 23 | +const ( |
| 24 | + PurposeKeyEncapsulation KeyPurpose = "key_encapsulation" |
| 25 | + PurposeKeyWrapping KeyPurpose = "key_wrapping" |
| 26 | + PurposeRecipientDecrypt KeyPurpose = "recipient_decrypt" |
| 27 | +) |
| 28 | + |
| 29 | +type KeyAlgorithm string |
| 30 | + |
| 31 | +const ( |
| 32 | + AlgorithmMLKEM768 KeyAlgorithm = "ml-kem-768" |
| 33 | + AlgorithmMLKEM1024 KeyAlgorithm = "ml-kem-1024" |
| 34 | + AlgorithmRSAOAEP3072SHA256 KeyAlgorithm = "rsa-oaep-3072-sha256" |
| 35 | + AlgorithmAES256GCM KeyAlgorithm = "aes-256-gcm" |
| 36 | +) |
| 37 | + |
| 38 | +type ProtectionLevel string |
| 39 | + |
| 40 | +const ( |
| 41 | + ProtectionSoftware ProtectionLevel = "software" |
| 42 | + ProtectionHSM ProtectionLevel = "hsm" |
| 43 | + ProtectionKMS ProtectionLevel = "kms" |
| 44 | +) |
| 45 | + |
| 46 | +type SecurityLevel string |
| 47 | + |
| 48 | +const ( |
| 49 | + SecurityLevelLocalPQ SecurityLevel = "local_pq" |
| 50 | + SecurityLevelCloudPQNative SecurityLevel = "cloud_pq_native" |
| 51 | + SecurityLevelCloudClassic SecurityLevel = "cloud_classical" |
| 52 | +) |
| 53 | + |
| 54 | +type CreateKeyRequest struct { |
| 55 | + Name string `json:"name"` |
| 56 | + Purpose KeyPurpose `json:"purpose"` |
| 57 | + Algorithm KeyAlgorithm `json:"algorithm"` |
| 58 | + ProtectionLevel ProtectionLevel `json:"protection_level"` |
| 59 | + Exportable bool `json:"exportable"` |
| 60 | + Metadata map[string]string `json:"metadata,omitempty"` |
| 61 | +} |
| 62 | + |
| 63 | +type RotateKeyRequest struct { |
| 64 | + SuccessorName string `json:"successor_name"` |
| 65 | + Metadata map[string]string `json:"metadata,omitempty"` |
| 66 | +} |
| 67 | + |
| 68 | +type KeyReference struct { |
| 69 | + Backend string `json:"backend"` |
| 70 | + URI string `json:"uri"` |
| 71 | + ID string `json:"id"` |
| 72 | + Version string `json:"version"` |
| 73 | +} |
| 74 | + |
| 75 | +type PublicKeyInfo struct { |
| 76 | + Algorithm KeyAlgorithm `json:"algorithm"` |
| 77 | + Data []byte `json:"data"` |
| 78 | +} |
| 79 | + |
| 80 | +type KeyDescriptor struct { |
| 81 | + ID string `json:"id"` |
| 82 | + Backend string `json:"backend"` |
| 83 | + Class KeyClass `json:"class"` |
| 84 | + Purpose KeyPurpose `json:"purpose"` |
| 85 | + Algorithm KeyAlgorithm `json:"algorithm"` |
| 86 | + SecurityLevel SecurityLevel `json:"security_level"` |
| 87 | + Reference KeyReference `json:"reference"` |
| 88 | + PublicInfo *PublicKeyInfo `json:"public_info,omitempty"` |
| 89 | + Capabilities CapabilitySet `json:"capabilities"` |
| 90 | + Metadata map[string]string `json:"metadata,omitempty"` |
| 91 | +} |
| 92 | + |
| 93 | +type CapabilitySet struct { |
| 94 | + CanCreateKeys bool `json:"can_create_keys"` |
| 95 | + CanDeleteKeys bool `json:"can_delete_keys"` |
| 96 | + CanRotateProviderNative bool `json:"can_rotate_provider_native"` |
| 97 | + CanExportPublicKey bool `json:"can_export_public_key"` |
| 98 | + CanResolveRecipient bool `json:"can_resolve_recipient"` |
| 99 | + SupportsPQNatively bool `json:"supports_pq_natively"` |
| 100 | + SupportsClassicalWrapping bool `json:"supports_classical_wrapping"` |
| 101 | + SupportsRewrapWorkflow bool `json:"supports_rewrap_workflow"` |
| 102 | +} |
| 103 | + |
| 104 | +func CloneMap(in map[string]string) map[string]string { |
| 105 | + if len(in) == 0 { |
| 106 | + return nil |
| 107 | + } |
| 108 | + out := make(map[string]string, len(in)) |
| 109 | + for k, v := range in { |
| 110 | + out[k] = v |
| 111 | + } |
| 112 | + return out |
| 113 | +} |
0 commit comments