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

Side by Side 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: Address codereview comments. 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 GetKeyFromSystem(const std::string& network_guid,
101 bool get_plaintext_key,
102 std::string* key_data,
103 std::string* error) OVERRIDE;
104
100 virtual void SetEventObservers( 105 virtual void SetEventObservers(
101 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, 106 scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
102 const NetworkGuidListCallback& networks_changed_observer, 107 const NetworkGuidListCallback& networks_changed_observer,
103 const NetworkGuidListCallback& network_list_changed_observer) OVERRIDE; 108 const NetworkGuidListCallback& network_list_changed_observer) OVERRIDE;
104 109
105 virtual void RequestConnectedNetworkUpdate() OVERRIDE; 110 virtual void RequestConnectedNetworkUpdate() OVERRIDE;
106 111
107 private: 112 private:
108 // Checks |ns_error| and if is not |nil|, then stores |error_name| 113 // Checks |ns_error| and if is not |nil|, then stores |error_name|
109 // into |error|. 114 // into |error|.
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 NSError* ns_error = nil; 365 NSError* ns_error = nil;
361 [interface_ setPower:NO error:&ns_error]; 366 [interface_ setPower:NO error:&ns_error];
362 CheckError(ns_error, kErrorAssociateToNetwork, error); 367 CheckError(ns_error, kErrorAssociateToNetwork, error);
363 [interface_ setPower:YES error:&ns_error]; 368 [interface_ setPower:YES error:&ns_error];
364 CheckError(ns_error, kErrorAssociateToNetwork, error); 369 CheckError(ns_error, kErrorAssociateToNetwork, error);
365 } else { 370 } else {
366 *error = kErrorNotConnected; 371 *error = kErrorNotConnected;
367 } 372 }
368 } 373 }
369 374
375 void WiFiServiceMac::GetKeyFromSystem(const std::string& network_guid,
376 bool get_plaintext_key,
377 std::string* key_data,
378 std::string* error) {
379 static const char kAirPortServiceName[] = "AirPort";
380
381 UInt32 password_length = 0;
382 void *password_data = NULL;
383 OSStatus status = noErr;
384 if (get_plaintext_key) {
385 status = SecKeychainFindGenericPassword(NULL,
386 strlen(kAirPortServiceName),
387 kAirPortServiceName,
388 network_guid.length(),
389 network_guid.c_str(),
390 &password_length,
391 &password_data,
392 NULL);
393 } else {
394 status = SecKeychainFindGenericPassword(NULL,
395 strlen(kAirPortServiceName),
396 kAirPortServiceName,
397 network_guid.length(),
398 network_guid.c_str(),
399 NULL,
400 NULL,
401 NULL);
402 }
403
404 if (status != noErr) {
405 *error = kErrorNotFound;
406 return;
407 }
408
409 if (password_data) {
410 *key_data = std::string(reinterpret_cast<char*>(password_data),
411 password_length);
412 SecKeychainItemFreeContent(NULL, password_data);
413 }
414 }
415
370 void WiFiServiceMac::SetEventObservers( 416 void WiFiServiceMac::SetEventObservers(
371 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, 417 scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
372 const NetworkGuidListCallback& networks_changed_observer, 418 const NetworkGuidListCallback& networks_changed_observer,
373 const NetworkGuidListCallback& network_list_changed_observer) { 419 const NetworkGuidListCallback& network_list_changed_observer) {
374 message_loop_proxy_.swap(message_loop_proxy); 420 message_loop_proxy_.swap(message_loop_proxy);
375 networks_changed_observer_ = networks_changed_observer; 421 networks_changed_observer_ = networks_changed_observer;
376 network_list_changed_observer_ = network_list_changed_observer; 422 network_list_changed_observer_ = network_list_changed_observer;
377 423
378 // Remove previous OS notifications observer. 424 // Remove previous OS notifications observer.
379 if (wlan_observer_) { 425 if (wlan_observer_) {
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 NetworkGuidList changed_networks(1, network_guid); 640 NetworkGuidList changed_networks(1, network_guid);
595 message_loop_proxy_->PostTask( 641 message_loop_proxy_->PostTask(
596 FROM_HERE, 642 FROM_HERE,
597 base::Bind(networks_changed_observer_, changed_networks)); 643 base::Bind(networks_changed_observer_, changed_networks));
598 } 644 }
599 645
600 // static 646 // static
601 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); } 647 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); }
602 648
603 } // namespace wifi 649 } // namespace wifi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698