@cocoar/secrets 0.0.0-stage → 6.2.0-beta.15
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 +54 -2
- package/dist/index.cjs +125 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +70 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.js +94 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -3
package/README.md
CHANGED
|
@@ -1,3 +1,55 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @cocoar/secrets
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Encrypt secrets for **Cocoar.Configuration** client-side — in the browser or Node — so the server
|
|
4
|
+
stores only an encrypted envelope and **never sees the plaintext**.
|
|
5
|
+
|
|
6
|
+
The server publishes the public half of its secrets encryption key; this library uses it to seal a
|
|
7
|
+
value with hybrid encryption (a one-time **AES-256-GCM** data key wrapped with the server's
|
|
8
|
+
**RSA-OAEP-SHA256** public key). The resulting `cocoar.secret` envelope is what you store (e.g. via a
|
|
9
|
+
WritableStore secret-write endpoint). Only the server, holding the private key, can decrypt it.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @cocoar/secrets
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Requires WebCrypto (`globalThis.crypto.subtle`) — every modern browser and Node 18+.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { fetchEncryptionKey, encryptSecret } from "@cocoar/secrets";
|
|
23
|
+
|
|
24
|
+
// 1. Fetch the server's published public key.
|
|
25
|
+
const key = await fetchEncryptionKey("/.well-known/cocoar/encryption-key");
|
|
26
|
+
|
|
27
|
+
// 2. Encrypt a secret value (string or any JSON-serializable object).
|
|
28
|
+
const envelope = await encryptSecret(key, "my-oauth-client-secret");
|
|
29
|
+
|
|
30
|
+
// 3. Send the envelope to your API — the plaintext never left the browser.
|
|
31
|
+
await fetch("/admin/config/oauth-secret", {
|
|
32
|
+
method: "POST",
|
|
33
|
+
headers: { "content-type": "application/json" },
|
|
34
|
+
body: JSON.stringify(envelope),
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
For multi-tenant servers the same endpoint returns the current tenant's key (resolved server-side),
|
|
39
|
+
so no client changes are needed.
|
|
40
|
+
|
|
41
|
+
## API
|
|
42
|
+
|
|
43
|
+
- `fetchEncryptionKey(url, init?)` → `Promise<PublishedKey>` — fetch the published public key.
|
|
44
|
+
- `encryptSecret(key, value)` → `Promise<SecretEnvelope>` — seal a value into a `cocoar.secret` envelope.
|
|
45
|
+
- `base64UrlEncode` / `base64UrlDecode` — base64url (no padding) helpers.
|
|
46
|
+
|
|
47
|
+
## Wire format
|
|
48
|
+
|
|
49
|
+
The value is JSON-serialized (a string becomes a quoted JSON string, matching the server's
|
|
50
|
+
`JsonSerializer`), sealed with AES-256-GCM, and the data key is wrapped with RSA-OAEP-SHA256. All
|
|
51
|
+
binary fields are **base64url without padding**.
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
Apache-2.0
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ALG_ENC: () => ALG_ENC,
|
|
24
|
+
ALG_HYBRID: () => ALG_HYBRID,
|
|
25
|
+
ALG_WRAP: () => ALG_WRAP,
|
|
26
|
+
base64UrlDecode: () => base64UrlDecode,
|
|
27
|
+
base64UrlEncode: () => base64UrlEncode,
|
|
28
|
+
encryptSecret: () => encryptSecret,
|
|
29
|
+
fetchEncryptionKey: () => fetchEncryptionKey
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(index_exports);
|
|
32
|
+
var ALG_HYBRID = "RSA-OAEP-AES256-GCM";
|
|
33
|
+
var ALG_WRAP = "RSA-OAEP-256";
|
|
34
|
+
var ALG_ENC = "AES-256-GCM";
|
|
35
|
+
function subtle() {
|
|
36
|
+
const c = globalThis.crypto;
|
|
37
|
+
if (!c?.subtle) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
"WebCrypto is unavailable. Use a browser or Node 18+ where globalThis.crypto.subtle exists."
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return c.subtle;
|
|
43
|
+
}
|
|
44
|
+
function base64UrlEncode(bytes) {
|
|
45
|
+
let binary = "";
|
|
46
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
47
|
+
binary += String.fromCharCode(bytes[i]);
|
|
48
|
+
}
|
|
49
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
50
|
+
}
|
|
51
|
+
function base64UrlDecode(value) {
|
|
52
|
+
const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
53
|
+
const padded = normalized + "=".repeat((4 - normalized.length % 4) % 4);
|
|
54
|
+
const binary = atob(padded);
|
|
55
|
+
const out = new Uint8Array(binary.length);
|
|
56
|
+
for (let i = 0; i < binary.length; i++) {
|
|
57
|
+
out[i] = binary.charCodeAt(i);
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
function assertSupported(key) {
|
|
62
|
+
if (key.format !== "spki") {
|
|
63
|
+
throw new Error(`Unsupported public-key format '${key.format}' (expected 'spki').`);
|
|
64
|
+
}
|
|
65
|
+
if (key.encoding !== "base64url") {
|
|
66
|
+
throw new Error(`Unsupported public-key encoding '${key.encoding}' (expected 'base64url').`);
|
|
67
|
+
}
|
|
68
|
+
if (key.walg !== ALG_WRAP) {
|
|
69
|
+
throw new Error(`Unsupported key-wrap algorithm '${key.walg}' (expected '${ALG_WRAP}').`);
|
|
70
|
+
}
|
|
71
|
+
if (key.enc !== ALG_ENC) {
|
|
72
|
+
throw new Error(`Unsupported data-encryption algorithm '${key.enc}' (expected '${ALG_ENC}').`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function fetchEncryptionKey(url, init) {
|
|
76
|
+
const res = await fetch(url, init);
|
|
77
|
+
if (!res.ok) {
|
|
78
|
+
throw new Error(`Failed to fetch encryption key from ${url}: HTTP ${res.status}.`);
|
|
79
|
+
}
|
|
80
|
+
return await res.json();
|
|
81
|
+
}
|
|
82
|
+
async function encryptSecret(key, value) {
|
|
83
|
+
assertSupported(key);
|
|
84
|
+
const crypto = subtle();
|
|
85
|
+
const plaintext = new TextEncoder().encode(JSON.stringify(value));
|
|
86
|
+
const dek = globalThis.crypto.getRandomValues(new Uint8Array(32));
|
|
87
|
+
const iv = globalThis.crypto.getRandomValues(new Uint8Array(12));
|
|
88
|
+
const aesKey = await crypto.importKey("raw", dek, { name: "AES-GCM" }, false, ["encrypt"]);
|
|
89
|
+
const sealed = new Uint8Array(
|
|
90
|
+
await crypto.encrypt({ name: "AES-GCM", iv, tagLength: 128 }, aesKey, plaintext)
|
|
91
|
+
);
|
|
92
|
+
const ct = sealed.slice(0, sealed.length - 16);
|
|
93
|
+
const tag = sealed.slice(sealed.length - 16);
|
|
94
|
+
const rsaPublicKey = await crypto.importKey(
|
|
95
|
+
"spki",
|
|
96
|
+
base64UrlDecode(key.publicKey),
|
|
97
|
+
{ name: "RSA-OAEP", hash: "SHA-256" },
|
|
98
|
+
false,
|
|
99
|
+
["encrypt"]
|
|
100
|
+
);
|
|
101
|
+
const wrappedKey = new Uint8Array(await crypto.encrypt({ name: "RSA-OAEP" }, rsaPublicKey, dek));
|
|
102
|
+
dek.fill(0);
|
|
103
|
+
return {
|
|
104
|
+
type: "cocoar.secret",
|
|
105
|
+
version: 1,
|
|
106
|
+
kid: key.kid,
|
|
107
|
+
alg: ALG_HYBRID,
|
|
108
|
+
wk: base64UrlEncode(wrappedKey),
|
|
109
|
+
walg: ALG_WRAP,
|
|
110
|
+
iv: base64UrlEncode(iv),
|
|
111
|
+
ct: base64UrlEncode(ct),
|
|
112
|
+
tag: base64UrlEncode(tag)
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
+
0 && (module.exports = {
|
|
117
|
+
ALG_ENC,
|
|
118
|
+
ALG_HYBRID,
|
|
119
|
+
ALG_WRAP,
|
|
120
|
+
base64UrlDecode,
|
|
121
|
+
base64UrlEncode,
|
|
122
|
+
encryptSecret,
|
|
123
|
+
fetchEncryptionKey
|
|
124
|
+
});
|
|
125
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@cocoar/secrets` — encrypt a secret for **Cocoar.Configuration** so the server stores only an\n * encrypted envelope and never sees the plaintext.\n *\n * Hybrid encryption matching the server's decryption contract: a one-time **AES-256-GCM** data key\n * seals the value, and that key is wrapped with the server's **RSA-OAEP-SHA256** public key. Runs\n * anywhere WebCrypto is available — browsers and Node 18+ (`globalThis.crypto.subtle`).\n *\n * @example\n * ```ts\n * const key = await fetchEncryptionKey(\"/.well-known/cocoar/encryption-key\");\n * const envelope = await encryptSecret(key, \"my-oauth-client-secret\");\n * await fetch(\"/admin/config/oauth-secret\", { method: \"POST\", body: JSON.stringify(envelope) });\n * ```\n */\n\n/** Overall hybrid scheme identifier (envelope `alg`). */\nexport const ALG_HYBRID = \"RSA-OAEP-AES256-GCM\";\n/** Key-wrapping algorithm identifier (envelope `walg`). */\nexport const ALG_WRAP = \"RSA-OAEP-256\";\n/** Data-encryption algorithm identifier (published key `enc`). */\nexport const ALG_ENC = \"AES-256-GCM\";\n\n/** The public-key document the server publishes at `/.well-known/cocoar/encryption-key`. */\nexport interface PublishedKey {\n /** Key id (single-tenant: the configured kid; multi-tenant: the tenant id). */\n kid: string;\n /** Overall scheme — `\"RSA-OAEP-AES256-GCM\"`. */\n alg: string;\n /** Key-wrap algorithm — `\"RSA-OAEP-256\"`. */\n walg: string;\n /** Data-encryption algorithm — `\"AES-256-GCM\"`. */\n enc: string;\n /** Public-key structure — `\"spki\"` (X.509 SubjectPublicKeyInfo, DER). */\n format: string;\n /** Encoding of {@link publicKey} — `\"base64url\"` (no padding). */\n encoding: string;\n /** The RSA public key: DER SubjectPublicKeyInfo, base64url-encoded without padding. */\n publicKey: string;\n}\n\n/** The encrypted envelope the server accepts (`cocoar.secret`, version 1). */\nexport interface SecretEnvelope {\n type: \"cocoar.secret\";\n version: 1;\n kid: string;\n alg: string;\n /** base64url: the AES key wrapped with RSA-OAEP-SHA256. */\n wk: string;\n walg: string;\n /** base64url: the 96-bit AES-GCM IV. */\n iv: string;\n /** base64url: the ciphertext. */\n ct: string;\n /** base64url: the 128-bit GCM authentication tag. */\n tag: string;\n}\n\nfunction subtle(): SubtleCrypto {\n const c = (globalThis as { crypto?: Crypto }).crypto;\n if (!c?.subtle) {\n throw new Error(\n \"WebCrypto is unavailable. Use a browser or Node 18+ where globalThis.crypto.subtle exists.\",\n );\n }\n return c.subtle;\n}\n\n/** Encode bytes as base64url **without** padding (the wire format Cocoar expects). */\nexport function base64UrlEncode(bytes: Uint8Array): string {\n let binary = \"\";\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]!);\n }\n return btoa(binary).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\n\n/** Decode base64url (with or without padding) into bytes. */\nexport function base64UrlDecode(value: string): Uint8Array {\n const normalized = value.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padded = normalized + \"=\".repeat((4 - (normalized.length % 4)) % 4);\n const binary = atob(padded);\n const out = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n out[i] = binary.charCodeAt(i);\n }\n return out;\n}\n\nfunction assertSupported(key: PublishedKey): void {\n if (key.format !== \"spki\") {\n throw new Error(`Unsupported public-key format '${key.format}' (expected 'spki').`);\n }\n if (key.encoding !== \"base64url\") {\n throw new Error(`Unsupported public-key encoding '${key.encoding}' (expected 'base64url').`);\n }\n if (key.walg !== ALG_WRAP) {\n throw new Error(`Unsupported key-wrap algorithm '${key.walg}' (expected '${ALG_WRAP}').`);\n }\n if (key.enc !== ALG_ENC) {\n throw new Error(`Unsupported data-encryption algorithm '${key.enc}' (expected '${ALG_ENC}').`);\n }\n}\n\n/** Fetch the server's published public key from the given URL. */\nexport async function fetchEncryptionKey(url: string, init?: RequestInit): Promise<PublishedKey> {\n const res = await fetch(url, init);\n if (!res.ok) {\n throw new Error(`Failed to fetch encryption key from ${url}: HTTP ${res.status}.`);\n }\n return (await res.json()) as PublishedKey;\n}\n\n/**\n * Encrypt a value into a Cocoar secret envelope using the server's published public key.\n *\n * The value is JSON-serialized first (a string becomes a quoted JSON string, matching the server's\n * `JsonSerializer` round-trip), then sealed with a one-time AES-256-GCM key that is wrapped with the\n * server's RSA-OAEP-SHA256 public key. The plaintext never leaves the caller in clear form.\n */\nexport async function encryptSecret(key: PublishedKey, value: unknown): Promise<SecretEnvelope> {\n assertSupported(key);\n const crypto = subtle();\n\n const plaintext = new TextEncoder().encode(JSON.stringify(value));\n\n // One-time AES-256-GCM data-encryption key + 96-bit IV.\n const dek = globalThis.crypto.getRandomValues(new Uint8Array(32));\n const iv = globalThis.crypto.getRandomValues(new Uint8Array(12));\n const aesKey = await crypto.importKey(\"raw\", dek, { name: \"AES-GCM\" }, false, [\"encrypt\"]);\n const sealed = new Uint8Array(\n await crypto.encrypt({ name: \"AES-GCM\", iv, tagLength: 128 }, aesKey, plaintext),\n );\n\n // WebCrypto returns ciphertext || tag concatenated; the server expects them as separate fields.\n const ct = sealed.slice(0, sealed.length - 16);\n const tag = sealed.slice(sealed.length - 16);\n\n // Wrap the AES key with the server's RSA-OAEP-SHA256 public key. (Cast to BufferSource: TS 5.7+ types a\n // bare Uint8Array as Uint8Array<ArrayBufferLike>, which WebCrypto's BufferSource doesn't accept — the public\n // base64UrlDecode return type stays a plain Uint8Array so older-TS consumers aren't forced onto the generic.)\n const rsaPublicKey = await crypto.importKey(\n \"spki\",\n base64UrlDecode(key.publicKey) as BufferSource,\n { name: \"RSA-OAEP\", hash: \"SHA-256\" },\n false,\n [\"encrypt\"],\n );\n const wrappedKey = new Uint8Array(await crypto.encrypt({ name: \"RSA-OAEP\" }, rsaPublicKey, dek));\n\n // Best-effort: drop the plaintext key bytes once wrapped.\n dek.fill(0);\n\n return {\n type: \"cocoar.secret\",\n version: 1,\n kid: key.kid,\n alg: ALG_HYBRID,\n wk: base64UrlEncode(wrappedKey),\n walg: ALG_WRAP,\n iv: base64UrlEncode(iv),\n ct: base64UrlEncode(ct),\n tag: base64UrlEncode(tag),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBO,IAAM,aAAa;AAEnB,IAAM,WAAW;AAEjB,IAAM,UAAU;AAqCvB,SAAS,SAAuB;AAC9B,QAAM,IAAK,WAAmC;AA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K,gBAAgB,GAAG;AAAA,EAC1B;AACF;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@cocoar/secrets` — encrypt a secret for **Cocoar.Configuration** so the server stores only an
|
|
3
|
+
* encrypted envelope and never sees the plaintext.
|
|
4
|
+
*
|
|
5
|
+
* Hybrid encryption matching the server's decryption contract: a one-time **AES-256-GCM** data key
|
|
6
|
+
* seals the value, and that key is wrapped with the server's **RSA-OAEP-SHA256** public key. Runs
|
|
7
|
+
* anywhere WebCrypto is available — browsers and Node 18+ (`globalThis.crypto.subtle`).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const key = await fetchEncryptionKey("/.well-known/cocoar/encryption-key");
|
|
12
|
+
* const envelope = await encryptSecret(key, "my-oauth-client-secret");
|
|
13
|
+
* await fetch("/admin/config/oauth-secret", { method: "POST", body: JSON.stringify(envelope) });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
/** Overall hybrid scheme identifier (envelope `alg`). */
|
|
17
|
+
declare const ALG_HYBRID = "RSA-OAEP-AES256-GCM";
|
|
18
|
+
/** Key-wrapping algorithm identifier (envelope `walg`). */
|
|
19
|
+
declare const ALG_WRAP = "RSA-OAEP-256";
|
|
20
|
+
/** Data-encryption algorithm identifier (published key `enc`). */
|
|
21
|
+
declare const ALG_ENC = "AES-256-GCM";
|
|
22
|
+
/** The public-key document the server publishes at `/.well-known/cocoar/encryption-key`. */
|
|
23
|
+
interface PublishedKey {
|
|
24
|
+
/** Key id (single-tenant: the configured kid; multi-tenant: the tenant id). */
|
|
25
|
+
kid: string;
|
|
26
|
+
/** Overall scheme — `"RSA-OAEP-AES256-GCM"`. */
|
|
27
|
+
alg: string;
|
|
28
|
+
/** Key-wrap algorithm — `"RSA-OAEP-256"`. */
|
|
29
|
+
walg: string;
|
|
30
|
+
/** Data-encryption algorithm — `"AES-256-GCM"`. */
|
|
31
|
+
enc: string;
|
|
32
|
+
/** Public-key structure — `"spki"` (X.509 SubjectPublicKeyInfo, DER). */
|
|
33
|
+
format: string;
|
|
34
|
+
/** Encoding of {@link publicKey} — `"base64url"` (no padding). */
|
|
35
|
+
encoding: string;
|
|
36
|
+
/** The RSA public key: DER SubjectPublicKeyInfo, base64url-encoded without padding. */
|
|
37
|
+
publicKey: string;
|
|
38
|
+
}
|
|
39
|
+
/** The encrypted envelope the server accepts (`cocoar.secret`, version 1). */
|
|
40
|
+
interface SecretEnvelope {
|
|
41
|
+
type: "cocoar.secret";
|
|
42
|
+
version: 1;
|
|
43
|
+
kid: string;
|
|
44
|
+
alg: string;
|
|
45
|
+
/** base64url: the AES key wrapped with RSA-OAEP-SHA256. */
|
|
46
|
+
wk: string;
|
|
47
|
+
walg: string;
|
|
48
|
+
/** base64url: the 96-bit AES-GCM IV. */
|
|
49
|
+
iv: string;
|
|
50
|
+
/** base64url: the ciphertext. */
|
|
51
|
+
ct: string;
|
|
52
|
+
/** base64url: the 128-bit GCM authentication tag. */
|
|
53
|
+
tag: string;
|
|
54
|
+
}
|
|
55
|
+
/** Encode bytes as base64url **without** padding (the wire format Cocoar expects). */
|
|
56
|
+
declare function base64UrlEncode(bytes: Uint8Array): string;
|
|
57
|
+
/** Decode base64url (with or without padding) into bytes. */
|
|
58
|
+
declare function base64UrlDecode(value: string): Uint8Array;
|
|
59
|
+
/** Fetch the server's published public key from the given URL. */
|
|
60
|
+
declare function fetchEncryptionKey(url: string, init?: RequestInit): Promise<PublishedKey>;
|
|
61
|
+
/**
|
|
62
|
+
* Encrypt a value into a Cocoar secret envelope using the server's published public key.
|
|
63
|
+
*
|
|
64
|
+
* The value is JSON-serialized first (a string becomes a quoted JSON string, matching the server's
|
|
65
|
+
* `JsonSerializer` round-trip), then sealed with a one-time AES-256-GCM key that is wrapped with the
|
|
66
|
+
* server's RSA-OAEP-SHA256 public key. The plaintext never leaves the caller in clear form.
|
|
67
|
+
*/
|
|
68
|
+
declare function encryptSecret(key: PublishedKey, value: unknown): Promise<SecretEnvelope>;
|
|
69
|
+
|
|
70
|
+
export { ALG_ENC, ALG_HYBRID, ALG_WRAP, type PublishedKey, type SecretEnvelope, base64UrlDecode, base64UrlEncode, encryptSecret, fetchEncryptionKey };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@cocoar/secrets` — encrypt a secret for **Cocoar.Configuration** so the server stores only an
|
|
3
|
+
* encrypted envelope and never sees the plaintext.
|
|
4
|
+
*
|
|
5
|
+
* Hybrid encryption matching the server's decryption contract: a one-time **AES-256-GCM** data key
|
|
6
|
+
* seals the value, and that key is wrapped with the server's **RSA-OAEP-SHA256** public key. Runs
|
|
7
|
+
* anywhere WebCrypto is available — browsers and Node 18+ (`globalThis.crypto.subtle`).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const key = await fetchEncryptionKey("/.well-known/cocoar/encryption-key");
|
|
12
|
+
* const envelope = await encryptSecret(key, "my-oauth-client-secret");
|
|
13
|
+
* await fetch("/admin/config/oauth-secret", { method: "POST", body: JSON.stringify(envelope) });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
/** Overall hybrid scheme identifier (envelope `alg`). */
|
|
17
|
+
declare const ALG_HYBRID = "RSA-OAEP-AES256-GCM";
|
|
18
|
+
/** Key-wrapping algorithm identifier (envelope `walg`). */
|
|
19
|
+
declare const ALG_WRAP = "RSA-OAEP-256";
|
|
20
|
+
/** Data-encryption algorithm identifier (published key `enc`). */
|
|
21
|
+
declare const ALG_ENC = "AES-256-GCM";
|
|
22
|
+
/** The public-key document the server publishes at `/.well-known/cocoar/encryption-key`. */
|
|
23
|
+
interface PublishedKey {
|
|
24
|
+
/** Key id (single-tenant: the configured kid; multi-tenant: the tenant id). */
|
|
25
|
+
kid: string;
|
|
26
|
+
/** Overall scheme — `"RSA-OAEP-AES256-GCM"`. */
|
|
27
|
+
alg: string;
|
|
28
|
+
/** Key-wrap algorithm — `"RSA-OAEP-256"`. */
|
|
29
|
+
walg: string;
|
|
30
|
+
/** Data-encryption algorithm — `"AES-256-GCM"`. */
|
|
31
|
+
enc: string;
|
|
32
|
+
/** Public-key structure — `"spki"` (X.509 SubjectPublicKeyInfo, DER). */
|
|
33
|
+
format: string;
|
|
34
|
+
/** Encoding of {@link publicKey} — `"base64url"` (no padding). */
|
|
35
|
+
encoding: string;
|
|
36
|
+
/** The RSA public key: DER SubjectPublicKeyInfo, base64url-encoded without padding. */
|
|
37
|
+
publicKey: string;
|
|
38
|
+
}
|
|
39
|
+
/** The encrypted envelope the server accepts (`cocoar.secret`, version 1). */
|
|
40
|
+
interface SecretEnvelope {
|
|
41
|
+
type: "cocoar.secret";
|
|
42
|
+
version: 1;
|
|
43
|
+
kid: string;
|
|
44
|
+
alg: string;
|
|
45
|
+
/** base64url: the AES key wrapped with RSA-OAEP-SHA256. */
|
|
46
|
+
wk: string;
|
|
47
|
+
walg: string;
|
|
48
|
+
/** base64url: the 96-bit AES-GCM IV. */
|
|
49
|
+
iv: string;
|
|
50
|
+
/** base64url: the ciphertext. */
|
|
51
|
+
ct: string;
|
|
52
|
+
/** base64url: the 128-bit GCM authentication tag. */
|
|
53
|
+
tag: string;
|
|
54
|
+
}
|
|
55
|
+
/** Encode bytes as base64url **without** padding (the wire format Cocoar expects). */
|
|
56
|
+
declare function base64UrlEncode(bytes: Uint8Array): string;
|
|
57
|
+
/** Decode base64url (with or without padding) into bytes. */
|
|
58
|
+
declare function base64UrlDecode(value: string): Uint8Array;
|
|
59
|
+
/** Fetch the server's published public key from the given URL. */
|
|
60
|
+
declare function fetchEncryptionKey(url: string, init?: RequestInit): Promise<PublishedKey>;
|
|
61
|
+
/**
|
|
62
|
+
* Encrypt a value into a Cocoar secret envelope using the server's published public key.
|
|
63
|
+
*
|
|
64
|
+
* The value is JSON-serialized first (a string becomes a quoted JSON string, matching the server's
|
|
65
|
+
* `JsonSerializer` round-trip), then sealed with a one-time AES-256-GCM key that is wrapped with the
|
|
66
|
+
* server's RSA-OAEP-SHA256 public key. The plaintext never leaves the caller in clear form.
|
|
67
|
+
*/
|
|
68
|
+
declare function encryptSecret(key: PublishedKey, value: unknown): Promise<SecretEnvelope>;
|
|
69
|
+
|
|
70
|
+
export { ALG_ENC, ALG_HYBRID, ALG_WRAP, type PublishedKey, type SecretEnvelope, base64UrlDecode, base64UrlEncode, encryptSecret, fetchEncryptionKey };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var ALG_HYBRID = "RSA-OAEP-AES256-GCM";
|
|
3
|
+
var ALG_WRAP = "RSA-OAEP-256";
|
|
4
|
+
var ALG_ENC = "AES-256-GCM";
|
|
5
|
+
function subtle() {
|
|
6
|
+
const c = globalThis.crypto;
|
|
7
|
+
if (!c?.subtle) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
"WebCrypto is unavailable. Use a browser or Node 18+ where globalThis.crypto.subtle exists."
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
return c.subtle;
|
|
13
|
+
}
|
|
14
|
+
function base64UrlEncode(bytes) {
|
|
15
|
+
let binary = "";
|
|
16
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
17
|
+
binary += String.fromCharCode(bytes[i]);
|
|
18
|
+
}
|
|
19
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
20
|
+
}
|
|
21
|
+
function base64UrlDecode(value) {
|
|
22
|
+
const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
23
|
+
const padded = normalized + "=".repeat((4 - normalized.length % 4) % 4);
|
|
24
|
+
const binary = atob(padded);
|
|
25
|
+
const out = new Uint8Array(binary.length);
|
|
26
|
+
for (let i = 0; i < binary.length; i++) {
|
|
27
|
+
out[i] = binary.charCodeAt(i);
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
function assertSupported(key) {
|
|
32
|
+
if (key.format !== "spki") {
|
|
33
|
+
throw new Error(`Unsupported public-key format '${key.format}' (expected 'spki').`);
|
|
34
|
+
}
|
|
35
|
+
if (key.encoding !== "base64url") {
|
|
36
|
+
throw new Error(`Unsupported public-key encoding '${key.encoding}' (expected 'base64url').`);
|
|
37
|
+
}
|
|
38
|
+
if (key.walg !== ALG_WRAP) {
|
|
39
|
+
throw new Error(`Unsupported key-wrap algorithm '${key.walg}' (expected '${ALG_WRAP}').`);
|
|
40
|
+
}
|
|
41
|
+
if (key.enc !== ALG_ENC) {
|
|
42
|
+
throw new Error(`Unsupported data-encryption algorithm '${key.enc}' (expected '${ALG_ENC}').`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function fetchEncryptionKey(url, init) {
|
|
46
|
+
const res = await fetch(url, init);
|
|
47
|
+
if (!res.ok) {
|
|
48
|
+
throw new Error(`Failed to fetch encryption key from ${url}: HTTP ${res.status}.`);
|
|
49
|
+
}
|
|
50
|
+
return await res.json();
|
|
51
|
+
}
|
|
52
|
+
async function encryptSecret(key, value) {
|
|
53
|
+
assertSupported(key);
|
|
54
|
+
const crypto = subtle();
|
|
55
|
+
const plaintext = new TextEncoder().encode(JSON.stringify(value));
|
|
56
|
+
const dek = globalThis.crypto.getRandomValues(new Uint8Array(32));
|
|
57
|
+
const iv = globalThis.crypto.getRandomValues(new Uint8Array(12));
|
|
58
|
+
const aesKey = await crypto.importKey("raw", dek, { name: "AES-GCM" }, false, ["encrypt"]);
|
|
59
|
+
const sealed = new Uint8Array(
|
|
60
|
+
await crypto.encrypt({ name: "AES-GCM", iv, tagLength: 128 }, aesKey, plaintext)
|
|
61
|
+
);
|
|
62
|
+
const ct = sealed.slice(0, sealed.length - 16);
|
|
63
|
+
const tag = sealed.slice(sealed.length - 16);
|
|
64
|
+
const rsaPublicKey = await crypto.importKey(
|
|
65
|
+
"spki",
|
|
66
|
+
base64UrlDecode(key.publicKey),
|
|
67
|
+
{ name: "RSA-OAEP", hash: "SHA-256" },
|
|
68
|
+
false,
|
|
69
|
+
["encrypt"]
|
|
70
|
+
);
|
|
71
|
+
const wrappedKey = new Uint8Array(await crypto.encrypt({ name: "RSA-OAEP" }, rsaPublicKey, dek));
|
|
72
|
+
dek.fill(0);
|
|
73
|
+
return {
|
|
74
|
+
type: "cocoar.secret",
|
|
75
|
+
version: 1,
|
|
76
|
+
kid: key.kid,
|
|
77
|
+
alg: ALG_HYBRID,
|
|
78
|
+
wk: base64UrlEncode(wrappedKey),
|
|
79
|
+
walg: ALG_WRAP,
|
|
80
|
+
iv: base64UrlEncode(iv),
|
|
81
|
+
ct: base64UrlEncode(ct),
|
|
82
|
+
tag: base64UrlEncode(tag)
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export {
|
|
86
|
+
ALG_ENC,
|
|
87
|
+
ALG_HYBRID,
|
|
88
|
+
ALG_WRAP,
|
|
89
|
+
base64UrlDecode,
|
|
90
|
+
base64UrlEncode,
|
|
91
|
+
encryptSecret,
|
|
92
|
+
fetchEncryptionKey
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@cocoar/secrets` — encrypt a secret for **Cocoar.Configuration** so the server stores only an\n * encrypted envelope and never sees the plaintext.\n *\n * Hybrid encryption matching the server's decryption contract: a one-time **AES-256-GCM** data key\n * seals the value, and that key is wrapped with the server's **RSA-OAEP-SHA256** public key. Runs\n * anywhere WebCrypto is available — browsers and Node 18+ (`globalThis.crypto.subtle`).\n *\n * @example\n * ```ts\n * const key = await fetchEncryptionKey(\"/.well-known/cocoar/encryption-key\");\n * const envelope = await encryptSecret(key, \"my-oauth-client-secret\");\n * await fetch(\"/admin/config/oauth-secret\", { method: \"POST\", body: JSON.stringify(envelope) });\n * ```\n */\n\n/** Overall hybrid scheme identifier (envelope `alg`). */\nexport const ALG_HYBRID = \"RSA-OAEP-AES256-GCM\";\n/** Key-wrapping algorithm identifier (envelope `walg`). */\nexport const ALG_WRAP = \"RSA-OAEP-256\";\n/** Data-encryption algorithm identifier (published key `enc`). */\nexport const ALG_ENC = \"AES-256-GCM\";\n\n/** The public-key document the server publishes at `/.well-known/cocoar/encryption-key`. */\nexport interface PublishedKey {\n /** Key id (single-tenant: the configured kid; multi-tenant: the tenant id). */\n kid: string;\n /** Overall scheme — `\"RSA-OAEP-AES256-GCM\"`. */\n alg: string;\n /** Key-wrap algorithm — `\"RSA-OAEP-256\"`. */\n walg: string;\n /** Data-encryption algorithm — `\"AES-256-GCM\"`. */\n enc: string;\n /** Public-key structure — `\"spki\"` (X.509 SubjectPublicKeyInfo, DER). */\n format: string;\n /** Encoding of {@link publicKey} — `\"base64url\"` (no padding). */\n encoding: string;\n /** The RSA public key: DER SubjectPublicKeyInfo, base64url-encoded without padding. */\n publicKey: string;\n}\n\n/** The encrypted envelope the server accepts (`cocoar.secret`, version 1). */\nexport interface SecretEnvelope {\n type: \"cocoar.secret\";\n version: 1;\n kid: string;\n alg: string;\n /** base64url: the AES key wrapped with RSA-OAEP-SHA256. */\n wk: string;\n walg: string;\n /** base64url: the 96-bit AES-GCM IV. */\n iv: string;\n /** base64url: the ciphertext. */\n ct: string;\n /** base64url: the 128-bit GCM authentication tag. */\n tag: string;\n}\n\nfunction subtle(): SubtleCrypto {\n const c = (globalThis as { crypto?: Crypto }).crypto;\n if (!c?.subtle) {\n throw new Error(\n \"WebCrypto is unavailable. Use a browser or Node 18+ where globalThis.crypto.subtle exists.\",\n );\n }\n return c.subtle;\n}\n\n/** Encode bytes as base64url **without** padding (the wire format Cocoar expects). */\nexport function base64UrlEncode(bytes: Uint8Array): string {\n let binary = \"\";\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]!);\n }\n return btoa(binary).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\n\n/** Decode base64url (with or without padding) into bytes. */\nexport function base64UrlDecode(value: string): Uint8Array {\n const normalized = value.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padded = normalized + \"=\".repeat((4 - (normalized.length % 4)) % 4);\n const binary = atob(padded);\n const out = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n out[i] = binary.charCodeAt(i);\n }\n return out;\n}\n\nfunction assertSupported(key: PublishedKey): void {\n if (key.format !== \"spki\") {\n throw new Error(`Unsupported public-key format '${key.format}' (expected 'spki').`);\n }\n if (key.encoding !== \"base64url\") {\n throw new Error(`Unsupported public-key encoding '${key.encoding}' (expected 'base64url').`);\n }\n if (key.walg !== ALG_WRAP) {\n throw new Error(`Unsupported key-wrap algorithm '${key.walg}' (expected '${ALG_WRAP}').`);\n }\n if (key.enc !== ALG_ENC) {\n throw new Error(`Unsupported data-encryption algorithm '${key.enc}' (expected '${ALG_ENC}').`);\n }\n}\n\n/** Fetch the server's published public key from the given URL. */\nexport async function fetchEncryptionKey(url: string, init?: RequestInit): Promise<PublishedKey> {\n const res = await fetch(url, init);\n if (!res.ok) {\n throw new Error(`Failed to fetch encryption key from ${url}: HTTP ${res.status}.`);\n }\n return (await res.json()) as PublishedKey;\n}\n\n/**\n * Encrypt a value into a Cocoar secret envelope using the server's published public key.\n *\n * The value is JSON-serialized first (a string becomes a quoted JSON string, matching the server's\n * `JsonSerializer` round-trip), then sealed with a one-time AES-256-GCM key that is wrapped with the\n * server's RSA-OAEP-SHA256 public key. The plaintext never leaves the caller in clear form.\n */\nexport async function encryptSecret(key: PublishedKey, value: unknown): Promise<SecretEnvelope> {\n assertSupported(key);\n const crypto = subtle();\n\n const plaintext = new TextEncoder().encode(JSON.stringify(value));\n\n // One-time AES-256-GCM data-encryption key + 96-bit IV.\n const dek = globalThis.crypto.getRandomValues(new Uint8Array(32));\n const iv = globalThis.crypto.getRandomValues(new Uint8Array(12));\n const aesKey = await crypto.importKey(\"raw\", dek, { name: \"AES-GCM\" }, false, [\"encrypt\"]);\n const sealed = new Uint8Array(\n await crypto.encrypt({ name: \"AES-GCM\", iv, tagLength: 128 }, aesKey, plaintext),\n );\n\n // WebCrypto returns ciphertext || tag concatenated; the server expects them as separate fields.\n const ct = sealed.slice(0, sealed.length - 16);\n const tag = sealed.slice(sealed.length - 16);\n\n // Wrap the AES key with the server's RSA-OAEP-SHA256 public key. (Cast to BufferSource: TS 5.7+ types a\n // bare Uint8Array as Uint8Array<ArrayBufferLike>, which WebCrypto's BufferSource doesn't accept — the public\n // base64UrlDecode return type stays a plain Uint8Array so older-TS consumers aren't forced onto the generic.)\n const rsaPublicKey = await crypto.importKey(\n \"spki\",\n base64UrlDecode(key.publicKey) as BufferSource,\n { name: \"RSA-OAEP\", hash: \"SHA-256\" },\n false,\n [\"encrypt\"],\n );\n const wrappedKey = new Uint8Array(await crypto.encrypt({ name: \"RSA-OAEP\" }, rsaPublicKey, dek));\n\n // Best-effort: drop the plaintext key bytes once wrapped.\n dek.fill(0);\n\n return {\n type: \"cocoar.secret\",\n version: 1,\n kid: key.kid,\n alg: ALG_HYBRID,\n wk: base64UrlEncode(wrappedKey),\n walg: ALG_WRAP,\n iv: base64UrlEncode(iv),\n ct: base64UrlEncode(ct),\n tag: base64UrlEncode(tag),\n };\n}\n"],"mappings":";AAiBO,IAAM,aAAa;AAEnB,IAAM,WAAW;AAEjB,IAAM,UAAU;AAqCvB,SAAS,SAAuB;AAC9B,QAAM,IAAK,WAAmC;AAC9C,MAAI,CAAC,GAAG,QAAQ;AACd,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO,EAAE;AACX;AAGO,SAAS,gBAAgB,OAA2B;AACzD,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,cAAU,OAAO,aAAa,MAAM,CAAC,CAAE;AAAA,EACzC;AACA,SAAO,KAAK,MAAM,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,EA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,IAAI,WAAW,EAAE,CAAC;AAChE,QAAM,KAAK,WAAW,OAAO,gBAAgB,IAAI,WAAW,EAAE,CAAC;AAC/D,QAAM,SAAS,MAAM,OAAO,UAAU,OAAO,KAAK,EAAE,MAAM,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;AACzF,QAAM,SAAS,IAAI;AAAA,IACjB,MAAM,OAAO,QAAQ,EAAE,MAAM,WAAW,IAAI,WAAW,IAAI,GAAG,QAAQ,SAAS;AAAA,EACjF;AAGA,QAAM,KAAK,OAAO,MAAM,GAAG,OAAO,SAAS,EAAE;AAC7C,QAAM,MAAM,OAAO,MAAM,OAAO,SAAS,EAAE;AAK3C,QAAM,eAAe,MAAM,OAAO;AAAA,IAChC;AAAA,IACA,gBAAgB,IAAI,SAAS;AAAA,IAC7B,EAAE,MAAM,YAAY,MAAM,UAAU;AAAA,IACpC;AAAA,IACA,CAAC,SAAS;AAAA,EACZ;AACA,QAAM,aAAa,IAAI,WAAW,MAAM,OAAO,QAAQ,EAAE,MAAM,WAAW,GAAG,cAAc,GAAG,CAAC;AAG/F,MAAI,KAAK,CAAC;AAEV,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,KAAK,IAAI;AAAA,IACT,KAAK;AAAA,IACL,IAAI,gBAAgB,UAAU;AAAA,IAC9B,MAAM;AAAA,IACN,IAAI,gBAAgB,EAAE;AAAA,IACtB,IAAI,gBAAgB,EAAE;AAAA,IACtB,KAAK,gBAAgB,GAAG;AAAA,EAC1B;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocoar/secrets",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "6.2.0-beta.15",
|
|
4
|
+
"description": "Encrypt secrets for Cocoar.Configuration in the browser or Node — the server stores only an encrypted envelope and never sees the plaintext.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"require": "./dist/index.cjs"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist/"
|
|
17
|
+
],
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"keywords": [
|
|
20
|
+
"cocoar",
|
|
21
|
+
"configuration",
|
|
22
|
+
"secrets",
|
|
23
|
+
"encryption",
|
|
24
|
+
"rsa-oaep",
|
|
25
|
+
"aes-gcm",
|
|
26
|
+
"webcrypto"
|
|
27
|
+
],
|
|
28
|
+
"author": "Bernhard Windisch",
|
|
29
|
+
"license": "Apache-2.0",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/cocoar-dev/cocoar.configuration.git",
|
|
33
|
+
"directory": "src/ts/secrets"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://docs.cocoar.dev/configuration/",
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"tsup": "^8.0.0",
|
|
38
|
+
"typescript": "^5.7.0",
|
|
39
|
+
"vitest": "^4.1.0"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"gitHead": "1e70e701679f1a8b5d9d0fd2d472e9f72871ea5c",
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsup",
|
|
47
|
+
"dev": "tsup --watch",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"test:watch": "vitest",
|
|
50
|
+
"gen:fixtures": "node scripts/gen-crosslang-fixtures.mjs"
|
|
51
|
+
}
|
|
6
52
|
}
|