OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/strict_transport_security_state.h" | 5 #include "net/base/strict_transport_security_state.h" |
6 | 6 |
| 7 #include "base/base64.h" |
7 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
11 #include "base/sha2.h" | 12 #include "base/sha2.h" |
12 #include "base/string_tokenizer.h" | 13 #include "base/string_tokenizer.h" |
13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
16 #include "net/base/base64.h" | |
17 #include "net/base/dns_util.h" | 17 #include "net/base/dns_util.h" |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 | 20 |
21 StrictTransportSecurityState::StrictTransportSecurityState() | 21 StrictTransportSecurityState::StrictTransportSecurityState() |
22 : delegate_(NULL) { | 22 : delegate_(NULL) { |
23 } | 23 } |
24 | 24 |
25 void StrictTransportSecurityState::DidReceiveHeader(const GURL& url, | 25 void StrictTransportSecurityState::DidReceiveHeader(const GURL& url, |
26 const std::string& value) { | 26 const std::string& value) { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 StrictTransportSecurityState::Delegate* delegate) { | 191 StrictTransportSecurityState::Delegate* delegate) { |
192 AutoLock lock(lock_); | 192 AutoLock lock(lock_); |
193 | 193 |
194 delegate_ = delegate; | 194 delegate_ = delegate; |
195 } | 195 } |
196 | 196 |
197 // This function converts the binary hashes, which we store in | 197 // This function converts the binary hashes, which we store in |
198 // |enabled_hosts_|, to a base64 string which we can include in a JSON file. | 198 // |enabled_hosts_|, to a base64 string which we can include in a JSON file. |
199 static std::wstring HashedDomainToExternalString(const std::string& hashed) { | 199 static std::wstring HashedDomainToExternalString(const std::string& hashed) { |
200 std::string out; | 200 std::string out; |
201 CHECK(Base64Encode(hashed, &out)); | 201 CHECK(base::Base64Encode(hashed, &out)); |
202 return ASCIIToWide(out); | 202 return ASCIIToWide(out); |
203 } | 203 } |
204 | 204 |
205 // This inverts |HashedDomainToExternalString|, above. It turns an external | 205 // This inverts |HashedDomainToExternalString|, above. It turns an external |
206 // string (from a JSON file) into an internal (binary) string. | 206 // string (from a JSON file) into an internal (binary) string. |
207 static std::string ExternalStringToHashedDomain(const std::wstring& external) { | 207 static std::string ExternalStringToHashedDomain(const std::wstring& external) { |
208 std::string external_ascii = WideToASCII(external); | 208 std::string external_ascii = WideToASCII(external); |
209 std::string out; | 209 std::string out; |
210 if (!Base64Decode(external_ascii, &out) || | 210 if (!base::Base64Decode(external_ascii, &out) || |
211 out.size() != base::SHA256_LENGTH) { | 211 out.size() != base::SHA256_LENGTH) { |
212 return std::string(); | 212 return std::string(); |
213 } | 213 } |
214 | 214 |
215 return out; | 215 return out; |
216 } | 216 } |
217 | 217 |
218 bool StrictTransportSecurityState::Serialise(std::string* output) { | 218 bool StrictTransportSecurityState::Serialise(std::string* output) { |
219 AutoLock lock(lock_); | 219 AutoLock lock(lock_); |
220 | 220 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 if (new_host[i + 1] == '-' || | 309 if (new_host[i + 1] == '-' || |
310 new_host[i + label_length] == '-') { | 310 new_host[i + label_length] == '-') { |
311 return std::string(); | 311 return std::string(); |
312 } | 312 } |
313 } | 313 } |
314 | 314 |
315 return new_host; | 315 return new_host; |
316 } | 316 } |
317 | 317 |
318 } // namespace | 318 } // namespace |
OLD | NEW |