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 KeyStorageLinux::SetStore(store_type); |
| 216 } |
| 217 |
213 void UseMockKeyStorageForTesting(KeyStorageLinux* (*get_key_storage_mock)(), | 218 void UseMockKeyStorageForTesting(KeyStorageLinux* (*get_key_storage_mock)(), |
214 std::string* (*get_password_v11_mock)()) { | 219 std::string* (*get_password_v11_mock)()) { |
215 // Save the real implementation to restore it later. | 220 // Save the real implementation to restore it later. |
216 static bool is_get_password_saved = false; | 221 static bool is_get_password_saved = false; |
217 static std::string* (*get_password_save[arraysize(g_get_password)])(); | 222 static std::string* (*get_password_save[arraysize(g_get_password)])(); |
218 if (!is_get_password_saved) { | 223 if (!is_get_password_saved) { |
219 std::copy(std::begin(g_get_password), std::end(g_get_password), | 224 std::copy(std::begin(g_get_password), std::end(g_get_password), |
220 std::begin(get_password_save)); | 225 std::begin(get_password_save)); |
221 is_get_password_saved = true; | 226 is_get_password_saved = true; |
222 } | 227 } |
223 | 228 |
224 if (get_key_storage_mock && get_password_v11_mock) { | 229 if (get_key_storage_mock && get_password_v11_mock) { |
225 // Bypass calling KeyStorage::CreateService and caching of the key for V11 | 230 // Bypass calling KeyStorage::CreateService and caching of the key for V11 |
226 g_get_password[Version::V11] = get_password_v11_mock; | 231 g_get_password[Version::V11] = get_password_v11_mock; |
227 // OSCrypt will determine the encryption version by checking if a | 232 // OSCrypt will determine the encryption version by checking if a |
228 // |KeyStorage| instance can be created. Enable V11 by returning the mock. | 233 // |KeyStorage| instance can be created. Enable V11 by returning the mock. |
229 g_key_storage_provider = get_key_storage_mock; | 234 g_key_storage_provider = get_key_storage_mock; |
230 } else { | 235 } else { |
231 // Restore real implementation | 236 // Restore real implementation |
232 std::copy(std::begin(get_password_save), std::end(get_password_save), | 237 std::copy(std::begin(get_password_save), std::end(get_password_save), |
233 std::begin(g_get_password)); | 238 std::begin(g_get_password)); |
234 } | 239 } |
235 } | 240 } |
OLD | NEW |