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 "chrome/browser/keychain_mac.h" | 12 #include "crypto/keychain_mac.h" |
13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
14 | 14 |
| 15 using crypto::MacKeychain; |
| 16 |
15 namespace { | 17 namespace { |
16 | 18 |
17 // 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 |
18 // 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 |
19 // returned. | 21 // returned. |
20 std::string AddRandomPasswordToKeychain(const MacKeychain& keychain, | 22 std::string AddRandomPasswordToKeychain(const MacKeychain& keychain, |
21 const std::string& service_name, | 23 const std::string& service_name, |
22 const std::string& account_name) { | 24 const std::string& account_name) { |
23 // Generate a password with 128 bits of randomness. | 25 // Generate a password with 128 bits of randomness. |
24 const int kBytes = 128 / 8; | 26 const int kBytes = 128 / 8; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 std::string(static_cast<char*>(password_data), password_length); | 71 std::string(static_cast<char*>(password_data), password_length); |
70 keychain_.ItemFreeContent(NULL, password_data); | 72 keychain_.ItemFreeContent(NULL, password_data); |
71 return password; | 73 return password; |
72 } else if (error == errSecItemNotFound) { | 74 } else if (error == errSecItemNotFound) { |
73 return AddRandomPasswordToKeychain(keychain_, service_name, account_name); | 75 return AddRandomPasswordToKeychain(keychain_, service_name, account_name); |
74 } else { | 76 } else { |
75 OSSTATUS_DLOG(ERROR, error) << "Keychain lookup failed"; | 77 OSSTATUS_DLOG(ERROR, error) << "Keychain lookup failed"; |
76 return std::string(); | 78 return std::string(); |
77 } | 79 } |
78 } | 80 } |
OLD | NEW |