OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "components/os_crypt/os_crypt.h" | 5 #include "components/os_crypt/os_crypt.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <iterator> | 10 #include <iterator> |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 // Strip off the versioning prefix before decrypting. | 203 // Strip off the versioning prefix before decrypting. |
204 std::string raw_ciphertext = | 204 std::string raw_ciphertext = |
205 ciphertext.substr(strlen(kObfuscationPrefix[version])); | 205 ciphertext.substr(strlen(kObfuscationPrefix[version])); |
206 | 206 |
207 if (!encryptor.Decrypt(raw_ciphertext, plaintext)) | 207 if (!encryptor.Decrypt(raw_ciphertext, plaintext)) |
208 return false; | 208 return false; |
209 | 209 |
210 return true; | 210 return true; |
211 } | 211 } |
212 | 212 |
| 213 // static |
| 214 void OSCrypt::SetStore(const std::string& store_type) { |
| 215 // Changing the targeted password store makes no sense after initializing. |
| 216 DCHECK(!g_cache.Get().is_key_storage_cached); |
| 217 |
| 218 KeyStorageLinux::SetStore(store_type); |
| 219 } |
| 220 |
213 void UseMockKeyStorageForTesting(KeyStorageLinux* (*get_key_storage_mock)(), | 221 void UseMockKeyStorageForTesting(KeyStorageLinux* (*get_key_storage_mock)(), |
214 std::string* (*get_password_v11_mock)()) { | 222 std::string* (*get_password_v11_mock)()) { |
215 // Save the real implementation to restore it later. | 223 // Save the real implementation to restore it later. |
216 static bool is_get_password_saved = false; | 224 static bool is_get_password_saved = false; |
217 static std::string* (*get_password_save[arraysize(g_get_password)])(); | 225 static std::string* (*get_password_save[arraysize(g_get_password)])(); |
218 if (!is_get_password_saved) { | 226 if (!is_get_password_saved) { |
219 std::copy(std::begin(g_get_password), std::end(g_get_password), | 227 std::copy(std::begin(g_get_password), std::end(g_get_password), |
220 std::begin(get_password_save)); | 228 std::begin(get_password_save)); |
221 is_get_password_saved = true; | 229 is_get_password_saved = true; |
222 } | 230 } |
223 | 231 |
224 if (get_key_storage_mock && get_password_v11_mock) { | 232 if (get_key_storage_mock && get_password_v11_mock) { |
225 // Bypass calling KeyStorage::CreateService and caching of the key for V11 | 233 // Bypass calling KeyStorage::CreateService and caching of the key for V11 |
226 g_get_password[Version::V11] = get_password_v11_mock; | 234 g_get_password[Version::V11] = get_password_v11_mock; |
227 // OSCrypt will determine the encryption version by checking if a | 235 // OSCrypt will determine the encryption version by checking if a |
228 // |KeyStorage| instance can be created. Enable V11 by returning the mock. | 236 // |KeyStorage| instance can be created. Enable V11 by returning the mock. |
229 g_key_storage_provider = get_key_storage_mock; | 237 g_key_storage_provider = get_key_storage_mock; |
230 } else { | 238 } else { |
231 // Restore real implementation | 239 // Restore real implementation |
232 std::copy(std::begin(get_password_save), std::end(get_password_save), | 240 std::copy(std::begin(get_password_save), std::end(get_password_save), |
233 std::begin(g_get_password)); | 241 std::begin(g_get_password)); |
234 } | 242 } |
235 } | 243 } |
OLD | NEW |