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

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

Issue 999003003: Include attributes of zipped binaries in ClientDownloadRequests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@zip2
Patch Set: fix ordering of SandboxedZipAnalyzer methods Created 5 years, 9 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
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/download_protection_service.h" 5 #include "chrome/browser/safe_browsing/download_protection_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/browser/history/history_service_factory.h" 24 #include "chrome/browser/history/history_service_factory.h"
25 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/safe_browsing/download_feedback_service.h" 26 #include "chrome/browser/safe_browsing/download_feedback_service.h"
27 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 27 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
28 #include "chrome/browser/safe_browsing/sandboxed_zip_analyzer.h" 28 #include "chrome/browser/safe_browsing/sandboxed_zip_analyzer.h"
29 #include "chrome/browser/ui/browser.h" 29 #include "chrome/browser/ui/browser.h"
30 #include "chrome/browser/ui/browser_list.h" 30 #include "chrome/browser/ui/browser_list.h"
31 #include "chrome/common/safe_browsing/binary_feature_extractor.h" 31 #include "chrome/common/safe_browsing/binary_feature_extractor.h"
32 #include "chrome/common/safe_browsing/csd.pb.h" 32 #include "chrome/common/safe_browsing/csd.pb.h"
33 #include "chrome/common/safe_browsing/download_protection_util.h" 33 #include "chrome/common/safe_browsing/download_protection_util.h"
34 #include "chrome/common/safe_browsing/zip_analyzer.h" 34 #include "chrome/common/safe_browsing/zip_analyzer_results.h"
35 #include "chrome/common/url_constants.h" 35 #include "chrome/common/url_constants.h"
36 #include "components/google/core/browser/google_util.h" 36 #include "components/google/core/browser/google_util.h"
37 #include "components/history/core/browser/history_service.h" 37 #include "components/history/core/browser/history_service.h"
38 #include "content/public/browser/browser_thread.h" 38 #include "content/public/browser/browser_thread.h"
39 #include "content/public/browser/download_item.h" 39 #include "content/public/browser/download_item.h"
40 #include "content/public/browser/page_navigator.h" 40 #include "content/public/browser/page_navigator.h"
41 #include "crypto/sha2.h" 41 #include "crypto/sha2.h"
42 #include "google_apis/google_api_keys.h" 42 #include "google_apis/google_api_keys.h"
43 #include "net/base/escape.h" 43 #include "net/base/escape.h"
44 #include "net/base/load_flags.h" 44 #include "net/base/load_flags.h"
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 weakptr_factory_.GetWeakPtr())); 580 weakptr_factory_.GetWeakPtr()));
581 analyzer_->Start(); 581 analyzer_->Start();
582 } 582 }
583 583
584 void OnZipAnalysisFinished(const zip_analyzer::Results& results) { 584 void OnZipAnalysisFinished(const zip_analyzer::Results& results) {
585 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 585 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
586 if (!service_) 586 if (!service_)
587 return; 587 return;
588 if (results.success) { 588 if (results.success) {
589 zipped_executable_ = results.has_executable; 589 zipped_executable_ = results.has_executable;
590 archived_binary_.CopyFrom(results.archived_binary);
590 DVLOG(1) << "Zip analysis finished for " << item_->GetFullPath().value() 591 DVLOG(1) << "Zip analysis finished for " << item_->GetFullPath().value()
591 << ", has_executable=" << results.has_executable 592 << ", has_executable=" << results.has_executable
592 << " has_archive=" << results.has_archive; 593 << " has_archive=" << results.has_archive;
593 } else { 594 } else {
594 DVLOG(1) << "Zip analysis failed for " << item_->GetFullPath().value(); 595 DVLOG(1) << "Zip analysis failed for " << item_->GetFullPath().value();
595 } 596 }
596 UMA_HISTOGRAM_BOOLEAN("SBClientDownload.ZipFileHasExecutable", 597 UMA_HISTOGRAM_BOOLEAN("SBClientDownload.ZipFileHasExecutable",
597 zipped_executable_); 598 zipped_executable_);
598 UMA_HISTOGRAM_BOOLEAN("SBClientDownload.ZipFileHasArchiveButNoExecutable", 599 UMA_HISTOGRAM_BOOLEAN("SBClientDownload.ZipFileHasArchiveButNoExecutable",
599 results.has_archive && !zipped_executable_); 600 results.has_archive && !zipped_executable_);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 request.set_file_basename( 767 request.set_file_basename(
767 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe()); 768 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe());
768 request.set_download_type(type_); 769 request.set_download_type(type_);
769 request.mutable_signature()->CopyFrom(signature_info_); 770 request.mutable_signature()->CopyFrom(signature_info_);
770 if (image_headers_) 771 if (image_headers_)
771 request.set_allocated_image_headers(image_headers_.release()); 772 request.set_allocated_image_headers(image_headers_.release());
772 if (!request.SerializeToString(&client_download_request_data_)) { 773 if (!request.SerializeToString(&client_download_request_data_)) {
773 FinishRequest(UNKNOWN, REASON_INVALID_REQUEST_PROTO); 774 FinishRequest(UNKNOWN, REASON_INVALID_REQUEST_PROTO);
774 return; 775 return;
775 } 776 }
776 777 if (zipped_executable_)
778 request.mutable_archived_binary()->Swap(&archived_binary_);
777 service_->client_download_request_callbacks_.Notify(item_, &request); 779 service_->client_download_request_callbacks_.Notify(item_, &request);
778 780
779 DVLOG(2) << "Sending a request for URL: " 781 DVLOG(2) << "Sending a request for URL: "
780 << item_->GetUrlChain().back(); 782 << item_->GetUrlChain().back();
781 fetcher_.reset(net::URLFetcher::Create(0 /* ID used for testing */, 783 fetcher_.reset(net::URLFetcher::Create(0 /* ID used for testing */,
782 GetDownloadRequestUrl(), 784 GetDownloadRequestUrl(),
783 net::URLFetcher::POST, 785 net::URLFetcher::POST,
784 this)); 786 this));
785 fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); 787 fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE);
786 fetcher_->SetAutomaticallyRetryOn5xx(false); // Don't retry on error. 788 fetcher_->SetAutomaticallyRetryOn5xx(false); // Don't retry on error.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 GURL referrer_url_; 913 GURL referrer_url_;
912 // URL chain of redirects leading to (but not including) |tab_url|. 914 // URL chain of redirects leading to (but not including) |tab_url|.
913 std::vector<GURL> tab_redirects_; 915 std::vector<GURL> tab_redirects_;
914 // URL and referrer of the window the download was started from. 916 // URL and referrer of the window the download was started from.
915 GURL tab_url_; 917 GURL tab_url_;
916 GURL tab_referrer_url_; 918 GURL tab_referrer_url_;
917 919
918 bool zipped_executable_; 920 bool zipped_executable_;
919 ClientDownloadRequest_SignatureInfo signature_info_; 921 ClientDownloadRequest_SignatureInfo signature_info_;
920 scoped_ptr<ClientDownloadRequest_ImageHeaders> image_headers_; 922 scoped_ptr<ClientDownloadRequest_ImageHeaders> image_headers_;
923 google::protobuf::RepeatedPtrField<ClientDownloadRequest_ArchivedBinary>
924 archived_binary_;
921 CheckDownloadCallback callback_; 925 CheckDownloadCallback callback_;
922 // Will be NULL if the request has been canceled. 926 // Will be NULL if the request has been canceled.
923 DownloadProtectionService* service_; 927 DownloadProtectionService* service_;
924 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor_; 928 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor_;
925 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; 929 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_;
926 const bool pingback_enabled_; 930 const bool pingback_enabled_;
927 scoped_ptr<net::URLFetcher> fetcher_; 931 scoped_ptr<net::URLFetcher> fetcher_;
928 scoped_refptr<SandboxedZipAnalyzer> analyzer_; 932 scoped_refptr<SandboxedZipAnalyzer> analyzer_;
929 base::TimeTicks zip_analysis_start_time_; 933 base::TimeTicks zip_analysis_start_time_;
930 bool finished_; 934 bool finished_;
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 GURL DownloadProtectionService::GetDownloadRequestUrl() { 1140 GURL DownloadProtectionService::GetDownloadRequestUrl() {
1137 GURL url(kDownloadRequestUrl); 1141 GURL url(kDownloadRequestUrl);
1138 std::string api_key = google_apis::GetAPIKey(); 1142 std::string api_key = google_apis::GetAPIKey();
1139 if (!api_key.empty()) 1143 if (!api_key.empty())
1140 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); 1144 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true));
1141 1145
1142 return url; 1146 return url;
1143 } 1147 }
1144 1148
1145 } // namespace safe_browsing 1149 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698