@sebastienrousseau/crypto-kms 0.0.35 → 0.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -20
- package/dist/errors.d.ts.map +1 -1
- package/dist/providers/algorithms.d.ts +11 -0
- package/dist/providers/algorithms.d.ts.map +1 -0
- package/dist/providers/algorithms.js +78 -0
- package/dist/providers/aws.d.ts +1 -0
- package/dist/providers/aws.d.ts.map +1 -1
- package/dist/providers/aws.js +53 -16
- package/dist/providers/azure.d.ts.map +1 -1
- package/dist/providers/azure.js +13 -12
- package/dist/providers/gcp.d.ts +4 -1
- package/dist/providers/gcp.d.ts.map +1 -1
- package/dist/providers/gcp.js +129 -44
- package/dist/providers/local.d.ts.map +1 -1
- package/dist/providers/local.js +4 -2
- package/dist/providers/pkcs11.d.ts.map +1 -1
- package/dist/providers/pkcs11.js +4 -2
- package/dist/providers/vault.d.ts +5 -2
- package/dist/providers/vault.d.ts.map +1 -1
- package/dist/providers/vault.js +58 -54
- package/dist/providers/versioned-key.d.ts +1 -0
- package/dist/providers/versioned-key.d.ts.map +1 -1
- package/dist/providers/versioned-key.js +12 -1
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
<h1 align="center">@sebastienrousseau/crypto-kms</h1>
|
|
8
8
|
|
|
9
9
|
<p align="center">
|
|
10
|
-
Unified Key Management Service interface
|
|
10
|
+
Unified Key Management Service interface with AWS KMS, Google Cloud KMS, HashiCorp Vault Transit and in-memory local providers. Azure is a stub.
|
|
11
11
|
</p>
|
|
12
12
|
|
|
13
13
|
<p align="center">
|
|
@@ -98,12 +98,12 @@ Crypto Service provides a complete cryptography stack across 14 specialized pack
|
|
|
98
98
|
|
|
99
99
|
| Package | Role | Description |
|
|
100
100
|
| :---------------------------------------------------------------------------------------------------------------------------------------- | :-------------- | :----------------------------------------------------------------------------------------------------------------------------- |
|
|
101
|
-
| [`@sebastienrousseau/crypto-api`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-api) | API
|
|
101
|
+
| [`@sebastienrousseau/crypto-api`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-api) | API docs | Postman collection types and a Postman-to-Markdown converter; the server's API contract is its OpenAPI document. |
|
|
102
102
|
| [`@sebastienrousseau/crypto-benchmarks`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-benchmarks) | Benchmarks | Benchmarks comparing classical and post-quantum cryptography: ops/sec, latency and throughput. |
|
|
103
103
|
| [`@sebastienrousseau/crypto-cbom`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-cbom) | CBOM | Cryptographic Bill of Materials generator and auditor (CycloneDX 1.6, SPDX 3.0). |
|
|
104
104
|
| [`@sebastienrousseau/crypto-cli`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-cli) | Terminal CLI | Command-line interface: hashing, key generation, encryption, signing, HPKE, Argon2id and CBOM scans, with an interactive menu. |
|
|
105
105
|
| [`@sebastienrousseau/crypto-edge`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-edge) | Edge Runtime | Edge-runtime cryptographic operations using the Web Crypto API, optimized for Cloudflare Workers, Vercel Edge, and Deno. |
|
|
106
|
-
| **[`@sebastienrousseau/crypto-kms`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-kms)** _(this package)_ | **Cloud KMS** | **Unified KMS interface: AWS KMS and local providers
|
|
106
|
+
| **[`@sebastienrousseau/crypto-kms`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-kms)** _(this package)_ | **Cloud KMS** | **Unified KMS interface: AWS KMS, Google Cloud KMS, Vault Transit and local providers; Azure is a stub.** |
|
|
107
107
|
| [`@sebastienrousseau/crypto-lib`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-lib) | Core Library | Core library: post-quantum ML-KEM, ML-DSA and SLH-DSA, plus classical, modern and OpenPGP cryptography for TypeScript. |
|
|
108
108
|
| [`@sebastienrousseau/crypto-lsp`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-lsp) | IDE Analysis | Language server that flags weak and quantum-vulnerable cryptography in the editor, with quick fixes. |
|
|
109
109
|
| [`@sebastienrousseau/crypto-mcp`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-mcp) | AI Agents | Model Context Protocol server exposing cryptography tools to AI assistants and agents. |
|
|
@@ -125,24 +125,53 @@ Crypto Service provides a complete cryptography stack across 14 specialized pack
|
|
|
125
125
|
|
|
126
126
|
crypto-kms defines a unified `KmsProvider` interface for key
|
|
127
127
|
creation, encryption, decryption, signing, verification, rotation
|
|
128
|
-
and data-key generation.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
The
|
|
132
|
-
|
|
128
|
+
and data-key generation. Four providers talk to a real key store: AWS
|
|
129
|
+
KMS (through the AWS SDK), Google Cloud KMS and HashiCorp Vault
|
|
130
|
+
Transit (through their REST APIs, with `fetch`), and an in-memory
|
|
131
|
+
local provider. The Azure Key Vault provider is a stub: every method
|
|
132
|
+
rejects with `NOT_IMPLEMENTED`. The PKCS#11 provider is an in-memory
|
|
133
|
+
software simulation for tests (see below); it does not talk to an HSM.
|
|
134
|
+
|
|
135
|
+
`createKey` creates exactly the algorithm you ask for or rejects with
|
|
136
|
+
`INVALID_ARGUMENT`; it never substitutes another. Each provider accepts
|
|
137
|
+
the names below, and its backend's own names (such as `ML_DSA_65` on
|
|
138
|
+
AWS or `EC_SIGN_P384_SHA384` on Google Cloud).
|
|
133
139
|
|
|
134
140
|
<p align="right"><a href="#contents">Back to Top</a></p>
|
|
135
141
|
|
|
136
142
|
## Providers
|
|
137
143
|
|
|
138
|
-
| Provider | Class | Backend |
|
|
139
|
-
| :---------- | :------------------ | :------------------------- |
|
|
140
|
-
| **AWS** | `AwsKmsProvider` | AWS Key Management Service |
|
|
141
|
-
| **GCP** | `GcpKmsProvider` | Google Cloud KMS
|
|
142
|
-
| **
|
|
143
|
-
| **
|
|
144
|
-
| **
|
|
145
|
-
| **PKCS#11** | `Pkcs11HsmProvider` | None (in-memory) | Software simulation
|
|
144
|
+
| Provider | Class | Backend | Encryption and wrap | Signing | Dependency |
|
|
145
|
+
| :---------- | :------------------ | :------------------------- | :--------------------------------------------------------- | :------------------------------------------------------------------------- | :-------------------- |
|
|
146
|
+
| **AWS** | `AwsKmsProvider` | AWS Key Management Service | `aes-256-gcm` (`SYMMETRIC_DEFAULT`), `rsa-*` | `ed25519`, `p256`, `p384`, `p521`, `secp256k1`, `rsa-*`, `ml-dsa-44/65/87` | `@aws-sdk/client-kms` |
|
|
147
|
+
| **GCP** | `GcpKmsProvider` | Google Cloud KMS (REST v1) | `aes-256-gcm` (`GOOGLE_SYMMETRIC_ENCRYPTION`) | `ed25519`, `p256`, `p384`, `rsa-2048/3072/4096` (PSS or PKCS#1) | None |
|
|
148
|
+
| **Vault** | `VaultKmsProvider` | HashiCorp Vault Transit | `aes-256-gcm`, `aes-128-gcm`, `chacha20-poly1305`, `rsa-*` | `ed25519`, `p256`, `p384`, `p521`, `rsa-*` | None |
|
|
149
|
+
| **Local** | `LocalKmsProvider` | In-memory (crypto-lib) | `aes-256-gcm` | `ed25519` | None |
|
|
150
|
+
| **Azure** | `AzureKmsProvider` | Azure Key Vault | Stub: rejects `NOT_IMPLEMENTED` | Stub | None |
|
|
151
|
+
| **PKCS#11** | `Pkcs11HsmProvider` | None (in-memory) | Software simulation of `aes-256-gcm`; `simulate: true` | Software simulation of `ed25519` | None |
|
|
152
|
+
|
|
153
|
+
Backend behaviour worth knowing:
|
|
154
|
+
|
|
155
|
+
- **AWS**: without an explicit algorithm, `sign` and `verify` use the
|
|
156
|
+
one matching the key spec (for example `ECDSA_SHA_256` for P-256,
|
|
157
|
+
`ML_DSA_SHAKE_256` for ML-DSA). `rotateKey` rotates on demand, which
|
|
158
|
+
AWS supports for symmetric keys only.
|
|
159
|
+
- **Google Cloud**: signing uses the newest enabled key version, and
|
|
160
|
+
verification is done locally against the public key of each enabled
|
|
161
|
+
version, since Cloud KMS has no remote asymmetric verify; signatures
|
|
162
|
+
made before a rotation keep verifying until their version is
|
|
163
|
+
disabled. Post-quantum signing keys are refused for now.
|
|
164
|
+
`enableKey`, `disableKey` and `scheduleKeyDeletion` act on every
|
|
165
|
+
version; deletion uses the key's own destroy-scheduled duration.
|
|
166
|
+
- **Vault**: the encryption context is bound as Transit
|
|
167
|
+
`associated_data`. Ciphertext written by crypto-kms 0.0.35 or
|
|
168
|
+
earlier is not bound to its context; set `acceptUnboundContext` to
|
|
169
|
+
read it, then re-encrypt. Transit cannot disable a key, so
|
|
170
|
+
`enableKey`/`disableKey` reject with `NOT_IMPLEMENTED`; deletion is
|
|
171
|
+
immediate, so `scheduleKeyDeletion` requires `pendingWindowDays: 0`
|
|
172
|
+
to confirm. Vault creates a key on the first encrypt to an unknown
|
|
173
|
+
name unless the token's policy denies `create` on `transit/encrypt`;
|
|
174
|
+
grant `update` only.
|
|
146
175
|
|
|
147
176
|
`Pkcs11HsmProvider` has no PKCS#11 binding: it never loads a module,
|
|
148
177
|
accepts any PIN, keeps keys in process memory and reports
|
|
@@ -225,7 +254,7 @@ message:
|
|
|
225
254
|
| `INVALID_CIPHERTEXT` | Truncated ciphertext or an unknown format |
|
|
226
255
|
| `DECRYPTION_FAILED` | Wrong context, wrong key, or tampered ciphertext |
|
|
227
256
|
| `VERSION_DESTROYED` | The ciphertext's key version has been destroyed |
|
|
228
|
-
| `NOT_IMPLEMENTED` | Stub provider (
|
|
257
|
+
| `NOT_IMPLEMENTED` | Stub provider (Azure), or an operation the backend lacks |
|
|
229
258
|
| `DEPENDENCY_MISSING` | The AWS SDK peer dependency is not installed |
|
|
230
259
|
|
|
231
260
|
Errors raised by the AWS SDK itself are passed through unchanged. No
|
|
@@ -238,9 +267,9 @@ provider method takes a timeout or an `AbortSignal` yet.
|
|
|
238
267
|
| Provider | Credentials |
|
|
239
268
|
| :-------- | :--------------------------------------------------------------------------------- |
|
|
240
269
|
| **AWS** | Pass `credentials` in `AwsKmsOptions`, or rely on the default AWS credential chain |
|
|
241
|
-
| **GCP** |
|
|
242
|
-
| **Azure** | Not applicable
|
|
243
|
-
| **Vault** |
|
|
270
|
+
| **GCP** | An OAuth2 access token in `token`; the provider does not refresh it |
|
|
271
|
+
| **Azure** | Not applicable (stub provider) |
|
|
272
|
+
| **Vault** | A Vault token in `token`, and `namespace` for Vault Enterprise namespaces |
|
|
244
273
|
| **Local** | No authentication required |
|
|
245
274
|
|
|
246
275
|
<p align="right"><a href="#contents">Back to Top</a></p>
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AA2BA,MAAM,MAAM,YAAY,GACpB,WAAW,GACX,UAAU,GACV,eAAe,GACf,kBAAkB,GAClB,oBAAoB,GACpB,mBAAmB,GACnB,mBAAmB,GACnB,iBAAiB,GACjB,oBAAoB,CAAC;AAmBzB,qBAAa,QAAS,SAAQ,KAAK;IAEjC,SAAkB,IAAI,cAAc;IAEpC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAE5B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;gBAGvB,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;CAKhE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type KeyUsage = "encrypt" | "sign" | "wrap";
|
|
2
|
+
export interface AlgorithmTable {
|
|
3
|
+
encrypt: Readonly<Record<string, string>>;
|
|
4
|
+
sign: Readonly<Record<string, string>>;
|
|
5
|
+
}
|
|
6
|
+
export declare function resolveAlgorithm(provider: string, table: AlgorithmTable, algorithm: string, usage: KeyUsage): string;
|
|
7
|
+
export declare const LOCAL_ALGORITHMS: AlgorithmTable;
|
|
8
|
+
export declare const GCP_ALGORITHMS: AlgorithmTable;
|
|
9
|
+
export declare const VAULT_ALGORITHMS: AlgorithmTable;
|
|
10
|
+
export declare const AWS_ALGORITHMS: AlgorithmTable;
|
|
11
|
+
//# sourceMappingURL=algorithms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"algorithms.d.ts","sourceRoot":"","sources":["../../src/providers/algorithms.ts"],"names":[],"mappings":"AAeA,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAOnD,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1C,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACxC;AAMD,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,cAAc,EACrB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,QAAQ,GACd,MAAM,CAaR;AAOD,eAAO,MAAM,gBAAgB,EAAE,cAG9B,CAAC;AAMF,eAAO,MAAM,cAAc,EAAE,cA4B5B,CAAC;AAGF,eAAO,MAAM,gBAAgB,EAAE,cA2B9B,CAAC;AAGF,eAAO,MAAM,cAAc,EAAE,cAqC5B,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AWS_ALGORITHMS = exports.VAULT_ALGORITHMS = exports.GCP_ALGORITHMS = exports.LOCAL_ALGORITHMS = void 0;
|
|
4
|
+
exports.resolveAlgorithm = resolveAlgorithm;
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
function resolveAlgorithm(provider, table, algorithm, usage) {
|
|
7
|
+
const names = usage === "sign" ? table.sign : table.encrypt;
|
|
8
|
+
const resolved = Object.hasOwn(names, algorithm.toLowerCase())
|
|
9
|
+
? names[algorithm.toLowerCase()]
|
|
10
|
+
: undefined;
|
|
11
|
+
if (resolved === undefined) {
|
|
12
|
+
const supported = [...new Set(Object.values(names))].join(", ");
|
|
13
|
+
throw new errors_1.KmsError("INVALID_ARGUMENT", `${provider} cannot create a ${algorithm} key for ${usage}; supported: ${supported}`);
|
|
14
|
+
}
|
|
15
|
+
return resolved;
|
|
16
|
+
}
|
|
17
|
+
const native = (...names) => Object.fromEntries(names.map((n) => [n.toLowerCase(), n]));
|
|
18
|
+
exports.LOCAL_ALGORITHMS = {
|
|
19
|
+
encrypt: { "aes-256-gcm": "aes-256-gcm" },
|
|
20
|
+
sign: { ed25519: "ed25519" },
|
|
21
|
+
};
|
|
22
|
+
exports.GCP_ALGORITHMS = {
|
|
23
|
+
encrypt: {
|
|
24
|
+
"aes-256-gcm": "GOOGLE_SYMMETRIC_ENCRYPTION",
|
|
25
|
+
...native("GOOGLE_SYMMETRIC_ENCRYPTION"),
|
|
26
|
+
},
|
|
27
|
+
sign: {
|
|
28
|
+
ed25519: "EC_SIGN_ED25519",
|
|
29
|
+
p256: "EC_SIGN_P256_SHA256",
|
|
30
|
+
"ecdsa-p256": "EC_SIGN_P256_SHA256",
|
|
31
|
+
p384: "EC_SIGN_P384_SHA384",
|
|
32
|
+
"ecdsa-p384": "EC_SIGN_P384_SHA384",
|
|
33
|
+
"rsa-2048": "RSA_SIGN_PSS_2048_SHA256",
|
|
34
|
+
"rsa-3072": "RSA_SIGN_PSS_3072_SHA256",
|
|
35
|
+
"rsa-4096": "RSA_SIGN_PSS_4096_SHA256",
|
|
36
|
+
...native("EC_SIGN_ED25519", "EC_SIGN_P256_SHA256", "EC_SIGN_P384_SHA384", "RSA_SIGN_PSS_2048_SHA256", "RSA_SIGN_PSS_3072_SHA256", "RSA_SIGN_PSS_4096_SHA256", "RSA_SIGN_PSS_4096_SHA512", "RSA_SIGN_PKCS1_2048_SHA256", "RSA_SIGN_PKCS1_3072_SHA256", "RSA_SIGN_PKCS1_4096_SHA256", "RSA_SIGN_PKCS1_4096_SHA512"),
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
exports.VAULT_ALGORITHMS = {
|
|
40
|
+
encrypt: {
|
|
41
|
+
"aes-256-gcm": "aes256-gcm96",
|
|
42
|
+
"aes-128-gcm": "aes128-gcm96",
|
|
43
|
+
...native("aes256-gcm96", "aes128-gcm96", "chacha20-poly1305", "rsa-2048", "rsa-3072", "rsa-4096"),
|
|
44
|
+
},
|
|
45
|
+
sign: {
|
|
46
|
+
p256: "ecdsa-p256",
|
|
47
|
+
p384: "ecdsa-p384",
|
|
48
|
+
p521: "ecdsa-p521",
|
|
49
|
+
...native("ed25519", "ecdsa-p256", "ecdsa-p384", "ecdsa-p521", "rsa-2048", "rsa-3072", "rsa-4096"),
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
exports.AWS_ALGORITHMS = {
|
|
53
|
+
encrypt: {
|
|
54
|
+
"aes-256-gcm": "SYMMETRIC_DEFAULT",
|
|
55
|
+
"rsa-2048": "RSA_2048",
|
|
56
|
+
"rsa-3072": "RSA_3072",
|
|
57
|
+
"rsa-4096": "RSA_4096",
|
|
58
|
+
...native("SYMMETRIC_DEFAULT", "RSA_2048", "RSA_3072", "RSA_4096"),
|
|
59
|
+
},
|
|
60
|
+
sign: {
|
|
61
|
+
ed25519: "ECC_NIST_EDWARDS25519",
|
|
62
|
+
p256: "ECC_NIST_P256",
|
|
63
|
+
"ecdsa-p256": "ECC_NIST_P256",
|
|
64
|
+
p384: "ECC_NIST_P384",
|
|
65
|
+
"ecdsa-p384": "ECC_NIST_P384",
|
|
66
|
+
p521: "ECC_NIST_P521",
|
|
67
|
+
"ecdsa-p521": "ECC_NIST_P521",
|
|
68
|
+
secp256k1: "ECC_SECG_P256K1",
|
|
69
|
+
"rsa-2048": "RSA_2048",
|
|
70
|
+
"rsa-3072": "RSA_3072",
|
|
71
|
+
"rsa-4096": "RSA_4096",
|
|
72
|
+
"ml-dsa-44": "ML_DSA_44",
|
|
73
|
+
"ml-dsa-65": "ML_DSA_65",
|
|
74
|
+
"ml-dsa-87": "ML_DSA_87",
|
|
75
|
+
...native("ECC_NIST_EDWARDS25519", "ECC_NIST_P256", "ECC_NIST_P384", "ECC_NIST_P521", "ECC_SECG_P256K1", "RSA_2048", "RSA_3072", "RSA_4096", "ML_DSA_44", "ML_DSA_65", "ML_DSA_87"),
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=algorithms.js.map
|
package/dist/providers/aws.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export declare class AwsKmsProvider implements KmsProvider {
|
|
|
25
25
|
scheduleKeyDeletion(keyId: string, pendingWindowDays?: number): Promise<void>;
|
|
26
26
|
encrypt(keyId: string, plaintext: Uint8Array, context?: Record<string, string>): Promise<KmsEncryptResult>;
|
|
27
27
|
decrypt(keyId: string, ciphertext: string, context?: Record<string, string>): Promise<KmsDecryptResult>;
|
|
28
|
+
private signingAlgorithm;
|
|
28
29
|
sign(keyId: string, data: Uint8Array, algorithm?: string): Promise<KmsSignResult>;
|
|
29
30
|
verify(keyId: string, data: Uint8Array, signature: string, algorithm?: string): Promise<boolean>;
|
|
30
31
|
rotateKey(keyId: string): Promise<KmsKeyMetadata>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws.d.ts","sourceRoot":"","sources":["../../src/providers/aws.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACd,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"aws.d.ts","sourceRoot":"","sources":["../../src/providers/aws.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACd,MAAM,UAAU,CAAC;AAuClB,MAAM,WAAW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EAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,gBAAgB,CAAC;YAqBd,gBAAgB;IAmBxB,IAAI,CACR,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,UAAU,EAChB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,aAAa,CAAC;IAwBnB,MAAM,CACV,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,OAAO,CAAC;IA2Bb,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAQjD,eAAe,CACnB,KAAK,EAAE,MAAM,EACb,OAAO,SAAY,GAClB,OAAO,CAAC;QAET,SAAS,EAAE,UAAU,CAAC;QAEtB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IAgBI,OAAO,CACX,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,UAAU,EACxB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAM3C,SAAS,CACb,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC;QAAE,YAAY,EAAE,UAAU,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAIxD"}
|
package/dist/providers/aws.js
CHANGED
|
@@ -35,6 +35,20 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.AwsKmsProvider = void 0;
|
|
37
37
|
const errors_1 = require("../errors");
|
|
38
|
+
const algorithms_1 = require("./algorithms");
|
|
39
|
+
const DEFAULT_SIGNING_ALGORITHM = {
|
|
40
|
+
ECC_NIST_P256: "ECDSA_SHA_256",
|
|
41
|
+
ECC_NIST_P384: "ECDSA_SHA_384",
|
|
42
|
+
ECC_NIST_P521: "ECDSA_SHA_512",
|
|
43
|
+
ECC_SECG_P256K1: "ECDSA_SHA_256",
|
|
44
|
+
ECC_NIST_EDWARDS25519: "ED25519_SHA_512",
|
|
45
|
+
RSA_2048: "RSASSA_PSS_SHA_256",
|
|
46
|
+
RSA_3072: "RSASSA_PSS_SHA_256",
|
|
47
|
+
RSA_4096: "RSASSA_PSS_SHA_256",
|
|
48
|
+
ML_DSA_44: "ML_DSA_SHAKE_256",
|
|
49
|
+
ML_DSA_65: "ML_DSA_SHAKE_256",
|
|
50
|
+
ML_DSA_87: "ML_DSA_SHAKE_256",
|
|
51
|
+
};
|
|
38
52
|
const AWS_SDK_MISSING = "AWS KMS requires @aws-sdk/client-kms. Install it: npm install @aws-sdk/client-kms";
|
|
39
53
|
class AwsKmsProvider {
|
|
40
54
|
name = "aws";
|
|
@@ -91,9 +105,9 @@ class AwsKmsProvider {
|
|
|
91
105
|
};
|
|
92
106
|
}
|
|
93
107
|
async createKey(algorithm, usage, metadata) {
|
|
108
|
+
const keySpec = (0, algorithms_1.resolveAlgorithm)("AwsKmsProvider", algorithms_1.AWS_ALGORITHMS, algorithm, usage);
|
|
94
109
|
const client = await this.getClient();
|
|
95
110
|
const { CreateKeyCommand } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-kms")));
|
|
96
|
-
const keySpec = algorithm.toUpperCase().replace(/-/g, "_");
|
|
97
111
|
const result = await client.send(new CreateKeyCommand({
|
|
98
112
|
KeyUsage: usage === "sign" ? "SIGN_VERIFY" : "ENCRYPT_DECRYPT",
|
|
99
113
|
KeySpec: keySpec,
|
|
@@ -108,7 +122,7 @@ class AwsKmsProvider {
|
|
|
108
122
|
}));
|
|
109
123
|
return {
|
|
110
124
|
keyId: result.KeyMetadata?.KeyId ?? "",
|
|
111
|
-
algorithm,
|
|
125
|
+
algorithm: keySpec,
|
|
112
126
|
usage,
|
|
113
127
|
createdAt: result.KeyMetadata?.CreationDate?.toISOString() ??
|
|
114
128
|
new Date().toISOString(),
|
|
@@ -164,37 +178,60 @@ class AwsKmsProvider {
|
|
|
164
178
|
keyId: result.KeyId ?? keyId,
|
|
165
179
|
};
|
|
166
180
|
}
|
|
167
|
-
async
|
|
181
|
+
async signingAlgorithm(keyId, algorithm) {
|
|
182
|
+
if (algorithm)
|
|
183
|
+
return algorithm;
|
|
184
|
+
const client = await this.getClient();
|
|
185
|
+
const { DescribeKeyCommand } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-kms")));
|
|
186
|
+
const res = await client.send(new DescribeKeyCommand({ KeyId: keyId }));
|
|
187
|
+
const meta = res.KeyMetadata;
|
|
188
|
+
const chosen = DEFAULT_SIGNING_ALGORITHM[meta?.KeySpec ?? ""] ??
|
|
189
|
+
meta?.SigningAlgorithms?.[0];
|
|
190
|
+
if (!chosen) {
|
|
191
|
+
throw new errors_1.KmsError("INVALID_USAGE", `Key ${keyId} cannot sign`, keyId);
|
|
192
|
+
}
|
|
193
|
+
return chosen;
|
|
194
|
+
}
|
|
195
|
+
async sign(keyId, data, algorithm) {
|
|
196
|
+
const signingAlgorithm = await this.signingAlgorithm(keyId, algorithm);
|
|
168
197
|
const client = await this.getClient();
|
|
169
198
|
const { SignCommand } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-kms")));
|
|
170
199
|
const result = await client.send(new SignCommand({
|
|
171
200
|
KeyId: keyId,
|
|
172
201
|
Message: data,
|
|
173
202
|
MessageType: "RAW",
|
|
174
|
-
SigningAlgorithm:
|
|
203
|
+
SigningAlgorithm: signingAlgorithm,
|
|
175
204
|
}));
|
|
176
205
|
return {
|
|
177
206
|
signature: Buffer.from(result.Signature).toString("base64"),
|
|
178
207
|
keyId: result.KeyId ?? keyId,
|
|
179
|
-
algorithm: result.SigningAlgorithm ??
|
|
208
|
+
algorithm: result.SigningAlgorithm ?? signingAlgorithm,
|
|
180
209
|
};
|
|
181
210
|
}
|
|
182
|
-
async verify(keyId, data, signature, algorithm
|
|
211
|
+
async verify(keyId, data, signature, algorithm) {
|
|
212
|
+
const signingAlgorithm = await this.signingAlgorithm(keyId, algorithm);
|
|
183
213
|
const client = await this.getClient();
|
|
184
214
|
const { VerifyCommand } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-kms")));
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
215
|
+
try {
|
|
216
|
+
const result = await client.send(new VerifyCommand({
|
|
217
|
+
KeyId: keyId,
|
|
218
|
+
Message: data,
|
|
219
|
+
MessageType: "RAW",
|
|
220
|
+
Signature: Buffer.from(signature, "base64"),
|
|
221
|
+
SigningAlgorithm: signingAlgorithm,
|
|
222
|
+
}));
|
|
223
|
+
return result.SignatureValid === true;
|
|
224
|
+
}
|
|
225
|
+
catch (err) {
|
|
226
|
+
if (err.name === "KMSInvalidSignatureException")
|
|
227
|
+
return false;
|
|
228
|
+
throw err;
|
|
229
|
+
}
|
|
193
230
|
}
|
|
194
231
|
async rotateKey(keyId) {
|
|
195
232
|
const client = await this.getClient();
|
|
196
|
-
const {
|
|
197
|
-
await client.send(new
|
|
233
|
+
const { RotateKeyOnDemandCommand } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-kms")));
|
|
234
|
+
await client.send(new RotateKeyOnDemandCommand({ KeyId: keyId }));
|
|
198
235
|
return this.getKey(keyId);
|
|
199
236
|
}
|
|
200
237
|
async generateDataKey(keyId, keySpec = "AES_256") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"azure.d.ts","sourceRoot":"","sources":["../../src/providers/azure.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"azure.d.ts","sourceRoot":"","sources":["../../src/providers/azure.ts"],"names":[],"mappings":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AAM,CAAC,GAChC,OAAO,CAAC,gBAAgB,CAAC;IAO5B,IAAI,CACF,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,UAAU,EACjB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,aAAa,CAAC;IAOzB,MAAM,CACJ,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,UAAU,EACjB,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,OAAO,CAAC;IAOnB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAOlD,eAAe,CACb,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;QAET,SAAS,EAAE,UAAU,CAAC;QAEtB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CAKH"}
|
package/dist/providers/azure.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AzureKmsProvider = void 0;
|
|
4
4
|
const errors_1 = require("../errors");
|
|
5
|
+
const NOT_IMPLEMENTED_MESSAGE = "Not implemented: the Azure Key Vault provider is a stub";
|
|
5
6
|
class AzureKmsProvider {
|
|
6
7
|
name = "azure";
|
|
7
8
|
_vaultUrl;
|
|
@@ -12,40 +13,40 @@ class AzureKmsProvider {
|
|
|
12
13
|
return this._vaultUrl;
|
|
13
14
|
}
|
|
14
15
|
listKeys(_filters) {
|
|
15
|
-
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED",
|
|
16
|
+
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED", NOT_IMPLEMENTED_MESSAGE));
|
|
16
17
|
}
|
|
17
18
|
getKey(_keyId) {
|
|
18
|
-
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED",
|
|
19
|
+
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED", NOT_IMPLEMENTED_MESSAGE));
|
|
19
20
|
}
|
|
20
21
|
createKey(_algorithm, _usage, _metadata) {
|
|
21
|
-
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED",
|
|
22
|
+
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED", NOT_IMPLEMENTED_MESSAGE));
|
|
22
23
|
}
|
|
23
24
|
enableKey(_keyId) {
|
|
24
|
-
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED",
|
|
25
|
+
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED", NOT_IMPLEMENTED_MESSAGE));
|
|
25
26
|
}
|
|
26
27
|
disableKey(_keyId) {
|
|
27
|
-
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED",
|
|
28
|
+
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED", NOT_IMPLEMENTED_MESSAGE));
|
|
28
29
|
}
|
|
29
30
|
scheduleKeyDeletion(_keyId, _pendingWindowDays) {
|
|
30
|
-
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED",
|
|
31
|
+
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED", NOT_IMPLEMENTED_MESSAGE));
|
|
31
32
|
}
|
|
32
33
|
encrypt(_keyId, _plaintext, _context) {
|
|
33
|
-
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED",
|
|
34
|
+
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED", NOT_IMPLEMENTED_MESSAGE));
|
|
34
35
|
}
|
|
35
36
|
decrypt(_keyId, _ciphertext, _context) {
|
|
36
|
-
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED",
|
|
37
|
+
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED", NOT_IMPLEMENTED_MESSAGE));
|
|
37
38
|
}
|
|
38
39
|
sign(_keyId, _data, _algorithm) {
|
|
39
|
-
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED",
|
|
40
|
+
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED", NOT_IMPLEMENTED_MESSAGE));
|
|
40
41
|
}
|
|
41
42
|
verify(_keyId, _data, _signature, _algorithm) {
|
|
42
|
-
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED",
|
|
43
|
+
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED", NOT_IMPLEMENTED_MESSAGE));
|
|
43
44
|
}
|
|
44
45
|
rotateKey(_keyId) {
|
|
45
|
-
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED",
|
|
46
|
+
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED", NOT_IMPLEMENTED_MESSAGE));
|
|
46
47
|
}
|
|
47
48
|
generateDataKey(_keyId, _keySpec) {
|
|
48
|
-
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED",
|
|
49
|
+
return Promise.reject(new errors_1.KmsError("NOT_IMPLEMENTED", NOT_IMPLEMENTED_MESSAGE));
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
exports.AzureKmsProvider = AzureKmsProvider;
|
package/dist/providers/gcp.d.ts
CHANGED
|
@@ -20,12 +20,15 @@ export declare class GcpKmsProvider implements KmsProvider {
|
|
|
20
20
|
}): Promise<KmsKeyMetadata[]>;
|
|
21
21
|
getKey(keyId: string): Promise<KmsKeyMetadata>;
|
|
22
22
|
createKey(algorithm: string, usage: "encrypt" | "sign" | "wrap", metadata?: Record<string, string>): Promise<KmsKeyMetadata>;
|
|
23
|
+
private listVersions;
|
|
24
|
+
private versionsIn;
|
|
25
|
+
private setVersionStates;
|
|
23
26
|
enableKey(keyId: string): Promise<void>;
|
|
24
27
|
disableKey(keyId: string): Promise<void>;
|
|
25
28
|
scheduleKeyDeletion(keyId: string, _pendingWindowDays?: number): Promise<void>;
|
|
26
29
|
encrypt(keyId: string, plaintext: Uint8Array, context?: Record<string, string>): Promise<KmsEncryptResult>;
|
|
27
30
|
decrypt(keyId: string, ciphertext: string, context?: Record<string, string>): Promise<KmsDecryptResult>;
|
|
28
|
-
sign(keyId: string, data: Uint8Array,
|
|
31
|
+
sign(keyId: string, data: Uint8Array, _algorithm?: string): Promise<KmsSignResult>;
|
|
29
32
|
verify(keyId: string, data: Uint8Array, signature: string, _algorithm?: string): Promise<boolean>;
|
|
30
33
|
rotateKey(keyId: string): Promise<KmsKeyMetadata>;
|
|
31
34
|
generateDataKey(keyId: string, keySpec?: string): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gcp.d.ts","sourceRoot":"","sources":["../../src/providers/gcp.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gcp.d.ts","sourceRoot":"","sources":["../../src/providers/gcp.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACd,MAAM,UAAU,CAAC;AAiBlB,MAAM,WAAW,aAAa;IAE5B,SAAS,EAAE,MAAM,CAAC;IAElB,UAAU,EAAE,MAAM,CAAC;IAEnB,SAAS,EAAE,MAAM,CAAC;IAElB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAuJD,qBAAa,cAAe,YAAW,WAAW;IAEhD,QAAQ,CAAC,IAAI,SAAS;IAEtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;gBAG5B,OAAO,EAAE,aAAa;IAKlC,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,UAAU;IAUlB,OAAO,CAAC,QAAQ;YAeF,OAAO;IAqCf,QAAQ,CAAC,OAAO,CAAC,EAAE;QACvB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAcvB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAO9C,SAAS,CACb,SAAS,EAAE,MAAM,EACjB,KAAK,E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,EACb,YAAY,EAAE,UAAU,EACxB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAM3C,SAAS,CACb,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC;QAAE,YAAY,EAAE,UAAU,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAIxD"}
|
package/dist/providers/gcp.js
CHANGED
|
@@ -1,7 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.GcpKmsProvider = void 0;
|
|
37
|
+
const nodeCrypto = __importStar(require("node:crypto"));
|
|
4
38
|
const errors_1 = require("../errors");
|
|
39
|
+
const algorithms_1 = require("./algorithms");
|
|
40
|
+
function verifyParams(algorithm) {
|
|
41
|
+
const digest = /SHA512$/.test(algorithm)
|
|
42
|
+
? "sha512"
|
|
43
|
+
: /SHA384$/.test(algorithm)
|
|
44
|
+
? "sha384"
|
|
45
|
+
: "sha256";
|
|
46
|
+
if (algorithm === "EC_SIGN_ED25519")
|
|
47
|
+
return { digest: null };
|
|
48
|
+
if (/^EC_SIGN_/.test(algorithm))
|
|
49
|
+
return { digest };
|
|
50
|
+
if (/^RSA_SIGN_PSS_/.test(algorithm)) {
|
|
51
|
+
return { digest, padding: nodeCrypto.constants.RSA_PKCS1_PSS_PADDING };
|
|
52
|
+
}
|
|
53
|
+
if (/^RSA_SIGN_PKCS1_/.test(algorithm)) {
|
|
54
|
+
return { digest, padding: nodeCrypto.constants.RSA_PKCS1_PADDING };
|
|
55
|
+
}
|
|
56
|
+
throw new errors_1.KmsError("INVALID_ARGUMENT", `GCP signing algorithm ${algorithm} is not supported`);
|
|
57
|
+
}
|
|
58
|
+
const versionNumber = (v) => Number(v.name.slice(v.name.lastIndexOf("/") + 1));
|
|
5
59
|
function parseGcpResponse(text) {
|
|
6
60
|
if (!text)
|
|
7
61
|
return {};
|
|
@@ -25,28 +79,23 @@ function handleGcpError(res, json, keyId) {
|
|
|
25
79
|
}
|
|
26
80
|
throw new errors_1.KmsError("INVALID_ARGUMENT", `GCP KMS error: ${errMsg}`, keyId);
|
|
27
81
|
}
|
|
28
|
-
function mapGcpAlgorithm(algorithm, usage) {
|
|
29
|
-
const upper = algorithm.toUpperCase();
|
|
30
|
-
if (usage === "sign") {
|
|
31
|
-
if (upper.includes("EC") || upper.includes("P256")) {
|
|
32
|
-
return "EC_SIGN_P256_SHA256";
|
|
33
|
-
}
|
|
34
|
-
return "RSA_SIGN_PSS_2048_SHA256";
|
|
35
|
-
}
|
|
36
|
-
return "GOOGLE_SYMMETRIC_ENCRYPTION";
|
|
37
|
-
}
|
|
38
82
|
function extractGcpKeyId(fullName) {
|
|
39
83
|
if (!fullName)
|
|
40
84
|
return "";
|
|
41
85
|
const idx = fullName.lastIndexOf("/");
|
|
42
86
|
return idx >= 0 ? fullName.slice(idx + 1) : fullName;
|
|
43
87
|
}
|
|
88
|
+
function keyAlgorithm(raw) {
|
|
89
|
+
return (raw.primary?.algorithm ??
|
|
90
|
+
raw.versionTemplate?.algorithm ??
|
|
91
|
+
"GOOGLE_SYMMETRIC_ENCRYPTION");
|
|
92
|
+
}
|
|
44
93
|
function mapGcpKey(raw, fallbackId) {
|
|
45
94
|
const keyId = extractGcpKeyId(raw.name) || fallbackId;
|
|
46
95
|
const isSign = raw.purpose === "ASYMMETRIC_SIGN";
|
|
47
96
|
return {
|
|
48
97
|
keyId,
|
|
49
|
-
algorithm: raw
|
|
98
|
+
algorithm: keyAlgorithm(raw),
|
|
50
99
|
usage: isSign ? "sign" : "encrypt",
|
|
51
100
|
createdAt: raw.createTime ?? new Date().toISOString(),
|
|
52
101
|
enabled: raw.primary?.state !== "DISABLED" && raw.primary?.state !== "DESTROYED",
|
|
@@ -67,16 +116,20 @@ class GcpKmsProvider {
|
|
|
67
116
|
return keyId;
|
|
68
117
|
return `${this.getParent()}/cryptoKeys/${keyId}`;
|
|
69
118
|
}
|
|
70
|
-
buildUrl(path) {
|
|
119
|
+
buildUrl(path, query) {
|
|
71
120
|
if (!/^[a-zA-Z0-9_\-/:.?=&]+$/.test(path) || path.includes("..")) {
|
|
72
121
|
throw new errors_1.KmsError("INVALID_ARGUMENT", "Invalid GCP KMS path", path);
|
|
73
122
|
}
|
|
74
123
|
const endpoint = this.options.endpoint ?? "https://cloudkms.googleapis.com/v1";
|
|
75
124
|
const base = `${endpoint.replace(/\/+$/, "")}/`;
|
|
76
|
-
|
|
125
|
+
const url = new URL(path, base);
|
|
126
|
+
for (const [k, v] of Object.entries(query ?? {})) {
|
|
127
|
+
url.searchParams.set(k, v);
|
|
128
|
+
}
|
|
129
|
+
return url.href;
|
|
77
130
|
}
|
|
78
|
-
async request(path, method = "GET", body) {
|
|
79
|
-
const url = this.buildUrl(path);
|
|
131
|
+
async request(path, method = "GET", body, query) {
|
|
132
|
+
const url = this.buildUrl(path, query);
|
|
80
133
|
const headers = {
|
|
81
134
|
"Content-Type": "application/json",
|
|
82
135
|
};
|
|
@@ -126,24 +179,43 @@ class GcpKmsProvider {
|
|
|
126
179
|
const body = {
|
|
127
180
|
purpose,
|
|
128
181
|
versionTemplate: {
|
|
129
|
-
algorithm:
|
|
182
|
+
algorithm: (0, algorithms_1.resolveAlgorithm)("GcpKmsProvider", algorithms_1.GCP_ALGORITHMS, algorithm, usage),
|
|
130
183
|
},
|
|
131
184
|
...(metadata ? { labels: metadata } : {}),
|
|
132
185
|
};
|
|
133
186
|
const res = await this.request(path, "POST", body);
|
|
134
187
|
return mapGcpKey(res, keyId);
|
|
135
188
|
}
|
|
189
|
+
async listVersions(keyId) {
|
|
190
|
+
const path = `${this.getKeyName(keyId)}/cryptoKeyVersions`;
|
|
191
|
+
const versions = [];
|
|
192
|
+
let pageToken;
|
|
193
|
+
do {
|
|
194
|
+
const res = await this.request(path, "GET", undefined, pageToken ? { pageToken } : undefined);
|
|
195
|
+
versions.push(...(res.cryptoKeyVersions ?? []));
|
|
196
|
+
pageToken = res.nextPageToken;
|
|
197
|
+
} while (pageToken);
|
|
198
|
+
return versions;
|
|
199
|
+
}
|
|
200
|
+
async versionsIn(keyId, states) {
|
|
201
|
+
const all = await this.listVersions(keyId);
|
|
202
|
+
return all.filter((v) => states.includes(v.state));
|
|
203
|
+
}
|
|
204
|
+
async setVersionStates(keyId, from, to) {
|
|
205
|
+
for (const v of await this.versionsIn(keyId, [from])) {
|
|
206
|
+
await this.request(`${v.name}?updateMask=state`, "PATCH", { state: to });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
136
209
|
async enableKey(keyId) {
|
|
137
|
-
|
|
138
|
-
await this.request(path, "PATCH", { state: "ENABLED" });
|
|
210
|
+
await this.setVersionStates(keyId, "DISABLED", "ENABLED");
|
|
139
211
|
}
|
|
140
212
|
async disableKey(keyId) {
|
|
141
|
-
|
|
142
|
-
await this.request(path, "PATCH", { state: "DISABLED" });
|
|
213
|
+
await this.setVersionStates(keyId, "ENABLED", "DISABLED");
|
|
143
214
|
}
|
|
144
215
|
async scheduleKeyDeletion(keyId, _pendingWindowDays) {
|
|
145
|
-
const
|
|
146
|
-
|
|
216
|
+
for (const v of await this.versionsIn(keyId, ["ENABLED", "DISABLED"])) {
|
|
217
|
+
await this.request(`${v.name}:destroy`, "POST", {});
|
|
218
|
+
}
|
|
147
219
|
}
|
|
148
220
|
async encrypt(keyId, plaintext, context) {
|
|
149
221
|
const path = `${this.getKeyName(keyId)}:encrypt`;
|
|
@@ -181,31 +253,44 @@ class GcpKmsProvider {
|
|
|
181
253
|
keyId,
|
|
182
254
|
};
|
|
183
255
|
}
|
|
184
|
-
async sign(keyId, data,
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
256
|
+
async sign(keyId, data, _algorithm) {
|
|
257
|
+
const enabled = await this.versionsIn(keyId, ["ENABLED"]);
|
|
258
|
+
const version = enabled.sort((a, b) => versionNumber(b) - versionNumber(a))[0];
|
|
259
|
+
if (!version) {
|
|
260
|
+
throw new errors_1.KmsError("DISABLED", "Key has no enabled version", keyId);
|
|
261
|
+
}
|
|
262
|
+
const algorithm = version.algorithm;
|
|
263
|
+
const { digest } = verifyParams(algorithm);
|
|
264
|
+
const body = digest
|
|
265
|
+
? {
|
|
266
|
+
digest: {
|
|
267
|
+
[digest]: nodeCrypto
|
|
268
|
+
.createHash(digest)
|
|
269
|
+
.update(data)
|
|
270
|
+
.digest("base64"),
|
|
271
|
+
},
|
|
272
|
+
}
|
|
273
|
+
: { data: Buffer.from(data).toString("base64") };
|
|
274
|
+
const res = await this.request(`${version.name}:asymmetricSign`, "POST", body);
|
|
275
|
+
return { signature: res.signature, keyId, algorithm };
|
|
195
276
|
}
|
|
196
277
|
async verify(keyId, data, signature, _algorithm) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
278
|
+
const sig = Buffer.from(signature, "base64");
|
|
279
|
+
for (const v of await this.versionsIn(keyId, ["ENABLED"])) {
|
|
280
|
+
const res = await this.request(`${v.name}/publicKey`);
|
|
281
|
+
const { digest, padding } = verifyParams(res.algorithm);
|
|
282
|
+
const key = nodeCrypto.createPublicKey(res.pem);
|
|
283
|
+
const ok = nodeCrypto.verify(digest, data, padding === undefined
|
|
284
|
+
? key
|
|
285
|
+
: {
|
|
286
|
+
key,
|
|
287
|
+
padding,
|
|
288
|
+
saltLength: nodeCrypto.constants.RSA_PSS_SALTLEN_DIGEST,
|
|
289
|
+
}, sig);
|
|
290
|
+
if (ok)
|
|
291
|
+
return true;
|
|
208
292
|
}
|
|
293
|
+
return false;
|
|
209
294
|
}
|
|
210
295
|
async rotateKey(keyId) {
|
|
211
296
|
const path = `${this.getKeyName(keyId)}/cryptoKeyVersions`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../src/providers/local.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../src/providers/local.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACd,MAAM,UAAU,CAAC;AAqDlB,qBAAa,gBAAiB,YAAW,WAAW;IAElD,QAAQ,CAAC,IAAI,WAAW;IAExB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqC;IAG3D,OAAO,CAAC,MAAM;IASd,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,QAAQ;IAQV,QAAQ,CAAC,OAAO,CAAC,EAAE;QACvB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAevB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAK9C,SAAS,CACb,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,MAAM,EAClC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACjC,OAAO,CAAC,cAAc,CAAC;IA2BpB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKvC,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKxC,mBAAmB,CACvB,KAAK,EAAE,MAAM,EACb,iBAAiB,SAAK,GACrB,OAAO,CAAC,IAAI,CAAC;IAUV,OAAO,CACX,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,UAAU,EACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,gBAAgB,CAA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|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LocalKmsProvider = void 0;
|
|
4
4
|
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const algorithms_1 = require("./algorithms");
|
|
5
6
|
const crypto_lib_1 = require("@sebastienrousseau/crypto-lib");
|
|
6
7
|
const errors_1 = require("../errors");
|
|
7
8
|
const versioned_key_1 = require("./versioned-key");
|
|
@@ -51,10 +52,11 @@ class LocalKmsProvider {
|
|
|
51
52
|
return this.snapshot(this.record(keyId));
|
|
52
53
|
}
|
|
53
54
|
async createKey(algorithm, usage, _metadata) {
|
|
55
|
+
const resolved = (0, algorithms_1.resolveAlgorithm)("LocalKmsProvider", algorithms_1.LOCAL_ALGORITHMS, algorithm, usage);
|
|
54
56
|
const keyId = generateId();
|
|
55
57
|
const metadata = {
|
|
56
58
|
keyId,
|
|
57
|
-
algorithm,
|
|
59
|
+
algorithm: resolved,
|
|
58
60
|
usage,
|
|
59
61
|
createdAt: new Date().toISOString(),
|
|
60
62
|
enabled: true,
|
|
@@ -117,7 +119,7 @@ class LocalKmsProvider {
|
|
|
117
119
|
}
|
|
118
120
|
async verify(keyId, data, signature, _algorithm) {
|
|
119
121
|
const key = this.signingRecord(keyId, this.record(keyId));
|
|
120
|
-
return (0, versioned_key_1.
|
|
122
|
+
return (0, versioned_key_1.verifyBase64Signature)(key, data, signature);
|
|
121
123
|
}
|
|
122
124
|
async rotateKey(keyId) {
|
|
123
125
|
const record = this.record(keyId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pkcs11.d.ts","sourceRoot":"","sources":["../../src/providers/pkcs11.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pkcs11.d.ts","sourceRoot":"","sources":["../../src/providers/pkcs11.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACd,MAAM,UAAU,CAAC;AAgB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QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;CAQ1D"}
|
package/dist/providers/pkcs11.js
CHANGED
|
@@ -5,6 +5,7 @@ const node_crypto_1 = require("node:crypto");
|
|
|
5
5
|
const crypto_lib_1 = require("@sebastienrousseau/crypto-lib");
|
|
6
6
|
const errors_1 = require("../errors");
|
|
7
7
|
const versioned_key_1 = require("./versioned-key");
|
|
8
|
+
const algorithms_1 = require("./algorithms");
|
|
8
9
|
function generateHsmKeyId(model) {
|
|
9
10
|
return `pkcs11-${model}-${(0, crypto_lib_1.bytesToHex)((0, node_crypto_1.randomBytes)(12))}`;
|
|
10
11
|
}
|
|
@@ -79,11 +80,12 @@ class Pkcs11HsmProvider {
|
|
|
79
80
|
return this.snapshot(this.record(keyId));
|
|
80
81
|
}
|
|
81
82
|
async createKey(algorithm, usage, _metadata) {
|
|
83
|
+
const resolved = (0, algorithms_1.resolveAlgorithm)("Pkcs11HsmProvider", algorithms_1.LOCAL_ALGORITHMS, algorithm, usage);
|
|
82
84
|
const keyId = generateHsmKeyId(this.hsmModel);
|
|
83
85
|
const record = {
|
|
84
86
|
metadata: {
|
|
85
87
|
keyId,
|
|
86
|
-
algorithm,
|
|
88
|
+
algorithm: resolved,
|
|
87
89
|
usage,
|
|
88
90
|
createdAt: new Date().toISOString(),
|
|
89
91
|
enabled: true,
|
|
@@ -140,7 +142,7 @@ class Pkcs11HsmProvider {
|
|
|
140
142
|
}
|
|
141
143
|
async verify(keyId, data, signature, _algorithm) {
|
|
142
144
|
const key = this.requireUsage(keyId, this.record(keyId), "sign");
|
|
143
|
-
return (0, versioned_key_1.
|
|
145
|
+
return (0, versioned_key_1.verifyBase64Signature)(key, data, signature);
|
|
144
146
|
}
|
|
145
147
|
async rotateKey(keyId) {
|
|
146
148
|
const record = this.record(keyId);
|
|
@@ -4,6 +4,7 @@ export interface VaultKmsOptions {
|
|
|
4
4
|
token: string;
|
|
5
5
|
mountPath?: string;
|
|
6
6
|
namespace?: string;
|
|
7
|
+
acceptUnboundContext?: boolean;
|
|
7
8
|
}
|
|
8
9
|
export declare class VaultKmsProvider implements KmsProvider {
|
|
9
10
|
readonly name = "vault";
|
|
@@ -11,6 +12,7 @@ export declare class VaultKmsProvider implements KmsProvider {
|
|
|
11
12
|
private readonly _token;
|
|
12
13
|
private readonly _mount;
|
|
13
14
|
private readonly _namespace?;
|
|
15
|
+
private readonly _acceptUnboundContext;
|
|
14
16
|
constructor(options: VaultKmsOptions);
|
|
15
17
|
buildUrl(path: string): string;
|
|
16
18
|
buildHeaders(): Record<string, string>;
|
|
@@ -21,13 +23,14 @@ export declare class VaultKmsProvider implements KmsProvider {
|
|
|
21
23
|
enabled?: boolean;
|
|
22
24
|
}): Promise<KmsKeyMetadata[]>;
|
|
23
25
|
getKey(keyId: string): Promise<KmsKeyMetadata>;
|
|
24
|
-
private resolveVaultType;
|
|
25
26
|
createKey(algorithm: string, usage: "encrypt" | "sign" | "wrap", metadata?: Record<string, string>): Promise<KmsKeyMetadata>;
|
|
26
27
|
enableKey(keyId: string): Promise<void>;
|
|
27
28
|
disableKey(keyId: string): Promise<void>;
|
|
28
|
-
scheduleKeyDeletion(keyId: string,
|
|
29
|
+
scheduleKeyDeletion(keyId: string, pendingWindowDays?: number): Promise<void>;
|
|
30
|
+
private aad;
|
|
29
31
|
encrypt(keyId: string, plaintext: Uint8Array, context?: Record<string, string>): Promise<KmsEncryptResult>;
|
|
30
32
|
decrypt(keyId: string, ciphertext: string, context?: Record<string, string>): Promise<KmsDecryptResult>;
|
|
33
|
+
private decryptWith;
|
|
31
34
|
sign(keyId: string, data: Uint8Array, algorithm?: string): Promise<KmsSignResult>;
|
|
32
35
|
verify(keyId: string, data: Uint8Array, signature: string, algorithm?: string): Promise<boolean>;
|
|
33
36
|
rotateKey(keyId: string): Promise<KmsKeyMetadata>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vault.d.ts","sourceRoot":"","sources":["../../src/providers/vault.ts"],"names":[],"mappings":"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E,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAM3C,SAAS,CACb,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC;QAAE,YAAY,EAAE,UAAU,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAIxD"}
|
package/dist/providers/vault.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VaultKmsProvider = void 0;
|
|
4
4
|
const errors_1 = require("../errors");
|
|
5
|
+
const versioned_key_1 = require("./versioned-key");
|
|
6
|
+
const algorithms_1 = require("./algorithms");
|
|
5
7
|
function parseVaultResponse(text) {
|
|
6
8
|
if (!text)
|
|
7
9
|
return {};
|
|
@@ -15,9 +17,12 @@ function parseVaultResponse(text) {
|
|
|
15
17
|
function handleVaultError(res, json, keyId) {
|
|
16
18
|
const errMsg = json.errors?.join(", ") ?? `HTTP ${res.status}`;
|
|
17
19
|
if (res.status === 400 &&
|
|
18
|
-
/ciphertext.*invalid|decryption failed/i.test(errMsg)) {
|
|
20
|
+
/ciphertext.*invalid|decryption failed|authentication failed/i.test(errMsg)) {
|
|
19
21
|
throw new errors_1.KmsError("DECRYPTION_FAILED", errMsg, keyId);
|
|
20
22
|
}
|
|
23
|
+
if (/key not found/i.test(errMsg)) {
|
|
24
|
+
throw new errors_1.KmsError("NOT_FOUND", errMsg, keyId);
|
|
25
|
+
}
|
|
21
26
|
if (/disabled/i.test(errMsg)) {
|
|
22
27
|
throw new errors_1.KmsError("DISABLED", errMsg, keyId);
|
|
23
28
|
}
|
|
@@ -29,11 +34,13 @@ class VaultKmsProvider {
|
|
|
29
34
|
_token;
|
|
30
35
|
_mount;
|
|
31
36
|
_namespace;
|
|
37
|
+
_acceptUnboundContext;
|
|
32
38
|
constructor(options) {
|
|
33
39
|
this._address = options.address;
|
|
34
40
|
this._token = options.token;
|
|
35
41
|
this._mount = options.mountPath ?? "transit";
|
|
36
42
|
this._namespace = options.namespace;
|
|
43
|
+
this._acceptUnboundContext = options.acceptUnboundContext ?? false;
|
|
37
44
|
}
|
|
38
45
|
buildUrl(path) {
|
|
39
46
|
if (!/^[a-zA-Z0-9_\-/:.?=&]+$/.test(path) || path.includes("..")) {
|
|
@@ -123,88 +130,85 @@ class VaultKmsProvider {
|
|
|
123
130
|
const details = await this.request(`keys/${keyId}`, "GET", undefined, keyId);
|
|
124
131
|
return this.mapMetadata(keyId, details);
|
|
125
132
|
}
|
|
126
|
-
resolveVaultType(algorithm, usage) {
|
|
127
|
-
const lower = algorithm.toLowerCase();
|
|
128
|
-
if (lower.includes("p256") || lower.includes("ecdsa"))
|
|
129
|
-
return "ecdsa-p256";
|
|
130
|
-
if (lower.includes("rsa-4096"))
|
|
131
|
-
return "rsa-4096";
|
|
132
|
-
if (lower.includes("rsa"))
|
|
133
|
-
return "rsa-2048";
|
|
134
|
-
if (lower.includes("chacha"))
|
|
135
|
-
return "chacha20-poly1305";
|
|
136
|
-
if (lower.includes("ed25519"))
|
|
137
|
-
return "ed25519";
|
|
138
|
-
if (usage === "sign")
|
|
139
|
-
return "ed25519";
|
|
140
|
-
return "aes256-gcm96";
|
|
141
|
-
}
|
|
142
133
|
async createKey(algorithm, usage, metadata) {
|
|
143
134
|
const keyId = metadata?.["keyId"] ??
|
|
144
135
|
`vault-${Date.now()}-${Math.floor(Math.random() * 1e6)}`;
|
|
145
|
-
const vaultType =
|
|
136
|
+
const vaultType = (0, algorithms_1.resolveAlgorithm)("VaultKmsProvider", algorithms_1.VAULT_ALGORITHMS, algorithm, usage);
|
|
146
137
|
await this.request(`keys/${keyId}`, "POST", { type: vaultType }, keyId);
|
|
147
138
|
return this.getKey(keyId);
|
|
148
139
|
}
|
|
149
140
|
async enableKey(keyId) {
|
|
150
|
-
|
|
141
|
+
throw new errors_1.KmsError("NOT_IMPLEMENTED", "Vault Transit keys cannot be enabled or disabled; use a Vault policy", keyId);
|
|
151
142
|
}
|
|
152
143
|
async disableKey(keyId) {
|
|
153
|
-
|
|
154
|
-
const disableVersion = (meta.currentVersion ?? 1) + 1;
|
|
155
|
-
await this.request(`keys/${keyId}/config`, "POST", { min_encryption_version: disableVersion }, keyId);
|
|
144
|
+
return this.enableKey(keyId);
|
|
156
145
|
}
|
|
157
|
-
async scheduleKeyDeletion(keyId,
|
|
146
|
+
async scheduleKeyDeletion(keyId, pendingWindowDays) {
|
|
147
|
+
if (pendingWindowDays !== 0) {
|
|
148
|
+
throw new errors_1.KmsError("INVALID_ARGUMENT", "Vault Transit deletes keys immediately; pass pendingWindowDays 0 to confirm", keyId);
|
|
149
|
+
}
|
|
158
150
|
await this.request(`keys/${keyId}/config`, "POST", { deletion_allowed: true }, keyId);
|
|
159
151
|
await this.request(`keys/${keyId}`, "DELETE", undefined, keyId);
|
|
160
152
|
}
|
|
153
|
+
aad(context) {
|
|
154
|
+
const bytes = (0, versioned_key_1.canonicalContext)(context);
|
|
155
|
+
return bytes.length > 0
|
|
156
|
+
? { associated_data: bytes.toString("base64") }
|
|
157
|
+
: {};
|
|
158
|
+
}
|
|
161
159
|
async encrypt(keyId, plaintext, context) {
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
if (b64Context)
|
|
168
|
-
body.context = b64Context;
|
|
169
|
-
const res = await this.request(`encrypt/${keyId}`, "POST", body, keyId);
|
|
170
|
-
const out = {
|
|
171
|
-
ciphertext: res.ciphertext,
|
|
172
|
-
keyId,
|
|
173
|
-
};
|
|
160
|
+
const res = await this.request(`encrypt/${keyId}`, "POST", {
|
|
161
|
+
plaintext: Buffer.from(plaintext).toString("base64"),
|
|
162
|
+
...this.aad(context),
|
|
163
|
+
}, keyId);
|
|
164
|
+
const out = { ciphertext: res.ciphertext, keyId };
|
|
174
165
|
if (context)
|
|
175
166
|
out.context = context;
|
|
176
167
|
return out;
|
|
177
168
|
}
|
|
178
169
|
async decrypt(keyId, ciphertext, context) {
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
170
|
+
const aad = this.aad(context);
|
|
171
|
+
try {
|
|
172
|
+
return await this.decryptWith(keyId, ciphertext, aad);
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
const retry = this._acceptUnboundContext &&
|
|
176
|
+
"associated_data" in aad &&
|
|
177
|
+
err instanceof errors_1.KmsError &&
|
|
178
|
+
err.code === "DECRYPTION_FAILED";
|
|
179
|
+
if (!retry)
|
|
180
|
+
throw err;
|
|
181
|
+
return this.decryptWith(keyId, ciphertext, {});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async decryptWith(keyId, ciphertext, aad) {
|
|
185
|
+
const res = await this.request(`decrypt/${keyId}`, "POST", { ciphertext, ...aad }, keyId);
|
|
186
186
|
return {
|
|
187
187
|
plaintext: new Uint8Array(Buffer.from(res.plaintext, "base64")),
|
|
188
188
|
keyId,
|
|
189
189
|
};
|
|
190
190
|
}
|
|
191
191
|
async sign(keyId, data, algorithm = "sha2-256") {
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
algorithm,
|
|
198
|
-
};
|
|
192
|
+
const res = await this.request(`sign/${keyId}`, "POST", {
|
|
193
|
+
input: Buffer.from(data).toString("base64"),
|
|
194
|
+
hash_algorithm: algorithm,
|
|
195
|
+
}, keyId);
|
|
196
|
+
return { signature: res.signature, keyId, algorithm };
|
|
199
197
|
}
|
|
200
198
|
async verify(keyId, data, signature, algorithm = "sha2-256") {
|
|
201
|
-
const input = Buffer.from(data).toString("base64");
|
|
202
199
|
try {
|
|
203
|
-
const res = await this.request(`verify/${keyId}`, "POST", {
|
|
204
|
-
|
|
200
|
+
const res = await this.request(`verify/${keyId}`, "POST", {
|
|
201
|
+
input: Buffer.from(data).toString("base64"),
|
|
202
|
+
signature,
|
|
203
|
+
hash_algorithm: algorithm,
|
|
204
|
+
}, keyId);
|
|
205
|
+
return res.valid === true;
|
|
205
206
|
}
|
|
206
|
-
catch {
|
|
207
|
-
|
|
207
|
+
catch (err) {
|
|
208
|
+
if (err instanceof errors_1.KmsError && /invalid signature/i.test(err.message)) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
throw err;
|
|
208
212
|
}
|
|
209
213
|
}
|
|
210
214
|
async rotateKey(keyId) {
|
|
@@ -22,5 +22,6 @@ export declare function openVersioned(key: VersionedKey, keyId: string, cipherte
|
|
|
22
22
|
version: number;
|
|
23
23
|
};
|
|
24
24
|
export declare function signCurrent(key: VersionedKey, data: Uint8Array): Uint8Array;
|
|
25
|
+
export declare function verifyBase64Signature(key: VersionedKey, data: Uint8Array, signature: string): boolean;
|
|
25
26
|
export declare function verifyAnyVersion(key: VersionedKey, data: Uint8Array, signature: Uint8Array): boolean;
|
|
26
27
|
//# sourceMappingURL=versioned-key.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"versioned-key.d.ts","sourceRoot":"","sources":["../../src/providers/versioned-key.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"versioned-key.d.ts","sourceRoot":"","sources":["../../src/providers/versioned-key.ts"],"names":[],"mappings":"AA6CA,MAAM,WAAW,UAAU;IAEzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,QAAQ,EAAE,UAAU,GAAG,SAAS,CAAC;IAEjC,QAAQ,CAAC,SAAS,EAAE,UAAU,GAAG,SAAS,CAAC;CAC5C;AAGD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,KAAK,EAAE,SAAS,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EAChB,SAAS,EAAE,UAAU,GACpB,OAAO,CAQT"}
|
|
@@ -8,6 +8,7 @@ exports.canonicalContext = canonicalContext;
|
|
|
8
8
|
exports.sealCurrent = sealCurrent;
|
|
9
9
|
exports.openVersioned = openVersioned;
|
|
10
10
|
exports.signCurrent = signCurrent;
|
|
11
|
+
exports.verifyBase64Signature = verifyBase64Signature;
|
|
11
12
|
exports.verifyAnyVersion = verifyAnyVersion;
|
|
12
13
|
const node_crypto_1 = require("node:crypto");
|
|
13
14
|
const crypto_lib_1 = require("@sebastienrousseau/crypto-lib");
|
|
@@ -20,7 +21,7 @@ const ED25519_SIG_LEN = 64;
|
|
|
20
21
|
function newVersion(usage, version) {
|
|
21
22
|
const createdAt = new Date().toISOString();
|
|
22
23
|
if (usage === "sign") {
|
|
23
|
-
const kp = (0, crypto_lib_1.
|
|
24
|
+
const kp = (0, crypto_lib_1.ed25519Keygen)();
|
|
24
25
|
return {
|
|
25
26
|
version,
|
|
26
27
|
createdAt,
|
|
@@ -131,6 +132,16 @@ function signCurrent(key, data) {
|
|
|
131
132
|
const { signature } = (0, crypto_lib_1.ed25519Sign)(material, signedMessage(data));
|
|
132
133
|
return (0, crypto_lib_1.hexToBytes)(signature);
|
|
133
134
|
}
|
|
135
|
+
function verifyBase64Signature(key, data, signature) {
|
|
136
|
+
let bytes;
|
|
137
|
+
try {
|
|
138
|
+
bytes = (0, crypto_lib_1.base64ToBytes)(signature);
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
return verifyAnyVersion(key, data, bytes);
|
|
144
|
+
}
|
|
134
145
|
function verifyAnyVersion(key, data, signature) {
|
|
135
146
|
if (signature.length !== ED25519_SIG_LEN)
|
|
136
147
|
return false;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebastienrousseau/crypto-kms",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Key management interface for envelope encryption and key rotation, with AWS KMS
|
|
3
|
+
"version": "0.0.37",
|
|
4
|
+
"description": "Key management interface for envelope encryption, signing and key rotation, with providers for AWS KMS (including ML-DSA signing keys), Google Cloud KMS, HashiCorp Vault Transit and an in-memory local store. The Azure Key Vault provider is a stub and the PKCS#11 provider is a software simulation.",
|
|
5
5
|
"author": "Sebastien Rousseau <sebastienrousseau@users.noreply.github.com>",
|
|
6
6
|
"license": "MIT OR Apache-2.0",
|
|
7
7
|
"engines": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dist/**/*.d.ts.map"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@sebastienrousseau/crypto-lib": "0.0.
|
|
28
|
+
"@sebastienrousseau/crypto-lib": "0.0.37"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@aws-sdk/client-kms": "^3.0.0",
|
|
@@ -73,12 +73,16 @@
|
|
|
73
73
|
"key-rotation",
|
|
74
74
|
"cryptography",
|
|
75
75
|
"encryption",
|
|
76
|
-
"typescript"
|
|
76
|
+
"typescript",
|
|
77
|
+
"google-cloud-kms",
|
|
78
|
+
"hashicorp-vault",
|
|
79
|
+
"vault-transit"
|
|
77
80
|
],
|
|
78
81
|
"scripts": {
|
|
79
82
|
"build": "tsc --build tsconfig.json",
|
|
80
83
|
"clean": "rimraf ./coverage ./dist ./docs",
|
|
81
84
|
"test": "c8 --check-coverage --lines 100 --branches 100 --functions 100 --reporter=lcov --reporter=text mocha --config=.mocharc.cjs",
|
|
85
|
+
"test:run": "mocha --config=.mocharc.cjs",
|
|
82
86
|
"docs": "typedoc",
|
|
83
87
|
"lint": "eslint src __tests__",
|
|
84
88
|
"lint:fix": "eslint --cache --fix src __tests__",
|