Skip to content

Commit 2296a4f

Browse files
socketpairrvagg
authored andcommitted
tls: add options argument to createSecurePair
Helps in implementation of #6204, where some options passed to `createSecurePair()` are ignored before this patch. These options are very helpful if someone wants to pass `options.servername` or `options.SNICallback` to securepair. PR-URL: #2441 Reviewed-By: Fedor Indutny <[email protected]>
1 parent 5e0759f commit 2296a4f

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

doc/api/tls.markdown

+3-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ publicly trusted list of CAs as given in
511511
<http://mxr.mozilla.org/mozilla/source/security/nss/lib/ckfw/builtins/certdata.txt>.
512512

513513

514-
## tls.createSecurePair([context][, isServer][, requestCert][, rejectUnauthorized])
514+
## tls.createSecurePair([context][, isServer][, requestCert][, rejectUnauthorized][, options])
515515

516516
Creates a new secure pair object with two streams, one of which reads/writes
517517
encrypted data, and one reads/writes cleartext data.
@@ -530,6 +530,8 @@ and the cleartext one is used as a replacement for the initial encrypted stream.
530530
automatically reject clients with invalid certificates. Only applies to
531531
servers with `requestCert` enabled.
532532

533+
- `options`: An object with common SSL options. See [tls.TLSSocket][].
534+
533535
`tls.createSecurePair()` returns a SecurePair object with `cleartext` and
534536
`encrypted` stream properties.
535537

lib/_tls_legacy.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -761,11 +761,13 @@ function securePairNT(self, options) {
761761
exports.createSecurePair = function(context,
762762
isServer,
763763
requestCert,
764-
rejectUnauthorized) {
764+
rejectUnauthorized,
765+
options) {
765766
var pair = new SecurePair(context,
766767
isServer,
767768
requestCert,
768-
rejectUnauthorized);
769+
rejectUnauthorized,
770+
options);
769771
return pair;
770772
};
771773

test/fixtures/google_ssl_hello.bin

517 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const fs = require('fs');
6+
const tls = require('tls');
7+
8+
const sslcontext = tls.createSecureContext({
9+
cert: fs.readFileSync(common.fixturesDir + '/test_cert.pem'),
10+
key: fs.readFileSync(common.fixturesDir + '/test_key.pem')
11+
});
12+
13+
var catchedServername;
14+
const pair = tls.createSecurePair(sslcontext, true, false, false, {
15+
SNICallback: common.mustCall(function(servername, cb) {
16+
catchedServername = servername;
17+
})
18+
});
19+
20+
// captured traffic from browser's request to https://www.google.com
21+
const sslHello = fs.readFileSync(common.fixturesDir + '/google_ssl_hello.bin');
22+
23+
pair.encrypted.write(sslHello);
24+
25+
process.on('exit', function() {
26+
assert.strictEqual('www.google.com', catchedServername);
27+
});

0 commit comments

Comments
 (0)