| 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/encryptor/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/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "components/encryptor/encryptor_switches.h" | 13 #include "components/os_crypt/keychain_password_mac.h" |
| 14 #include "components/encryptor/keychain_password_mac.h" | 14 #include "components/os_crypt/os_crypt_switches.h" |
| 15 #include "crypto/apple_keychain.h" | 15 #include "crypto/apple_keychain.h" |
| 16 #include "crypto/encryptor.h" | 16 #include "crypto/encryptor.h" |
| 17 #include "crypto/symmetric_key.h" | 17 #include "crypto/symmetric_key.h" |
| 18 | 18 |
| 19 using crypto::AppleKeychain; | 19 using crypto::AppleKeychain; |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // Salt for Symmetric key derivation. | 23 // Salt for Symmetric key derivation. |
| 24 const char kSalt[] = "saltysalt"; | 24 const char kSalt[] = "saltysalt"; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 37 // this and migrate to different encryption without data loss. | 37 // this and migrate to different encryption without data loss. |
| 38 const char kEncryptionVersionPrefix[] = "v10"; | 38 const char kEncryptionVersionPrefix[] = "v10"; |
| 39 | 39 |
| 40 // Generates a newly allocated SymmetricKey object based on the password found | 40 // Generates a newly allocated SymmetricKey object based on the password found |
| 41 // in the Keychain. The generated key is for AES encryption. Ownership of the | 41 // in the Keychain. The generated key is for AES encryption. Ownership of the |
| 42 // key is passed to the caller. Returns NULL key in the case password access | 42 // key is passed to the caller. Returns NULL key in the case password access |
| 43 // is denied or key generation error occurs. | 43 // is denied or key generation error occurs. |
| 44 crypto::SymmetricKey* GetEncryptionKey() { | 44 crypto::SymmetricKey* GetEncryptionKey() { |
| 45 static bool mock_keychain_command_line_flag = | 45 static bool mock_keychain_command_line_flag = |
| 46 CommandLine::ForCurrentProcess()->HasSwitch( | 46 CommandLine::ForCurrentProcess()->HasSwitch( |
| 47 encryptor::switches::kUseMockKeychain); | 47 os_crypt::switches::kUseMockKeychain); |
| 48 | 48 |
| 49 std::string password; | 49 std::string password; |
| 50 if (use_mock_keychain || mock_keychain_command_line_flag) { | 50 if (use_mock_keychain || mock_keychain_command_line_flag) { |
| 51 password = "mock_password"; | 51 password = "mock_password"; |
| 52 } else { | 52 } else { |
| 53 AppleKeychain keychain; | 53 AppleKeychain keychain; |
| 54 KeychainPassword encryptor_password(keychain); | 54 KeychainPassword encryptor_password(keychain); |
| 55 password = encryptor_password.GetPassword(); | 55 password = encryptor_password.GetPassword(); |
| 56 } | 56 } |
| 57 | 57 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 if (!encryptor.Decrypt(raw_ciphertext, plaintext)) | 146 if (!encryptor.Decrypt(raw_ciphertext, plaintext)) |
| 147 return false; | 147 return false; |
| 148 | 148 |
| 149 return true; | 149 return true; |
| 150 } | 150 } |
| 151 | 151 |
| 152 void OSCrypt::UseMockKeychain(bool use_mock) { | 152 void OSCrypt::UseMockKeychain(bool use_mock) { |
| 153 use_mock_keychain = use_mock; | 153 use_mock_keychain = use_mock; |
| 154 } | 154 } |
| 155 | 155 |
| OLD | NEW |