| 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" |
| 11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "crypto/sha2.h" | 18 #include "crypto/sha2.h" |
| 19 #include "net/base/transport_security_state.h" | 19 #include "net/base/transport_security_state.h" |
| 20 #include "net/base/x509_certificate.h" | 20 #include "net/base/x509_certificate.h" |
| 21 | 21 |
| 22 using content::BrowserThread; | 22 using content::BrowserThread; |
| 23 using net::Fingerprint; | 23 using net::HashValue; |
| 24 using net::FingerprintVector; | 24 using net::HashValueTag; |
| 25 using net::HashValueVector; |
| 25 using net::TransportSecurityState; | 26 using net::TransportSecurityState; |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 ListValue* SPKIHashesToListValue(const FingerprintVector& hashes) { | 30 ListValue* SPKIHashesToListValue(const HashValueVector& hashes) { |
| 30 ListValue* pins = new ListValue; | 31 ListValue* pins = new ListValue; |
| 31 | 32 |
| 32 for (FingerprintVector::const_iterator i = hashes.begin(); | 33 for (HashValueVector::const_iterator i = hashes.begin(); |
| 33 i != hashes.end(); ++i) { | 34 i != hashes.end(); ++i) { |
| 34 std::string hash_str(reinterpret_cast<const char*>(i->data), | 35 std::string hash_str(reinterpret_cast<const char*>(i->data()), i->size()); |
| 35 sizeof(i->data)); | |
| 36 std::string b64; | 36 std::string b64; |
| 37 base::Base64Encode(hash_str, &b64); | 37 if (base::Base64Encode(hash_str, &b64)) |
| 38 pins->Append(new StringValue("sha1/" + b64)); | 38 pins->Append(new StringValue(TransportSecurityState::HashValueLabel(*i) + |
| 39 b64)); |
| 39 } | 40 } |
| 40 | 41 |
| 41 return pins; | 42 return pins; |
| 42 } | 43 } |
| 43 | 44 |
| 44 void SPKIHashesFromListValue(const ListValue& pins, FingerprintVector* hashes) { | 45 void SPKIHashesFromListValue(const ListValue& pins, HashValueVector* hashes) { |
| 45 size_t num_pins = pins.GetSize(); | 46 size_t num_pins = pins.GetSize(); |
| 46 for (size_t i = 0; i < num_pins; ++i) { | 47 for (size_t i = 0; i < num_pins; ++i) { |
| 47 std::string type_and_base64; | 48 std::string type_and_base64; |
| 48 Fingerprint fingerprint; | 49 HashValue fingerprint; |
| 49 if (pins.GetString(i, &type_and_base64) && | 50 if (pins.GetString(i, &type_and_base64) && |
| 50 TransportSecurityState::ParsePin(type_and_base64, &fingerprint)) { | 51 TransportSecurityState::ParsePin(type_and_base64, &fingerprint)) { |
| 51 hashes->push_back(fingerprint); | 52 hashes->push_back(fingerprint); |
| 52 } | 53 } |
| 53 } | 54 } |
| 54 } | 55 } |
| 55 | 56 |
| 56 // This function converts the binary hashes to a base64 string which we can | 57 // This function converts the binary hashes to a base64 string which we can |
| 57 // include in a JSON file. | 58 // include in a JSON file. |
| 58 std::string HashedDomainToExternalString(const std::string& hashed) { | 59 std::string HashedDomainToExternalString(const std::string& hashed) { |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 330 | 331 |
| 331 bool dirty = false; | 332 bool dirty = false; |
| 332 if (!LoadEntries(state, &dirty)) { | 333 if (!LoadEntries(state, &dirty)) { |
| 333 LOG(ERROR) << "Failed to deserialize state: " << state; | 334 LOG(ERROR) << "Failed to deserialize state: " << state; |
| 334 return; | 335 return; |
| 335 } | 336 } |
| 336 if (dirty) | 337 if (dirty) |
| 337 StateIsDirty(transport_security_state_); | 338 StateIsDirty(transport_security_state_); |
| 338 } | 339 } |
| OLD | NEW |