diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-09 01:10:50 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-09 01:10:50 +0000 |
commit | c36f06436af5ef0b9b63cdba15ef95a790fdcee6 (patch) | |
tree | f45cddb8f09dfc5a9a2ce2181d0a984fc085a337 /net/base/dns_util.cc | |
parent | bc2fc85e5f1c0d24e4d597837017c1dfbfe3ab22 (diff) | |
download | chromium_src-c36f06436af5ef0b9b63cdba15ef95a790fdcee6.zip chromium_src-c36f06436af5ef0b9b63cdba15ef95a790fdcee6.tar.gz chromium_src-c36f06436af5ef0b9b63cdba15ef95a790fdcee6.tar.bz2 |
ForceTLS: hash hostnames, handle subdomains, canonicalise.
It turns out that JSON[Reader|Writer] cannot handle periods in key
names(!). Because of this, an also to avoid leaking a sort of ForceTLS
browser history in the state file, we hash the domain names.
Also, this patch tries to implement the RFCs with respect to
canonicalising the names. Since IDN processing has already occured by
the time the name reaches us, there's only so much that we can do
however.
http://codereview.chromium.org/201033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25696 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/dns_util.cc')
-rw-r--r-- | net/base/dns_util.cc | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/net/base/dns_util.cc b/net/base/dns_util.cc new file mode 100644 index 0000000..9c7e35a --- /dev/null +++ b/net/base/dns_util.cc @@ -0,0 +1,71 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/base/dns_util.h" + +namespace net { + +// Based on DJB's public domain code. +bool DNSDomainFromDot(const std::string& dotted, std::string* out) { + const char* buf = dotted.data(); + unsigned n = dotted.size(); + char label[63]; + unsigned int labellen = 0; /* <= sizeof label */ + char name[255]; + unsigned int namelen = 0; /* <= sizeof name */ + char ch; + + for (;;) { + if (!n) + break; + ch = *buf++; + --n; + if (ch == '.') { + if (labellen) { + if (namelen + labellen + 1 > sizeof name) + return false; + name[namelen++] = labellen; + memcpy(name + namelen, label, labellen); + namelen += labellen; + labellen = 0; + } + continue; + } + if (labellen >= sizeof label) + return false; + label[labellen++] = ch; + } + + if (labellen) { + if (namelen + labellen + 1 > sizeof name) + return false; + name[namelen++] = labellen; + memcpy(name + namelen, label, labellen); + namelen += labellen; + labellen = 0; + } + + if (namelen + 1 > sizeof name) + return false; + name[namelen++] = 0; + + *out = name; + return true; +} + +bool IsSTD3ASCIIValidCharacter(char c) { + if (c <= 0x2c) + return false; + if (c >= 0x7b) + return false; + if (c >= 0x2e && c <= 0x2f) + return false; + if (c >= 0x3a && c <= 0x40) + return false; + if (c >= 0x5b && c <= 0x60) + return false; + return true; +} + +} // namespace net |