Skip to content

Commit e8e6227

Browse files
socketpairMyles Borins
authored and
Myles Borins
committed
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 f661927 commit e8e6227

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

doc/api/tls.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ publicly trusted list of CAs as given in
661661
<http://mxr.mozilla.org/mozilla/source/security/nss/lib/ckfw/builtins/certdata.txt>.
662662

663663

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

666666
Creates a new secure pair object with two streams, one of which reads/writes
667667
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.
680680
automatically reject clients with invalid certificates. Only applies to
681681
servers with `requestCert` enabled.
682682

683+
- `options`: An object with common SSL options. See [tls.TLSSocket][].
684+
683685
`tls.createSecurePair()` returns a SecurePair object with `cleartext` and
684686
`encrypted` stream properties.
685687

lib/_tls_legacy.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,11 +763,13 @@ function securePairNT(self, options) {
763763
exports.createSecurePair = function(context,
764764
isServer,
765765
requestCert,
766-
rejectUnauthorized) {
766+
rejectUnauthorized,
767+
options) {
767768
var pair = new SecurePair(context,
768769
isServer,
769770
requestCert,
770-
rejectUnauthorized);
771+
rejectUnauthorized,
772+
options);
771773
return pair;
772774
};
773775

test/fixtures/google_ssl_hello.bin

517 Bytes
Binary file not shown.
Lines changed: 27 additions & 0 deletions
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)