Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMattias Holmlund <mattias.holmlund@netinsight.net>2017-08-10 16:11:19 +0300
committerAnatoli Papirovski <apapirovski@mac.com>2017-11-03 04:05:20 +0300
commitb6df87e1d482f18202586273200fd7a8e9bc2fcd (patch)
tree8603a7c67ac8b61dddce193bb7e7e1a452975b00 /src/cares_wrap.cc
parent14181a3368b38978e3178d66a549349cc720f707 (diff)
http, tls: better support for IPv6 addresses
- Properly handle IPv6 in Host header when setting servername. - When comparing IP addresses against addresses in the subjectAltName field of a certificate, format the address correctly before doing the string comparison. PR-URL: https://github.com/nodejs/node/pull/14772 Fixes: https://github.com/nodejs/node/issues/14736 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/cares_wrap.cc')
-rw-r--r--src/cares_wrap.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc
index 2cd494fca81..7c09b01d80c 100644
--- a/src/cares_wrap.cc
+++ b/src/cares_wrap.cc
@@ -1945,6 +1945,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];
+
+ 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));
+}
+
void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
@@ -2165,6 +2186,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);