Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(581)

Unified Diff: chrome/browser/safe_browsing/binary_integrity_service_win_unittest.cc

Issue 444123002: Adding a new delayed analysis that verify binaries signature. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@grt
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/binary_integrity_service_win_unittest.cc
diff --git a/chrome/browser/safe_browsing/binary_integrity_service_win_unittest.cc b/chrome/browser/safe_browsing/binary_integrity_service_win_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1f2debbbccbd4c7c56f0fc6630314912150b9def
--- /dev/null
+++ b/chrome/browser/safe_browsing/binary_integrity_service_win_unittest.cc
@@ -0,0 +1,113 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/safe_browsing/binary_integrity_service.h"
+
+#include "base/bind.h"
+#include "base/files/scoped_temp_dir.h"
+#include "base/file_util.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/path_service.h"
+#include "base/test/scoped_path_override.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/common/safe_browsing/csd.pb.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace safe_browsing {
+
+namespace {
+
+
+const wchar_t kChromeDll[] = L"chrome.dll";
+const wchar_t kChromeElfDll[] = L"chrome_elf.dll";
+const wchar_t kChromeExe[] = L"chrome.exe";
+const wchar_t kSignedBinaryDll[] = L"signed_binary.dll";
+
+// Indicate if the AddIncidentCallback has been called.
+bool g_callback_called = false;
+
+// Helper function to erase the content of a binary to make sure the signature
+// verification will fail.
+bool EraseFileContent(const base::FilePath& file_path) {
+ FILE* file = base::OpenFile(file_path, "w");
+
+ if (file == NULL)
+ return false;
+
+ bool success = base::TruncateFile(file);
+ return base::CloseFile(file) && success;
+}
+
+// Mock the AddIncidentCallback so we can test that VerifyBinaryIntegrity
+// adds an incident callback when a signature verification fails.
+void MockAddIncidentCallback(scoped_ptr<ClientIncidentReport_IncidentData>) {
+ g_callback_called = true;
+}
+
+} // namespace
+
+class BinaryIntegrityServiceWinTest : public ::testing::Test {
+ protected:
+ BinaryIntegrityServiceWinTest();
+
+ base::FilePath test_data_dir_;
+ base::ScopedTempDir temp_dir_;
+ scoped_ptr<base::ScopedPathOverride> exe_dir_override_;
+};
+
+BinaryIntegrityServiceWinTest::BinaryIntegrityServiceWinTest() {
+ temp_dir_.CreateUniqueTempDir();
+ base::CreateDirectory(temp_dir_.path().Append(GetChromeVersion()));
+
+ // We retrieve DIR_TEST_DATA here because it is based on DIR_EXE and we are
+ // about to override the path to the latter.
+ if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_))
+ NOTREACHED();
+
+ exe_dir_override_.reset(
+ new base::ScopedPathOverride(base::DIR_EXE, temp_dir_.path()));
+}
+
+TEST_F(BinaryIntegrityServiceWinTest, GetCriticalBinariesPath) {
+ // Expected paths.
+ std::vector<base::FilePath> critical_binaries_path_expected;
+ critical_binaries_path_expected.push_back(
+ temp_dir_.path().Append(GetChromeVersion()).Append(kChromeDll));
+ critical_binaries_path_expected.push_back(
+ temp_dir_.path().Append(GetChromeVersion()).Append(kChromeElfDll));
+ critical_binaries_path_expected.push_back(
+ temp_dir_.path().Append(kChromeExe));
+
+ std::vector<base::FilePath> critical_binaries_path =
+ GetCriticalBinariesPath();
+
+ ASSERT_THAT(critical_binaries_path,
+ ::testing::ContainerEq(critical_binaries_path_expected));
+}
+
+TEST_F(BinaryIntegrityServiceWinTest, VerifyBinaryIntegrity) {
+ // Copy the signed dll to the temp exe directory.
+ base::FilePath signed_binary_path(test_data_dir_);
+ signed_binary_path =
+ signed_binary_path.Append(L"safe_browsing").Append(kSignedBinaryDll);
+
+ base::FilePath chrome_elf_path(temp_dir_.path());
+ chrome_elf_path = chrome_elf_path.Append(
+ GetChromeVersion()).Append(kChromeElfDll);
+
+ ASSERT_TRUE(base::CopyFile(signed_binary_path, chrome_elf_path));
+
+ AddIncidentCallback callback = base::Bind(&MockAddIncidentCallback);
+
+ VerifyBinaryIntegrity(callback);
+ ASSERT_FALSE(g_callback_called);
+
+ ASSERT_TRUE(EraseFileContent(chrome_elf_path));
+
+ VerifyBinaryIntegrity(callback);
+ ASSERT_TRUE(g_callback_called);
+}
+
+} // namespace safe_browsing

Powered by Google App Engine
This is Rietveld 408576698