OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/net/transport_security_persister.h" | 5 #include "chrome/browser/net/transport_security_persister.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 using content::BrowserThread; | 22 using content::BrowserThread; |
23 using net::HashValue; | 23 using net::HashValue; |
24 using net::HashValueTag; | 24 using net::HashValueTag; |
25 using net::HashValueVector; | 25 using net::HashValueVector; |
26 using net::TransportSecurityState; | 26 using net::TransportSecurityState; |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 ListValue* SPKIHashesToListValue(const HashValueVector& hashes) { | 30 ListValue* SPKIHashesToListValue(const HashValueVector& hashes) { |
31 ListValue* pins = new ListValue; | 31 ListValue* pins = new ListValue; |
32 | 32 for (size_t i = 0; i != hashes.size(); i++) |
33 for (HashValueVector::const_iterator i = hashes.begin(); | 33 pins->Append(new StringValue(hashes[i].WriteBase64String())); |
34 i != hashes.end(); ++i) { | |
35 std::string hash_str(reinterpret_cast<const char*>(i->data()), i->size()); | |
36 std::string b64; | |
37 if (base::Base64Encode(hash_str, &b64)) | |
38 pins->Append(new StringValue(TransportSecurityState::HashValueLabel(*i) + | |
39 b64)); | |
40 } | |
41 | |
42 return pins; | 34 return pins; |
43 } | 35 } |
44 | 36 |
45 void SPKIHashesFromListValue(const ListValue& pins, HashValueVector* hashes) { | 37 void SPKIHashesFromListValue(const ListValue& pins, HashValueVector* hashes) { |
46 size_t num_pins = pins.GetSize(); | 38 size_t num_pins = pins.GetSize(); |
47 for (size_t i = 0; i < num_pins; ++i) { | 39 for (size_t i = 0; i < num_pins; ++i) { |
48 std::string type_and_base64; | 40 std::string type_and_base64; |
49 HashValue fingerprint; | 41 HashValue fingerprint; |
50 if (pins.GetString(i, &type_and_base64) && | 42 if (pins.GetString(i, &type_and_base64) && |
51 TransportSecurityState::ParsePin(type_and_base64, &fingerprint)) { | 43 fingerprint.ParseBase64String(type_and_base64)) { |
52 hashes->push_back(fingerprint); | 44 hashes->push_back(fingerprint); |
53 } | 45 } |
54 } | 46 } |
55 } | 47 } |
56 | 48 |
57 // This function converts the binary hashes to a base64 string which we can | 49 // This function converts the binary hashes to a base64 string which we can |
58 // include in a JSON file. | 50 // include in a JSON file. |
59 std::string HashedDomainToExternalString(const std::string& hashed) { | 51 std::string HashedDomainToExternalString(const std::string& hashed) { |
60 std::string out; | 52 std::string out; |
61 base::Base64Encode(hashed, &out); | 53 base::Base64Encode(hashed, &out); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
331 | 323 |
332 bool dirty = false; | 324 bool dirty = false; |
333 if (!LoadEntries(state, &dirty)) { | 325 if (!LoadEntries(state, &dirty)) { |
334 LOG(ERROR) << "Failed to deserialize state: " << state; | 326 LOG(ERROR) << "Failed to deserialize state: " << state; |
335 return; | 327 return; |
336 } | 328 } |
337 if (dirty) | 329 if (dirty) |
338 StateIsDirty(transport_security_state_); | 330 StateIsDirty(transport_security_state_); |
339 } | 331 } |
OLD | NEW |