OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/password_manager/encryptor.h" | 5 #include "chrome/browser/password_manager/encryptor.h" |
6 | 6 |
7 #include <CommonCrypto/CommonCryptor.h> // for kCCBlockSizeAES128 | 7 #include <CommonCrypto/CommonCryptor.h> // for kCCBlockSizeAES128 |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/password_manager/encryptor_password_mac.h" | 12 #include "chrome/browser/password_manager/encryptor_password_mac.h" |
| 13 #include "crypto/apple_keychain.h" |
13 #include "crypto/encryptor.h" | 14 #include "crypto/encryptor.h" |
14 #include "crypto/keychain_mac.h" | |
15 #include "crypto/symmetric_key.h" | 15 #include "crypto/symmetric_key.h" |
16 | 16 |
17 using crypto::MacKeychain; | 17 using crypto::AppleKeychain; |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // Salt for Symmetric key derivation. | 21 // Salt for Symmetric key derivation. |
22 const char kSalt[] = "saltysalt"; | 22 const char kSalt[] = "saltysalt"; |
23 | 23 |
24 // Key size required for 128 bit AES. | 24 // Key size required for 128 bit AES. |
25 const size_t kDerivedKeySizeInBits = 128; | 25 const size_t kDerivedKeySizeInBits = 128; |
26 | 26 |
27 // Constant for Symmetic key derivation. | 27 // Constant for Symmetic key derivation. |
(...skipping 10 matching lines...) Expand all Loading... |
38 // Generates a newly allocated SymmetricKey object based on the password found | 38 // Generates a newly allocated SymmetricKey object based on the password found |
39 // in the Keychain. The generated key is for AES encryption. Ownership of the | 39 // in the Keychain. The generated key is for AES encryption. Ownership of the |
40 // key is passed to the caller. Returns NULL key in the case password access | 40 // key is passed to the caller. Returns NULL key in the case password access |
41 // is denied or key generation error occurs. | 41 // is denied or key generation error occurs. |
42 crypto::SymmetricKey* GetEncryptionKey() { | 42 crypto::SymmetricKey* GetEncryptionKey() { |
43 | 43 |
44 std::string password; | 44 std::string password; |
45 if (use_mock_keychain) { | 45 if (use_mock_keychain) { |
46 password = "mock_password"; | 46 password = "mock_password"; |
47 } else { | 47 } else { |
48 MacKeychain keychain; | 48 AppleKeychain keychain; |
49 EncryptorPassword encryptor_password(keychain); | 49 EncryptorPassword encryptor_password(keychain); |
50 password = encryptor_password.GetEncryptorPassword(); | 50 password = encryptor_password.GetEncryptorPassword(); |
51 } | 51 } |
52 | 52 |
53 if (password.empty()) | 53 if (password.empty()) |
54 return NULL; | 54 return NULL; |
55 | 55 |
56 std::string salt(kSalt); | 56 std::string salt(kSalt); |
57 | 57 |
58 // Create an encryption key from our password and salt. | 58 // Create an encryption key from our password and salt. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 if (!encryptor.Decrypt(raw_ciphertext, plaintext)) | 141 if (!encryptor.Decrypt(raw_ciphertext, plaintext)) |
142 return false; | 142 return false; |
143 | 143 |
144 return true; | 144 return true; |
145 } | 145 } |
146 | 146 |
147 void Encryptor::UseMockKeychain(bool use_mock) { | 147 void Encryptor::UseMockKeychain(bool use_mock) { |
148 use_mock_keychain = use_mock; | 148 use_mock_keychain = use_mock; |
149 } | 149 } |
150 | 150 |
OLD | NEW |