Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c807287

Browse filesBrowse files
bnoordhuisMyles Borins
authored andcommitted
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 <cjihrig@gmail.com>
1 parent 271927f commit c807287
Copy full SHA for c807287

File tree

Expand file treeCollapse file tree

6 files changed

+74
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

6 files changed

+74
-0
lines changed
Open diff view settings
Collapse file

‎lib/_http_agent.js‎

Copy file name to clipboardExpand all lines: lib/_http_agent.js
+5Lines changed: 5 additions & 0 deletions
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

Collapse file

‎lib/_tls_wrap.js‎

Copy file name to clipboardExpand all lines: lib/_tls_wrap.js
+1Lines changed: 1 addition & 0 deletions
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
}
Collapse file

‎test/parallel/parallel.status‎

Copy file name to clipboardExpand all lines: test/parallel/parallel.status
+7Lines changed: 7 additions & 0 deletions
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
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-http-agent-getname.js
+6Lines changed: 6 additions & 0 deletions
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);
Collapse file
+28Lines changed: 28 additions & 0 deletions
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+
});
Collapse file
+27Lines changed: 27 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.