| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/signature_evaluator_mac.h" | 5 #include "chrome/browser/safe_browsing/signature_evaluator_mac.h" |
| 6 | 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <sys/xattr.h> | 10 #include <sys/xattr.h> |
| 11 | 11 |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
| 17 #include "base/files/scoped_temp_dir.h" | 17 #include "base/files/scoped_temp_dir.h" |
| 18 #include "base/mac/mac_util.h" | |
| 19 #include "base/mac/scoped_cftyperef.h" | 18 #include "base/mac/scoped_cftyperef.h" |
| 20 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 21 #include "base/strings/sys_string_conversions.h" | 20 #include "base/strings/sys_string_conversions.h" |
| 22 #include "base/test/scoped_path_override.h" | 21 #include "base/test/scoped_path_override.h" |
| 23 #include "chrome/browser/safe_browsing/incident_reporting/incident.h" | 22 #include "chrome/browser/safe_browsing/incident_reporting/incident.h" |
| 24 #include "chrome/browser/safe_browsing/incident_reporting/mock_incident_receiver
.h" | 23 #include "chrome/browser/safe_browsing/incident_reporting/mock_incident_receiver
.h" |
| 25 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/safe_browsing/csd.pb.h" | 25 #include "chrome/common/safe_browsing/csd.pb.h" |
| 27 #include "testing/gmock/include/gmock/gmock-matchers.h" | 26 #include "testing/gmock/include/gmock/gmock-matchers.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 ASSERT_EQ(1, incident.contained_file_size()); | 168 ASSERT_EQ(1, incident.contained_file_size()); |
| 170 | 169 |
| 171 const ClientIncidentReport_IncidentData_BinaryIntegrityIncident_ContainedFile& | 170 const ClientIncidentReport_IncidentData_BinaryIntegrityIncident_ContainedFile& |
| 172 contained_file = incident.contained_file(0); | 171 contained_file = incident.contained_file(0); |
| 173 EXPECT_EQ(contained_file.relative_path(), "Contents/MacOS/test-bundle"); | 172 EXPECT_EQ(contained_file.relative_path(), "Contents/MacOS/test-bundle"); |
| 174 EXPECT_TRUE(contained_file.has_signature()); | 173 EXPECT_TRUE(contained_file.has_signature()); |
| 175 EXPECT_TRUE(contained_file.has_image_headers()); | 174 EXPECT_TRUE(contained_file.has_image_headers()); |
| 176 } | 175 } |
| 177 | 176 |
| 178 TEST_F(MacSignatureEvaluatorTest, ModifiedMainExecTest64) { | 177 TEST_F(MacSignatureEvaluatorTest, ModifiedMainExecTest64) { |
| 179 // Snow Leopard does not know about the 64-bit slice so this test is | |
| 180 // irrelevant. | |
| 181 if (!base::mac::IsOSLionOrLater()) | |
| 182 return; | |
| 183 | |
| 184 // Now to a test modified, signed bundle. | 178 // Now to a test modified, signed bundle. |
| 185 base::FilePath path = testdata_path_.AppendASCII("modified-main-exec64.app"); | 179 base::FilePath path = testdata_path_.AppendASCII("modified-main-exec64.app"); |
| 186 | 180 |
| 187 std::string requirement( | 181 std::string requirement( |
| 188 "certificate leaf[subject.CN]=\"untrusted@goat.local\""); | 182 "certificate leaf[subject.CN]=\"untrusted@goat.local\""); |
| 189 MacSignatureEvaluator evaluator(path, requirement); | 183 MacSignatureEvaluator evaluator(path, requirement); |
| 190 ASSERT_TRUE(evaluator.Initialize()); | 184 ASSERT_TRUE(evaluator.Initialize()); |
| 191 | 185 |
| 192 ClientIncidentReport_IncidentData_BinaryIntegrityIncident incident; | 186 ClientIncidentReport_IncidentData_BinaryIntegrityIncident incident; |
| 193 EXPECT_FALSE(evaluator.PerformEvaluation(&incident)); | 187 EXPECT_FALSE(evaluator.PerformEvaluation(&incident)); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 std::vector<std::string> xattrs_seen; | 328 std::vector<std::string> xattrs_seen; |
| 335 for (const auto& xattr : mainmenunib->signature().xattr()) { | 329 for (const auto& xattr : mainmenunib->signature().xattr()) { |
| 336 ASSERT_TRUE(xattr.has_key()); | 330 ASSERT_TRUE(xattr.has_key()); |
| 337 EXPECT_TRUE(xattr.has_value()); | 331 EXPECT_TRUE(xattr.has_value()); |
| 338 xattrs_seen.push_back(xattr.key()); | 332 xattrs_seen.push_back(xattr.key()); |
| 339 } | 333 } |
| 340 EXPECT_THAT(xattrs_known, ::testing::ContainerEq(xattrs_seen)); | 334 EXPECT_THAT(xattrs_known, ::testing::ContainerEq(xattrs_seen)); |
| 341 } | 335 } |
| 342 | 336 |
| 343 } // namespace safe_browsing | 337 } // namespace safe_browsing |
| OLD | NEW |