diff --git a/doc/api/tls.markdown b/doc/api/tls.markdown index 469b0d64733be2..2df457baff0416 100644 --- a/doc/api/tls.markdown +++ b/doc/api/tls.markdown @@ -661,7 +661,7 @@ publicly trusted list of CAs as given in . -## tls.createSecurePair([context][, isServer][, requestCert][, rejectUnauthorized]) +## tls.createSecurePair([context][, isServer][, requestCert][, rejectUnauthorized][, options]) Creates a new secure pair object with two streams, one of which reads/writes encrypted data, and one reads/writes cleartext data. @@ -680,6 +680,8 @@ and the cleartext one is used as a replacement for the initial encrypted stream. automatically reject clients with invalid certificates. Only applies to servers with `requestCert` enabled. + - `options`: An object with common SSL options. See [tls.TLSSocket][]. + `tls.createSecurePair()` returns a SecurePair object with `cleartext` and `encrypted` stream properties. diff --git a/lib/_tls_legacy.js b/lib/_tls_legacy.js index 3471ccb2d03b58..54ffb0a903b786 100644 --- a/lib/_tls_legacy.js +++ b/lib/_tls_legacy.js @@ -763,11 +763,13 @@ function securePairNT(self, options) { exports.createSecurePair = function(context, isServer, requestCert, - rejectUnauthorized) { + rejectUnauthorized, + options) { var pair = new SecurePair(context, isServer, requestCert, - rejectUnauthorized); + rejectUnauthorized, + options); return pair; }; diff --git a/test/fixtures/google_ssl_hello.bin b/test/fixtures/google_ssl_hello.bin new file mode 100644 index 00000000000000..5170533ab2170f Binary files /dev/null and b/test/fixtures/google_ssl_hello.bin differ diff --git a/test/parallel/test-tls-securepair-fiftharg.js b/test/parallel/test-tls-securepair-fiftharg.js new file mode 100644 index 00000000000000..b4610117889cc2 --- /dev/null +++ b/test/parallel/test-tls-securepair-fiftharg.js @@ -0,0 +1,27 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); +const tls = require('tls'); + +const sslcontext = tls.createSecureContext({ + cert: fs.readFileSync(common.fixturesDir + '/test_cert.pem'), + key: fs.readFileSync(common.fixturesDir + '/test_key.pem') +}); + +var catchedServername; +const pair = tls.createSecurePair(sslcontext, true, false, false, { + SNICallback: common.mustCall(function(servername, cb) { + catchedServername = servername; + }) +}); + +// captured traffic from browser's request to https://www.google.com +const sslHello = fs.readFileSync(common.fixturesDir + '/google_ssl_hello.bin'); + +pair.encrypted.write(sslHello); + +process.on('exit', function() { + assert.strictEqual('www.google.com', catchedServername); +});