-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 14736 tls ipv6 address #14772
Issue 14736 tls ipv6 address #14772
Changes from 14 commits
0d19c20
31b5eda
f0332a1
328a02f
be2b33c
5384b4a
fbe4aa0
1fa645f
9d2cb6a
897c99a
19c96e4
a9dc190
34ef11e
067600b
d5ecf17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1935,6 +1935,27 @@ void IsIPv6(const FunctionCallbackInfo<Value>& args) { | |
} | ||
} | ||
|
||
void CanonicalizeIP(const FunctionCallbackInfo<Value>& args) { | ||
v8::Isolate* isolate = args.GetIsolate(); | ||
node::Utf8Value ip(isolate, args[0]); | ||
char address_buffer[sizeof(struct in6_addr)]; | ||
char canonical_ip[INET6_ADDRSTRLEN]; | ||
|
||
if (uv_inet_pton(AF_INET, *ip, &address_buffer) == 0) { | ||
int err = uv_inet_ntop(AF_INET, address_buffer, canonical_ip, | ||
sizeof(canonical_ip)); | ||
CHECK_EQ(err, 0); | ||
|
||
args.GetReturnValue().Set(String::NewFromUtf8(isolate, canonical_ip)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a total nit: The two if clauses seem almost identical other than AF_INET(6), could this be more like: int af;
if (uv_inet_pton(AF_INET, *ip, &address_buffer) == 0)
af = AF_INET;
else if (uv_inet_pton(AF_INET6, *ip, &address_buffer) == 0)
af = AF_INET6;
else
return;
int err = uv_inet_ntop(af, address_buffer, canonical_ip,
sizeof(canonical_ip));
CHECK_EQ(err, 0);
args.GetReturnValue().Set(String::NewFromUtf8(isolate, canonical_ip)); This way it's more immediately apparent that the only difference is the |
||
} else if (uv_inet_pton(AF_INET6, *ip, &address_buffer) == 0) { | ||
int err = uv_inet_ntop(AF_INET6, address_buffer, canonical_ip, | ||
sizeof(canonical_ip)); | ||
CHECK_EQ(err, 0); | ||
|
||
args.GetReturnValue().Set(String::NewFromUtf8(isolate, canonical_ip)); | ||
} | ||
} | ||
|
||
void GetAddrInfo(const FunctionCallbackInfo<Value>& args) { | ||
Environment* env = Environment::GetCurrent(args); | ||
|
||
|
@@ -2144,6 +2165,7 @@ void Initialize(Local<Object> target, | |
env->SetMethod(target, "isIP", IsIP); | ||
env->SetMethod(target, "isIPv4", IsIPv4); | ||
env->SetMethod(target, "isIPv6", IsIPv6); | ||
env->SetMethod(target, "canonicalizeIP", CanonicalizeIP); | ||
|
||
env->SetMethod(target, "strerror", StrError); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
require('../common'); | ||
|
||
// Test conversion of IP addresses to the format returned | ||
// for addresses in Subject Alternative Name section | ||
// of a TLS certificate | ||
|
||
const assert = require('assert'); | ||
const canonicalizeIP = process.binding('cares_wrap').canonicalizeIP; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: it would be nice to use destructuring here since there was a PR recently to convert most of the code base to more consistently do that. |
||
|
||
assert.strictEqual(canonicalizeIP('127.0.0.1'), '127.0.0.1'); | ||
assert.strictEqual(canonicalizeIP('10.1.0.1'), '10.1.0.1'); | ||
assert.strictEqual(canonicalizeIP('::1'), '::1'); | ||
assert.strictEqual(canonicalizeIP('fe80:0:0:0:0:0:0:1'), 'fe80::1'); | ||
assert.strictEqual(canonicalizeIP('fe80:0:0:0:0:0:0:0'), 'fe80::'); | ||
assert.strictEqual(canonicalizeIP('fe80::0000:0010:0001'), 'fe80::10:1'); | ||
assert.strictEqual(canonicalizeIP('0001:2222:3333:4444:5555:6666:7777:0088'), | ||
'1:2222:3333:4444:5555:6666:7777:88'); | ||
|
||
assert.strictEqual(canonicalizeIP('0001:2222:3333:4444:5555:6666::'), | ||
'1:2222:3333:4444:5555:6666::'); | ||
|
||
assert.strictEqual(canonicalizeIP('a002:B12:00Ba:4444:5555:6666:0:0'), | ||
'a002:b12:ba:4444:5555:6666::'); | ||
|
||
// IPv4 address represented in IPv6 | ||
assert.strictEqual(canonicalizeIP('0:0:0:0:0:ffff:c0a8:101'), | ||
'::ffff:192.168.1.1'); | ||
|
||
assert.strictEqual(canonicalizeIP('::ffff:192.168.1.1'), | ||
'::ffff:192.168.1.1'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this needs to be here twice? (It seems to already exist on line 124.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I think that is some sort of merge conflict.