Chromium Code Reviews| 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/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 Loading... | |
| 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 Loading... | |
| 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 const char kAirPortServiceName[] = "AirPort"; | |
|
arw
2014/02/06 20:51:30
Probably could be static?
mef
2014/02/06 21:53:43
Done.
| |
| 380 | |
| 381 UInt32 password_length = 0; | |
| 382 void *password_data = nil; | |
|
arw
2014/02/06 20:51:30
Not super familiar with ObjC++... but should passw
mef
2014/02/06 21:53:43
Done.
| |
| 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); | |
|
arw
2014/02/06 20:51:30
Do you mean to pass in an itemRef here and derive
mef
2014/02/06 21:53:43
Good point. My idea was to have a method of checki
arw
2014/02/07 23:25:29
Yeah, it is possible to see if the password exists
mef
2014/02/12 16:29:37
Done. SecKeychainFindGenericPassword with NULL out
arw
2014/02/12 17:41:50
Okay, I think I understand now. My final suggestio
mef
2014/02/12 22:26:21
Done. There is no immediate need for key existence
| |
| 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 Loading... | |
| 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 |
| OLD | NEW |