| 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/common/safe_browsing/binary_feature_extractor.h" | 5 #include "chrome/common/safe_browsing/binary_feature_extractor.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 ParseCertificateChain(signature_info.certificate_chain(0), &certs); | 58 ParseCertificateChain(signature_info.certificate_chain(0), &certs); |
| 59 ASSERT_EQ(2u, certs.size()); | 59 ASSERT_EQ(2u, certs.size()); |
| 60 EXPECT_EQ("Joe's-Software-Emporium", certs[0]->subject().common_name); | 60 EXPECT_EQ("Joe's-Software-Emporium", certs[0]->subject().common_name); |
| 61 EXPECT_EQ("Root Agency", certs[1]->subject().common_name); | 61 EXPECT_EQ("Root Agency", certs[1]->subject().common_name); |
| 62 | 62 |
| 63 EXPECT_TRUE(signature_info.has_trusted()); | 63 EXPECT_TRUE(signature_info.has_trusted()); |
| 64 EXPECT_FALSE(signature_info.trusted()); | 64 EXPECT_FALSE(signature_info.trusted()); |
| 65 } | 65 } |
| 66 | 66 |
| 67 TEST_F(BinaryFeatureExtractorWinTest, TrustedBinary) { | 67 TEST_F(BinaryFeatureExtractorWinTest, TrustedBinary) { |
| 68 // wow_helper.exe is signed using Google's signing certifiacte. | 68 // disable_outdated_build_detector.exe is dual signed using Google's signing |
| 69 // certifiacte. |
| 69 ClientDownloadRequest_SignatureInfo signature_info; | 70 ClientDownloadRequest_SignatureInfo signature_info; |
| 70 binary_feature_extractor_->CheckSignature( | 71 binary_feature_extractor_->CheckSignature( |
| 71 testdata_path_.Append(L"wow_helper.exe"), | 72 testdata_path_.Append(L"disable_outdated_build_detector.exe"), |
| 72 &signature_info); | 73 &signature_info); |
| 73 ASSERT_EQ(1, signature_info.certificate_chain_size()); | 74 ASSERT_EQ(1, signature_info.certificate_chain_size()); |
| 74 std::vector<scoped_refptr<net::X509Certificate> > certs; | 75 std::vector<scoped_refptr<net::X509Certificate> > certs; |
| 75 ParseCertificateChain(signature_info.certificate_chain(0), &certs); | 76 ParseCertificateChain(signature_info.certificate_chain(0), &certs); |
| 76 ASSERT_EQ(3u, certs.size()); | 77 ASSERT_EQ(3u, certs.size()); |
| 77 | 78 |
| 78 EXPECT_EQ("Google Inc", certs[0]->subject().common_name); | 79 EXPECT_EQ("Google Inc", certs[0]->subject().common_name); |
| 79 EXPECT_EQ("VeriSign Class 3 Code Signing 2009-2 CA", | 80 EXPECT_EQ("VeriSign Class 3 Code Signing 2010 CA", |
| 80 certs[1]->subject().common_name); | 81 certs[1]->subject().common_name); |
| 81 EXPECT_EQ("Class 3 Public Primary Certification Authority", | 82 EXPECT_EQ("VeriSign Trust Network", |
| 82 certs[2]->subject().organization_unit_names[0]); | 83 certs[2]->subject().organization_unit_names[0]); |
| 83 | 84 |
| 84 EXPECT_TRUE(signature_info.trusted()); | 85 EXPECT_TRUE(signature_info.trusted()); |
| 85 } | 86 } |
| 86 | 87 |
| 87 TEST_F(BinaryFeatureExtractorWinTest, UnsignedBinary) { | 88 TEST_F(BinaryFeatureExtractorWinTest, UnsignedBinary) { |
| 88 // unsigned.exe has no signature information. | 89 // unsigned.exe has no signature information. |
| 89 ClientDownloadRequest_SignatureInfo signature_info; | 90 ClientDownloadRequest_SignatureInfo signature_info; |
| 90 binary_feature_extractor_->CheckSignature( | 91 binary_feature_extractor_->CheckSignature( |
| 91 testdata_path_.Append(L"unsigned.exe"), | 92 testdata_path_.Append(L"unsigned.exe"), |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 BinaryFeatureExtractor::kDefaultOptions, &image_headers, &signed_data)); | 192 BinaryFeatureExtractor::kDefaultOptions, &image_headers, &signed_data)); |
| 192 ASSERT_EQ(1, signed_data.size()); | 193 ASSERT_EQ(1, signed_data.size()); |
| 193 ASSERT_LT(0U, signed_data.Get(0).size()); | 194 ASSERT_LT(0U, signed_data.Get(0).size()); |
| 194 } | 195 } |
| 195 | 196 |
| 196 TEST_F(BinaryFeatureExtractorWinTest, ExtractImageFeaturesTrustedSigned) { | 197 TEST_F(BinaryFeatureExtractorWinTest, ExtractImageFeaturesTrustedSigned) { |
| 197 // Test extracting features from a signed PE image from a trusted root. | 198 // Test extracting features from a signed PE image from a trusted root. |
| 198 ClientDownloadRequest_ImageHeaders image_headers; | 199 ClientDownloadRequest_ImageHeaders image_headers; |
| 199 google::protobuf::RepeatedPtrField<std::string> signed_data; | 200 google::protobuf::RepeatedPtrField<std::string> signed_data; |
| 200 ASSERT_TRUE(binary_feature_extractor_->ExtractImageFeatures( | 201 ASSERT_TRUE(binary_feature_extractor_->ExtractImageFeatures( |
| 201 testdata_path_.AppendASCII("wow_helper.exe"), | 202 testdata_path_.AppendASCII("disable_outdated_build_detector.exe"), |
| 202 BinaryFeatureExtractor::kDefaultOptions, &image_headers, &signed_data)); | 203 BinaryFeatureExtractor::kDefaultOptions, &image_headers, &signed_data)); |
| 203 ASSERT_EQ(1, signed_data.size()); | 204 ASSERT_EQ(1, signed_data.size()); |
| 204 ASSERT_LT(0U, signed_data.Get(0).size()); | 205 ASSERT_LT(0U, signed_data.Get(0).size()); |
| 205 } | 206 } |
| 206 | 207 |
| 207 } // namespace safe_browsing | 208 } // namespace safe_browsing |
| OLD | NEW |