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

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: scan raw DB file for values to ensure encyrption 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 521
486 extensions_context->set_throttler_manager( 522 extensions_context->set_throttler_manager(
487 io_thread_globals->throttler_manager.get()); 523 io_thread_globals->throttler_manager.get());
488 524
489 net::CookieStore* extensions_cookie_store = 525 net::CookieStore* extensions_cookie_store =
490 content::CreatePersistentCookieStore( 526 content::CreatePersistentCookieStore(
491 lazy_params_->extensions_cookie_path, 527 lazy_params_->extensions_cookie_path,
492 lazy_params_->restore_old_session_cookies, 528 lazy_params_->restore_old_session_cookies,
493 NULL, 529 NULL,
494 NULL, 530 NULL,
495 scoped_refptr<base::SequencedTaskRunner>()); 531 scoped_refptr<base::SequencedTaskRunner>(),
532 CreateCookieCryptoIfUseful());
496 // Enable cookies for devtools and extension URLs. 533 // Enable cookies for devtools and extension URLs.
497 const char* schemes[] = {chrome::kChromeDevToolsScheme, 534 const char* schemes[] = {chrome::kChromeDevToolsScheme,
498 extensions::kExtensionScheme}; 535 extensions::kExtensionScheme};
499 extensions_cookie_store->GetCookieMonster()->SetCookieableSchemes(schemes, 2); 536 extensions_cookie_store->GetCookieMonster()->SetCookieableSchemes(schemes, 2);
500 extensions_context->set_cookie_store(extensions_cookie_store); 537 extensions_context->set_cookie_store(extensions_cookie_store);
501 538
502 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( 539 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory(
503 new net::URLRequestJobFactoryImpl()); 540 new net::URLRequestJobFactoryImpl());
504 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. 541 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate.
505 // Without a network_delegate, this protocol handler will never 542 // Without a network_delegate, this protocol handler will never
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 DCHECK(!cookie_path.empty()); 609 DCHECK(!cookie_path.empty());
573 610
574 // TODO(creis): We should have a cookie delegate for notifying the cookie 611 // TODO(creis): We should have a cookie delegate for notifying the cookie
575 // extensions API, but we need to update it to understand isolated apps 612 // extensions API, but we need to update it to understand isolated apps
576 // first. 613 // first.
577 cookie_store = content::CreatePersistentCookieStore( 614 cookie_store = content::CreatePersistentCookieStore(
578 cookie_path, 615 cookie_path,
579 false, 616 false,
580 NULL, 617 NULL,
581 NULL, 618 NULL,
582 scoped_refptr<base::SequencedTaskRunner>()); 619 scoped_refptr<base::SequencedTaskRunner>(),
620 CreateCookieCryptoIfUseful());
583 } 621 }
584 622
585 // Transfer ownership of the cookies and cache to AppRequestContext. 623 // Transfer ownership of the cookies and cache to AppRequestContext.
586 context->SetCookieStore(cookie_store.get()); 624 context->SetCookieStore(cookie_store.get());
587 context->SetHttpTransactionFactory( 625 context->SetHttpTransactionFactory(
588 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); 626 scoped_ptr<net::HttpTransactionFactory>(app_http_cache));
589 627
590 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( 628 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
591 new net::URLRequestJobFactoryImpl()); 629 new net::URLRequestJobFactoryImpl());
592 InstallProtocolHandlers(job_factory.get(), protocol_handlers); 630 InstallProtocolHandlers(job_factory.get(), protocol_handlers);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 const base::Closure& completion) { 733 const base::Closure& completion) {
696 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 734 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
697 DCHECK(initialized()); 735 DCHECK(initialized());
698 736
699 DCHECK(transport_security_state()); 737 DCHECK(transport_security_state());
700 // Completes synchronously. 738 // Completes synchronously.
701 transport_security_state()->DeleteAllDynamicDataSince(time); 739 transport_security_state()->DeleteAllDynamicDataSince(time);
702 DCHECK(http_server_properties_manager_); 740 DCHECK(http_server_properties_manager_);
703 http_server_properties_manager_->Clear(completion); 741 http_server_properties_manager_->Clear(completion);
704 } 742 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698