| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_util.h" | 5 #include "chrome/browser/safe_browsing/signature_util.h" |
| 6 | 6 |
| 7 #include <string> |
| 7 #include "base/base_paths.h" | 8 #include "base/base_paths.h" |
| 8 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "chrome/common/safe_browsing/csd.pb.h" |
| 13 #include "net/base/x509_cert_types.h" |
| 14 #include "net/base/x509_certificate.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 16 |
| 12 namespace safe_browsing { | 17 namespace safe_browsing { |
| 13 | 18 |
| 14 TEST(SignatureUtilWinTest, IsSigned) { | 19 TEST(SignatureUtilWinTest, CheckSignature) { |
| 15 FilePath source_path; | 20 FilePath source_path; |
| 16 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &source_path)); | 21 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &source_path)); |
| 17 | 22 |
| 18 FilePath testdata_path = source_path | 23 FilePath testdata_path = source_path |
| 19 .AppendASCII("chrome") | 24 .AppendASCII("chrome") |
| 20 .AppendASCII("test") | 25 .AppendASCII("test") |
| 21 .AppendASCII("data") | 26 .AppendASCII("data") |
| 22 .AppendASCII("safe_browsing") | 27 .AppendASCII("safe_browsing") |
| 23 .AppendASCII("download_protection"); | 28 .AppendASCII("download_protection"); |
| 24 | 29 |
| 25 EXPECT_TRUE(signature_util::IsSigned(testdata_path.Append(L"signed.exe"))); | 30 scoped_refptr<SignatureUtil> signature_util(new SignatureUtil()); |
| 26 EXPECT_FALSE(signature_util::IsSigned( | 31 ClientDownloadRequest_SignatureInfo signature_info; |
| 27 testdata_path.Append(L"unsigned.exe"))); | 32 signature_util->CheckSignature(testdata_path.Append(L"signed.exe"), |
| 28 EXPECT_FALSE(signature_util::IsSigned( | 33 &signature_info); |
| 29 testdata_path.Append(L"doesnotexist.exe"))); | 34 EXPECT_FALSE(signature_info.certificate_contents().empty()); |
| 35 scoped_refptr<net::X509Certificate> cert( |
| 36 net::X509Certificate::CreateFromBytes( |
| 37 signature_info.certificate_contents().data(), |
| 38 signature_info.certificate_contents().size())); |
| 39 ASSERT_TRUE(cert.get()); |
| 40 EXPECT_EQ("Joe's-Software-Emporium", cert->subject().common_name); |
| 41 |
| 42 signature_info.Clear(); |
| 43 signature_util->CheckSignature(testdata_path.Append(L"unsigned.exe"), |
| 44 &signature_info); |
| 45 EXPECT_FALSE(signature_info.has_certificate_contents()); |
| 46 |
| 47 signature_info.Clear(); |
| 48 signature_util->CheckSignature(testdata_path.Append(L"doesnotexist.exe"), |
| 49 &signature_info); |
| 50 EXPECT_FALSE(signature_info.has_certificate_contents()); |
| 30 } | 51 } |
| 31 | 52 |
| 32 } // namespace safe_browsing | 53 } // namespace safe_browsing |
| OLD | NEW |