Skip to content

Commit c807287

Browse files
bnoordhuisMyles Borins
authored and
Myles Borins
committedJul 12, 2016
tls,https: respect address family when connecting
Respect the `{ family: 6 }` address family property when connecting to a remote peer over TLS. Fixes: #4139 Fixes: #6440 PR-URL: #6654 Reviewed-By: Colin Ihrig <[email protected]>
1 parent 271927f commit c807287

6 files changed

+74
-0
lines changed
 

‎lib/_http_agent.js

+5
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ Agent.prototype.getName = function(options) {
102102
if (options.localAddress)
103103
name += options.localAddress;
104104

105+
// Pacify parallel/test-http-agent-getname by only appending
106+
// the ':' when options.family is set.
107+
if (options.family === 4 || options.family === 6)
108+
name += ':' + options.family;
109+
105110
return name;
106111
};
107112

‎lib/_tls_wrap.js

+1
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,7 @@ exports.connect = function(/* [port, host], options, cb */) {
994994
connect_opt = {
995995
port: options.port,
996996
host: options.host,
997+
family: options.family,
997998
localAddress: options.localAddress
998999
};
9991000
}

‎test/parallel/parallel.status

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ test-tick-processor : PASS,FLAKY
1212
[$system==linux]
1313
test-tick-processor : PASS,FLAKY
1414

15+
# Flaky until https://github.com/nodejs/build/issues/415 is resolved.
16+
# On some of the buildbots, AAAA queries for localhost don't resolve
17+
# to an address and neither do any of the alternatives from the
18+
# localIPv6Hosts list from test/common.js.
19+
test-https-connect-address-family : PASS,FLAKY
20+
test-tls-connect-address-family : PASS,FLAKY
21+
1522
[$system==macos]
1623

1724
[$system==solaris] # Also applies to SmartOS

‎test/parallel/test-http-agent-getname.js

+6
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@ assert.equal(
3030
}),
3131
'0.0.0.0:80:192.168.1.1'
3232
);
33+
34+
for (const family of [0, null, undefined, 'bogus'])
35+
assert.strictEqual(agent.getName({ family }), 'localhost::');
36+
37+
for (const family of [4, 6])
38+
assert.strictEqual(agent.getName({ family }), 'localhost:::' + family);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const https = require('https');
5+
6+
if (!common.hasIPv6) {
7+
common.skip('no IPv6 support');
8+
return;
9+
}
10+
11+
const ciphers = 'AECDH-NULL-SHA';
12+
https.createServer({ ciphers }, function(req, res) {
13+
this.close();
14+
res.end();
15+
}).listen(common.PORT, '::1', function() {
16+
const options = {
17+
host: 'localhost',
18+
port: common.PORT,
19+
family: 6,
20+
ciphers: ciphers,
21+
rejectUnauthorized: false,
22+
};
23+
// Will fail with ECONNREFUSED if the address family is not honored.
24+
https.get(options, common.mustCall(function() {
25+
assert.strictEqual('::1', this.socket.remoteAddress);
26+
this.destroy();
27+
}));
28+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const tls = require('tls');
5+
6+
if (!common.hasIPv6) {
7+
common.skip('no IPv6 support');
8+
return;
9+
}
10+
11+
const ciphers = 'AECDH-NULL-SHA';
12+
tls.createServer({ ciphers }, function() {
13+
this.close();
14+
}).listen(common.PORT, '::1', function() {
15+
const options = {
16+
host: 'localhost',
17+
port: common.PORT,
18+
family: 6,
19+
ciphers: ciphers,
20+
rejectUnauthorized: false,
21+
};
22+
// Will fail with ECONNREFUSED if the address family is not honored.
23+
tls.connect(options).once('secureConnect', common.mustCall(function() {
24+
assert.strictEqual('::1', this.remoteAddress);
25+
this.destroy();
26+
}));
27+
});

0 commit comments

Comments
 (0)
Please sign in to comment.