@browsercore/tls 0.1.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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +65 -0
  3. package/dist/certificates/certificates.d.ts +78 -0
  4. package/dist/certificates/certificates.d.ts.map +1 -0
  5. package/dist/certificates/certificates.js +692 -0
  6. package/dist/certificates/certificates.js.map +1 -0
  7. package/dist/crypto/keySchedule.d.ts +65 -0
  8. package/dist/crypto/keySchedule.d.ts.map +1 -0
  9. package/dist/crypto/keySchedule.js +197 -0
  10. package/dist/crypto/keySchedule.js.map +1 -0
  11. package/dist/errors.d.ts +53 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +72 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/extensions/extensions.d.ts +89 -0
  16. package/dist/extensions/extensions.d.ts.map +1 -0
  17. package/dist/extensions/extensions.js +141 -0
  18. package/dist/extensions/extensions.js.map +1 -0
  19. package/dist/handshake/handshake.d.ts +98 -0
  20. package/dist/handshake/handshake.d.ts.map +1 -0
  21. package/dist/handshake/handshake.js +366 -0
  22. package/dist/handshake/handshake.js.map +1 -0
  23. package/dist/index.d.ts +24 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +18 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/profiles/profiles.d.ts +28 -0
  28. package/dist/profiles/profiles.d.ts.map +1 -0
  29. package/dist/profiles/profiles.js +68 -0
  30. package/dist/profiles/profiles.js.map +1 -0
  31. package/dist/record/record.d.ts +80 -0
  32. package/dist/record/record.d.ts.map +1 -0
  33. package/dist/record/record.js +135 -0
  34. package/dist/record/record.js.map +1 -0
  35. package/dist/tls.d.ts +56 -0
  36. package/dist/tls.d.ts.map +1 -0
  37. package/dist/tls.js +102 -0
  38. package/dist/tls.js.map +1 -0
  39. package/dist/types.d.ts +157 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/dist/types.js +12 -0
  42. package/dist/types.js.map +1 -0
  43. package/dist/utils.d.ts +15 -0
  44. package/dist/utils.d.ts.map +1 -0
  45. package/dist/utils.js +20 -0
  46. package/dist/utils.js.map +1 -0
  47. package/package.json +51 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC5E,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EACH,QAAQ,EACR,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,cAAc,GACjB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9D,OAAO,EACH,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,OAAO,EACP,OAAO,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,KAAK,UAAU,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAElI,OAAO,EACH,WAAW,EACX,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,GACrB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,WAAW,IAAI,cAAc,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEjG,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC7F,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,IAAI,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5G,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3F,YAAY,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC3G,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAEjG,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAE5G,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @browsercore/tls — public API surface.
3
+ *
4
+ * A TLS 1.3 (and 1.2 fallback) client implemented entirely in TypeScript.
5
+ * Depends on @browsercore/transport and @browsercore/crypto — never node:crypto directly.
6
+ * Higher layers (http1, http2, fetch) compose exclusively through these exports.
7
+ */
8
+ export { connectTls, TlsConnectionImpl, generateKeyShares } from "./tls.js";
9
+ export { TlsError, TlsHandshakeError, TlsDecryptError, TlsAlertError, ensureTlsError, } from "./errors.js";
10
+ export { TLS_1_2, TLS_1_3, } from "./types.js";
11
+ export { MODERN_TLS13_PROFILE, COMPATIBILITY_PROFILE, getProfile, resolveProfile } from "./profiles/profiles.js";
12
+ export { ContentType, parseRecordHeader, serializeRecordHeader, cipherSuiteToAead, RECORD_HEADER_SIZE, } from "./record/record.js";
13
+ export { HandshakeType, buildClientHello, parseServerHello } from "./handshake/handshake.js";
14
+ export { ExtensionType, parseExtensions, findExtension } from "./extensions/extensions.js";
15
+ export { parseCertificate, validateHostname, verifyChain, pemToDer } from "./certificates/certificates.js";
16
+ export { hkdfExpandLabel, deriveHandshakeSecrets, deriveApplicationSecrets } from "./crypto/keySchedule.js";
17
+ export { assertNever } from "./utils.js";
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAG5E,OAAO,EACH,QAAQ,EACR,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,cAAc,GACjB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAcH,OAAO,EACP,OAAO,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAmB,oBAAoB,EAAE,qBAAqB,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAElI,OAAO,EACH,WAAW,EACX,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,GACrB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAG7F,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAG3F,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAG3G,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAE5G,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * ClientHello configuration profiles (placeholder).
3
+ *
4
+ * This module defines the local `TlsProfile` shape and a couple of example
5
+ * configurations. Once @browsercore/profiles is built, it becomes the single source
6
+ * of truth and this module will re-export from there. Keeping the shape here
7
+ * avoids a circular dependency while @browsercore/profiles is not yet ready.
8
+ */
9
+ import type { ClientHelloConfig } from "../types.js";
10
+ /**
11
+ * A TLS profile: a named, reusable ClientHello configuration.
12
+ * Higher layers (HTTP/2, fetch) select a profile by name.
13
+ */
14
+ export interface TlsProfile {
15
+ readonly name: string;
16
+ readonly config: ClientHelloConfig;
17
+ }
18
+ /** TLS 1.3 only, modern ciphers, X25519 + secp256r1 key shares. */
19
+ export declare const MODERN_TLS13_PROFILE: TlsProfile;
20
+ /** TLS 1.2 fallback profile for legacy servers. */
21
+ export declare const COMPATIBILITY_PROFILE: TlsProfile;
22
+ /** Registry of profiles by name. */
23
+ export declare const PROFILES: Readonly<Record<string, TlsProfile>>;
24
+ /** Look up a profile by name, or undefined if unknown. */
25
+ export declare function getProfile(name: string): TlsProfile | undefined;
26
+ /** Resolve a profile and fill in the serverName (which is connection-specific). */
27
+ export declare function resolveProfile(name: string, serverName: string): ClientHelloConfig;
28
+ //# sourceMappingURL=profiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profiles.d.ts","sourceRoot":"","sources":["../../src/profiles/profiles.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD;;;GAGG;AACH,MAAM,WAAW,UAAU;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;CACtC;AAED,mEAAmE;AACnE,eAAO,MAAM,oBAAoB,EAAE,UAiBlC,CAAC;AAEF,mDAAmD;AACnD,eAAO,MAAM,qBAAqB,EAAE,UAqBnC,CAAC;AAEF,oCAAoC;AACpC,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAGzD,CAAC;AAEF,0DAA0D;AAC1D,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAE/D;AAED,mFAAmF;AACnF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,iBAAiB,CAMlF"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * ClientHello configuration profiles (placeholder).
3
+ *
4
+ * This module defines the local `TlsProfile` shape and a couple of example
5
+ * configurations. Once @browsercore/profiles is built, it becomes the single source
6
+ * of truth and this module will re-export from there. Keeping the shape here
7
+ * avoids a circular dependency while @browsercore/profiles is not yet ready.
8
+ */
9
+ /** TLS 1.3 only, modern ciphers, X25519 + secp256r1 key shares. */
10
+ export const MODERN_TLS13_PROFILE = {
11
+ name: "modern-tls13",
12
+ config: {
13
+ cipherSuites: [
14
+ "TLS_AES_256_GCM_SHA384",
15
+ "TLS_AES_128_GCM_SHA256",
16
+ "TLS_CHACHA20_POLY1305_SHA256",
17
+ ],
18
+ keyShareGroups: ["x25519", "secp256r1"],
19
+ signatureAlgorithms: [
20
+ "ecdsa_secp256r1_sha256",
21
+ "rsa_pss_rsae_sha256",
22
+ "rsa_pss_rsae_sha384",
23
+ ],
24
+ supportedVersions: [{ name: "TLS 1.3", wire: 0x0304 }],
25
+ serverName: "",
26
+ },
27
+ };
28
+ /** TLS 1.2 fallback profile for legacy servers. */
29
+ export const COMPATIBILITY_PROFILE = {
30
+ name: "compatibility",
31
+ config: {
32
+ cipherSuites: [
33
+ "TLS_AES_256_GCM_SHA384",
34
+ "TLS_AES_128_GCM_SHA256",
35
+ "TLS_CHACHA20_POLY1305_SHA256",
36
+ ],
37
+ keyShareGroups: ["x25519", "secp256r1", "secp384r1"],
38
+ signatureAlgorithms: [
39
+ "ecdsa_secp256r1_sha256",
40
+ "ecdsa_secp384r1_sha384",
41
+ "rsa_pss_rsae_sha256",
42
+ "rsa_pkcs1_sha256",
43
+ ],
44
+ supportedVersions: [
45
+ { name: "TLS 1.3", wire: 0x0304 },
46
+ { name: "TLS 1.2", wire: 0x0303 },
47
+ ],
48
+ serverName: "",
49
+ },
50
+ };
51
+ /** Registry of profiles by name. */
52
+ export const PROFILES = {
53
+ [MODERN_TLS13_PROFILE.name]: MODERN_TLS13_PROFILE,
54
+ [COMPATIBILITY_PROFILE.name]: COMPATIBILITY_PROFILE,
55
+ };
56
+ /** Look up a profile by name, or undefined if unknown. */
57
+ export function getProfile(name) {
58
+ return PROFILES[name];
59
+ }
60
+ /** Resolve a profile and fill in the serverName (which is connection-specific). */
61
+ export function resolveProfile(name, serverName) {
62
+ const profile = PROFILES[name];
63
+ if (!profile) {
64
+ throw new Error(`unknown TLS profile: ${name}`);
65
+ }
66
+ return { ...profile.config, serverName };
67
+ }
68
+ //# sourceMappingURL=profiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profiles.js","sourceRoot":"","sources":["../../src/profiles/profiles.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAaH,mEAAmE;AACnE,MAAM,CAAC,MAAM,oBAAoB,GAAe;IAC5C,IAAI,EAAE,cAAc;IACpB,MAAM,EAAE;QACJ,YAAY,EAAE;YACV,wBAAwB;YACxB,wBAAwB;YACxB,8BAA8B;SACjC;QACD,cAAc,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC;QACvC,mBAAmB,EAAE;YACjB,wBAAwB;YACxB,qBAAqB;YACrB,qBAAqB;SACxB;QACD,iBAAiB,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QACtD,UAAU,EAAE,EAAE;KACjB;CACJ,CAAC;AAEF,mDAAmD;AACnD,MAAM,CAAC,MAAM,qBAAqB,GAAe;IAC7C,IAAI,EAAE,eAAe;IACrB,MAAM,EAAE;QACJ,YAAY,EAAE;YACV,wBAAwB;YACxB,wBAAwB;YACxB,8BAA8B;SACjC;QACD,cAAc,EAAE,CAAC,QAAQ,EAAE,WAAW,EAAE,WAAW,CAAC;QACpD,mBAAmB,EAAE;YACjB,wBAAwB;YACxB,wBAAwB;YACxB,qBAAqB;YACrB,kBAAkB;SACrB;QACD,iBAAiB,EAAE;YACf,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE;YACjC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE;SACpC;QACD,UAAU,EAAE,EAAE;KACjB;CACJ,CAAC;AAEF,oCAAoC;AACpC,MAAM,CAAC,MAAM,QAAQ,GAAyC;IAC1D,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,oBAAoB;IACjD,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,qBAAqB;CACtD,CAAC;AAEF,0DAA0D;AAC1D,MAAM,UAAU,UAAU,CAAC,IAAY;IACnC,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,UAAkB;IAC3D,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,wBAAwB,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * TLS record layer (RFC 8446 §5, RFC 5246 §6.2).
3
+ *
4
+ * Frames all higher-layer protocol messages (handshake, alert, change_cipher_spec,
5
+ * application_data) into typed records. Encryption/decryption of the record
6
+ * payload is delegated to @browsercore/crypto — this module owns framing only.
7
+ */
8
+ import type { AeadAlgorithm, CipherSuite } from "../types.js";
9
+ /** TLS record content types, per RFC 8446 §5.1. */
10
+ export declare const ContentType: {
11
+ readonly CHANGE_CIPHER_SPEC: 20;
12
+ readonly ALERT: 21;
13
+ readonly HANDSHAKE: 22;
14
+ readonly APPLICATION_DATA: 23;
15
+ };
16
+ /** Union of valid content-type values. */
17
+ export type ContentType = (typeof ContentType)[keyof typeof ContentType];
18
+ /** On-the-wire record header (5 bytes). */
19
+ export interface RecordHeader {
20
+ readonly type: ContentType;
21
+ /** Legacy record version (0x0303 for TLS 1.2/1.3). */
22
+ readonly version: number;
23
+ /** Length of the fragment that follows (uint16). */
24
+ readonly length: number;
25
+ }
26
+ /** A fully parsed record: header + (still possibly encrypted) fragment. */
27
+ export interface TlsRecord {
28
+ readonly header: RecordHeader;
29
+ readonly fragment: Uint8Array;
30
+ }
31
+ /** Size of a TLS record header in bytes. */
32
+ export declare const RECORD_HEADER_SIZE: 5;
33
+ /** Maximum plaintext fragment length allowed by TLS (2^14). */
34
+ export declare const MAX_PLAINTEXT_FRAGMENT: 16384;
35
+ /** Map a cipher suite to its AEAD algorithm. */
36
+ export declare function cipherSuiteToAead(cipherSuite: CipherSuite): AeadAlgorithm;
37
+ /**
38
+ * Parse a 5-byte record header from the start of a buffer.
39
+ * Throws {@link TlsDecryptError} if the buffer is too short.
40
+ */
41
+ export declare function parseRecordHeader(buf: Uint8Array): RecordHeader;
42
+ /**
43
+ * Serialize a record header into a 5-byte buffer.
44
+ *
45
+ * @param type Content type.
46
+ * @param length Fragment length (must fit in uint16).
47
+ * @param version Legacy record version, defaults to 0x0303.
48
+ */
49
+ export declare function serializeRecordHeader(type: ContentType, length: number, version?: number): Uint8Array;
50
+ /**
51
+ * Encrypt a plaintext fragment with the negotiated AEAD algorithm.
52
+ *
53
+ * The TLS 1.3 record layer appends the inner content type to `plaintext` BEFORE
54
+ * calling this function and uses the 5-byte record header as the AEAD
55
+ * `additionalData`; this function is the pure AEAD step that delegates to
56
+ * @browsercore/crypto. The outer record type (APPLICATION_DATA in TLS 1.3) is the
57
+ * caller's responsibility.
58
+ *
59
+ * @param plaintext Data to encrypt (caller has already appended the inner content type).
60
+ * @param key AEAD key for this direction.
61
+ * @param nonce Per-record nonce (already XOR'd with the sequence number).
62
+ * @param additionalData The 5-byte record header, used as the AEAD AAD.
63
+ * @param algorithm AEAD algorithm negotiated for this connection.
64
+ */
65
+ export declare function encryptRecord(plaintext: Uint8Array, key: Uint8Array, nonce: Uint8Array, additionalData: Uint8Array, algorithm: AeadAlgorithm): Uint8Array;
66
+ /**
67
+ * Decrypt a TLSCiphertext fragment with the negotiated AEAD algorithm.
68
+ *
69
+ * The TLS 1.3 record layer strips the trailing inner content type byte from the
70
+ * returned plaintext and verifies it; this function is the pure AEAD step that
71
+ * delegates to @browsercore/crypto, throwing {@link TlsDecryptError} on auth failure.
72
+ *
73
+ * @param ciphertext Ciphertext with the 16-byte authentication tag appended.
74
+ * @param key AEAD key for this direction.
75
+ * @param nonce Per-record nonce (already XOR'd with the sequence number).
76
+ * @param additionalData The 5-byte record header, used as the AEAD AAD.
77
+ * @param algorithm AEAD algorithm negotiated for this connection.
78
+ */
79
+ export declare function decryptRecord(ciphertext: Uint8Array, key: Uint8Array, nonce: Uint8Array, additionalData: Uint8Array, algorithm: AeadAlgorithm): Uint8Array;
80
+ //# sourceMappingURL=record.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../src/record/record.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI9D,mDAAmD;AACnD,eAAO,MAAM,WAAW;;;;;CAKd,CAAC;AAEX,0CAA0C;AAC1C,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAEzE,2CAA2C;AAC3C,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,sDAAsD;IACtD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CAC3B;AAED,2EAA2E;AAC3E,MAAM,WAAW,SAAS;IACtB,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;CACjC;AAED,4CAA4C;AAC5C,eAAO,MAAM,kBAAkB,EAAG,CAAU,CAAC;AAE7C,+DAA+D;AAC/D,eAAO,MAAM,sBAAsB,EAAG,KAAe,CAAC;AAEtD,gDAAgD;AAChD,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,WAAW,GAAG,aAAa,CAUzE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,GAAG,YAAY,CAkB/D;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACjC,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,MAAM,EACd,OAAO,SAAS,GACjB,UAAU,CAQZ;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CACzB,SAAS,EAAE,UAAU,EACrB,GAAG,EAAE,UAAU,EACf,KAAK,EAAE,UAAU,EACjB,cAAc,EAAE,UAAU,EAC1B,SAAS,EAAE,aAAa,GACzB,UAAU,CAWZ;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CACzB,UAAU,EAAE,UAAU,EACtB,GAAG,EAAE,UAAU,EACf,KAAK,EAAE,UAAU,EACjB,cAAc,EAAE,UAAU,EAC1B,SAAS,EAAE,aAAa,GACzB,UAAU,CAsBZ"}
@@ -0,0 +1,135 @@
1
+ /**
2
+ * TLS record layer (RFC 8446 §5, RFC 5246 §6.2).
3
+ *
4
+ * Frames all higher-layer protocol messages (handshake, alert, change_cipher_spec,
5
+ * application_data) into typed records. Encryption/decryption of the record
6
+ * payload is delegated to @browsercore/crypto — this module owns framing only.
7
+ */
8
+ import { crypto } from "@browsercore/crypto";
9
+ import { TlsDecryptError } from "../errors.js";
10
+ import { assertNever } from "../utils.js";
11
+ /** TLS record content types, per RFC 8446 §5.1. */
12
+ export const ContentType = {
13
+ CHANGE_CIPHER_SPEC: 20,
14
+ ALERT: 21,
15
+ HANDSHAKE: 22,
16
+ APPLICATION_DATA: 23,
17
+ };
18
+ /** Size of a TLS record header in bytes. */
19
+ export const RECORD_HEADER_SIZE = 5;
20
+ /** Maximum plaintext fragment length allowed by TLS (2^14). */
21
+ export const MAX_PLAINTEXT_FRAGMENT = 16_384;
22
+ /** Map a cipher suite to its AEAD algorithm. */
23
+ export function cipherSuiteToAead(cipherSuite) {
24
+ switch (cipherSuite) {
25
+ case "TLS_AES_128_GCM_SHA256":
26
+ case "TLS_AES_128_CCM_SHA256":
27
+ return "AES-128-GCM";
28
+ case "TLS_AES_256_GCM_SHA384":
29
+ return "AES-256-GCM";
30
+ case "TLS_CHACHA20_POLY1305_SHA256":
31
+ return "CHACHA20-POLY1305";
32
+ }
33
+ }
34
+ /**
35
+ * Parse a 5-byte record header from the start of a buffer.
36
+ * Throws {@link TlsDecryptError} if the buffer is too short.
37
+ */
38
+ export function parseRecordHeader(buf) {
39
+ if (buf.length < RECORD_HEADER_SIZE) {
40
+ throw new TlsDecryptError("record", {
41
+ cause: new Error(`record header truncated: ${buf.length} < ${RECORD_HEADER_SIZE}`),
42
+ });
43
+ }
44
+ const type = buf[0];
45
+ if (type !== ContentType.CHANGE_CIPHER_SPEC &&
46
+ type !== ContentType.ALERT &&
47
+ type !== ContentType.HANDSHAKE &&
48
+ type !== ContentType.APPLICATION_DATA) {
49
+ throw new TlsDecryptError("record", { cause: new Error(`invalid content type: ${type}`) });
50
+ }
51
+ const version = (buf[1] << 8) | buf[2];
52
+ const length = (buf[3] << 8) | buf[4];
53
+ return { type, version, length };
54
+ }
55
+ /**
56
+ * Serialize a record header into a 5-byte buffer.
57
+ *
58
+ * @param type Content type.
59
+ * @param length Fragment length (must fit in uint16).
60
+ * @param version Legacy record version, defaults to 0x0303.
61
+ */
62
+ export function serializeRecordHeader(type, length, version = 0x0303) {
63
+ const out = new Uint8Array(RECORD_HEADER_SIZE);
64
+ out[0] = type;
65
+ out[1] = (version >> 8) & 0xff;
66
+ out[2] = version & 0xff;
67
+ out[3] = (length >> 8) & 0xff;
68
+ out[4] = length & 0xff;
69
+ return out;
70
+ }
71
+ /**
72
+ * Encrypt a plaintext fragment with the negotiated AEAD algorithm.
73
+ *
74
+ * The TLS 1.3 record layer appends the inner content type to `plaintext` BEFORE
75
+ * calling this function and uses the 5-byte record header as the AEAD
76
+ * `additionalData`; this function is the pure AEAD step that delegates to
77
+ * @browsercore/crypto. The outer record type (APPLICATION_DATA in TLS 1.3) is the
78
+ * caller's responsibility.
79
+ *
80
+ * @param plaintext Data to encrypt (caller has already appended the inner content type).
81
+ * @param key AEAD key for this direction.
82
+ * @param nonce Per-record nonce (already XOR'd with the sequence number).
83
+ * @param additionalData The 5-byte record header, used as the AEAD AAD.
84
+ * @param algorithm AEAD algorithm negotiated for this connection.
85
+ */
86
+ export function encryptRecord(plaintext, key, nonce, additionalData, algorithm) {
87
+ switch (algorithm) {
88
+ case "AES-128-GCM":
89
+ return crypto.aes128GcmEncrypt(key, nonce, plaintext, additionalData);
90
+ case "AES-256-GCM":
91
+ return crypto.aes256GcmEncrypt(key, nonce, plaintext, additionalData);
92
+ case "CHACHA20-POLY1305":
93
+ return crypto.chacha20Poly1305Encrypt(key, nonce, plaintext, additionalData);
94
+ default:
95
+ return assertNever(algorithm);
96
+ }
97
+ }
98
+ /**
99
+ * Decrypt a TLSCiphertext fragment with the negotiated AEAD algorithm.
100
+ *
101
+ * The TLS 1.3 record layer strips the trailing inner content type byte from the
102
+ * returned plaintext and verifies it; this function is the pure AEAD step that
103
+ * delegates to @browsercore/crypto, throwing {@link TlsDecryptError} on auth failure.
104
+ *
105
+ * @param ciphertext Ciphertext with the 16-byte authentication tag appended.
106
+ * @param key AEAD key for this direction.
107
+ * @param nonce Per-record nonce (already XOR'd with the sequence number).
108
+ * @param additionalData The 5-byte record header, used as the AEAD AAD.
109
+ * @param algorithm AEAD algorithm negotiated for this connection.
110
+ */
111
+ export function decryptRecord(ciphertext, key, nonce, additionalData, algorithm) {
112
+ try {
113
+ switch (algorithm) {
114
+ case "AES-128-GCM":
115
+ return crypto.aes128GcmDecrypt(key, nonce, ciphertext, additionalData);
116
+ case "AES-256-GCM":
117
+ return crypto.aes256GcmDecrypt(key, nonce, ciphertext, additionalData);
118
+ case "CHACHA20-POLY1305":
119
+ return crypto.chacha20Poly1305Decrypt(key, nonce, ciphertext, additionalData);
120
+ default:
121
+ return assertNever(algorithm);
122
+ }
123
+ }
124
+ catch (cause) {
125
+ // @browsercore/crypto throws its own DecryptError on auth failure; translate it
126
+ // into the TLS-layer typed error so callers see a consistent error type.
127
+ // Under exactOptionalPropertyTypes, `cause` must be `Error` (never undefined)
128
+ // when passed in the options object — omit the key entirely otherwise.
129
+ if (cause instanceof Error) {
130
+ throw new TlsDecryptError(algorithm, { cause });
131
+ }
132
+ throw new TlsDecryptError(algorithm);
133
+ }
134
+ }
135
+ //# sourceMappingURL=record.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record.js","sourceRoot":"","sources":["../../src/record/record.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,mDAAmD;AACnD,MAAM,CAAC,MAAM,WAAW,GAAG;IACvB,kBAAkB,EAAE,EAAE;IACtB,KAAK,EAAE,EAAE;IACT,SAAS,EAAE,EAAE;IACb,gBAAgB,EAAE,EAAE;CACd,CAAC;AAoBX,4CAA4C;AAC5C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAU,CAAC;AAE7C,+DAA+D;AAC/D,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAe,CAAC;AAEtD,gDAAgD;AAChD,MAAM,UAAU,iBAAiB,CAAC,WAAwB;IACtD,QAAQ,WAAW,EAAE,CAAC;QAClB,KAAK,wBAAwB,CAAC;QAC9B,KAAK,wBAAwB;YACzB,OAAO,aAAa,CAAC;QACzB,KAAK,wBAAwB;YACzB,OAAO,aAAa,CAAC;QACzB,KAAK,8BAA8B;YAC/B,OAAO,mBAA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CAAC,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC;YAClF;gBACI,OAAO,WAAW,CAAC,SAAS,CAAC,CAAC;QACtC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,gFAAgF;QAChF,yEAAyE;QACzE,8EAA8E;QAC9E,uEAAuE;QACvE,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YACzB,MAAM,IAAI,eAAe,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACpD,CAAC;QACD,MAAM,IAAI,eAAe,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC;AACL,CAAC"}
package/dist/tls.d.ts ADDED
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @browsercore/tls — public entry point.
3
+ *
4
+ * Establishes a TLS 1.3 (with 1.2 fallback) connection over an existing
5
+ * byte-stream transport. Wires together the record layer, handshake state
6
+ * machine, key schedule, and certificate validation — consuming @browsercore/transport
7
+ * and @browsercore/crypto, never node:crypto directly.
8
+ */
9
+ import type { CloseReason, KeyPair, TlsConnection, TlsOptions, TlsSessionId, TlsState } from "./types.js";
10
+ import type { TlsError } from "./errors.js";
11
+ /**
12
+ * Establish a TLS connection over the given transport.
13
+ *
14
+ * Performs the full TLS 1.3 handshake (falling back to 1.2 if the server does
15
+ * not support 1.3), derives traffic secrets, and returns a {@link TlsConnection}
16
+ * that transparently encrypts/decrypts application data.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const transport = await connect({ host: "example.com", port: 443 });
21
+ * const tls = await connectTls({
22
+ * transport,
23
+ * serverName: "example.com",
24
+ * profile: resolveProfile("modern-tls13", "example.com"),
25
+ * alpnProtocols: ["h2", "http/1.1"],
26
+ * });
27
+ * await tls.write(new TextEncoder().encode("GET / HTTP/1.1\r\n"));
28
+ * const chunk = await tls.read();
29
+ * await tls.close();
30
+ * ```
31
+ */
32
+ export declare function connectTls(options: TlsOptions): Promise<TlsConnection>;
33
+ /** Concrete TLS connection implementation (filled in per PLAN.md). */
34
+ export declare class TlsConnectionImpl implements TlsConnection {
35
+ readonly id: TlsSessionId;
36
+ state: TlsState;
37
+ readonly protocolVersion: {
38
+ readonly name: "TLS 1.3";
39
+ readonly wire: 772;
40
+ };
41
+ readonly cipherSuite: "TLS_AES_128_GCM_SHA256";
42
+ readonly alpnProtocol?: string;
43
+ private readonly _transport;
44
+ private readonly _applicationSecrets;
45
+ constructor();
46
+ read(): Promise<{
47
+ payload: Uint8Array;
48
+ }>;
49
+ write(_data: Uint8Array): Promise<void>;
50
+ close(): Promise<void>;
51
+ on(_event: "close" | "error", _listener: (arg: CloseReason | TlsError) => void): this;
52
+ private _ensureOpen;
53
+ }
54
+ /** Generate key shares for the requested groups (delegates to @browsercore/crypto). */
55
+ export declare function generateKeyShares(groups: readonly string[]): Promise<KeyPair[]>;
56
+ //# sourceMappingURL=tls.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tls.d.ts","sourceRoot":"","sources":["../src/tls.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAER,WAAW,EACX,OAAO,EACP,aAAa,EACb,UAAU,EACV,YAAY,EACZ,QAAQ,EACX,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAS5C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,CAqB5E;AAED,sEAAsE;AACtE,qBAAa,iBAAkB,YAAW,aAAa;IACnD,SAAgB,EAAE,EAAE,YAAY,CAAmC;IAC5D,KAAK,EAAE,QAAQ,CAA2B;IACjD,SAAgB,eAAe;;;MAAC;IAChC,SAAgB,WAAW,2BAAC;IAC5B,SAAgB,YAAY,CAAC,EAAE,MAAM,CAAC;IAItC,iBAAyB,UAAU,CAAY;IAC/C,iBAAyB,mBAAmB,CAA4B;;IAQ3D,IAAI,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,UAAU,CAAA;KAAE,CAAC;IAMxC,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAMvC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,EAAE,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,EAAE,SAAS,EAAE,CAAC,GAAG,EAAE,WAAW,GAAG,QAAQ,KAAK,IAAI,GAAG,IAAI;IAM5F,OAAO,CAAC,WAAW;CAOtB;AAED,uFAAuF;AACvF,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAIrF"}
package/dist/tls.js ADDED
@@ -0,0 +1,102 @@
1
+ /**
2
+ * @browsercore/tls — public entry point.
3
+ *
4
+ * Establishes a TLS 1.3 (with 1.2 fallback) connection over an existing
5
+ * byte-stream transport. Wires together the record layer, handshake state
6
+ * machine, key schedule, and certificate validation — consuming @browsercore/transport
7
+ * and @browsercore/crypto, never node:crypto directly.
8
+ */
9
+ import { TlsHandshakeError } from "./errors.js";
10
+ import { createId } from "./utils.js";
11
+ import { parseRecordHeader, serializeRecordHeader, RECORD_HEADER_SIZE } from "./record/record.js";
12
+ import { buildClientHello, parseServerHello } from "./handshake/handshake.js";
13
+ /** Default handshake timeout in milliseconds. */
14
+ const DEFAULT_HANDSHAKE_TIMEOUT_MS = 10_000;
15
+ /**
16
+ * Establish a TLS connection over the given transport.
17
+ *
18
+ * Performs the full TLS 1.3 handshake (falling back to 1.2 if the server does
19
+ * not support 1.3), derives traffic secrets, and returns a {@link TlsConnection}
20
+ * that transparently encrypts/decrypts application data.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const transport = await connect({ host: "example.com", port: 443 });
25
+ * const tls = await connectTls({
26
+ * transport,
27
+ * serverName: "example.com",
28
+ * profile: resolveProfile("modern-tls13", "example.com"),
29
+ * alpnProtocols: ["h2", "http/1.1"],
30
+ * });
31
+ * await tls.write(new TextEncoder().encode("GET / HTTP/1.1\r\n"));
32
+ * const chunk = await tls.read();
33
+ * await tls.close();
34
+ * ```
35
+ */
36
+ export async function connectTls(options) {
37
+ // PLAN: implement the full handshake:
38
+ // 1. Generate key shares for each group in options.profile.keyShareGroups
39
+ // via @browsercore/crypto -> KeyPair[].
40
+ // 2. buildClientHello(options.profile, keyPairs) -> write handshake record.
41
+ // 3. Read ServerHello record -> parseServerHello.
42
+ // 4. (EC)DHE key exchange via @browsercore/crypto -> sharedSecret.
43
+ // 5. deriveHandshakeSecrets / deriveApplicationSecrets.
44
+ // 6. Read + decrypt EncryptedExtensions, Certificate, CertificateVerify, Finished.
45
+ // 7. verifyChain against trust anchors + serverName.
46
+ // 8. Send client Finished. Transition state to "open".
47
+ // Drive TlsState through connecting -> handshaking -> open.
48
+ const handshakeTimeoutMs = options.handshakeTimeoutMs ?? DEFAULT_HANDSHAKE_TIMEOUT_MS;
49
+ void handshakeTimeoutMs;
50
+ void options;
51
+ void parseRecordHeader;
52
+ void serializeRecordHeader;
53
+ void RECORD_HEADER_SIZE;
54
+ void buildClientHello;
55
+ void parseServerHello;
56
+ throw new Error("not implemented — see PLAN.md");
57
+ }
58
+ /** Concrete TLS connection implementation (filled in per PLAN.md). */
59
+ export class TlsConnectionImpl {
60
+ id = createId("tls");
61
+ state = { state: "connecting" };
62
+ protocolVersion;
63
+ cipherSuite;
64
+ alpnProtocol;
65
+ constructor() {
66
+ // Placeholder values so the readonly fields are initialized.
67
+ this.protocolVersion = { name: "TLS 1.3", wire: 0x0304 };
68
+ this.cipherSuite = "TLS_AES_128_GCM_SHA256";
69
+ }
70
+ async read() {
71
+ this._ensureOpen();
72
+ void this._applicationSecrets;
73
+ throw new Error("not implemented — see PLAN.md");
74
+ }
75
+ async write(_data) {
76
+ this._ensureOpen();
77
+ void this._transport;
78
+ throw new Error("not implemented — see PLAN.md");
79
+ }
80
+ async close() {
81
+ throw new Error("not implemented — see PLAN.md");
82
+ }
83
+ on(_event, _listener) {
84
+ void _event;
85
+ void _listener;
86
+ throw new Error("not implemented — see PLAN.md");
87
+ }
88
+ _ensureOpen() {
89
+ if (this.state.state !== "open") {
90
+ throw new TlsHandshakeError("finished", {
91
+ cause: new Error(`connection not open (state: ${this.state.state})`),
92
+ });
93
+ }
94
+ }
95
+ }
96
+ /** Generate key shares for the requested groups (delegates to @browsercore/crypto). */
97
+ export async function generateKeyShares(groups) {
98
+ // PLAN: for each group call @browsercore/crypto generateKeyPair(group).
99
+ void groups;
100
+ throw new Error("not implemented — see PLAN.md");
101
+ }
102
+ //# sourceMappingURL=tls.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tls.js","sourceRoot":"","sources":["../src/tls.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAaH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAClG,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE9E,iDAAiD;AACjD,MAAM,4BAA4B,GAAG,MAAM,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAmB;IAChD,sCAAsC;IACtC,4EAA4E;IAC5E,6CAA6C;IAC7C,8EAA8E;IAC9E,oDAAoD;IACpD,qEAAqE;IACrE,0DAA0D;IAC1D,qFAAqF;IACrF,uDAAuD;IACvD,yDAAyD;IACzD,8DAA8D;IAC9D,MAAM,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,IAAI,4BAA4B,CAAC;IACtF,KAAK,kBAAkB,CAAC;IACxB,KAAK,OAAO,CAAC;IACb,KAAK,iBAAiB,CAAC;IACvB,KAAK,qBAAqB,CAAC;IAC3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