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

Unified Diff: components/os_crypt/os_crypt_linux.cc

Issue 2377973002: Fix race condition on OSCrypt linux (Closed)
Patch Set: typo Created 4 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/os_crypt/os_crypt_linux.cc
diff --git a/components/os_crypt/os_crypt_linux.cc b/components/os_crypt/os_crypt_linux.cc
index 86503382b4f43466b918746aabb6097aee847413..496d9716ea425d3bae6e069bd5e47860cf2163a9 100644
--- a/components/os_crypt/os_crypt_linux.cc
+++ b/components/os_crypt/os_crypt_linux.cc
@@ -72,6 +72,10 @@ KeyStorageLinux* GetKeyStorage() {
return g_cache.Get().key_storage_cache.get();
}
+// Pointer to a function that creates and returns the |KeyStorage| instance to
+// be used. The function maintains ownership of the pointer.
+KeyStorageLinux* (*g_key_storage_provider)() = &GetKeyStorage;
+
// Returns a cached string of "peanuts". Is thread-safe.
std::string* GetPasswordV10() {
base::AutoLock auto_lock(g_cache.Get().lock);
@@ -87,16 +91,14 @@ std::string* GetPasswordV11() {
base::AutoLock auto_lock(g_cache.Get().lock);
if (!g_cache.Get().is_password_v11_cached) {
g_cache.Get().password_v11_cache.reset(
- GetKeyStorage() ? new std::string(GetKeyStorage()->GetKey()) : nullptr);
+ g_key_storage_provider()
+ ? new std::string(g_key_storage_provider()->GetKey())
+ : nullptr);
g_cache.Get().is_password_v11_cached = true;
}
return g_cache.Get().password_v11_cache.get();
}
-// Pointer to a function that creates and returns the |KeyStorage| instance to
-// be used. The function maintains ownership of the pointer.
-KeyStorageLinux* (*g_key_storage_provider)() = &GetKeyStorage;
-
// Pointers to functions that return a password for deriving the encryption key.
// One function for each supported password version (see Version enum).
std::string* (*g_get_password[])() = {
@@ -150,12 +152,16 @@ bool OSCrypt::EncryptString(const std::string& plaintext,
return true;
}
- // If a |KeyStorage| is available, use a password backed by the |KeyStorage|.
- // Otherwise use the hardcoded password.
- Version version = g_key_storage_provider() ? Version::V11 : Version::V10;
-
+ // If we are able to create a V11 key (i.e. a KeyStorage was available), then
+ // we'll use it. If not, we'll use V10.
+ Version version = Version::V11;
std::unique_ptr<crypto::SymmetricKey> encryption_key(
GetEncryptionKey(version));
+ if (!encryption_key) {
+ version = Version::V10;
+ encryption_key = GetEncryptionKey(version);
+ }
+
if (!encryption_key)
return false;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698