@sebastienrousseau/crypto-server 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 +128 -73
- package/dist/@types/types.d.ts +1 -0
- package/dist/@types/types.d.ts.map +1 -1
- package/dist/config/auth-policy.d.ts +1 -0
- package/dist/config/auth-policy.d.ts.map +1 -1
- package/dist/config/auth-policy.js +10 -4
- package/dist/config/constants.d.ts +7 -2
- package/dist/config/constants.d.ts.map +1 -1
- package/dist/config/constants.js +15 -18
- package/dist/config/env.d.ts +9 -2
- package/dist/config/env.d.ts.map +1 -1
- package/dist/config/env.js +59 -36
- package/dist/config/settings.d.ts +3 -0
- package/dist/config/settings.d.ts.map +1 -0
- package/dist/config/settings.js +24 -0
- package/dist/enterprise/metering.d.ts +5 -5
- package/dist/enterprise/metering.d.ts.map +1 -1
- package/dist/enterprise/metering.js +20 -63
- package/dist/enterprise/types.d.ts +0 -11
- package/dist/enterprise/types.d.ts.map +1 -1
- package/dist/index.js +9 -35
- package/dist/lib/audit.d.ts +18 -0
- package/dist/lib/audit.d.ts.map +1 -0
- package/dist/lib/audit.js +57 -0
- package/dist/lib/auth.d.ts +4 -0
- package/dist/lib/auth.d.ts.map +1 -1
- package/dist/lib/auth.js +15 -1
- package/dist/lib/crypto-workers.d.ts +27 -0
- package/dist/lib/crypto-workers.d.ts.map +1 -0
- package/dist/lib/crypto-workers.js +46 -0
- package/dist/lib/http-metrics.d.ts +13 -0
- package/dist/lib/http-metrics.d.ts.map +1 -0
- package/dist/lib/http-metrics.js +45 -0
- package/dist/lib/key-store.d.ts +15 -1
- package/dist/lib/key-store.d.ts.map +1 -1
- package/dist/lib/key-store.js +128 -44
- package/dist/lib/kms-owners.d.ts +9 -0
- package/dist/lib/kms-owners.d.ts.map +1 -0
- package/dist/lib/kms-owners.js +80 -0
- package/dist/lib/kms-providers.d.ts +15 -0
- package/dist/lib/kms-providers.d.ts.map +1 -0
- package/dist/lib/kms-providers.js +99 -0
- package/dist/lib/lifecycle.d.ts +16 -0
- package/dist/lib/lifecycle.d.ts.map +1 -0
- package/dist/lib/lifecycle.js +50 -0
- package/dist/lib/logger.d.ts +5 -1
- package/dist/lib/logger.d.ts.map +1 -1
- package/dist/lib/logger.js +34 -15
- package/dist/lib/opaque-store.d.ts +13 -0
- package/dist/lib/opaque-store.d.ts.map +1 -1
- package/dist/lib/opaque-store.js +27 -2
- package/dist/lib/problem.d.ts +8 -0
- package/dist/lib/problem.d.ts.map +1 -1
- package/dist/lib/problem.js +25 -15
- package/dist/lib/readiness.d.ts +12 -0
- package/dist/lib/readiness.d.ts.map +1 -0
- package/dist/lib/readiness.js +17 -0
- package/dist/lib/telemetry.d.ts +1 -1
- package/dist/lib/telemetry.d.ts.map +1 -1
- package/dist/lib/telemetry.js +45 -73
- package/dist/routes/index.d.ts +3 -0
- package/dist/routes/index.d.ts.map +1 -1
- package/dist/routes/index.js +19 -12
- package/dist/routes/probes.d.ts.map +1 -1
- package/dist/routes/probes.js +4 -10
- package/dist/routes/v1/decrypt.d.ts.map +1 -1
- package/dist/routes/v1/decrypt.js +2 -1
- package/dist/routes/v1/encrypt.d.ts.map +1 -1
- package/dist/routes/v1/encrypt.js +2 -1
- package/dist/routes/v1/generate.d.ts.map +1 -1
- package/dist/routes/v1/generate.js +3 -2
- package/dist/routes/v1/index.js +2 -2
- package/dist/routes/v1/revoke.d.ts.map +1 -1
- package/dist/routes/v1/revoke.js +3 -2
- package/dist/routes/v1/verify.d.ts.map +1 -1
- package/dist/routes/v1/verify.js +27 -12
- package/dist/routes/v2/compliance.js +1 -1
- package/dist/routes/v2/hpke.d.ts.map +1 -1
- package/dist/routes/v2/hpke.js +8 -4
- package/dist/routes/v2/keys.d.ts.map +1 -1
- package/dist/routes/v2/keys.js +24 -2
- package/dist/routes/v2/kms.d.ts +8 -4
- package/dist/routes/v2/kms.d.ts.map +1 -1
- package/dist/routes/v2/kms.js +81 -82
- package/dist/routes/v2/opaque.d.ts.map +1 -1
- package/dist/routes/v2/opaque.js +26 -4
- package/dist/routes/v2/pq-hash-sign.d.ts.map +1 -1
- package/dist/routes/v2/pq-hash-sign.js +2 -4
- package/dist/routes/v2/pq-sign.d.ts.map +1 -1
- package/dist/routes/v2/pq-sign.js +2 -4
- package/dist/routes/v2/pq.d.ts.map +1 -1
- package/dist/routes/v2/pq.js +10 -9
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +40 -15
- package/dist/utils/keys.d.ts +1 -0
- package/dist/utils/keys.d.ts.map +1 -1
- package/dist/utils/keys.js +9 -2
- package/dist/utils/route-helpers.d.ts.map +1 -1
- package/dist/utils/route-helpers.js +5 -10
- package/package.json +6 -8
- package/dist/lib/kdf-runner.d.ts +0 -18
- package/dist/lib/kdf-runner.d.ts.map +0 -1
- package/dist/lib/kdf-runner.js +0 -27
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decrypt.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/decrypt.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"decrypt.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/decrypt.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBA4C/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAkCE"}
|
|
@@ -7,6 +7,7 @@ const problem_1 = require("../../lib/problem");
|
|
|
7
7
|
const keys_1 = require("../../utils/keys");
|
|
8
8
|
const decryptSchema = {
|
|
9
9
|
tags: ["Encryption"],
|
|
10
|
+
deprecated: true,
|
|
10
11
|
summary: "Decrypt a message",
|
|
11
12
|
description: "Decrypts a PGP message encrypted to the server's key pair (CRYPTO_KEY_DIR), unlocked with the passphrase. The API never takes a private key.",
|
|
12
13
|
response: {
|
|
@@ -49,7 +50,7 @@ exports.default = (app) => {
|
|
|
49
50
|
publicKey: (0, validation_1.validateBase64)(body.publicKey, "publicKey"),
|
|
50
51
|
}, reply);
|
|
51
52
|
if (!v)
|
|
52
|
-
return;
|
|
53
|
+
return reply;
|
|
53
54
|
const decryptedData = await (0, pgp_1.decrypt)({
|
|
54
55
|
passphrase: v.passphrase,
|
|
55
56
|
message: v.message,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/encrypt.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/encrypt.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAsC/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBA+BE"}
|
|
@@ -7,6 +7,7 @@ const problem_1 = require("../../lib/problem");
|
|
|
7
7
|
const keys_1 = require("../../utils/keys");
|
|
8
8
|
const encryptSchema = {
|
|
9
9
|
tags: ["Encryption"],
|
|
10
|
+
deprecated: true,
|
|
10
11
|
summary: "Encrypt a message",
|
|
11
12
|
description: "Encrypts a plaintext message using the supplied PGP public key and passphrase.",
|
|
12
13
|
response: {
|
|
@@ -39,7 +40,7 @@ exports.default = (app) => {
|
|
|
39
40
|
publicKey: (0, validation_1.validateBase64)(body.publicKey, "publicKey"),
|
|
40
41
|
}, reply);
|
|
41
42
|
if (!v)
|
|
42
|
-
return;
|
|
43
|
+
return reply;
|
|
43
44
|
const encryptedData = await (0, pgp_1.encrypt)({
|
|
44
45
|
passphrase: v.passphrase,
|
|
45
46
|
message: v.message,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/generate.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,eAAe,EAAgB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/generate.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,eAAe,EAAgB,MAAM,SAAS,CAAC;yBAuF7C,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAoDE"}
|
|
@@ -7,6 +7,7 @@ const route_helpers_1 = require("../../utils/route-helpers");
|
|
|
7
7
|
const problem_1 = require("../../lib/problem");
|
|
8
8
|
const generateSchema = {
|
|
9
9
|
tags: ["Key Management"],
|
|
10
|
+
deprecated: true,
|
|
10
11
|
summary: "Generate a key pair",
|
|
11
12
|
description: "Generates an OpenPGP key pair (RSA or ECC). The private key is NOT returned for security.",
|
|
12
13
|
response: {
|
|
@@ -62,7 +63,7 @@ exports.default = (app) => {
|
|
|
62
63
|
try {
|
|
63
64
|
const v = validateGenerateBody(request.body, reply);
|
|
64
65
|
if (!v)
|
|
65
|
-
return;
|
|
66
|
+
return reply;
|
|
66
67
|
const generated = (await (0, pgp_1.generate)({
|
|
67
68
|
date: new Date(),
|
|
68
69
|
name: v.name,
|
|
@@ -74,7 +75,7 @@ exports.default = (app) => {
|
|
|
74
75
|
curve: v.curve,
|
|
75
76
|
keyExpirationTime: v.keyExpirationTime,
|
|
76
77
|
format: v.format,
|
|
77
|
-
}));
|
|
78
|
+
}, { persist: false }));
|
|
78
79
|
return reply.send({
|
|
79
80
|
data: {
|
|
80
81
|
publicKey: generated.publicKey,
|
package/dist/routes/v1/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const crypto_1 = require("crypto");
|
|
4
4
|
const constants_1 = require("../../config/constants");
|
|
5
|
-
const id = (0,
|
|
5
|
+
const id = (0, crypto_1.randomUUID)();
|
|
6
6
|
exports.default = (app) => {
|
|
7
7
|
app.get("/", async () => {
|
|
8
8
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"revoke.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/revoke.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"revoke.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/revoke.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBA6C/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAqCE"}
|
package/dist/routes/v1/revoke.js
CHANGED
|
@@ -7,6 +7,7 @@ const route_helpers_1 = require("../../utils/route-helpers");
|
|
|
7
7
|
const problem_1 = require("../../lib/problem");
|
|
8
8
|
const revokeSchema = {
|
|
9
9
|
tags: ["Key Management"],
|
|
10
|
+
deprecated: true,
|
|
10
11
|
summary: "Revoke a key pair",
|
|
11
12
|
description: "Revokes the shipped key pair with a reason code (0=unspecified, 1=superseded, 2=compromised, 3=retired). Returns the revoked public key only.",
|
|
12
13
|
response: {
|
|
@@ -45,12 +46,12 @@ exports.default = (app) => {
|
|
|
45
46
|
reason: (0, validation_1.validateRequiredString)(body.reason, "reason"),
|
|
46
47
|
}, reply);
|
|
47
48
|
if (!v)
|
|
48
|
-
return;
|
|
49
|
+
return reply;
|
|
49
50
|
const revocationData = await (0, pgp_1.revoke)({
|
|
50
51
|
passphrase: v.passphrase,
|
|
51
52
|
flag: v.flag,
|
|
52
53
|
reason: v.reason,
|
|
53
|
-
});
|
|
54
|
+
}, { persist: false });
|
|
54
55
|
return reply.send({ data: { publicKey: revocationData.publicKey } });
|
|
55
56
|
}
|
|
56
57
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/verify.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/verify.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAkD/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBA+CE"}
|
package/dist/routes/v1/verify.js
CHANGED
|
@@ -6,13 +6,23 @@ const route_helpers_1 = require("../../utils/route-helpers");
|
|
|
6
6
|
const problem_1 = require("../../lib/problem");
|
|
7
7
|
const verifySchema = {
|
|
8
8
|
tags: ["Signing"],
|
|
9
|
+
deprecated: true,
|
|
9
10
|
summary: "Verify a signed message",
|
|
10
|
-
description: "Verifies a
|
|
11
|
+
description: "Verifies a clear-signed PGP message, or a message and its base64-encoded detached signature, against the supplied verification keys. `verified` is true only when every signature found verifies; input that carries no signature answers 400.",
|
|
11
12
|
response: {
|
|
12
13
|
200: {
|
|
13
14
|
type: "object",
|
|
14
15
|
additionalProperties: true,
|
|
15
|
-
properties: {
|
|
16
|
+
properties: {
|
|
17
|
+
data: {
|
|
18
|
+
type: "object",
|
|
19
|
+
properties: {
|
|
20
|
+
verified: { type: "boolean" },
|
|
21
|
+
data: { type: "string" },
|
|
22
|
+
keyIDs: { type: "array", items: { type: "string" } },
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
16
26
|
},
|
|
17
27
|
400: problem_1.PROBLEM_SCHEMA,
|
|
18
28
|
401: problem_1.PROBLEM_SCHEMA,
|
|
@@ -25,6 +35,7 @@ const verifySchema = {
|
|
|
25
35
|
date: { type: "string", minLength: 1, maxLength: 64 },
|
|
26
36
|
message: { type: "string", minLength: 1, maxLength: 1024 * 1024 },
|
|
27
37
|
verificationKeys: { type: "string", minLength: 1, maxLength: 64 * 1024 },
|
|
38
|
+
signature: { type: "string", minLength: 1, maxLength: 64 * 1024 },
|
|
28
39
|
},
|
|
29
40
|
},
|
|
30
41
|
};
|
|
@@ -33,25 +44,29 @@ exports.default = (app) => {
|
|
|
33
44
|
schema: verifySchema,
|
|
34
45
|
config: { rateLimit: { max: 100, timeWindow: "1 minute" } },
|
|
35
46
|
}, async (request, reply) => {
|
|
47
|
+
const body = request.body;
|
|
48
|
+
const v = (0, route_helpers_1.collectValidation)({
|
|
49
|
+
date: (0, validation_1.validateDateString)(body.date, "date"),
|
|
50
|
+
message: (0, validation_1.validateRequiredString)(body.message, "message"),
|
|
51
|
+
verificationKeys: (0, validation_1.validateBase64)(body.verificationKeys, "verificationKeys"),
|
|
52
|
+
...(body.signature === undefined
|
|
53
|
+
? {}
|
|
54
|
+
: { signature: (0, validation_1.validateBase64)(body.signature, "signature") }),
|
|
55
|
+
}, reply);
|
|
56
|
+
if (!v)
|
|
57
|
+
return reply;
|
|
36
58
|
try {
|
|
37
|
-
const body = request.body;
|
|
38
|
-
const v = (0, route_helpers_1.collectValidation)({
|
|
39
|
-
date: (0, validation_1.validateDateString)(body.date, "date"),
|
|
40
|
-
message: (0, validation_1.validateRequiredString)(body.message, "message"),
|
|
41
|
-
verificationKeys: (0, validation_1.validateBase64)(body.verificationKeys, "verificationKeys"),
|
|
42
|
-
}, reply);
|
|
43
|
-
if (!v)
|
|
44
|
-
return;
|
|
45
59
|
const verifyData = await (0, pgp_1.verify)({
|
|
46
60
|
date: v.date,
|
|
47
61
|
message: v.message,
|
|
48
62
|
verificationKeys: v.verificationKeys,
|
|
63
|
+
...(v.signature === undefined ? {} : { signature: v.signature }),
|
|
49
64
|
});
|
|
50
65
|
return reply.send({ data: verifyData });
|
|
51
66
|
}
|
|
52
67
|
catch (error) {
|
|
53
|
-
request.log.
|
|
54
|
-
return (0, problem_1.sendProblem)(reply,
|
|
68
|
+
request.log.warn(error, "Verification input rejected");
|
|
69
|
+
return (0, problem_1.sendProblem)(reply, 400, "invalid-input", "The message must be clear-signed or come with a detached signature, and the keys must be armored OpenPGP public keys");
|
|
55
70
|
}
|
|
56
71
|
});
|
|
57
72
|
};
|
|
@@ -69,7 +69,7 @@ const INVENTORY = [
|
|
|
69
69
|
{
|
|
70
70
|
package: "@sebastienrousseau/crypto-kms",
|
|
71
71
|
status: "partial",
|
|
72
|
-
fipsCompliance: "AWS KMS and in-memory local providers;
|
|
72
|
+
fipsCompliance: "AWS KMS, Google Cloud KMS, Vault Transit and in-memory local providers; Azure provider is a stub; PKCS#11 provider is a software simulation; not FIPS 140 validated",
|
|
73
73
|
},
|
|
74
74
|
{
|
|
75
75
|
package: "@sebastienrousseau/crypto-edge",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hpke.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/hpke.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"hpke.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/hpke.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AA+L/C,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI,CAI5D"}
|
package/dist/routes/v2/hpke.js
CHANGED
|
@@ -50,8 +50,8 @@ const KEYGEN_SCHEMA = {
|
|
|
50
50
|
properties: {
|
|
51
51
|
kem: {
|
|
52
52
|
type: "string",
|
|
53
|
-
enum: ["x25519", "p256", "x25519-ml-kem-768"],
|
|
54
|
-
default: "
|
|
53
|
+
enum: ["x25519", "p256", "x-wing", "x25519-ml-kem-768"],
|
|
54
|
+
default: "x-wing",
|
|
55
55
|
},
|
|
56
56
|
},
|
|
57
57
|
},
|
|
@@ -66,7 +66,10 @@ const SEAL_SCHEMA = {
|
|
|
66
66
|
properties: {
|
|
67
67
|
recipientPublicKey: { type: "string", minLength: 1 },
|
|
68
68
|
plaintext: { type: "string", minLength: 1 },
|
|
69
|
-
kem: {
|
|
69
|
+
kem: {
|
|
70
|
+
type: "string",
|
|
71
|
+
enum: ["x25519", "p256", "x-wing", "x25519-ml-kem-768"],
|
|
72
|
+
},
|
|
70
73
|
aead: { type: "string", enum: ["chacha20-poly1305", "aes-128-gcm"] },
|
|
71
74
|
info: { type: "string" },
|
|
72
75
|
aad: { type: "string" },
|
|
@@ -113,7 +116,7 @@ function registerSeal(app) {
|
|
|
113
116
|
recipientPublicKey: b.recipientPublicKey,
|
|
114
117
|
plaintext: hexPlaintext,
|
|
115
118
|
suite: {
|
|
116
|
-
kem: b.kem ?? "
|
|
119
|
+
kem: b.kem ?? "x-wing",
|
|
117
120
|
aead: b.aead ?? "chacha20-poly1305",
|
|
118
121
|
},
|
|
119
122
|
...(b.info ? { info: ensureHex(b.info) } : {}),
|
|
@@ -134,6 +137,7 @@ function registerOpen(app) {
|
|
|
134
137
|
}, async (request, reply) => {
|
|
135
138
|
const b = request.body;
|
|
136
139
|
const key = await (0, keys_1.resolveKey)(request, b.keyId, [
|
|
140
|
+
"x-wing",
|
|
137
141
|
"x25519-ml-kem-768",
|
|
138
142
|
"x25519",
|
|
139
143
|
"p256",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/keys.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/keys.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBA4I/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAIE"}
|
package/dist/routes/v2/keys.js
CHANGED
|
@@ -63,9 +63,10 @@ function registerGenerate(app) {
|
|
|
63
63
|
},
|
|
64
64
|
},
|
|
65
65
|
}, async (request, reply) => {
|
|
66
|
-
const { generateKeyPair } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/keys")));
|
|
67
66
|
const { algorithm, metadata } = request.body;
|
|
68
|
-
const pair =
|
|
67
|
+
const pair = algorithm.startsWith("ml-dsa-")
|
|
68
|
+
? await request.server.signer.run("keys", "generateKeyPair", algorithm, metadata)
|
|
69
|
+
: (await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/keys")))).generateKeyPair(algorithm, metadata);
|
|
69
70
|
const stored = await (0, keys_2.storeKey)(request, pair.algorithm, { publicKey: pair.publicKey }, { privateKey: pair.privateKey });
|
|
70
71
|
return reply.send({
|
|
71
72
|
data: { ...(0, keys_2.publicView)(stored), kid: pair.kid, metadata: pair.metadata },
|
|
@@ -94,8 +95,29 @@ function registerExport(app) {
|
|
|
94
95
|
});
|
|
95
96
|
});
|
|
96
97
|
}
|
|
98
|
+
function registerDelete(app) {
|
|
99
|
+
app.post("/v2/keys/delete", {
|
|
100
|
+
schema: {
|
|
101
|
+
tags: ["Key Management"],
|
|
102
|
+
summary: "Delete a server-held key",
|
|
103
|
+
description: "Deletes a key pair this principal generated, from memory and from disk. Another principal's key answers 404.",
|
|
104
|
+
body: {
|
|
105
|
+
type: "object",
|
|
106
|
+
required: ["keyId"],
|
|
107
|
+
additionalProperties: false,
|
|
108
|
+
properties: { keyId: keys_2.KEY_ID_SCHEMA },
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
}, async (request, reply) => {
|
|
112
|
+
const { keyId } = request.body;
|
|
113
|
+
await (0, keys_2.deleteKey)(request, keyId);
|
|
114
|
+
request.log.info({ keyId }, "Key deleted");
|
|
115
|
+
return reply.send({ data: { keyId, deleted: true } });
|
|
116
|
+
});
|
|
117
|
+
}
|
|
97
118
|
exports.default = (app) => {
|
|
98
119
|
registerGenerate(app);
|
|
99
120
|
registerExport(app);
|
|
121
|
+
registerDelete(app);
|
|
100
122
|
};
|
|
101
123
|
//# sourceMappingURL=keys.js.map
|
package/dist/routes/v2/kms.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { FastifyInstance } from "fastify";
|
|
2
|
-
import { type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { type KmsRegistry } from "../../lib/kms-providers";
|
|
3
|
+
import type { KmsOwners } from "../../lib/kms-owners";
|
|
4
|
+
declare module "fastify" {
|
|
5
|
+
interface FastifyInstance {
|
|
6
|
+
kms: KmsRegistry;
|
|
7
|
+
kmsOwners: KmsOwners;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
6
10
|
export default function kmsRoute(app: FastifyInstance): void;
|
|
7
11
|
//# sourceMappingURL=kms.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kms.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/kms.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"kms.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/kms.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;AAS7E,OAAO,EAEL,KAAK,WAAW,EACjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAU,eAAe;QAEvB,GAAG,EAAE,WAAW,CAAC;QAEjB,SAAS,EAAE,SAAS,CAAC;KACtB;CACF;AAwYD,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI,CAO3D"}
|
package/dist/routes/v2/kms.js
CHANGED
|
@@ -1,78 +1,71 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerKmsProvider = registerKmsProvider;
|
|
4
|
-
exports.resetKmsProviders = resetKmsProviders;
|
|
5
|
-
exports.resolveKmsProvider = resolveKmsProvider;
|
|
6
3
|
exports.default = kmsRoute;
|
|
7
4
|
const crypto_kms_1 = require("@sebastienrousseau/crypto-kms");
|
|
8
5
|
const route_helpers_1 = require("../../utils/route-helpers");
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
const auth_1 = require("../../lib/auth");
|
|
7
|
+
const problem_1 = require("../../lib/problem");
|
|
8
|
+
const kms_providers_1 = require("../../lib/kms-providers");
|
|
9
|
+
const audit_1 = require("../../lib/audit");
|
|
10
|
+
class KmsKeyNotOwnedError extends Error {
|
|
11
|
+
name = "KmsKeyNotOwnedError";
|
|
13
12
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
13
|
+
const KMS_PROBLEMS = {
|
|
14
|
+
NOT_FOUND: [404, "kms-key-not-found"],
|
|
15
|
+
DISABLED: [409, "kms-key-disabled"],
|
|
16
|
+
INVALID_USAGE: [400, "invalid-input"],
|
|
17
|
+
INVALID_ARGUMENT: [400, "invalid-input"],
|
|
18
|
+
INVALID_CIPHERTEXT: [400, "invalid-input"],
|
|
19
|
+
DECRYPTION_FAILED: [400, "invalid-input"],
|
|
20
|
+
VERSION_DESTROYED: [400, "invalid-input"],
|
|
21
|
+
NOT_IMPLEMENTED: [501, "not-implemented"],
|
|
22
|
+
DEPENDENCY_MISSING: [503, "service-unavailable"],
|
|
23
|
+
};
|
|
24
|
+
function kmsFailure(err, request, reply, operation) {
|
|
25
|
+
if (err instanceof kms_providers_1.KmsProviderNotEnabledError) {
|
|
26
|
+
return (0, problem_1.sendProblem)(reply, 400, "kms-provider-not-enabled", err.message);
|
|
27
|
+
}
|
|
28
|
+
if (err instanceof KmsKeyNotOwnedError) {
|
|
29
|
+
return (0, problem_1.sendProblem)(reply, 404, "kms-key-not-found", "Unknown KMS key");
|
|
30
|
+
}
|
|
31
|
+
if (err instanceof crypto_kms_1.KmsError) {
|
|
32
|
+
const [status, slug] = KMS_PROBLEMS[err.code];
|
|
33
|
+
request.log.warn(err, `${operation} failed`);
|
|
34
|
+
return (0, problem_1.sendProblem)(reply, status, slug, `${operation} failed`, {
|
|
35
|
+
code: err.code,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return (0, route_helpers_1.classifyCryptoError)(err, request, reply, operation);
|
|
30
39
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
40
|
+
const authOf = (request) => request.auth;
|
|
41
|
+
function providerFor(request, b) {
|
|
42
|
+
const name = (b["provider"] ?? "local").toLowerCase();
|
|
43
|
+
return { name, provider: request.server.kms.get(name) };
|
|
36
44
|
}
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
function ownedKey(request, b) {
|
|
46
|
+
const { name, provider } = providerFor(request, b);
|
|
47
|
+
const keyId = sanitizeKeyId(b["keyId"]);
|
|
48
|
+
const auth = authOf(request);
|
|
49
|
+
const owner = request.server.kmsOwners.ownerOf(name, keyId);
|
|
50
|
+
const allowed = owner === undefined ? (0, auth_1.hasScope)(auth, "crypto:admin") : owner === auth.sub;
|
|
51
|
+
if (!allowed)
|
|
52
|
+
throw new KmsKeyNotOwnedError();
|
|
53
|
+
return { provider, keyId };
|
|
41
54
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
case "vault":
|
|
49
|
-
return createVaultProvider();
|
|
50
|
-
case "azure":
|
|
51
|
-
return createAzureProvider();
|
|
52
|
-
default:
|
|
53
|
-
throw new Error(`Unsupported KMS provider: ${name}`);
|
|
55
|
+
const HEX_BYTES = "^([0-9a-fA-F]{2})*$";
|
|
56
|
+
function plaintextBytes(text, encoding) {
|
|
57
|
+
if (encoding !== "hex")
|
|
58
|
+
return new Uint8Array(Buffer.from(text, "utf8"));
|
|
59
|
+
if (!new RegExp(HEX_BYTES).test(text)) {
|
|
60
|
+
throw new crypto_kms_1.KmsError("INVALID_ARGUMENT", "plaintext is not hex");
|
|
54
61
|
}
|
|
55
|
-
|
|
56
|
-
function resolveKmsProvider(name) {
|
|
57
|
-
const key = (name ?? "local").toLowerCase();
|
|
58
|
-
const existing = providerRegistry.get(key);
|
|
59
|
-
if (existing)
|
|
60
|
-
return existing;
|
|
61
|
-
const provider = createDefaultProvider(key, name);
|
|
62
|
-
providerRegistry.set(key, provider);
|
|
63
|
-
return provider;
|
|
64
|
-
}
|
|
65
|
-
function parseBytes(text) {
|
|
66
|
-
const isHex = /^[0-9a-fA-F]*$/.test(text) && text.length % 2 === 0;
|
|
67
|
-
return isHex
|
|
68
|
-
? new Uint8Array(Buffer.from(text, "hex"))
|
|
69
|
-
: new Uint8Array(Buffer.from(text, "utf8"));
|
|
62
|
+
return new Uint8Array(Buffer.from(text, "hex"));
|
|
70
63
|
}
|
|
71
64
|
function sanitizeKeyId(id) {
|
|
72
65
|
if (typeof id !== "string" ||
|
|
73
66
|
!/^[a-zA-Z0-9_\-/:.]+$/.test(id) ||
|
|
74
67
|
id.includes("..")) {
|
|
75
|
-
throw new
|
|
68
|
+
throw new crypto_kms_1.KmsError("INVALID_ARGUMENT", "Invalid keyId format");
|
|
76
69
|
}
|
|
77
70
|
return encodeURIComponent(id).replace(/%2F/g, "/").replace(/%3A/g, ":");
|
|
78
71
|
}
|
|
@@ -99,7 +92,11 @@ const WRAP_SCHEMA = {
|
|
|
99
92
|
additionalProperties: false,
|
|
100
93
|
properties: {
|
|
101
94
|
keyId: { type: "string" },
|
|
102
|
-
unwrappedKey: {
|
|
95
|
+
unwrappedKey: {
|
|
96
|
+
type: "string",
|
|
97
|
+
pattern: HEX_BYTES,
|
|
98
|
+
description: "Key bytes to wrap, as hex (the encoding unwrap returns).",
|
|
99
|
+
},
|
|
103
100
|
provider: { type: "string" },
|
|
104
101
|
context: { type: "object", additionalProperties: { type: "string" } },
|
|
105
102
|
},
|
|
@@ -144,6 +141,11 @@ const ENCRYPT_SCHEMA = {
|
|
|
144
141
|
properties: {
|
|
145
142
|
keyId: { type: "string" },
|
|
146
143
|
plaintext: { type: "string" },
|
|
144
|
+
encoding: {
|
|
145
|
+
type: "string",
|
|
146
|
+
enum: ["utf8", "hex"],
|
|
147
|
+
description: "How plaintext is encoded: utf8 (default) or hex. Never guessed from the content.",
|
|
148
|
+
},
|
|
147
149
|
provider: { type: "string" },
|
|
148
150
|
context: { type: "object", additionalProperties: { type: "string" } },
|
|
149
151
|
},
|
|
@@ -171,12 +173,14 @@ function registerCreateKey(app) {
|
|
|
171
173
|
}, async (request, reply) => {
|
|
172
174
|
const b = request.body;
|
|
173
175
|
try {
|
|
174
|
-
const provider =
|
|
176
|
+
const { name, provider } = providerFor(request, b);
|
|
175
177
|
const meta = await provider.createKey(b["algorithm"] ?? "aes-256-gcm", b["usage"] ?? "encrypt", b["metadata"]);
|
|
178
|
+
request.server.kmsOwners.bind(name, meta.keyId, authOf(request).sub);
|
|
179
|
+
(0, audit_1.noteAuditKey)(request, meta.keyId);
|
|
176
180
|
return reply.send({ data: meta });
|
|
177
181
|
}
|
|
178
182
|
catch (err) {
|
|
179
|
-
return (
|
|
183
|
+
return kmsFailure(err, request, reply, "KMS CreateKey");
|
|
180
184
|
}
|
|
181
185
|
});
|
|
182
186
|
}
|
|
@@ -187,19 +191,18 @@ function registerWrap(app) {
|
|
|
187
191
|
}, async (request, reply) => {
|
|
188
192
|
const b = request.body;
|
|
189
193
|
try {
|
|
190
|
-
const provider =
|
|
194
|
+
const { provider, keyId } = ownedKey(request, b);
|
|
191
195
|
if (!provider.wrapKey) {
|
|
192
|
-
throw new
|
|
196
|
+
throw new crypto_kms_1.KmsError("NOT_IMPLEMENTED", "wrapKey is not supported");
|
|
193
197
|
}
|
|
194
|
-
const
|
|
195
|
-
const bytes = parseBytes(b["unwrappedKey"]);
|
|
198
|
+
const bytes = new Uint8Array(Buffer.from(b["unwrappedKey"], "hex"));
|
|
196
199
|
const res = await provider.wrapKey(keyId, bytes, b["context"]);
|
|
197
200
|
return reply.send({
|
|
198
201
|
data: { ...res, provider: provider.name },
|
|
199
202
|
});
|
|
200
203
|
}
|
|
201
204
|
catch (err) {
|
|
202
|
-
return (
|
|
205
|
+
return kmsFailure(err, request, reply, "KMS Wrap");
|
|
203
206
|
}
|
|
204
207
|
});
|
|
205
208
|
}
|
|
@@ -210,11 +213,10 @@ function registerUnwrap(app) {
|
|
|
210
213
|
}, async (request, reply) => {
|
|
211
214
|
const b = request.body;
|
|
212
215
|
try {
|
|
213
|
-
const provider =
|
|
216
|
+
const { provider, keyId } = ownedKey(request, b);
|
|
214
217
|
if (!provider.unwrapKey) {
|
|
215
|
-
throw new
|
|
218
|
+
throw new crypto_kms_1.KmsError("NOT_IMPLEMENTED", "unwrapKey is not supported");
|
|
216
219
|
}
|
|
217
|
-
const keyId = sanitizeKeyId(b["keyId"]);
|
|
218
220
|
const res = await provider.unwrapKey(keyId, b["wrappedKey"], b["context"]);
|
|
219
221
|
return reply.send({
|
|
220
222
|
data: {
|
|
@@ -225,7 +227,7 @@ function registerUnwrap(app) {
|
|
|
225
227
|
});
|
|
226
228
|
}
|
|
227
229
|
catch (err) {
|
|
228
|
-
return (
|
|
230
|
+
return kmsFailure(err, request, reply, "KMS Unwrap");
|
|
229
231
|
}
|
|
230
232
|
});
|
|
231
233
|
}
|
|
@@ -236,8 +238,7 @@ function registerDataKey(app) {
|
|
|
236
238
|
}, async (request, reply) => {
|
|
237
239
|
const b = request.body;
|
|
238
240
|
try {
|
|
239
|
-
const provider =
|
|
240
|
-
const keyId = sanitizeKeyId(b["keyId"]);
|
|
241
|
+
const { provider, keyId } = ownedKey(request, b);
|
|
241
242
|
const res = await provider.generateDataKey(keyId, b["keySpec"]);
|
|
242
243
|
return reply.send({
|
|
243
244
|
data: {
|
|
@@ -249,7 +250,7 @@ function registerDataKey(app) {
|
|
|
249
250
|
});
|
|
250
251
|
}
|
|
251
252
|
catch (err) {
|
|
252
|
-
return (
|
|
253
|
+
return kmsFailure(err, request, reply, "KMS GenerateDataKey");
|
|
253
254
|
}
|
|
254
255
|
});
|
|
255
256
|
}
|
|
@@ -260,16 +261,15 @@ function registerEncrypt(app) {
|
|
|
260
261
|
}, async (request, reply) => {
|
|
261
262
|
const b = request.body;
|
|
262
263
|
try {
|
|
263
|
-
const provider =
|
|
264
|
-
const
|
|
265
|
-
const bytes = parseBytes(b["plaintext"]);
|
|
264
|
+
const { provider, keyId } = ownedKey(request, b);
|
|
265
|
+
const bytes = plaintextBytes(b["plaintext"], b["encoding"]);
|
|
266
266
|
const res = await provider.encrypt(keyId, bytes, b["context"]);
|
|
267
267
|
return reply.send({
|
|
268
268
|
data: { ...res, provider: provider.name },
|
|
269
269
|
});
|
|
270
270
|
}
|
|
271
271
|
catch (err) {
|
|
272
|
-
return (
|
|
272
|
+
return kmsFailure(err, request, reply, "KMS Encrypt");
|
|
273
273
|
}
|
|
274
274
|
});
|
|
275
275
|
}
|
|
@@ -280,8 +280,7 @@ function registerDecrypt(app) {
|
|
|
280
280
|
}, async (request, reply) => {
|
|
281
281
|
const b = request.body;
|
|
282
282
|
try {
|
|
283
|
-
const provider =
|
|
284
|
-
const keyId = sanitizeKeyId(b["keyId"]);
|
|
283
|
+
const { provider, keyId } = ownedKey(request, b);
|
|
285
284
|
const res = await provider.decrypt(keyId, b["ciphertext"], b["context"]);
|
|
286
285
|
const utf8 = Buffer.from(res.plaintext).toString("utf8");
|
|
287
286
|
const hex = Buffer.from(res.plaintext).toString("hex");
|
|
@@ -295,7 +294,7 @@ function registerDecrypt(app) {
|
|
|
295
294
|
});
|
|
296
295
|
}
|
|
297
296
|
catch (err) {
|
|
298
|
-
return (
|
|
297
|
+
return kmsFailure(err, request, reply, "KMS Decrypt");
|
|
299
298
|
}
|
|
300
299
|
});
|
|
301
300
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opaque.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/opaque.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"opaque.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/opaque.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;yBAyS7D,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAKE"}
|