summaryrefslogtreecommitdiff
path: root/chromium/components/os_crypt
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-07-17 13:57:45 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-07-19 13:44:40 +0000
commit6ec7b8da05d21a3878bd21c691b41e675d74bb1c (patch)
treeb87f250bc19413750b9bb9cdbf2da20ef5014820 /chromium/components/os_crypt
parentec02ee4181c49b61fce1c8fb99292dbb8139cc90 (diff)
downloadqtwebengine-chromium-6ec7b8da05d21a3878bd21c691b41e675d74bb1c.tar.gz
BASELINE: Update Chromium to 60.0.3112.70
Change-Id: I9911c2280a014d4632f254857876a395d4baed2d Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/components/os_crypt')
-rw-r--r--chromium/components/os_crypt/os_crypt.h7
-rw-r--r--chromium/components/os_crypt/os_crypt_linux.cc16
-rw-r--r--chromium/components/os_crypt/os_crypt_linux_unittest.cc13
-rw-r--r--chromium/components/os_crypt/os_crypt_mocker_linux.cc1
4 files changed, 36 insertions, 1 deletions
diff --git a/chromium/components/os_crypt/os_crypt.h b/chromium/components/os_crypt/os_crypt.h
index b62aca48365..b03d72608d6 100644
--- a/chromium/components/os_crypt/os_crypt.h
+++ b/chromium/components/os_crypt/os_crypt.h
@@ -38,6 +38,9 @@ class OSCrypt {
// this when we stop supporting keyring.
static void SetMainThreadRunner(
scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner);
+
+ // Returns true iff the real secret key (not hardcoded one) is available.
+ static bool IsEncryptionAvailable();
#endif // defined(OS_LINUX) && !defined(OS_CHROMEOS)
// Encrypt a string16. The output (second argument) is really an array of
@@ -80,6 +83,10 @@ class OSCrypt {
// If all parameters are |nullptr|, the real implementation is restored.
void UseMockKeyStorageForTesting(KeyStorageLinux* (*get_key_storage_mock)(),
std::string* (*get_password_v11_mock)());
+
+// Clears any caching and most lazy initialisations performed by the production
+// code. Should be used after any test which required a password.
+void ClearCacheForTesting();
#endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(UNIT_TEST)
#endif // COMPONENTS_OS_CRYPT_OS_CRYPT_H_
diff --git a/chromium/components/os_crypt/os_crypt_linux.cc b/chromium/components/os_crypt/os_crypt_linux.cc
index 496d9716ea4..b8b6ada030e 100644
--- a/chromium/components/os_crypt/os_crypt_linux.cc
+++ b/chromium/components/os_crypt/os_crypt_linux.cc
@@ -12,6 +12,7 @@
#include "base/lazy_instance.h"
#include "base/logging.h"
+#include "base/single_thread_task_runner.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/lock.h"
@@ -248,6 +249,19 @@ void OSCrypt::SetMainThreadRunner(
KeyStorageLinux::SetMainThreadRunner(main_thread_runner);
}
+// static
+bool OSCrypt::IsEncryptionAvailable() {
+ return g_get_password[Version::V11]();
+}
+
+void ClearCacheForTesting() {
+ g_cache.Get().key_storage_cache.reset();
+ g_cache.Get().password_v10_cache.reset();
+ g_cache.Get().password_v11_cache.reset();
+ g_cache.Get().is_key_storage_cached = false;
+ g_cache.Get().is_password_v11_cached = false;
+}
+
void UseMockKeyStorageForTesting(KeyStorageLinux* (*get_key_storage_mock)(),
std::string* (*get_password_v11_mock)()) {
// Save the real implementation to restore it later.
@@ -259,7 +273,7 @@ void UseMockKeyStorageForTesting(KeyStorageLinux* (*get_key_storage_mock)(),
is_get_password_saved = true;
}
- if (get_key_storage_mock && get_password_v11_mock) {
+ if (get_key_storage_mock || get_password_v11_mock) {
// Bypass calling KeyStorage::CreateService and caching of the key for V11
if (get_password_v11_mock)
g_get_password[Version::V11] = get_password_v11_mock;
diff --git a/chromium/components/os_crypt/os_crypt_linux_unittest.cc b/chromium/components/os_crypt/os_crypt_linux_unittest.cc
index 5f22c316aed..dce4c4a20e7 100644
--- a/chromium/components/os_crypt/os_crypt_linux_unittest.cc
+++ b/chromium/components/os_crypt/os_crypt_linux_unittest.cc
@@ -12,6 +12,10 @@
namespace {
+KeyStorageLinux* GetNullKeyStorage() {
+ return nullptr;
+}
+
class OSCryptLinuxTest : public testing::Test {
public:
OSCryptLinuxTest() = default;
@@ -67,4 +71,13 @@ TEST_F(OSCryptLinuxTest, VerifyV11) {
ASSERT_EQ(originaltext, decipheredtext);
}
+TEST_F(OSCryptLinuxTest, IsEncryptionAvailable) {
+ EXPECT_TRUE(OSCrypt::IsEncryptionAvailable());
+ // Restore default GetKeyStorage and GetPassword functions.
+ UseMockKeyStorageForTesting(nullptr, nullptr);
+ // Mock only GetKeyStorage function.
+ UseMockKeyStorageForTesting(GetNullKeyStorage, nullptr);
+ EXPECT_FALSE(OSCrypt::IsEncryptionAvailable());
+}
+
} // namespace
diff --git a/chromium/components/os_crypt/os_crypt_mocker_linux.cc b/chromium/components/os_crypt/os_crypt_mocker_linux.cc
index a222c88d98a..d4dc0ac361c 100644
--- a/chromium/components/os_crypt/os_crypt_mocker_linux.cc
+++ b/chromium/components/os_crypt/os_crypt_mocker_linux.cc
@@ -55,4 +55,5 @@ void OSCryptMockerLinux::SetUpWithSingleton() {
// static
void OSCryptMockerLinux::TearDown() {
UseMockKeyStorageForTesting(nullptr, nullptr);
+ ClearCacheForTesting();
}