OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/keychain_mac.h" | 9 #include "chrome/browser/keychain_mac.h" |
10 #include "chrome/browser/sync/util/crypto_helpers.h" | 10 #include "crypto/random.h" |
11 #include "ui/base/l10n/l10n_util.h" | 11 #include "ui/base/l10n/l10n_util.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 // Generates a random password and adds it to the Keychain. The added password | 15 // Generates a random password and adds it to the Keychain. The added password |
16 // is returned from the function. If an error occurs, an empty password is | 16 // is returned from the function. If an error occurs, an empty password is |
17 // returned. | 17 // returned. |
18 std::string AddRandomPasswordToKeychain(const MacKeychain& keychain, | 18 std::string AddRandomPasswordToKeychain(const MacKeychain& keychain, |
19 const std::string& service_name, | 19 const std::string& service_name, |
20 const std::string& account_name) { | 20 const std::string& account_name) { |
21 std::string password = Generate128BitRandomHexString(); | 21 std::string password = Generate128BitRandomBase64String(); |
22 void* password_data = | 22 void* password_data = |
23 const_cast<void*>(static_cast<const void*>(password.data())); | 23 const_cast<void*>(static_cast<const void*>(password.data())); |
24 | 24 |
25 OSStatus error = keychain.AddGenericPassword(NULL, | 25 OSStatus error = keychain.AddGenericPassword(NULL, |
26 service_name.size(), | 26 service_name.size(), |
27 service_name.data(), | 27 service_name.data(), |
28 account_name.size(), | 28 account_name.size(), |
29 account_name.data(), | 29 account_name.data(), |
30 password.size(), | 30 password.size(), |
31 password_data, | 31 password_data, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 return password; | 66 return password; |
67 } else if (error == errSecItemNotFound) { | 67 } else if (error == errSecItemNotFound) { |
68 return AddRandomPasswordToKeychain(keychain_, service_name, account_name); | 68 return AddRandomPasswordToKeychain(keychain_, service_name, account_name); |
69 } else { | 69 } else { |
70 DLOG(ERROR) << "Keychain lookup failed with error " << error; | 70 DLOG(ERROR) << "Keychain lookup failed with error " << error; |
71 return std::string(); | 71 return std::string(); |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 | 75 |
OLD | NEW |