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/sandboxed_zip_analyzer.h" | 5 #include "chrome/browser/safe_browsing/sandboxed_zip_analyzer.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 EXPECT_TRUE(binary.image_headers().pe_headers().has_optional_headers32()); | 110 EXPECT_TRUE(binary.image_headers().pe_headers().has_optional_headers32()); |
111 EXPECT_FALSE(binary.image_headers().pe_headers().has_optional_headers64()); | 111 EXPECT_FALSE(binary.image_headers().pe_headers().has_optional_headers64()); |
112 #else // OS_WIN | 112 #else // OS_WIN |
113 ASSERT_FALSE(binary.has_signature()); | 113 ASSERT_FALSE(binary.has_signature()); |
114 ASSERT_FALSE(binary.has_image_headers()); | 114 ASSERT_FALSE(binary.has_image_headers()); |
115 #endif // !OS_WIN | 115 #endif // !OS_WIN |
116 } | 116 } |
117 | 117 |
118 static const uint8_t kUnsignedDigest[]; | 118 static const uint8_t kUnsignedDigest[]; |
119 static const uint8_t kSignedDigest[]; | 119 static const uint8_t kSignedDigest[]; |
| 120 static const uint8_t kJSEFileDigest[]; |
120 static const BinaryData kUnsignedExe; | 121 static const BinaryData kUnsignedExe; |
121 static const BinaryData kSignedExe; | 122 static const BinaryData kSignedExe; |
| 123 static const BinaryData kJSEFile; |
122 | 124 |
123 base::FilePath dir_test_data_; | 125 base::FilePath dir_test_data_; |
124 content::TestBrowserThreadBundle browser_thread_bundle_; | 126 content::TestBrowserThreadBundle browser_thread_bundle_; |
125 content::InProcessUtilityThreadHelper utility_thread_helper_; | 127 content::InProcessUtilityThreadHelper utility_thread_helper_; |
126 }; | 128 }; |
127 | 129 |
128 // static | 130 // static |
129 const uint8_t SandboxedZipAnalyzerTest::kUnsignedDigest[] = { | 131 const uint8_t SandboxedZipAnalyzerTest::kUnsignedDigest[] = { |
130 0x1e, 0x95, 0x4d, 0x9c, 0xe0, 0x38, 0x9e, 0x2b, 0xa7, 0x44, 0x72, 0x16, | 132 0x1e, 0x95, 0x4d, 0x9c, 0xe0, 0x38, 0x9e, 0x2b, 0xa7, 0x44, 0x72, |
131 0xf2, 0x17, 0x61, 0xf9, 0x8d, 0x1e, 0x65, 0x40, 0xc2, 0xab, 0xec, 0xdb, | 133 0x16, 0xf2, 0x17, 0x61, 0xf9, 0x8d, 0x1e, 0x65, 0x40, 0xc2, 0xab, |
132 0xec, 0xff, 0x57, 0x0e, 0x36, 0xc4, 0x93, 0xdb | 134 0xec, 0xdb, 0xec, 0xff, 0x57, 0x0e, 0x36, 0xc4, 0x93, 0xdb}; |
133 }; | |
134 const uint8_t SandboxedZipAnalyzerTest::kSignedDigest[] = { | 135 const uint8_t SandboxedZipAnalyzerTest::kSignedDigest[] = { |
135 0xe1, 0x1f, 0xfa, 0x0c, 0x9f, 0x25, 0x23, 0x44, 0x53, 0xa9, 0xed, 0xd1, | 136 0xe1, 0x1f, 0xfa, 0x0c, 0x9f, 0x25, 0x23, 0x44, 0x53, 0xa9, 0xed, |
136 0xcb, 0x25, 0x1d, 0x46, 0x10, 0x7f, 0x34, 0xb5, 0x36, 0xad, 0x74, 0x64, | 137 0xd1, 0xcb, 0x25, 0x1d, 0x46, 0x10, 0x7f, 0x34, 0xb5, 0x36, 0xad, |
137 0x2a, 0x85, 0x84, 0xac, 0xa8, 0xc1, 0xa8, 0xce | 138 0x74, 0x64, 0x2a, 0x85, 0x84, 0xac, 0xa8, 0xc1, 0xa8, 0xce}; |
138 }; | 139 const uint8_t SandboxedZipAnalyzerTest::kJSEFileDigest[] = { |
| 140 0x58, 0x91, 0xb5, 0xb5, 0x22, 0xd5, 0xdf, 0x08, 0x6d, 0x0f, 0xf0, |
| 141 0xb1, 0x10, 0xfb, 0xd9, 0xd2, 0x1b, 0xb4, 0xfc, 0x71, 0x63, 0xaf, |
| 142 0x34, 0xd0, 0x82, 0x86, 0xa2, 0xe8, 0x46, 0xf6, 0xbe, 0x03}; |
139 const SandboxedZipAnalyzerTest::BinaryData | 143 const SandboxedZipAnalyzerTest::BinaryData |
140 SandboxedZipAnalyzerTest::kUnsignedExe = { | 144 SandboxedZipAnalyzerTest::kUnsignedExe = { |
141 "unsigned.exe", | 145 "unsigned.exe", |
142 ClientDownloadRequest_DownloadType_WIN_EXECUTABLE, | 146 ClientDownloadRequest_DownloadType_WIN_EXECUTABLE, |
143 &kUnsignedDigest[0], | 147 &kUnsignedDigest[0], |
144 36864, | 148 36864, |
145 false, // !is_signed | 149 false, // !is_signed |
146 }; | 150 }; |
147 const SandboxedZipAnalyzerTest::BinaryData | 151 const SandboxedZipAnalyzerTest::BinaryData |
148 SandboxedZipAnalyzerTest::kSignedExe = { | 152 SandboxedZipAnalyzerTest::kSignedExe = { |
149 "signed.exe", | 153 "signed.exe", |
150 ClientDownloadRequest_DownloadType_WIN_EXECUTABLE, | 154 ClientDownloadRequest_DownloadType_WIN_EXECUTABLE, |
151 &kSignedDigest[0], | 155 &kSignedDigest[0], |
152 37768, | 156 37768, |
153 true, // is_signed | 157 true, // is_signed |
154 }; | 158 }; |
155 | 159 |
| 160 const SandboxedZipAnalyzerTest::BinaryData |
| 161 SandboxedZipAnalyzerTest::kJSEFile = { |
| 162 "hello.jse", |
| 163 ClientDownloadRequest_DownloadType_WIN_EXECUTABLE, |
| 164 &kJSEFileDigest[0], |
| 165 6, |
| 166 false, // is_signed |
| 167 }; |
| 168 |
156 TEST_F(SandboxedZipAnalyzerTest, NoBinaries) { | 169 TEST_F(SandboxedZipAnalyzerTest, NoBinaries) { |
157 zip_analyzer::Results results; | 170 zip_analyzer::Results results; |
158 RunAnalyzer(dir_test_data_.AppendASCII("zipfile_no_binaries.zip"), &results); | 171 RunAnalyzer(dir_test_data_.AppendASCII("zipfile_no_binaries.zip"), &results); |
159 ASSERT_TRUE(results.success); | 172 ASSERT_TRUE(results.success); |
160 EXPECT_FALSE(results.has_executable); | 173 EXPECT_FALSE(results.has_executable); |
161 EXPECT_FALSE(results.has_archive); | 174 EXPECT_FALSE(results.has_archive); |
162 EXPECT_EQ(0, results.archived_binary.size()); | 175 EXPECT_EQ(0, results.archived_binary.size()); |
163 } | 176 } |
164 | 177 |
165 TEST_F(SandboxedZipAnalyzerTest, OneUnsignedBinary) { | 178 TEST_F(SandboxedZipAnalyzerTest, OneUnsignedBinary) { |
(...skipping 12 matching lines...) Expand all Loading... |
178 RunAnalyzer(dir_test_data_.AppendASCII("zipfile_two_binaries_one_signed.zip"), | 191 RunAnalyzer(dir_test_data_.AppendASCII("zipfile_two_binaries_one_signed.zip"), |
179 &results); | 192 &results); |
180 ASSERT_TRUE(results.success); | 193 ASSERT_TRUE(results.success); |
181 EXPECT_TRUE(results.has_executable); | 194 EXPECT_TRUE(results.has_executable); |
182 EXPECT_FALSE(results.has_archive); | 195 EXPECT_FALSE(results.has_archive); |
183 ASSERT_EQ(2, results.archived_binary.size()); | 196 ASSERT_EQ(2, results.archived_binary.size()); |
184 ExpectBinary(kUnsignedExe, results.archived_binary.Get(0)); | 197 ExpectBinary(kUnsignedExe, results.archived_binary.Get(0)); |
185 ExpectBinary(kSignedExe, results.archived_binary.Get(1)); | 198 ExpectBinary(kSignedExe, results.archived_binary.Get(1)); |
186 } | 199 } |
187 | 200 |
| 201 TEST_F(SandboxedZipAnalyzerTest, ZippedArchiveNoBinaries) { |
| 202 zip_analyzer::Results results; |
| 203 RunAnalyzer(dir_test_data_.AppendASCII("zipfile_archive_no_binaries.zip"), |
| 204 &results); |
| 205 ASSERT_TRUE(results.success); |
| 206 EXPECT_FALSE(results.has_executable); |
| 207 EXPECT_TRUE(results.has_archive); |
| 208 EXPECT_EQ(0, results.archived_binary.size()); |
| 209 } |
| 210 |
| 211 TEST_F(SandboxedZipAnalyzerTest, ZippedRarArchiveNoBinaries) { |
| 212 zip_analyzer::Results results; |
| 213 RunAnalyzer(dir_test_data_.AppendASCII("zipfile_rar_archive_no_binaries.zip"), |
| 214 &results); |
| 215 ASSERT_TRUE(results.success); |
| 216 EXPECT_FALSE(results.has_executable); |
| 217 EXPECT_TRUE(results.has_archive); |
| 218 EXPECT_EQ(0, results.archived_binary.size()); |
| 219 } |
| 220 |
| 221 TEST_F(SandboxedZipAnalyzerTest, ZippedArchiveAndBinaries) { |
| 222 zip_analyzer::Results results; |
| 223 RunAnalyzer(dir_test_data_.AppendASCII("zipfile_archive_and_binaries.zip"), |
| 224 &results); |
| 225 ASSERT_TRUE(results.success); |
| 226 EXPECT_TRUE(results.has_executable); |
| 227 EXPECT_TRUE(results.has_archive); |
| 228 ASSERT_EQ(1, results.archived_binary.size()); |
| 229 ExpectBinary(kSignedExe, results.archived_binary.Get(0)); |
| 230 } |
| 231 |
| 232 TEST_F(SandboxedZipAnalyzerTest, ZippedJSEFile) { |
| 233 zip_analyzer::Results results; |
| 234 RunAnalyzer(dir_test_data_.AppendASCII("zipfile_one_jse_file.zip"), |
| 235 &results); |
| 236 ASSERT_TRUE(results.success); |
| 237 EXPECT_TRUE(results.has_executable); |
| 238 EXPECT_FALSE(results.has_archive); |
| 239 ASSERT_EQ(1, results.archived_binary.size()); |
| 240 ExpectBinary(kJSEFile, results.archived_binary.Get(0)); |
| 241 } |
| 242 |
188 } // namespace safe_browsing | 243 } // namespace safe_browsing |
OLD | NEW |