@php-wasm/web 1.0.4 → 1.0.6
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/index.js +2399 -234
- package/lib/index.d.ts +2 -0
- package/lib/load-runtime.d.ts +2 -2
- package/lib/tcp-over-fetch-websocket.d.ts +108 -0
- package/lib/tls/1_2/connection.d.ts +194 -0
- package/lib/tls/1_2/prf.d.ts +7 -0
- package/lib/tls/1_2/types.d.ts +223 -0
- package/lib/tls/certificates.d.ts +199 -0
- package/lib/tls/cipher-suites.d.ts +210 -0
- package/lib/tls/extensions/0_server_name.d.ts +33 -0
- package/lib/tls/extensions/10_supported_groups.d.ts +44 -0
- package/lib/tls/extensions/11_ec_point_formats.d.ts +45 -0
- package/lib/tls/extensions/13_signature_algorithms.d.ts +74 -0
- package/lib/tls/extensions/parse-extensions.d.ts +66 -0
- package/lib/tls/extensions/types.d.ts +62 -0
- package/lib/tls/utils.d.ts +28 -0
- package/package.json +6 -6
- package/php/asyncify/7_0_33/php_7_0.wasm +0 -0
- package/php/asyncify/7_1_30/php_7_1.wasm +0 -0
- package/php/asyncify/7_2_34/php_7_2.wasm +0 -0
- package/php/asyncify/7_3_33/php_7_3.wasm +0 -0
- package/php/asyncify/7_4_33/php_7_4.wasm +0 -0
- package/php/asyncify/8_0_30/php_8_0.wasm +0 -0
- package/php/asyncify/8_1_23/php_8_1.wasm +0 -0
- package/php/asyncify/8_2_10/php_8_2.wasm +0 -0
- package/php/asyncify/8_3_0/php_8_3.wasm +0 -0
- package/php/asyncify/php_7_0.js +3 -3
- package/php/asyncify/php_7_1.js +3 -3
- package/php/asyncify/php_7_2.js +3 -3
- package/php/asyncify/php_7_3.js +3 -3
- package/php/asyncify/php_7_4.js +3 -3
- package/php/asyncify/php_8_0.js +3 -3
- package/php/asyncify/php_8_1.js +3 -3
- package/php/asyncify/php_8_2.js +3 -3
- package/php/asyncify/php_8_3.js +3 -3
- package/php/jspi/7_0_33/php_7_0.wasm +0 -0
- package/php/jspi/7_1_30/php_7_1.wasm +0 -0
- package/php/jspi/7_2_34/php_7_2.wasm +0 -0
- package/php/jspi/7_3_33/php_7_3.wasm +0 -0
- package/php/jspi/7_4_33/php_7_4.wasm +0 -0
- package/php/jspi/8_0_30/php_8_0.wasm +0 -0
- package/php/jspi/8_1_23/php_8_1.wasm +0 -0
- package/php/jspi/8_2_10/php_8_2.wasm +0 -0
- package/php/jspi/8_3_0/php_8_3.wasm +0 -0
- package/php/jspi/php_7_0.js +2 -2
- package/php/jspi/php_7_1.js +2 -2
- package/php/jspi/php_7_2.js +2 -2
- package/php/jspi/php_7_3.js +2 -2
- package/php/jspi/php_7_4.js +2 -2
- package/php/jspi/php_8_0.js +2 -2
- package/php/jspi/php_8_1.js +2 -2
- package/php/jspi/php_8_2.js +2 -2
- package/php/jspi/php_8_3.js +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -7,3 +7,5 @@ export { setupPostMessageRelay } from './setup-post-message-relay';
|
|
|
7
7
|
export { spawnPHPWorkerThread } from './worker-thread/spawn-php-worker-thread';
|
|
8
8
|
export { createDirectoryHandleMountHandler } from './directory-handle-mount';
|
|
9
9
|
export type { MountDevice, MountOptions, SyncProgress, SyncProgressCallback, } from './directory-handle-mount';
|
|
10
|
+
export * from './tls/certificates';
|
|
11
|
+
export type { TCPOverFetchOptions } from './tcp-over-fetch-websocket';
|
package/lib/load-runtime.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { EmscriptenOptions, PHPLoaderModule, SupportedPHPVersion } from '@php-wasm/universal';
|
|
2
|
+
import { TCPOverFetchOptions } from './tcp-over-fetch-websocket';
|
|
2
3
|
export interface LoaderOptions {
|
|
3
4
|
emscriptenOptions?: EmscriptenOptions;
|
|
4
5
|
onPhpLoaderModuleLoaded?: (module: PHPLoaderModule) => void;
|
|
5
|
-
|
|
6
|
-
loadAllExtensions?: boolean;
|
|
6
|
+
tcpOverFetch?: TCPOverFetchOptions;
|
|
7
7
|
}
|
|
8
8
|
export declare function loadWebRuntime(phpVersion: SupportedPHPVersion, options?: LoaderOptions): Promise<number>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { GeneratedCertificate } from './tls/certificates';
|
|
2
|
+
export type TCPOverFetchOptions = {
|
|
3
|
+
CAroot: GeneratedCertificate;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Sets up a WebSocket that analyzes the received bytes and, if they look like
|
|
7
|
+
* TLS or HTTP, handles the network transmission using fetch().
|
|
8
|
+
*/
|
|
9
|
+
export declare const tcpOverFetchWebsocket: (tcpOptions: TCPOverFetchOptions) => {
|
|
10
|
+
websocket: {
|
|
11
|
+
url: (_: any, host: string, port: string) => string;
|
|
12
|
+
subprotocol: string;
|
|
13
|
+
decorator: () => {
|
|
14
|
+
new (url: string, wsOptions: string[]): {
|
|
15
|
+
CONNECTING: number;
|
|
16
|
+
OPEN: number;
|
|
17
|
+
CLOSING: number;
|
|
18
|
+
CLOSED: number;
|
|
19
|
+
readyState: number;
|
|
20
|
+
binaryType: string;
|
|
21
|
+
bufferedAmount: number;
|
|
22
|
+
extensions: string;
|
|
23
|
+
protocol: string;
|
|
24
|
+
host: string;
|
|
25
|
+
port: number;
|
|
26
|
+
listeners: Map<string, any>;
|
|
27
|
+
CAroot?: GeneratedCertificate | undefined;
|
|
28
|
+
clientUpstream: TransformStream<any, any>;
|
|
29
|
+
clientUpstreamWriter: WritableStreamDefaultWriter<any>;
|
|
30
|
+
clientDownstream: TransformStream<any, any>;
|
|
31
|
+
fetchInitiated: boolean;
|
|
32
|
+
bufferedBytesFromClient: Uint8Array;
|
|
33
|
+
url: string;
|
|
34
|
+
options: string[];
|
|
35
|
+
on(eventName: string, callback: (e: any) => void): void;
|
|
36
|
+
once(eventName: string, callback: (e: any) => void): void;
|
|
37
|
+
addEventListener(eventName: string, callback: (e: any) => void): void;
|
|
38
|
+
removeListener(eventName: string, callback: (e: any) => void): void;
|
|
39
|
+
removeEventListener(eventName: string, callback: (e: any) => void): void;
|
|
40
|
+
emit(eventName: string, data?: any): void;
|
|
41
|
+
onclose(data: any): void;
|
|
42
|
+
onerror(data: any): void;
|
|
43
|
+
onmessage(data: any): void;
|
|
44
|
+
onopen(data: any): void;
|
|
45
|
+
/**
|
|
46
|
+
* Emscripten calls this method whenever the WASM module
|
|
47
|
+
* writes bytes to the TCP socket.
|
|
48
|
+
*/
|
|
49
|
+
send(data: ArrayBuffer): void;
|
|
50
|
+
fetchOverTLS(): Promise<void>;
|
|
51
|
+
fetchOverHTTP(): Promise<void>;
|
|
52
|
+
close(): void;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export interface TCPOverFetchWebsocketOptions {
|
|
58
|
+
CAroot?: GeneratedCertificate;
|
|
59
|
+
/**
|
|
60
|
+
* If true, the WebSocket will emit 'message' events with the received bytes
|
|
61
|
+
* and the 'close' event when the WebSocket is closed.
|
|
62
|
+
*
|
|
63
|
+
* If false, the consumer will be responsible for reading the bytes from the
|
|
64
|
+
* clientDownstream stream and tracking the closure of that stream.
|
|
65
|
+
*/
|
|
66
|
+
outputType?: 'messages' | 'stream';
|
|
67
|
+
}
|
|
68
|
+
export declare class TCPOverFetchWebsocket {
|
|
69
|
+
url: string;
|
|
70
|
+
options: string[];
|
|
71
|
+
CONNECTING: number;
|
|
72
|
+
OPEN: number;
|
|
73
|
+
CLOSING: number;
|
|
74
|
+
CLOSED: number;
|
|
75
|
+
readyState: number;
|
|
76
|
+
binaryType: string;
|
|
77
|
+
bufferedAmount: number;
|
|
78
|
+
extensions: string;
|
|
79
|
+
protocol: string;
|
|
80
|
+
host: string;
|
|
81
|
+
port: number;
|
|
82
|
+
listeners: Map<string, any>;
|
|
83
|
+
CAroot?: GeneratedCertificate;
|
|
84
|
+
clientUpstream: TransformStream<any, any>;
|
|
85
|
+
clientUpstreamWriter: WritableStreamDefaultWriter<any>;
|
|
86
|
+
clientDownstream: TransformStream<any, any>;
|
|
87
|
+
fetchInitiated: boolean;
|
|
88
|
+
bufferedBytesFromClient: Uint8Array;
|
|
89
|
+
constructor(url: string, options: string[], { CAroot, outputType }?: TCPOverFetchWebsocketOptions);
|
|
90
|
+
on(eventName: string, callback: (e: any) => void): void;
|
|
91
|
+
once(eventName: string, callback: (e: any) => void): void;
|
|
92
|
+
addEventListener(eventName: string, callback: (e: any) => void): void;
|
|
93
|
+
removeListener(eventName: string, callback: (e: any) => void): void;
|
|
94
|
+
removeEventListener(eventName: string, callback: (e: any) => void): void;
|
|
95
|
+
emit(eventName: string, data?: any): void;
|
|
96
|
+
onclose(data: any): void;
|
|
97
|
+
onerror(data: any): void;
|
|
98
|
+
onmessage(data: any): void;
|
|
99
|
+
onopen(data: any): void;
|
|
100
|
+
/**
|
|
101
|
+
* Emscripten calls this method whenever the WASM module
|
|
102
|
+
* writes bytes to the TCP socket.
|
|
103
|
+
*/
|
|
104
|
+
send(data: ArrayBuffer): void;
|
|
105
|
+
fetchOverTLS(): Promise<void>;
|
|
106
|
+
fetchOverHTTP(): Promise<void>;
|
|
107
|
+
close(): void;
|
|
108
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This isomorphic class implements the server end of
|
|
3
|
+
* the client <-> server TLS 1.2 connection. It has two ends:
|
|
4
|
+
*
|
|
5
|
+
* * Client end, that emits and accepts TLS encrypted data.
|
|
6
|
+
* * Server end, that emits and accepts unencrypted data.
|
|
7
|
+
*
|
|
8
|
+
* The API consumer is responsible for connecting both ends
|
|
9
|
+
* to the appropriate handlers.
|
|
10
|
+
*
|
|
11
|
+
* See https://datatracker.ietf.org/doc/html/rfc5246.
|
|
12
|
+
*
|
|
13
|
+
* ## Warning
|
|
14
|
+
*
|
|
15
|
+
* **WARNING** NEVER USE THIS CODE AS A SERVER-SIDE TLS HANDLER.
|
|
16
|
+
*
|
|
17
|
+
* This code is not secure. It is a minimal subset required
|
|
18
|
+
* to decrypt the TLS traffic from a PHP-wasm worker. Yes,
|
|
19
|
+
* it can speak TLS. No, it won't protect your data.
|
|
20
|
+
*
|
|
21
|
+
* ## Rationale
|
|
22
|
+
*
|
|
23
|
+
* This is useful for running PHP.wasm in web browsers.
|
|
24
|
+
* Function calls such as `file_get_contents("https://w.org")`
|
|
25
|
+
* emit encrypted TLS traffic. With this class, you
|
|
26
|
+
* can decrypt it, serve the requested data, and encrypt
|
|
27
|
+
* the response before passing it back to the PHP.wasm
|
|
28
|
+
* module.
|
|
29
|
+
*
|
|
30
|
+
* ## Implementation details
|
|
31
|
+
*
|
|
32
|
+
* TLS_1_2_Connection implements the minimal subset of TLS 1.2
|
|
33
|
+
* required to exchange encrypted data with PHP.wasm:
|
|
34
|
+
*
|
|
35
|
+
* * TLS Handshake
|
|
36
|
+
* * All TLS 1.2 record types, including messages spanning multiple
|
|
37
|
+
* records and empty records.
|
|
38
|
+
* * Encryption and decryption of application data.
|
|
39
|
+
* * Auto-chunking long data blobs before encrypting them to
|
|
40
|
+
* respect the AES-GCM record size limit.
|
|
41
|
+
*
|
|
42
|
+
* The logic is based on numerous RFCs:
|
|
43
|
+
*
|
|
44
|
+
* * RFC 5246: The TLS Protocol Version 1.2
|
|
45
|
+
* * RFC 8446: TLS 1.3
|
|
46
|
+
* * RFC 6066: TLS Extensions
|
|
47
|
+
* * RFC 4492: Elliptic Curve Cryptography (ECC) Cipher Suites for TLS
|
|
48
|
+
* * RFC 5288: AES Galois Counter Mode (GCM) Cipher Suites for TLS
|
|
49
|
+
* * RFC 6070: PKCS #5: Password-Based Key Derivation Function 2 (PBKDF2) Test Vectors
|
|
50
|
+
*
|
|
51
|
+
* ... and a few others.
|
|
52
|
+
*
|
|
53
|
+
* ## Limitations
|
|
54
|
+
*
|
|
55
|
+
* * Multiple ChangeCipherSpec messages are not supported.
|
|
56
|
+
* * Only uncompressed mode (compression method 0) is supported.
|
|
57
|
+
* * Only the TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256 cipher suite is
|
|
58
|
+
* supported, primarily because `crypto.subtle` supports AES-GCM.
|
|
59
|
+
* For AES-GCM details, see https://datatracker.ietf.org/doc/html/rfc5288.
|
|
60
|
+
*/
|
|
61
|
+
export declare class TLS_1_2_Connection {
|
|
62
|
+
/**
|
|
63
|
+
* Sequence number of the last received TLS record.
|
|
64
|
+
*
|
|
65
|
+
* AES-GCM requires transmitting the sequence number
|
|
66
|
+
* in the clear in the additional data to prevent a
|
|
67
|
+
* potential attacker from re-transmitting the same
|
|
68
|
+
* TLS record in a different context.
|
|
69
|
+
*/
|
|
70
|
+
private receivedRecordSequenceNumber;
|
|
71
|
+
/**
|
|
72
|
+
* Sequence number of the last sent TLS record.
|
|
73
|
+
*
|
|
74
|
+
* AES-GCM requires transmitting the sequence number
|
|
75
|
+
* in the clear in the additional data to prevent a
|
|
76
|
+
* potential attacker from re-transmitting the same
|
|
77
|
+
* TLS record in a different context.
|
|
78
|
+
*/
|
|
79
|
+
private sentRecordSequenceNumber;
|
|
80
|
+
/**
|
|
81
|
+
* Encryption keys for this connection derived during
|
|
82
|
+
* the TLS handshake.
|
|
83
|
+
*/
|
|
84
|
+
private sessionKeys;
|
|
85
|
+
/**
|
|
86
|
+
* Whether this connection have been closed.
|
|
87
|
+
*/
|
|
88
|
+
private closed;
|
|
89
|
+
/**
|
|
90
|
+
* Bytes received from the client but not yet parsed
|
|
91
|
+
* as TLS records.
|
|
92
|
+
*/
|
|
93
|
+
private receivedBytesBuffer;
|
|
94
|
+
/**
|
|
95
|
+
* TLS records received from the client but not yet
|
|
96
|
+
* parsed as TLS messages.
|
|
97
|
+
*/
|
|
98
|
+
private receivedTLSRecords;
|
|
99
|
+
/**
|
|
100
|
+
* TLS messages can span multiple TLS records. This
|
|
101
|
+
* map holds partial TLS messages that are still incomplete
|
|
102
|
+
* after parsing one or more TLS records.
|
|
103
|
+
*/
|
|
104
|
+
private partialTLSMessages;
|
|
105
|
+
/**
|
|
106
|
+
* A log of all the exchanged TLS handshake messages.
|
|
107
|
+
* This is required to build the Finished message and
|
|
108
|
+
* verify the integrity of the handshake.
|
|
109
|
+
*/
|
|
110
|
+
private handshakeMessages;
|
|
111
|
+
/**
|
|
112
|
+
* Maximum chunk size supported by the cipher suite used
|
|
113
|
+
* in this TLS implementation.
|
|
114
|
+
*/
|
|
115
|
+
private MAX_CHUNK_SIZE;
|
|
116
|
+
/**
|
|
117
|
+
* The client end of the TLS connection.
|
|
118
|
+
* This is where the WASM module can write and read the
|
|
119
|
+
* encrypted data.
|
|
120
|
+
*/
|
|
121
|
+
clientEnd: {
|
|
122
|
+
upstream: TransformStream<Uint8Array, Uint8Array>;
|
|
123
|
+
downstream: TransformStream<Uint8Array, Uint8Array>;
|
|
124
|
+
};
|
|
125
|
+
private clientDownstreamWriter;
|
|
126
|
+
private clientUpstreamReader;
|
|
127
|
+
/**
|
|
128
|
+
* The server end of the TLS connection.
|
|
129
|
+
* This is where the JavaScript handler can write and read the
|
|
130
|
+
* unencrypted data.
|
|
131
|
+
*/
|
|
132
|
+
serverEnd: {
|
|
133
|
+
upstream: TransformStream<Uint8Array, Uint8Array>;
|
|
134
|
+
/**
|
|
135
|
+
* Chunk the data before encrypting it. The
|
|
136
|
+
* TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256 cipher suite
|
|
137
|
+
* only supports up to 16KB of data per record.
|
|
138
|
+
*
|
|
139
|
+
* This will spread some messages across multiple records,
|
|
140
|
+
* but TLS supports it so that's fine.
|
|
141
|
+
*/
|
|
142
|
+
downstream: TransformStream<any, any>;
|
|
143
|
+
};
|
|
144
|
+
private serverUpstreamWriter;
|
|
145
|
+
constructor();
|
|
146
|
+
/**
|
|
147
|
+
* Marks this connections as closed and closes all the associated
|
|
148
|
+
* streams.
|
|
149
|
+
*/
|
|
150
|
+
close(): Promise<void>;
|
|
151
|
+
/**
|
|
152
|
+
* TLS handshake as per RFC 5246.
|
|
153
|
+
*
|
|
154
|
+
* https://datatracker.ietf.org/doc/html/rfc5246#section-7.4
|
|
155
|
+
*/
|
|
156
|
+
TLSHandshake(certificatePrivateKey: CryptoKey, certificatesDER: Uint8Array[]): Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* Derives the session keys from the random values and the
|
|
159
|
+
* pre-master secret – as per RFC 5246.
|
|
160
|
+
*/
|
|
161
|
+
private deriveSessionKeys;
|
|
162
|
+
private readNextHandshakeMessage;
|
|
163
|
+
private readNextMessage;
|
|
164
|
+
private readNextTLSRecord;
|
|
165
|
+
/**
|
|
166
|
+
* Returns the requested number of bytes from the client.
|
|
167
|
+
* Waits for the bytes to arrive if necessary.
|
|
168
|
+
*/
|
|
169
|
+
private pollBytes;
|
|
170
|
+
/**
|
|
171
|
+
* Listens for all incoming messages and passes them to the
|
|
172
|
+
* server handler.
|
|
173
|
+
*/
|
|
174
|
+
private pollForClientMessages;
|
|
175
|
+
/**
|
|
176
|
+
* Decrypts data in a TLS 1.2-compliant manner using
|
|
177
|
+
* the AES-GCM algorithm.
|
|
178
|
+
*/
|
|
179
|
+
private decryptData;
|
|
180
|
+
private accumulateUntilMessageIsComplete;
|
|
181
|
+
/**
|
|
182
|
+
* Passes a TLS record to the client.
|
|
183
|
+
*
|
|
184
|
+
* Accepts unencrypted data and ensures it gets encrypted
|
|
185
|
+
* if needed before sending it to the client. The encryption
|
|
186
|
+
* only kicks in after the handshake is complete.
|
|
187
|
+
*/
|
|
188
|
+
private writeTLSRecord;
|
|
189
|
+
/**
|
|
190
|
+
* Encrypts data in a TLS 1.2-compliant manner using
|
|
191
|
+
* the AES-GCM algorithm.
|
|
192
|
+
*/
|
|
193
|
+
private encryptData;
|
|
194
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Implements the TLS 1.2 PRF using HMAC-SHA256.
|
|
3
|
+
*
|
|
4
|
+
* See https://datatracker.ietf.org/doc/html/rfc5246#section-5
|
|
5
|
+
*/
|
|
6
|
+
export declare function tls12Prf(secret: ArrayBuffer, label: ArrayBuffer, seed: ArrayBuffer, outputLength: number): Promise<ArrayBuffer>;
|
|
7
|
+
export declare function hmacSha256(key: CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer>;
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TLS 1.2 Record layer types defined after the structs
|
|
3
|
+
* from the TLS 1.2 RFC.
|
|
4
|
+
* https://datatracker.ietf.org/doc/html/rfc5246#section-6.2
|
|
5
|
+
*/
|
|
6
|
+
import { ParsedExtension } from '../extensions/parse-extensions';
|
|
7
|
+
export declare const enum CompressionMethod {
|
|
8
|
+
Null = 0,
|
|
9
|
+
Deflate = 1
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* TLS 1.2 Record layer types defined after the structs
|
|
13
|
+
* from the TLS 1.2 RFC.
|
|
14
|
+
* https://datatracker.ietf.org/doc/html/rfc5246#section-6.2.1
|
|
15
|
+
*/
|
|
16
|
+
export interface TLSRecord {
|
|
17
|
+
type: ContentType;
|
|
18
|
+
version: ProtocolVersion;
|
|
19
|
+
length: number;
|
|
20
|
+
fragment: Uint8Array;
|
|
21
|
+
}
|
|
22
|
+
export interface ProtocolVersion {
|
|
23
|
+
major: number;
|
|
24
|
+
minor: number;
|
|
25
|
+
}
|
|
26
|
+
export interface GenericStreamCipher {
|
|
27
|
+
content: Uint8Array;
|
|
28
|
+
MAC: Uint8Array;
|
|
29
|
+
}
|
|
30
|
+
export interface GenericBlockCipher {
|
|
31
|
+
IV: Uint8Array;
|
|
32
|
+
block_ciphered: BlockCiphered;
|
|
33
|
+
}
|
|
34
|
+
export interface BlockCiphered {
|
|
35
|
+
content: Uint8Array;
|
|
36
|
+
MAC: Uint8Array;
|
|
37
|
+
padding: Uint8Array;
|
|
38
|
+
padding_length: number;
|
|
39
|
+
}
|
|
40
|
+
export interface GenericAEADCipher {
|
|
41
|
+
nonce_explicit: Uint8Array;
|
|
42
|
+
aead_encrypted: Uint8Array;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* TLS 1.2 Handshake types defined after the structs
|
|
46
|
+
* from the TLS 1.2 RFC.
|
|
47
|
+
* https://datatracker.ietf.org/doc/html/rfc5246#section-7.4
|
|
48
|
+
*/
|
|
49
|
+
export type TLSMessage = AlertMessage | HandshakeMessage<any> | ChangeCipherSpecMessage | ApplicationDataMessage;
|
|
50
|
+
export interface AlertMessage {
|
|
51
|
+
type: typeof ContentTypes.Alert;
|
|
52
|
+
level: AlertLevel;
|
|
53
|
+
description: AlertDescription;
|
|
54
|
+
}
|
|
55
|
+
export declare const AlertLevels: {
|
|
56
|
+
readonly Warning: 1;
|
|
57
|
+
readonly Fatal: 2;
|
|
58
|
+
};
|
|
59
|
+
export type AlertLevel = (typeof AlertLevels)[keyof typeof AlertLevels];
|
|
60
|
+
export declare const AlertLevelNames: any;
|
|
61
|
+
export declare const AlertDescriptions: {
|
|
62
|
+
readonly CloseNotify: 0;
|
|
63
|
+
readonly UnexpectedMessage: 10;
|
|
64
|
+
readonly BadRecordMac: 20;
|
|
65
|
+
readonly DecryptionFailed: 21;
|
|
66
|
+
readonly RecordOverflow: 22;
|
|
67
|
+
readonly DecompressionFailure: 30;
|
|
68
|
+
readonly HandshakeFailure: 40;
|
|
69
|
+
readonly NoCertificate: 41;
|
|
70
|
+
readonly BadCertificate: 42;
|
|
71
|
+
readonly UnsupportedCertificate: 43;
|
|
72
|
+
readonly CertificateRevoked: 44;
|
|
73
|
+
readonly CertificateExpired: 45;
|
|
74
|
+
readonly CertificateUnknown: 46;
|
|
75
|
+
readonly IllegalParameter: 47;
|
|
76
|
+
readonly UnknownCa: 48;
|
|
77
|
+
readonly AccessDenied: 49;
|
|
78
|
+
readonly DecodeError: 50;
|
|
79
|
+
readonly DecryptError: 51;
|
|
80
|
+
readonly ExportRestriction: 60;
|
|
81
|
+
readonly ProtocolVersion: 70;
|
|
82
|
+
readonly InsufficientSecurity: 71;
|
|
83
|
+
readonly InternalError: 80;
|
|
84
|
+
readonly UserCanceled: 90;
|
|
85
|
+
readonly NoRenegotiation: 100;
|
|
86
|
+
readonly UnsupportedExtension: 110;
|
|
87
|
+
};
|
|
88
|
+
export type AlertDescription = (typeof AlertDescriptions)[keyof typeof AlertDescriptions];
|
|
89
|
+
export declare const AlertDescriptionNames: any;
|
|
90
|
+
export interface ChangeCipherSpecMessage {
|
|
91
|
+
type: typeof ContentTypes.ChangeCipherSpec;
|
|
92
|
+
body: Uint8Array;
|
|
93
|
+
}
|
|
94
|
+
export interface ApplicationDataMessage {
|
|
95
|
+
type: typeof ContentTypes.ApplicationData;
|
|
96
|
+
body: Uint8Array;
|
|
97
|
+
}
|
|
98
|
+
export declare const ContentTypes: {
|
|
99
|
+
readonly ChangeCipherSpec: 20;
|
|
100
|
+
readonly Alert: 21;
|
|
101
|
+
readonly Handshake: 22;
|
|
102
|
+
readonly ApplicationData: 23;
|
|
103
|
+
};
|
|
104
|
+
export type ContentType = (typeof ContentTypes)[keyof typeof ContentTypes];
|
|
105
|
+
export declare const enum HandshakeType {
|
|
106
|
+
HelloRequest = 0,
|
|
107
|
+
ClientHello = 1,
|
|
108
|
+
ServerHello = 2,
|
|
109
|
+
Certificate = 11,
|
|
110
|
+
ServerKeyExchange = 12,
|
|
111
|
+
CertificateRequest = 13,
|
|
112
|
+
ServerHelloDone = 14,
|
|
113
|
+
CertificateVerify = 15,
|
|
114
|
+
ClientKeyExchange = 16,
|
|
115
|
+
Finished = 20
|
|
116
|
+
}
|
|
117
|
+
export type HandshakeMessageBody = HelloRequest | ClientHello | ServerHello | Certificate | ServerKeyExchange | CertificateRequest | ServerHelloDone | CertificateVerify | ClientKeyExchange | Finished;
|
|
118
|
+
export interface HandshakeMessage<Body extends HandshakeMessageBody> {
|
|
119
|
+
type: typeof ContentTypes.Handshake;
|
|
120
|
+
msg_type: HandshakeType;
|
|
121
|
+
length: number;
|
|
122
|
+
body: Body;
|
|
123
|
+
}
|
|
124
|
+
export interface HelloRequest {
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* 1 byte
|
|
128
|
+
*/
|
|
129
|
+
export type SessionId = Uint8Array;
|
|
130
|
+
export interface ClientHello {
|
|
131
|
+
client_version: Uint8Array;
|
|
132
|
+
random: Uint8Array;
|
|
133
|
+
session_id: SessionId;
|
|
134
|
+
cipher_suites: string[];
|
|
135
|
+
compression_methods: Uint8Array;
|
|
136
|
+
extensions: ParsedExtension[];
|
|
137
|
+
}
|
|
138
|
+
export interface ServerHello {
|
|
139
|
+
server_version: Uint8Array;
|
|
140
|
+
random: Uint8Array;
|
|
141
|
+
session_id: Uint8Array;
|
|
142
|
+
cipher_suite: Uint8Array;
|
|
143
|
+
compression_method: number;
|
|
144
|
+
extensions?: Uint8Array;
|
|
145
|
+
}
|
|
146
|
+
export interface Certificate {
|
|
147
|
+
certificate_list: Uint8Array[];
|
|
148
|
+
}
|
|
149
|
+
export interface ServerKeyExchange {
|
|
150
|
+
params: Uint8Array;
|
|
151
|
+
signed_params: Uint8Array;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* ECCurveType from
|
|
155
|
+
* https://datatracker.ietf.org/doc/html/rfc4492#section-5.4
|
|
156
|
+
*/
|
|
157
|
+
export declare const ECCurveTypes: {
|
|
158
|
+
/**
|
|
159
|
+
* Indicates the elliptic curve domain parameters are
|
|
160
|
+
* conveyed verbosely, and the underlying finite field is a prime
|
|
161
|
+
* field.
|
|
162
|
+
*/
|
|
163
|
+
ExplicitPrime: number;
|
|
164
|
+
/**
|
|
165
|
+
* Indicates the elliptic curve domain parameters are
|
|
166
|
+
* conveyed verbosely, and the underlying finite field is a
|
|
167
|
+
* characteristic-2 field.
|
|
168
|
+
*/
|
|
169
|
+
ExplicitChar2: number;
|
|
170
|
+
/**
|
|
171
|
+
* Indicates that a named curve is used. This option
|
|
172
|
+
* SHOULD be used when applicable.
|
|
173
|
+
*/
|
|
174
|
+
NamedCurve: number;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Named elliptic curves from
|
|
178
|
+
* https://datatracker.ietf.org/doc/html/rfc4492#section-5.1.1
|
|
179
|
+
*/
|
|
180
|
+
export declare const ECNamedCurves: {
|
|
181
|
+
sect163k1: number;
|
|
182
|
+
sect163r1: number;
|
|
183
|
+
sect163r2: number;
|
|
184
|
+
sect193r1: number;
|
|
185
|
+
sect193r2: number;
|
|
186
|
+
sect233k1: number;
|
|
187
|
+
sect233r1: number;
|
|
188
|
+
sect239k1: number;
|
|
189
|
+
sect283k1: number;
|
|
190
|
+
sect283r1: number;
|
|
191
|
+
sect409k1: number;
|
|
192
|
+
sect409r1: number;
|
|
193
|
+
secp256k1: number;
|
|
194
|
+
secp256r1: number;
|
|
195
|
+
secp384r1: number;
|
|
196
|
+
secp521r1: number;
|
|
197
|
+
arbitrary_explicit_prime_curves: number;
|
|
198
|
+
arbitrary_explicit_char2_curves: number;
|
|
199
|
+
};
|
|
200
|
+
export interface CertificateRequest {
|
|
201
|
+
certificate_types: Uint8Array;
|
|
202
|
+
supported_signature_algorithms: Uint8Array;
|
|
203
|
+
certificate_authorities: Uint8Array;
|
|
204
|
+
}
|
|
205
|
+
export interface ServerHelloDone {
|
|
206
|
+
}
|
|
207
|
+
export interface CertificateVerify {
|
|
208
|
+
algorithm: Uint8Array;
|
|
209
|
+
signature: Uint8Array;
|
|
210
|
+
}
|
|
211
|
+
export interface ClientKeyExchange {
|
|
212
|
+
exchange_keys: Uint8Array;
|
|
213
|
+
}
|
|
214
|
+
export interface Finished {
|
|
215
|
+
verify_data: Uint8Array;
|
|
216
|
+
}
|
|
217
|
+
export type SessionKeys = {
|
|
218
|
+
masterSecret: Uint8Array;
|
|
219
|
+
clientWriteKey: CryptoKey;
|
|
220
|
+
serverWriteKey: CryptoKey;
|
|
221
|
+
clientIV: Uint8Array;
|
|
222
|
+
serverIV: Uint8Array;
|
|
223
|
+
};
|