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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_service.cc

Issue 10069031: Replace SafeBrowsing MAC with downloads over SSL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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/safe_browsing/safe_browsing_service.h" 5 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 using content::BrowserThread; 52 using content::BrowserThread;
53 using content::NavigationEntry; 53 using content::NavigationEntry;
54 using content::WebContents; 54 using content::WebContents;
55 55
56 namespace { 56 namespace {
57 57
58 // Filename suffix for the cookie database. 58 // Filename suffix for the cookie database.
59 const FilePath::CharType kCookiesFile[] = FILE_PATH_LITERAL(" Cookies"); 59 const FilePath::CharType kCookiesFile[] = FILE_PATH_LITERAL(" Cookies");
60 60
61 // The default URL prefix where browser fetches chunk updates, hashes, 61 // The default URL prefix where browser fetches chunk updates, hashes,
62 // and reports safe browsing hits. 62 // and reports safe browsing hits and malware details.
63 const char* const kSbDefaultInfoURLPrefix = 63 const char* const kSbDefaultURLPrefix =
64 "http://safebrowsing.clients.google.com/safebrowsing"; 64 "https://safebrowsing.google.com/safebrowsing";
65
66 // The default URL prefix where browser fetches MAC client key and reports
67 // malware details.
68 const char* const kSbDefaultMacKeyURLPrefix =
69 "https://sb-ssl.google.com/safebrowsing";
70 65
71 // When download url check takes this long, client's callback will be called 66 // When download url check takes this long, client's callback will be called
72 // without waiting for the result. 67 // without waiting for the result.
73 const int64 kDownloadUrlCheckTimeoutMs = 10000; 68 const int64 kDownloadUrlCheckTimeoutMs = 10000;
74 69
75 // Similar to kDownloadUrlCheckTimeoutMs, but for download hash checks. 70 // Similar to kDownloadUrlCheckTimeoutMs, but for download hash checks.
76 const int64 kDownloadHashCheckTimeoutMs = 10000; 71 const int64 kDownloadHashCheckTimeoutMs = 10000;
77 72
78 // Records disposition information about the check. |hit| should be 73 // Records disposition information about the check. |hit| should be
79 // |true| if there were any prefix hits in |full_hashes|. 74 // |true| if there were any prefix hits in |full_hashes|.
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 574
580 if (proceed) { 575 if (proceed) {
581 BrowserThread::PostTask( 576 BrowserThread::PostTask(
582 BrowserThread::UI, 577 BrowserThread::UI,
583 FROM_HERE, 578 FROM_HERE,
584 base::Bind(&SafeBrowsingService::UpdateWhitelist, this, resource)); 579 base::Bind(&SafeBrowsingService::UpdateWhitelist, this, resource));
585 } 580 }
586 } 581 }
587 } 582 }
588 583
589 void SafeBrowsingService::OnNewMacKeys(const std::string& client_key,
590 const std::string& wrapped_key) {
591 PrefService* prefs = g_browser_process->local_state();
592 if (prefs) {
593 prefs->SetString(prefs::kSafeBrowsingClientKey, client_key);
594 prefs->SetString(prefs::kSafeBrowsingWrappedKey, wrapped_key);
595 }
596 }
597
598 net::URLRequestContextGetter* SafeBrowsingService::url_request_context() { 584 net::URLRequestContextGetter* SafeBrowsingService::url_request_context() {
599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 585 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
600 return url_request_context_getter_.get(); 586 return url_request_context_getter_.get();
601 } 587 }
602 588
603 // static
604 void SafeBrowsingService::RegisterPrefs(PrefService* prefs) {
605 prefs->RegisterStringPref(prefs::kSafeBrowsingClientKey, "");
606 prefs->RegisterStringPref(prefs::kSafeBrowsingWrappedKey, "");
607 }
608
609 void SafeBrowsingService::ResetDatabase() { 589 void SafeBrowsingService::ResetDatabase() {
610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 590 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
611 DCHECK(enabled_); 591 DCHECK(enabled_);
612 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( 592 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind(
613 &SafeBrowsingService::OnResetDatabase, this)); 593 &SafeBrowsingService::OnResetDatabase, this));
614 } 594 }
615 595
616 void SafeBrowsingService::PurgeMemory() { 596 void SafeBrowsingService::PurgeMemory() {
617 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
618 CloseDatabase(); 598 CloseDatabase();
(...skipping 27 matching lines...) Expand all
646 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where 626 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where
647 // url_request_context_getter_ is cleared, since the URLRequestContextGetter 627 // url_request_context_getter_ is cleared, since the URLRequestContextGetter
648 // will PostTask to IOTread to delete itself. 628 // will PostTask to IOTread to delete itself.
649 using base::debug::LeakTracker; 629 using base::debug::LeakTracker;
650 LeakTracker<SafeBrowsingURLRequestContextGetter>::CheckForLeaks(); 630 LeakTracker<SafeBrowsingURLRequestContextGetter>::CheckForLeaks();
651 631
652 DCHECK(url_request_context_.get()); 632 DCHECK(url_request_context_.get());
653 url_request_context_ = NULL; 633 url_request_context_ = NULL;
654 } 634 }
655 635
656 void SafeBrowsingService::StartOnIOThread( 636 void SafeBrowsingService::StartOnIOThread() {
657 const std::string& client_key,
658 const std::string& wrapped_key) {
659 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 637 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
660 if (enabled_) 638 if (enabled_)
661 return; 639 return;
662 DCHECK(!safe_browsing_thread_.get()); 640 DCHECK(!safe_browsing_thread_.get());
663 safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread")); 641 safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread"));
664 if (!safe_browsing_thread_->Start()) 642 if (!safe_browsing_thread_->Start())
665 return; 643 return;
666 enabled_ = true; 644 enabled_ = true;
667 645
668 registrar_.reset(new content::NotificationRegistrar); 646 registrar_.reset(new content::NotificationRegistrar);
(...skipping 10 matching lines...) Expand all
679 #if defined(GOOGLE_CHROME_BUILD) 657 #if defined(GOOGLE_CHROME_BUILD)
680 std::string client_name("googlechrome"); 658 std::string client_name("googlechrome");
681 #else 659 #else
682 std::string client_name("chromium"); 660 std::string client_name("chromium");
683 #endif 661 #endif
684 #endif 662 #endif
685 CommandLine* cmdline = CommandLine::ForCurrentProcess(); 663 CommandLine* cmdline = CommandLine::ForCurrentProcess();
686 bool disable_auto_update = 664 bool disable_auto_update =
687 cmdline->HasSwitch(switches::kSbDisableAutoUpdate) || 665 cmdline->HasSwitch(switches::kSbDisableAutoUpdate) ||
688 cmdline->HasSwitch(switches::kDisableBackgroundNetworking); 666 cmdline->HasSwitch(switches::kDisableBackgroundNetworking);
689 std::string info_url_prefix = 667 std::string url_prefix =
690 cmdline->HasSwitch(switches::kSbInfoURLPrefix) ? 668 cmdline->HasSwitch(switches::kSbURLPrefix) ?
691 cmdline->GetSwitchValueASCII(switches::kSbInfoURLPrefix) : 669 cmdline->GetSwitchValueASCII(switches::kSbURLPrefix) :
692 kSbDefaultInfoURLPrefix; 670 kSbDefaultURLPrefix;
693 std::string mackey_url_prefix =
694 cmdline->HasSwitch(switches::kSbMacKeyURLPrefix) ?
695 cmdline->GetSwitchValueASCII(switches::kSbMacKeyURLPrefix) :
696 kSbDefaultMacKeyURLPrefix;
697 671
698 DCHECK(!protocol_manager_); 672 DCHECK(!protocol_manager_);
699 protocol_manager_ = 673 protocol_manager_ =
700 SafeBrowsingProtocolManager::Create(this, 674 SafeBrowsingProtocolManager::Create(this,
701 client_name, 675 client_name,
702 client_key,
703 wrapped_key,
704 url_request_context_getter_, 676 url_request_context_getter_,
705 info_url_prefix, 677 url_prefix,
706 mackey_url_prefix,
707 disable_auto_update); 678 disable_auto_update);
708 679
709 protocol_manager_->Initialize(); 680 protocol_manager_->Initialize();
710 } 681 }
711 682
712 void SafeBrowsingService::StopOnIOThread() { 683 void SafeBrowsingService::StopOnIOThread() {
713 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 684 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
714 if (!enabled_) 685 if (!enabled_)
715 return; 686 return;
716 687
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 void SafeBrowsingService::DatabaseUpdateFinished(bool update_succeeded) { 969 void SafeBrowsingService::DatabaseUpdateFinished(bool update_succeeded) {
999 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop()); 970 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop());
1000 GetDatabase()->UpdateFinished(update_succeeded); 971 GetDatabase()->UpdateFinished(update_succeeded);
1001 DCHECK(database_update_in_progress_); 972 DCHECK(database_update_in_progress_);
1002 database_update_in_progress_ = false; 973 database_update_in_progress_ = false;
1003 } 974 }
1004 975
1005 void SafeBrowsingService::Start() { 976 void SafeBrowsingService::Start() {
1006 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 977 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1007 978
1008 // Retrieve client MAC keys.
1009 PrefService* local_state = g_browser_process->local_state();
1010 DCHECK(local_state);
1011 std::string client_key, wrapped_key;
1012 if (local_state) {
1013 client_key =
1014 local_state->GetString(prefs::kSafeBrowsingClientKey);
1015 wrapped_key =
1016 local_state->GetString(prefs::kSafeBrowsingWrappedKey);
1017 }
1018
1019 CommandLine* cmdline = CommandLine::ForCurrentProcess(); 979 CommandLine* cmdline = CommandLine::ForCurrentProcess();
1020 enable_download_protection_ = 980 enable_download_protection_ =
1021 !cmdline->HasSwitch(switches::kSbDisableDownloadProtection); 981 !cmdline->HasSwitch(switches::kSbDisableDownloadProtection);
1022 982
1023 // We only download the csd-whitelist if client-side phishing detection is 983 // We only download the csd-whitelist if client-side phishing detection is
1024 // enabled. 984 // enabled.
1025 #ifdef OS_CHROMEOS 985 #ifdef OS_CHROMEOS
1026 // Client-side detection is disabled on ChromeOS for now, so don't bother 986 // Client-side detection is disabled on ChromeOS for now, so don't bother
1027 // downloading the whitelist. 987 // downloading the whitelist.
1028 enable_csd_whitelist_ = false; 988 enable_csd_whitelist_ = false;
1029 #else 989 #else
1030 enable_csd_whitelist_ = 990 enable_csd_whitelist_ =
1031 !cmdline->HasSwitch(switches::kDisableClientSidePhishingDetection); 991 !cmdline->HasSwitch(switches::kDisableClientSidePhishingDetection);
1032 #endif 992 #endif
1033 993
1034 // TODO(noelutz): remove this boolean variable since it should always be true 994 // TODO(noelutz): remove this boolean variable since it should always be true
1035 // if SafeBrowsing is enabled. Unfortunately, we have no test data for this 995 // if SafeBrowsing is enabled. Unfortunately, we have no test data for this
1036 // list right now. This means that we need to be able to disable this list 996 // list right now. This means that we need to be able to disable this list
1037 // for the SafeBrowsing test to pass. 997 // for the SafeBrowsing test to pass.
1038 enable_download_whitelist_ = enable_csd_whitelist_; 998 enable_download_whitelist_ = enable_csd_whitelist_;
1039 999
1040 BrowserThread::PostTask( 1000 BrowserThread::PostTask(
1041 BrowserThread::IO, FROM_HERE, 1001 BrowserThread::IO, FROM_HERE,
1042 base::Bind(&SafeBrowsingService::StartOnIOThread, 1002 base::Bind(&SafeBrowsingService::StartOnIOThread, this));
1043 this, client_key, wrapped_key));
1044 } 1003 }
1045 1004
1046 void SafeBrowsingService::Stop() { 1005 void SafeBrowsingService::Stop() {
1047 BrowserThread::PostTask( 1006 BrowserThread::PostTask(
1048 BrowserThread::IO, FROM_HERE, 1007 BrowserThread::IO, FROM_HERE,
1049 base::Bind(&SafeBrowsingService::StopOnIOThread, this)); 1008 base::Bind(&SafeBrowsingService::StopOnIOThread, this));
1050 } 1009 }
1051 1010
1052 void SafeBrowsingService::OnCloseDatabase() { 1011 void SafeBrowsingService::OnCloseDatabase() {
1053 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop()); 1012 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop());
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 Stop(); 1419 Stop();
1461 1420
1462 if (csd_service_.get()) 1421 if (csd_service_.get())
1463 csd_service_->SetEnabledAndRefreshState(enable); 1422 csd_service_->SetEnabledAndRefreshState(enable);
1464 if (download_service_.get()) { 1423 if (download_service_.get()) {
1465 download_service_->SetEnabled( 1424 download_service_->SetEnabled(
1466 enable && !CommandLine::ForCurrentProcess()->HasSwitch( 1425 enable && !CommandLine::ForCurrentProcess()->HasSwitch(
1467 switches::kDisableImprovedDownloadProtection)); 1426 switches::kDisableImprovedDownloadProtection));
1468 } 1427 }
1469 } 1428 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698