1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | declare module 'tls' {
|
12 | import { X509Certificate } from 'node:crypto';
|
13 | import * as net from 'node:net';
|
14 | const CLIENT_RENEG_LIMIT: number;
|
15 | const CLIENT_RENEG_WINDOW: number;
|
16 | interface Certificate {
|
17 | |
18 |
|
19 |
|
20 | C: string;
|
21 | |
22 |
|
23 |
|
24 | ST: string;
|
25 | |
26 |
|
27 |
|
28 | L: string;
|
29 | |
30 |
|
31 |
|
32 | O: string;
|
33 | |
34 |
|
35 |
|
36 | OU: string;
|
37 | |
38 |
|
39 |
|
40 | CN: string;
|
41 | }
|
42 | interface PeerCertificate {
|
43 | subject: Certificate;
|
44 | issuer: Certificate;
|
45 | subjectaltname: string;
|
46 | infoAccess: NodeJS.Dict<string[]>;
|
47 | modulus: string;
|
48 | exponent: string;
|
49 | valid_from: string;
|
50 | valid_to: string;
|
51 | fingerprint: string;
|
52 | fingerprint256: string;
|
53 | ext_key_usage: string[];
|
54 | serialNumber: string;
|
55 | raw: Buffer;
|
56 | }
|
57 | interface DetailedPeerCertificate extends PeerCertificate {
|
58 | issuerCertificate: DetailedPeerCertificate;
|
59 | }
|
60 | interface CipherNameAndProtocol {
|
61 | |
62 |
|
63 |
|
64 | name: string;
|
65 | |
66 |
|
67 |
|
68 | version: string;
|
69 | |
70 |
|
71 |
|
72 | standardName: string;
|
73 | }
|
74 | interface EphemeralKeyInfo {
|
75 | |
76 |
|
77 |
|
78 | type: string;
|
79 | |
80 |
|
81 |
|
82 | name?: string | undefined;
|
83 | |
84 |
|
85 |
|
86 | size: number;
|
87 | }
|
88 | interface KeyObject {
|
89 | |
90 |
|
91 |
|
92 | pem: string | Buffer;
|
93 | |
94 |
|
95 |
|
96 | passphrase?: string | undefined;
|
97 | }
|
98 | interface PxfObject {
|
99 | |
100 |
|
101 |
|
102 | buf: string | Buffer;
|
103 | |
104 |
|
105 |
|
106 | passphrase?: string | undefined;
|
107 | }
|
108 | interface TLSSocketOptions extends SecureContextOptions, CommonConnectionOptions {
|
109 | |
110 |
|
111 |
|
112 |
|
113 | isServer?: boolean | undefined;
|
114 | |
115 |
|
116 |
|
117 | server?: net.Server | undefined;
|
118 | |
119 |
|
120 |
|
121 | session?: Buffer | undefined;
|
122 | |
123 |
|
124 |
|
125 |
|
126 |
|
127 | requestOCSP?: boolean | undefined;
|
128 | }
|
129 | |
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 | class TLSSocket extends net.Socket {
|
140 | |
141 |
|
142 |
|
143 | constructor(socket: net.Socket, options?: TLSSocketOptions);
|
144 | /**
|
145 | * Returns `true` if the peer certificate was signed by one of the CAs specified
|
146 | * when creating the `tls.TLSSocket` instance, otherwise `false`.
|
147 | * @since v0.11.4
|
148 | */
|
149 | authorized: boolean;
|
150 | /**
|
151 | * Returns the reason why the peer's certificate was not been verified. This
|
152 | * property is set only when `tlsSocket.authorized === false`.
|
153 | * @since v0.11.4
|
154 | */
|
155 | authorizationError: Error;
|
156 | /**
|
157 | * Always returns `true`. This may be used to distinguish TLS sockets from regular`net.Socket` instances.
|
158 | * @since v0.11.4
|
159 | */
|
160 | encrypted: boolean;
|
161 | /**
|
162 | * String containing the selected ALPN protocol.
|
163 | * When ALPN has no selected protocol, tlsSocket.alpnProtocol equals false.
|
164 | */
|
165 | alpnProtocol?: string | undefined;
|
166 | /**
|
167 | * Returns an object representing the local certificate. The returned object has
|
168 | * some properties corresponding to the fields of the certificate.
|
169 | *
|
170 | * See {@link TLSSocket.getPeerCertificate} for an example of the certificate
|
171 | * structure.
|
172 | *
|
173 | * If there is no local certificate, an empty object will be returned. If the
|
174 | * socket has been destroyed, `null` will be returned.
|
175 | * @since v11.2.0
|
176 | */
|
177 | getCertificate(): PeerCertificate | object | null;
|
178 | |
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 | getCipher(): CipherNameAndProtocol;
|
195 | |
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 | getEphemeralKeyInfo(): EphemeralKeyInfo | object | null;
|
206 | |
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 | getFinished(): Buffer | undefined;
|
218 | |
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 | getPeerCertificate(detailed: true): DetailedPeerCertificate;
|
230 | getPeerCertificate(detailed?: false): PeerCertificate;
|
231 | getPeerCertificate(detailed?: boolean): PeerCertificate | DetailedPeerCertificate;
|
232 | |
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 | getPeerFinished(): Buffer | undefined;
|
245 | |
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 | getProtocol(): string | null;
|
263 | |
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 | getSession(): Buffer | undefined;
|
275 | |
276 |
|
277 |
|
278 |
|
279 |
|
280 | getSharedSigalgs(): string[];
|
281 | |
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 | getTLSTicket(): Buffer | undefined;
|
290 | |
291 |
|
292 |
|
293 |
|
294 |
|
295 | isSessionReused(): boolean;
|
296 | |
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 | renegotiate(
|
314 | options: {
|
315 | rejectUnauthorized?: boolean | undefined;
|
316 | requestCert?: boolean | undefined;
|
317 | },
|
318 | callback: (err: Error | null) => void
|
319 | ): undefined | boolean;
|
320 | |
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 | setMaxSendFragment(size: number): boolean;
|
334 | |
335 |
|
336 |
|
337 |
|
338 |
|
339 | disableRenegotiation(): void;
|
340 | |
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 | enableTrace(): void;
|
350 | |
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 | getPeerX509Certificate(): X509Certificate | undefined;
|
357 | |
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 | getX509Certificate(): X509Certificate | undefined;
|
364 | |
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 | exportKeyingMaterial(length: number, label: string, context: Buffer): Buffer;
|
393 | addListener(event: string, listener: (...args: any[]) => void): this;
|
394 | addListener(event: 'OCSPResponse', listener: (response: Buffer) => void): this;
|
395 | addListener(event: 'secureConnect', listener: () => void): this;
|
396 | addListener(event: 'session', listener: (session: Buffer) => void): this;
|
397 | addListener(event: 'keylog', listener: (line: Buffer) => void): this;
|
398 | emit(event: string | symbol, ...args: any[]): boolean;
|
399 | emit(event: 'OCSPResponse', response: Buffer): boolean;
|
400 | emit(event: 'secureConnect'): boolean;
|
401 | emit(event: 'session', session: Buffer): boolean;
|
402 | emit(event: 'keylog', line: Buffer): boolean;
|
403 | on(event: string, listener: (...args: any[]) => void): this;
|
404 | on(event: 'OCSPResponse', listener: (response: Buffer) => void): this;
|
405 | on(event: 'secureConnect', listener: () => void): this;
|
406 | on(event: 'session', listener: (session: Buffer) => void): this;
|
407 | on(event: 'keylog', listener: (line: Buffer) => void): this;
|
408 | once(event: string, listener: (...args: any[]) => void): this;
|
409 | once(event: 'OCSPResponse', listener: (response: Buffer) => void): this;
|
410 | once(event: 'secureConnect', listener: () => void): this;
|
411 | once(event: 'session', listener: (session: Buffer) => void): this;
|
412 | once(event: 'keylog', listener: (line: Buffer) => void): this;
|
413 | prependListener(event: string, listener: (...args: any[]) => void): this;
|
414 | prependListener(event: 'OCSPResponse', listener: (response: Buffer) => void): this;
|
415 | prependListener(event: 'secureConnect', listener: () => void): this;
|
416 | prependListener(event: 'session', listener: (session: Buffer) => void): this;
|
417 | prependListener(event: 'keylog', listener: (line: Buffer) => void): this;
|
418 | prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
419 | prependOnceListener(event: 'OCSPResponse', listener: (response: Buffer) => void): this;
|
420 | prependOnceListener(event: 'secureConnect', listener: () => void): this;
|
421 | prependOnceListener(event: 'session', listener: (session: Buffer) => void): this;
|
422 | prependOnceListener(event: 'keylog', listener: (line: Buffer) => void): this;
|
423 | }
|
424 | interface CommonConnectionOptions {
|
425 | |
426 |
|
427 |
|
428 | secureContext?: SecureContext | undefined;
|
429 | |
430 |
|
431 |
|
432 |
|
433 |
|
434 | enableTrace?: boolean | undefined;
|
435 | |
436 |
|
437 |
|
438 |
|
439 |
|
440 | requestCert?: boolean | undefined;
|
441 | |
442 |
|
443 |
|
444 |
|
445 | ALPNProtocols?: string[] | Uint8Array[] | Uint8Array | undefined;
|
446 | |
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 | SNICallback?: ((servername: string, cb: (err: Error | null, ctx: SecureContext) => void) => void) | undefined;
|
456 | /**
|
457 | * If true the server will reject any connection which is not
|
458 | * authorized with the list of supplied CAs. This option only has an
|
459 | * effect if requestCert is true.
|
460 | * @default true
|
461 | */
|
462 | rejectUnauthorized?: boolean | undefined;
|
463 | }
|
464 | interface TlsOptions extends SecureContextOptions, CommonConnectionOptions, net.ServerOpts {
|
465 | /**
|
466 | * Abort the connection if the SSL/TLS handshake does not finish in the
|
467 | * specified number of milliseconds. A 'tlsClientError' is emitted on
|
468 | * the tls.Server object whenever a handshake times out. Default:
|
469 | * 120000 (120 seconds).
|
470 | */
|
471 | handshakeTimeout?: number | undefined;
|
472 | /**
|
473 | * The number of seconds after which a TLS session created by the
|
474 | * server will no longer be resumable. See Session Resumption for more
|
475 | * information. Default: 300.
|
476 | */
|
477 | sessionTimeout?: number | undefined;
|
478 | /**
|
479 | * 48-bytes of cryptographically strong pseudo-random data.
|
480 | */
|
481 | ticketKeys?: Buffer | undefined;
|
482 | /**
|
483 | *
|
484 | * @param socket
|
485 | * @param identity identity parameter sent from the client.
|
486 | * @return pre-shared key that must either be
|
487 | * a buffer or `null` to stop the negotiation process. Returned PSK must be
|
488 | * compatible with the selected cipher's digest.
|
489 | *
|
490 | * When negotiating TLS-PSK (pre-shared keys), this function is called
|
491 | * with the identity provided by the client.
|
492 | * If the return value is `null` the negotiation process will stop and an
|
493 | * "unknown_psk_identity" alert message will be sent to the other party.
|
494 | * If the server wishes to hide the fact that the PSK identity was not known,
|
495 | * the callback must provide some random data as `psk` to make the connection
|
496 | * fail with "decrypt_error" before negotiation is finished.
|
497 | * PSK ciphers are disabled by default, and using TLS-PSK thus
|
498 | * requires explicitly specifying a cipher suite with the `ciphers` option.
|
499 | * More information can be found in the RFC 4279.
|
500 | */
|
501 | pskCallback?(socket: TLSSocket, identity: string): DataView | NodeJS.TypedArray | null;
|
502 | /**
|
503 | * hint to send to a client to help
|
504 | * with selecting the identity during TLS-PSK negotiation. Will be ignored
|
505 | * in TLS 1.3. Upon failing to set pskIdentityHint `tlsClientError` will be
|
506 | * emitted with `ERR_TLS_PSK_SET_IDENTIY_HINT_FAILED` code.
|
507 | */
|
508 | pskIdentityHint?: string | undefined;
|
509 | }
|
510 | interface PSKCallbackNegotation {
|
511 | psk: DataView | NodeJS.TypedArray;
|
512 | identity: string;
|
513 | }
|
514 | interface ConnectionOptions extends SecureContextOptions, CommonConnectionOptions {
|
515 | host?: string | undefined;
|
516 | port?: number | undefined;
|
517 | path?: string | undefined; // Creates unix socket connection to path. If this option is specified, `host` and `port` are ignored.
|
518 | socket?: net.Socket | undefined; // Establish secure connection on a given socket rather than creating a new socket
|
519 | checkServerIdentity?: typeof checkServerIdentity | undefined;
|
520 | servername?: string | undefined; // SNI TLS Extension
|
521 | session?: Buffer | undefined;
|
522 | minDHSize?: number | undefined;
|
523 | lookup?: net.LookupFunction | undefined;
|
524 | timeout?: number | undefined;
|
525 | /**
|
526 | * When negotiating TLS-PSK (pre-shared keys), this function is called
|
527 | * with optional identity `hint` provided by the server or `null`
|
528 | * in case of TLS 1.3 where `hint` was removed.
|
529 | * It will be necessary to provide a custom `tls.checkServerIdentity()`
|
530 | * for the connection as the default one will try to check hostname/IP
|
531 | * of the server against the certificate but that's not applicable for PSK
|
532 | * because there won't be a certificate present.
|
533 | * More information can be found in the RFC 4279.
|
534 | *
|
535 | * @param hint message sent from the server to help client
|
536 | * decide which identity to use during negotiation.
|
537 | * Always `null` if TLS 1.3 is used.
|
538 | * @returns Return `null` to stop the negotiation process. `psk` must be
|
539 | * compatible with the selected cipher's digest.
|
540 | * `identity` must use UTF-8 encoding.
|
541 | */
|
542 | pskCallback?(hint: string | null): PSKCallbackNegotation | null;
|
543 | }
|
544 | /**
|
545 | * Accepts encrypted connections using TLS or SSL.
|
546 | * @since v0.3.2
|
547 | */
|
548 | class Server extends net.Server {
|
549 | constructor(secureConnectionListener?: (socket: TLSSocket) => void);
|
550 | constructor(options: TlsOptions, secureConnectionListener?: (socket: TLSSocket) => void);
|
551 | /**
|
552 | * The `server.addContext()` method adds a secure context that will be used if
|
553 | * the client request's SNI name matches the supplied `hostname` (or wildcard).
|
554 | *
|
555 | * When there are multiple matching contexts, the most recently added one is
|
556 | * used.
|
557 | * @since v0.5.3
|
558 | * @param hostname A SNI host name or wildcard (e.g. `'*'`)
|
559 | * @param context An object containing any of the possible properties from the {@link createSecureContext} `options` arguments (e.g. `key`, `cert`, `ca`, etc).
|
560 | */
|
561 | addContext(hostname: string, context: SecureContextOptions): void;
|
562 | /**
|
563 | * Returns the session ticket keys.
|
564 | *
|
565 | * See `Session Resumption` for more information.
|
566 | * @since v3.0.0
|
567 | * @return A 48-byte buffer containing the session ticket keys.
|
568 | */
|
569 | getTicketKeys(): Buffer;
|
570 | /**
|
571 | * The `server.setSecureContext()` method replaces the secure context of an
|
572 | * existing server. Existing connections to the server are not interrupted.
|
573 | * @since v11.0.0
|
574 | * @param options An object containing any of the possible properties from the {@link createSecureContext} `options` arguments (e.g. `key`, `cert`, `ca`, etc).
|
575 | */
|
576 | setSecureContext(options: SecureContextOptions): void;
|
577 | /**
|
578 | * Sets the session ticket keys.
|
579 | *
|
580 | * Changes to the ticket keys are effective only for future server connections.
|
581 | * Existing or currently pending server connections will use the previous keys.
|
582 | *
|
583 | * See `Session Resumption` for more information.
|
584 | * @since v3.0.0
|
585 | * @param keys A 48-byte buffer containing the session ticket keys.
|
586 | */
|
587 | setTicketKeys(keys: Buffer): void;
|
588 | /**
|
589 | * events.EventEmitter
|
590 | * 1. tlsClientError
|
591 | * 2. newSession
|
592 | * 3. OCSPRequest
|
593 | * 4. resumeSession
|
594 | * 5. secureConnection
|
595 | * 6. keylog
|
596 | */
|
597 | addListener(event: string, listener: (...args: any[]) => void): this;
|
598 | addListener(event: 'tlsClientError', listener: (err: Error, tlsSocket: TLSSocket) => void): this;
|
599 | addListener(event: 'newSession', listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void): this;
|
600 | addListener(event: 'OCSPRequest', listener: (certificate: Buffer, issuer: Buffer, callback: (err: Error | null, resp: Buffer) => void) => void): this;
|
601 | addListener(event: 'resumeSession', listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void): this;
|
602 | addListener(event: 'secureConnection', listener: (tlsSocket: TLSSocket) => void): this;
|
603 | addListener(event: 'keylog', listener: (line: Buffer, tlsSocket: TLSSocket) => void): this;
|
604 | emit(event: string | symbol, ...args: any[]): boolean;
|
605 | emit(event: 'tlsClientError', err: Error, tlsSocket: TLSSocket): boolean;
|
606 | emit(event: 'newSession', sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void): boolean;
|
607 | emit(event: 'OCSPRequest', certificate: Buffer, issuer: Buffer, callback: (err: Error | null, resp: Buffer) => void): boolean;
|
608 | emit(event: 'resumeSession', sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void): boolean;
|
609 | emit(event: 'secureConnection', tlsSocket: TLSSocket): boolean;
|
610 | emit(event: 'keylog', line: Buffer, tlsSocket: TLSSocket): boolean;
|
611 | on(event: string, listener: (...args: any[]) => void): this;
|
612 | on(event: 'tlsClientError', listener: (err: Error, tlsSocket: TLSSocket) => void): this;
|
613 | on(event: 'newSession', listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void): this;
|
614 | on(event: 'OCSPRequest', listener: (certificate: Buffer, issuer: Buffer, callback: (err: Error | null, resp: Buffer) => void) => void): this;
|
615 | on(event: 'resumeSession', listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void): this;
|
616 | on(event: 'secureConnection', listener: (tlsSocket: TLSSocket) => void): this;
|
617 | on(event: 'keylog', listener: (line: Buffer, tlsSocket: TLSSocket) => void): this;
|
618 | once(event: string, listener: (...args: any[]) => void): this;
|
619 | once(event: 'tlsClientError', listener: (err: Error, tlsSocket: TLSSocket) => void): this;
|
620 | once(event: 'newSession', listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void): this;
|
621 | once(event: 'OCSPRequest', listener: (certificate: Buffer, issuer: Buffer, callback: (err: Error | null, resp: Buffer) => void) => void): this;
|
622 | once(event: 'resumeSession', listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void): this;
|
623 | once(event: 'secureConnection', listener: (tlsSocket: TLSSocket) => void): this;
|
624 | once(event: 'keylog', listener: (line: Buffer, tlsSocket: TLSSocket) => void): this;
|
625 | prependListener(event: string, listener: (...args: any[]) => void): this;
|
626 | prependListener(event: 'tlsClientError', listener: (err: Error, tlsSocket: TLSSocket) => void): this;
|
627 | prependListener(event: 'newSession', listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void): this;
|
628 | prependListener(event: 'OCSPRequest', listener: (certificate: Buffer, issuer: Buffer, callback: (err: Error | null, resp: Buffer) => void) => void): this;
|
629 | prependListener(event: 'resumeSession', listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void): this;
|
630 | prependListener(event: 'secureConnection', listener: (tlsSocket: TLSSocket) => void): this;
|
631 | prependListener(event: 'keylog', listener: (line: Buffer, tlsSocket: TLSSocket) => void): this;
|
632 | prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
633 | prependOnceListener(event: 'tlsClientError', listener: (err: Error, tlsSocket: TLSSocket) => void): this;
|
634 | prependOnceListener(event: 'newSession', listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void): this;
|
635 | prependOnceListener(event: 'OCSPRequest', listener: (certificate: Buffer, issuer: Buffer, callback: (err: Error | null, resp: Buffer) => void) => void): this;
|
636 | prependOnceListener(event: 'resumeSession', listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void): this;
|
637 | prependOnceListener(event: 'secureConnection', listener: (tlsSocket: TLSSocket) => void): this;
|
638 | prependOnceListener(event: 'keylog', listener: (line: Buffer, tlsSocket: TLSSocket) => void): this;
|
639 | }
|
640 | /**
|
641 | * @deprecated since v0.11.3 Use `tls.TLSSocket` instead.
|
642 | */
|
643 | interface SecurePair {
|
644 | encrypted: TLSSocket;
|
645 | cleartext: TLSSocket;
|
646 | }
|
647 | type SecureVersion = 'TLSv1.3' | 'TLSv1.2' | 'TLSv1.1' | 'TLSv1';
|
648 | interface SecureContextOptions {
|
649 | /**
|
650 | * Optionally override the trusted CA certificates. Default is to trust
|
651 | * the well-known CAs curated by Mozilla. Mozilla's CAs are completely
|
652 | * replaced when CAs are explicitly specified using this option.
|
653 | */
|
654 | ca?: string | Buffer | Array<string | Buffer> | undefined;
|
655 | /**
|
656 | * Cert chains in PEM format. One cert chain should be provided per
|
657 | * private key. Each cert chain should consist of the PEM formatted
|
658 | * certificate for a provided private key, followed by the PEM
|
659 | * formatted intermediate certificates (if any), in order, and not
|
660 | * including the root CA (the root CA must be pre-known to the peer,
|
661 | * see ca). When providing multiple cert chains, they do not have to
|
662 | * be in the same order as their private keys in key. If the
|
663 | * intermediate certificates are not provided, the peer will not be
|
664 | * able to validate the certificate, and the handshake will fail.
|
665 | */
|
666 | cert?: string | Buffer | Array<string | Buffer> | undefined;
|
667 | /**
|
668 | * Colon-separated list of supported signature algorithms. The list
|
669 | * can contain digest algorithms (SHA256, MD5 etc.), public key
|
670 | * algorithms (RSA-PSS, ECDSA etc.), combination of both (e.g
|
671 | * 'RSA+SHA384') or TLS v1.3 scheme names (e.g. rsa_pss_pss_sha512).
|
672 | */
|
673 | sigalgs?: string | undefined;
|
674 | /**
|
675 | * Cipher suite specification, replacing the default. For more
|
676 | * information, see modifying the default cipher suite. Permitted
|
677 | * ciphers can be obtained via tls.getCiphers(). Cipher names must be
|
678 | * uppercased in order for OpenSSL to accept them.
|
679 | */
|
680 | ciphers?: string | undefined;
|
681 | /**
|
682 | * Name of an OpenSSL engine which can provide the client certificate.
|
683 | */
|
684 | clientCertEngine?: string | undefined;
|
685 | /**
|
686 | * PEM formatted CRLs (Certificate Revocation Lists).
|
687 | */
|
688 | crl?: string | Buffer | Array<string | Buffer> | undefined;
|
689 | /**
|
690 | * Diffie Hellman parameters, required for Perfect Forward Secrecy. Use
|
691 | * openssl dhparam to create the parameters. The key length must be
|
692 | * greater than or equal to 1024 bits or else an error will be thrown.
|
693 | * Although 1024 bits is permissible, use 2048 bits or larger for
|
694 | * stronger security. If omitted or invalid, the parameters are
|
695 | * silently discarded and DHE ciphers will not be available.
|
696 | */
|
697 | dhparam?: string | Buffer | undefined;
|
698 | /**
|
699 | * A string describing a named curve or a colon separated list of curve
|
700 | * NIDs or names, for example P-521:P-384:P-256, to use for ECDH key
|
701 | * agreement. Set to auto to select the curve automatically. Use
|
702 | * crypto.getCurves() to obtain a list of available curve names. On
|
703 | * recent releases, openssl ecparam -list_curves will also display the
|
704 | * name and description of each available elliptic curve. Default:
|
705 | * tls.DEFAULT_ECDH_CURVE.
|
706 | */
|
707 | ecdhCurve?: string | undefined;
|
708 | /**
|
709 | * Attempt to use the server's cipher suite preferences instead of the
|
710 | * client's. When true, causes SSL_OP_CIPHER_SERVER_PREFERENCE to be
|
711 | * set in secureOptions
|
712 | */
|
713 | honorCipherOrder?: boolean | undefined;
|
714 | /**
|
715 | * Private keys in PEM format. PEM allows the option of private keys
|
716 | * being encrypted. Encrypted keys will be decrypted with
|
717 | * options.passphrase. Multiple keys using different algorithms can be
|
718 | * provided either as an array of unencrypted key strings or buffers,
|
719 | * or an array of objects in the form {pem: <string|buffer>[,
|
720 | * passphrase: <string>]}. The object form can only occur in an array.
|
721 | * object.passphrase is optional. Encrypted keys will be decrypted with
|
722 | * object.passphrase if provided, or options.passphrase if it is not.
|
723 | */
|
724 | key?: string | Buffer | Array<Buffer | KeyObject> | undefined;
|
725 | /**
|
726 | * Name of an OpenSSL engine to get private key from. Should be used
|
727 | * together with privateKeyIdentifier.
|
728 | */
|
729 | privateKeyEngine?: string | undefined;
|
730 | /**
|
731 | * Identifier of a private key managed by an OpenSSL engine. Should be
|
732 | * used together with privateKeyEngine. Should not be set together with
|
733 | * key, because both options define a private key in different ways.
|
734 | */
|
735 | privateKeyIdentifier?: string | undefined;
|
736 | /**
|
737 | * Optionally set the maximum TLS version to allow. One
|
738 | * of `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the
|
739 | * `secureProtocol` option, use one or the other.
|
740 | * **Default:** `'TLSv1.3'`, unless changed using CLI options. Using
|
741 | * `--tls-max-v1.2` sets the default to `'TLSv1.2'`. Using `--tls-max-v1.3` sets the default to
|
742 | * `'TLSv1.3'`. If multiple of the options are provided, the highest maximum is used.
|
743 | */
|
744 | maxVersion?: SecureVersion | undefined;
|
745 | /**
|
746 | * Optionally set the minimum TLS version to allow. One
|
747 | * of `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the
|
748 | * `secureProtocol` option, use one or the other. It is not recommended to use
|
749 | * less than TLSv1.2, but it may be required for interoperability.
|
750 | * **Default:** `'TLSv1.2'`, unless changed using CLI options. Using
|
751 | * `--tls-v1.0` sets the default to `'TLSv1'`. Using `--tls-v1.1` sets the default to
|
752 | * `'TLSv1.1'`. Using `--tls-min-v1.3` sets the default to
|
753 | * 'TLSv1.3'. If multiple of the options are provided, the lowest minimum is used.
|
754 | */
|
755 | minVersion?: SecureVersion | undefined;
|
756 | /**
|
757 | * Shared passphrase used for a single private key and/or a PFX.
|
758 | */
|
759 | passphrase?: string | undefined;
|
760 | /**
|
761 | * PFX or PKCS12 encoded private key and certificate chain. pfx is an
|
762 | * alternative to providing key and cert individually. PFX is usually
|
763 | * encrypted, if it is, passphrase will be used to decrypt it. Multiple
|
764 | * PFX can be provided either as an array of unencrypted PFX buffers,
|
765 | * or an array of objects in the form {buf: <string|buffer>[,
|
766 | * passphrase: <string>]}. The object form can only occur in an array.
|
767 | * object.passphrase is optional. Encrypted PFX will be decrypted with
|
768 | * object.passphrase if provided, or options.passphrase if it is not.
|
769 | */
|
770 | pfx?: string | Buffer | Array<string | Buffer | PxfObject> | undefined;
|
771 | /**
|
772 | * Optionally affect the OpenSSL protocol behavior, which is not
|
773 | * usually necessary. This should be used carefully if at all! Value is
|
774 | * a numeric bitmask of the SSL_OP_* options from OpenSSL Options
|
775 | */
|
776 | secureOptions?: number | undefined; // Value is a numeric bitmask of the `SSL_OP_*` options
|
777 | /**
|
778 | * Legacy mechanism to select the TLS protocol version to use, it does
|
779 | * not support independent control of the minimum and maximum version,
|
780 | * and does not support limiting the protocol to TLSv1.3. Use
|
781 | * minVersion and maxVersion instead. The possible values are listed as
|
782 | * SSL_METHODS, use the function names as strings. For example, use
|
783 | * 'TLSv1_1_method' to force TLS version 1.1, or 'TLS_method' to allow
|
784 | * any TLS protocol version up to TLSv1.3. It is not recommended to use
|
785 | * TLS versions less than 1.2, but it may be required for
|
786 | * interoperability. Default: none, see minVersion.
|
787 | */
|
788 | secureProtocol?: string | undefined;
|
789 | /**
|
790 | * Opaque identifier used by servers to ensure session state is not
|
791 | * shared between applications. Unused by clients.
|
792 | */
|
793 | sessionIdContext?: string | undefined;
|
794 | /**
|
795 | * 48-bytes of cryptographically strong pseudo-random data.
|
796 | * See Session Resumption for more information.
|
797 | */
|
798 | ticketKeys?: Buffer | undefined;
|
799 | /**
|
800 | * The number of seconds after which a TLS session created by the
|
801 | * server will no longer be resumable. See Session Resumption for more
|
802 | * information. Default: 300.
|
803 | */
|
804 | sessionTimeout?: number | undefined;
|
805 | }
|
806 | interface SecureContext {
|
807 | context: any;
|
808 | }
|
809 | /**
|
810 | * Verifies the certificate `cert` is issued to `hostname`.
|
811 | *
|
812 | * Returns [<Error>](https:
|
813 | * failure. On success, returns [<undefined>](https:
|
814 | *
|
815 | * This function can be overwritten by providing alternative function as part of
|
816 | * the `options.checkServerIdentity` option passed to `tls.connect()`. The
|
817 | * overwriting function can call `tls.checkServerIdentity()` of course, to augment
|
818 | * the checks done with additional verification.
|
819 | *
|
820 | * This function is only called if the certificate passed all other checks, such as
|
821 | * being issued by trusted CA (`options.ca`).
|
822 | * @since v0.8.4
|
823 | * @param hostname The host name or IP address to verify the certificate against.
|
824 | * @param cert A `certificate object` representing the peer's certificate.
|
825 | */
|
826 | function checkServerIdentity(hostname: string, cert: PeerCertificate): Error | undefined;
|
827 | |
828 |
|
829 |
|
830 |
|
831 |
|
832 |
|
833 |
|
834 |
|
835 |
|
836 |
|
837 |
|
838 |
|
839 |
|
840 |
|
841 |
|
842 |
|
843 |
|
844 |
|
845 |
|
846 |
|
847 |
|
848 |
|
849 |
|
850 |
|
851 |
|
852 |
|
853 |
|
854 |
|
855 |
|
856 |
|
857 |
|
858 |
|
859 |
|
860 |
|
861 |
|
862 |
|
863 |
|
864 |
|
865 |
|
866 | function createServer(secureConnectionListener?: (socket: TLSSocket) => void): Server;
|
867 | function createServer(options: TlsOptions, secureConnectionListener?: (socket: TLSSocket) => void): Server;
|
868 | |
869 |
|
870 |
|
871 |
|
872 |
|
873 |
|
874 |
|
875 |
|
876 |
|
877 |
|
878 |
|
879 |
|
880 |
|
881 |
|
882 |
|
883 |
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 |
|
900 |
|
901 |
|
902 |
|
903 |
|
904 |
|
905 |
|
906 |
|
907 |
|
908 |
|
909 |
|
910 |
|
911 |
|
912 |
|
913 |
|
914 | function connect(options: ConnectionOptions, secureConnectListener?: () => void): TLSSocket;
|
915 | function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () => void): TLSSocket;
|
916 | function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () => void): TLSSocket;
|
917 | |
918 |
|
919 |
|
920 |
|
921 |
|
922 |
|
923 |
|
924 |
|
925 |
|
926 |
|
927 |
|
928 |
|
929 |
|
930 |
|
931 |
|
932 |
|
933 |
|
934 |
|
935 |
|
936 |
|
937 |
|
938 |
|
939 |
|
940 |
|
941 |
|
942 |
|
943 |
|
944 |
|
945 |
|
946 |
|
947 |
|
948 |
|
949 |
|
950 | function createSecurePair(context?: SecureContext, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair;
|
951 | |
952 |
|
953 |
|
954 |
|
955 |
|
956 |
|
957 |
|
958 |
|
959 |
|
960 |
|
961 |
|
962 |
|
963 |
|
964 |
|
965 |
|
966 |
|
967 |
|
968 | function createSecureContext(options?: SecureContextOptions): SecureContext;
|
969 | |
970 |
|
971 |
|
972 |
|
973 |
|
974 |
|
975 |
|
976 |
|
977 |
|
978 |
|
979 |
|
980 |
|
981 |
|
982 | function getCiphers(): string[];
|
983 | |
984 |
|
985 |
|
986 |
|
987 |
|
988 | let DEFAULT_ECDH_CURVE: string;
|
989 | |
990 |
|
991 |
|
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 |
|
998 | let DEFAULT_MAX_VERSION: SecureVersion;
|
999 | |
1000 |
|
1001 |
|
1002 |
|
1003 |
|
1004 |
|
1005 |
|
1006 |
|
1007 |
|
1008 | let DEFAULT_MIN_VERSION: SecureVersion;
|
1009 | |
1010 |
|
1011 |
|
1012 |
|
1013 |
|
1014 | const rootCertificates: ReadonlyArray<string>;
|
1015 | }
|
1016 | declare module 'node:tls' {
|
1017 | export * from 'tls';
|
1018 | }
|
1019 |
|
\ | No newline at end of file |