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

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

Issue 2926473002: Mac Archive Type Sniffing (Closed)
Patch Set: simplified unit test since not parsing actual compressed data in DMGs Created 3 years, 6 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 #include "net/base/url_util.h" 67 #include "net/base/url_util.h"
68 #include "net/cert/x509_cert_types.h" 68 #include "net/cert/x509_cert_types.h"
69 #include "net/cert/x509_certificate.h" 69 #include "net/cert/x509_certificate.h"
70 #include "net/http/http_status_code.h" 70 #include "net/http/http_status_code.h"
71 #include "net/traffic_annotation/network_traffic_annotation.h" 71 #include "net/traffic_annotation/network_traffic_annotation.h"
72 #include "net/url_request/url_fetcher.h" 72 #include "net/url_request/url_fetcher.h"
73 #include "net/url_request/url_fetcher_delegate.h" 73 #include "net/url_request/url_fetcher_delegate.h"
74 #include "net/url_request/url_request_status.h" 74 #include "net/url_request/url_request_status.h"
75 75
76 #if defined(OS_MACOSX) 76 #if defined(OS_MACOSX)
77 #include "chrome/browser/safe_browsing/mac_archive_type_sniffer.h"
77 #include "chrome/browser/safe_browsing/sandboxed_dmg_analyzer_mac.h" 78 #include "chrome/browser/safe_browsing/sandboxed_dmg_analyzer_mac.h"
78 #endif 79 #endif
79 80
80 using content::BrowserThread; 81 using content::BrowserThread;
81 namespace safe_browsing { 82 namespace safe_browsing {
82 83
83 namespace { 84 namespace {
84 85
85 const int64_t kDownloadRequestTimeoutMs = 7000; 86 const int64_t kDownloadRequestTimeoutMs = 7000;
86 // We sample 1% of whitelisted downloads to still send out download pings. 87 // We sample 1% of whitelisted downloads to still send out download pings.
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 FILE_PATH_LITERAL(".sparsebundle")) || 465 FILE_PATH_LITERAL(".sparsebundle")) ||
465 item_->GetTargetFilePath().MatchesExtension( 466 item_->GetTargetFilePath().MatchesExtension(
466 FILE_PATH_LITERAL(".sparseimage")) || 467 FILE_PATH_LITERAL(".sparseimage")) ||
467 item_->GetTargetFilePath().MatchesExtension( 468 item_->GetTargetFilePath().MatchesExtension(
468 FILE_PATH_LITERAL(".toast")) || 469 FILE_PATH_LITERAL(".toast")) ||
469 item_->GetTargetFilePath().MatchesExtension( 470 item_->GetTargetFilePath().MatchesExtension(
470 FILE_PATH_LITERAL(".udif"))) { 471 FILE_PATH_LITERAL(".udif"))) {
471 StartExtractDmgFeatures(); 472 StartExtractDmgFeatures();
472 #endif 473 #endif
473 } else { 474 } else {
475 #if defined(OS_MACOSX)
476 // Checks for existence of "koly" signature even if file doesn't have
477 // archive-type extension, then calls ExtractFileOrDmgFeatures() with
478 // result.
479 BrowserThread::PostTaskAndReplyWithResult(
480 BrowserThread::FILE, FROM_HERE,
481 base::Bind(MacArchiveTypeSniffer::FileIsArchiveType,
482 item_->GetTargetFilePath()),
483 base::Bind(&CheckClientDownloadRequest::ExtractFileOrDmgFeatures,
484 this));
485 #else
474 StartExtractFileFeatures(); 486 StartExtractFileFeatures();
487 #endif
475 } 488 }
476 } 489 }
477 490
478 // Start a timeout to cancel the request if it takes too long. 491 // Start a timeout to cancel the request if it takes too long.
479 // This should only be called after we have finished accessing the file. 492 // This should only be called after we have finished accessing the file.
480 void StartTimeout() { 493 void StartTimeout() {
481 DCHECK_CURRENTLY_ON(BrowserThread::UI); 494 DCHECK_CURRENTLY_ON(BrowserThread::UI);
482 if (!service_) { 495 if (!service_) {
483 // Request has already been cancelled. 496 // Request has already been cancelled.
484 return; 497 return;
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 DCHECK_CURRENTLY_ON(BrowserThread::UI); 785 DCHECK_CURRENTLY_ON(BrowserThread::UI);
773 DCHECK(item_); 786 DCHECK(item_);
774 dmg_analyzer_ = new SandboxedDMGAnalyzer( 787 dmg_analyzer_ = new SandboxedDMGAnalyzer(
775 item_->GetFullPath(), 788 item_->GetFullPath(),
776 base::Bind(&CheckClientDownloadRequest::OnDmgAnalysisFinished, 789 base::Bind(&CheckClientDownloadRequest::OnDmgAnalysisFinished,
777 weakptr_factory_.GetWeakPtr())); 790 weakptr_factory_.GetWeakPtr()));
778 dmg_analyzer_->Start(); 791 dmg_analyzer_->Start();
779 dmg_analysis_start_time_ = base::TimeTicks::Now(); 792 dmg_analysis_start_time_ = base::TimeTicks::Now();
780 } 793 }
781 794
795 // Extracts DMG features if file has 'koly' signature, otherwise extracts
796 // regular file features.
797 void ExtractFileOrDmgFeatures(bool download_file_has_koly_signature) {
798 DCHECK_CURRENTLY_ON(BrowserThread::UI);
799 if (download_file_has_koly_signature) {
800 StartExtractDmgFeatures();
801 } else {
Jialiu Lin 2017/06/09 18:48:49 nit: curly braces are not required for single-line
mortonm 2017/06/09 19:47:20 Done.
802 StartExtractFileFeatures();
803 }
804 }
805
782 void OnDmgAnalysisFinished(const ArchiveAnalyzerResults& results) { 806 void OnDmgAnalysisFinished(const ArchiveAnalyzerResults& results) {
783 DCHECK_CURRENTLY_ON(BrowserThread::UI); 807 DCHECK_CURRENTLY_ON(BrowserThread::UI);
784 DCHECK_EQ(ClientDownloadRequest::MAC_EXECUTABLE, type_); 808 DCHECK_EQ(ClientDownloadRequest::MAC_EXECUTABLE, type_);
785 if (!service_) 809 if (!service_)
786 return; 810 return;
787 811
788 // Even if !results.success, some of the DMG may have been parsed. 812 // Even if !results.success, some of the DMG may have been parsed.
789 archive_is_valid_ = 813 archive_is_valid_ =
790 (results.success ? ArchiveValid::VALID : ArchiveValid::INVALID); 814 (results.success ? ArchiveValid::VALID : ArchiveValid::INVALID);
791 archived_executable_ = results.has_executable; 815 archived_executable_ = results.has_executable;
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1991 out_request->mutable_referrer_chain()); 2015 out_request->mutable_referrer_chain());
1992 UMA_HISTOGRAM_COUNTS_100( 2016 UMA_HISTOGRAM_COUNTS_100(
1993 "SafeBrowsing.ReferrerURLChainSize.PPAPIDownloadAttribution", 2017 "SafeBrowsing.ReferrerURLChainSize.PPAPIDownloadAttribution",
1994 out_request->referrer_chain_size()); 2018 out_request->referrer_chain_size());
1995 UMA_HISTOGRAM_ENUMERATION( 2019 UMA_HISTOGRAM_ENUMERATION(
1996 "SafeBrowsing.ReferrerAttributionResult.PPAPIDownloadAttribution", result, 2020 "SafeBrowsing.ReferrerAttributionResult.PPAPIDownloadAttribution", result,
1997 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); 2021 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX);
1998 } 2022 }
1999 2023
2000 } // namespace safe_browsing 2024 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698