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/binary_feature_extractor.h" | 18 #include "chrome/browser/safe_browsing/binary_feature_extractor.h" |
19 #include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_incid
ent.h" | 19 #include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_incid
ent.h" |
| 20 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h" |
20 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 21 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
21 #include "chrome/common/safe_browsing/csd.pb.h" | 22 #include "chrome/common/safe_browsing/csd.pb.h" |
22 | 23 |
23 namespace safe_browsing { | 24 namespace safe_browsing { |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 void RecordSignatureVerificationTime(size_t file_index, | 28 void RecordSignatureVerificationTime(size_t file_index, |
28 const base::TimeDelta& verification_time) { | 29 const base::TimeDelta& verification_time) { |
29 static const char kHistogramName[] = "SBIRS.VerifyBinaryIntegrity."; | 30 static const char kHistogramName[] = "SBIRS.VerifyBinaryIntegrity."; |
(...skipping 14 matching lines...) Expand all Loading... |
44 void RegisterBinaryIntegrityAnalysis() { | 45 void RegisterBinaryIntegrityAnalysis() { |
45 #if defined(OS_WIN) | 46 #if defined(OS_WIN) |
46 scoped_refptr<SafeBrowsingService> safe_browsing_service( | 47 scoped_refptr<SafeBrowsingService> safe_browsing_service( |
47 g_browser_process->safe_browsing_service()); | 48 g_browser_process->safe_browsing_service()); |
48 | 49 |
49 safe_browsing_service->RegisterDelayedAnalysisCallback( | 50 safe_browsing_service->RegisterDelayedAnalysisCallback( |
50 base::Bind(&VerifyBinaryIntegrity)); | 51 base::Bind(&VerifyBinaryIntegrity)); |
51 #endif | 52 #endif |
52 } | 53 } |
53 | 54 |
54 void VerifyBinaryIntegrity(const AddIncidentCallback& callback) { | 55 void VerifyBinaryIntegrity(scoped_ptr<IncidentReceiver> incident_receiver) { |
55 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor( | 56 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor( |
56 new BinaryFeatureExtractor()); | 57 new BinaryFeatureExtractor()); |
57 | 58 |
58 std::vector<base::FilePath> critical_binaries = GetCriticalBinariesPath(); | 59 std::vector<base::FilePath> critical_binaries = GetCriticalBinariesPath(); |
59 for (size_t i = 0; i < critical_binaries.size(); ++i) { | 60 for (size_t i = 0; i < critical_binaries.size(); ++i) { |
60 base::FilePath binary_path(critical_binaries[i]); | 61 base::FilePath binary_path(critical_binaries[i]); |
61 if (!base::PathExists(binary_path)) | 62 if (!base::PathExists(binary_path)) |
62 continue; | 63 continue; |
63 | 64 |
64 scoped_ptr<ClientDownloadRequest_SignatureInfo> signature_info( | 65 scoped_ptr<ClientDownloadRequest_SignatureInfo> signature_info( |
65 new ClientDownloadRequest_SignatureInfo()); | 66 new ClientDownloadRequest_SignatureInfo()); |
66 | 67 |
67 base::TimeTicks time_before = base::TimeTicks::Now(); | 68 base::TimeTicks time_before = base::TimeTicks::Now(); |
68 binary_feature_extractor->CheckSignature(binary_path, signature_info.get()); | 69 binary_feature_extractor->CheckSignature(binary_path, signature_info.get()); |
69 RecordSignatureVerificationTime(i, base::TimeTicks::Now() - time_before); | 70 RecordSignatureVerificationTime(i, base::TimeTicks::Now() - time_before); |
70 | 71 |
71 // Only create a report if the signature is untrusted. | 72 // Only create a report if the signature is untrusted. |
72 if (!signature_info->trusted()) { | 73 if (!signature_info->trusted()) { |
73 scoped_ptr<ClientIncidentReport_IncidentData_BinaryIntegrityIncident> | 74 scoped_ptr<ClientIncidentReport_IncidentData_BinaryIntegrityIncident> |
74 incident( | 75 incident( |
75 new ClientIncidentReport_IncidentData_BinaryIntegrityIncident()); | 76 new ClientIncidentReport_IncidentData_BinaryIntegrityIncident()); |
76 | 77 |
77 incident->set_file_basename(binary_path.BaseName().AsUTF8Unsafe()); | 78 incident->set_file_basename(binary_path.BaseName().AsUTF8Unsafe()); |
78 incident->set_allocated_signature(signature_info.release()); | 79 incident->set_allocated_signature(signature_info.release()); |
79 | 80 |
80 // Send the report. | 81 // Send the report. |
81 callback.Run(make_scoped_ptr( | 82 incident_receiver->AddIncidentForProcess( |
82 new BinaryIntegrityIncident(incident.Pass()))); | 83 make_scoped_ptr(new BinaryIntegrityIncident(incident.Pass()))); |
83 } | 84 } |
84 } | 85 } |
85 } | 86 } |
86 | 87 |
87 #if !defined(OS_WIN) | 88 #if !defined(OS_WIN) |
88 std::vector<base::FilePath> GetCriticalBinariesPath() { | 89 std::vector<base::FilePath> GetCriticalBinariesPath() { |
89 return std::vector<base::FilePath>(); | 90 return std::vector<base::FilePath>(); |
90 } | 91 } |
91 #endif // !defined(OS_WIN) | 92 #endif // !defined(OS_WIN) |
92 | 93 |
93 } // namespace safe_browsing | 94 } // namespace safe_browsing |
OLD | NEW |