OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "net/base/transport_security_state.h" | 5 #include "net/base/transport_security_state.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
38 | 38 |
39 char hashed[base::SHA256_LENGTH]; | 39 char hashed[base::SHA256_LENGTH]; |
40 base::SHA256HashString(canonicalised_host, hashed, sizeof(hashed)); | 40 base::SHA256HashString(canonicalised_host, hashed, sizeof(hashed)); |
41 | 41 |
42 // Use the original creation date if we already have this host. | 42 // Use the original creation date if we already have this host. |
43 DomainState state_copy(state); | 43 DomainState state_copy(state); |
44 DomainState existing_state; | 44 DomainState existing_state; |
45 if (IsEnabledForHost(&existing_state, host)) | 45 if (IsEnabledForHost(&existing_state, host)) |
46 state_copy.created = existing_state.created; | 46 state_copy.created = existing_state.created; |
47 | 47 |
48 // We don't store these values. | |
49 state_copy.preloaded = false; | |
50 state_copy.domain.clear(); | |
51 | |
48 enabled_hosts_[std::string(hashed, sizeof(hashed))] = state_copy; | 52 enabled_hosts_[std::string(hashed, sizeof(hashed))] = state_copy; |
49 DirtyNotify(); | 53 DirtyNotify(); |
50 } | 54 } |
51 | 55 |
56 bool TransportSecurityState::DeleteHost(const std::string& host) { | |
57 const std::string canonicalised_host = CanonicaliseHost(host); | |
58 if (canonicalised_host.empty()) | |
59 return false; | |
60 | |
61 char hashed[base::SHA256_LENGTH]; | |
62 base::SHA256HashString(canonicalised_host, hashed, sizeof(hashed)); | |
willchan no longer on Chromium
2011/02/11 21:16:27
arraysize
| |
63 | |
64 std::map<std::string, DomainState>::iterator i = enabled_hosts_.find( | |
65 std::string(hashed, sizeof(hashed))); | |
66 if (i != enabled_hosts_.end()) { | |
67 enabled_hosts_.erase(i); | |
68 DirtyNotify(); | |
69 return true; | |
70 } | |
71 return false; | |
72 } | |
73 | |
52 // IncludeNUL converts a char* to a std::string and includes the terminating | 74 // IncludeNUL converts a char* to a std::string and includes the terminating |
53 // NUL in the result. | 75 // NUL in the result. |
54 static std::string IncludeNUL(const char* in) { | 76 static std::string IncludeNUL(const char* in) { |
55 return std::string(in, strlen(in) + 1); | 77 return std::string(in, strlen(in) + 1); |
56 } | 78 } |
57 | 79 |
58 bool TransportSecurityState::IsEnabledForHost(DomainState* result, | 80 bool TransportSecurityState::IsEnabledForHost(DomainState* result, |
59 const std::string& host) { | 81 const std::string& host) { |
60 const std::string canonicalised_host = CanonicaliseHost(host); | 82 const std::string canonicalised_host = CanonicaliseHost(host); |
61 if (canonicalised_host.empty()) | 83 if (canonicalised_host.empty()) |
62 return false; | 84 return false; |
63 | 85 |
64 bool include_subdomains; | 86 bool include_subdomains; |
65 if (IsPreloadedSTS(canonicalised_host, &include_subdomains)) { | 87 if (IsPreloadedSTS(canonicalised_host, &include_subdomains)) { |
66 result->created = result->expiry = base::Time::FromTimeT(0); | 88 result->created = result->expiry = base::Time::FromTimeT(0); |
67 result->mode = DomainState::MODE_STRICT; | 89 result->mode = DomainState::MODE_STRICT; |
68 result->include_subdomains = include_subdomains; | 90 result->include_subdomains = include_subdomains; |
91 result->preloaded = true; | |
69 return true; | 92 return true; |
70 } | 93 } |
71 | 94 |
95 result->preloaded = false; | |
72 base::Time current_time(base::Time::Now()); | 96 base::Time current_time(base::Time::Now()); |
73 | 97 |
74 for (size_t i = 0; canonicalised_host[i]; i += canonicalised_host[i] + 1) { | 98 for (size_t i = 0; canonicalised_host[i]; i += canonicalised_host[i] + 1) { |
75 char hashed_domain[base::SHA256_LENGTH]; | 99 char hashed_domain[base::SHA256_LENGTH]; |
76 | 100 |
77 base::SHA256HashString(IncludeNUL(&canonicalised_host[i]), &hashed_domain, | 101 base::SHA256HashString(IncludeNUL(&canonicalised_host[i]), &hashed_domain, |
78 sizeof(hashed_domain)); | 102 sizeof(hashed_domain)); |
79 std::map<std::string, DomainState>::iterator j = | 103 std::map<std::string, DomainState>::iterator j = |
80 enabled_hosts_.find(std::string(hashed_domain, sizeof(hashed_domain))); | 104 enabled_hosts_.find(std::string(hashed_domain, sizeof(hashed_domain))); |
81 if (j == enabled_hosts_.end()) | 105 if (j == enabled_hosts_.end()) |
82 continue; | 106 continue; |
83 | 107 |
84 if (current_time > j->second.expiry) { | 108 if (current_time > j->second.expiry) { |
85 enabled_hosts_.erase(j); | 109 enabled_hosts_.erase(j); |
86 DirtyNotify(); | 110 DirtyNotify(); |
87 continue; | 111 continue; |
88 } | 112 } |
89 | 113 |
90 *result = j->second; | 114 *result = j->second; |
115 result->domain = DNSDomainToString(&canonicalised_host[i]); | |
91 | 116 |
92 // If we matched the domain exactly, it doesn't matter what the value of | 117 // If we matched the domain exactly, it doesn't matter what the value of |
93 // include_subdomains is. | 118 // include_subdomains is. |
94 if (i == 0) | 119 if (i == 0) |
95 return true; | 120 return true; |
96 | 121 |
97 return j->second.include_subdomains; | 122 return j->second.include_subdomains; |
98 } | 123 } |
99 | 124 |
100 return false; | 125 return false; |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 *include_subdomains = kPreloadedSTS[j].include_subdomains; | 476 *include_subdomains = kPreloadedSTS[j].include_subdomains; |
452 return true; | 477 return true; |
453 } | 478 } |
454 } | 479 } |
455 } | 480 } |
456 | 481 |
457 return false; | 482 return false; |
458 } | 483 } |
459 | 484 |
460 } // namespace | 485 } // namespace |
OLD | NEW |