Index: components/wifi/wifi_service_win.cc |
diff --git a/components/wifi/wifi_service_win.cc b/components/wifi/wifi_service_win.cc |
index e04a4008ea758f65b541d7ac91e728745d3ad2e3..90edaf5a2bab617a4d9ed62cb7e50ede91884b39 100644 |
--- a/components/wifi/wifi_service_win.cc |
+++ b/components/wifi/wifi_service_win.cc |
@@ -25,6 +25,8 @@ |
namespace { |
const char kWiFiServiceError[] = "Error.WiFiService"; |
+const char kWiFiServiceErrorNotImplemented[] = |
+ "Error.WiFiService.NotImplemented"; |
const wchar_t kNwCategoryWizardRegKey[] = |
L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Network\\" |
L"NwCategoryWizard"; |
@@ -208,6 +210,10 @@ class WiFiServiceImpl : public WiFiService { |
virtual void StartDisconnect(const std::string& network_guid, |
std::string* error) OVERRIDE; |
+ virtual void GetPassphraseFromSystem(const std::string& network_guid, |
+ std::string* passphrase, |
+ std::string* error) OVERRIDE; |
+ |
virtual void SetEventObservers( |
scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
const NetworkGuidListCallback& networks_changed_observer, |
@@ -635,6 +641,38 @@ void WiFiServiceImpl::StartDisconnect(const std::string& network_guid, |
CheckError(error_code, kWiFiServiceError, error); |
} |
+void WiFiServiceImpl::GetPassphraseFromSystem(const std::string& network_guid, |
+ std::string* passphrase, |
+ std::string* error) { |
+ DWORD error_code = EnsureInitialized(); |
+ if (CheckError(error_code, kWiFiServiceError, error)) |
+ return; |
+ |
+ std::string profile_xml; |
+ error_code = GetProfile(network_guid, &profile_xml); |
+ if (CheckError(error_code, kWiFiServiceError, error)) |
+ return; |
+ |
+ // Quick check to verify presence of <sharedKey> element. |
+ if (profile_xml.find("<sharedKey>") == std::string::npos) { |
+ *error = kWiFiServiceError; |
+ return; |
+ } |
+ |
+ XmlReader reader; |
+ if (reader.Load(profile_xml)) { |
+ while(reader.Read()) { |
+ reader.SkipToElement(); |
+ if (reader.NodeName() == "keyMaterial") { |
+ reader.ReadElementContent(passphrase); |
+ return; |
+ } |
+ } |
+ } |
+ // Did not find passphrase in the profile. |
+ *error = kWiFiServiceError; |
+} |
+ |
void WiFiServiceImpl::SetEventObservers( |
scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
const NetworkGuidListCallback& networks_changed_observer, |
@@ -1450,13 +1488,14 @@ DWORD WiFiServiceImpl::GetProfile(const std::string& network_guid, |
DWORD error = ERROR_SUCCESS; |
base::string16 profile_name = ProfileNameFromGUID(network_guid); |
+ DWORD flags = WLAN_PROFILE_GET_PLAINTEXT_KEY; |
LPWSTR str_profile_xml = NULL; |
error = WlanGetProfile_function_(client_, |
&interface_guid_, |
profile_name.c_str(), |
NULL, |
&str_profile_xml, |
- NULL, |
+ &flags, |
NULL); |
if (error == ERROR_SUCCESS && str_profile_xml != NULL) { |