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_win.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_incid
ent.h" |
| 12 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h" |
10 #include "chrome/common/chrome_version.h" | 13 #include "chrome/common/chrome_version.h" |
| 14 #include "chrome/common/safe_browsing/binary_feature_extractor.h" |
| 15 #include "chrome/common/safe_browsing/csd.pb.h" |
11 | 16 |
12 namespace safe_browsing { | 17 namespace safe_browsing { |
13 | 18 |
14 std::vector<base::FilePath> GetCriticalBinariesPath() { | 19 std::vector<base::FilePath> GetCriticalBinariesPath() { |
15 static const base::FilePath::CharType* const kUnversionedFiles[] = { | 20 static const base::FilePath::CharType* const kUnversionedFiles[] = { |
16 FILE_PATH_LITERAL("chrome.exe"), | 21 FILE_PATH_LITERAL("chrome.exe"), |
17 }; | 22 }; |
18 static const base::FilePath::CharType* const kVersionedFiles[] = { | 23 static const base::FilePath::CharType* const kVersionedFiles[] = { |
19 FILE_PATH_LITERAL("chrome.dll"), | 24 FILE_PATH_LITERAL("chrome.dll"), |
20 FILE_PATH_LITERAL("chrome_child.dll"), | 25 FILE_PATH_LITERAL("chrome_child.dll"), |
(...skipping 15 matching lines...) Expand all Loading... |
36 | 41 |
37 base::FilePath version_dir( | 42 base::FilePath version_dir( |
38 chrome_exe_dir.AppendASCII(CHROME_VERSION_STRING)); | 43 chrome_exe_dir.AppendASCII(CHROME_VERSION_STRING)); |
39 for (size_t i = 0; i < arraysize(kVersionedFiles); ++i) { | 44 for (size_t i = 0; i < arraysize(kVersionedFiles); ++i) { |
40 critical_binaries.push_back(version_dir.Append(kVersionedFiles[i])); | 45 critical_binaries.push_back(version_dir.Append(kVersionedFiles[i])); |
41 } | 46 } |
42 | 47 |
43 return critical_binaries; | 48 return critical_binaries; |
44 } | 49 } |
45 | 50 |
| 51 void VerifyBinaryIntegrity(scoped_ptr<IncidentReceiver> incident_receiver) { |
| 52 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor( |
| 53 new BinaryFeatureExtractor()); |
| 54 |
| 55 std::vector<base::FilePath> critical_binaries = GetCriticalBinariesPath(); |
| 56 for (size_t i = 0; i < critical_binaries.size(); ++i) { |
| 57 base::FilePath binary_path(critical_binaries[i]); |
| 58 if (!base::PathExists(binary_path)) |
| 59 continue; |
| 60 |
| 61 scoped_ptr<ClientDownloadRequest_SignatureInfo> signature_info( |
| 62 new ClientDownloadRequest_SignatureInfo()); |
| 63 |
| 64 base::TimeTicks time_before = base::TimeTicks::Now(); |
| 65 binary_feature_extractor->CheckSignature(binary_path, signature_info.get()); |
| 66 RecordSignatureVerificationTime(i, base::TimeTicks::Now() - time_before); |
| 67 |
| 68 // Only create a report if the signature is untrusted. |
| 69 if (!signature_info->trusted()) { |
| 70 scoped_ptr<ClientIncidentReport_IncidentData_BinaryIntegrityIncident> |
| 71 incident( |
| 72 new ClientIncidentReport_IncidentData_BinaryIntegrityIncident()); |
| 73 |
| 74 incident->set_file_basename(binary_path.BaseName().AsUTF8Unsafe()); |
| 75 incident->set_allocated_signature(signature_info.release()); |
| 76 |
| 77 // Send the report. |
| 78 incident_receiver->AddIncidentForProcess( |
| 79 make_scoped_ptr(new BinaryIntegrityIncident(incident.Pass()))); |
| 80 } else { |
| 81 // The binary is integral, remove previous report so that next incidents |
| 82 // for the binary will be reported. |
| 83 ClearBinaryIntegrityForFile(incident_receiver.get(), |
| 84 binary_path.BaseName().AsUTF8Unsafe()); |
| 85 } |
| 86 } |
| 87 } |
| 88 |
46 } // namespace safe_browsing | 89 } // namespace safe_browsing |
OLD | NEW |