OLD | NEW |
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 12 matching lines...) Expand all Loading... |
77 | 73 |
78 incident->set_file_basename(binary_path.BaseName().AsUTF8Unsafe()); | 74 incident->set_file_basename(binary_path.BaseName().AsUTF8Unsafe()); |
79 incident->set_allocated_signature(signature_info.release()); | 75 incident->set_allocated_signature(signature_info.release()); |
80 | 76 |
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 } | 80 } |
85 } | 81 } |
86 } | 82 } |
| 83 #endif // !defined(OS_MACOSX) |
87 | 84 |
88 #if !defined(OS_WIN) | 85 #if !defined(OS_WIN) |
89 std::vector<base::FilePath> GetCriticalBinariesPath() { | 86 std::vector<base::FilePath> GetCriticalBinariesPath() { |
90 return std::vector<base::FilePath>(); | 87 return std::vector<base::FilePath>(); |
91 } | 88 } |
92 #endif // !defined(OS_WIN) | 89 #endif // !defined(OS_WIN) |
93 | 90 |
94 } // namespace safe_browsing | 91 } // namespace safe_browsing |
OLD | NEW |