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/os_crypt/keychain_password_mac.h" | 5 #include "components/os_crypt/keychain_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" |
(...skipping 29 matching lines...) Expand all Loading... | |
40 if (error != noErr) { | 40 if (error != noErr) { |
41 OSSTATUS_DLOG(ERROR, error) << "Keychain add failed"; | 41 OSSTATUS_DLOG(ERROR, error) << "Keychain add failed"; |
42 return std::string(); | 42 return std::string(); |
43 } | 43 } |
44 | 44 |
45 return password; | 45 return password; |
46 } | 46 } |
47 | 47 |
48 } // namespace | 48 } // namespace |
49 | 49 |
50 std::string KeychainPassword::GetPassword() const { | 50 // These two strings ARE indeed user facing. But they are used to access |
51 // These two strings ARE indeed user facing. But they are used to access | 51 // the encryption keyword. So as to not lose encrypted data when system |
52 // the encryption keyword. So as to not lose encrypted data when system | 52 // locale changes we DO NOT LOCALIZE. |
53 // locale changes we DO NOT LOCALIZE. | |
54 #if defined(GOOGLE_CHROME_BUILD) | 53 #if defined(GOOGLE_CHROME_BUILD) |
55 const std::string service_name = "Chrome Safe Storage"; | 54 const char KeychainPassword::service_name[] = "Chrome Safe Storage"; |
56 const std::string account_name = "Chrome"; | 55 const char KeychainPassword::account_name[] = "Chrome"; |
57 #else | 56 #else |
58 const std::string service_name = "Chromium Safe Storage"; | 57 const char KeychainPassword::service_name[] = "Chromium Safe Storage"; |
59 const std::string account_name = "Chromium"; | 58 const char KeychainPassword::account_name[] = "Chromium"; |
60 #endif | 59 #endif |
61 | 60 |
61 std::string KeychainPassword::GetPassword() const { | |
62 UInt32 password_length = 0; | 62 UInt32 password_length = 0; |
63 void* password_data = NULL; | 63 void* password_data = NULL; |
64 OSStatus error = keychain_.FindGenericPassword(NULL, | 64 OSStatus error = keychain_.FindGenericPassword( |
Mark Mentovai
2017/03/01 22:00:31
Again with the clang-format? “Before” was so much
Greg K
2017/03/02 01:28:27
Done.
| |
65 service_name.size(), | 65 NULL, strlen(service_name), service_name, strlen(account_name), |
66 service_name.data(), | 66 account_name, &password_length, &password_data, NULL); |
67 account_name.size(), | |
68 account_name.data(), | |
69 &password_length, | |
70 &password_data, | |
71 NULL); | |
72 | 67 |
73 if (error == noErr) { | 68 if (error == noErr) { |
74 std::string password = | 69 std::string password = |
75 std::string(static_cast<char*>(password_data), password_length); | 70 std::string(static_cast<char*>(password_data), password_length); |
76 keychain_.ItemFreeContent(NULL, password_data); | 71 keychain_.ItemFreeContent(NULL, password_data); |
77 return password; | 72 return password; |
78 } else if (error == errSecItemNotFound) { | 73 } else if (error == errSecItemNotFound) { |
79 return AddRandomPasswordToKeychain(keychain_, service_name, account_name); | 74 return AddRandomPasswordToKeychain(keychain_, service_name, account_name); |
80 } else { | 75 } else { |
81 OSSTATUS_DLOG(ERROR, error) << "Keychain lookup failed"; | 76 OSSTATUS_DLOG(ERROR, error) << "Keychain lookup failed"; |
82 return std::string(); | 77 return std::string(); |
83 } | 78 } |
84 } | 79 } |
OLD | NEW |