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

Side by Side Diff: components/wifi/wifi_service_mac.mm

Issue 102993002: Implement Networking Private API VerifyAndEncryptCredentials method (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Implement GetWiFiPasswordFromSystem on Mac. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/wifi/wifi_service.h" 5 #include "components/wifi/wifi_service.h"
6 6
7 #import <netinet/in.h> 7 #import <netinet/in.h>
8 #import <CoreWLAN/CoreWLAN.h> 8 #import <CoreWLAN/CoreWLAN.h>
9 #import <SystemConfiguration/SystemConfiguration.h> 9 #import <SystemConfiguration/SystemConfiguration.h>
10 10
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 base::ListValue* network_list) OVERRIDE; 90 base::ListValue* network_list) OVERRIDE;
91 91
92 virtual void RequestNetworkScan() OVERRIDE; 92 virtual void RequestNetworkScan() OVERRIDE;
93 93
94 virtual void StartConnect(const std::string& network_guid, 94 virtual void StartConnect(const std::string& network_guid,
95 std::string* error) OVERRIDE; 95 std::string* error) OVERRIDE;
96 96
97 virtual void StartDisconnect(const std::string& network_guid, 97 virtual void StartDisconnect(const std::string& network_guid,
98 std::string* error) OVERRIDE; 98 std::string* error) OVERRIDE;
99 99
100 virtual void GetPassphraseFromSystem(const std::string& network_guid,
101 std::string* passphrase,
102 std::string* error) OVERRIDE;
103
100 virtual void SetEventObservers( 104 virtual void SetEventObservers(
101 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, 105 scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
102 const NetworkGuidListCallback& networks_changed_observer, 106 const NetworkGuidListCallback& networks_changed_observer,
103 const NetworkGuidListCallback& network_list_changed_observer) OVERRIDE; 107 const NetworkGuidListCallback& network_list_changed_observer) OVERRIDE;
104 108
105 virtual void RequestConnectedNetworkUpdate() OVERRIDE; 109 virtual void RequestConnectedNetworkUpdate() OVERRIDE;
106 110
107 private: 111 private:
108 // Checks |ns_error| and if is not |nil|, then stores |error_name| 112 // Checks |ns_error| and if is not |nil|, then stores |error_name|
109 // into |error|. 113 // into |error|.
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 NSError* ns_error = nil; 364 NSError* ns_error = nil;
361 [interface_ setPower:NO error:&ns_error]; 365 [interface_ setPower:NO error:&ns_error];
362 CheckError(ns_error, kErrorAssociateToNetwork, error); 366 CheckError(ns_error, kErrorAssociateToNetwork, error);
363 [interface_ setPower:YES error:&ns_error]; 367 [interface_ setPower:YES error:&ns_error];
364 CheckError(ns_error, kErrorAssociateToNetwork, error); 368 CheckError(ns_error, kErrorAssociateToNetwork, error);
365 } else { 369 } else {
366 *error = kErrorNotConnected; 370 *error = kErrorNotConnected;
367 } 371 }
368 } 372 }
369 373
374 void WiFiServiceMac::GetPassphraseFromSystem(const std::string& network_guid,
375 std::string* passphrase,
376 std::string* error) {
377 const char kAirPortServiceName[] = "AirPort";
378
379 UInt32 password_length = 0;
380 void *password_data = nil;
381
382 OSStatus status = SecKeychainFindGenericPassword(NULL,
383 strlen(kAirPortServiceName),
384 kAirPortServiceName,
385 network_guid.length(),
386 network_guid.c_str(),
387 &password_length,
388 &password_data,
389 NULL);
390 if (status != noErr) {
391 *error = kErrorNotFound;
392 return;
393 }
394 *passphrase = std::string(reinterpret_cast<char*>(password_data),
395 password_length);
396 if (password_data)
397 SecKeychainItemFreeContent(NULL, password_data);
398 }
399
370 void WiFiServiceMac::SetEventObservers( 400 void WiFiServiceMac::SetEventObservers(
371 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, 401 scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
372 const NetworkGuidListCallback& networks_changed_observer, 402 const NetworkGuidListCallback& networks_changed_observer,
373 const NetworkGuidListCallback& network_list_changed_observer) { 403 const NetworkGuidListCallback& network_list_changed_observer) {
374 message_loop_proxy_.swap(message_loop_proxy); 404 message_loop_proxy_.swap(message_loop_proxy);
375 networks_changed_observer_ = networks_changed_observer; 405 networks_changed_observer_ = networks_changed_observer;
376 network_list_changed_observer_ = network_list_changed_observer; 406 network_list_changed_observer_ = network_list_changed_observer;
377 407
378 // Remove previous OS notifications observer. 408 // Remove previous OS notifications observer.
379 if (wlan_observer_) { 409 if (wlan_observer_) {
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 NetworkGuidList changed_networks(1, network_guid); 624 NetworkGuidList changed_networks(1, network_guid);
595 message_loop_proxy_->PostTask( 625 message_loop_proxy_->PostTask(
596 FROM_HERE, 626 FROM_HERE,
597 base::Bind(networks_changed_observer_, changed_networks)); 627 base::Bind(networks_changed_observer_, changed_networks));
598 } 628 }
599 629
600 // static 630 // static
601 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); } 631 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); }
602 632
603 } // namespace wifi 633 } // namespace wifi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698