@browsercore/tls 0.1.2 → 0.1.9

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 (104) hide show
  1. package/README.md +104 -4
  2. package/dist/certificates/cert-extensions.d.ts +46 -0
  3. package/dist/certificates/cert-extensions.d.ts.map +1 -0
  4. package/dist/certificates/cert-extensions.js +203 -0
  5. package/dist/certificates/cert-extensions.js.map +1 -0
  6. package/dist/certificates/certificates.d.ts +11 -9
  7. package/dist/certificates/certificates.d.ts.map +1 -1
  8. package/dist/certificates/certificates.js +75 -503
  9. package/dist/certificates/certificates.js.map +1 -1
  10. package/dist/certificates/der.d.ts +43 -0
  11. package/dist/certificates/der.d.ts.map +1 -0
  12. package/dist/certificates/der.js +204 -0
  13. package/dist/certificates/der.js.map +1 -0
  14. package/dist/certificates/hostname.d.ts +21 -0
  15. package/dist/certificates/hostname.d.ts.map +1 -0
  16. package/dist/certificates/hostname.js +46 -0
  17. package/dist/certificates/hostname.js.map +1 -0
  18. package/dist/certificates/pem.d.ts +11 -0
  19. package/dist/certificates/pem.d.ts.map +1 -0
  20. package/dist/certificates/pem.js +69 -0
  21. package/dist/certificates/pem.js.map +1 -0
  22. package/dist/connection/handshake-driver.d.ts +59 -0
  23. package/dist/connection/handshake-driver.d.ts.map +1 -0
  24. package/dist/connection/handshake-driver.js +137 -0
  25. package/dist/connection/handshake-driver.js.map +1 -0
  26. package/dist/connection/handshake-messages.d.ts +45 -0
  27. package/dist/connection/handshake-messages.d.ts.map +1 -0
  28. package/dist/connection/handshake-messages.js +170 -0
  29. package/dist/connection/handshake-messages.js.map +1 -0
  30. package/dist/connection/index.d.ts +19 -0
  31. package/dist/connection/index.d.ts.map +1 -0
  32. package/dist/connection/index.js +19 -0
  33. package/dist/connection/index.js.map +1 -0
  34. package/dist/connection/key-exchange.d.ts +24 -0
  35. package/dist/connection/key-exchange.d.ts.map +1 -0
  36. package/dist/connection/key-exchange.js +104 -0
  37. package/dist/connection/key-exchange.js.map +1 -0
  38. package/dist/connection/lifecycle.d.ts +38 -0
  39. package/dist/connection/lifecycle.d.ts.map +1 -0
  40. package/dist/connection/lifecycle.js +101 -0
  41. package/dist/connection/lifecycle.js.map +1 -0
  42. package/dist/connection/record-layer.d.ts +65 -0
  43. package/dist/connection/record-layer.d.ts.map +1 -0
  44. package/dist/connection/record-layer.js +140 -0
  45. package/dist/connection/record-layer.js.map +1 -0
  46. package/dist/crypto/keySchedule.d.ts +18 -3
  47. package/dist/crypto/keySchedule.d.ts.map +1 -1
  48. package/dist/crypto/keySchedule.js +82 -11
  49. package/dist/crypto/keySchedule.js.map +1 -1
  50. package/dist/errors.d.ts +43 -0
  51. package/dist/errors.d.ts.map +1 -1
  52. package/dist/errors.js +60 -2
  53. package/dist/errors.js.map +1 -1
  54. package/dist/extensions/extensions.d.ts +26 -25
  55. package/dist/extensions/extensions.d.ts.map +1 -1
  56. package/dist/extensions/extensions.js +92 -49
  57. package/dist/extensions/extensions.js.map +1 -1
  58. package/dist/handshake/client-hello.d.ts +30 -0
  59. package/dist/handshake/client-hello.d.ts.map +1 -0
  60. package/dist/handshake/client-hello.js +464 -0
  61. package/dist/handshake/client-hello.js.map +1 -0
  62. package/dist/handshake/grease.d.ts +70 -0
  63. package/dist/handshake/grease.d.ts.map +1 -0
  64. package/dist/handshake/grease.js +293 -0
  65. package/dist/handshake/grease.js.map +1 -0
  66. package/dist/handshake/handshake-types.d.ts +84 -0
  67. package/dist/handshake/handshake-types.d.ts.map +1 -0
  68. package/dist/handshake/handshake-types.js +31 -0
  69. package/dist/handshake/handshake-types.js.map +1 -0
  70. package/dist/handshake/handshake.d.ts +19 -118
  71. package/dist/handshake/handshake.d.ts.map +1 -1
  72. package/dist/handshake/handshake.js +19 -412
  73. package/dist/handshake/handshake.js.map +1 -1
  74. package/dist/handshake/server-hello.d.ts +33 -0
  75. package/dist/handshake/server-hello.d.ts.map +1 -0
  76. package/dist/handshake/server-hello.js +134 -0
  77. package/dist/handshake/server-hello.js.map +1 -0
  78. package/dist/handshake/state-machine.d.ts +34 -0
  79. package/dist/handshake/state-machine.d.ts.map +1 -0
  80. package/dist/handshake/state-machine.js +105 -0
  81. package/dist/handshake/state-machine.js.map +1 -0
  82. package/dist/index.d.ts +1 -1
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +1 -1
  85. package/dist/index.js.map +1 -1
  86. package/dist/profiles/profiles.d.ts +12 -2
  87. package/dist/profiles/profiles.d.ts.map +1 -1
  88. package/dist/profiles/profiles.js +22 -7
  89. package/dist/profiles/profiles.js.map +1 -1
  90. package/dist/record/record.d.ts +18 -1
  91. package/dist/record/record.d.ts.map +1 -1
  92. package/dist/record/record.js +79 -11
  93. package/dist/record/record.js.map +1 -1
  94. package/dist/tls.d.ts +62 -101
  95. package/dist/tls.d.ts.map +1 -1
  96. package/dist/tls.js +166 -566
  97. package/dist/tls.js.map +1 -1
  98. package/dist/types.d.ts +40 -6
  99. package/dist/types.d.ts.map +1 -1
  100. package/dist/utils.d.ts +7 -0
  101. package/dist/utils.d.ts.map +1 -1
  102. package/dist/utils.js +23 -0
  103. package/dist/utils.js.map +1 -1
  104. package/package.json +53 -48
@@ -0,0 +1,34 @@
1
+ /**
2
+ * TLS handshake state machine (RFC 8446 §4).
3
+ *
4
+ * Tracks the client's progress through the server's flight of messages
5
+ * (ServerHello -> EncryptedExtensions -> Certificate -> CertificateVerify ->
6
+ * Finished) and validates every transition, so an out-of-order or repeated
7
+ * message is rejected at the type level rather than corrupting handshake state.
8
+ *
9
+ * Also hosts the small predicate helpers over {@link NamedGroup} and
10
+ * {@link ProtocolVersion} that the handshake layer needs — kept here (rather
11
+ * than in types.ts) because they are handshake-layer decisions, not pure type
12
+ * facts.
13
+ */
14
+ import type { NamedGroup, ProtocolVersion } from "../types.js";
15
+ import { HandshakeType, type HandshakePhase, type ServerHello } from "./handshake-types.js";
16
+ /**
17
+ * Transition the handshake state machine given the next received message type.
18
+ * Returns the next phase, or throws {@link TlsHandshakeError} on an invalid
19
+ * transition (making invalid state sequences unrepresentable).
20
+ */
21
+ export declare function advanceHandshake(current: HandshakePhase, received: HandshakeType): HandshakePhase;
22
+ /**
23
+ * Record the parsed ServerHello and transition from "client_hello_sent" to
24
+ * "server_hello_received". Separated from {@link advanceHandshake} because the
25
+ * state machine needs to carry the parsed ServerHello forward.
26
+ */
27
+ export declare function recordServerHello(_current: HandshakePhase, serverHello: ServerHello): HandshakePhase;
28
+ /** Mark the handshake as complete (after client Finished is sent). */
29
+ export declare function completeHandshake(_current: HandshakePhase): HandshakePhase;
30
+ /** True if the named group is a (EC)DHE group usable for TLS 1.3 key share. */
31
+ export declare function isKeyShareGroup(group: NamedGroup): boolean;
32
+ /** True if the protocol version is TLS 1.3. */
33
+ export declare function isTls13(version: ProtocolVersion): boolean;
34
+ //# sourceMappingURL=state-machine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state-machine.d.ts","sourceRoot":"","sources":["../../src/handshake/state-machine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG/D,OAAO,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAE5F;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,aAAa,GAAG,cAAc,CAsDjG;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,GAAG,cAAc,CAGpG;AAED,sEAAsE;AACtE,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,cAAc,GAAG,cAAc,CAG1E;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAU1D;AAED,+CAA+C;AAC/C,wBAAgB,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAEzD"}
@@ -0,0 +1,105 @@
1
+ /**
2
+ * TLS handshake state machine (RFC 8446 §4).
3
+ *
4
+ * Tracks the client's progress through the server's flight of messages
5
+ * (ServerHello -> EncryptedExtensions -> Certificate -> CertificateVerify ->
6
+ * Finished) and validates every transition, so an out-of-order or repeated
7
+ * message is rejected at the type level rather than corrupting handshake state.
8
+ *
9
+ * Also hosts the small predicate helpers over {@link NamedGroup} and
10
+ * {@link ProtocolVersion} that the handshake layer needs — kept here (rather
11
+ * than in types.ts) because they are handshake-layer decisions, not pure type
12
+ * facts.
13
+ */
14
+ import { TlsHandshakeError } from "../errors.js";
15
+ import { assertNever } from "../utils.js";
16
+ import { HandshakeType } from "./handshake-types.js";
17
+ /**
18
+ * Transition the handshake state machine given the next received message type.
19
+ * Returns the next phase, or throws {@link TlsHandshakeError} on an invalid
20
+ * transition (making invalid state sequences unrepresentable).
21
+ */
22
+ export function advanceHandshake(current, received) {
23
+ switch (current.phase) {
24
+ case "start":
25
+ throw new TlsHandshakeError("client_hello", {
26
+ cause: new Error("expected client_hello_sent as the first transition"),
27
+ });
28
+ case "client_hello_sent":
29
+ if (received !== HandshakeType.SERVER_HELLO) {
30
+ throw new TlsHandshakeError("server_hello", {
31
+ cause: new Error(`expected SERVER_HELLO after client_hello_sent, got ${received}`),
32
+ });
33
+ }
34
+ // The caller must call `recordServerHello` to attach the parsed ServerHello.
35
+ throw new TlsHandshakeError("server_hello", {
36
+ cause: new Error("use recordServerHello(serverHello) to transition client_hello_sent -> server_hello_received"),
37
+ });
38
+ case "server_hello_received":
39
+ if (received !== HandshakeType.ENCRYPTED_EXTENSIONS) {
40
+ throw new TlsHandshakeError("server_hello", {
41
+ cause: new Error(`expected ENCRYPTED_EXTENSIONS, got ${received}`),
42
+ });
43
+ }
44
+ return { phase: "encrypted_extensions_received" };
45
+ case "encrypted_extensions_received":
46
+ if (received !== HandshakeType.CERTIFICATE) {
47
+ throw new TlsHandshakeError("certificate", {
48
+ cause: new Error(`expected CERTIFICATE, got ${received}`),
49
+ });
50
+ }
51
+ return { phase: "certificate_received" };
52
+ case "certificate_received":
53
+ if (received !== HandshakeType.CERTIFICATE_VERIFY) {
54
+ throw new TlsHandshakeError("certificate", {
55
+ cause: new Error(`expected CERTIFICATE_VERIFY, got ${received}`),
56
+ });
57
+ }
58
+ return { phase: "certificate_verify_received" };
59
+ case "certificate_verify_received":
60
+ if (received !== HandshakeType.FINISHED) {
61
+ throw new TlsHandshakeError("finished", {
62
+ cause: new Error(`expected FINISHED, got ${received}`),
63
+ });
64
+ }
65
+ return { phase: "finished_received" };
66
+ case "finished_received":
67
+ case "complete":
68
+ throw new TlsHandshakeError("finished", {
69
+ cause: new Error(`handshake already in terminal phase: ${current.phase}`),
70
+ });
71
+ default:
72
+ return assertNever(current);
73
+ }
74
+ }
75
+ /**
76
+ * Record the parsed ServerHello and transition from "client_hello_sent" to
77
+ * "server_hello_received". Separated from {@link advanceHandshake} because the
78
+ * state machine needs to carry the parsed ServerHello forward.
79
+ */
80
+ export function recordServerHello(_current, serverHello) {
81
+ void _current;
82
+ return { phase: "server_hello_received", serverHello };
83
+ }
84
+ /** Mark the handshake as complete (after client Finished is sent). */
85
+ export function completeHandshake(_current) {
86
+ void _current;
87
+ return { phase: "complete" };
88
+ }
89
+ /** True if the named group is a (EC)DHE group usable for TLS 1.3 key share. */
90
+ export function isKeyShareGroup(group) {
91
+ switch (group) {
92
+ case "secp256r1":
93
+ case "secp384r1":
94
+ case "x25519":
95
+ case "x448":
96
+ return true;
97
+ default:
98
+ return assertNever(group);
99
+ }
100
+ }
101
+ /** True if the protocol version is TLS 1.3. */
102
+ export function isTls13(version) {
103
+ return version.name === "TLS 1.3";
104
+ }
105
+ //# sourceMappingURL=state-machine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state-machine.js","sourceRoot":"","sources":["../../src/handshake/state-machine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,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;QACjB,KAAK,WAAW,CAAC;QACjB,KAAK,QAAQ,CAAC;QACd,KAAK,MAAM;YACP,OAAO,IAAI,CAAC;QAChB;YACI,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;AACL,CAAC;AAED,+CAA+C;AAC/C,MAAM,UAAU,OAAO,CAAC,OAAwB;IAC5C,OAAO,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC;AACtC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@ export { type ApplicationData, type ApplicationTrafficSecrets, type CipherSuite,
13
13
  export { type TlsProfile, MODERN_TLS13_PROFILE, COMPATIBILITY_PROFILE, getProfile, resolveProfile } from "./profiles/profiles.js";
14
14
  export { ContentType, parseRecordHeader, serializeRecordHeader, cipherSuiteToAead, RECORD_HEADER_SIZE, } from "./record/record.js";
15
15
  export type { ContentType as TlsContentType, RecordHeader, TlsRecord } from "./record/record.js";
16
- export { HandshakeType, buildClientHello, parseServerHello } from "./handshake/handshake.js";
16
+ export { HandshakeType, buildClientHello, parseServerHello, cipherSuiteToWire } from "./handshake/handshake.js";
17
17
  export type { ClientHello, ServerHello, ServerHelloValidation, HandshakeType as TlsHandshakeType, } from "./handshake/handshake.js";
18
18
  export { ExtensionType, parseExtensions, findExtension, wireToNamedGroup } from "./extensions/extensions.js";
19
19
  export type { TlsExtension } from "./extensions/extensions.js";
@@ -1 +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,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BAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC7G,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,EACH,eAAe,EACf,sBAAsB,EACtB,6BAA6B,EAC7B,wBAAwB,GAC3B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ export { TlsError, TlsHandshakeError, TlsDecryptError, TlsAlertError, ensureTlsE
10
10
  export { TLS_1_2, TLS_1_3, } from "./types.js";
11
11
  export { MODERN_TLS13_PROFILE, COMPATIBILITY_PROFILE, getProfile, resolveProfile } from "./profiles/profiles.js";
12
12
  export { ContentType, parseRecordHeader, serializeRecordHeader, cipherSuiteToAead, RECORD_HEADER_SIZE, } from "./record/record.js";
13
- export { HandshakeType, buildClientHello, parseServerHello } from "./handshake/handshake.js";
13
+ export { HandshakeType, buildClientHello, parseServerHello, cipherSuiteToWire } from "./handshake/handshake.js";
14
14
  export { ExtensionType, parseExtensions, findExtension, wireToNamedGroup } from "./extensions/extensions.js";
15
15
  export { parseCertificate, validateHostname, verifyChain, pemToDer } from "./certificates/certificates.js";
16
16
  export { hkdfExpandLabel, deriveHandshakeSecrets, deriveHandshakeTrafficSecrets, deriveApplicationSecrets, } from "./crypto/keySchedule.js";
package/dist/index.js.map CHANGED
@@ -1 +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,iBAA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AAoB,CAAC;AAG5B,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAQhH,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAG7G,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAG3G,OAAO,EACH,eAAe,EACf,sBAAsB,EACtB,6BAA6B,EAC7B,wBAAwB,GAC3B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
@@ -15,9 +15,19 @@ export interface TlsProfile {
15
15
  readonly name: string;
16
16
  readonly config: ClientHelloConfig;
17
17
  }
18
- /** TLS 1.3 only, modern ciphers, X25519 + secp256r1 key shares. */
18
+ /**
19
+ * TLS 1.3 only, modern ciphers, X25519 + secp256r1 key shares.
20
+ *
21
+ * Extension order mirrors chrome-140's GREASE-inclusive layout so this
22
+ * placeholder profile exercises the full order-driven extension path.
23
+ */
19
24
  export declare const MODERN_TLS13_PROFILE: TlsProfile;
20
- /** TLS 1.2 fallback profile for legacy servers. */
25
+ /**
26
+ * Broad TLS 1.3 profile: the same modern ciphers as {@link MODERN_TLS13_PROFILE}
27
+ * plus secp384r1 key shares and additional signature algorithms, for servers
28
+ * that require a broader offer. TLS 1.2 is intentionally NOT advertised — this
29
+ * client speaks TLS 1.3 only and rejects TLS 1.2-only handshakes.
30
+ */
21
31
  export declare const COMPATIBILITY_PROFILE: TlsProfile;
22
32
  /** Registry of profiles by name. */
23
33
  export declare const PROFILES: Readonly<Record<string, TlsProfile>>;
@@ -1 +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,a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AAM,EAAE,UAAU,EAAE,MAAM,GAAG,iBAAiB,CAMlF"}
@@ -6,7 +6,13 @@
6
6
  * of truth and this module will re-export from there. Keeping the shape here
7
7
  * avoids a circular dependency while @browsercore/profiles is not yet ready.
8
8
  */
9
- /** TLS 1.3 only, modern ciphers, X25519 + secp256r1 key shares. */
9
+ import { TlsProfileError } from "../errors.js";
10
+ /**
11
+ * TLS 1.3 only, modern ciphers, X25519 + secp256r1 key shares.
12
+ *
13
+ * Extension order mirrors chrome-140's GREASE-inclusive layout so this
14
+ * placeholder profile exercises the full order-driven extension path.
15
+ */
10
16
  export const MODERN_TLS13_PROFILE = {
11
17
  name: "modern-tls13",
12
18
  config: {
@@ -15,6 +21,9 @@ export const MODERN_TLS13_PROFILE = {
15
21
  "TLS_AES_128_GCM_SHA256",
16
22
  "TLS_CHACHA20_POLY1305_SHA256",
17
23
  ],
24
+ extensionOrder: [
25
+ 0, 10, 11, 13, 16, 17513, 18, 23, 27, 35, 41, 43, 45, 5, 51, 65281,
26
+ ],
18
27
  keyShareGroups: ["x25519", "secp256r1"],
19
28
  signatureAlgorithms: [
20
29
  "ecdsa_secp256r1_sha256",
@@ -23,9 +32,15 @@ export const MODERN_TLS13_PROFILE = {
23
32
  ],
24
33
  supportedVersions: [{ name: "TLS 1.3", wire: 0x0304 }],
25
34
  serverName: "",
35
+ grease: true,
26
36
  },
27
37
  };
28
- /** TLS 1.2 fallback profile for legacy servers. */
38
+ /**
39
+ * Broad TLS 1.3 profile: the same modern ciphers as {@link MODERN_TLS13_PROFILE}
40
+ * plus secp384r1 key shares and additional signature algorithms, for servers
41
+ * that require a broader offer. TLS 1.2 is intentionally NOT advertised — this
42
+ * client speaks TLS 1.3 only and rejects TLS 1.2-only handshakes.
43
+ */
29
44
  export const COMPATIBILITY_PROFILE = {
30
45
  name: "compatibility",
31
46
  config: {
@@ -34,6 +49,8 @@ export const COMPATIBILITY_PROFILE = {
34
49
  "TLS_AES_128_GCM_SHA256",
35
50
  "TLS_CHACHA20_POLY1305_SHA256",
36
51
  ],
52
+ // Firefox-128 style order: no GREASE, no session_ticket/renegotiation_info.
53
+ extensionOrder: [0, 10, 11, 13, 16, 18, 23, 35, 41, 43, 45, 51, 65281],
37
54
  keyShareGroups: ["x25519", "secp256r1", "secp384r1"],
38
55
  signatureAlgorithms: [
39
56
  "ecdsa_secp256r1_sha256",
@@ -41,11 +58,9 @@ export const COMPATIBILITY_PROFILE = {
41
58
  "rsa_pss_rsae_sha256",
42
59
  "rsa_pkcs1_sha256",
43
60
  ],
44
- supportedVersions: [
45
- { name: "TLS 1.3", wire: 0x0304 },
46
- { name: "TLS 1.2", wire: 0x0303 },
47
- ],
61
+ supportedVersions: [{ name: "TLS 1.3", wire: 0x0304 }],
48
62
  serverName: "",
63
+ grease: false,
49
64
  },
50
65
  };
51
66
  /** Registry of profiles by name. */
@@ -61,7 +76,7 @@ export function getProfile(name) {
61
76
  export function resolveProfile(name, serverName) {
62
77
  const profile = PROFILES[name];
63
78
  if (!profile) {
64
- throw new Error(`unknown TLS profile: ${name}`);
79
+ throw new TlsProfileError(name);
65
80
  }
66
81
  return { ...profile.config, serverName };
67
82
  }
@@ -1 +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;AA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AAU,EAAE,EAAE;QACd,MAAM,EAAE,KAAK;KAChB;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,eAAe,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IACD,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC;AAC7C,CAAC"}
@@ -32,7 +32,24 @@ export interface TlsRecord {
32
32
  export declare const RECORD_HEADER_SIZE: 5;
33
33
  /** Maximum plaintext fragment length allowed by TLS (2^14). */
34
34
  export declare const MAX_PLAINTEXT_FRAGMENT: 16384;
35
- /** Map a cipher suite to its AEAD algorithm. */
35
+ /**
36
+ * Validate a raw byte as a known {@link ContentType}.
37
+ *
38
+ * Replaces the `raw[0] as ContentType` / `plaintext[end-1] as ContentType`
39
+ * casts that pretended any number was a member of the union. Used by the record
40
+ * layer to recover a typed content type from a raw header byte (and from the
41
+ * trailing inner-type byte of a decrypted TLS 1.3 record).
42
+ */
43
+ export declare function readContentType(byte: number): ContentType;
44
+ /**
45
+ * Map a cipher suite to its AEAD algorithm.
46
+ *
47
+ * Only the four TLS 1.3 AEAD suites can ever be the *negotiated* suite in a
48
+ * TLS 1.3 handshake, so only those map to an AEAD. TLS 1.2 suites appear in the
49
+ * offered ClientHello list but can never be negotiated by this TLS-1.3-only
50
+ * client — reaching the default with one means the server selected a suite we
51
+ * can't speak, which is a protocol violation we fail fast on.
52
+ */
36
53
  export declare function cipherSuiteToAead(cipherSuite: CipherSuite): AeadAlgorithm;
37
54
  /**
38
55
  * Parse a 5-byte record header from the start of a buffer.
@@ -1 +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,CAQ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,KAAe,CAAC;AAEtD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAUzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,WAAW,GAAG,aAAa,CAqCzE;AAWD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,GAAG,YAAY,CAoB/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,CAaZ;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,CAwBZ"}
@@ -6,7 +6,7 @@
6
6
  * payload is delegated to @browsercore/crypto — this module owns framing only.
7
7
  */
8
8
  import { crypto } from "@browsercore/crypto";
9
- import { TlsDecryptError } from "../errors.js";
9
+ import { NotImplementedError, TlsDecryptError } from "../errors.js";
10
10
  import { assertNever } from "../utils.js";
11
11
  /** TLS record content types, per RFC 8446 §5.1. */
12
12
  export const ContentType = {
@@ -19,18 +19,78 @@ export const ContentType = {
19
19
  export const RECORD_HEADER_SIZE = 5;
20
20
  /** Maximum plaintext fragment length allowed by TLS (2^14). */
21
21
  export const MAX_PLAINTEXT_FRAGMENT = 16_384;
22
- /** Map a cipher suite to its AEAD algorithm. */
22
+ /**
23
+ * Validate a raw byte as a known {@link ContentType}.
24
+ *
25
+ * Replaces the `raw[0] as ContentType` / `plaintext[end-1] as ContentType`
26
+ * casts that pretended any number was a member of the union. Used by the record
27
+ * layer to recover a typed content type from a raw header byte (and from the
28
+ * trailing inner-type byte of a decrypted TLS 1.3 record).
29
+ */
30
+ export function readContentType(byte) {
31
+ switch (byte) {
32
+ case ContentType.CHANGE_CIPHER_SPEC:
33
+ case ContentType.ALERT:
34
+ case ContentType.HANDSHAKE:
35
+ case ContentType.APPLICATION_DATA:
36
+ return byte;
37
+ default:
38
+ throw new TlsDecryptError("record", { cause: new Error(`invalid content type: ${byte}`) });
39
+ }
40
+ }
41
+ /**
42
+ * Map a cipher suite to its AEAD algorithm.
43
+ *
44
+ * Only the four TLS 1.3 AEAD suites can ever be the *negotiated* suite in a
45
+ * TLS 1.3 handshake, so only those map to an AEAD. TLS 1.2 suites appear in the
46
+ * offered ClientHello list but can never be negotiated by this TLS-1.3-only
47
+ * client — reaching the default with one means the server selected a suite we
48
+ * can't speak, which is a protocol violation we fail fast on.
49
+ */
23
50
  export function cipherSuiteToAead(cipherSuite) {
24
51
  switch (cipherSuite) {
52
+ // The four TLS 1.3 AEAD suites — the only ones this client can negotiate.
25
53
  case "TLS_AES_128_GCM_SHA256":
26
- case "TLS_AES_128_CCM_SHA256":
27
54
  return "AES-128-GCM";
55
+ case "TLS_AES_128_CCM_SHA256":
56
+ return "AES-128-CCM";
28
57
  case "TLS_AES_256_GCM_SHA384":
29
58
  return "AES-256-GCM";
30
59
  case "TLS_CHACHA20_POLY1305_SHA256":
31
60
  return "CHACHA20-POLY1305";
61
+ // TLS 1.2 suites (and the GREASE placeholder) appear only in the offered
62
+ // list and can never be negotiated in TLS 1.3. The server selecting one is
63
+ // a protocol error we fail fast on.
64
+ case "TLS_GREASE_RESERVED_0":
65
+ case "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256":
66
+ case "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256":
67
+ case "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384":
68
+ case "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384":
69
+ case "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256":
70
+ case "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256":
71
+ case "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA":
72
+ case "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA":
73
+ case "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA":
74
+ case "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA":
75
+ case "TLS_RSA_WITH_AES_128_GCM_SHA256":
76
+ case "TLS_RSA_WITH_AES_256_GCM_SHA384":
77
+ case "TLS_RSA_WITH_AES_128_CBC_SHA":
78
+ case "TLS_RSA_WITH_AES_256_CBC_SHA":
79
+ return throwNotImplemented(`cipher suite ${cipherSuite} has no AEAD mapping — not a negotiable TLS 1.3 suite`);
80
+ default:
81
+ // Every CipherSuite member is covered above; this is unreachable but
82
+ // keeps the switch exhaustive if the union is ever extended.
83
+ return assertNever(cipherSuite);
32
84
  }
33
85
  }
86
+ /**
87
+ * Throw a {@link NotImplementedError} and return `never`, so call sites can use
88
+ * `return throwNotImplemented(...)` to satisfy `consistent-return` while failing
89
+ * fast with a descriptive message.
90
+ */
91
+ function throwNotImplemented(message) {
92
+ throw new NotImplementedError(message);
93
+ }
34
94
  /**
35
95
  * Parse a 5-byte record header from the start of a buffer.
36
96
  * Throws {@link TlsDecryptError} if the buffer is too short.
@@ -41,15 +101,19 @@ export function parseRecordHeader(buf) {
41
101
  cause: new Error(`record header truncated: ${buf.length} < ${RECORD_HEADER_SIZE}`),
42
102
  });
43
103
  }
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}`) });
104
+ const typeByte = buf[0];
105
+ const b1 = buf[1];
106
+ const b2 = buf[2];
107
+ const b3 = buf[3];
108
+ const b4 = buf[4];
109
+ if (typeByte === undefined || b1 === undefined || b2 === undefined || b3 === undefined || b4 === undefined) {
110
+ throw new TlsDecryptError("record", {
111
+ cause: new Error(`record header truncated: ${buf.length} < ${RECORD_HEADER_SIZE}`),
112
+ });
50
113
  }
51
- const version = (buf[1] << 8) | buf[2];
52
- const length = (buf[3] << 8) | buf[4];
114
+ const type = readContentType(typeByte);
115
+ const version = (b1 << 8) | b2;
116
+ const length = (b3 << 8) | b4;
53
117
  return { type, version, length };
54
118
  }
55
119
  /**
@@ -89,6 +153,8 @@ export function encryptRecord(plaintext, key, nonce, additionalData, algorithm)
89
153
  return crypto.aes128GcmEncrypt(key, nonce, plaintext, additionalData);
90
154
  case "AES-256-GCM":
91
155
  return crypto.aes256GcmEncrypt(key, nonce, plaintext, additionalData);
156
+ case "AES-128-CCM":
157
+ return crypto.aes128CcmEncrypt(key, nonce, plaintext, additionalData);
92
158
  case "CHACHA20-POLY1305":
93
159
  return crypto.chacha20Poly1305Encrypt(key, nonce, plaintext, additionalData);
94
160
  default:
@@ -115,6 +181,8 @@ export function decryptRecord(ciphertext, key, nonce, additionalData, algorithm)
115
181
  return crypto.aes128GcmDecrypt(key, nonce, ciphertext, additionalData);
116
182
  case "AES-256-GCM":
117
183
  return crypto.aes256GcmDecrypt(key, nonce, ciphertext, additionalData);
184
+ case "AES-128-CCM":
185
+ return crypto.aes128CcmDecrypt(key, nonce, ciphertext, additionalData);
118
186
  case "CHACHA20-POLY1305":
119
187
  return crypto.chacha20Poly1305Decrypt(key, nonce, ciphertext, additionalData);
120
188
  default:
@@ -1 +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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