| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef COMPONENTS_OS_CRYPT_OS_CRYPT_H_ | 5 #ifndef COMPONENTS_OS_CRYPT_OS_CRYPT_H_ |
| 6 #define COMPONENTS_OS_CRYPT_OS_CRYPT_H_ | 6 #define COMPONENTS_OS_CRYPT_OS_CRYPT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 | 15 |
| 16 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 16 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 17 #include "components/os_crypt/key_storage_linux.h" | 17 #include "components/os_crypt/key_storage_linux.h" |
| 18 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) | 18 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 19 | 19 |
| 20 namespace base { |
| 21 class FilePath; |
| 22 } |
| 23 |
| 20 // The OSCrypt class gives access to simple encryption and decryption of | 24 // The OSCrypt class gives access to simple encryption and decryption of |
| 21 // strings. Note that on Mac, access to the system Keychain is required and | 25 // strings. Note that on Mac, access to the system Keychain is required and |
| 22 // these calls can block the current thread to collect user input. The same is | 26 // these calls can block the current thread to collect user input. The same is |
| 23 // true for Linux, if a password management tool is available. | 27 // true for Linux, if a password management tool is available. |
| 24 class OSCrypt { | 28 class OSCrypt { |
| 25 public: | 29 public: |
| 26 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 30 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 27 // If |store_type| is a known password store, we will attempt to use it. | 31 // If |store_type| is a known password store, we will attempt to use it. |
| 28 // In any other case, we default to auto-detecting the store. | 32 // In any other case, we default to auto-detecting the store. |
| 29 // This should not be changed after OSCrypt has been used. | 33 // This should not be changed after OSCrypt has been used. |
| 30 static void SetStore(const std::string& store_type); | 34 static void SetStore(const std::string& store_type); |
| 31 | 35 |
| 32 // Some password stores may prompt the user for permission and show the | 36 // Some password stores may prompt the user for permission and show the |
| 33 // application name. | 37 // application name. |
| 34 static void SetProductName(const std::string& product_name); | 38 static void SetProductName(const std::string& product_name); |
| 35 | 39 |
| 36 // The gnome-keyring implementation requires calls from the main thread. | 40 // The gnome-keyring implementation requires calls from the main thread. |
| 37 // TODO(crbug/466975): Libsecret and KWallet don't need this. We can remove | 41 // TODO(crbug/466975): Libsecret and KWallet don't need this. We can remove |
| 38 // this when we stop supporting keyring. | 42 // this when we stop supporting keyring. |
| 39 static void SetMainThreadRunner( | 43 static void SetMainThreadRunner( |
| 40 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner); | 44 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner); |
| 41 | 45 |
| 46 // Enable the feature where we determine if we should try a backend via a |
| 47 // preference file. |
| 48 static void ShouldUsePreference(bool should_use_preference); |
| 49 |
| 50 // Set the folder, where OSCrypt will check for its preference file. |
| 51 static void SetUserDataPath(const base::FilePath& path); |
| 52 |
| 42 // Returns true iff the real secret key (not hardcoded one) is available. | 53 // Returns true iff the real secret key (not hardcoded one) is available. |
| 43 static bool IsEncryptionAvailable(); | 54 static bool IsEncryptionAvailable(); |
| 44 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) | 55 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 45 | 56 |
| 46 // Encrypt a string16. The output (second argument) is really an array of | 57 // Encrypt a string16. The output (second argument) is really an array of |
| 47 // bytes, but we're passing it back as a std::string. | 58 // bytes, but we're passing it back as a std::string. |
| 48 static bool EncryptString16(const base::string16& plaintext, | 59 static bool EncryptString16(const base::string16& plaintext, |
| 49 std::string* ciphertext); | 60 std::string* ciphertext); |
| 50 | 61 |
| 51 // Decrypt an array of bytes obtained with EncryptString16 back into a | 62 // Decrypt an array of bytes obtained with EncryptString16 back into a |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // If all parameters are |nullptr|, the real implementation is restored. | 94 // If all parameters are |nullptr|, the real implementation is restored. |
| 84 void UseMockKeyStorageForTesting(KeyStorageLinux* (*get_key_storage_mock)(), | 95 void UseMockKeyStorageForTesting(KeyStorageLinux* (*get_key_storage_mock)(), |
| 85 std::string* (*get_password_v11_mock)()); | 96 std::string* (*get_password_v11_mock)()); |
| 86 | 97 |
| 87 // Clears any caching and most lazy initialisations performed by the production | 98 // Clears any caching and most lazy initialisations performed by the production |
| 88 // code. Should be used after any test which required a password. | 99 // code. Should be used after any test which required a password. |
| 89 void ClearCacheForTesting(); | 100 void ClearCacheForTesting(); |
| 90 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(UNIT_TEST) | 101 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(UNIT_TEST) |
| 91 | 102 |
| 92 #endif // COMPONENTS_OS_CRYPT_OS_CRYPT_H_ | 103 #endif // COMPONENTS_OS_CRYPT_OS_CRYPT_H_ |
| OLD | NEW |