UNPKG

37.9 kBTypeScriptView Raw
1declare module 'node:tls' {
2 export * from 'tls';
3}
4
5declare module 'tls' {
6 import * as net from 'node:net';
7
8 const CLIENT_RENEG_LIMIT: number;
9 const CLIENT_RENEG_WINDOW: number;
10
11 interface Certificate {
12 /**
13 * Country code.
14 */
15 C: string;
16 /**
17 * Street.
18 */
19 ST: string;
20 /**
21 * Locality.
22 */
23 L: string;
24 /**
25 * Organization.
26 */
27 O: string;
28 /**
29 * Organizational unit.
30 */
31 OU: string;
32 /**
33 * Common name.
34 */
35 CN: string;
36 }
37
38 interface PeerCertificate {
39 subject: Certificate;
40 issuer: Certificate;
41 subjectaltname: string;
42 infoAccess: NodeJS.Dict<string[]>;
43 modulus: string;
44 exponent: string;
45 valid_from: string;
46 valid_to: string;
47 fingerprint: string;
48 fingerprint256: string;
49 ext_key_usage: string[];
50 serialNumber: string;
51 raw: Buffer;
52 }
53
54 interface DetailedPeerCertificate extends PeerCertificate {
55 issuerCertificate: DetailedPeerCertificate;
56 }
57
58 interface CipherNameAndProtocol {
59 /**
60 * The cipher name.
61 */
62 name: string;
63 /**
64 * SSL/TLS protocol version.
65 */
66 version: string;
67
68 /**
69 * IETF name for the cipher suite.
70 */
71 standardName: string;
72 }
73
74 interface EphemeralKeyInfo {
75 /**
76 * The supported types are 'DH' and 'ECDH'.
77 */
78 type: string;
79 /**
80 * The name property is available only when type is 'ECDH'.
81 */
82 name?: string;
83 /**
84 * The size of parameter of an ephemeral key exchange.
85 */
86 size: number;
87 }
88
89 interface KeyObject {
90 /**
91 * Private keys in PEM format.
92 */
93 pem: string | Buffer;
94 /**
95 * Optional passphrase.
96 */
97 passphrase?: string;
98 }
99
100 interface PxfObject {
101 /**
102 * PFX or PKCS12 encoded private key and certificate chain.
103 */
104 buf: string | Buffer;
105 /**
106 * Optional passphrase.
107 */
108 passphrase?: string;
109 }
110
111 interface TLSSocketOptions extends SecureContextOptions, CommonConnectionOptions {
112 /**
113 * If true the TLS socket will be instantiated in server-mode.
114 * Defaults to false.
115 */
116 isServer?: boolean;
117 /**
118 * An optional net.Server instance.
119 */
120 server?: net.Server;
121
122 /**
123 * An optional Buffer instance containing a TLS session.
124 */
125 session?: Buffer;
126 /**
127 * If true, specifies that the OCSP status request extension will be
128 * added to the client hello and an 'OCSPResponse' event will be
129 * emitted on the socket before establishing a secure communication
130 */
131 requestOCSP?: boolean;
132 }
133
134 class TLSSocket extends net.Socket {
135 /**
136 * Construct a new tls.TLSSocket object from an existing TCP socket.
137 */
138 constructor(socket: net.Socket, options?: TLSSocketOptions);
139
140 /**
141 * A boolean that is true if the peer certificate was signed by one of the specified CAs, otherwise false.
142 */
143 authorized: boolean;
144 /**
145 * The reason why the peer's certificate has not been verified.
146 * This property becomes available only when tlsSocket.authorized === false.
147 */
148 authorizationError: Error;
149 /**
150 * Static boolean value, always true.
151 * May be used to distinguish TLS sockets from regular ones.
152 */
153 encrypted: boolean;
154
155 /**
156 * String containing the selected ALPN protocol.
157 * When ALPN has no selected protocol, tlsSocket.alpnProtocol equals false.
158 */
159 alpnProtocol?: string;
160
161 /**
162 * Returns an object representing the local certificate. The returned
163 * object has some properties corresponding to the fields of the
164 * certificate.
165 *
166 * See tls.TLSSocket.getPeerCertificate() for an example of the
167 * certificate structure.
168 *
169 * If there is no local certificate, an empty object will be returned.
170 * If the socket has been destroyed, null will be returned.
171 */
172 getCertificate(): PeerCertificate | object | null;
173 /**
174 * Returns an object representing the cipher name and the SSL/TLS protocol version of the current connection.
175 * @returns Returns an object representing the cipher name
176 * and the SSL/TLS protocol version of the current connection.
177 */
178 getCipher(): CipherNameAndProtocol;
179 /**
180 * Returns an object representing the type, name, and size of parameter
181 * of an ephemeral key exchange in Perfect Forward Secrecy on a client
182 * connection. It returns an empty object when the key exchange is not
183 * ephemeral. As this is only supported on a client socket; null is
184 * returned if called on a server socket. The supported types are 'DH'
185 * and 'ECDH'. The name property is available only when type is 'ECDH'.
186 *
187 * For example: { type: 'ECDH', name: 'prime256v1', size: 256 }.
188 */
189 getEphemeralKeyInfo(): EphemeralKeyInfo | object | null;
190 /**
191 * Returns the latest Finished message that has
192 * been sent to the socket as part of a SSL/TLS handshake, or undefined
193 * if no Finished message has been sent yet.
194 *
195 * As the Finished messages are message digests of the complete
196 * handshake (with a total of 192 bits for TLS 1.0 and more for SSL
197 * 3.0), they can be used for external authentication procedures when
198 * the authentication provided by SSL/TLS is not desired or is not
199 * enough.
200 *
201 * Corresponds to the SSL_get_finished routine in OpenSSL and may be
202 * used to implement the tls-unique channel binding from RFC 5929.
203 */
204 getFinished(): Buffer | undefined;
205 /**
206 * Returns an object representing the peer's certificate.
207 * The returned object has some properties corresponding to the field of the certificate.
208 * If detailed argument is true the full chain with issuer property will be returned,
209 * if false only the top certificate without issuer property.
210 * If the peer does not provide a certificate, it returns null or an empty object.
211 * @param detailed - If true; the full chain with issuer property will be returned.
212 * @returns An object representing the peer's certificate.
213 */
214 getPeerCertificate(detailed: true): DetailedPeerCertificate;
215 getPeerCertificate(detailed?: false): PeerCertificate;
216 getPeerCertificate(detailed?: boolean): PeerCertificate | DetailedPeerCertificate;
217 /**
218 * Returns the latest Finished message that is expected or has actually
219 * been received from the socket as part of a SSL/TLS handshake, or
220 * undefined if there is no Finished message so far.
221 *
222 * As the Finished messages are message digests of the complete
223 * handshake (with a total of 192 bits for TLS 1.0 and more for SSL
224 * 3.0), they can be used for external authentication procedures when
225 * the authentication provided by SSL/TLS is not desired or is not
226 * enough.
227 *
228 * Corresponds to the SSL_get_peer_finished routine in OpenSSL and may
229 * be used to implement the tls-unique channel binding from RFC 5929.
230 */
231 getPeerFinished(): Buffer | undefined;
232 /**
233 * Returns a string containing the negotiated SSL/TLS protocol version of the current connection.
234 * The value `'unknown'` will be returned for connected sockets that have not completed the handshaking process.
235 * The value `null` will be returned for server sockets or disconnected client sockets.
236 * See https://www.openssl.org/docs/man1.0.2/ssl/SSL_get_version.html for more information.
237 * @returns negotiated SSL/TLS protocol version of the current connection
238 */
239 getProtocol(): string | null;
240 /**
241 * Could be used to speed up handshake establishment when reconnecting to the server.
242 * @returns ASN.1 encoded TLS session or undefined if none was negotiated.
243 */
244 getSession(): Buffer | undefined;
245 /**
246 * Returns a list of signature algorithms shared between the server and
247 * the client in the order of decreasing preference.
248 */
249 getSharedSigalgs(): string[];
250 /**
251 * NOTE: Works only with client TLS sockets.
252 * Useful only for debugging, for session reuse provide session option to tls.connect().
253 * @returns TLS session ticket or undefined if none was negotiated.
254 */
255 getTLSTicket(): Buffer | undefined;
256 /**
257 * Returns true if the session was reused, false otherwise.
258 */
259 isSessionReused(): boolean;
260 /**
261 * Initiate TLS renegotiation process.
262 *
263 * NOTE: Can be used to request peer's certificate after the secure connection has been established.
264 * ANOTHER NOTE: When running as the server, socket will be destroyed with an error after handshakeTimeout timeout.
265 * @param options - The options may contain the following fields: rejectUnauthorized,
266 * requestCert (See tls.createServer() for details).
267 * @param callback - callback(err) will be executed with null as err, once the renegotiation
268 * is successfully completed.
269 * @return `undefined` when socket is destroy, `false` if negotiaion can't be initiated.
270 */
271 renegotiate(options: { rejectUnauthorized?: boolean, requestCert?: boolean }, callback: (err: Error | null) => void): undefined | boolean;
272 /**
273 * Set maximum TLS fragment size (default and maximum value is: 16384, minimum is: 512).
274 * Smaller fragment size decreases buffering latency on the client: large fragments are buffered by
275 * the TLS layer until the entire fragment is received and its integrity is verified;
276 * large fragments can span multiple roundtrips, and their processing can be delayed due to packet
277 * loss or reordering. However, smaller fragments add extra TLS framing bytes and CPU overhead,
278 * which may decrease overall server throughput.
279 * @param size - TLS fragment size (default and maximum value is: 16384, minimum is: 512).
280 * @returns Returns true on success, false otherwise.
281 */
282 setMaxSendFragment(size: number): boolean;
283
284 /**
285 * Disables TLS renegotiation for this TLSSocket instance. Once called,
286 * attempts to renegotiate will trigger an 'error' event on the
287 * TLSSocket.
288 */
289 disableRenegotiation(): void;
290
291 /**
292 * When enabled, TLS packet trace information is written to `stderr`. This can be
293 * used to debug TLS connection problems.
294 *
295 * Note: The format of the output is identical to the output of `openssl s_client
296 * -trace` or `openssl s_server -trace`. While it is produced by OpenSSL's
297 * `SSL_trace()` function, the format is undocumented, can change without notice,
298 * and should not be relied on.
299 */
300 enableTrace(): void;
301
302 /**
303 * @param length number of bytes to retrieve from keying material
304 * @param label an application specific label, typically this will be a value from the
305 * [IANA Exporter Label Registry](https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#exporter-labels).
306 * @param context optionally provide a context.
307 */
308 exportKeyingMaterial(length: number, label: string, context: Buffer): Buffer;
309
310 addListener(event: string, listener: (...args: any[]) => void): this;
311 addListener(event: "OCSPResponse", listener: (response: Buffer) => void): this;
312 addListener(event: "secureConnect", listener: () => void): this;
313 addListener(event: "session", listener: (session: Buffer) => void): this;
314 addListener(event: "keylog", listener: (line: Buffer) => void): this;
315
316 emit(event: string | symbol, ...args: any[]): boolean;
317 emit(event: "OCSPResponse", response: Buffer): boolean;
318 emit(event: "secureConnect"): boolean;
319 emit(event: "session", session: Buffer): boolean;
320 emit(event: "keylog", line: Buffer): boolean;
321
322 on(event: string, listener: (...args: any[]) => void): this;
323 on(event: "OCSPResponse", listener: (response: Buffer) => void): this;
324 on(event: "secureConnect", listener: () => void): this;
325 on(event: "session", listener: (session: Buffer) => void): this;
326 on(event: "keylog", listener: (line: Buffer) => void): this;
327
328 once(event: string, listener: (...args: any[]) => void): this;
329 once(event: "OCSPResponse", listener: (response: Buffer) => void): this;
330 once(event: "secureConnect", listener: () => void): this;
331 once(event: "session", listener: (session: Buffer) => void): this;
332 once(event: "keylog", listener: (line: Buffer) => void): this;
333
334 prependListener(event: string, listener: (...args: any[]) => void): this;
335 prependListener(event: "OCSPResponse", listener: (response: Buffer) => void): this;
336 prependListener(event: "secureConnect", listener: () => void): this;
337 prependListener(event: "session", listener: (session: Buffer) => void): this;
338 prependListener(event: "keylog", listener: (line: Buffer) => void): this;
339
340 prependOnceListener(event: string, listener: (...args: any[]) => void): this;
341 prependOnceListener(event: "OCSPResponse", listener: (response: Buffer) => void): this;
342 prependOnceListener(event: "secureConnect", listener: () => void): this;
343 prependOnceListener(event: "session", listener: (session: Buffer) => void): this;
344 prependOnceListener(event: "keylog", listener: (line: Buffer) => void): this;
345 }
346
347 interface CommonConnectionOptions {
348 /**
349 * An optional TLS context object from tls.createSecureContext()
350 */
351 secureContext?: SecureContext;
352
353 /**
354 * When enabled, TLS packet trace information is written to `stderr`. This can be
355 * used to debug TLS connection problems.
356 * @default false
357 */
358 enableTrace?: boolean;
359 /**
360 * If true the server will request a certificate from clients that
361 * connect and attempt to verify that certificate. Defaults to
362 * false.
363 */
364 requestCert?: boolean;
365 /**
366 * An array of strings or a Buffer naming possible ALPN protocols.
367 * (Protocols should be ordered by their priority.)
368 */
369 ALPNProtocols?: string[] | Uint8Array[] | Uint8Array;
370 /**
371 * SNICallback(servername, cb) <Function> A function that will be
372 * called if the client supports SNI TLS extension. Two arguments
373 * will be passed when called: servername and cb. SNICallback should
374 * invoke cb(null, ctx), where ctx is a SecureContext instance.
375 * (tls.createSecureContext(...) can be used to get a proper
376 * SecureContext.) If SNICallback wasn't provided the default callback
377 * with high-level API will be used (see below).
378 */
379 SNICallback?: (servername: string, cb: (err: Error | null, ctx: SecureContext) => void) => void;
380 /**
381 * If true the server will reject any connection which is not
382 * authorized with the list of supplied CAs. This option only has an
383 * effect if requestCert is true.
384 * @default true
385 */
386 rejectUnauthorized?: boolean;
387 }
388
389 interface TlsOptions extends SecureContextOptions, CommonConnectionOptions, net.ServerOpts {
390 /**
391 * Abort the connection if the SSL/TLS handshake does not finish in the
392 * specified number of milliseconds. A 'tlsClientError' is emitted on
393 * the tls.Server object whenever a handshake times out. Default:
394 * 120000 (120 seconds).
395 */
396 handshakeTimeout?: number;
397 /**
398 * The number of seconds after which a TLS session created by the
399 * server will no longer be resumable. See Session Resumption for more
400 * information. Default: 300.
401 */
402 sessionTimeout?: number;
403 /**
404 * 48-bytes of cryptographically strong pseudo-random data.
405 */
406 ticketKeys?: Buffer;
407
408 /**
409 *
410 * @param socket
411 * @param identity identity parameter sent from the client.
412 * @return pre-shared key that must either be
413 * a buffer or `null` to stop the negotiation process. Returned PSK must be
414 * compatible with the selected cipher's digest.
415 *
416 * When negotiating TLS-PSK (pre-shared keys), this function is called
417 * with the identity provided by the client.
418 * If the return value is `null` the negotiation process will stop and an
419 * "unknown_psk_identity" alert message will be sent to the other party.
420 * If the server wishes to hide the fact that the PSK identity was not known,
421 * the callback must provide some random data as `psk` to make the connection
422 * fail with "decrypt_error" before negotiation is finished.
423 * PSK ciphers are disabled by default, and using TLS-PSK thus
424 * requires explicitly specifying a cipher suite with the `ciphers` option.
425 * More information can be found in the RFC 4279.
426 */
427
428 pskCallback?(socket: TLSSocket, identity: string): DataView | NodeJS.TypedArray | null;
429 /**
430 * hint to send to a client to help
431 * with selecting the identity during TLS-PSK negotiation. Will be ignored
432 * in TLS 1.3. Upon failing to set pskIdentityHint `tlsClientError` will be
433 * emitted with `ERR_TLS_PSK_SET_IDENTIY_HINT_FAILED` code.
434 */
435 pskIdentityHint?: string;
436 }
437
438 interface PSKCallbackNegotation {
439 psk: DataView | NodeJS.TypedArray;
440 identity: string;
441 }
442
443 interface ConnectionOptions extends SecureContextOptions, CommonConnectionOptions {
444 host?: string;
445 port?: number;
446 path?: string; // Creates unix socket connection to path. If this option is specified, `host` and `port` are ignored.
447 socket?: net.Socket; // Establish secure connection on a given socket rather than creating a new socket
448 checkServerIdentity?: typeof checkServerIdentity;
449 servername?: string; // SNI TLS Extension
450 session?: Buffer;
451 minDHSize?: number;
452 lookup?: net.LookupFunction;
453 timeout?: number;
454 /**
455 * When negotiating TLS-PSK (pre-shared keys), this function is called
456 * with optional identity `hint` provided by the server or `null`
457 * in case of TLS 1.3 where `hint` was removed.
458 * It will be necessary to provide a custom `tls.checkServerIdentity()`
459 * for the connection as the default one will try to check hostname/IP
460 * of the server against the certificate but that's not applicable for PSK
461 * because there won't be a certificate present.
462 * More information can be found in the RFC 4279.
463 *
464 * @param hint message sent from the server to help client
465 * decide which identity to use during negotiation.
466 * Always `null` if TLS 1.3 is used.
467 * @returns Return `null` to stop the negotiation process. `psk` must be
468 * compatible with the selected cipher's digest.
469 * `identity` must use UTF-8 encoding.
470 */
471 pskCallback?(hint: string | null): PSKCallbackNegotation | null;
472 }
473
474 class Server extends net.Server {
475 constructor(secureConnectionListener?: (socket: TLSSocket) => void);
476 constructor(options: TlsOptions, secureConnectionListener?: (socket: TLSSocket) => void);
477
478 /**
479 * The server.addContext() method adds a secure context that will be
480 * used if the client request's SNI name matches the supplied hostname
481 * (or wildcard).
482 */
483 addContext(hostName: string, credentials: SecureContextOptions): void;
484 /**
485 * Returns the session ticket keys.
486 */
487 getTicketKeys(): Buffer;
488 /**
489 *
490 * The server.setSecureContext() method replaces the
491 * secure context of an existing server. Existing connections to the
492 * server are not interrupted.
493 */
494 setSecureContext(details: SecureContextOptions): void;
495 /**
496 * The server.setSecureContext() method replaces the secure context of
497 * an existing server. Existing connections to the server are not
498 * interrupted.
499 */
500 setTicketKeys(keys: Buffer): void;
501
502 /**
503 * events.EventEmitter
504 * 1. tlsClientError
505 * 2. newSession
506 * 3. OCSPRequest
507 * 4. resumeSession
508 * 5. secureConnection
509 * 6. keylog
510 */
511 addListener(event: string, listener: (...args: any[]) => void): this;
512 addListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this;
513 addListener(event: "newSession", listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void): this;
514 addListener(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: (err: Error | null, resp: Buffer) => void) => void): this;
515 addListener(event: "resumeSession", listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void): this;
516 addListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this;
517 addListener(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this;
518
519 emit(event: string | symbol, ...args: any[]): boolean;
520 emit(event: "tlsClientError", err: Error, tlsSocket: TLSSocket): boolean;
521 emit(event: "newSession", sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void): boolean;
522 emit(event: "OCSPRequest", certificate: Buffer, issuer: Buffer, callback: (err: Error | null, resp: Buffer) => void): boolean;
523 emit(event: "resumeSession", sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void): boolean;
524 emit(event: "secureConnection", tlsSocket: TLSSocket): boolean;
525 emit(event: "keylog", line: Buffer, tlsSocket: TLSSocket): boolean;
526
527 on(event: string, listener: (...args: any[]) => void): this;
528 on(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this;
529 on(event: "newSession", listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void): this;
530 on(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: (err: Error | null, resp: Buffer) => void) => void): this;
531 on(event: "resumeSession", listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void): this;
532 on(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this;
533 on(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this;
534
535 once(event: string, listener: (...args: any[]) => void): this;
536 once(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this;
537 once(event: "newSession", listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void): this;
538 once(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: (err: Error | null, resp: Buffer) => void) => void): this;
539 once(event: "resumeSession", listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void): this;
540 once(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this;
541 once(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this;
542
543 prependListener(event: string, listener: (...args: any[]) => void): this;
544 prependListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this;
545 prependListener(event: "newSession", listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void): this;
546 prependListener(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: (err: Error | null, resp: Buffer) => void) => void): this;
547 prependListener(event: "resumeSession", listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void): this;
548 prependListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this;
549 prependListener(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this;
550
551 prependOnceListener(event: string, listener: (...args: any[]) => void): this;
552 prependOnceListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this;
553 prependOnceListener(event: "newSession", listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void): this;
554 prependOnceListener(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: (err: Error | null, resp: Buffer) => void) => void): this;
555 prependOnceListener(event: "resumeSession", listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void): this;
556 prependOnceListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this;
557 prependOnceListener(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this;
558 }
559
560 interface SecurePair {
561 encrypted: TLSSocket;
562 cleartext: TLSSocket;
563 }
564
565 type SecureVersion = 'TLSv1.3' | 'TLSv1.2' | 'TLSv1.1' | 'TLSv1';
566
567 interface SecureContextOptions {
568 /**
569 * Optionally override the trusted CA certificates. Default is to trust
570 * the well-known CAs curated by Mozilla. Mozilla's CAs are completely
571 * replaced when CAs are explicitly specified using this option.
572 */
573 ca?: string | Buffer | Array<string | Buffer>;
574 /**
575 * Cert chains in PEM format. One cert chain should be provided per
576 * private key. Each cert chain should consist of the PEM formatted
577 * certificate for a provided private key, followed by the PEM
578 * formatted intermediate certificates (if any), in order, and not
579 * including the root CA (the root CA must be pre-known to the peer,
580 * see ca). When providing multiple cert chains, they do not have to
581 * be in the same order as their private keys in key. If the
582 * intermediate certificates are not provided, the peer will not be
583 * able to validate the certificate, and the handshake will fail.
584 */
585 cert?: string | Buffer | Array<string | Buffer>;
586 /**
587 * Colon-separated list of supported signature algorithms. The list
588 * can contain digest algorithms (SHA256, MD5 etc.), public key
589 * algorithms (RSA-PSS, ECDSA etc.), combination of both (e.g
590 * 'RSA+SHA384') or TLS v1.3 scheme names (e.g. rsa_pss_pss_sha512).
591 */
592 sigalgs?: string;
593 /**
594 * Cipher suite specification, replacing the default. For more
595 * information, see modifying the default cipher suite. Permitted
596 * ciphers can be obtained via tls.getCiphers(). Cipher names must be
597 * uppercased in order for OpenSSL to accept them.
598 */
599 ciphers?: string;
600 /**
601 * Name of an OpenSSL engine which can provide the client certificate.
602 */
603 clientCertEngine?: string;
604 /**
605 * PEM formatted CRLs (Certificate Revocation Lists).
606 */
607 crl?: string | Buffer | Array<string | Buffer>;
608 /**
609 * Diffie Hellman parameters, required for Perfect Forward Secrecy. Use
610 * openssl dhparam to create the parameters. The key length must be
611 * greater than or equal to 1024 bits or else an error will be thrown.
612 * Although 1024 bits is permissible, use 2048 bits or larger for
613 * stronger security. If omitted or invalid, the parameters are
614 * silently discarded and DHE ciphers will not be available.
615 */
616 dhparam?: string | Buffer;
617 /**
618 * A string describing a named curve or a colon separated list of curve
619 * NIDs or names, for example P-521:P-384:P-256, to use for ECDH key
620 * agreement. Set to auto to select the curve automatically. Use
621 * crypto.getCurves() to obtain a list of available curve names. On
622 * recent releases, openssl ecparam -list_curves will also display the
623 * name and description of each available elliptic curve. Default:
624 * tls.DEFAULT_ECDH_CURVE.
625 */
626 ecdhCurve?: string;
627 /**
628 * Attempt to use the server's cipher suite preferences instead of the
629 * client's. When true, causes SSL_OP_CIPHER_SERVER_PREFERENCE to be
630 * set in secureOptions
631 */
632 honorCipherOrder?: boolean;
633 /**
634 * Private keys in PEM format. PEM allows the option of private keys
635 * being encrypted. Encrypted keys will be decrypted with
636 * options.passphrase. Multiple keys using different algorithms can be
637 * provided either as an array of unencrypted key strings or buffers,
638 * or an array of objects in the form {pem: <string|buffer>[,
639 * passphrase: <string>]}. The object form can only occur in an array.
640 * object.passphrase is optional. Encrypted keys will be decrypted with
641 * object.passphrase if provided, or options.passphrase if it is not.
642 */
643 key?: string | Buffer | Array<Buffer | KeyObject>;
644 /**
645 * Name of an OpenSSL engine to get private key from. Should be used
646 * together with privateKeyIdentifier.
647 */
648 privateKeyEngine?: string;
649 /**
650 * Identifier of a private key managed by an OpenSSL engine. Should be
651 * used together with privateKeyEngine. Should not be set together with
652 * key, because both options define a private key in different ways.
653 */
654 privateKeyIdentifier?: string;
655 /**
656 * Optionally set the maximum TLS version to allow. One
657 * of `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the
658 * `secureProtocol` option, use one or the other.
659 * **Default:** `'TLSv1.3'`, unless changed using CLI options. Using
660 * `--tls-max-v1.2` sets the default to `'TLSv1.2'`. Using `--tls-max-v1.3` sets the default to
661 * `'TLSv1.3'`. If multiple of the options are provided, the highest maximum is used.
662 */
663 maxVersion?: SecureVersion;
664 /**
665 * Optionally set the minimum TLS version to allow. One
666 * of `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the
667 * `secureProtocol` option, use one or the other. It is not recommended to use
668 * less than TLSv1.2, but it may be required for interoperability.
669 * **Default:** `'TLSv1.2'`, unless changed using CLI options. Using
670 * `--tls-v1.0` sets the default to `'TLSv1'`. Using `--tls-v1.1` sets the default to
671 * `'TLSv1.1'`. Using `--tls-min-v1.3` sets the default to
672 * 'TLSv1.3'. If multiple of the options are provided, the lowest minimum is used.
673 */
674 minVersion?: SecureVersion;
675 /**
676 * Shared passphrase used for a single private key and/or a PFX.
677 */
678 passphrase?: string;
679 /**
680 * PFX or PKCS12 encoded private key and certificate chain. pfx is an
681 * alternative to providing key and cert individually. PFX is usually
682 * encrypted, if it is, passphrase will be used to decrypt it. Multiple
683 * PFX can be provided either as an array of unencrypted PFX buffers,
684 * or an array of objects in the form {buf: <string|buffer>[,
685 * passphrase: <string>]}. The object form can only occur in an array.
686 * object.passphrase is optional. Encrypted PFX will be decrypted with
687 * object.passphrase if provided, or options.passphrase if it is not.
688 */
689 pfx?: string | Buffer | Array<string | Buffer | PxfObject>;
690 /**
691 * Optionally affect the OpenSSL protocol behavior, which is not
692 * usually necessary. This should be used carefully if at all! Value is
693 * a numeric bitmask of the SSL_OP_* options from OpenSSL Options
694 */
695 secureOptions?: number; // Value is a numeric bitmask of the `SSL_OP_*` options
696 /**
697 * Legacy mechanism to select the TLS protocol version to use, it does
698 * not support independent control of the minimum and maximum version,
699 * and does not support limiting the protocol to TLSv1.3. Use
700 * minVersion and maxVersion instead. The possible values are listed as
701 * SSL_METHODS, use the function names as strings. For example, use
702 * 'TLSv1_1_method' to force TLS version 1.1, or 'TLS_method' to allow
703 * any TLS protocol version up to TLSv1.3. It is not recommended to use
704 * TLS versions less than 1.2, but it may be required for
705 * interoperability. Default: none, see minVersion.
706 */
707 secureProtocol?: string;
708 /**
709 * Opaque identifier used by servers to ensure session state is not
710 * shared between applications. Unused by clients.
711 */
712 sessionIdContext?: string;
713 /**
714 * 48-bytes of cryptographically strong pseudo-random data.
715 * See Session Resumption for more information.
716 */
717 ticketKeys?: Buffer;
718 /**
719 * The number of seconds after which a TLS session created by the
720 * server will no longer be resumable. See Session Resumption for more
721 * information. Default: 300.
722 */
723 sessionTimeout?: number;
724 }
725
726 interface SecureContext {
727 context: any;
728 }
729
730 /*
731 * Verifies the certificate `cert` is issued to host `host`.
732 * @host The hostname to verify the certificate against
733 * @cert PeerCertificate representing the peer's certificate
734 *
735 * Returns Error object, populating it with the reason, host and cert on failure. On success, returns undefined.
736 */
737 function checkServerIdentity(host: string, cert: PeerCertificate): Error | undefined;
738 function createServer(secureConnectionListener?: (socket: TLSSocket) => void): Server;
739 function createServer(options: TlsOptions, secureConnectionListener?: (socket: TLSSocket) => void): Server;
740 function connect(options: ConnectionOptions, secureConnectListener?: () => void): TLSSocket;
741 function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () => void): TLSSocket;
742 function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () => void): TLSSocket;
743 /**
744 * @deprecated since v0.11.3 Use `tls.TLSSocket` instead.
745 */
746 function createSecurePair(credentials?: SecureContext, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair;
747 function createSecureContext(options?: SecureContextOptions): SecureContext;
748 function getCiphers(): string[];
749
750 /**
751 * The default curve name to use for ECDH key agreement in a tls server.
752 * The default value is 'auto'. See tls.createSecureContext() for further
753 * information.
754 */
755 let DEFAULT_ECDH_CURVE: string;
756 /**
757 * The default value of the maxVersion option of
758 * tls.createSecureContext(). It can be assigned any of the supported TLS
759 * protocol versions, 'TLSv1.3', 'TLSv1.2', 'TLSv1.1', or 'TLSv1'. Default:
760 * 'TLSv1.3', unless changed using CLI options. Using --tls-max-v1.2 sets
761 * the default to 'TLSv1.2'. Using --tls-max-v1.3 sets the default to
762 * 'TLSv1.3'. If multiple of the options are provided, the highest maximum
763 * is used.
764 */
765 let DEFAULT_MAX_VERSION: SecureVersion;
766 /**
767 * The default value of the minVersion option of tls.createSecureContext().
768 * It can be assigned any of the supported TLS protocol versions,
769 * 'TLSv1.3', 'TLSv1.2', 'TLSv1.1', or 'TLSv1'. Default: 'TLSv1.2', unless
770 * changed using CLI options. Using --tls-min-v1.0 sets the default to
771 * 'TLSv1'. Using --tls-min-v1.1 sets the default to 'TLSv1.1'. Using
772 * --tls-min-v1.3 sets the default to 'TLSv1.3'. If multiple of the options
773 * are provided, the lowest minimum is used.
774 */
775 let DEFAULT_MIN_VERSION: SecureVersion;
776
777 /**
778 * An immutable array of strings representing the root certificates (in PEM
779 * format) used for verifying peer certificates. This is the default value
780 * of the ca option to tls.createSecureContext().
781 */
782 const rootCertificates: ReadonlyArray<string>;
783}