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 "net/http/transport_security_persister.h" | 5 #include "net/http/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_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 return out; | 66 return out; |
67 } | 67 } |
68 | 68 |
69 const char kIncludeSubdomains[] = "include_subdomains"; | 69 const char kIncludeSubdomains[] = "include_subdomains"; |
70 const char kStsIncludeSubdomains[] = "sts_include_subdomains"; | 70 const char kStsIncludeSubdomains[] = "sts_include_subdomains"; |
71 const char kPkpIncludeSubdomains[] = "pkp_include_subdomains"; | 71 const char kPkpIncludeSubdomains[] = "pkp_include_subdomains"; |
72 const char kMode[] = "mode"; | 72 const char kMode[] = "mode"; |
73 const char kExpiry[] = "expiry"; | 73 const char kExpiry[] = "expiry"; |
74 const char kDynamicSPKIHashesExpiry[] = "dynamic_spki_hashes_expiry"; | 74 const char kDynamicSPKIHashesExpiry[] = "dynamic_spki_hashes_expiry"; |
75 const char kStaticSPKIHashes[] = "static_spki_hashes"; | |
76 const char kPreloadedSPKIHashes[] = "preloaded_spki_hashes"; | |
77 const char kDynamicSPKIHashes[] = "dynamic_spki_hashes"; | 75 const char kDynamicSPKIHashes[] = "dynamic_spki_hashes"; |
78 const char kForceHTTPS[] = "force-https"; | 76 const char kForceHTTPS[] = "force-https"; |
79 const char kStrict[] = "strict"; | 77 const char kStrict[] = "strict"; |
80 const char kDefault[] = "default"; | 78 const char kDefault[] = "default"; |
81 const char kPinningOnly[] = "pinning-only"; | 79 const char kPinningOnly[] = "pinning-only"; |
82 const char kCreated[] = "created"; | 80 const char kCreated[] = "created"; |
83 const char kStsObserved[] = "sts_observed"; | 81 const char kStsObserved[] = "sts_observed"; |
84 const char kPkpObserved[] = "pkp_observed"; | 82 const char kPkpObserved[] = "pkp_observed"; |
85 | 83 |
86 std::string LoadState(const base::FilePath& path) { | 84 std::string LoadState(const base::FilePath& path) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 break; | 161 break; |
164 case TransportSecurityState::DomainState::MODE_DEFAULT: | 162 case TransportSecurityState::DomainState::MODE_DEFAULT: |
165 serialized->SetString(kMode, kDefault); | 163 serialized->SetString(kMode, kDefault); |
166 break; | 164 break; |
167 default: | 165 default: |
168 NOTREACHED() << "DomainState with unknown mode"; | 166 NOTREACHED() << "DomainState with unknown mode"; |
169 delete serialized; | 167 delete serialized; |
170 continue; | 168 continue; |
171 } | 169 } |
172 | 170 |
173 serialized->Set(kStaticSPKIHashes, | |
174 SPKIHashesToListValue(domain_state.static_spki_hashes)); | |
175 | |
176 if (now < domain_state.dynamic_spki_hashes_expiry) { | 171 if (now < domain_state.dynamic_spki_hashes_expiry) { |
177 serialized->Set(kDynamicSPKIHashes, | 172 serialized->Set(kDynamicSPKIHashes, |
178 SPKIHashesToListValue(domain_state.dynamic_spki_hashes)); | 173 SPKIHashesToListValue(domain_state.dynamic_spki_hashes)); |
179 } | 174 } |
180 | 175 |
181 toplevel.Set(HashedDomainToExternalString(hostname), serialized); | 176 toplevel.Set(HashedDomainToExternalString(hostname), serialized); |
182 } | 177 } |
183 | 178 |
184 base::JSONWriter::WriteWithOptions(&toplevel, | 179 base::JSONWriter::WriteWithOptions(&toplevel, |
185 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 180 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 LOG(WARNING) << "Could not parse some elements of entry " << i.key() | 238 LOG(WARNING) << "Could not parse some elements of entry " << i.key() |
244 << "; skipping entry"; | 239 << "; skipping entry"; |
245 continue; | 240 continue; |
246 } | 241 } |
247 | 242 |
248 // Don't fail if this key is not present. | 243 // Don't fail if this key is not present. |
249 parsed->GetDouble(kDynamicSPKIHashesExpiry, | 244 parsed->GetDouble(kDynamicSPKIHashesExpiry, |
250 &dynamic_spki_hashes_expiry); | 245 &dynamic_spki_hashes_expiry); |
251 | 246 |
252 const base::ListValue* pins_list = NULL; | 247 const base::ListValue* pins_list = NULL; |
253 // preloaded_spki_hashes is a legacy synonym for static_spki_hashes. | |
254 if (parsed->GetList(kStaticSPKIHashes, &pins_list)) | |
255 SPKIHashesFromListValue(*pins_list, &domain_state.static_spki_hashes); | |
256 else if (parsed->GetList(kPreloadedSPKIHashes, &pins_list)) | |
257 SPKIHashesFromListValue(*pins_list, &domain_state.static_spki_hashes); | |
258 | |
259 if (parsed->GetList(kDynamicSPKIHashes, &pins_list)) | 248 if (parsed->GetList(kDynamicSPKIHashes, &pins_list)) |
260 SPKIHashesFromListValue(*pins_list, &domain_state.dynamic_spki_hashes); | 249 SPKIHashesFromListValue(*pins_list, &domain_state.dynamic_spki_hashes); |
261 | 250 |
262 if (mode_string == kForceHTTPS || mode_string == kStrict) { | 251 if (mode_string == kForceHTTPS || mode_string == kStrict) { |
263 domain_state.upgrade_mode = | 252 domain_state.upgrade_mode = |
264 TransportSecurityState::DomainState::MODE_FORCE_HTTPS; | 253 TransportSecurityState::DomainState::MODE_FORCE_HTTPS; |
265 } else if (mode_string == kDefault || mode_string == kPinningOnly) { | 254 } else if (mode_string == kDefault || mode_string == kPinningOnly) { |
266 domain_state.upgrade_mode = | 255 domain_state.upgrade_mode = |
267 TransportSecurityState::DomainState::MODE_DEFAULT; | 256 TransportSecurityState::DomainState::MODE_DEFAULT; |
268 } else { | 257 } else { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 bool dirty = false; | 316 bool dirty = false; |
328 if (!LoadEntries(state, &dirty)) { | 317 if (!LoadEntries(state, &dirty)) { |
329 LOG(ERROR) << "Failed to deserialize state: " << state; | 318 LOG(ERROR) << "Failed to deserialize state: " << state; |
330 return; | 319 return; |
331 } | 320 } |
332 if (dirty) | 321 if (dirty) |
333 StateIsDirty(transport_security_state_); | 322 StateIsDirty(transport_security_state_); |
334 } | 323 } |
335 | 324 |
336 } // namespace net | 325 } // namespace net |
OLD | NEW |