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 // 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 // legacy key synonym "bad_preloaded_spki_hashes" | 78 // legacy key synonym "bad_preloaded_spki_hashes" |
79 // "dynamic_spki_hashes": list of strings | 79 // "dynamic_spki_hashes": list of strings |
80 // | 80 // |
81 // The JSON dictionary keys are strings containing | 81 // The JSON dictionary keys are strings containing |
82 // Base64(SHA256(net::TransportSecurityState::CanonicalizeHost(domain))). | 82 // Base64(SHA256(net::TransportSecurityState::CanonicalizeHost(domain))). |
83 // The reason for hashing them is so that the stored state does not | 83 // The reason for hashing them is so that the stored state does not |
84 // trivially reveal a user's browsing history to an attacker reading the | 84 // trivially reveal a user's browsing history to an attacker reading the |
85 // serialized state on disk. | 85 // serialized state on disk. |
86 virtual bool SerializeData(std::string* data) OVERRIDE; | 86 virtual bool SerializeData(std::string* data) OVERRIDE; |
87 | 87 |
88 // Parses an array of JSON-encoded TransportSecurityState::DomainState | |
89 // entries. For use in loading entries defined on the command line | |
90 // (switches::kHstsHosts). | |
91 bool DeserializeFromCommandLine(const std::string& serialized); | |
92 | |
93 // Clears any existing non-static entries, and then re-populates | 88 // Clears any existing non-static entries, and then re-populates |
94 // |transport_security_state_|. | 89 // |transport_security_state_|. |
95 // | 90 // |
96 // Sets |*dirty| to true if the new state differs from the persisted | 91 // Sets |*dirty| to true if the new state differs from the persisted |
97 // state; false otherwise. | 92 // state; false otherwise. |
98 bool LoadEntries(const std::string& serialized, bool* dirty); | 93 bool LoadEntries(const std::string& serialized, bool* dirty); |
99 | 94 |
100 private: | 95 private: |
101 class Loader; | 96 class Loader; |
102 | 97 |
103 // Populates |state| from the JSON string |serialized|. Returns true if | 98 // Populates |state| from the JSON string |serialized|. Returns true if |
104 // all entries were parsed and deserialized correctly. If |forced| is | 99 // all entries were parsed and deserialized correctly. |
105 // true, updates |state|'s map of "forced" DomainState entries; normally, | |
106 // leave this false. | |
107 // | 100 // |
108 // Sets |*dirty| to true if the new state differs from the persisted | 101 // Sets |*dirty| to true if the new state differs from the persisted |
109 // state; false otherwise. | 102 // state; false otherwise. |
110 static bool Deserialize(const std::string& serialized, | 103 static bool Deserialize(const std::string& serialized, |
111 bool forced, | |
112 bool* dirty, | 104 bool* dirty, |
113 net::TransportSecurityState* state); | 105 net::TransportSecurityState* state); |
114 | 106 |
115 void CompleteLoad(const std::string& state); | 107 void CompleteLoad(const std::string& state); |
116 | 108 |
117 net::TransportSecurityState* transport_security_state_; | 109 net::TransportSecurityState* transport_security_state_; |
118 | 110 |
119 // Helper for safely writing the data. | 111 // Helper for safely writing the data. |
120 base::ImportantFileWriter writer_; | 112 base::ImportantFileWriter writer_; |
121 | 113 |
122 // Whether or not we're in read-only mode. | 114 // Whether or not we're in read-only mode. |
123 const bool readonly_; | 115 const bool readonly_; |
124 | 116 |
125 base::WeakPtrFactory<TransportSecurityPersister> weak_ptr_factory_; | 117 base::WeakPtrFactory<TransportSecurityPersister> weak_ptr_factory_; |
126 | 118 |
127 DISALLOW_COPY_AND_ASSIGN(TransportSecurityPersister); | 119 DISALLOW_COPY_AND_ASSIGN(TransportSecurityPersister); |
128 }; | 120 }; |
129 | 121 |
130 #endif // CHROME_BROWSER_NET_TRANSPORT_SECURITY_PERSISTER_H_ | 122 #endif // CHROME_BROWSER_NET_TRANSPORT_SECURITY_PERSISTER_H_ |
OLD | NEW |