Chromium Code Reviews| 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..fe15c55779be0cfc67d976530a6e01ca8ef812ed 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 avaible), then |
|
Lei Zhang
2016/09/28 16:45:14
available
Lei Zhang
2016/09/28 17:32:58
Eh. I'll just fix this in a follow up CL.
Lei Zhang
2016/09/28 17:33:27
Oh wait, you did, I just didn't see an email from
|
| + // 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; |