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

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

Issue 1262753002: [SafeBrowsing] Send pings for Zip files that contain other archives. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 const CheckDownloadCallback& callback, 314 const CheckDownloadCallback& callback,
315 DownloadProtectionService* service, 315 DownloadProtectionService* service,
316 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, 316 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager,
317 BinaryFeatureExtractor* binary_feature_extractor) 317 BinaryFeatureExtractor* binary_feature_extractor)
318 : item_(item), 318 : item_(item),
319 url_chain_(item->GetUrlChain()), 319 url_chain_(item->GetUrlChain()),
320 referrer_url_(item->GetReferrerUrl()), 320 referrer_url_(item->GetReferrerUrl()),
321 tab_url_(item->GetTabUrl()), 321 tab_url_(item->GetTabUrl()),
322 tab_referrer_url_(item->GetTabReferrerUrl()), 322 tab_referrer_url_(item->GetTabReferrerUrl()),
323 zipped_executable_(false), 323 zipped_executable_(false),
324 zipped_archive_(false),
324 callback_(callback), 325 callback_(callback),
325 service_(service), 326 service_(service),
326 binary_feature_extractor_(binary_feature_extractor), 327 binary_feature_extractor_(binary_feature_extractor),
327 database_manager_(database_manager), 328 database_manager_(database_manager),
328 pingback_enabled_(service_->enabled()), 329 pingback_enabled_(service_->enabled()),
329 finished_(false), 330 finished_(false),
330 type_(ClientDownloadRequest::WIN_EXECUTABLE), 331 type_(ClientDownloadRequest::WIN_EXECUTABLE),
331 start_time_(base::TimeTicks::Now()), 332 start_time_(base::TimeTicks::Now()),
332 weakptr_factory_(this) { 333 weakptr_factory_(this) {
333 DCHECK_CURRENTLY_ON(BrowserThread::UI); 334 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 // analyzer is refcounted, it might outlive the request. 595 // analyzer is refcounted, it might outlive the request.
595 analyzer_ = new SandboxedZipAnalyzer( 596 analyzer_ = new SandboxedZipAnalyzer(
596 item_->GetFullPath(), 597 item_->GetFullPath(),
597 base::Bind(&CheckClientDownloadRequest::OnZipAnalysisFinished, 598 base::Bind(&CheckClientDownloadRequest::OnZipAnalysisFinished,
598 weakptr_factory_.GetWeakPtr())); 599 weakptr_factory_.GetWeakPtr()));
599 analyzer_->Start(); 600 analyzer_->Start();
600 } 601 }
601 602
602 void OnZipAnalysisFinished(const zip_analyzer::Results& results) { 603 void OnZipAnalysisFinished(const zip_analyzer::Results& results) {
603 DCHECK_CURRENTLY_ON(BrowserThread::UI); 604 DCHECK_CURRENTLY_ON(BrowserThread::UI);
605 DCHECK_EQ(ClientDownloadRequest::ZIPPED_EXECUTABLE, type_);
604 if (!service_) 606 if (!service_)
605 return; 607 return;
606 if (results.success) { 608 if (results.success) {
607 zipped_executable_ = results.has_executable; 609 zipped_executable_ = results.has_executable;
610 zipped_archive_ = results.has_archive;
608 archived_binary_.CopyFrom(results.archived_binary); 611 archived_binary_.CopyFrom(results.archived_binary);
609 DVLOG(1) << "Zip analysis finished for " << item_->GetFullPath().value() 612 DVLOG(1) << "Zip analysis finished for " << item_->GetFullPath().value()
610 << ", has_executable=" << results.has_executable 613 << ", has_executable=" << results.has_executable
611 << " has_archive=" << results.has_archive; 614 << " has_archive=" << results.has_archive;
612 } else { 615 } else {
613 DVLOG(1) << "Zip analysis failed for " << item_->GetFullPath().value(); 616 DVLOG(1) << "Zip analysis failed for " << item_->GetFullPath().value();
614 } 617 }
615 UMA_HISTOGRAM_BOOLEAN("SBClientDownload.ZipFileHasExecutable", 618 UMA_HISTOGRAM_BOOLEAN("SBClientDownload.ZipFileHasExecutable",
616 zipped_executable_); 619 zipped_executable_);
617 UMA_HISTOGRAM_BOOLEAN("SBClientDownload.ZipFileHasArchiveButNoExecutable", 620 UMA_HISTOGRAM_BOOLEAN("SBClientDownload.ZipFileHasArchiveButNoExecutable",
618 results.has_archive && !zipped_executable_); 621 zipped_archive_ && !zipped_executable_);
619 UMA_HISTOGRAM_TIMES("SBClientDownload.ExtractZipFeaturesTime", 622 UMA_HISTOGRAM_TIMES("SBClientDownload.ExtractZipFeaturesTime",
620 base::TimeTicks::Now() - zip_analysis_start_time_); 623 base::TimeTicks::Now() - zip_analysis_start_time_);
621 624
622 if (!zipped_executable_) { 625 if (!zipped_executable_ && !zipped_archive_) {
623 PostFinishTask(UNKNOWN, REASON_ARCHIVE_WITHOUT_BINARIES); 626 PostFinishTask(UNKNOWN, REASON_ARCHIVE_WITHOUT_BINARIES);
624 return; 627 return;
625 } 628 }
629 if (!zipped_executable_ && zipped_archive_)
630 type_ = ClientDownloadRequest::ZIPPED_ARCHIVE;
626 OnFileFeatureExtractionDone(); 631 OnFileFeatureExtractionDone();
627 } 632 }
628 633
629 static void RecordCountOfSignedOrWhitelistedDownload() { 634 static void RecordCountOfSignedOrWhitelistedDownload() {
630 UMA_HISTOGRAM_COUNTS("SBClientDownload.SignedOrWhitelistedDownload", 1); 635 UMA_HISTOGRAM_COUNTS("SBClientDownload.SignedOrWhitelistedDownload", 1);
631 } 636 }
632 637
633 void CheckWhitelists() { 638 void CheckWhitelists() {
634 DCHECK_CURRENTLY_ON(BrowserThread::IO); 639 DCHECK_CURRENTLY_ON(BrowserThread::IO);
635 640
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 } 779 }
775 } 780 }
776 781
777 request.set_user_initiated(item_->HasUserGesture()); 782 request.set_user_initiated(item_->HasUserGesture());
778 request.set_file_basename( 783 request.set_file_basename(
779 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe()); 784 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe());
780 request.set_download_type(type_); 785 request.set_download_type(type_);
781 request.mutable_signature()->CopyFrom(signature_info_); 786 request.mutable_signature()->CopyFrom(signature_info_);
782 if (image_headers_) 787 if (image_headers_)
783 request.set_allocated_image_headers(image_headers_.release()); 788 request.set_allocated_image_headers(image_headers_.release());
784 if (zipped_executable_) 789 if (zipped_executable_)
mattm 2015/07/29 22:53:25 should archived_binary be set for zipped_archive t
785 request.mutable_archived_binary()->Swap(&archived_binary_); 790 request.mutable_archived_binary()->Swap(&archived_binary_);
786 if (!request.SerializeToString(&client_download_request_data_)) { 791 if (!request.SerializeToString(&client_download_request_data_)) {
787 FinishRequest(UNKNOWN, REASON_INVALID_REQUEST_PROTO); 792 FinishRequest(UNKNOWN, REASON_INVALID_REQUEST_PROTO);
788 return; 793 return;
789 } 794 }
790 service_->client_download_request_callbacks_.Notify(item_, &request); 795 service_->client_download_request_callbacks_.Notify(item_, &request);
791 796
792 DVLOG(2) << "Sending a request for URL: " 797 DVLOG(2) << "Sending a request for URL: "
793 << item_->GetUrlChain().back(); 798 << item_->GetUrlChain().back();
794 fetcher_ = net::URLFetcher::Create(0 /* ID used for testing */, 799 fetcher_ = net::URLFetcher::Create(0 /* ID used for testing */,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 // Copies of data from |item_| for access on other threads. 910 // Copies of data from |item_| for access on other threads.
906 std::vector<GURL> url_chain_; 911 std::vector<GURL> url_chain_;
907 GURL referrer_url_; 912 GURL referrer_url_;
908 // URL chain of redirects leading to (but not including) |tab_url|. 913 // URL chain of redirects leading to (but not including) |tab_url|.
909 std::vector<GURL> tab_redirects_; 914 std::vector<GURL> tab_redirects_;
910 // URL and referrer of the window the download was started from. 915 // URL and referrer of the window the download was started from.
911 GURL tab_url_; 916 GURL tab_url_;
912 GURL tab_referrer_url_; 917 GURL tab_referrer_url_;
913 918
914 bool zipped_executable_; 919 bool zipped_executable_;
920 bool zipped_archive_;
915 ClientDownloadRequest_SignatureInfo signature_info_; 921 ClientDownloadRequest_SignatureInfo signature_info_;
916 scoped_ptr<ClientDownloadRequest_ImageHeaders> image_headers_; 922 scoped_ptr<ClientDownloadRequest_ImageHeaders> image_headers_;
917 google::protobuf::RepeatedPtrField<ClientDownloadRequest_ArchivedBinary> 923 google::protobuf::RepeatedPtrField<ClientDownloadRequest_ArchivedBinary>
918 archived_binary_; 924 archived_binary_;
919 CheckDownloadCallback callback_; 925 CheckDownloadCallback callback_;
920 // Will be NULL if the request has been canceled. 926 // Will be NULL if the request has been canceled.
921 DownloadProtectionService* service_; 927 DownloadProtectionService* service_;
922 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor_; 928 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor_;
923 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; 929 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_;
924 const bool pingback_enabled_; 930 const bool pingback_enabled_;
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 GURL DownloadProtectionService::GetDownloadRequestUrl() { 1142 GURL DownloadProtectionService::GetDownloadRequestUrl() {
1137 GURL url(kDownloadRequestUrl); 1143 GURL url(kDownloadRequestUrl);
1138 std::string api_key = google_apis::GetAPIKey(); 1144 std::string api_key = google_apis::GetAPIKey();
1139 if (!api_key.empty()) 1145 if (!api_key.empty())
1140 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); 1146 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true));
1141 1147
1142 return url; 1148 return url;
1143 } 1149 }
1144 1150
1145 } // namespace safe_browsing 1151 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698