UNPKG

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