[email protected] | d0d49dd8 | 2012-01-26 00:03:59 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | c36f064 | 2009-09-09 01:10:50 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef NET_BASE_DNS_UTIL_H_ |
| 6 | #define NET_BASE_DNS_UTIL_H_ |
[email protected] | c36f064 | 2009-09-09 01:10:50 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
[email protected] | b3ccac8 | 2010-08-04 15:54:40 | [diff] [blame] | 10 | #include "base/basictypes.h" |
[email protected] | d10740b | 2011-05-24 19:26:31 | [diff] [blame] | 11 | #include "base/string_piece.h" |
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 12 | #include "net/base/net_export.h" |
[email protected] | b3ccac8 | 2010-08-04 15:54:40 | [diff] [blame] | 13 | |
[email protected] | c36f064 | 2009-09-09 01:10:50 | [diff] [blame] | 14 | namespace net { |
| 15 | |
| 16 | // DNSDomainFromDot - convert a domain string to DNS format. From DJB's |
| 17 | // public domain DNS library. |
| 18 | // |
| 19 | // dotted: a string in dotted form: "www.google.com" |
| 20 | // out: a result in DNS form: "\x03www\x06google\x03com\x00" |
[email protected] | 7556ea2 | 2011-12-08 19:29:15 | [diff] [blame] | 21 | NET_EXPORT_PRIVATE bool DNSDomainFromDot(const base::StringPiece& dotted, |
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 22 | std::string* out); |
[email protected] | c36f064 | 2009-09-09 01:10:50 | [diff] [blame] | 23 | |
[email protected] | d0d49dd8 | 2012-01-26 00:03:59 | [diff] [blame] | 24 | // DNSDomainToString converts a domain in DNS format to a dotted string. |
| 25 | // Excludes the dot at the end. |
[email protected] | 7556ea2 | 2011-12-08 19:29:15 | [diff] [blame] | 26 | NET_EXPORT_PRIVATE std::string DNSDomainToString( |
| 27 | const base::StringPiece& domain); |
[email protected] | f060be3 | 2011-02-17 17:20:28 | [diff] [blame] | 28 | |
[email protected] | c36f064 | 2009-09-09 01:10:50 | [diff] [blame] | 29 | // Returns true iff the given character is in the set of valid DNS label |
| 30 | // characters as given in RFC 3490, 4.1, 3(a) |
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 31 | NET_EXPORT_PRIVATE bool IsSTD3ASCIIValidCharacter(char c); |
[email protected] | c36f064 | 2009-09-09 01:10:50 | [diff] [blame] | 32 | |
[email protected] | 13c340e1 | 2010-03-08 19:29:41 | [diff] [blame] | 33 | // Returns the hostname by trimming the ending dot, if one exists. |
[email protected] | 7556ea2 | 2011-12-08 19:29:15 | [diff] [blame] | 34 | NET_EXPORT std::string TrimEndingDot(const base::StringPiece& host); |
| 35 | |
| 36 | // TODO(szym): remove all definitions below once DnsRRResolver migrates to |
| 37 | // DnsClient |
[email protected] | 13c340e1 | 2010-03-08 19:29:41 | [diff] [blame] | 38 | |
[email protected] | b581064 | 2011-06-03 21:26:49 | [diff] [blame] | 39 | // DNS class types. |
| 40 | static const uint16 kClassIN = 1; |
| 41 | |
[email protected] | b3ccac8 | 2010-08-04 15:54:40 | [diff] [blame] | 42 | // DNS resource record types. See |
| 43 | // http://www.iana.org/assignments/dns-parameters |
[email protected] | c284be3 | 2012-02-23 15:51:34 | [diff] [blame] | 44 | // WARNING: if you're adding any new values here you may need to add them to |
| 45 | // dnsrr_resolver.cc:DnsRRIsParsedByWindows. |
| 46 | static const uint16 kDNS_A = 1; |
[email protected] | b40f05a | 2010-09-09 20:13:23 | [diff] [blame] | 47 | static const uint16 kDNS_CNAME = 5; |
[email protected] | b3ccac8 | 2010-08-04 15:54:40 | [diff] [blame] | 48 | static const uint16 kDNS_TXT = 16; |
[email protected] | c284be3 | 2012-02-23 15:51:34 | [diff] [blame] | 49 | static const uint16 kDNS_AAAA = 28; |
[email protected] | b3ccac8 | 2010-08-04 15:54:40 | [diff] [blame] | 50 | static const uint16 kDNS_CERT = 37; |
[email protected] | b2471359 | 2010-08-11 19:50:02 | [diff] [blame] | 51 | static const uint16 kDNS_DS = 43; |
| 52 | static const uint16 kDNS_RRSIG = 46; |
| 53 | static const uint16 kDNS_DNSKEY = 48; |
[email protected] | c284be3 | 2012-02-23 15:51:34 | [diff] [blame] | 54 | static const uint16 kDNS_ANY = 0xff; |
[email protected] | bad796d | 2011-06-02 21:06:54 | [diff] [blame] | 55 | static const uint16 kDNS_CAA = 257; |
[email protected] | c284be3 | 2012-02-23 15:51:34 | [diff] [blame] | 56 | static const uint16 kDNS_TESTING = 0xfffe; // in private use area. |
[email protected] | b3ccac8 | 2010-08-04 15:54:40 | [diff] [blame] | 57 | |
[email protected] | b2471359 | 2010-08-11 19:50:02 | [diff] [blame] | 58 | // http://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml |
| 59 | static const uint8 kDNSSEC_RSA_SHA1 = 5; |
| 60 | static const uint8 kDNSSEC_RSA_SHA1_NSEC3 = 7; |
| 61 | static const uint8 kDNSSEC_RSA_SHA256 = 8; |
[email protected] | 659ba74 | 2012-04-17 19:05:15 | [diff] [blame] | 62 | static const uint8 kDNSSEC_RSA_SHA512 = 10; |
[email protected] | b2471359 | 2010-08-11 19:50:02 | [diff] [blame] | 63 | |
| 64 | // RFC 4509 |
| 65 | static const uint8 kDNSSEC_SHA1 = 1; |
| 66 | static const uint8 kDNSSEC_SHA256 = 2; |
| 67 | |
[email protected] | c284be3 | 2012-02-23 15:51:34 | [diff] [blame] | 68 | // A Buffer is used for walking over a DNS response packet. |
| 69 | class DnsResponseBuffer { |
| 70 | public: |
| 71 | DnsResponseBuffer(const uint8* p, unsigned len) |
| 72 | : p_(p), |
| 73 | packet_(p), |
| 74 | len_(len), |
| 75 | packet_len_(len) { |
| 76 | } |
| 77 | |
| 78 | bool U8(uint8* v); |
| 79 | bool U16(uint16* v); |
| 80 | bool U32(uint32* v); |
| 81 | bool Skip(unsigned n); |
| 82 | |
| 83 | bool Block(base::StringPiece* out, unsigned len); |
| 84 | |
| 85 | // DNSName parses a (possibly compressed) DNS name from the packet. If |name| |
| 86 | // is not NULL, then the name is written into it. See RFC 1035 section 4.1.4. |
| 87 | bool DNSName(std::string* name); |
| 88 | |
| 89 | private: |
| 90 | const uint8* p_; |
| 91 | const uint8* const packet_; |
| 92 | unsigned len_; |
| 93 | const unsigned packet_len_; |
| 94 | |
| 95 | DISALLOW_COPY_AND_ASSIGN(DnsResponseBuffer); |
| 96 | }; |
| 97 | |
| 98 | |
[email protected] | c36f064 | 2009-09-09 01:10:50 | [diff] [blame] | 99 | } // namespace net |
| 100 | |
| 101 | #endif // NET_BASE_DNS_UTIL_H_ |