Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2017-12-23 07:55:37 +0300
committerAnna Henningsen <anna@addaleax.net>2018-01-14 16:49:41 +0300
commit9301b8a9c69d112b98c7d60e074c845d80342b4e (patch)
treefa9f8d98fc7eca29eb6283fa303f8e71976fbb03 /lib/tls.js
parent02fef8ad5a6c0e5c1ce0d4b46aa3a762935c981c (diff)
tls: make deprecated tls.createSecurePair() use public API
Make the deprecated `tls.createSecurePair()` method use other public APIs only (`TLSSocket` in particular). Since `tls.createSecurePair()` has been runtime-deprecated only since Node 8, it probably isn’t quite time to remove it yet, but this patch removes almost all of the code complexity that is retained by it. The API, as it is documented, is retained. However, it is very likely that some users have come to rely on parts of undocumented API of the `SecurePair` class, especially since some of the existing tests checked for those. Therefore, this should definitely be considered a breaking change. PR-URL: https://github.com/nodejs/node/pull/17882 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Diffstat (limited to 'lib/tls.js')
-rw-r--r--lib/tls.js37
1 files changed, 35 insertions, 2 deletions
diff --git a/lib/tls.js b/lib/tls.js
index 554ddb77b81..96b6ec8d340 100644
--- a/lib/tls.js
+++ b/lib/tls.js
@@ -31,6 +31,8 @@ const net = require('net');
const url = require('url');
const binding = process.binding('crypto');
const Buffer = require('buffer').Buffer;
+const EventEmitter = require('events');
+const DuplexPair = require('internal/streams/duplexpair');
const canonicalizeIP = process.binding('cares_wrap').canonicalizeIP;
// Allow {CLIENT_RENEG_LIMIT} client-initiated session renegotiations
@@ -230,6 +232,33 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
}
};
+
+class SecurePair extends EventEmitter {
+ constructor(secureContext = exports.createSecureContext(),
+ isServer = false,
+ requestCert = !isServer,
+ rejectUnauthorized = false,
+ options = {}) {
+ super();
+ const { socket1, socket2 } = new DuplexPair();
+
+ this.server = options.server;
+ this.credentials = secureContext;
+
+ this.encrypted = socket1;
+ this.cleartext = new exports.TLSSocket(socket2, Object.assign({
+ secureContext, isServer, requestCert, rejectUnauthorized
+ }, options));
+ this.cleartext.once('secure', () => this.emit('secure'));
+ }
+
+ destroy() {
+ this.cleartext.destroy();
+ this.encrypted.destroy();
+ }
+}
+
+
exports.parseCertString = internalUtil.deprecate(
internalTLS.parseCertString,
'tls.parseCertString() is deprecated. ' +
@@ -243,5 +272,9 @@ exports.Server = require('_tls_wrap').Server;
exports.createServer = require('_tls_wrap').createServer;
exports.connect = require('_tls_wrap').connect;
-// Deprecated: DEP0064
-exports.createSecurePair = require('_tls_legacy').createSecurePair;
+exports.createSecurePair = internalUtil.deprecate(
+ function createSecurePair(...args) {
+ return new SecurePair(...args);
+ },
+ 'tls.createSecurePair() is deprecated. Please use ' +
+ 'tls.TLSSocket instead.', 'DEP0064');