@shieldfive/crypto 1.0.0-rc.2 → 1.0.0-rc.4
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/CHANGELOG.md +18 -0
- package/dist/format/signature-tail.d.ts +54 -0
- package/dist/format/signature-tail.d.ts.map +1 -0
- package/dist/format/signature-tail.js +82 -0
- package/dist/format/signature-tail.js.map +1 -0
- package/dist/identity/inbound.d.ts +35 -0
- package/dist/identity/inbound.d.ts.map +1 -1
- package/dist/identity/inbound.js +71 -1
- package/dist/identity/inbound.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/types.d.ts +1 -0
- package/dist/internal/types.d.ts.map +1 -1
- package/dist/internal/types.js +3 -0
- package/dist/internal/types.js.map +1 -1
- package/dist/migration/v0-bridge.d.ts +22 -2
- package/dist/migration/v0-bridge.d.ts.map +1 -1
- package/dist/migration/v0-bridge.js.map +1 -1
- package/dist/streams/aes-gcm-v1.d.ts +3 -37
- package/dist/streams/aes-gcm-v1.d.ts.map +1 -1
- package/dist/streams/aes-gcm-v1.js +8 -64
- package/dist/streams/aes-gcm-v1.js.map +1 -1
- package/dist/suites/aes-gcm-v1/api.d.ts +18 -0
- package/dist/suites/aes-gcm-v1/api.d.ts.map +1 -1
- package/dist/suites/aes-gcm-v1/api.js +23 -5
- package/dist/suites/aes-gcm-v1/api.js.map +1 -1
- package/dist/suites/aes-gcm-v1/index.d.ts.map +1 -1
- package/dist/suites/aes-gcm-v1/index.js +11 -0
- package/dist/suites/aes-gcm-v1/index.js.map +1 -1
- package/dist/suites/aes-gcm-v2/api.d.ts +17 -0
- package/dist/suites/aes-gcm-v2/api.d.ts.map +1 -1
- package/dist/suites/aes-gcm-v2/api.js +19 -3
- package/dist/suites/aes-gcm-v2/api.js.map +1 -1
- package/dist/suites/aes-gcm-v2/index.d.ts.map +1 -1
- package/dist/suites/aes-gcm-v2/index.js +7 -0
- package/dist/suites/aes-gcm-v2/index.js.map +1 -1
- package/dist/suites/pq-hybrid-v1/api.d.ts +17 -0
- package/dist/suites/pq-hybrid-v1/api.d.ts.map +1 -1
- package/dist/suites/pq-hybrid-v1/api.js +19 -3
- package/dist/suites/pq-hybrid-v1/api.js.map +1 -1
- package/dist/suites/xchacha-v1/api.d.ts +17 -0
- package/dist/suites/xchacha-v1/api.d.ts.map +1 -1
- package/dist/suites/xchacha-v1/api.js +19 -3
- package/dist/suites/xchacha-v1/api.js.map +1 -1
- package/dist/suites/xchacha-v1/index.d.ts.map +1 -1
- package/dist/suites/xchacha-v1/index.js +8 -0
- package/dist/suites/xchacha-v1/index.js.map +1 -1
- package/package.json +1 -1
- package/spec/key-derivation.md +19 -5
- package/src/format/signature-tail.ts +114 -0
- package/src/identity/inbound.ts +118 -1
- package/src/index.ts +1 -1
- package/src/internal/types.ts +3 -0
- package/src/migration/v0-bridge.ts +22 -2
- package/src/streams/aes-gcm-v1.ts +17 -91
- package/src/suites/aes-gcm-v1/api.ts +46 -5
- package/src/suites/aes-gcm-v1/index.ts +11 -0
- package/src/suites/aes-gcm-v2/api.ts +41 -3
- package/src/suites/aes-gcm-v2/index.ts +7 -0
- package/src/suites/pq-hybrid-v1/api.ts +41 -3
- package/src/suites/xchacha-v1/api.ts +41 -3
- package/src/suites/xchacha-v1/index.ts +8 -0
|
@@ -7,6 +7,8 @@ import { buildAuthenticatedHeader, parseHeader, verifyHeaderMac, HeaderError, }
|
|
|
7
7
|
import { XCHACHA_V1_SUITE_PAYLOAD_LENGTH, XCHACHA_V1_TAG_BYTES, createChunkContext, decryptChunk, encryptChunk, generateContentMaterial, parseXChaChaV1SuitePayload, } from './index.js';
|
|
8
8
|
import { DEFAULT_CHUNK_SIZE, HEADER_SIZES, MAX_TOTAL_CHUNKS, SUITE, } from '../../internal/types.js';
|
|
9
9
|
import { asBlobPart, readUint32BE, uint32BE, } from '../../internal/encoding.js';
|
|
10
|
+
import { SenderSigTranscript } from '../../identity/sign.js';
|
|
11
|
+
import { finalizeSignatureMetadata, } from '../../format/signature-tail.js';
|
|
10
12
|
const LENGTH_PREFIX_BYTES = 4;
|
|
11
13
|
export async function encryptBlob(options) {
|
|
12
14
|
const { blob, onProgress } = options;
|
|
@@ -104,6 +106,11 @@ export async function decryptBlob(options) {
|
|
|
104
106
|
await verifyHeaderMac(parsed, contentKey);
|
|
105
107
|
parseXChaChaV1SuitePayload(parsed.suitePayload);
|
|
106
108
|
const ctx = await createChunkContext(contentKey, parsed.fileId, parsed.totalChunks);
|
|
109
|
+
// Rebuild the sender-attribution transcript only when verifying, so an
|
|
110
|
+
// unsigned decrypt pays nothing for the extra hash over ciphertext.
|
|
111
|
+
const expectedSignerPublicKey = options.expectedSignerPublicKey;
|
|
112
|
+
const transcript = expectedSignerPublicKey ? new SenderSigTranscript() : null;
|
|
113
|
+
transcript?.absorbHeader(parsed.unauthenticatedBytes, parsed.totalChunks);
|
|
107
114
|
const plaintextParts = [];
|
|
108
115
|
let cursor = parsed.headerLength;
|
|
109
116
|
let bytesEmitted = 0;
|
|
@@ -131,14 +138,23 @@ export async function decryptBlob(options) {
|
|
|
131
138
|
const plaintext = await decryptChunk(ctx, i, cipherBytes);
|
|
132
139
|
bytesEmitted += plaintext.length;
|
|
133
140
|
plaintextParts.push(asBlobPart(plaintext));
|
|
141
|
+
transcript?.absorbChunk(i, cipherBytes);
|
|
134
142
|
onProgress?.((i + 1) / Math.max(parsed.totalChunks, 1));
|
|
135
143
|
}
|
|
136
144
|
if (bytesEmitted !== parsed.plaintextSize) {
|
|
137
145
|
throw new HeaderError('plaintext_size_mismatch');
|
|
138
146
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
147
|
+
// Trailing bytes are an optional signature block, not corruption; parse
|
|
148
|
+
// and surface it, rejecting only malformed trailing garbage.
|
|
149
|
+
const trailingBytes = cursor < blob.size
|
|
150
|
+
? new Uint8Array(await blob.slice(cursor).arrayBuffer())
|
|
151
|
+
: new Uint8Array(0);
|
|
152
|
+
const signature = finalizeSignatureMetadata({
|
|
153
|
+
trailingBytes,
|
|
154
|
+
transcriptDigest: transcript ? transcript.digest() : new Uint8Array(32),
|
|
155
|
+
expectedSignerPublicKey,
|
|
156
|
+
});
|
|
157
|
+
options.onSignature?.(signature);
|
|
142
158
|
if (parsed.totalChunks === 0)
|
|
143
159
|
onProgress?.(1);
|
|
144
160
|
return new Blob(plaintextParts, { type: 'application/octet-stream' });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/suites/xchacha-v1/api.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,wBAAwB,EACxB,WAAW,EACX,eAAe,EACf,WAAW,GACZ,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,+BAA+B,EAC/B,oBAAoB,EACpB,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,kBAAkB,EAElB,YAAY,EACZ,gBAAgB,EAEhB,KAAK,GACN,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,UAAU,EACV,YAAY,EACZ,QAAQ,GACT,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/suites/xchacha-v1/api.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,wBAAwB,EACxB,WAAW,EACX,eAAe,EACf,WAAW,GACZ,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,+BAA+B,EAC/B,oBAAoB,EACpB,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,kBAAkB,EAElB,YAAY,EACZ,gBAAgB,EAEhB,KAAK,GACN,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,UAAU,EACV,YAAY,EACZ,QAAQ,G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,EAAE,CAAC,CAAA;AACvE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,KAA+B,EAC/B,OAAqC;IAErC,MAAM,IAAI,GACR,KAAK,YAAY,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;IAC1D,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;IAC7B,OAAO,WAAW,CAAC,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;AAC1C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAuB;IAEvB,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,CAAA;IACvC,OAAO,IAAI,UAAU,CAAC,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC,CAAA;AACjD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/suites/xchacha-v1/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,yBAAyB,CAAA;AAMhC,eAAO,MAAM,oBAAoB,KAAK,CAAA;AACtC,eAAO,MAAM,sBAAsB,KAAK,CAAA;AACxC,eAAO,MAAM,oBAAoB,KAAK,CAAA;AAEtC,sFAAsF;AACtF,eAAO,MAAM,+BAA+B,KAAK,CAAA;AAEjD,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,UAAU,CAAA;IACtB,SAAS,EAAE,UAAU,CAAA;CACtB;AAED,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,qBAAqB,GAC7B,UAAU,CAQZ;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,UAAU,GAChB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/suites/xchacha-v1/index.ts"],"names":[],"mapp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AAE,OAAO,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,UAAU,CAAA;CAAE,CAAC,CAuB1D;AAED,wBAAsB,gBAAgB,CAAC,OAAO,EAAE;IAC9C,WAAW,EAAE,UAAU,CAAA;IACvB,YAAY,EAAE,UAAU,CAAA;IACxB,SAAS,EAAE,UAAU,CAAA;CACtB,GAAG,OAAO,CAAC,UAAU,CAAC,CAuBtB;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,YAAY,GACnB,qBAAqB,CAEvB"}
|
|
@@ -34,6 +34,14 @@ export function parseXChaChaV1SuitePayload(bytes) {
|
|
|
34
34
|
if (bytes.length !== XCHACHA_V1_SUITE_PAYLOAD_LENGTH) {
|
|
35
35
|
throw new RangeError('xchacha-v1: suite payload must be 96 bytes');
|
|
36
36
|
}
|
|
37
|
+
// The 48-byte secretbox wrap (32-byte key + 16-byte tag) is zero-padded to
|
|
38
|
+
// 72 bytes; the reserved pad (bytes 48..72) MUST be all zero — same
|
|
39
|
+
// invariant suite 0x03 enforces (M6). See parseAesGcmV1SuitePayload.
|
|
40
|
+
for (let i = 48; i < 72; i += 1) {
|
|
41
|
+
if (bytes[i] !== 0) {
|
|
42
|
+
throw new RangeError('xchacha-v1: reserved wrapped_key pad must be zero');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
37
45
|
return {
|
|
38
46
|
wrappedKey: bytes.slice(0, 72),
|
|
39
47
|
wrapNonce: bytes.slice(72, 96),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/suites/xchacha-v1/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACtD,OAAO,EACL,SAAS,EACT,YAAY,GAEb,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,UAAU,EA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AChC,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,OAAO,CAAA;IACxD,IAAI,WAAW,CAAC,MAAM,KAAK,oBAAoB,EAAE,CAAC;QAChD,MAAM,IAAI,UAAU,CAAC,gDAAgD,CAAC,CAAA;IACxE,CAAC;IACD,IAAI,YAAY,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QAC/B,MAAM,IAAI,UAAU,CAAC,iDAAiD,CAAC,CAAA;IACzE,CAAC;IACD,IAAI,SAAS,CAAC,MAAM,KAAK,sBAAsB,EAAE,CAAC;QAChD,MAAM,IAAI,UAAU,CAAC,8CAA8C,CAAC,CAAA;IACtE,CAAC;IACD,0DAA0D;IAC1D,MAAM,OAAO,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IACzC,MAAM,SAAS,GAAG,MAAM,CAAC,0BAA0B,CACjD,OAAO,EACP,SAAS,EACT,WAAW,CACZ,CAAA;IACD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAA;IAC1E,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,MAAoB;IAEpB,OAAO,0BAA0B,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;AACxD,CAAC"}
|
package/package.json
CHANGED
package/spec/key-derivation.md
CHANGED
|
@@ -145,9 +145,20 @@ shieldfive/v1/xchacha/nonce-prefix
|
|
|
145
145
|
shieldfive/v1/pq-hybrid/combine
|
|
146
146
|
shieldfive/v1/pq-hybrid/ml-kem-1024-seed
|
|
147
147
|
shieldfive/v1/share-transport
|
|
148
|
+
shieldfive/v1/inbound/x25519-static-seed
|
|
149
|
+
shieldfive/v1/inbound/envelope-key
|
|
150
|
+
shieldfive/v1/inbound/ed25519-signing-seed
|
|
148
151
|
shieldfive/v1/argon2id/salt-compression
|
|
149
152
|
```
|
|
150
153
|
|
|
154
|
+
The three `shieldfive/v1/inbound/*` labels drive the zero-knowledge
|
|
155
|
+
inbound-intake path (`src/identity/inbound.ts`). Two are derived directly
|
|
156
|
+
from the account master secret — `ed25519-signing-seed` yields the firm's
|
|
157
|
+
inbound signing seed and `x25519-static-seed` its static X25519 secret —
|
|
158
|
+
so a host that reuses either label against the master secret would
|
|
159
|
+
recompute identity-grade key material. They are forbidden for the same
|
|
160
|
+
reason as every other entry.
|
|
161
|
+
|
|
151
162
|
### Reserved for future use
|
|
152
163
|
|
|
153
164
|
These strings are reserved by this specification but are NOT yet
|
|
@@ -160,11 +171,14 @@ shieldfive/v1/envelope-key
|
|
|
160
171
|
shieldfive/v1/metadata-key
|
|
161
172
|
```
|
|
162
173
|
|
|
163
|
-
Interpretation note: the
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
174
|
+
Interpretation note: the "Forbidden cross-context usage" list above is
|
|
175
|
+
kept in one-to-one correspondence with the consumed entries of
|
|
176
|
+
`HKDF_INFO` in `src/internal/types.ts` — every string the library derives
|
|
177
|
+
with today appears there (this is asserted by a unit test so the two
|
|
178
|
+
cannot drift). The two entries in this "Reserved for future use" block
|
|
179
|
+
are spec-only reservations that `HKDF_INFO` does NOT yet contain, kept
|
|
180
|
+
separate so the cross-check stays exact with no phantom entries in either
|
|
181
|
+
direction.
|
|
168
182
|
|
|
169
183
|
If the host application needs a new derived key, it MUST use a fresh
|
|
170
184
|
domain string of the form `<application>/<version>/<purpose>` to ensure
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared trailing-signature-block handling for the v1 wire format.
|
|
3
|
+
*
|
|
4
|
+
* A v1 file MAY carry an optional trailing Ed25519 signature block after
|
|
5
|
+
* the last chunk (see `spec/format-v1.md § "Signature block"`). Both the
|
|
6
|
+
* streaming decoders and the whole-blob decryptors need identical
|
|
7
|
+
* semantics for that tail — parse it, reject malformed trailing garbage,
|
|
8
|
+
* and optionally verify it against a caller-pinned public key — so the
|
|
9
|
+
* logic lives here, in one place, rather than being duplicated (or, as
|
|
10
|
+
* happened before, implemented by the streams and silently omitted by the
|
|
11
|
+
* blob readers).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { HeaderError } from './header.js'
|
|
15
|
+
import {
|
|
16
|
+
parseSignatureBlock,
|
|
17
|
+
type SignatureBlock,
|
|
18
|
+
SignatureError,
|
|
19
|
+
SIGNATURE_ALGO_ED25519,
|
|
20
|
+
verifySenderTranscript,
|
|
21
|
+
} from '../identity/sign.js'
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Verified signature metadata surfaced by a v1 decryptor.
|
|
25
|
+
*
|
|
26
|
+
* - `algorithm`, `publicKey`, `signature` come from the parsed block.
|
|
27
|
+
* - `verified` is `true` if the caller passed `expectedSignerPublicKey`
|
|
28
|
+
* AND it matched the embedded pubkey AND the signature verifies; it
|
|
29
|
+
* is `false` if the check ran and failed; it is `null` if the caller
|
|
30
|
+
* passed no `expectedSignerPublicKey` (the application policy layer
|
|
31
|
+
* is expected to do its own verification using the surfaced bytes).
|
|
32
|
+
*/
|
|
33
|
+
export interface VerifiedSignature {
|
|
34
|
+
algorithm: number
|
|
35
|
+
publicKey: Uint8Array
|
|
36
|
+
signature: Uint8Array
|
|
37
|
+
verified: boolean | null
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface DecryptionMetadata {
|
|
41
|
+
/** Null when the file has no signature block (legacy / unsigned). */
|
|
42
|
+
signature: VerifiedSignature | null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Parse a trailing signature block (if any) from a decryptor's residual
|
|
47
|
+
* bytes, optionally verifying it against the caller's trusted public key.
|
|
48
|
+
*
|
|
49
|
+
* `transcriptDigest` is the {@link SenderSigTranscript} digest rebuilt
|
|
50
|
+
* over the header and every chunk's full ciphertext as it was decrypted,
|
|
51
|
+
* so `verified: true` means the signer signed exactly these bytes. It is
|
|
52
|
+
* only consulted when `expectedSignerPublicKey` is supplied.
|
|
53
|
+
*
|
|
54
|
+
* Returns `null` for a file with no trailing bytes (legacy / unsigned).
|
|
55
|
+
* Throws `HeaderError` if the trailing bytes are not a well-formed
|
|
56
|
+
* signature block or carry garbage after it — the spec's MUST-reject.
|
|
57
|
+
*
|
|
58
|
+
* Shared between the AES-GCM and PQ-hybrid stream decoders and every
|
|
59
|
+
* whole-blob decryptor so the signature semantics live in one place.
|
|
60
|
+
*/
|
|
61
|
+
export function finalizeSignatureMetadata(input: {
|
|
62
|
+
trailingBytes: Uint8Array
|
|
63
|
+
transcriptDigest: Uint8Array
|
|
64
|
+
expectedSignerPublicKey: Uint8Array | undefined
|
|
65
|
+
}): VerifiedSignature | null {
|
|
66
|
+
if (input.trailingBytes.length === 0) {
|
|
67
|
+
return null
|
|
68
|
+
}
|
|
69
|
+
let parsed: { block: SignatureBlock; consumed: number }
|
|
70
|
+
try {
|
|
71
|
+
parsed = parseSignatureBlock(input.trailingBytes, 0)
|
|
72
|
+
} catch (err) {
|
|
73
|
+
if (err instanceof SignatureError) {
|
|
74
|
+
throw new HeaderError(`signature_block_${err.code}`)
|
|
75
|
+
}
|
|
76
|
+
throw err
|
|
77
|
+
}
|
|
78
|
+
if (parsed.consumed !== input.trailingBytes.length) {
|
|
79
|
+
throw new HeaderError('trailing_bytes_after_signature_block')
|
|
80
|
+
}
|
|
81
|
+
const { algorithm, publicKey, signature } = parsed.block
|
|
82
|
+
|
|
83
|
+
let verified: boolean | null = null
|
|
84
|
+
if (input.expectedSignerPublicKey) {
|
|
85
|
+
if (algorithm !== SIGNATURE_ALGO_ED25519) {
|
|
86
|
+
// Unknown / unsupported algorithm: cannot verify with our
|
|
87
|
+
// Ed25519-only verifier; treat as a verification failure under
|
|
88
|
+
// the caller's policy (they asked us to verify, we couldn't).
|
|
89
|
+
verified = false
|
|
90
|
+
} else {
|
|
91
|
+
// Pubkey-pinning: if the embedded pubkey doesn't match the caller's
|
|
92
|
+
// expected one, fail without doing the (still-honest) Ed25519
|
|
93
|
+
// math. This keeps the "verified=true" contract tight: it means
|
|
94
|
+
// the file was signed by the key the caller expected.
|
|
95
|
+
verified =
|
|
96
|
+
bytesEqualConstantTime(publicKey, input.expectedSignerPublicKey) &&
|
|
97
|
+
verifySenderTranscript({
|
|
98
|
+
ed25519PublicKey: input.expectedSignerPublicKey,
|
|
99
|
+
transcriptDigest: input.transcriptDigest,
|
|
100
|
+
signature,
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return { algorithm, publicKey, signature, verified }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function bytesEqualConstantTime(a: Uint8Array, b: Uint8Array): boolean {
|
|
108
|
+
if (a.length !== b.length) return false
|
|
109
|
+
let diff = 0
|
|
110
|
+
for (let i = 0; i < a.length; i += 1) {
|
|
111
|
+
diff |= a[i]! ^ b[i]!
|
|
112
|
+
}
|
|
113
|
+
return diff === 0
|
|
114
|
+
}
|
package/src/identity/inbound.ts
CHANGED
|
@@ -28,8 +28,17 @@
|
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
import { x25519 } from '@noble/curves/ed25519.js'
|
|
31
|
+
import { sha256 } from '@noble/hashes/sha2.js'
|
|
31
32
|
|
|
32
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
deriveEd25519PublicKey,
|
|
35
|
+
ED25519_PUBLIC_KEY_LENGTH,
|
|
36
|
+
ED25519_SECRET_KEY_LENGTH,
|
|
37
|
+
ED25519_SIGNATURE_LENGTH,
|
|
38
|
+
signSenderTranscript,
|
|
39
|
+
verifySenderTranscript,
|
|
40
|
+
} from './sign.js'
|
|
41
|
+
import { concatBytes, uint32BE } from '../internal/encoding.js'
|
|
33
42
|
import { hkdfSha256 } from '../internal/hkdf.js'
|
|
34
43
|
import { randomBytes } from '../internal/runtime.js'
|
|
35
44
|
import { HEADER_SIZES, HKDF_INFO } from '../internal/types.js'
|
|
@@ -171,3 +180,111 @@ export async function openInboundEnvelopeKey(options: {
|
|
|
171
180
|
)
|
|
172
181
|
return { envelopeKey }
|
|
173
182
|
}
|
|
183
|
+
|
|
184
|
+
// ── Firm key-bundle signing ──────────────────────────────────────────────────
|
|
185
|
+
//
|
|
186
|
+
// The guest fetches the firm's ml_kem + x25519 public keys from a server it does
|
|
187
|
+
// not trust. To detect a swapped key, the firm signs its published key bundle
|
|
188
|
+
// with a long-lived Ed25519 identity key derived from the same master secret,
|
|
189
|
+
// and the guest verifies the signature against the firm's published signing key
|
|
190
|
+
// (whose fingerprint the firm communicates out of band). This raises the bar to
|
|
191
|
+
// a firm-key forgery; it does not defeat a server that also serves malicious
|
|
192
|
+
// verifying code (the honest-claim ceiling).
|
|
193
|
+
|
|
194
|
+
/** Ed25519 signing public key length (bytes). */
|
|
195
|
+
export const INBOUND_SIGNING_PUBLIC_KEY_LENGTH = ED25519_PUBLIC_KEY_LENGTH
|
|
196
|
+
/** Ed25519 key-bundle signature length (bytes). */
|
|
197
|
+
export const INBOUND_KEY_BUNDLE_SIGNATURE_LENGTH = ED25519_SIGNATURE_LENGTH
|
|
198
|
+
|
|
199
|
+
const INBOUND_KEY_BUNDLE_DOMAIN = new TextEncoder().encode(
|
|
200
|
+
'shieldfive/v1/inbound/key-bundle',
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
export interface InboundSigningKeypair {
|
|
204
|
+
/** Ed25519 public key (32 bytes) — publish so guests can verify the bundle. */
|
|
205
|
+
ed25519PublicKey: Uint8Array
|
|
206
|
+
/** Ed25519 secret seed (32 bytes) — treat as highly sensitive. */
|
|
207
|
+
ed25519SecretKey: Uint8Array
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Deterministically derive the firm's Ed25519 signing keypair from its master
|
|
212
|
+
* secret, mirroring the ML-KEM / X25519 derivations. Stable across devices.
|
|
213
|
+
*/
|
|
214
|
+
export async function deriveInboundSigningKeypair(
|
|
215
|
+
masterSecret: Uint8Array,
|
|
216
|
+
): Promise<InboundSigningKeypair> {
|
|
217
|
+
if (masterSecret.length < 16) {
|
|
218
|
+
throw new RangeError(
|
|
219
|
+
'deriveInboundSigningKeypair: masterSecret must be at least 16 bytes',
|
|
220
|
+
)
|
|
221
|
+
}
|
|
222
|
+
const seed = await hkdfSha256({
|
|
223
|
+
ikm: masterSecret,
|
|
224
|
+
info: HKDF_INFO.INBOUND_SIGNING_SEED,
|
|
225
|
+
length: ED25519_SECRET_KEY_LENGTH,
|
|
226
|
+
})
|
|
227
|
+
const ed25519PublicKey = deriveEd25519PublicKey(seed)
|
|
228
|
+
return { ed25519PublicKey, ed25519SecretKey: seed }
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Domain-separated, length-framed digest over the published key bundle. Framing
|
|
233
|
+
* the lengths prevents a (ml_kem, x25519) split from colliding with a different
|
|
234
|
+
* pairing.
|
|
235
|
+
*/
|
|
236
|
+
function inboundKeyBundleDigest(
|
|
237
|
+
mlKemPublicKey: Uint8Array,
|
|
238
|
+
x25519PublicKey: Uint8Array,
|
|
239
|
+
): Uint8Array {
|
|
240
|
+
return sha256(
|
|
241
|
+
concatBytes([
|
|
242
|
+
INBOUND_KEY_BUNDLE_DOMAIN,
|
|
243
|
+
uint32BE(mlKemPublicKey.length),
|
|
244
|
+
mlKemPublicKey,
|
|
245
|
+
uint32BE(x25519PublicKey.length),
|
|
246
|
+
x25519PublicKey,
|
|
247
|
+
]),
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Sign the firm's published (ml_kem || x25519) bundle with its Ed25519 signing
|
|
253
|
+
* secret. Returns a raw 64-byte signature to store next to the keys.
|
|
254
|
+
*/
|
|
255
|
+
export function signInboundKeyBundle(options: {
|
|
256
|
+
ed25519SecretKey: Uint8Array
|
|
257
|
+
mlKemPublicKey: Uint8Array
|
|
258
|
+
x25519PublicKey: Uint8Array
|
|
259
|
+
}): Uint8Array {
|
|
260
|
+
const digest = inboundKeyBundleDigest(
|
|
261
|
+
options.mlKemPublicKey,
|
|
262
|
+
options.x25519PublicKey,
|
|
263
|
+
)
|
|
264
|
+
return signSenderTranscript({
|
|
265
|
+
ed25519SecretKey: options.ed25519SecretKey,
|
|
266
|
+
transcriptDigest: digest,
|
|
267
|
+
})
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Guest side: verify a firm key-bundle signature. Returns false on any failure
|
|
272
|
+
* (never throws). The guest must additionally trust the signing public key via
|
|
273
|
+
* an out-of-band fingerprint.
|
|
274
|
+
*/
|
|
275
|
+
export function verifyInboundKeyBundle(options: {
|
|
276
|
+
ed25519PublicKey: Uint8Array
|
|
277
|
+
mlKemPublicKey: Uint8Array
|
|
278
|
+
x25519PublicKey: Uint8Array
|
|
279
|
+
signature: Uint8Array
|
|
280
|
+
}): boolean {
|
|
281
|
+
const digest = inboundKeyBundleDigest(
|
|
282
|
+
options.mlKemPublicKey,
|
|
283
|
+
options.x25519PublicKey,
|
|
284
|
+
)
|
|
285
|
+
return verifySenderTranscript({
|
|
286
|
+
ed25519PublicKey: options.ed25519PublicKey,
|
|
287
|
+
transcriptDigest: digest,
|
|
288
|
+
signature: options.signature,
|
|
289
|
+
})
|
|
290
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -219,7 +219,7 @@ export async function autoDecryptBlob(
|
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
/** Library version, also written into format documentation. */
|
|
222
|
-
export const SHIELDFIVE_CRYPTO_VERSION = '1.0.0-rc.
|
|
222
|
+
export const SHIELDFIVE_CRYPTO_VERSION = '1.0.0-rc.4'
|
|
223
223
|
|
|
224
224
|
/** Default cipher suite for new files when not specified by the caller. */
|
|
225
225
|
export const DEFAULT_SUITE = SUITE.PQ_HYBRID_XCHACHA_MLKEM1024_V1
|
package/src/internal/types.ts
CHANGED
|
@@ -102,6 +102,9 @@ export const HKDF_INFO = Object.freeze({
|
|
|
102
102
|
// nowhere else.
|
|
103
103
|
INBOUND_X25519_STATIC_SEED: 'shieldfive/v1/inbound/x25519-static-seed',
|
|
104
104
|
INBOUND_ENVELOPE: 'shieldfive/v1/inbound/envelope-key',
|
|
105
|
+
// Ed25519 identity signing key for inbound intake. The firm signs its
|
|
106
|
+
// published (ml_kem || x25519) bundle so a guest can detect a key swap.
|
|
107
|
+
INBOUND_SIGNING_SEED: 'shieldfive/v1/inbound/ed25519-signing-seed',
|
|
105
108
|
ARGON2ID_SALT_COMPRESSION: 'shieldfive/v1/argon2id/salt-compression',
|
|
106
109
|
})
|
|
107
110
|
|
|
@@ -52,9 +52,29 @@ export {
|
|
|
52
52
|
export interface V0EncryptOptions {
|
|
53
53
|
/** Plaintext blob. */
|
|
54
54
|
blob: Blob
|
|
55
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* 32-byte AES-256 content key. Must already be unwrapped.
|
|
57
|
+
*
|
|
58
|
+
* SECURITY: `contentKey` and `noncePrefix` together form this file's
|
|
59
|
+
* AES-GCM nonce namespace. Reusing the same (contentKey, noncePrefix)
|
|
60
|
+
* pair across two DIFFERENT plaintexts reuses every chunk's (key, IV)
|
|
61
|
+
* and is catastrophic — it reproduces the keystream (ct1 ^ ct2 = pt1 ^
|
|
62
|
+
* pt2, enabling plaintext recovery) and leaks the GHASH authentication
|
|
63
|
+
* key (enabling forgery). See the note on `noncePrefix`.
|
|
64
|
+
*/
|
|
56
65
|
contentKey: Uint8Array
|
|
57
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* 4-byte per-file nonce prefix. Generated fresh (random) when omitted —
|
|
68
|
+
* that is the safe default and requires no caller cooperation.
|
|
69
|
+
*
|
|
70
|
+
* SECURITY: if you persist and re-supply a prefix (which the returned
|
|
71
|
+
* {@link V0EncryptResult} explicitly invites you to do), you MUST use a
|
|
72
|
+
* FRESH prefix whenever you re-encrypt an edited file under the same
|
|
73
|
+
* `contentKey`. Re-encrypting different content under an unchanged
|
|
74
|
+
* (contentKey, noncePrefix) pair reuses the AES-GCM nonce and is
|
|
75
|
+
* catastrophic (see `contentKey`). This legacy v0 writer exists solely
|
|
76
|
+
* for the Phase-1 migration; new data must use a v1 suite instead.
|
|
77
|
+
*/
|
|
58
78
|
noncePrefix?: Uint8Array
|
|
59
79
|
/** Plaintext bytes per chunk. Production uses 5 MiB or 8 MiB. */
|
|
60
80
|
chunkSize: number
|
|
@@ -46,14 +46,20 @@ import {
|
|
|
46
46
|
buildSignatureBlock,
|
|
47
47
|
deriveEd25519PublicKey,
|
|
48
48
|
ED25519_SECRET_KEY_LENGTH,
|
|
49
|
-
parseSignatureBlock,
|
|
50
49
|
SenderSigTranscript,
|
|
51
50
|
SIGNATURE_ALGO_ED25519,
|
|
52
51
|
signSenderTranscript,
|
|
53
|
-
type SignatureBlock,
|
|
54
|
-
SignatureError,
|
|
55
|
-
verifySenderTranscript,
|
|
56
52
|
} from '../identity/sign.js'
|
|
53
|
+
import {
|
|
54
|
+
finalizeSignatureMetadata,
|
|
55
|
+
type DecryptionMetadata,
|
|
56
|
+
} from '../format/signature-tail.js'
|
|
57
|
+
|
|
58
|
+
// Re-exported so `streams/aes-gcm-v1.js` stays the import site these
|
|
59
|
+
// symbols have always had (the PQ-hybrid stream and public barrels
|
|
60
|
+
// import them from here).
|
|
61
|
+
export { finalizeSignatureMetadata }
|
|
62
|
+
export type { DecryptionMetadata, VerifiedSignature } from '../format/signature-tail.js'
|
|
57
63
|
|
|
58
64
|
const LENGTH_PREFIX_BYTES = 4
|
|
59
65
|
|
|
@@ -295,27 +301,11 @@ export interface AesGcmV1DecryptStreamOptions {
|
|
|
295
301
|
expectedSignerPublicKey?: Uint8Array
|
|
296
302
|
}
|
|
297
303
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
* AND it matched the embedded pubkey AND the signature verifies; it
|
|
304
|
-
* is `false` if the check ran and failed; it is `null` if the caller
|
|
305
|
-
* passed no `expectedSignerPublicKey` (the application policy layer
|
|
306
|
-
* is expected to do its own verification using the surfaced bytes).
|
|
307
|
-
*/
|
|
308
|
-
export interface VerifiedSignature {
|
|
309
|
-
algorithm: number
|
|
310
|
-
publicKey: Uint8Array
|
|
311
|
-
signature: Uint8Array
|
|
312
|
-
verified: boolean | null
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
export interface DecryptionMetadata {
|
|
316
|
-
/** Null when the file has no signature block (legacy / unsigned). */
|
|
317
|
-
signature: VerifiedSignature | null
|
|
318
|
-
}
|
|
304
|
+
// `VerifiedSignature` and `DecryptionMetadata` (and the shared
|
|
305
|
+
// `finalizeSignatureMetadata` helper) now live in
|
|
306
|
+
// `../format/signature-tail.js` so the whole-blob decryptors can reuse
|
|
307
|
+
// the exact same tail semantics. They are re-exported below so existing
|
|
308
|
+
// import paths (`streams/aes-gcm-v1.js`) keep working unchanged.
|
|
319
309
|
|
|
320
310
|
export interface AesGcmV1DecryptStreamResult {
|
|
321
311
|
stream: TransformStream<Uint8Array, Uint8Array>
|
|
@@ -598,69 +588,5 @@ export function decryptStreamAesGcmV1(
|
|
|
598
588
|
}
|
|
599
589
|
}
|
|
600
590
|
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
* residual buffer, optionally verifying it against the caller's
|
|
604
|
-
* trusted public key.
|
|
605
|
-
*
|
|
606
|
-
* `transcriptDigest` is the {@link SenderSigTranscript} digest rebuilt
|
|
607
|
-
* over the header and every chunk's full ciphertext as it was decrypted,
|
|
608
|
-
* so `verified: true` means the signer signed exactly these bytes.
|
|
609
|
-
*
|
|
610
|
-
* Shared between the AES-GCM and PQ-hybrid stream decoders so the
|
|
611
|
-
* signature semantics live in one place.
|
|
612
|
-
*/
|
|
613
|
-
export function finalizeSignatureMetadata(input: {
|
|
614
|
-
trailingBytes: Uint8Array
|
|
615
|
-
transcriptDigest: Uint8Array
|
|
616
|
-
expectedSignerPublicKey: Uint8Array | undefined
|
|
617
|
-
}): VerifiedSignature | null {
|
|
618
|
-
if (input.trailingBytes.length === 0) {
|
|
619
|
-
return null
|
|
620
|
-
}
|
|
621
|
-
let parsed: { block: SignatureBlock; consumed: number }
|
|
622
|
-
try {
|
|
623
|
-
parsed = parseSignatureBlock(input.trailingBytes, 0)
|
|
624
|
-
} catch (err) {
|
|
625
|
-
if (err instanceof SignatureError) {
|
|
626
|
-
throw new HeaderError(`signature_block_${err.code}`)
|
|
627
|
-
}
|
|
628
|
-
throw err
|
|
629
|
-
}
|
|
630
|
-
if (parsed.consumed !== input.trailingBytes.length) {
|
|
631
|
-
throw new HeaderError('trailing_bytes_after_signature_block')
|
|
632
|
-
}
|
|
633
|
-
const { algorithm, publicKey, signature } = parsed.block
|
|
634
|
-
|
|
635
|
-
let verified: boolean | null = null
|
|
636
|
-
if (input.expectedSignerPublicKey) {
|
|
637
|
-
if (algorithm !== SIGNATURE_ALGO_ED25519) {
|
|
638
|
-
// Unknown / unsupported algorithm: cannot verify with our
|
|
639
|
-
// Ed25519-only verifier; treat as a verification failure under
|
|
640
|
-
// the caller's policy (they asked us to verify, we couldn't).
|
|
641
|
-
verified = false
|
|
642
|
-
} else {
|
|
643
|
-
// Pubkey-pinning: if the embedded pubkey doesn't match the caller's
|
|
644
|
-
// expected one, fail without doing the (still-honest) Ed25519
|
|
645
|
-
// math. This keeps the "verified=true" contract tight: it means
|
|
646
|
-
// the file was signed by the key the caller expected.
|
|
647
|
-
verified =
|
|
648
|
-
bytesEqualConstantTime(publicKey, input.expectedSignerPublicKey) &&
|
|
649
|
-
verifySenderTranscript({
|
|
650
|
-
ed25519PublicKey: input.expectedSignerPublicKey,
|
|
651
|
-
transcriptDigest: input.transcriptDigest,
|
|
652
|
-
signature,
|
|
653
|
-
})
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
return { algorithm, publicKey, signature, verified }
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
function bytesEqualConstantTime(a: Uint8Array, b: Uint8Array): boolean {
|
|
660
|
-
if (a.length !== b.length) return false
|
|
661
|
-
let diff = 0
|
|
662
|
-
for (let i = 0; i < a.length; i += 1) {
|
|
663
|
-
diff |= a[i]! ^ b[i]!
|
|
664
|
-
}
|
|
665
|
-
return diff === 0
|
|
666
|
-
}
|
|
591
|
+
// `finalizeSignatureMetadata` moved to `../format/signature-tail.js`
|
|
592
|
+
// (re-exported above) so the whole-blob decryptors share it.
|