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

Side by Side Diff: chrome/browser/profiles/profile_impl_io_data.cc

Issue 24734007: Encrypt all stored cookies on selected operating systems. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updated new DB schema to be consistent with after-upgrade version Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
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 "chrome/browser/profiles/profile_impl_io_data.h" 5 #include "chrome/browser/profiles/profile_impl_io_data.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/browser/net/chrome_network_delegate.h" 24 #include "chrome/browser/net/chrome_network_delegate.h"
25 #include "chrome/browser/net/connect_interceptor.h" 25 #include "chrome/browser/net/connect_interceptor.h"
26 #include "chrome/browser/net/http_server_properties_manager.h" 26 #include "chrome/browser/net/http_server_properties_manager.h"
27 #include "chrome/browser/net/predictor.h" 27 #include "chrome/browser/net/predictor.h"
28 #include "chrome/browser/net/sqlite_server_bound_cert_store.h" 28 #include "chrome/browser/net/sqlite_server_bound_cert_store.h"
29 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/common/chrome_constants.h" 30 #include "chrome/common/chrome_constants.h"
31 #include "chrome/common/chrome_switches.h" 31 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
33 #include "chrome/common/url_constants.h" 33 #include "chrome/common/url_constants.h"
34 #include "components/webdata/encryptor/encryptor.h"
34 #include "content/public/browser/browser_thread.h" 35 #include "content/public/browser/browser_thread.h"
36 #include "content/public/browser/cookie_crypto_delegate.h"
35 #include "content/public/browser/cookie_store_factory.h" 37 #include "content/public/browser/cookie_store_factory.h"
36 #include "content/public/browser/notification_service.h" 38 #include "content/public/browser/notification_service.h"
37 #include "content/public/browser/resource_context.h" 39 #include "content/public/browser/resource_context.h"
38 #include "content/public/browser/storage_partition.h" 40 #include "content/public/browser/storage_partition.h"
39 #include "extensions/common/constants.h" 41 #include "extensions/common/constants.h"
40 #include "net/base/cache_type.h" 42 #include "net/base/cache_type.h"
41 #include "net/ftp/ftp_network_layer.h" 43 #include "net/ftp/ftp_network_layer.h"
42 #include "net/http/http_cache.h" 44 #include "net/http/http_cache.h"
43 #include "net/ssl/server_bound_cert_service.h" 45 #include "net/ssl/server_bound_cert_service.h"
44 #include "net/url_request/protocol_intercept_job_factory.h" 46 #include "net/url_request/protocol_intercept_job_factory.h"
45 #include "net/url_request/url_request_job_factory_impl.h" 47 #include "net/url_request/url_request_job_factory_impl.h"
46 #include "webkit/browser/quota/special_storage_policy.h" 48 #include "webkit/browser/quota/special_storage_policy.h"
47 49
48 #if defined(OS_ANDROID) 50 #if defined(OS_ANDROID)
49 #include "chrome/app/android/chrome_data_reduction_proxy_android.h" 51 #include "chrome/app/android/chrome_data_reduction_proxy_android.h"
50 #endif 52 #endif
51 53
52 namespace { 54 namespace {
53 55
56 // Use the operating system's mechanisms to encrypt cookies before writing
57 // them to persistent store. Currently this only is done with desktop OS's
58 // because ChromeOS and Android already protect the entire profile contents.
59 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
60 class CookieOSCryptoDelegate : public content::CookieCryptoDelegate {
61 public:
62 virtual bool EncryptString(const std::string& plaintext,
63 std::string* ciphertext) OVERRIDE;
64 virtual bool DecryptString(const std::string& ciphertext,
65 std::string* plaintext) OVERRIDE;
66 };
67
68 bool CookieOSCryptoDelegate::EncryptString(const std::string& plaintext,
69 std::string* ciphertext) {
70 return Encryptor::EncryptString(plaintext, ciphertext);
71 }
72
73 bool CookieOSCryptoDelegate::DecryptString(const std::string& ciphertext,
74 std::string* plaintext) {
75 return Encryptor::DecryptString(ciphertext, plaintext);
76 }
77
78 scoped_ptr<content::CookieCryptoDelegate> CreateCookieCryptoIfUseful() {
79 return scoped_ptr<content::CookieCryptoDelegate>(
80 new CookieOSCryptoDelegate);
81 }
82 #else
83 scoped_ptr<content::CookieCryptoDelegate> CreateCookieCryptoIfUseful() {
84 return scoped_ptr<content::CookieCryptoDelegate>();
85 }
86 #endif
87
88
54 net::BackendType ChooseCacheBackendType() { 89 net::BackendType ChooseCacheBackendType() {
55 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 90 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
56 if (command_line.HasSwitch(switches::kUseSimpleCacheBackend)) { 91 if (command_line.HasSwitch(switches::kUseSimpleCacheBackend)) {
57 const std::string opt_value = 92 const std::string opt_value =
58 command_line.GetSwitchValueASCII(switches::kUseSimpleCacheBackend); 93 command_line.GetSwitchValueASCII(switches::kUseSimpleCacheBackend);
59 if (LowerCaseEqualsASCII(opt_value, "off")) 94 if (LowerCaseEqualsASCII(opt_value, "off"))
60 return net::CACHE_BACKEND_BLOCKFILE; 95 return net::CACHE_BACKEND_BLOCKFILE;
61 if (opt_value == "" || LowerCaseEqualsASCII(opt_value, "on")) 96 if (opt_value == "" || LowerCaseEqualsASCII(opt_value, "on"))
62 return net::CACHE_BACKEND_SIMPLE; 97 return net::CACHE_BACKEND_SIMPLE;
63 } 98 }
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 422
388 // setup cookie store 423 // setup cookie store
389 if (!cookie_store.get()) { 424 if (!cookie_store.get()) {
390 DCHECK(!lazy_params_->cookie_path.empty()); 425 DCHECK(!lazy_params_->cookie_path.empty());
391 426
392 cookie_store = content::CreatePersistentCookieStore( 427 cookie_store = content::CreatePersistentCookieStore(
393 lazy_params_->cookie_path, 428 lazy_params_->cookie_path,
394 lazy_params_->restore_old_session_cookies, 429 lazy_params_->restore_old_session_cookies,
395 lazy_params_->special_storage_policy.get(), 430 lazy_params_->special_storage_policy.get(),
396 profile_params->cookie_monster_delegate.get(), 431 profile_params->cookie_monster_delegate.get(),
397 scoped_refptr<base::SequencedTaskRunner>()); 432 scoped_refptr<base::SequencedTaskRunner>(),
433 CreateCookieCryptoIfUseful());
398 cookie_store->GetCookieMonster()->SetPersistSessionCookies(true); 434 cookie_store->GetCookieMonster()->SetPersistSessionCookies(true);
399 } 435 }
400 436
401 main_context->set_cookie_store(cookie_store.get()); 437 main_context->set_cookie_store(cookie_store.get());
402 438
403 // Setup server bound cert service. 439 // Setup server bound cert service.
404 if (!server_bound_cert_service) { 440 if (!server_bound_cert_service) {
405 DCHECK(!lazy_params_->server_bound_cert_path.empty()); 441 DCHECK(!lazy_params_->server_bound_cert_path.empty());
406 442
407 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = 443 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db =
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 519
484 extensions_context->set_throttler_manager( 520 extensions_context->set_throttler_manager(
485 io_thread_globals->throttler_manager.get()); 521 io_thread_globals->throttler_manager.get());
486 522
487 net::CookieStore* extensions_cookie_store = 523 net::CookieStore* extensions_cookie_store =
488 content::CreatePersistentCookieStore( 524 content::CreatePersistentCookieStore(
489 lazy_params_->extensions_cookie_path, 525 lazy_params_->extensions_cookie_path,
490 lazy_params_->restore_old_session_cookies, 526 lazy_params_->restore_old_session_cookies,
491 NULL, 527 NULL,
492 NULL, 528 NULL,
493 scoped_refptr<base::SequencedTaskRunner>()); 529 scoped_refptr<base::SequencedTaskRunner>(),
530 CreateCookieCryptoIfUseful());
494 // Enable cookies for devtools and extension URLs. 531 // Enable cookies for devtools and extension URLs.
495 const char* schemes[] = {chrome::kChromeDevToolsScheme, 532 const char* schemes[] = {chrome::kChromeDevToolsScheme,
496 extensions::kExtensionScheme}; 533 extensions::kExtensionScheme};
497 extensions_cookie_store->GetCookieMonster()->SetCookieableSchemes(schemes, 2); 534 extensions_cookie_store->GetCookieMonster()->SetCookieableSchemes(schemes, 2);
498 extensions_context->set_cookie_store(extensions_cookie_store); 535 extensions_context->set_cookie_store(extensions_cookie_store);
499 536
500 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( 537 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory(
501 new net::URLRequestJobFactoryImpl()); 538 new net::URLRequestJobFactoryImpl());
502 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. 539 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate.
503 // Without a network_delegate, this protocol handler will never 540 // Without a network_delegate, this protocol handler will never
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 DCHECK(!cookie_path.empty()); 607 DCHECK(!cookie_path.empty());
571 608
572 // TODO(creis): We should have a cookie delegate for notifying the cookie 609 // TODO(creis): We should have a cookie delegate for notifying the cookie
573 // extensions API, but we need to update it to understand isolated apps 610 // extensions API, but we need to update it to understand isolated apps
574 // first. 611 // first.
575 cookie_store = content::CreatePersistentCookieStore( 612 cookie_store = content::CreatePersistentCookieStore(
576 cookie_path, 613 cookie_path,
577 false, 614 false,
578 NULL, 615 NULL,
579 NULL, 616 NULL,
580 scoped_refptr<base::SequencedTaskRunner>()); 617 scoped_refptr<base::SequencedTaskRunner>(),
618 CreateCookieCryptoIfUseful());
581 } 619 }
582 620
583 // Transfer ownership of the cookies and cache to AppRequestContext. 621 // Transfer ownership of the cookies and cache to AppRequestContext.
584 context->SetCookieStore(cookie_store.get()); 622 context->SetCookieStore(cookie_store.get());
585 context->SetHttpTransactionFactory( 623 context->SetHttpTransactionFactory(
586 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); 624 scoped_ptr<net::HttpTransactionFactory>(app_http_cache));
587 625
588 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( 626 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
589 new net::URLRequestJobFactoryImpl()); 627 new net::URLRequestJobFactoryImpl());
590 InstallProtocolHandlers(job_factory.get(), protocol_handlers); 628 InstallProtocolHandlers(job_factory.get(), protocol_handlers);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 const base::Closure& completion) { 731 const base::Closure& completion) {
694 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 732 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
695 DCHECK(initialized()); 733 DCHECK(initialized());
696 734
697 DCHECK(transport_security_state()); 735 DCHECK(transport_security_state());
698 // Completes synchronously. 736 // Completes synchronously.
699 transport_security_state()->DeleteAllDynamicDataSince(time); 737 transport_security_state()->DeleteAllDynamicDataSince(time);
700 DCHECK(http_server_properties_manager_); 738 DCHECK(http_server_properties_manager_);
701 http_server_properties_manager_->Clear(completion); 739 http_server_properties_manager_->Clear(completion);
702 } 740 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698