@browsercore/tls 0.1.3 → 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.
- 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
package/README.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# @browsercore/tls
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@browsercore/tls)
|
|
4
|
+
[](https://github.com/jverneuer/browsercore-tls/blob/main/COVERAGE.md)
|
|
5
|
+
[](https://github.com/jverneuer/browsercore-tls/actions/workflows/ci.yml)
|
|
6
|
+
|
|
7
|
+
A TLS 1.3 client implemented entirely in TypeScript. TLS 1.2 fallback is
|
|
8
|
+
intentionally not implemented — requesting a TLS 1.2-only handshake is rejected
|
|
9
|
+
up front with a typed error rather than failing silently mid-flight.
|
|
4
10
|
|
|
5
11
|
## Responsibility
|
|
6
12
|
|
|
@@ -45,21 +51,115 @@ await tls.close();
|
|
|
45
51
|
| --- | --- | --- |
|
|
46
52
|
| `TlsConnection` | interface | Public contract higher layers depend on |
|
|
47
53
|
| `connectTls()` | function | Perform the TLS handshake over a transport |
|
|
54
|
+
| `TlsConnectionImpl` | class | Concrete connection (thin coordinator over `./connection/` modules) |
|
|
48
55
|
| `TlsState` | discriminated union | `connecting \| handshaking \| open \| closed` |
|
|
49
56
|
| `CloseReason` | discriminated union | Why a TLS connection closed |
|
|
50
57
|
| `ProtocolVersion` | discriminated union | `TLS 1.2` / `TLS 1.3` with wire codes |
|
|
51
58
|
| `CipherSuite` | string-literal union | Negotiated AEAD + hash |
|
|
52
59
|
| `ClientHelloConfig` | interface | ClientHello configuration (placeholder for @browsercore/profiles) |
|
|
60
|
+
| `TlsProfile` | interface | Named, reusable ClientHello config |
|
|
61
|
+
| `resolveProfile()` | function | Look up a profile by name and fill in serverName |
|
|
53
62
|
| `TlsError` | class | Base typed error |
|
|
54
63
|
| `TlsHandshakeError` | class | Handshake failure at a specific phase |
|
|
55
64
|
| `TlsDecryptError` | class | Record decryption / auth failure |
|
|
56
|
-
| `TlsAlertError` class | TLS alert with level + description |
|
|
65
|
+
| `TlsAlertError` | class | TLS alert with level + description |
|
|
57
66
|
|
|
58
67
|
## Dependency graph
|
|
59
68
|
|
|
60
69
|
```
|
|
61
70
|
@browsercore/tls
|
|
62
|
-
|
|
71
|
+
├─ @browsercore/transport
|
|
72
|
+
└─ @browsercore/crypto
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
No other `@browsercore/*` packages are imported. Shared build, lint,
|
|
76
|
+
and test config comes from `@browsercore/dev` (see [Development](#development)).
|
|
77
|
+
|
|
78
|
+
## Architecture
|
|
79
|
+
|
|
80
|
+
The package is a thin coordinator + focused pure-function modules. The
|
|
81
|
+
connection class (`TlsConnectionImpl`) owns mutable state (read buffer,
|
|
82
|
+
transcript, traffic secrets, sequence counters) and the public surface
|
|
83
|
+
(`handshake` / `read` / `write` / `close` / `on`). Every byte-level computation
|
|
84
|
+
lives in a module under `src/connection/` and is written as functions over
|
|
85
|
+
explicit inputs, so the protocol logic is unit-testable without a live
|
|
86
|
+
connection.
|
|
87
|
+
|
|
88
|
+
| Module | Responsibility |
|
|
89
|
+
| --- | --- |
|
|
90
|
+
| `src/record/record.ts` | Record header parse/serialize, AEAD encrypt/decrypt (delegates to `@browsercore/crypto`) |
|
|
91
|
+
| `src/handshake/client-hello.ts` | ClientHello builder (SNI, supported_versions, key_share, signature_algorithms, ALPN) |
|
|
92
|
+
| `src/handshake/server-hello.ts` | ServerHello parser — validates cipher suite + version |
|
|
93
|
+
| `src/handshake/state-machine.ts` | Handshake phase state machine with phase-tagged errors |
|
|
94
|
+
| `src/crypto/keySchedule.ts` | TLS 1.3 key schedule (RFC 8446 §7.1): HKDF-Expand-Label, traffic secrets |
|
|
95
|
+
| `src/certificates/` | X.509 DER parse, hostname validation (RFC 6125), chain verification |
|
|
96
|
+
| `src/extensions/` | Extension types, parsers, and wire encoders |
|
|
97
|
+
| `src/connection/handshake-driver.ts` | Handshake choreography (what to send, what to read, when to derive) |
|
|
98
|
+
| `src/connection/record-layer.ts` | TLS 1.3 inner-content-type wrapping, nonce XOR, record framing |
|
|
99
|
+
| `src/connection/key-exchange.ts` | (EC)DHE shared secret, transcript hash, server Finished verification |
|
|
100
|
+
| `src/connection/handshake-messages.ts` | EncryptedExtensions/Certificate/Finished parsing, client Finished builder |
|
|
101
|
+
| `src/connection/lifecycle.ts` | Timeouts, alerts, state transitions, post-handshake record dispatch |
|
|
102
|
+
|
|
103
|
+
Errors all carry a `kind` discriminator so callers can narrow and inspect
|
|
104
|
+
without leaking backend specifics (`TlsHandshakeError(phase)`,
|
|
105
|
+
`TlsDecryptError`, `TlsAlertError(level, description)`).
|
|
106
|
+
|
|
107
|
+
## Not implemented
|
|
108
|
+
|
|
109
|
+
- TLS 1.2 fallback — the client speaks TLS 1.3 only
|
|
110
|
+
- Post-handshake messages (NewSessionTicket, KeyUpdate)
|
|
111
|
+
- Session resumption / PSK / 0-RTT
|
|
112
|
+
- Mutual TLS (client certificate)
|
|
113
|
+
- Certificate compression
|
|
114
|
+
- HelloRetryRequest
|
|
115
|
+
- Additional key-share groups beyond X25519
|
|
116
|
+
|
|
117
|
+
## Development
|
|
118
|
+
|
|
119
|
+
This repo shares tooling with the `@browsercore/*` family via
|
|
120
|
+
[`@browsercore/dev`](https://www.npmjs.com/package/@browsercore/dev). That package
|
|
121
|
+
is the single source of truth for:
|
|
122
|
+
|
|
123
|
+
- `tsconfig` strict flags — `tsconfig.json` extends `@browsercore/dev/tsconfig.base.json`
|
|
124
|
+
- `vitest` config — `vitest.config.ts` imports `definePackageConfig` from `@browsercore/dev/vitest`
|
|
125
|
+
- `oxlint` config — `oxlint.config.ts` imports the base ruleset from `@browsercore/dev/oxlint`
|
|
126
|
+
- `coverage-md` bin — shipped via `@browsercore/dev`'s `bin/`, used as `npx coverage-md`
|
|
127
|
+
|
|
128
|
+
`@browsercore/dev` is declared in `devDependencies` as `"file:../dev"` for local
|
|
129
|
+
development (the monorepo layout). When installing from npm, consumers resolve the
|
|
130
|
+
published version.
|
|
131
|
+
|
|
132
|
+
### Scripts
|
|
133
|
+
|
|
134
|
+
```sh
|
|
135
|
+
npm run typecheck # tsc --noEmit (strict mode — noUncheckedIndexedAccess, exactOptionalPropertyTypes)
|
|
136
|
+
npm run lint # oxlint --type-aware src/ (tests excluded)
|
|
137
|
+
npm test # vitest run (in-process fixture server, no real network)
|
|
138
|
+
npm run build # tsc -p tsconfig.build.json → dist/
|
|
139
|
+
npx coverage-md # write COVERAGE.md + coverage/badge.json from coverage-summary.json
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Run a single test file:
|
|
143
|
+
|
|
144
|
+
```sh
|
|
145
|
+
npx vitest run tests/handshake.test.ts
|
|
63
146
|
```
|
|
64
147
|
|
|
65
|
-
|
|
148
|
+
Run tests by name pattern:
|
|
149
|
+
|
|
150
|
+
```sh
|
|
151
|
+
npx vitest run -t "rejects a non-browser User-Agent"
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Lint config
|
|
155
|
+
|
|
156
|
+
Linting is type-aware oxlint via `oxlint.config.ts`. The file extends the shared
|
|
157
|
+
`@browsercore/dev/oxlint` base (which enables the `typescript`, `unicorn`, `import`,
|
|
158
|
+
`promise`, and `node` plugins with `correctness`/`suspicious`/`pedantic` as errors).
|
|
159
|
+
The old `.oxlintrc.json` has been removed.
|
|
160
|
+
|
|
161
|
+
Private fields use the native TypeScript `private` keyword — the legacy
|
|
162
|
+
`_`-prefixed naming convention has been fully migrated away, so no
|
|
163
|
+
`no-underscore-dangle` allowlist is required.
|
|
164
|
+
|
|
165
|
+
Requires **Node >= 26**. ESM only (`"type": "module"`).
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* X.509 name and extension parsing.
|
|
3
|
+
*
|
|
4
|
+
* These decode the higher-level X.509 structures a TLS server cert actually
|
|
5
|
+
* carries: the subject/issuer DistinguishedNames (RFC 2253), the SAN
|
|
6
|
+
* extension (the source of truth for hostname validation), KeyUsage, and
|
|
7
|
+
* BasicConstraints (the cA flag that separates leaf from CA certs). They sit on
|
|
8
|
+
* top of the raw DER primitives in `der.ts` but are agnostic to validation
|
|
9
|
+
* policy — they only turn bytes into structured fields.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Parse the subject Name and return a readable DN string (RFC 2253-ish).
|
|
13
|
+
* Used only for the `issuer` field and debug-friendliness.
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseName(buf: Uint8Array, start: number, _end: number): string;
|
|
16
|
+
/** Extract the CN (OID 2.5.4.3) from a subject Name, if present. */
|
|
17
|
+
export declare function parseCommonName(buf: Uint8Array, start: number, _end: number): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Parse the extensions block (SEQUENCE OF Extension) between `start` and `end`.
|
|
20
|
+
* Each extension is SEQUENCE { extnID OID, critical BOOLEAN?, extnValue OCTET STRING }.
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseExtensionsBlock(buf: Uint8Array, start: number, _end: number): readonly {
|
|
23
|
+
readonly oid: string;
|
|
24
|
+
readonly value: Uint8Array;
|
|
25
|
+
}[];
|
|
26
|
+
/**
|
|
27
|
+
* Parse the SAN extension value (already unwrapped from its OCTET STRING).
|
|
28
|
+
* The value is a SEQUENCE OF GeneralName; we only extract dNSName entries
|
|
29
|
+
* (context tag [2]).
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseSubjectAltNames(value: Uint8Array): readonly string[];
|
|
32
|
+
/**
|
|
33
|
+
* Parse the KeyUsage extension value (unwrapped OCTET STRING holding a BIT
|
|
34
|
+
* STRING). Returns the digitalSignature (bit 0) and keyEncipherment (bit 2)
|
|
35
|
+
* flags.
|
|
36
|
+
*/
|
|
37
|
+
export declare function parseKeyUsage(value: Uint8Array): {
|
|
38
|
+
readonly digitalSignature: boolean;
|
|
39
|
+
readonly keyEncipherment: boolean;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Parse the BasicConstraints extension value (unwrapped OCTET STRING holding a
|
|
43
|
+
* SEQUENCE { cA BOOLEAN DEFAULT FALSE, pathLenConstraint INTEGER? }).
|
|
44
|
+
*/
|
|
45
|
+
export declare function parseBasicConstraints(value: Uint8Array): boolean;
|
|
46
|
+
//# sourceMappingURL=cert-extensions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cert-extensions.d.ts","sourceRoot":"","sources":["../../src/certificates/cert-extensions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAiC9E;AAED,oEAAoE;AACpE,wBAAgB,eAAe,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CA8BhG;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS;IACzF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;CAC9B,EAAE,CAkCF;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,MAAM,EAAE,CAoBzE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG;IAC9C,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;IACnC,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;CACrC,CAiCA;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAWhE"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* X.509 name and extension parsing.
|
|
3
|
+
*
|
|
4
|
+
* These decode the higher-level X.509 structures a TLS server cert actually
|
|
5
|
+
* carries: the subject/issuer DistinguishedNames (RFC 2253), the SAN
|
|
6
|
+
* extension (the source of truth for hostname validation), KeyUsage, and
|
|
7
|
+
* BasicConstraints (the cA flag that separates leaf from CA certs). They sit on
|
|
8
|
+
* top of the raw DER primitives in `der.ts` but are agnostic to validation
|
|
9
|
+
* policy — they only turn bytes into structured fields.
|
|
10
|
+
*/
|
|
11
|
+
import { readTlv, peekTag, parseOid } from "./der.js";
|
|
12
|
+
import { TlsHandshakeError } from "../errors.js";
|
|
13
|
+
/**
|
|
14
|
+
* Parse the subject Name and return a readable DN string (RFC 2253-ish).
|
|
15
|
+
* Used only for the `issuer` field and debug-friendliness.
|
|
16
|
+
*/
|
|
17
|
+
export function parseName(buf, start, _end) {
|
|
18
|
+
void _end;
|
|
19
|
+
const seq = readTlv(buf, start);
|
|
20
|
+
if (seq.tag !== 0x30) {
|
|
21
|
+
return "";
|
|
22
|
+
}
|
|
23
|
+
const rdnParts = [];
|
|
24
|
+
let o = seq.valueStart;
|
|
25
|
+
const textDecoder = new TextDecoder();
|
|
26
|
+
while (o < seq.end) {
|
|
27
|
+
// Each RelativeDistinguishedName is a SET of AttributeTypeAndValue.
|
|
28
|
+
const setTlv = readTlv(buf, o);
|
|
29
|
+
if (setTlv.tag !== 0x31) {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
const p = setTlv.valueStart;
|
|
33
|
+
if (p >= setTlv.end) {
|
|
34
|
+
o = setTlv.end;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const atv = readTlv(buf, p);
|
|
38
|
+
if (atv.tag !== 0x30) {
|
|
39
|
+
o = setTlv.end;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const oidTlv = readTlv(buf, atv.valueStart);
|
|
43
|
+
const oid = parseOid(buf, oidTlv.valueStart, oidTlv.end);
|
|
44
|
+
const valueTlv = readTlv(buf, oidTlv.end);
|
|
45
|
+
const value = textDecoder.decode(buf.subarray(valueTlv.valueStart, valueTlv.end));
|
|
46
|
+
rdnParts.push(`${oid}=${value}`);
|
|
47
|
+
o = setTlv.end;
|
|
48
|
+
}
|
|
49
|
+
return rdnParts.join(", ");
|
|
50
|
+
}
|
|
51
|
+
/** Extract the CN (OID 2.5.4.3) from a subject Name, if present. */
|
|
52
|
+
export function parseCommonName(buf, start, _end) {
|
|
53
|
+
void _end;
|
|
54
|
+
const seq = readTlv(buf, start);
|
|
55
|
+
if (seq.tag !== 0x30) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
let o = seq.valueStart;
|
|
59
|
+
const textDecoder = new TextDecoder();
|
|
60
|
+
while (o < seq.end) {
|
|
61
|
+
const setTlv = readTlv(buf, o);
|
|
62
|
+
if (setTlv.tag !== 0x31) {
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
let p = setTlv.valueStart;
|
|
66
|
+
while (p < setTlv.end) {
|
|
67
|
+
const atv = readTlv(buf, p);
|
|
68
|
+
if (atv.tag !== 0x30) {
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
const oidTlv = readTlv(buf, atv.valueStart);
|
|
72
|
+
const oid = parseOid(buf, oidTlv.valueStart, oidTlv.end);
|
|
73
|
+
if (oid === "2.5.4.3") {
|
|
74
|
+
const valueTlv = readTlv(buf, oidTlv.end);
|
|
75
|
+
return textDecoder.decode(buf.subarray(valueTlv.valueStart, valueTlv.end));
|
|
76
|
+
}
|
|
77
|
+
p = atv.end;
|
|
78
|
+
}
|
|
79
|
+
o = setTlv.end;
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Parse the extensions block (SEQUENCE OF Extension) between `start` and `end`.
|
|
85
|
+
* Each extension is SEQUENCE { extnID OID, critical BOOLEAN?, extnValue OCTET STRING }.
|
|
86
|
+
*/
|
|
87
|
+
export function parseExtensionsBlock(buf, start, _end) {
|
|
88
|
+
void _end;
|
|
89
|
+
const seq = readTlv(buf, start);
|
|
90
|
+
if (seq.tag !== 0x30) {
|
|
91
|
+
throw new TlsHandshakeError("certificate", {
|
|
92
|
+
cause: new Error(`expected extensions SEQUENCE, got tag 0x${seq.tag.toString(16)}`),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
const extensions = [];
|
|
96
|
+
let o = seq.valueStart;
|
|
97
|
+
while (o < seq.end) {
|
|
98
|
+
const ext = readTlv(buf, o);
|
|
99
|
+
if (ext.tag !== 0x30) {
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
let p = ext.valueStart;
|
|
103
|
+
const oidTlv = readTlv(buf, p);
|
|
104
|
+
const oid = parseOid(buf, oidTlv.valueStart, oidTlv.end);
|
|
105
|
+
p = oidTlv.end;
|
|
106
|
+
// Optional critical BOOLEAN.
|
|
107
|
+
if (peekTag(buf, p) === 0x01) {
|
|
108
|
+
p = readTlv(buf, p).end;
|
|
109
|
+
}
|
|
110
|
+
const valueTlv = readTlv(buf, p);
|
|
111
|
+
if (valueTlv.tag !== 0x04) {
|
|
112
|
+
throw new TlsHandshakeError("certificate", {
|
|
113
|
+
cause: new Error(`expected extnValue OCTET STRING, got tag 0x${valueTlv.tag.toString(16)}`),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
// The extnValue OCTET STRING *contains* the DER-encoded extension value.
|
|
117
|
+
extensions.push({ oid, value: buf.subarray(valueTlv.valueStart, valueTlv.end) });
|
|
118
|
+
o = ext.end;
|
|
119
|
+
}
|
|
120
|
+
return extensions;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Parse the SAN extension value (already unwrapped from its OCTET STRING).
|
|
124
|
+
* The value is a SEQUENCE OF GeneralName; we only extract dNSName entries
|
|
125
|
+
* (context tag [2]).
|
|
126
|
+
*/
|
|
127
|
+
export function parseSubjectAltNames(value) {
|
|
128
|
+
const seq = readTlv(value, 0);
|
|
129
|
+
if (seq.tag !== 0x30) {
|
|
130
|
+
return Object.freeze([]);
|
|
131
|
+
}
|
|
132
|
+
const names = [];
|
|
133
|
+
const textDecoder = new TextDecoder();
|
|
134
|
+
let o = seq.valueStart;
|
|
135
|
+
while (o < seq.end) {
|
|
136
|
+
const tlv = readTlv(value, o);
|
|
137
|
+
// GeneralName: context-specific tag. dNSName is [2] (0x82), iPAddress [7].
|
|
138
|
+
const tag = tlv.tag;
|
|
139
|
+
const tagClass = tag & 0xc0;
|
|
140
|
+
const tagNumber = tag & 0x1f;
|
|
141
|
+
if (tagClass === 0x80 && tagNumber === 2) {
|
|
142
|
+
names.push(textDecoder.decode(value.subarray(tlv.valueStart, tlv.end)));
|
|
143
|
+
}
|
|
144
|
+
o = tlv.end;
|
|
145
|
+
}
|
|
146
|
+
return Object.freeze(names);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Parse the KeyUsage extension value (unwrapped OCTET STRING holding a BIT
|
|
150
|
+
* STRING). Returns the digitalSignature (bit 0) and keyEncipherment (bit 2)
|
|
151
|
+
* flags.
|
|
152
|
+
*/
|
|
153
|
+
export function parseKeyUsage(value) {
|
|
154
|
+
const bitString = readTlv(value, 0);
|
|
155
|
+
if (bitString.tag !== 0x03) {
|
|
156
|
+
return { digitalSignature: false, keyEncipherment: false };
|
|
157
|
+
}
|
|
158
|
+
// BIT STRING content: first byte = number of unused bits; then the bits.
|
|
159
|
+
const content = value.subarray(bitString.valueStart, bitString.end);
|
|
160
|
+
if (content.length < 2) {
|
|
161
|
+
return { digitalSignature: false, keyEncipherment: false };
|
|
162
|
+
}
|
|
163
|
+
// Pack the used bits into an integer (big-endian bit order).
|
|
164
|
+
const usedBytes = content.subarray(1); // skip the unused-bits count.
|
|
165
|
+
let bits = 0;
|
|
166
|
+
for (const byte of usedBytes) {
|
|
167
|
+
bits = (bits << 8) | byte;
|
|
168
|
+
}
|
|
169
|
+
// The bits are left-aligned; the real bit 0 is the most significant bit of
|
|
170
|
+
// the first used byte. digitalSignature = bit 0, keyEncipherment = bit 2.
|
|
171
|
+
// bitIndex therefore maps directly to a big-endian bit position (0 = MSB of
|
|
172
|
+
// the first byte), so no reversal is applied.
|
|
173
|
+
const getBit = (index) => {
|
|
174
|
+
const byteIndex = Math.floor(index / 8);
|
|
175
|
+
const bitInByte = index % 8;
|
|
176
|
+
const byte = usedBytes[byteIndex];
|
|
177
|
+
if (byte === undefined) {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
return (byte & (1 << (7 - bitInByte))) !== 0;
|
|
181
|
+
};
|
|
182
|
+
return {
|
|
183
|
+
digitalSignature: getBit(0),
|
|
184
|
+
keyEncipherment: getBit(2),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Parse the BasicConstraints extension value (unwrapped OCTET STRING holding a
|
|
189
|
+
* SEQUENCE { cA BOOLEAN DEFAULT FALSE, pathLenConstraint INTEGER? }).
|
|
190
|
+
*/
|
|
191
|
+
export function parseBasicConstraints(value) {
|
|
192
|
+
const seq = readTlv(value, 0);
|
|
193
|
+
if (seq.tag !== 0x30 || seq.valueStart >= seq.end) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
if (peekTag(value, seq.valueStart) !== 0x01) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
const boolTlv = readTlv(value, seq.valueStart);
|
|
200
|
+
const boolByte = value[boolTlv.valueStart];
|
|
201
|
+
return boolByte !== undefined && boolByte !== 0;
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=cert-extensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cert-extensions.js","sourceRoot":"","sources":["../../src/certificates/cert-extensions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,GAAe,EAAE,KAAa,EAAE,IAAY;IAClE,KAAK,IAAI,CAAC;IACV,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAChC,IAAI,GAAG,CAAC,GAAG,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,EAAE,CAAC;IACd,CAAC;IACD,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,IAAI,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC;IACvB,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;IACtC,OAAO,CAAC,GAAG,GAAG,CAAC,GAAG,EAAE,CAAC;QACjB,oEAAoE;QACpE,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAC/B,IAAI,MAAM,CAAC,GAAG,KAAK,IAAI,EAAE,CAAC;YACtB,MAAM;QACV,CAAC;QACD,MAAM,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC;QAC5B,IAAI,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;YAClB,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC;YACf,SAAS;QACb,CAAC;QACD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAC5B,IAAI,GAAG,CA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,MAAM,UAAU,qBAAqB,CAAC,KAAiB;IACnD,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC9B,IAAI,GAAG,CAAC,GAAG,KAAK,IAAI,IAAI,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,UAAU,CAAC,KAAK,IAAI,EAAE,CAAC;QAC1C,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC3C,OAAO,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -4,7 +4,14 @@
|
|
|
4
4
|
* Parses DER-encoded certificates, validates hostnames against SAN/CN, and
|
|
5
5
|
* verifies certificate chains against trust anchors. The cryptographic
|
|
6
6
|
* signature verification itself is delegated to @browsercore/crypto — this module
|
|
7
|
-
* owns
|
|
7
|
+
* owns validation policy and the top-level parse/verify orchestration only.
|
|
8
|
+
*
|
|
9
|
+
* The byte-level ASN.1 decoding lives in focused submodules so each layer can be
|
|
10
|
+
* read and tested in isolation:
|
|
11
|
+
* - `der.ts` — DER tag-length-value primitives (no X.509 semantics)
|
|
12
|
+
* - `cert-extensions.ts` — subject/issuer names, SAN, KeyUsage, BasicConstraints
|
|
13
|
+
* - `pem.ts` — PEM container decoding (the only place that knows about
|
|
14
|
+
* the BEGIN/END text wrapper; downstream code sees raw DER)
|
|
8
15
|
*/
|
|
9
16
|
import type { SignatureScheme } from "../types.js";
|
|
10
17
|
/** A parsed X.509 certificate (validation-relevant fields only). */
|
|
@@ -58,13 +65,9 @@ export interface TrustAnchor {
|
|
|
58
65
|
export declare function parseCertificate(buf: Uint8Array): Certificate;
|
|
59
66
|
/**
|
|
60
67
|
* Validate that a certificate is valid for the given hostname per RFC 6125.
|
|
61
|
-
*
|
|
62
|
-
* If the cert carries SAN DNS names, one must match (wildcard-aware, matching
|
|
63
|
-
* a single left-most label and NOT crossing dots). Otherwise we fall back to
|
|
64
|
-
* the legacy CommonName. IP-literal SANs are not matched here (server certs
|
|
65
|
-
* virtually always use DNS names).
|
|
68
|
+
* (Moved to {@link ./hostname.js} — re-exported here for the stable import path.)
|
|
66
69
|
*/
|
|
67
|
-
export
|
|
70
|
+
export { validateHostname, matchDnsName } from "./hostname.js";
|
|
68
71
|
/**
|
|
69
72
|
* Verify a certificate chain: each cert is signed by the next, the root is in
|
|
70
73
|
* the trust anchors, and the leaf is valid for the hostname and not expired.
|
|
@@ -73,6 +76,5 @@ export declare function validateHostname(cert: Certificate, hostname: string): b
|
|
|
73
76
|
* {@link TlsHandshakeError} with phase "certificate" on any failure.
|
|
74
77
|
*/
|
|
75
78
|
export declare function verifyChain(chain: CertificateChain, trustAnchors: readonly TrustAnchor[], hostname: string, now: number): Promise<void>;
|
|
76
|
-
|
|
77
|
-
export declare function pemToDer(pem: string): Uint8Array;
|
|
79
|
+
export { pemToDer } from "./pem.js";
|
|
78
80
|
//# sourceMappingURL=certificates.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"certificates.d.ts","sourceRoot":"","sources":["../../src/certificates/certificates.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"certificates.d.ts","sourceRoot":"","sources":["../../src/certificates/certificates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAmBnD,oEAAoE;AACpE,MAAM,WAAW,WAAW;IACxB,2EAA2E;IAC3E,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC9B,wCAAwC;IACxC,QAAQ,CAAC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