Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(584)

Unified Diff: net/base/net_util.cc

Issue 21572002: Add UMA entry for intranet SSL warnings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Needed to move the unit tests as well Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/base/net_util.cc
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 3ca0d99a89b4c33634a987791b446bb01d744fc0..47718a1f48066e3ac2be0eeb2c1517f747aa52dd 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -64,6 +64,7 @@
#include "net/base/escape.h"
#include "net/base/mime_util.h"
#include "net/base/net_module.h"
+#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#if defined(OS_WIN)
#include "net/base/winsock_init.h"
#endif
@@ -1390,6 +1391,41 @@ std::string GetHostAndOptionalPort(const GURL& url) {
return url.host();
}
+// static
+bool IsHostnameNonUnique(const std::string& hostname) {
+ // CanonicalizeHost requires surrounding brackets to parse an IPv6 address.
+ const std::string host_or_ip = hostname.find(':') != std::string::npos ?
+ "[" + hostname + "]" : hostname;
+ url_canon::CanonHostInfo host_info;
+ std::string canonical_name = CanonicalizeHost(host_or_ip, &host_info);
+
+ // If canonicalization fails, then the input is truly malformed. However,
+ // to avoid mis-reporting bad inputs as "non-unique", treat them as unique.
+ if (canonical_name.empty())
+ return false;
+
+ // If |hostname| is an IP address, presume it's unique.
+ // TODO(rsleevi): In the future, this should also reject IP addresses in
+ // IANA-reserved ranges, since those are also non-unique among publicly
+ // trusted CAs.
Ryan Sleevi 2013/08/01 21:37:55 nit: comment update re: "trusted CAs"
felt 2013/08/01 22:00:25 Not entirely sure what you want here -- I removed
+ if (host_info.IsIPAddress())
+ return false;
+
+ // Check for a registry controlled portion of |hostname|, ignoring private
+ // registries, as they already chain to ICANN-administered registries,
+ // and explicitly ignoring unknown registries.
+ //
+ // Note: This means that as new gTLDs are introduced on the Internet, they
+ // will be treated as non-unique until the registry controlled domain list
+ // is updated. However, because gTLDs are expected to provide significant
+ // advance notice to deprecate older versions of this code, this an
+ // acceptable tradeoff.
+ return 0 == registry_controlled_domains::GetRegistryLength(
+ canonical_name,
+ registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES,
+ registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
+}
+
// Extracts the address and port portions of a sockaddr.
bool GetIPAddressFromSockAddr(const struct sockaddr* sock_addr,
socklen_t sock_addr_len,

Powered by Google App Engine
This is Rietveld 408576698