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

Side by Side Diff: chrome/browser/net/transport_security_persister.cc

Issue 10836150: Revert 150375 - Implement SHA-256 fingerprint support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | chrome/browser/net/transport_security_persister_unittest.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) 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::HashValue; 23 using net::Fingerprint;
24 using net::HashValueTag; 24 using net::FingerprintVector;
25 using net::HashValueVector;
26 using net::TransportSecurityState; 25 using net::TransportSecurityState;
27 26
28 namespace { 27 namespace {
29 28
30 ListValue* SPKIHashesToListValue(const HashValueVector& hashes) { 29 ListValue* SPKIHashesToListValue(const FingerprintVector& hashes) {
31 ListValue* pins = new ListValue; 30 ListValue* pins = new ListValue;
32 31
33 for (HashValueVector::const_iterator i = hashes.begin(); 32 for (FingerprintVector::const_iterator i = hashes.begin();
34 i != hashes.end(); ++i) { 33 i != hashes.end(); ++i) {
35 std::string label; 34 std::string hash_str(reinterpret_cast<const char*>(i->data),
36 switch (i->tag) { 35 sizeof(i->data));
37 case net::HASH_VALUE_SHA1:
38 label = "sha1/";
39 break;
40 case net::HASH_VALUE_SHA256:
41 label = "sha256/";
42 break;
43 default:
44 LOG(WARNING) << "Skipping invalid fingerprint with unknown type "
45 << i->tag;
46 continue;
47 }
48
49 std::string hash_str(reinterpret_cast<const char*>(i->data()), i->size());
50 std::string b64; 36 std::string b64;
51 base::Base64Encode(hash_str, &b64); 37 base::Base64Encode(hash_str, &b64);
52 pins->Append(new StringValue(label + b64)); 38 pins->Append(new StringValue("sha1/" + b64));
53 } 39 }
54 40
55 return pins; 41 return pins;
56 } 42 }
57 43
58 void SPKIHashesFromListValue(const ListValue& pins, HashValueVector* hashes) { 44 void SPKIHashesFromListValue(const ListValue& pins, FingerprintVector* hashes) {
59 size_t num_pins = pins.GetSize(); 45 size_t num_pins = pins.GetSize();
60 for (size_t i = 0; i < num_pins; ++i) { 46 for (size_t i = 0; i < num_pins; ++i) {
61 std::string type_and_base64; 47 std::string type_and_base64;
62 HashValue fingerprint; 48 Fingerprint fingerprint;
63 if (pins.GetString(i, &type_and_base64) && 49 if (pins.GetString(i, &type_and_base64) &&
64 TransportSecurityState::ParsePin(type_and_base64, &fingerprint)) { 50 TransportSecurityState::ParsePin(type_and_base64, &fingerprint)) {
65 hashes->push_back(fingerprint); 51 hashes->push_back(fingerprint);
66 } 52 }
67 } 53 }
68 } 54 }
69 55
70 // This function converts the binary hashes to a base64 string which we can 56 // This function converts the binary hashes to a base64 string which we can
71 // include in a JSON file. 57 // include in a JSON file.
72 std::string HashedDomainToExternalString(const std::string& hashed) { 58 std::string HashedDomainToExternalString(const std::string& hashed) {
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
344 330
345 bool dirty = false; 331 bool dirty = false;
346 if (!LoadEntries(state, &dirty)) { 332 if (!LoadEntries(state, &dirty)) {
347 LOG(ERROR) << "Failed to deserialize state: " << state; 333 LOG(ERROR) << "Failed to deserialize state: " << state;
348 return; 334 return;
349 } 335 }
350 if (dirty) 336 if (dirty)
351 StateIsDirty(transport_security_state_); 337 StateIsDirty(transport_security_state_);
352 } 338 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/net/transport_security_persister_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698