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

Side by Side Diff: chrome/browser/safe_browsing/incident_reporting/binary_integrity_analyzer.cc

Issue 1363613004: Implement anonymous, opt-in, collection of OS X binary integrity incidents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/incident_reporting/binary_integrity_analy zer.h" 5 #include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_analy zer.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_incid ent.h" 18 #include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_incid ent.h"
19 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h" 19 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h"
20 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 20 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
21 #include "chrome/common/safe_browsing/binary_feature_extractor.h" 21 #include "chrome/common/safe_browsing/binary_feature_extractor.h"
22 #include "chrome/common/safe_browsing/csd.pb.h" 22 #include "chrome/common/safe_browsing/csd.pb.h"
23 23
24 namespace safe_browsing { 24 namespace safe_browsing {
25 25
26 namespace {
27
28 void RecordSignatureVerificationTime(size_t file_index, 26 void RecordSignatureVerificationTime(size_t file_index,
29 const base::TimeDelta& verification_time) { 27 const base::TimeDelta& verification_time) {
30 static const char kHistogramName[] = "SBIRS.VerifyBinaryIntegrity."; 28 static const char kHistogramName[] = "SBIRS.VerifyBinaryIntegrity.";
31 29
32 base::HistogramBase* signature_verification_time_histogram = 30 base::HistogramBase* signature_verification_time_histogram =
33 base::Histogram::FactoryTimeGet( 31 base::Histogram::FactoryTimeGet(
34 std::string(kHistogramName) + base::SizeTToString(file_index), 32 std::string(kHistogramName) + base::SizeTToString(file_index),
35 base::TimeDelta::FromMilliseconds(1), 33 base::TimeDelta::FromMilliseconds(1),
36 base::TimeDelta::FromSeconds(20), 34 base::TimeDelta::FromSeconds(20), 50,
37 50,
38 base::Histogram::kUmaTargetedHistogramFlag); 35 base::Histogram::kUmaTargetedHistogramFlag);
39 36
40 signature_verification_time_histogram->AddTime(verification_time); 37 signature_verification_time_histogram->AddTime(verification_time);
41 } 38 }
42 39
43 } // namespace
44
45 void RegisterBinaryIntegrityAnalysis() { 40 void RegisterBinaryIntegrityAnalysis() {
46 #if defined(OS_WIN) 41 #if defined(OS_WIN) || defined(OS_MACOSX)
47 scoped_refptr<SafeBrowsingService> safe_browsing_service( 42 scoped_refptr<SafeBrowsingService> safe_browsing_service(
48 g_browser_process->safe_browsing_service()); 43 g_browser_process->safe_browsing_service());
49 44
50 safe_browsing_service->RegisterDelayedAnalysisCallback( 45 safe_browsing_service->RegisterDelayedAnalysisCallback(
51 base::Bind(&VerifyBinaryIntegrity)); 46 base::Bind(&VerifyBinaryIntegrity));
52 #endif 47 #endif
53 } 48 }
54 49
50 #if !defined(OS_MACOSX)
55 void VerifyBinaryIntegrity(scoped_ptr<IncidentReceiver> incident_receiver) { 51 void VerifyBinaryIntegrity(scoped_ptr<IncidentReceiver> incident_receiver) {
56 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor( 52 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor(
57 new BinaryFeatureExtractor()); 53 new BinaryFeatureExtractor());
58 54
59 std::vector<base::FilePath> critical_binaries = GetCriticalBinariesPath(); 55 std::vector<base::FilePath> critical_binaries = GetCriticalBinariesPath();
60 for (size_t i = 0; i < critical_binaries.size(); ++i) { 56 for (size_t i = 0; i < critical_binaries.size(); ++i) {
61 base::FilePath binary_path(critical_binaries[i]); 57 base::FilePath binary_path(critical_binaries[i]);
62 if (!base::PathExists(binary_path)) 58 if (!base::PathExists(binary_path))
63 continue; 59 continue;
64 60
(...skipping 16 matching lines...) Expand all
81 // Send the report. 77 // Send the report.
82 incident_receiver->AddIncidentForProcess( 78 incident_receiver->AddIncidentForProcess(
83 make_scoped_ptr(new BinaryIntegrityIncident(incident.Pass()))); 79 make_scoped_ptr(new BinaryIntegrityIncident(incident.Pass())));
84 } else { 80 } else {
85 // The binary is integral, remove previous report so that next incidents 81 // The binary is integral, remove previous report so that next incidents
86 // for the binary will be reported. 82 // for the binary will be reported.
87 scoped_ptr<ClientIncidentReport_IncidentData_BinaryIntegrityIncident> 83 scoped_ptr<ClientIncidentReport_IncidentData_BinaryIntegrityIncident>
88 incident( 84 incident(
89 new ClientIncidentReport_IncidentData_BinaryIntegrityIncident()); 85 new ClientIncidentReport_IncidentData_BinaryIntegrityIncident());
90 incident->set_file_basename(binary_path.BaseName().AsUTF8Unsafe()); 86 incident->set_file_basename(binary_path.BaseName().AsUTF8Unsafe());
91 incident_receiver->ClearIncidentForProcess( 87 incident_receiver->ClearIncidentForProcess(
mattm 2015/10/21 02:06:34 This doesn't appear in the mac version. Should it?
Greg K 2015/10/27 01:06:18 I talked to some of the safe browsing engineers, a
92 make_scoped_ptr(new BinaryIntegrityIncident(incident.Pass()))); 88 make_scoped_ptr(new BinaryIntegrityIncident(incident.Pass())));
93 } 89 }
94 } 90 }
95 } 91 }
92 #endif // !defined(OS_MACOSX)
96 93
97 #if !defined(OS_WIN) 94 #if !defined(OS_WIN)
98 std::vector<base::FilePath> GetCriticalBinariesPath() { 95 std::vector<base::FilePath> GetCriticalBinariesPath() {
99 return std::vector<base::FilePath>(); 96 return std::vector<base::FilePath>();
100 } 97 }
101 #endif // !defined(OS_WIN) 98 #endif // !defined(OS_WIN)
102 99
103 } // namespace safe_browsing 100 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698