| 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 #include "components/os_crypt/os_crypt.h" | 5 #include "components/os_crypt/os_crypt.h" |
| 6 | 6 |
| 7 #include <CommonCrypto/CommonCryptor.h> // for kCCBlockSizeAES128 | 7 #include <CommonCrypto/CommonCryptor.h> // for kCCBlockSizeAES128 |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/leak_annotations.h" | 10 #include "base/debug/leak_annotations.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 crypto::SymmetricKey* GetEncryptionKey() { | 45 crypto::SymmetricKey* GetEncryptionKey() { |
| 46 static crypto::SymmetricKey* cached_encryption_key = NULL; | 46 static crypto::SymmetricKey* cached_encryption_key = NULL; |
| 47 static bool key_is_cached = false; | 47 static bool key_is_cached = false; |
| 48 static base::Lock lock; | 48 static base::Lock lock; |
| 49 base::AutoLock auto_lock(lock); | 49 base::AutoLock auto_lock(lock); |
| 50 | 50 |
| 51 if (key_is_cached) | 51 if (key_is_cached) |
| 52 return cached_encryption_key; | 52 return cached_encryption_key; |
| 53 | 53 |
| 54 static bool mock_keychain_command_line_flag = | 54 static bool mock_keychain_command_line_flag = |
| 55 CommandLine::ForCurrentProcess()->HasSwitch( | 55 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 56 os_crypt::switches::kUseMockKeychain); | 56 os_crypt::switches::kUseMockKeychain); |
| 57 | 57 |
| 58 std::string password; | 58 std::string password; |
| 59 if (use_mock_keychain || mock_keychain_command_line_flag) { | 59 if (use_mock_keychain || mock_keychain_command_line_flag) { |
| 60 password = "mock_password"; | 60 password = "mock_password"; |
| 61 } else { | 61 } else { |
| 62 AppleKeychain keychain; | 62 AppleKeychain keychain; |
| 63 KeychainPassword encryptor_password(keychain); | 63 KeychainPassword encryptor_password(keychain); |
| 64 password = encryptor_password.GetPassword(); | 64 password = encryptor_password.GetPassword(); |
| 65 } | 65 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 if (!encryptor.Decrypt(raw_ciphertext, plaintext)) | 160 if (!encryptor.Decrypt(raw_ciphertext, plaintext)) |
| 161 return false; | 161 return false; |
| 162 | 162 |
| 163 return true; | 163 return true; |
| 164 } | 164 } |
| 165 | 165 |
| 166 void OSCrypt::UseMockKeychain(bool use_mock) { | 166 void OSCrypt::UseMockKeychain(bool use_mock) { |
| 167 use_mock_keychain = use_mock; | 167 use_mock_keychain = use_mock; |
| 168 } | 168 } |
| 169 | 169 |
| OLD | NEW |