| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 15 #include "components/os_crypt/keychain_password_mac.h" | 15 #include "components/os_crypt/keychain_password_mac.h" |
| 16 #include "components/os_crypt/os_crypt_switches.h" | 16 #include "components/os_crypt/os_crypt_switches.h" |
| 17 #include "crypto/apple_keychain.h" | 17 #include "crypto/apple_keychain.h" |
| 18 #include "crypto/encryptor.h" | 18 #include "crypto/encryptor.h" |
| 19 #include "crypto/mock_apple_keychain.h" |
| 19 #include "crypto/symmetric_key.h" | 20 #include "crypto/symmetric_key.h" |
| 20 | 21 |
| 21 using crypto::AppleKeychain; | 22 using crypto::AppleKeychain; |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // Salt for Symmetric key derivation. | 26 // Salt for Symmetric key derivation. |
| 26 const char kSalt[] = "saltysalt"; | 27 const char kSalt[] = "saltysalt"; |
| 27 | 28 |
| 28 // Key size required for 128 bit AES. | 29 // Key size required for 128 bit AES. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 50 | 51 |
| 51 if (key_is_cached) | 52 if (key_is_cached) |
| 52 return cached_encryption_key; | 53 return cached_encryption_key; |
| 53 | 54 |
| 54 static bool mock_keychain_command_line_flag = | 55 static bool mock_keychain_command_line_flag = |
| 55 base::CommandLine::ForCurrentProcess()->HasSwitch( | 56 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 56 os_crypt::switches::kUseMockKeychain); | 57 os_crypt::switches::kUseMockKeychain); |
| 57 | 58 |
| 58 std::string password; | 59 std::string password; |
| 59 if (use_mock_keychain || mock_keychain_command_line_flag) { | 60 if (use_mock_keychain || mock_keychain_command_line_flag) { |
| 60 password = "mock_password"; | 61 crypto::MockAppleKeychain keychain; |
| 62 password = keychain.GetEncryptionPassword(); |
| 61 } else { | 63 } else { |
| 62 AppleKeychain keychain; | 64 AppleKeychain keychain; |
| 63 KeychainPassword encryptor_password(keychain); | 65 KeychainPassword encryptor_password(keychain); |
| 64 password = encryptor_password.GetPassword(); | 66 password = encryptor_password.GetPassword(); |
| 65 } | 67 } |
| 66 | 68 |
| 67 // Subsequent code must guarantee that the correct key is cached before | 69 // Subsequent code must guarantee that the correct key is cached before |
| 68 // returning. | 70 // returning. |
| 69 key_is_cached = true; | 71 key_is_cached = true; |
| 70 | 72 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 if (!encryptor.Decrypt(raw_ciphertext, plaintext)) | 162 if (!encryptor.Decrypt(raw_ciphertext, plaintext)) |
| 161 return false; | 163 return false; |
| 162 | 164 |
| 163 return true; | 165 return true; |
| 164 } | 166 } |
| 165 | 167 |
| 166 void OSCrypt::UseMockKeychain(bool use_mock) { | 168 void OSCrypt::UseMockKeychain(bool use_mock) { |
| 167 use_mock_keychain = use_mock; | 169 use_mock_keychain = use_mock; |
| 168 } | 170 } |
| 169 | 171 |
| OLD | NEW |