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

Side by Side Diff: net/base/transport_security_state.cc

Issue 3013048: Convert src/net to use std::string/char* for DictionaryValue keys. (Closed)
Patch Set: fix for windows Created 10 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
« no previous file with comments | « net/base/net_log.cc ('k') | net/http/http_net_log_params.h » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/base/transport_security_state.h" 5 #include "net/base/transport_security_state.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 195 }
196 } 196 }
197 197
198 void TransportSecurityState::SetDelegate( 198 void TransportSecurityState::SetDelegate(
199 TransportSecurityState::Delegate* delegate) { 199 TransportSecurityState::Delegate* delegate) {
200 delegate_ = delegate; 200 delegate_ = delegate;
201 } 201 }
202 202
203 // This function converts the binary hashes, which we store in 203 // This function converts the binary hashes, which we store in
204 // |enabled_hosts_|, to a base64 string which we can include in a JSON file. 204 // |enabled_hosts_|, to a base64 string which we can include in a JSON file.
205 static std::wstring HashedDomainToExternalString(const std::string& hashed) { 205 static std::string HashedDomainToExternalString(const std::string& hashed) {
206 std::string out; 206 std::string out;
207 CHECK(base::Base64Encode(hashed, &out)); 207 CHECK(base::Base64Encode(hashed, &out));
208 return ASCIIToWide(out); 208 return out;
209 } 209 }
210 210
211 // This inverts |HashedDomainToExternalString|, above. It turns an external 211 // This inverts |HashedDomainToExternalString|, above. It turns an external
212 // string (from a JSON file) into an internal (binary) string. 212 // string (from a JSON file) into an internal (binary) string.
213 static std::string ExternalStringToHashedDomain(const std::string& external) { 213 static std::string ExternalStringToHashedDomain(const std::string& external) {
214 std::string out; 214 std::string out;
215 if (!base::Base64Decode(external, &out) || 215 if (!base::Base64Decode(external, &out) ||
216 out.size() != base::SHA256_LENGTH) { 216 out.size() != base::SHA256_LENGTH) {
217 return std::string(); 217 return std::string();
218 } 218 }
219 219
220 return out; 220 return out;
221 } 221 }
222 222
223 bool TransportSecurityState::Serialise(std::string* output) { 223 bool TransportSecurityState::Serialise(std::string* output) {
224 DictionaryValue toplevel; 224 DictionaryValue toplevel;
225 for (std::map<std::string, DomainState>::const_iterator 225 for (std::map<std::string, DomainState>::const_iterator
226 i = enabled_hosts_.begin(); i != enabled_hosts_.end(); ++i) { 226 i = enabled_hosts_.begin(); i != enabled_hosts_.end(); ++i) {
227 DictionaryValue* state = new DictionaryValue; 227 DictionaryValue* state = new DictionaryValue;
228 state->SetBoolean(L"include_subdomains", i->second.include_subdomains); 228 state->SetBoolean("include_subdomains", i->second.include_subdomains);
229 state->SetReal(L"created", i->second.created.ToDoubleT()); 229 state->SetReal("created", i->second.created.ToDoubleT());
230 state->SetReal(L"expiry", i->second.expiry.ToDoubleT()); 230 state->SetReal("expiry", i->second.expiry.ToDoubleT());
231 231
232 switch (i->second.mode) { 232 switch (i->second.mode) {
233 case DomainState::MODE_STRICT: 233 case DomainState::MODE_STRICT:
234 state->SetString(L"mode", "strict"); 234 state->SetString("mode", "strict");
235 break; 235 break;
236 case DomainState::MODE_OPPORTUNISTIC: 236 case DomainState::MODE_OPPORTUNISTIC:
237 state->SetString(L"mode", "opportunistic"); 237 state->SetString("mode", "opportunistic");
238 break; 238 break;
239 case DomainState::MODE_SPDY_ONLY: 239 case DomainState::MODE_SPDY_ONLY:
240 state->SetString(L"mode", "spdy-only"); 240 state->SetString("mode", "spdy-only");
241 break; 241 break;
242 default: 242 default:
243 NOTREACHED() << "DomainState with unknown mode"; 243 NOTREACHED() << "DomainState with unknown mode";
244 delete state; 244 delete state;
245 continue; 245 continue;
246 } 246 }
247 247
248 toplevel.Set(HashedDomainToExternalString(i->first), state); 248 toplevel.Set(HashedDomainToExternalString(i->first), state);
249 } 249 }
250 250
(...skipping 18 matching lines...) Expand all
269 i != dict_value->end_keys(); ++i) { 269 i != dict_value->end_keys(); ++i) {
270 DictionaryValue* state; 270 DictionaryValue* state;
271 if (!dict_value->GetDictionaryWithoutPathExpansion(*i, &state)) 271 if (!dict_value->GetDictionaryWithoutPathExpansion(*i, &state))
272 continue; 272 continue;
273 273
274 bool include_subdomains; 274 bool include_subdomains;
275 std::string mode_string; 275 std::string mode_string;
276 double created; 276 double created;
277 double expiry; 277 double expiry;
278 278
279 if (!state->GetBoolean(L"include_subdomains", &include_subdomains) || 279 if (!state->GetBoolean("include_subdomains", &include_subdomains) ||
280 !state->GetString(L"mode", &mode_string) || 280 !state->GetString("mode", &mode_string) ||
281 !state->GetReal(L"expiry", &expiry)) { 281 !state->GetReal("expiry", &expiry)) {
282 continue; 282 continue;
283 } 283 }
284 284
285 DomainState::Mode mode; 285 DomainState::Mode mode;
286 if (mode_string == "strict") { 286 if (mode_string == "strict") {
287 mode = DomainState::MODE_STRICT; 287 mode = DomainState::MODE_STRICT;
288 } else if (mode_string == "opportunistic") { 288 } else if (mode_string == "opportunistic") {
289 mode = DomainState::MODE_OPPORTUNISTIC; 289 mode = DomainState::MODE_OPPORTUNISTIC;
290 } else if (mode_string == "spdy-only") { 290 } else if (mode_string == "spdy-only") {
291 mode = DomainState::MODE_SPDY_ONLY; 291 mode = DomainState::MODE_SPDY_ONLY;
292 } else { 292 } else {
293 LOG(WARNING) << "Unknown TransportSecurityState mode string found: " 293 LOG(WARNING) << "Unknown TransportSecurityState mode string found: "
294 << mode_string; 294 << mode_string;
295 continue; 295 continue;
296 } 296 }
297 297
298 base::Time expiry_time = base::Time::FromDoubleT(expiry); 298 base::Time expiry_time = base::Time::FromDoubleT(expiry);
299 base::Time created_time; 299 base::Time created_time;
300 if (state->GetReal(L"created", &created)) { 300 if (state->GetReal("created", &created)) {
301 created_time = base::Time::FromDoubleT(created); 301 created_time = base::Time::FromDoubleT(created);
302 } else { 302 } else {
303 // We're migrating an old entry with no creation date. Make sure we 303 // We're migrating an old entry with no creation date. Make sure we
304 // write the new date back in a reasonable time frame. 304 // write the new date back in a reasonable time frame.
305 dirtied = true; 305 dirtied = true;
306 created_time = base::Time::Now(); 306 created_time = base::Time::Now();
307 } 307 }
308 308
309 if (expiry_time <= current_time) { 309 if (expiry_time <= current_time) {
310 // Make sure we dirty the state if we drop an entry. 310 // Make sure we dirty the state if we drop an entry.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 *include_subdomains = kPreloadedSTS[j].include_subdomains; 414 *include_subdomains = kPreloadedSTS[j].include_subdomains;
415 return true; 415 return true;
416 } 416 }
417 } 417 }
418 } 418 }
419 419
420 return false; 420 return false;
421 } 421 }
422 422
423 } // namespace 423 } // namespace
OLDNEW
« no previous file with comments | « net/base/net_log.cc ('k') | net/http/http_net_log_params.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698