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

Side by Side Diff: components/os_crypt/os_crypt.h

Issue 2262693002: Initialize OSCrypt with a TaskRunner on the main thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 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 unified diff | Download patch
« no previous file with comments | « components/os_crypt/key_storage_linux.cc ('k') | components/os_crypt/os_crypt_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
12 #include "base/single_thread_task_runner.h"
11 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
12 #include "build/build_config.h" 14 #include "build/build_config.h"
13 15
14 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 16 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
15 #include "components/os_crypt/key_storage_linux.h" 17 #include "components/os_crypt/key_storage_linux.h"
16 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) 18 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS)
17 19
18 // The OSCrypt class gives access to simple encryption and decryption of 20 // The OSCrypt class gives access to simple encryption and decryption of
19 // strings. Note that on Mac, access to the system Keychain is required and 21 // strings. Note that on Mac, access to the system Keychain is required and
20 // these calls can block the current thread to collect user input. The same is 22 // these calls can block the current thread to collect user input. The same is
21 // true for Linux, if a password management tool is available. 23 // true for Linux, if a password management tool is available.
22 class OSCrypt { 24 class OSCrypt {
23 public: 25 public:
24 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 26 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
25 // If |store_type| is a known password store, we will attempt to use it. 27 // If |store_type| is a known password store, we will attempt to use it.
26 // In any other case, we default to auto-detecting the store. 28 // In any other case, we default to auto-detecting the store.
27 // This should not be changed after OSCrypt has been used. 29 // This should not be changed after OSCrypt has been used.
28 static void SetStore(const std::string& store_type); 30 static void SetStore(const std::string& store_type);
29 31
30 // Some password stores may prompt the user for permission and show the 32 // Some password stores may prompt the user for permission and show the
31 // application name. 33 // application name.
32 static void SetProductName(const std::string& product_name); 34 static void SetProductName(const std::string& product_name);
35
36 // The gnome-keyring implementation requires calls from the main thread.
37 // TODO(crbug/466975): Libsecret and KWallet don't need this. We can remove
38 // this when we stop supporting keyring.
39 static void SetMainThreadRunner(
40 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner);
33 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) 41 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS)
34 42
35 // Encrypt a string16. The output (second argument) is really an array of 43 // Encrypt a string16. The output (second argument) is really an array of
36 // bytes, but we're passing it back as a std::string. 44 // bytes, but we're passing it back as a std::string.
37 static bool EncryptString16(const base::string16& plaintext, 45 static bool EncryptString16(const base::string16& plaintext,
38 std::string* ciphertext); 46 std::string* ciphertext);
39 47
40 // Decrypt an array of bytes obtained with EncryptString16 back into a 48 // Decrypt an array of bytes obtained with EncryptString16 back into a
41 // string16. Note that the input (first argument) is a std::string, so you 49 // string16. Note that the input (first argument) is a std::string, so you
42 // need to first get your (binary) data into a string. 50 // need to first get your (binary) data into a string.
(...skipping 24 matching lines...) Expand all
67 // For unit testing purposes, inject methods to be used. 75 // For unit testing purposes, inject methods to be used.
68 // |get_key_storage_mock| provides the desired |KeyStorage| implementation. 76 // |get_key_storage_mock| provides the desired |KeyStorage| implementation.
69 // If the provider returns |nullptr|, a hardcoded password will be used. 77 // If the provider returns |nullptr|, a hardcoded password will be used.
70 // |get_password_v11_mock| provides a password to derive the encryption key from 78 // |get_password_v11_mock| provides a password to derive the encryption key from
71 // If both parameters are |nullptr|, the real implementation is restored. 79 // If both parameters are |nullptr|, the real implementation is restored.
72 void UseMockKeyStorageForTesting(KeyStorageLinux* (*get_key_storage_mock)(), 80 void UseMockKeyStorageForTesting(KeyStorageLinux* (*get_key_storage_mock)(),
73 std::string* (*get_password_v11_mock)()); 81 std::string* (*get_password_v11_mock)());
74 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(UNIT_TEST) 82 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(UNIT_TEST)
75 83
76 #endif // COMPONENTS_OS_CRYPT_OS_CRYPT_H_ 84 #endif // COMPONENTS_OS_CRYPT_OS_CRYPT_H_
OLDNEW
« no previous file with comments | « components/os_crypt/key_storage_linux.cc ('k') | components/os_crypt/os_crypt_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698