Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Unified Diff: components/wifi/wifi_service_mac.mm

Issue 156943002: Add method GetKeyFromSystem to WiFiService on Windows and Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed compilation error on windows. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/wifi/wifi_service.h ('k') | components/wifi/wifi_service_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/wifi/wifi_service_mac.mm
diff --git a/components/wifi/wifi_service_mac.mm b/components/wifi/wifi_service_mac.mm
index ffe3846d8306de6ae7f35f424ccf8f45d2871016..fabc974ae8e59a68437618896c57f16388811cbb 100644
--- a/components/wifi/wifi_service_mac.mm
+++ b/components/wifi/wifi_service_mac.mm
@@ -9,6 +9,7 @@
#import <SystemConfiguration/SystemConfiguration.h>
#include "base/bind.h"
+#include "base/mac/foundation_util.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/mac/scoped_nsobject.h"
#include "base/message_loop/message_loop.h"
@@ -97,6 +98,10 @@ class WiFiServiceMac : public WiFiService {
virtual void StartDisconnect(const std::string& network_guid,
std::string* error) OVERRIDE;
+ virtual void GetKeyFromSystem(const std::string& network_guid,
+ std::string* key_data,
+ std::string* error) OVERRIDE;
+
virtual void SetEventObservers(
scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
const NetworkGuidListCallback& networks_changed_observer,
@@ -367,6 +372,33 @@ void WiFiServiceMac::StartDisconnect(const std::string& network_guid,
}
}
+void WiFiServiceMac::GetKeyFromSystem(const std::string& network_guid,
+ std::string* key_data,
+ std::string* error) {
+ static const char kAirPortServiceName[] = "AirPort";
+
+ UInt32 password_length = 0;
+ void *password_data = NULL;
+ OSStatus status = SecKeychainFindGenericPassword(NULL,
+ strlen(kAirPortServiceName),
+ kAirPortServiceName,
+ network_guid.length(),
+ network_guid.c_str(),
+ &password_length,
+ &password_data,
+ NULL);
+ if (status != errSecSuccess) {
+ *error = kErrorNotFound;
+ return;
+ }
+
+ if (password_data) {
+ *key_data = std::string(reinterpret_cast<char*>(password_data),
+ password_length);
+ SecKeychainItemFreeContent(NULL, password_data);
+ }
+}
+
void WiFiServiceMac::SetEventObservers(
scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
const NetworkGuidListCallback& networks_changed_observer,
« no previous file with comments | « components/wifi/wifi_service.h ('k') | components/wifi/wifi_service_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698