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 12 matching lines...) Expand all Loading... |
23 // TransportSecurityPersister::StateIsDirty | 23 // TransportSecurityPersister::StateIsDirty |
24 // since the callback isn't allowed to block or reenter, we schedule a Task | 24 // since the callback isn't allowed to block or reenter, we schedule a Task |
25 // on the file task runner after some small amount of time | 25 // on the file task runner after some small amount of time |
26 // | 26 // |
27 // ... | 27 // ... |
28 // | 28 // |
29 // TransportSecurityPersister::SerializeState | 29 // TransportSecurityPersister::SerializeState |
30 // copies the current state of the TransportSecurityState, serializes | 30 // copies the current state of the TransportSecurityState, serializes |
31 // and writes to disk. | 31 // and writes to disk. |
32 | 32 |
33 #ifndef CHROME_BROWSER_NET_TRANSPORT_SECURITY_PERSISTER_H_ | 33 #ifndef NET_HTTP_TRANSPORT_SECURITY_PERSISTER_H_ |
34 #define CHROME_BROWSER_NET_TRANSPORT_SECURITY_PERSISTER_H_ | 34 #define NET_HTTP_TRANSPORT_SECURITY_PERSISTER_H_ |
35 | 35 |
36 #include <string> | 36 #include <string> |
37 | 37 |
38 #include "base/files/file_path.h" | 38 #include "base/files/file_path.h" |
39 #include "base/files/important_file_writer.h" | 39 #include "base/files/important_file_writer.h" |
40 #include "base/memory/ref_counted.h" | 40 #include "base/memory/ref_counted.h" |
41 #include "base/memory/weak_ptr.h" | 41 #include "base/memory/weak_ptr.h" |
| 42 #include "net/base/net_export.h" |
42 #include "net/http/transport_security_state.h" | 43 #include "net/http/transport_security_state.h" |
43 | 44 |
44 namespace base { | 45 namespace base { |
45 class SequencedTaskRunner; | 46 class SequencedTaskRunner; |
46 } | 47 } |
47 | 48 |
| 49 namespace net { |
| 50 |
48 // Reads and updates on-disk TransportSecurity state. Clients of this class | 51 // Reads and updates on-disk TransportSecurity state. Clients of this class |
49 // should create, destroy, and call into it from one thread. | 52 // should create, destroy, and call into it from one thread. |
50 // | 53 // |
51 // file_task_runner is the task runner this class should use internally to | 54 // file_task_runner is the task runner this class should use internally to |
52 // perform file IO, and can optionally be associated with a different thread. | 55 // perform file IO, and can optionally be associated with a different thread. |
53 class TransportSecurityPersister | 56 class NET_EXPORT TransportSecurityPersister |
54 : public net::TransportSecurityState::Delegate, | 57 : public TransportSecurityState::Delegate, |
55 public base::ImportantFileWriter::DataSerializer { | 58 public base::ImportantFileWriter::DataSerializer { |
56 public: | 59 public: |
57 TransportSecurityPersister(net::TransportSecurityState* state, | 60 TransportSecurityPersister(TransportSecurityState* state, |
58 const base::FilePath& profile_path, | 61 const base::FilePath& profile_path, |
59 base::SequencedTaskRunner* file_task_runner, | 62 base::SequencedTaskRunner* file_task_runner, |
60 bool readonly); | 63 bool readonly); |
61 virtual ~TransportSecurityPersister(); | 64 virtual ~TransportSecurityPersister(); |
62 | 65 |
63 // Called by the TransportSecurityState when it changes its state. | 66 // Called by the TransportSecurityState when it changes its state. |
64 virtual void StateIsDirty(net::TransportSecurityState*) OVERRIDE; | 67 virtual void StateIsDirty(TransportSecurityState*) OVERRIDE; |
65 | 68 |
66 // ImportantFileWriter::DataSerializer: | 69 // ImportantFileWriter::DataSerializer: |
67 // | 70 // |
68 // Serializes |transport_security_state_| into |*output|. Returns true if | 71 // Serializes |transport_security_state_| into |*output|. Returns true if |
69 // all DomainStates were serialized correctly. | 72 // all DomainStates were serialized correctly. |
70 // | 73 // |
71 // The serialization format is JSON; the JSON represents a dictionary of | 74 // The serialization format is JSON; the JSON represents a dictionary of |
72 // host:DomainState pairs (host is a string). The DomainState is | 75 // host:DomainState pairs (host is a string). The DomainState is |
73 // represented as a dictionary containing the following keys and value | 76 // represented as a dictionary containing the following keys and value |
74 // types (not all keys will always be present): | 77 // types (not all keys will always be present): |
75 // | 78 // |
76 // "sts_include_subdomains": true|false | 79 // "sts_include_subdomains": true|false |
77 // "pkp_include_subdomains": true|false | 80 // "pkp_include_subdomains": true|false |
78 // "created": double | 81 // "created": double |
79 // "expiry": double | 82 // "expiry": double |
80 // "dynamic_spki_hashes_expiry": double | 83 // "dynamic_spki_hashes_expiry": double |
81 // "mode": "default"|"force-https" | 84 // "mode": "default"|"force-https" |
82 // legacy value synonyms "strict" = "force-https" | 85 // legacy value synonyms "strict" = "force-https" |
83 // "pinning-only" = "default" | 86 // "pinning-only" = "default" |
84 // legacy value "spdy-only" is unused and ignored | 87 // legacy value "spdy-only" is unused and ignored |
85 // "static_spki_hashes": list of strings | 88 // "static_spki_hashes": list of strings |
86 // legacy key synonym "preloaded_spki_hashes" | 89 // legacy key synonym "preloaded_spki_hashes" |
87 // "bad_static_spki_hashes": list of strings | 90 // "bad_static_spki_hashes": list of strings |
88 // legacy key synonym "bad_preloaded_spki_hashes" | 91 // legacy key synonym "bad_preloaded_spki_hashes" |
89 // "dynamic_spki_hashes": list of strings | 92 // "dynamic_spki_hashes": list of strings |
90 // | 93 // |
91 // The JSON dictionary keys are strings containing | 94 // The JSON dictionary keys are strings containing |
92 // Base64(SHA256(net::TransportSecurityState::CanonicalizeHost(domain))). | 95 // Base64(SHA256(TransportSecurityState::CanonicalizeHost(domain))). |
93 // The reason for hashing them is so that the stored state does not | 96 // The reason for hashing them is so that the stored state does not |
94 // trivially reveal a user's browsing history to an attacker reading the | 97 // trivially reveal a user's browsing history to an attacker reading the |
95 // serialized state on disk. | 98 // serialized state on disk. |
96 virtual bool SerializeData(std::string* data) OVERRIDE; | 99 virtual bool SerializeData(std::string* data) OVERRIDE; |
97 | 100 |
98 // Clears any existing non-static entries, and then re-populates | 101 // Clears any existing non-static entries, and then re-populates |
99 // |transport_security_state_|. | 102 // |transport_security_state_|. |
100 // | 103 // |
101 // Sets |*dirty| to true if the new state differs from the persisted | 104 // Sets |*dirty| to true if the new state differs from the persisted |
102 // state; false otherwise. | 105 // state; false otherwise. |
103 bool LoadEntries(const std::string& serialized, bool* dirty); | 106 bool LoadEntries(const std::string& serialized, bool* dirty); |
104 | 107 |
105 private: | 108 private: |
106 // Populates |state| from the JSON string |serialized|. Returns true if | 109 // Populates |state| from the JSON string |serialized|. Returns true if |
107 // all entries were parsed and deserialized correctly. | 110 // all entries were parsed and deserialized correctly. |
108 // | 111 // |
109 // Sets |*dirty| to true if the new state differs from the persisted | 112 // Sets |*dirty| to true if the new state differs from the persisted |
110 // state; false otherwise. | 113 // state; false otherwise. |
111 static bool Deserialize(const std::string& serialized, | 114 static bool Deserialize(const std::string& serialized, |
112 bool* dirty, | 115 bool* dirty, |
113 net::TransportSecurityState* state); | 116 TransportSecurityState* state); |
114 | 117 |
115 void CompleteLoad(const std::string& state); | 118 void CompleteLoad(const std::string& state); |
116 | 119 |
117 net::TransportSecurityState* transport_security_state_; | 120 TransportSecurityState* transport_security_state_; |
118 | 121 |
119 // Helper for safely writing the data. | 122 // Helper for safely writing the data. |
120 base::ImportantFileWriter writer_; | 123 base::ImportantFileWriter writer_; |
121 | 124 |
122 scoped_refptr<base::SequencedTaskRunner> foreground_runner_; | 125 scoped_refptr<base::SequencedTaskRunner> foreground_runner_; |
123 scoped_refptr<base::SequencedTaskRunner> background_runner_; | 126 scoped_refptr<base::SequencedTaskRunner> background_runner_; |
124 | 127 |
125 // Whether or not we're in read-only mode. | 128 // Whether or not we're in read-only mode. |
126 const bool readonly_; | 129 const bool readonly_; |
127 | 130 |
128 base::WeakPtrFactory<TransportSecurityPersister> weak_ptr_factory_; | 131 base::WeakPtrFactory<TransportSecurityPersister> weak_ptr_factory_; |
129 | 132 |
130 DISALLOW_COPY_AND_ASSIGN(TransportSecurityPersister); | 133 DISALLOW_COPY_AND_ASSIGN(TransportSecurityPersister); |
131 }; | 134 }; |
132 | 135 |
133 #endif // CHROME_BROWSER_NET_TRANSPORT_SECURITY_PERSISTER_H_ | 136 } // namespace net |
| 137 |
| 138 #endif // NET_HTTP_TRANSPORT_SECURITY_PERSISTER_H_ |
OLD | NEW |