@browsercore/tls 0.1.3 → 0.2.0
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 +104 -4
- package/dist/certificates/cert-extensions.d.ts +46 -0
- package/dist/certificates/cert-extensions.d.ts.map +1 -0
- package/dist/certificates/cert-extensions.js +203 -0
- package/dist/certificates/cert-extensions.js.map +1 -0
- package/dist/certificates/certificates.d.ts +11 -9
- package/dist/certificates/certificates.d.ts.map +1 -1
- package/dist/certificates/certificates.js +75 -503
- package/dist/certificates/certificates.js.map +1 -1
- package/dist/certificates/der.d.ts +43 -0
- package/dist/certificates/der.d.ts.map +1 -0
- package/dist/certificates/der.js +204 -0
- package/dist/certificates/der.js.map +1 -0
- package/dist/certificates/hostname.d.ts +21 -0
- package/dist/certificates/hostname.d.ts.map +1 -0
- package/dist/certificates/hostname.js +46 -0
- package/dist/certificates/hostname.js.map +1 -0
- package/dist/certificates/pem.d.ts +11 -0
- package/dist/certificates/pem.d.ts.map +1 -0
- package/dist/certificates/pem.js +69 -0
- package/dist/certificates/pem.js.map +1 -0
- package/dist/connection/handshake-driver.d.ts +59 -0
- package/dist/connection/handshake-driver.d.ts.map +1 -0
- package/dist/connection/handshake-driver.js +137 -0
- package/dist/connection/handshake-driver.js.map +1 -0
- package/dist/connection/handshake-messages.d.ts +45 -0
- package/dist/connection/handshake-messages.d.ts.map +1 -0
- package/dist/connection/handshake-messages.js +170 -0
- package/dist/connection/handshake-messages.js.map +1 -0
- package/dist/connection/index.d.ts +19 -0
- package/dist/connection/index.d.ts.map +1 -0
- package/dist/connection/index.js +19 -0
- package/dist/connection/index.js.map +1 -0
- package/dist/connection/key-exchange.d.ts +24 -0
- package/dist/connection/key-exchange.d.ts.map +1 -0
- package/dist/connection/key-exchange.js +104 -0
- package/dist/connection/key-exchange.js.map +1 -0
- package/dist/connection/lifecycle.d.ts +38 -0
- package/dist/connection/lifecycle.d.ts.map +1 -0
- package/dist/connection/lifecycle.js +101 -0
- package/dist/connection/lifecycle.js.map +1 -0
- package/dist/connection/record-layer.d.ts +65 -0
- package/dist/connection/record-layer.d.ts.map +1 -0
- package/dist/connection/record-layer.js +140 -0
- package/dist/connection/record-layer.js.map +1 -0
- package/dist/crypto/keySchedule.d.ts +18 -3
- package/dist/crypto/keySchedule.d.ts.map +1 -1
- package/dist/crypto/keySchedule.js +82 -11
- package/dist/crypto/keySchedule.js.map +1 -1
- package/dist/errors.d.ts +43 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +60 -2
- package/dist/errors.js.map +1 -1
- package/dist/extensions/extensions.d.ts +26 -25
- package/dist/extensions/extensions.d.ts.map +1 -1
- package/dist/extensions/extensions.js +92 -49
- package/dist/extensions/extensions.js.map +1 -1
- package/dist/handshake/client-hello.d.ts +30 -0
- package/dist/handshake/client-hello.d.ts.map +1 -0
- package/dist/handshake/client-hello.js +464 -0
- package/dist/handshake/client-hello.js.map +1 -0
- package/dist/handshake/grease.d.ts +70 -0
- package/dist/handshake/grease.d.ts.map +1 -0
- package/dist/handshake/grease.js +293 -0
- package/dist/handshake/grease.js.map +1 -0
- package/dist/handshake/handshake-types.d.ts +84 -0
- package/dist/handshake/handshake-types.d.ts.map +1 -0
- package/dist/handshake/handshake-types.js +31 -0
- package/dist/handshake/handshake-types.js.map +1 -0
- package/dist/handshake/handshake.d.ts +19 -118
- package/dist/handshake/handshake.d.ts.map +1 -1
- package/dist/handshake/handshake.js +19 -412
- package/dist/handshake/handshake.js.map +1 -1
- package/dist/handshake/server-hello.d.ts +33 -0
- package/dist/handshake/server-hello.d.ts.map +1 -0
- package/dist/handshake/server-hello.js +134 -0
- package/dist/handshake/server-hello.js.map +1 -0
- package/dist/handshake/state-machine.d.ts +34 -0
- package/dist/handshake/state-machine.d.ts.map +1 -0
- package/dist/handshake/state-machine.js +105 -0
- package/dist/handshake/state-machine.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/profiles/profiles.d.ts +12 -2
- package/dist/profiles/profiles.d.ts.map +1 -1
- package/dist/profiles/profiles.js +22 -7
- package/dist/profiles/profiles.js.map +1 -1
- package/dist/record/record.d.ts +18 -1
- package/dist/record/record.d.ts.map +1 -1
- package/dist/record/record.js +79 -11
- package/dist/record/record.js.map +1 -1
- package/dist/tls.d.ts +62 -101
- package/dist/tls.d.ts.map +1 -1
- package/dist/tls.js +166 -566
- package/dist/tls.js.map +1 -1
- package/dist/types.d.ts +40 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +7 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +23 -0
- package/dist/utils.js.map +1 -1
- package/package.json +53 -48
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection lifecycle: timeouts, alerts, state transitions, error emission.
|
|
3
|
+
*
|
|
4
|
+
* The bookkeeping around a connection's lifetime — racing the handshake against
|
|
5
|
+
* a timeout, translating a received alert into a typed error, moving between
|
|
6
|
+
* lifecycle states, and notifying observers. Kept as thin functions over
|
|
7
|
+
* explicit state so the connection class stays a coordinator rather than owning
|
|
8
|
+
* this plumbing.
|
|
9
|
+
*/
|
|
10
|
+
import { TlsAlertError, TlsHandshakeError } from "../errors.js";
|
|
11
|
+
import { ContentType } from "../record/record.js";
|
|
12
|
+
import { assertNever } from "../utils.js";
|
|
13
|
+
/** Race `run` against a timeout, rejecting with a handshake error if it fires. */
|
|
14
|
+
export async function withTimeout(ms, run) {
|
|
15
|
+
let timer;
|
|
16
|
+
const timeout = new Promise((_, reject) => {
|
|
17
|
+
timer = setTimeout(() => {
|
|
18
|
+
reject(new TlsHandshakeError("finished", {
|
|
19
|
+
cause: new Error(`handshake timed out after ${ms}ms`),
|
|
20
|
+
}));
|
|
21
|
+
}, ms);
|
|
22
|
+
});
|
|
23
|
+
try {
|
|
24
|
+
await Promise.race([run(), timeout]);
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
if (timer !== undefined) {
|
|
28
|
+
clearTimeout(timer);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Handle a non-application record encountered while reading application data.
|
|
34
|
+
*
|
|
35
|
+
* Routes alerts to {@link handleAlert}, ignores post-handshake handshake
|
|
36
|
+
* messages (NewSessionTicket, KeyUpdate — out of scope for the happy path),
|
|
37
|
+
* and rejects any {@link ContentType.CHANGE_CIPHER_SPEC} or
|
|
38
|
+
* {@link ContentType.APPLICATION_DATA} that appears *inside* an encrypted
|
|
39
|
+
* record (application data is only valid as the outer record type; TLS 1.3 has
|
|
40
|
+
* no change_cipher_spec). Returns `true` if the alert was a close_notify and
|
|
41
|
+
* the connection should close gracefully.
|
|
42
|
+
*/
|
|
43
|
+
export function handlePostHandshakeRecord(innerType, content) {
|
|
44
|
+
switch (innerType) {
|
|
45
|
+
case ContentType.ALERT:
|
|
46
|
+
return handleAlert(content).close;
|
|
47
|
+
case ContentType.HANDSHAKE:
|
|
48
|
+
// Post-handshake handshake (e.g. NewSessionTicket, KeyUpdate) — out of
|
|
49
|
+
// scope for the happy path; ignore but do not error.
|
|
50
|
+
return false;
|
|
51
|
+
case ContentType.CHANGE_CIPHER_SPEC:
|
|
52
|
+
case ContentType.APPLICATION_DATA:
|
|
53
|
+
// Neither should appear here: application data is the only expected
|
|
54
|
+
// outer type, and TLS 1.3 has no change_cipher_spec. Reject typed.
|
|
55
|
+
throw new TlsHandshakeError("finished", {
|
|
56
|
+
cause: new Error(`unexpected post-handshake record type ${innerType}`),
|
|
57
|
+
});
|
|
58
|
+
default:
|
|
59
|
+
return assertNever(innerType);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** Translate a received alert into a typed error and close the connection. */
|
|
63
|
+
export function handleAlert(content) {
|
|
64
|
+
if (content.length < 2) {
|
|
65
|
+
return { close: false, error: new TlsAlertError("fatal", 0, { cause: new Error("truncated alert record") }) };
|
|
66
|
+
}
|
|
67
|
+
// content.length >= 2 (checked above) guarantees both indices are in bounds,
|
|
68
|
+
// but noUncheckedIndexedAccess cannot prove it — read through locals.
|
|
69
|
+
const levelByte = content[0];
|
|
70
|
+
const description = content[1];
|
|
71
|
+
if (levelByte === undefined || description === undefined) {
|
|
72
|
+
return { close: false, error: new TlsAlertError("fatal", 0, { cause: new Error("truncated alert record") }) };
|
|
73
|
+
}
|
|
74
|
+
const level = levelByte === 0x02 ? "fatal" : "warning";
|
|
75
|
+
if (description === 0) {
|
|
76
|
+
// close_notify — graceful.
|
|
77
|
+
return { close: true };
|
|
78
|
+
}
|
|
79
|
+
return { close: false, error: new TlsAlertError(level, description) };
|
|
80
|
+
}
|
|
81
|
+
/** Throw unless the connection is open. */
|
|
82
|
+
export function ensureOpen(state) {
|
|
83
|
+
if (state.state !== "open") {
|
|
84
|
+
throw new TlsHandshakeError("finished", {
|
|
85
|
+
cause: new Error(`connection not open (state: ${state.state})`),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** Emit an error to all registered error listeners. */
|
|
90
|
+
export function emitError(listeners, error) {
|
|
91
|
+
for (const listener of listeners) {
|
|
92
|
+
listener(error);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** Notify all close listeners. */
|
|
96
|
+
export function notifyClose(listeners, reason) {
|
|
97
|
+
for (const listener of listeners) {
|
|
98
|
+
listener(reason);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../src/connection/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAiB,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,WAAW,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C,KAAK,GAAG,CAAC;SAClE,CAAC,CAAC;IACP,CAAC;AACL,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,SAAS,CAAC,SAAiD,EAAE,KAAe;IACxF,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QAC/B,QAAQ,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;AACL,CAAC;AAED,kCAAkC;AAClC,MAAM,UAAU,WAAW,CAAC,SAAqD,EAAE,MAAmB;IAClG,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QAC/B,QAAQ,CAAC,MAAM,CAAC,CAAC;IACrB,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TLS record-layer I/O (RFC 8446 §5).
|
|
3
|
+
*
|
|
4
|
+
* Reading and writing records, and the AEAD encrypt/decrypt step that turns a
|
|
5
|
+
* plaintext fragment into an encrypted record (and back). These are expressed
|
|
6
|
+
* as pure functions over an explicit `readBuffer` + `transport` rather than as
|
|
7
|
+
* methods reaching into private connection state — the class owns its fields and
|
|
8
|
+
* threads the buffer through, while this module owns the byte mechanics.
|
|
9
|
+
*
|
|
10
|
+
* `readBuffer` is treated as an immutable input that each function consumes a
|
|
11
|
+
* prefix of and returns the remainder as part of its result; the caller (the
|
|
12
|
+
* connection) reassigns its buffer to that remainder. This keeps the framing
|
|
13
|
+
* logic testable in isolation without exposing the buffer.
|
|
14
|
+
*/
|
|
15
|
+
import type { Transport } from "@browsercore/transport";
|
|
16
|
+
import type { TrafficSecrets } from "../types.js";
|
|
17
|
+
import { ContentType, encryptRecord } from "../record/record.js";
|
|
18
|
+
/** AEAD authentication tag length for every cipher we support (bytes). */
|
|
19
|
+
export declare const AEAD_TAG_LENGTH = 16;
|
|
20
|
+
/** Concatenate byte chunks into a single buffer. */
|
|
21
|
+
export declare function concat(...chunks: readonly Uint8Array[]): Uint8Array;
|
|
22
|
+
/**
|
|
23
|
+
* Build the per-record AEAD nonce by XOR-ing the (zero-padded, big-endian)
|
|
24
|
+
* sequence number into the static IV — exactly TLS 1.3 §5.3.
|
|
25
|
+
*/
|
|
26
|
+
export declare function xorNonce(iv: Uint8Array, seq: number): Uint8Array;
|
|
27
|
+
/** Pull bytes from the transport until at least `n` are buffered. Returns the new buffer. */
|
|
28
|
+
export declare function ensureBytes(readBuffer: Uint8Array, transport: Transport, n: number): Promise<Uint8Array>;
|
|
29
|
+
/**
|
|
30
|
+
* Read the 5-byte record header and return it raw (needed as AEAD AAD) plus the
|
|
31
|
+
* parsed length and the buffer left after consuming the header.
|
|
32
|
+
*/
|
|
33
|
+
export declare function readHeaderBytes(readBuffer: Uint8Array, transport: Transport): Promise<{
|
|
34
|
+
raw: Uint8Array;
|
|
35
|
+
length: number;
|
|
36
|
+
readBuffer: Uint8Array;
|
|
37
|
+
}>;
|
|
38
|
+
/** Read a complete record given its already-consumed header. Returns the new buffer. */
|
|
39
|
+
export declare function readRawRecord(readBuffer: Uint8Array, transport: Transport, header: {
|
|
40
|
+
raw: Uint8Array;
|
|
41
|
+
length: number;
|
|
42
|
+
}): Promise<{
|
|
43
|
+
type: ContentType;
|
|
44
|
+
fragment: Uint8Array;
|
|
45
|
+
readBuffer: Uint8Array;
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Read and decrypt one record, returning its inner content type and content.
|
|
49
|
+
* TLS 1.3 wraps encrypted handshake messages in records whose outer type is
|
|
50
|
+
* application_data; the real type is the last non-zero byte of the plaintext.
|
|
51
|
+
*/
|
|
52
|
+
export declare function readEncryptedRecord(readBuffer: Uint8Array, transport: Transport, aead: Parameters<typeof encryptRecord>[4], traffic: TrafficSecrets, seq: number): Promise<{
|
|
53
|
+
innerType: ContentType;
|
|
54
|
+
content: Uint8Array;
|
|
55
|
+
readBuffer: Uint8Array;
|
|
56
|
+
}>;
|
|
57
|
+
/** Write an unencrypted record (used for the initial ClientHello/ServerHello). */
|
|
58
|
+
export declare function writeRecord(transport: Transport, type: ContentType, fragment: Uint8Array): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Encrypt a payload under `traffic` and write it as an encrypted record whose
|
|
61
|
+
* outer type is application_data. The inner content type byte is appended to
|
|
62
|
+
* the plaintext before encryption.
|
|
63
|
+
*/
|
|
64
|
+
export declare function writeEncryptedRecord(transport: Transport, aead: Parameters<typeof encryptRecord>[4], traffic: TrafficSecrets, innerType: ContentType, content: Uint8Array, seq: number): void;
|
|
65
|
+
//# sourceMappingURL=record-layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record-layer.d.ts","sourceRoot":"","sources":["../../src/connection/record-layer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,WAAW,EAAiB,aAAa,EAA6D,MAAM,qBAAqB,CAAC;AAC3I,0EAA0E;AAC1E,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,oDAAoD;AACpD,wBAAgB,MAAM,CAAC,GAAG,MAAM,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,CAYnE;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAgBhE;AAED,6FAA6F;AAC7F,wBAAsB,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAW9G;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACjC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,GACrB,OAAO,CAAC;IAAE,GAAG,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,CAAC,CAKtE;AAED,wFAAwF;AACxF,wBAAsB,aAAa,CAC/B,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE;IAAE,GAAG,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC5C,OAAO,CAAC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,CAAC,CAW9E;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACrC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,EACzC,OAAO,EAAE,cAAc,EACvB,GAAG,EAAE,MAAM,GACZ,OAAO,CAAC;IAAE,SAAS,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,CAAC,CA4BlF;AAED,kFAAkF;AAClF,wBAAsB,WAAW,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9G;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAChC,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,EACzC,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,WAAW,EACtB,OAAO,EAAE,UAAU,EACnB,GAAG,EAAE,MAAM,GACZ,IAAI,CAMN"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TLS record-layer I/O (RFC 8446 §5).
|
|
3
|
+
*
|
|
4
|
+
* Reading and writing records, and the AEAD encrypt/decrypt step that turns a
|
|
5
|
+
* plaintext fragment into an encrypted record (and back). These are expressed
|
|
6
|
+
* as pure functions over an explicit `readBuffer` + `transport` rather than as
|
|
7
|
+
* methods reaching into private connection state — the class owns its fields and
|
|
8
|
+
* threads the buffer through, while this module owns the byte mechanics.
|
|
9
|
+
*
|
|
10
|
+
* `readBuffer` is treated as an immutable input that each function consumes a
|
|
11
|
+
* prefix of and returns the remainder as part of its result; the caller (the
|
|
12
|
+
* connection) reassigns its buffer to that remainder. This keeps the framing
|
|
13
|
+
* logic testable in isolation without exposing the buffer.
|
|
14
|
+
*/
|
|
15
|
+
import { TlsDecryptError, TlsHandshakeError } from "../errors.js";
|
|
16
|
+
import { ContentType, decryptRecord, encryptRecord, parseRecordHeader, readContentType, serializeRecordHeader } from "../record/record.js";
|
|
17
|
+
/** AEAD authentication tag length for every cipher we support (bytes). */
|
|
18
|
+
export const AEAD_TAG_LENGTH = 16;
|
|
19
|
+
/** Concatenate byte chunks into a single buffer. */
|
|
20
|
+
export function concat(...chunks) {
|
|
21
|
+
let total = 0;
|
|
22
|
+
for (const c of chunks) {
|
|
23
|
+
total += c.length;
|
|
24
|
+
}
|
|
25
|
+
const out = new Uint8Array(total);
|
|
26
|
+
let o = 0;
|
|
27
|
+
for (const c of chunks) {
|
|
28
|
+
out.set(c, o);
|
|
29
|
+
o += c.length;
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Build the per-record AEAD nonce by XOR-ing the (zero-padded, big-endian)
|
|
35
|
+
* sequence number into the static IV — exactly TLS 1.3 §5.3.
|
|
36
|
+
*/
|
|
37
|
+
export function xorNonce(iv, seq) {
|
|
38
|
+
const nonce = Uint8Array.from(iv);
|
|
39
|
+
let s = seq;
|
|
40
|
+
for (let i = nonce.length - 1; i >= nonce.length - 8 && s > 0; i--) {
|
|
41
|
+
// The loop bounds guarantee i is a valid index, but noUncheckedIndexedAccess
|
|
42
|
+
// cannot see that — read through a local and guard before mutating.
|
|
43
|
+
const byte = nonce[i];
|
|
44
|
+
if (byte === undefined) {
|
|
45
|
+
throw new TlsDecryptError("xor_nonce", {
|
|
46
|
+
cause: new Error(`nonce index ${i} out of bounds (iv length ${nonce.length})`),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
nonce[i] = byte ^ (s & 0xff);
|
|
50
|
+
s = Math.floor(s / 256);
|
|
51
|
+
}
|
|
52
|
+
return nonce;
|
|
53
|
+
}
|
|
54
|
+
/** Pull bytes from the transport until at least `n` are buffered. Returns the new buffer. */
|
|
55
|
+
export async function ensureBytes(readBuffer, transport, n) {
|
|
56
|
+
let buffer = readBuffer;
|
|
57
|
+
while (buffer.length < n) {
|
|
58
|
+
// Sequential by necessity: each transport.read() delivers a variable
|
|
59
|
+
// number of bytes and the loop continuation (buffer.length < n) must be
|
|
60
|
+
// re-evaluated after every read, so the reads cannot be parallelized.
|
|
61
|
+
// eslint-disable-next-line no-await-in-loop
|
|
62
|
+
const chunk = await transport.read();
|
|
63
|
+
buffer = concat(buffer, chunk);
|
|
64
|
+
}
|
|
65
|
+
return buffer;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Read the 5-byte record header and return it raw (needed as AEAD AAD) plus the
|
|
69
|
+
* parsed length and the buffer left after consuming the header.
|
|
70
|
+
*/
|
|
71
|
+
export async function readHeaderBytes(readBuffer, transport) {
|
|
72
|
+
const buffer = await ensureBytes(readBuffer, transport, 5);
|
|
73
|
+
const raw = buffer.subarray(0, 5);
|
|
74
|
+
const parsed = parseRecordHeader(raw);
|
|
75
|
+
return { raw, length: parsed.length, readBuffer: buffer };
|
|
76
|
+
}
|
|
77
|
+
/** Read a complete record given its already-consumed header. Returns the new buffer. */
|
|
78
|
+
export async function readRawRecord(readBuffer, transport, header) {
|
|
79
|
+
const buffer = await ensureBytes(readBuffer, transport, 5 + header.length);
|
|
80
|
+
// type is byte 0 of the header; validate it back to the union (the cast that
|
|
81
|
+
// used to live here is replaced by a properly-typed parse step).
|
|
82
|
+
const typeByte = header.raw[0];
|
|
83
|
+
if (typeByte === undefined) {
|
|
84
|
+
throw new TlsDecryptError("record", { cause: new Error("record header missing content type byte") });
|
|
85
|
+
}
|
|
86
|
+
const type = readContentType(typeByte);
|
|
87
|
+
const fragment = buffer.subarray(5, 5 + header.length);
|
|
88
|
+
return { type, fragment, readBuffer: buffer.subarray(5 + header.length) };
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Read and decrypt one record, returning its inner content type and content.
|
|
92
|
+
* TLS 1.3 wraps encrypted handshake messages in records whose outer type is
|
|
93
|
+
* application_data; the real type is the last non-zero byte of the plaintext.
|
|
94
|
+
*/
|
|
95
|
+
export async function readEncryptedRecord(readBuffer, transport, aead, traffic, seq) {
|
|
96
|
+
const header = await readHeaderBytes(readBuffer, transport);
|
|
97
|
+
const record = await readRawRecord(header.readBuffer, transport, header);
|
|
98
|
+
if (record.type !== ContentType.APPLICATION_DATA) {
|
|
99
|
+
throw new TlsHandshakeError("finished", {
|
|
100
|
+
cause: new Error(`expected encrypted APPLICATION_DATA record, got ${record.type}`),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const nonce = xorNonce(traffic.iv, seq);
|
|
104
|
+
const plaintext = decryptRecord(record.fragment, traffic.key, nonce, header.raw, aead);
|
|
105
|
+
// plaintext = content || innerType || optional zero padding. Find the type.
|
|
106
|
+
let end = plaintext.length;
|
|
107
|
+
while (end > 0 && plaintext[end - 1] === 0) {
|
|
108
|
+
end--;
|
|
109
|
+
}
|
|
110
|
+
if (end === 0) {
|
|
111
|
+
throw new TlsHandshakeError("finished", {
|
|
112
|
+
cause: new Error("encrypted record plaintext is all zero padding"),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const innerTypeByte = plaintext[end - 1];
|
|
116
|
+
if (innerTypeByte === undefined) {
|
|
117
|
+
throw new TlsHandshakeError("finished", {
|
|
118
|
+
cause: new Error("encrypted record plaintext ended before the inner content type byte"),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
const innerType = readContentType(innerTypeByte);
|
|
122
|
+
return { innerType, content: plaintext.subarray(0, end - 1), readBuffer: record.readBuffer };
|
|
123
|
+
}
|
|
124
|
+
/** Write an unencrypted record (used for the initial ClientHello/ServerHello). */
|
|
125
|
+
export async function writeRecord(transport, type, fragment) {
|
|
126
|
+
await transport.write(concat(serializeRecordHeader(type, fragment.length), fragment));
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Encrypt a payload under `traffic` and write it as an encrypted record whose
|
|
130
|
+
* outer type is application_data. The inner content type byte is appended to
|
|
131
|
+
* the plaintext before encryption.
|
|
132
|
+
*/
|
|
133
|
+
export function writeEncryptedRecord(transport, aead, traffic, innerType, content, seq) {
|
|
134
|
+
const plaintext = concat(content, new Uint8Array([innerType]));
|
|
135
|
+
const header = serializeRecordHeader(ContentType.APPLICATION_DATA, plaintext.length + AEAD_TAG_LENGTH);
|
|
136
|
+
const nonce = xorNonce(traffic.iv, seq);
|
|
137
|
+
const ciphertext = encryptRecord(plaintext, traffic.key, nonce, header, aead);
|
|
138
|
+
void transport.write(concat(header, ciphertext));
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=record-layer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record-layer.js","sourceRoot":"","sources":["../../src/connection/record-layer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC3I,0EAA0E;AAC1E,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAElC,oDAAoD;AACpD,MAAM,UAAU,MAAM,CAAC,GAAG,MAA6B;IACnD,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACrB,KAAK,IAAI,C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C,SAAS,EAAE,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAC9E,KAAK,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -10,14 +10,29 @@
|
|
|
10
10
|
* always performs extract+expand in one call, but the TLS 1.3 schedule needs
|
|
11
11
|
* the two steps independently (the extract output feeds the next stage's salt).
|
|
12
12
|
*/
|
|
13
|
-
import type
|
|
13
|
+
import { type HashId } from "@browsercore/crypto";
|
|
14
14
|
import type { ApplicationTrafficSecrets, CipherSuite, ProtocolVersion, TrafficSecrets } from "../types.js";
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Map a cipher suite to its HKDF hash function.
|
|
17
|
+
*
|
|
18
|
+
* Only the four TLS 1.3 AEAD suites can be negotiated; they all use SHA-256
|
|
19
|
+
* except AES-256-GCM, which uses SHA-384. TLS 1.2 suites can't be negotiated by
|
|
20
|
+
* this client, so the default throws rather than guessing a hash.
|
|
21
|
+
*/
|
|
16
22
|
export declare function cipherSuiteToHash(cipherSuite: CipherSuite): HashId;
|
|
17
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Map a cipher suite to its AEAD key length in bytes.
|
|
25
|
+
*
|
|
26
|
+
* Only meaningful for the four negotiable TLS 1.3 AEAD suites. TLS 1.2 suites
|
|
27
|
+
* can't be negotiated, so the default throws.
|
|
28
|
+
*/
|
|
18
29
|
export declare function cipherSuiteKeyLength(cipherSuite: CipherSuite): number;
|
|
19
30
|
/** Map a cipher suite to its AEAD IV length in bytes (all TLS 1.3 AEADs use 12). */
|
|
20
31
|
export declare function cipherSuiteIvLength(_cipherSuite: CipherSuite): number;
|
|
32
|
+
/** Output length (bytes) of the hash used by a cipher suite. */
|
|
33
|
+
export declare function hashLengthFor(hash: HashId): number;
|
|
34
|
+
/** Map a negotiated cipher suite to the hash function used for its transcript. */
|
|
35
|
+
export declare function hashFor(cipherSuite: CipherSuite): HashId;
|
|
21
36
|
/**
|
|
22
37
|
* HKDF-Expand-Label per RFC 8446 §7.1.
|
|
23
38
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keySchedule.d.ts","sourceRoot":"","sources":["../../src/crypto/keySchedule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"keySchedule.d.ts","sourceRoot":"","sources":["../../src/crypto/keySchedule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAA4B,KAAK,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,KAAK,EACR,yBAAyB,EACzB,WAAW,EACX,eAAe,EACf,cAAc,EACjB,MAAM,aAAa,CAAC;AAIrB;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAkClE;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAkCrE;AAWD,oFAAoF;AACpF,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,WAAW,GAAG,MAAM,CAErE;AAED,gEAAgE;AAChE,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CASlD;AAED,kFAAkF;AAClF,wBAAgB,OAAO,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAExD;AAmCD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC3B,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GACb,UAAU,CAcZ;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAChC,aAAa,EAAE,UAAU,EACzB,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,MAAM,GACb,cAAc,CAIhB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,6BAA6B,CACzC,YAAY,EAAE,UAAU,EACxB,eAAe,EAAE,UAAU,EAC3B,WAAW,EAAE,WAAW,GACzB;IACC,YAAY,EAAE,UAAU,CAAC;IACzB,mBAAmB,EAAE,UAAU,CAAC;IAChC,mBAAmB,EAAE,UAAU,CAAC;CACnC,CAuBA;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAClC,YAAY,EAAE,UAAU,EACxB,eAAe,EAAE,UAAU,EAC3B,WAAW,EAAE,WAAW,GACzB;IACC,YAAY,EAAE,UAAU,CAAC;IACzB,OAAO,EAAE,yBAAyB,CAAC;CACtC,CAeA;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACpC,YAAY,EAAE,UAAU,EACxB,mBAAmB,EAAE,UAAU,EAC/B,WAAW,EAAE,WAAW,GACzB,yBAAyB,CAW3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,GAAG,cAAc,CAKxG;AAED,4EAA4E;AAC5E,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,WAAW,EAAE,GAAG,IAAI,CAMrG;AAKD,gEAAgE;AAChE,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAMtE"}
|
|
@@ -11,36 +11,101 @@
|
|
|
11
11
|
* the two steps independently (the extract output feeds the next stage's salt).
|
|
12
12
|
*/
|
|
13
13
|
import { crypto, SHA_256, SHA_384 } from "@browsercore/crypto";
|
|
14
|
-
import { TlsHandshakeError } from "../errors.js";
|
|
14
|
+
import { TlsHandshakeError, TlsKeyScheduleError } from "../errors.js";
|
|
15
15
|
import { assertNever } from "../utils.js";
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Map a cipher suite to its HKDF hash function.
|
|
18
|
+
*
|
|
19
|
+
* Only the four TLS 1.3 AEAD suites can be negotiated; they all use SHA-256
|
|
20
|
+
* except AES-256-GCM, which uses SHA-384. TLS 1.2 suites can't be negotiated by
|
|
21
|
+
* this client, so the default throws rather than guessing a hash.
|
|
22
|
+
*/
|
|
17
23
|
export function cipherSuiteToHash(cipherSuite) {
|
|
18
24
|
switch (cipherSuite) {
|
|
25
|
+
// The four TLS 1.3 AEAD suites — the only ones this client can negotiate.
|
|
19
26
|
case "TLS_AES_256_GCM_SHA384":
|
|
20
27
|
return SHA_384;
|
|
21
28
|
case "TLS_AES_128_GCM_SHA256":
|
|
22
29
|
case "TLS_CHACHA20_POLY1305_SHA256":
|
|
23
30
|
case "TLS_AES_128_CCM_SHA256":
|
|
24
31
|
return SHA_256;
|
|
32
|
+
// TLS 1.2 suites (and the GREASE placeholder) appear only in the offered
|
|
33
|
+
// list and can never be negotiated in TLS 1.3, so they have no HKDF hash.
|
|
34
|
+
case "TLS_GREASE_RESERVED_0":
|
|
35
|
+
case "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256":
|
|
36
|
+
case "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256":
|
|
37
|
+
case "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384":
|
|
38
|
+
case "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384":
|
|
39
|
+
case "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256":
|
|
40
|
+
case "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256":
|
|
41
|
+
case "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA":
|
|
42
|
+
case "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA":
|
|
43
|
+
case "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA":
|
|
44
|
+
case "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA":
|
|
45
|
+
case "TLS_RSA_WITH_AES_128_GCM_SHA256":
|
|
46
|
+
case "TLS_RSA_WITH_AES_256_GCM_SHA384":
|
|
47
|
+
case "TLS_RSA_WITH_AES_128_CBC_SHA":
|
|
48
|
+
case "TLS_RSA_WITH_AES_256_CBC_SHA":
|
|
49
|
+
return throwKeyScheduleError(`cipher suite ${cipherSuite} has no HKDF hash mapping — not a negotiable TLS 1.3 suite`);
|
|
50
|
+
default:
|
|
51
|
+
// Every CipherSuite member is covered above; this is unreachable but
|
|
52
|
+
// keeps the switch exhaustive if the union is ever extended.
|
|
53
|
+
return assertNever(cipherSuite);
|
|
25
54
|
}
|
|
26
55
|
}
|
|
27
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Map a cipher suite to its AEAD key length in bytes.
|
|
58
|
+
*
|
|
59
|
+
* Only meaningful for the four negotiable TLS 1.3 AEAD suites. TLS 1.2 suites
|
|
60
|
+
* can't be negotiated, so the default throws.
|
|
61
|
+
*/
|
|
28
62
|
export function cipherSuiteKeyLength(cipherSuite) {
|
|
29
63
|
switch (cipherSuite) {
|
|
64
|
+
// The four TLS 1.3 AEAD suites — the only ones this client can negotiate.
|
|
30
65
|
case "TLS_AES_128_GCM_SHA256":
|
|
31
66
|
case "TLS_AES_128_CCM_SHA256":
|
|
32
67
|
return 16;
|
|
33
68
|
case "TLS_AES_256_GCM_SHA384":
|
|
34
69
|
case "TLS_CHACHA20_POLY1305_SHA256":
|
|
35
70
|
return 32;
|
|
71
|
+
// TLS 1.2 suites (and the GREASE placeholder) appear only in the offered
|
|
72
|
+
// list and can never be negotiated in TLS 1.3, so they have no AEAD key length.
|
|
73
|
+
case "TLS_GREASE_RESERVED_0":
|
|
74
|
+
case "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256":
|
|
75
|
+
case "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256":
|
|
76
|
+
case "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384":
|
|
77
|
+
case "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384":
|
|
78
|
+
case "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256":
|
|
79
|
+
case "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256":
|
|
80
|
+
case "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA":
|
|
81
|
+
case "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA":
|
|
82
|
+
case "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA":
|
|
83
|
+
case "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA":
|
|
84
|
+
case "TLS_RSA_WITH_AES_128_GCM_SHA256":
|
|
85
|
+
case "TLS_RSA_WITH_AES_256_GCM_SHA384":
|
|
86
|
+
case "TLS_RSA_WITH_AES_128_CBC_SHA":
|
|
87
|
+
case "TLS_RSA_WITH_AES_256_CBC_SHA":
|
|
88
|
+
return throwKeyScheduleError(`cipher suite ${cipherSuite} has no AEAD key length — not a negotiable TLS 1.3 suite`);
|
|
89
|
+
default:
|
|
90
|
+
// Every CipherSuite member is covered above; this is unreachable but
|
|
91
|
+
// keeps the switch exhaustive if the union is ever extended.
|
|
92
|
+
return assertNever(cipherSuite);
|
|
36
93
|
}
|
|
37
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Throw a {@link TlsKeyScheduleError} and return `never`, so call sites can use
|
|
97
|
+
* `return throwKeyScheduleError(...)` to satisfy `consistent-return` while failing
|
|
98
|
+
* fast with a descriptive message.
|
|
99
|
+
*/
|
|
100
|
+
function throwKeyScheduleError(message) {
|
|
101
|
+
throw new TlsKeyScheduleError("SHA-256", message);
|
|
102
|
+
}
|
|
38
103
|
/** Map a cipher suite to its AEAD IV length in bytes (all TLS 1.3 AEADs use 12). */
|
|
39
104
|
export function cipherSuiteIvLength(_cipherSuite) {
|
|
40
105
|
return 12;
|
|
41
106
|
}
|
|
42
|
-
/**
|
|
43
|
-
function
|
|
107
|
+
/** Output length (bytes) of the hash used by a cipher suite. */
|
|
108
|
+
export function hashLengthFor(hash) {
|
|
44
109
|
switch (hash) {
|
|
45
110
|
case "SHA-256":
|
|
46
111
|
return 32;
|
|
@@ -50,11 +115,17 @@ function hashLength(hash) {
|
|
|
50
115
|
return assertNever(hash);
|
|
51
116
|
}
|
|
52
117
|
}
|
|
118
|
+
/** Map a negotiated cipher suite to the hash function used for its transcript. */
|
|
119
|
+
export function hashFor(cipherSuite) {
|
|
120
|
+
return cipherSuiteToHash(cipherSuite);
|
|
121
|
+
}
|
|
53
122
|
/**
|
|
54
123
|
* HKDF-Extract(salt, Ikm) = HMAC-Hash(salt, Ikm), per RFC 5869 §2.3.
|
|
55
|
-
* The output is exactly {@link
|
|
124
|
+
* The output is exactly {@link hashLengthFor}(hash) bytes.
|
|
56
125
|
*/
|
|
57
126
|
function hkdfExtract(hash, salt, ikm) {
|
|
127
|
+
// crypto.hmac is declared to return Uint8Array; the cast that used to live
|
|
128
|
+
// here was redundant.
|
|
58
129
|
return crypto.hmac(hash, salt, ikm);
|
|
59
130
|
}
|
|
60
131
|
/**
|
|
@@ -62,10 +133,10 @@ function hkdfExtract(hash, salt, ikm) {
|
|
|
62
133
|
* because @browsercore/crypto exposes only the combined extract+expand helper.
|
|
63
134
|
*/
|
|
64
135
|
function hkdfExpand(hash, prk, info, length) {
|
|
65
|
-
const hashLen =
|
|
136
|
+
const hashLen = hashLengthFor(hash);
|
|
66
137
|
const n = Math.ceil(length / hashLen);
|
|
67
138
|
if (n > 255) {
|
|
68
|
-
throw new
|
|
139
|
+
throw new TlsKeyScheduleError(hash, `HKDF-Expand length ${length} exceeds maximum for hash (255 * ${hashLen})`);
|
|
69
140
|
}
|
|
70
141
|
const okm = new Uint8Array(n * hashLen);
|
|
71
142
|
let t = new Uint8Array(0);
|
|
@@ -130,7 +201,7 @@ export function deriveTrafficSecrets(trafficSecret, cipherSuite, hash) {
|
|
|
130
201
|
*/
|
|
131
202
|
export function deriveHandshakeTrafficSecrets(sharedSecret, helloTranscript, cipherSuite) {
|
|
132
203
|
const hash = cipherSuiteToHash(cipherSuite);
|
|
133
|
-
const hashLen =
|
|
204
|
+
const hashLen = hashLengthFor(hash);
|
|
134
205
|
const zeros = new Uint8Array(hashLen);
|
|
135
206
|
// early_secret = HKDF-Extract(0, 0)
|
|
136
207
|
const earlySecret = hkdfExtract(hash, zeros, zeros);
|
|
@@ -178,7 +249,7 @@ export function deriveHandshakeSecrets(sharedSecret, helloTranscript, cipherSuit
|
|
|
178
249
|
*/
|
|
179
250
|
export function deriveApplicationSecrets(masterSecret, handshakeTranscript, cipherSuite) {
|
|
180
251
|
const hash = cipherSuiteToHash(cipherSuite);
|
|
181
|
-
const hashLen =
|
|
252
|
+
const hashLen = hashLengthFor(hash);
|
|
182
253
|
const clientApTraffic = hkdfExpandLabel(masterSecret, "c ap traffic", handshakeTranscript, hashLen, hash);
|
|
183
254
|
const serverApTraffic = hkdfExpandLabel(masterSecret, "s ap traffic", handshakeTranscript, hashLen, hash);
|
|
184
255
|
return {
|
|
@@ -197,7 +268,7 @@ export function deriveApplicationSecrets(masterSecret, handshakeTranscript, ciph
|
|
|
197
268
|
*/
|
|
198
269
|
export function updateTrafficSecrets(currentSecret, cipherSuite) {
|
|
199
270
|
const hash = cipherSuiteToHash(cipherSuite);
|
|
200
|
-
const hashLen =
|
|
271
|
+
const hashLen = hashLengthFor(hash);
|
|
201
272
|
const nextSecret = hkdfExpandLabel(currentSecret, "traffic upd", new Uint8Array(0), hashLen, hash);
|
|
202
273
|
return deriveTrafficSecrets(nextSecret, cipherSuite, hash);
|
|
203
274
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keySchedule.js","sourceRoot":"","sources":["../../src/crypto/keySchedule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"keySchedule.js","sourceRoot":"","sources":["../../src/crypto/keySchedule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAe,MAAM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,IAAI,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IACpC,MAAM,UAAU,GAAG,eAAe,CAAC,aAAa,EAAE,aAAa,EAAE,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IACnG,OAAO,oBAAoB,CAAC,UAAU,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;AAC/D,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,wBAAwB,CAAC,QAAqB,EAAE,OAA+B;IAC3F,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,iBAAiB,CAAC,cAAc,EAAE;YACxC,KAAK,EAAE,IAAI,KAAK,CAAC,2CAA2C,QAAQ,EAAE,CAAC;SAC1E,CAAC,CAAC;IACP,CAAC;AACL,CAAC;AAED,qDAAqD;AACrD,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAA0B,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;AAEpF,gEAAgE;AAChE,MAAM,UAAU,sBAAsB,CAAC,QAAyB;IAC5D,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,iBAAiB,CAAC,cAAc,EAAE;YACxC,KAAK,EAAE,IAAI,KAAK,CAAC,iCAAiC,QAAQ,CAAC,IAAI,EAAE,CAAC;SACrE,CAAC,CAAC;IACP,CAAC;AACL,CAAC;AAED,KAAK,WAAW,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -48,6 +48,49 @@ export declare class TlsAlertError extends Error {
|
|
|
48
48
|
cause?: Error;
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* A code path that has not been implemented yet.
|
|
53
|
+
*
|
|
54
|
+
* Used by placeholder extension builders (and any future stubs) so the failure
|
|
55
|
+
* is a typed, identifiable error rather than a bare `Error`. The message keeps
|
|
56
|
+
* the "not implemented" phrase so existing `/not implemented/` assertions still
|
|
57
|
+
* match.
|
|
58
|
+
*/
|
|
59
|
+
export declare class NotImplementedError extends Error {
|
|
60
|
+
readonly kind: "NotImplementedError";
|
|
61
|
+
readonly feature: string;
|
|
62
|
+
readonly cause: Error | undefined;
|
|
63
|
+
constructor(feature: string, options?: {
|
|
64
|
+
cause?: Error;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/** A PEM block was missing the required BEGIN/END CERTIFICATE markers. */
|
|
68
|
+
export declare class TlsPemError extends Error {
|
|
69
|
+
readonly kind: "TlsPemError";
|
|
70
|
+
readonly cause: Error | undefined;
|
|
71
|
+
constructor(message: string, options?: {
|
|
72
|
+
cause?: Error;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/** A TLS key-schedule computation rejected its inputs (e.g. HKDF-Expand overflow). */
|
|
76
|
+
export declare class TlsKeyScheduleError extends Error {
|
|
77
|
+
readonly kind: "TlsKeyScheduleError";
|
|
78
|
+
readonly hash: string;
|
|
79
|
+
readonly cause: Error | undefined;
|
|
80
|
+
constructor(hash: string, message: string, options?: {
|
|
81
|
+
cause?: Error;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/** A TLS profile name could not be resolved. */
|
|
85
|
+
export declare class TlsProfileError extends Error {
|
|
86
|
+
readonly kind: "TlsProfileError";
|
|
87
|
+
/** The unresolved profile name. Named `profile` (not `name`) to avoid shadowing `Error.name`. */
|
|
88
|
+
readonly profile: string;
|
|
89
|
+
readonly cause: Error | undefined;
|
|
90
|
+
constructor(profile: string, options?: {
|
|
91
|
+
cause?: Error;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
51
94
|
/** Narrow a caught error to a typed TLS error, or wrap it in {@link TlsError}. */
|
|
52
95
|
export declare function ensureTlsError(e: unknown): TlsError;
|
|
53
96
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,2EAA2E;AAC3E,qBAAa,QAAS,SAAQ,KAAK;IAC/B,SAAgB,IAAI,EAAG,UAAU,CAAU;IAC3C,SAAgB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjD,6FAA6F;IAC7F,SAAyB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,2EAA2E;AAC3E,qBAAa,QAAS,SAAQ,KAAK;IAC/B,SAAgB,IAAI,EAAG,UAAU,CAAU;IAC3C,SAAgB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjD,6FAA6F;IAC7F,SAAyB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;IAElD,YACI,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACrC,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE,EAM9B;CACJ;AAED,yEAAyE;AACzE,MAAM,MAAM,cAAc,GACpB,cAAc,GACd,cAAc,GACd,aAAa,GACb,UAAU,CAAC;AAEjB,oDAAoD;AACpD,qBAAa,iBAAkB,SAAQ,KAAK;IACxC,SAAgB,IAAI,EAAG,mBAAmB,CAAU;IACpD,SAAgB,KAAK,EAAE,cAAc,CAAC;IACtC,SAAyB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;IAElD,YAAY,KAAK,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE,EAS7D;CACJ;AAED,+EAA+E;AAC/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