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

Side by Side Diff: net/base/ssl_false_start_blacklist.h

Issue 7518035: net: handle trailing dots in LastTwoLabels. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/base/ssl_false_start_blacklist.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_BASE_SSL_FALSE_START_BLACKLIST_H_ 5 #ifndef NET_BASE_SSL_FALSE_START_BLACKLIST_H_
6 #define NET_BASE_SSL_FALSE_START_BLACKLIST_H_ 6 #define NET_BASE_SSL_FALSE_START_BLACKLIST_H_
7 7
8 #include <string>
9
8 #include "base/basictypes.h" 10 #include "base/basictypes.h"
9 #include "net/base/net_api.h" 11 #include "net/base/net_api.h"
10 12
11 namespace net { 13 namespace net {
12 14
13 // SSLFalseStartBlacklist is a set of domains which we believe to be intolerant 15 // SSLFalseStartBlacklist is a set of domains which we believe to be intolerant
14 // to TLS False Start. Because this set is several hundred long, it's 16 // to TLS False Start. Because this set is several hundred long, it's
15 // precompiled by the code in ssl_false_start_blacklist_process.cc into a hash 17 // precompiled by the code in ssl_false_start_blacklist_process.cc into a hash
16 // table for fast lookups. 18 // table for fast lookups.
17 class SSLFalseStartBlacklist { 19 class SSLFalseStartBlacklist {
(...skipping 10 matching lines...) Expand all
28 // generates. 30 // generates.
29 const unsigned char* in = reinterpret_cast<const unsigned char*>(str); 31 const unsigned char* in = reinterpret_cast<const unsigned char*>(str);
30 unsigned hash = 5381; 32 unsigned hash = 5381;
31 unsigned char c; 33 unsigned char c;
32 34
33 while ((c = *in++)) 35 while ((c = *in++))
34 hash = ((hash << 5) + hash) ^ c; 36 hash = ((hash << 5) + hash) ^ c;
35 return hash; 37 return hash;
36 } 38 }
37 39
38 // LastTwoLabels returns a pointer within |host| to the last two labels of 40 // LastTwoLabels returns the last two labels of |host|. For example, if
39 // |host|. For example, if |host| is "a.b.c.d" then LastTwoLabels will return 41 // |host| is "a.b.c.d" then LastTwoLabels will return "c.d".
40 // "c.d".
41 // host: a DNS name in dotted form. 42 // host: a DNS name in dotted form.
42 // returns: NULL on error, otherwise a pointer inside |host|. 43 // returns: empty string on error, otherwise the last two labels.
43 static const char* LastTwoLabels(const char* host) { 44 static std::string LastTwoLabels(const char* host) {
44 // See comment in |Hash| for why this function is inline. 45 // See comment in |Hash| for why this function is inline.
45 const size_t len = strlen(host); 46 const size_t len = strlen(host);
46 if (len == 0) 47 if (len == 0)
47 return NULL; 48 return std::string();
48 49
49 unsigned dots_found = 0; 50 unsigned dots_found = 0;
50 size_t i; 51 size_t i;
52
53 // Remove trailing dots.
51 for (i = len - 1; i < len; i--) { 54 for (i = len - 1; i < len; i--) {
55 if (host[i] != '.')
56 break;
57 }
58 const size_t end = i;
59
60 for (; i < len; i--) {
52 if (host[i] == '.') { 61 if (host[i] == '.') {
53 dots_found++; 62 dots_found++;
54 if (dots_found == 2) { 63 if (dots_found == 2) {
55 i++; 64 i++;
56 break; 65 break;
57 } 66 }
58 } 67 }
59 } 68 }
60
61 if (i > len) 69 if (i > len)
62 i = 0; 70 i = 0;
63 71
64 if (dots_found == 0) 72 if (dots_found == 0) {
65 return NULL; // no names with less than two labels are in the blacklist. 73 // no names with less than two labels are in the blacklist.
66 if (dots_found == 1) { 74 return std::string();
75 } else if (dots_found == 1) {
67 if (host[0] == '.') 76 if (host[0] == '.')
68 return NULL; // ditto 77 return std::string(); // ditto
69 } 78 }
70 79
71 return &host[i]; 80 return std::string(&host[i], end - i + 1);
72 } 81 }
73 82
74 // This is the number of buckets in the blacklist hash table. (Must be a 83 // This is the number of buckets in the blacklist hash table. (Must be a
75 // power of two). 84 // power of two).
76 static const unsigned kBuckets = 128; 85 static const unsigned kBuckets = 128;
77 86
78 private: 87 private:
79 // The following two members are defined in 88 // The following two members are defined in
80 // ssl_false_start_blacklist_data.cc, which is generated by 89 // ssl_false_start_blacklist_data.cc, which is generated by
81 // ssl_false_start_blacklist_process.cc 90 // ssl_false_start_blacklist_process.cc
82 91
83 // kHashTable contains an offset into |kHashData| for each bucket. The 92 // kHashTable contains an offset into |kHashData| for each bucket. The
84 // additional element at the end contains the length of |kHashData|. 93 // additional element at the end contains the length of |kHashData|.
85 static const uint32 kHashTable[kBuckets + 1]; 94 static const uint32 kHashTable[kBuckets + 1];
86 // kHashData contains the contents of the hash table. |kHashTable| indexes 95 // kHashData contains the contents of the hash table. |kHashTable| indexes
87 // into this array. Each bucket consists of zero or more, 8-bit length 96 // into this array. Each bucket consists of zero or more, 8-bit length
88 // prefixed strings. Each string is a DNS name in dotted form. For a given 97 // prefixed strings. Each string is a DNS name in dotted form. For a given
89 // string x, x and *.x are considered to be in the blacklist. In order to 98 // string x, x and *.x are considered to be in the blacklist. In order to
90 // assign a string to a hash bucket, the last two labels (not including the 99 // assign a string to a hash bucket, the last two labels (not including the
91 // root label) are hashed. Thus, the bucket for "www.example.com" is 100 // root label) are hashed. Thus, the bucket for "www.example.com" is
92 // Hash("example.com"). No names that are less than two labels long are 101 // Hash("example.com"). No names that are less than two labels long are
93 // included in the blacklist. 102 // included in the blacklist.
94 static const char kHashData[]; 103 static const char kHashData[];
95 }; 104 };
96 105
97 } // namespace net 106 } // namespace net
98 107
99 #endif // NET_BASE_SSL_FALSE_START_BLACKLIST_H_ 108 #endif // NET_BASE_SSL_FALSE_START_BLACKLIST_H_
OLDNEW
« no previous file with comments | « no previous file | net/base/ssl_false_start_blacklist.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698