OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // TransportSecurityState maintains an in memory database containing the | 5 // TransportSecurityState maintains an in memory database containing the |
6 // list of hosts that currently have transport security enabled. This | 6 // list of hosts that currently have transport security enabled. This |
7 // singleton object deals with writing that data out to disk as needed and | 7 // singleton object deals with writing that data out to disk as needed and |
8 // loading it at startup. | 8 // loading it at startup. |
9 | 9 |
10 // At startup we need to load the transport security state from the | 10 // At startup we need to load the transport security state from the |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 // Called by the TransportSecurityState when it changes its state. | 55 // Called by the TransportSecurityState when it changes its state. |
56 virtual void StateIsDirty(net::TransportSecurityState*) OVERRIDE; | 56 virtual void StateIsDirty(net::TransportSecurityState*) OVERRIDE; |
57 | 57 |
58 // ImportantFileWriter::DataSerializer: | 58 // ImportantFileWriter::DataSerializer: |
59 virtual bool SerializeData(std::string* data) OVERRIDE; | 59 virtual bool SerializeData(std::string* data) OVERRIDE; |
60 | 60 |
61 private: | 61 private: |
62 class Loader; | 62 class Loader; |
63 | 63 |
| 64 // Serializes transport security |state| into |*output|. Returns true if |
| 65 // all DomainStates were serialized correctly. |
| 66 // |
| 67 // The serialization format is JSON; the JSON represents a dictionary of |
| 68 // host:DomainState pairs (host is a string). The DomainState is |
| 69 // represented as a dictionary containing the following keys and value |
| 70 // types (not all keys will always be present): |
| 71 // |
| 72 // "include_subdomains": true|false |
| 73 // "created": double |
| 74 // "expiry": double |
| 75 // "dynamic_spki_hashes_expiry": double |
| 76 // "mode": "always"|"never" |
| 77 // legacy value synonyms "strict"|"pinning-only" |
| 78 // legacy value "spdy-only" is unused and ignored |
| 79 // "static_spki_hashes": list of strings |
| 80 // legacy key synonym "preloaded_spki_hashes" |
| 81 // "bad_static_spki_hashes": list of strings |
| 82 // legacy key synonym "bad_preloaded_spki_hashes" |
| 83 // "dynamic_spki_hashes": list of strings |
| 84 // |
| 85 // The keys are |
| 86 // SHA256(net::TransportSecurityState::CanonicalizeHost(domain)). The |
| 87 // reason for hashing them is so that the stored state does not trivially |
| 88 // reveal a user's browsing history to an attacker reading the serialized |
| 89 // state on disk. |
| 90 bool Serialize(const net::TransportSecurityState::Iterator& state, |
| 91 std::string* output) const; |
| 92 |
| 93 // Populates |state| from the JSON string |serialized|. Returns true if |
| 94 // all entries were parsed and deserialized correctly. |
| 95 // |
| 96 // Sets |*dirty| to true if the new state differs from the persisted |
| 97 // state; false otherwise. |
| 98 static bool Deserialize(const std::string& serialized, |
| 99 bool* dirty, |
| 100 net::TransportSecurityState* state); |
| 101 |
| 102 // Clears any existing non-static entries, and then re-populates |state| |
| 103 // by invoking |Deserialize|. |
| 104 // |
| 105 // Sets |*dirty| to true if the new state differs from the persisted |
| 106 // state; false otherwise. |
| 107 bool LoadEntries(const std::string& serialized, |
| 108 bool* dirty, |
| 109 net::TransportSecurityState* state); |
| 110 |
64 void CompleteLoad(const std::string& state); | 111 void CompleteLoad(const std::string& state); |
65 | 112 |
66 net::TransportSecurityState* transport_security_state_; | 113 net::TransportSecurityState* transport_security_state_; |
67 | 114 |
68 // Helper for safely writing the data. | 115 // Helper for safely writing the data. |
69 ImportantFileWriter writer_; | 116 ImportantFileWriter writer_; |
70 | 117 |
71 // Whether or not we're in read-only mode. | 118 // Whether or not we're in read-only mode. |
72 const bool readonly_; | 119 const bool readonly_; |
73 | 120 |
74 base::WeakPtrFactory<TransportSecurityPersister> weak_ptr_factory_; | 121 base::WeakPtrFactory<TransportSecurityPersister> weak_ptr_factory_; |
75 | 122 |
76 DISALLOW_COPY_AND_ASSIGN(TransportSecurityPersister); | 123 DISALLOW_COPY_AND_ASSIGN(TransportSecurityPersister); |
77 }; | 124 }; |
78 | 125 |
79 #endif // CHROME_BROWSER_TRANSPORT_SECURITY_PERSISTER_H_ | 126 #endif // CHROME_BROWSER_TRANSPORT_SECURITY_PERSISTER_H_ |
OLD | NEW |