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_password_mac.h" | 5 #include "chrome/browser/password_manager/encryptor_password_mac.h" |
6 | 6 |
7 #import <Security/Security.h> | 7 #import <Security/Security.h> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/mac/mac_logging.h" | 10 #include "base/mac/mac_logging.h" |
11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
12 #include "crypto/keychain_mac.h" | 12 #include "crypto/apple_keychain.h" |
13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
14 | 14 |
15 using crypto::MacKeychain; | 15 using crypto::AppleKeychain; |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // Generates a random password and adds it to the Keychain. The added password | 19 // Generates a random password and adds it to the Keychain. The added password |
20 // is returned from the function. If an error occurs, an empty password is | 20 // is returned from the function. If an error occurs, an empty password is |
21 // returned. | 21 // returned. |
22 std::string AddRandomPasswordToKeychain(const MacKeychain& keychain, | 22 std::string AddRandomPasswordToKeychain(const AppleKeychain& keychain, |
23 const std::string& service_name, | 23 const std::string& service_name, |
24 const std::string& account_name) { | 24 const std::string& account_name) { |
25 // Generate a password with 128 bits of randomness. | 25 // Generate a password with 128 bits of randomness. |
26 const int kBytes = 128 / 8; | 26 const int kBytes = 128 / 8; |
27 std::string password; | 27 std::string password; |
28 base::Base64Encode(base::RandBytesAsString(kBytes), &password); | 28 base::Base64Encode(base::RandBytesAsString(kBytes), &password); |
29 void* password_data = | 29 void* password_data = |
30 const_cast<void*>(static_cast<const void*>(password.data())); | 30 const_cast<void*>(static_cast<const void*>(password.data())); |
31 | 31 |
32 OSStatus error = keychain.AddGenericPassword(NULL, | 32 OSStatus error = keychain.AddGenericPassword(NULL, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 std::string(static_cast<char*>(password_data), password_length); | 71 std::string(static_cast<char*>(password_data), password_length); |
72 keychain_.ItemFreeContent(NULL, password_data); | 72 keychain_.ItemFreeContent(NULL, password_data); |
73 return password; | 73 return password; |
74 } else if (error == errSecItemNotFound) { | 74 } else if (error == errSecItemNotFound) { |
75 return AddRandomPasswordToKeychain(keychain_, service_name, account_name); | 75 return AddRandomPasswordToKeychain(keychain_, service_name, account_name); |
76 } else { | 76 } else { |
77 OSSTATUS_DLOG(ERROR, error) << "Keychain lookup failed"; | 77 OSSTATUS_DLOG(ERROR, error) << "Keychain lookup failed"; |
78 return std::string(); | 78 return std::string(); |
79 } | 79 } |
80 } | 80 } |
OLD | NEW |