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

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

Issue 2926473002: Mac Archive Type Sniffing (Closed)
Patch Set: addressing comments 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
Jialiu Lin 2017/06/09 20:24:18 You also need to add unittest in download_protecti
mortonm 2017/06/09 22:47:25 Ok, I have added the test. Currently I only check
477 // archive-type extension, then calls ExtractFileOrDmgFeatures() with
478 // result.
479 BrowserThread::PostTaskAndReplyWithResult(
480 BrowserThread::FILE, FROM_HERE,
481 base::Bind(MacArchiveTypeSniffer::IsAppleDiskImage,
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
802 StartExtractFileFeatures();
803 }
804
782 void OnDmgAnalysisFinished(const ArchiveAnalyzerResults& results) { 805 void OnDmgAnalysisFinished(const ArchiveAnalyzerResults& results) {
783 DCHECK_CURRENTLY_ON(BrowserThread::UI); 806 DCHECK_CURRENTLY_ON(BrowserThread::UI);
784 DCHECK_EQ(ClientDownloadRequest::MAC_EXECUTABLE, type_); 807 DCHECK_EQ(ClientDownloadRequest::MAC_EXECUTABLE, type_);
785 if (!service_) 808 if (!service_)
786 return; 809 return;
787 810
788 // Even if !results.success, some of the DMG may have been parsed. 811 // Even if !results.success, some of the DMG may have been parsed.
789 archive_is_valid_ = 812 archive_is_valid_ =
790 (results.success ? ArchiveValid::VALID : ArchiveValid::INVALID); 813 (results.success ? ArchiveValid::VALID : ArchiveValid::INVALID);
791 archived_executable_ = results.has_executable; 814 archived_executable_ = results.has_executable;
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1991 out_request->mutable_referrer_chain()); 2014 out_request->mutable_referrer_chain());
1992 UMA_HISTOGRAM_COUNTS_100( 2015 UMA_HISTOGRAM_COUNTS_100(
1993 "SafeBrowsing.ReferrerURLChainSize.PPAPIDownloadAttribution", 2016 "SafeBrowsing.ReferrerURLChainSize.PPAPIDownloadAttribution",
1994 out_request->referrer_chain_size()); 2017 out_request->referrer_chain_size());
1995 UMA_HISTOGRAM_ENUMERATION( 2018 UMA_HISTOGRAM_ENUMERATION(
1996 "SafeBrowsing.ReferrerAttributionResult.PPAPIDownloadAttribution", result, 2019 "SafeBrowsing.ReferrerAttributionResult.PPAPIDownloadAttribution", result,
1997 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); 2020 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX);
1998 } 2021 }
1999 2022
2000 } // namespace safe_browsing 2023 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/DEPS ('k') | chrome/browser/safe_browsing/mac_archive_type_sniffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698