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/encryptor.h" | 5 #include "components/encryptor/encryptor.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/logging.h" | 10 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
12 #include "components/encryptor/encryptor_password_mac.h" | 13 #include "components/encryptor/encryptor_password_mac.h" |
| 14 #include "components/encryptor/encryptor_switches.h" |
13 #include "crypto/apple_keychain.h" | 15 #include "crypto/apple_keychain.h" |
14 #include "crypto/encryptor.h" | 16 #include "crypto/encryptor.h" |
15 #include "crypto/symmetric_key.h" | 17 #include "crypto/symmetric_key.h" |
16 | 18 |
17 using crypto::AppleKeychain; | 19 using crypto::AppleKeychain; |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 // Salt for Symmetric key derivation. | 23 // Salt for Symmetric key derivation. |
22 const char kSalt[] = "saltysalt"; | 24 const char kSalt[] = "saltysalt"; |
(...skipping 10 matching lines...) Expand all Loading... |
33 // Prefix for cypher text returned by current encryption version. We prefix | 35 // Prefix for cypher text returned by current encryption version. We prefix |
34 // the cypher text with this string so that future data migration can detect | 36 // the cypher text with this string so that future data migration can detect |
35 // this and migrate to different encryption without data loss. | 37 // this and migrate to different encryption without data loss. |
36 const char kEncryptionVersionPrefix[] = "v10"; | 38 const char kEncryptionVersionPrefix[] = "v10"; |
37 | 39 |
38 // Generates a newly allocated SymmetricKey object based on the password found | 40 // 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 | 41 // 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 | 42 // key is passed to the caller. Returns NULL key in the case password access |
41 // is denied or key generation error occurs. | 43 // is denied or key generation error occurs. |
42 crypto::SymmetricKey* GetEncryptionKey() { | 44 crypto::SymmetricKey* GetEncryptionKey() { |
| 45 static bool mock_keychain_command_line_flag = |
| 46 CommandLine::ForCurrentProcess()->HasSwitch( |
| 47 encryptor::switches::kUseMockKeychain); |
43 | 48 |
44 std::string password; | 49 std::string password; |
45 if (use_mock_keychain) { | 50 if (use_mock_keychain || mock_keychain_command_line_flag) { |
46 password = "mock_password"; | 51 password = "mock_password"; |
47 } else { | 52 } else { |
48 AppleKeychain keychain; | 53 AppleKeychain keychain; |
49 EncryptorPassword encryptor_password(keychain); | 54 EncryptorPassword encryptor_password(keychain); |
50 password = encryptor_password.GetEncryptorPassword(); | 55 password = encryptor_password.GetEncryptorPassword(); |
51 } | 56 } |
52 | 57 |
53 if (password.empty()) | 58 if (password.empty()) |
54 return NULL; | 59 return NULL; |
55 | 60 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 if (!encryptor.Decrypt(raw_ciphertext, plaintext)) | 146 if (!encryptor.Decrypt(raw_ciphertext, plaintext)) |
142 return false; | 147 return false; |
143 | 148 |
144 return true; | 149 return true; |
145 } | 150 } |
146 | 151 |
147 void Encryptor::UseMockKeychain(bool use_mock) { | 152 void Encryptor::UseMockKeychain(bool use_mock) { |
148 use_mock_keychain = use_mock; | 153 use_mock_keychain = use_mock; |
149 } | 154 } |
150 | 155 |
OLD | NEW |