OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chromeos/network/network_connection_handler.h" | 5 #include "chromeos/network/network_connection_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "chromeos/chromeos_switches.h" | 10 #include "chromeos/chromeos_switches.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 dest->SetStringWithoutPathExpansion(key, string_value); | 55 dest->SetStringWithoutPathExpansion(key, string_value); |
56 } | 56 } |
57 | 57 |
58 bool NetworkRequiresActivation(const NetworkState* network) { | 58 bool NetworkRequiresActivation(const NetworkState* network) { |
59 return (network->type() == flimflam::kTypeCellular && | 59 return (network->type() == flimflam::kTypeCellular && |
60 (network->activation_state() != flimflam::kActivationStateActivated || | 60 (network->activation_state() != flimflam::kActivationStateActivated || |
61 network->cellular_out_of_credits())); | 61 network->cellular_out_of_credits())); |
62 } | 62 } |
63 | 63 |
64 bool VPNIsConfigured(const std::string& service_path, | 64 bool VPNIsConfigured(const std::string& service_path, |
65 const base::DictionaryValue& service_properties) { | 65 const std::string& provider_type, |
66 // VPN Provider values are read from the "Provider" dictionary, not the | 66 const base::DictionaryValue& provider_properties) { |
67 // "Provider.Type", etc keys (which are used only to set the values). | |
68 const base::DictionaryValue* provider_properties; | |
69 if (!service_properties.GetDictionaryWithoutPathExpansion( | |
70 flimflam::kProviderProperty, &provider_properties)) { | |
71 NET_LOG_ERROR("VPN Provider Dictionary not present", service_path); | |
72 return false; | |
73 } | |
74 std::string provider_type; | |
75 if (!provider_properties->GetStringWithoutPathExpansion( | |
76 flimflam::kTypeProperty, &provider_type)) { | |
77 NET_LOG_ERROR("VPN Provider Type not present", service_path); | |
78 return false; | |
79 } | |
80 if (provider_type == flimflam::kProviderOpenVpn) { | 67 if (provider_type == flimflam::kProviderOpenVpn) { |
81 std::string hostname; | 68 std::string hostname; |
82 provider_properties->GetStringWithoutPathExpansion( | 69 provider_properties.GetStringWithoutPathExpansion( |
83 flimflam::kHostProperty, &hostname); | 70 flimflam::kHostProperty, &hostname); |
84 if (hostname.empty()) { | 71 if (hostname.empty()) { |
85 NET_LOG_EVENT("OpenVPN: No hostname", service_path); | 72 NET_LOG_EVENT("OpenVPN: No hostname", service_path); |
86 return false; | 73 return false; |
87 } | 74 } |
88 std::string username; | 75 std::string username; |
89 provider_properties->GetStringWithoutPathExpansion( | 76 provider_properties.GetStringWithoutPathExpansion( |
90 flimflam::kOpenVPNUserProperty, &username); | 77 flimflam::kOpenVPNUserProperty, &username); |
91 if (username.empty()) { | 78 if (username.empty()) { |
92 NET_LOG_EVENT("OpenVPN: No username", service_path); | 79 NET_LOG_EVENT("OpenVPN: No username", service_path); |
93 return false; | 80 return false; |
94 } | 81 } |
95 bool passphrase_required = false; | 82 bool passphrase_required = false; |
96 provider_properties->GetBooleanWithoutPathExpansion( | 83 provider_properties.GetBooleanWithoutPathExpansion( |
97 flimflam::kPassphraseRequiredProperty, &passphrase_required); | 84 flimflam::kPassphraseRequiredProperty, &passphrase_required); |
98 std::string passphrase; | 85 if (passphrase_required) { |
99 provider_properties->GetStringWithoutPathExpansion( | 86 NET_LOG_EVENT("OpenVPN: Passphrase Required", service_path); |
100 flimflam::kOpenVPNPasswordProperty, &passphrase); | |
101 if (passphrase_required && passphrase.empty()) { | |
102 NET_LOG_EVENT("OpenVPN: No passphrase", service_path); | |
103 return false; | 87 return false; |
104 } | 88 } |
105 NET_LOG_EVENT("OpenVPN Is Configured", service_path); | 89 NET_LOG_EVENT("OpenVPN Is Configured", service_path); |
106 } else { | 90 } else { |
107 bool passphrase_required = false; | 91 bool passphrase_required = false; |
108 std::string passphrase; | 92 std::string passphrase; |
109 provider_properties->GetBooleanWithoutPathExpansion( | 93 provider_properties.GetBooleanWithoutPathExpansion( |
110 flimflam::kL2tpIpsecPskRequiredProperty, &passphrase_required); | 94 flimflam::kL2tpIpsecPskRequiredProperty, &passphrase_required); |
111 provider_properties->GetStringWithoutPathExpansion( | 95 if (passphrase_required) { |
112 flimflam::kL2tpIpsecPskProperty, &passphrase); | 96 NET_LOG_EVENT("VPN: Passphrase Required", service_path); |
113 if (passphrase_required && passphrase.empty()) | |
114 return false; | 97 return false; |
98 } | |
115 NET_LOG_EVENT("VPN Is Configured", service_path); | 99 NET_LOG_EVENT("VPN Is Configured", service_path); |
116 } | 100 } |
117 return true; | 101 return true; |
118 } | 102 } |
119 | 103 |
120 } // namespace | 104 } // namespace |
121 | 105 |
122 const char NetworkConnectionHandler::kErrorNotFound[] = "not-found"; | 106 const char NetworkConnectionHandler::kErrorNotFound[] = "not-found"; |
123 const char NetworkConnectionHandler::kErrorConnected[] = "connected"; | 107 const char NetworkConnectionHandler::kErrorConnected[] = "connected"; |
124 const char NetworkConnectionHandler::kErrorConnecting[] = "connecting"; | 108 const char NetworkConnectionHandler::kErrorConnecting[] = "connecting"; |
125 const char NetworkConnectionHandler::kErrorNotConnected[] = "not-connected"; | 109 const char NetworkConnectionHandler::kErrorNotConnected[] = "not-connected"; |
126 const char NetworkConnectionHandler::kErrorPassphraseRequired[] = | 110 const char NetworkConnectionHandler::kErrorPassphraseRequired[] = |
127 "passphrase-required"; | 111 "passphrase-required"; |
128 const char NetworkConnectionHandler::kErrorActivationRequired[] = | 112 const char NetworkConnectionHandler::kErrorActivationRequired[] = |
129 "activation-required"; | 113 "activation-required"; |
130 const char NetworkConnectionHandler::kErrorCertificateRequired[] = | 114 const char NetworkConnectionHandler::kErrorCertificateRequired[] = |
131 "certificate-required"; | 115 "certificate-required"; |
132 const char NetworkConnectionHandler::kErrorConfigurationRequired[] = | 116 const char NetworkConnectionHandler::kErrorConfigurationRequired[] = |
133 "configuration-required"; | 117 "configuration-required"; |
134 const char NetworkConnectionHandler::kErrorAuthenticationRequired[] = | 118 const char NetworkConnectionHandler::kErrorAuthenticationRequired[] = |
135 "authentication-required"; | 119 "authentication-required"; |
136 const char NetworkConnectionHandler::kErrorShillError[] = "shill-error"; | 120 const char NetworkConnectionHandler::kErrorShillError[] = "shill-error"; |
137 const char NetworkConnectionHandler::kErrorConnectFailed[] = "connect-failed"; | 121 const char NetworkConnectionHandler::kErrorConnectFailed[] = "connect-failed"; |
138 const char NetworkConnectionHandler::kErrorDisconnectFailed[] = | |
139 "disconnect-failed"; | |
140 const char NetworkConnectionHandler::kErrorMissingProviderType[] = | 122 const char NetworkConnectionHandler::kErrorMissingProviderType[] = |
141 "missing-provider-type"; | 123 "missing-provider-type"; |
142 const char NetworkConnectionHandler::kErrorUnknown[] = "unknown-error"; | 124 const char NetworkConnectionHandler::kErrorUnknown[] = "unknown-error"; |
143 | 125 |
144 struct NetworkConnectionHandler::ConnectRequest { | 126 struct NetworkConnectionHandler::ConnectRequest { |
145 ConnectRequest(const std::string& service_path, | 127 ConnectRequest(const std::string& service_path, |
146 const base::Closure& success, | 128 const base::Closure& success, |
147 const network_handler::ErrorCallback& error) | 129 const network_handler::ErrorCallback& error) |
148 : service_path(service_path), | 130 : service_path(service_path), |
149 connect_state(CONNECT_REQUESTED), | 131 connect_state(CONNECT_REQUESTED), |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 } | 178 } |
197 if (network_state_handler) { | 179 if (network_state_handler) { |
198 network_state_handler_ = network_state_handler; | 180 network_state_handler_ = network_state_handler; |
199 network_state_handler_->AddObserver(this, FROM_HERE); | 181 network_state_handler_->AddObserver(this, FROM_HERE); |
200 } | 182 } |
201 network_configuration_handler_ = network_configuration_handler; | 183 network_configuration_handler_ = network_configuration_handler; |
202 } | 184 } |
203 | 185 |
204 void NetworkConnectionHandler::LoggedInStateChanged( | 186 void NetworkConnectionHandler::LoggedInStateChanged( |
205 LoginState::LoggedInState state) { | 187 LoginState::LoggedInState state) { |
206 NET_LOG_EVENT("NewNetworkConnectionHandler", | |
207 CommandLine::ForCurrentProcess()->HasSwitch( | |
208 chromeos::switches::kUseNewNetworkConnectionHandler) ? | |
209 "enabled" : "disabled"); | |
210 if (state == LoginState::LOGGED_IN_ACTIVE) { | 188 if (state == LoginState::LOGGED_IN_ACTIVE) { |
211 logged_in_ = true; | 189 logged_in_ = true; |
212 NET_LOG_EVENT("Logged In", ""); | 190 NET_LOG_EVENT("Logged In", ""); |
213 } | 191 } |
214 } | 192 } |
215 | 193 |
216 void NetworkConnectionHandler::OnCertificatesLoaded( | 194 void NetworkConnectionHandler::OnCertificatesLoaded( |
217 const net::CertificateList& cert_list, | 195 const net::CertificateList& cert_list, |
218 bool initial_load) { | 196 bool initial_load) { |
219 certificates_loaded_ = true; | 197 certificates_loaded_ = true; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); | 287 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); |
310 return; | 288 return; |
311 } | 289 } |
312 if (!network->IsConnectedState()) { | 290 if (!network->IsConnectedState()) { |
313 InvokeErrorCallback(service_path, error_callback, kErrorNotConnected); | 291 InvokeErrorCallback(service_path, error_callback, kErrorNotConnected); |
314 return; | 292 return; |
315 } | 293 } |
316 CallShillDisconnect(service_path, success_callback, error_callback); | 294 CallShillDisconnect(service_path, success_callback, error_callback); |
317 } | 295 } |
318 | 296 |
297 void NetworkConnectionHandler::ActivateNetwork( | |
298 const std::string& service_path, | |
299 const std::string& carrier, | |
300 const base::Closure& success_callback, | |
301 const network_handler::ErrorCallback& error_callback) { | |
302 NET_LOG_USER("DisconnectNetwork", service_path); | |
303 const NetworkState* network = | |
304 network_state_handler_->GetNetworkState(service_path); | |
305 if (!network) { | |
306 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); | |
307 return; | |
308 } | |
309 CallShillActivate(service_path, carrier, success_callback, error_callback); | |
310 } | |
311 | |
319 bool NetworkConnectionHandler::HasConnectingNetwork( | 312 bool NetworkConnectionHandler::HasConnectingNetwork( |
320 const std::string& service_path) { | 313 const std::string& service_path) { |
321 return pending_requests_.count(service_path) != 0; | 314 return pending_requests_.count(service_path) != 0; |
322 } | 315 } |
323 | 316 |
324 void NetworkConnectionHandler::NetworkListChanged() { | 317 void NetworkConnectionHandler::NetworkListChanged() { |
325 CheckAllPendingRequests(); | 318 CheckAllPendingRequests(); |
326 } | 319 } |
327 | 320 |
328 void NetworkConnectionHandler::NetworkPropertiesUpdated( | 321 void NetworkConnectionHandler::NetworkPropertiesUpdated( |
(...skipping 11 matching lines...) Expand all Loading... | |
340 } | 333 } |
341 | 334 |
342 // ConnectToNetwork implementation | 335 // ConnectToNetwork implementation |
343 | 336 |
344 void NetworkConnectionHandler::VerifyConfiguredAndConnect( | 337 void NetworkConnectionHandler::VerifyConfiguredAndConnect( |
345 bool check_error_state, | 338 bool check_error_state, |
346 const std::string& service_path, | 339 const std::string& service_path, |
347 const base::DictionaryValue& service_properties) { | 340 const base::DictionaryValue& service_properties) { |
348 NET_LOG_EVENT("VerifyConfiguredAndConnect", service_path); | 341 NET_LOG_EVENT("VerifyConfiguredAndConnect", service_path); |
349 | 342 |
350 std::string type; | 343 std::string type, security; |
351 service_properties.GetStringWithoutPathExpansion( | 344 service_properties.GetStringWithoutPathExpansion( |
352 flimflam::kTypeProperty, &type); | 345 flimflam::kTypeProperty, &type); |
346 service_properties.GetStringWithoutPathExpansion( | |
347 flimflam::kSecurityProperty, &security); | |
353 | 348 |
354 if (check_error_state) { | 349 if (check_error_state) { |
355 std::string error; | 350 std::string error; |
356 service_properties.GetStringWithoutPathExpansion( | 351 service_properties.GetStringWithoutPathExpansion( |
357 flimflam::kErrorProperty, &error); | 352 flimflam::kErrorProperty, &error); |
358 if (error == flimflam::kErrorConnectFailed) { | 353 if (error == flimflam::kErrorConnectFailed) { |
359 ErrorCallbackForPendingRequest(service_path, kErrorPassphraseRequired); | 354 ErrorCallbackForPendingRequest(service_path, kErrorPassphraseRequired); |
360 return; | 355 return; |
361 } | 356 } |
362 if (error == flimflam::kErrorBadPassphrase) { | 357 if (error == flimflam::kErrorBadPassphrase) { |
(...skipping 11 matching lines...) Expand all Loading... | |
374 // If 'passphrase_required' is still true, then the 'Passphrase' property | 369 // If 'passphrase_required' is still true, then the 'Passphrase' property |
375 // has not been set to a minimum length value. | 370 // has not been set to a minimum length value. |
376 bool passphrase_required = false; | 371 bool passphrase_required = false; |
377 service_properties.GetBooleanWithoutPathExpansion( | 372 service_properties.GetBooleanWithoutPathExpansion( |
378 flimflam::kPassphraseRequiredProperty, &passphrase_required); | 373 flimflam::kPassphraseRequiredProperty, &passphrase_required); |
379 if (passphrase_required) { | 374 if (passphrase_required) { |
380 ErrorCallbackForPendingRequest(service_path, kErrorPassphraseRequired); | 375 ErrorCallbackForPendingRequest(service_path, kErrorPassphraseRequired); |
381 return; | 376 return; |
382 } | 377 } |
383 | 378 |
384 // VPN requires a host and username to be set. | 379 // Get VPN provider type and host (required for configuration) and ensure |
385 if (type == flimflam::kTypeVPN && | 380 // that required VPN non-cert properties are set. |
386 !VPNIsConfigured(service_path, service_properties)) { | 381 std::string vpn_provider_type, vpn_provider_host; |
387 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); | 382 if (type == flimflam::kTypeVPN) { |
388 return; | 383 const base::DictionaryValue* provider_properties; |
384 if (service_properties.GetDictionaryWithoutPathExpansion( | |
385 flimflam::kProviderProperty, &provider_properties)) { | |
386 provider_properties->GetStringWithoutPathExpansion( | |
387 flimflam::kTypeProperty, &vpn_provider_type); | |
388 provider_properties->GetStringWithoutPathExpansion( | |
gauravsh
2013/08/02 23:40:22
Ok if there's no vpn_provider_host?
stevenjb
2013/08/06 00:32:48
Probably not. Fixed.
| |
389 flimflam::kHostProperty, &vpn_provider_host); | |
390 } | |
391 if (vpn_provider_type.empty()) { | |
392 ErrorCallbackForPendingRequest(service_path, kErrorMissingProviderType); | |
393 return; | |
394 } | |
395 // VPN requires a host and username to be set. | |
396 if (!VPNIsConfigured( | |
397 service_path, vpn_provider_type, *provider_properties)) { | |
398 NET_LOG_ERROR("VPN Not Configured", service_path); | |
399 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); | |
400 return; | |
401 } | |
389 } | 402 } |
390 | 403 |
391 // Check certificate properties in kUIDataProperty. | 404 base::DictionaryValue config_properties; |
405 | |
406 // Check certificate properties in kUIDataProperty if configured. | |
407 // Note: Wifi/VPNConfigView set these properties explicitly. | |
392 scoped_ptr<NetworkUIData> ui_data = | 408 scoped_ptr<NetworkUIData> ui_data = |
393 ManagedNetworkConfigurationHandler::GetUIData(service_properties); | 409 ManagedNetworkConfigurationHandler::GetUIData(service_properties); |
394 if (ui_data && ui_data->certificate_type() == CLIENT_CERT_TYPE_PATTERN) { | 410 if (ui_data && ui_data->certificate_type() == CLIENT_CERT_TYPE_PATTERN) { |
395 // User must be logged in to connect to a network requiring a certificate. | 411 // User must be logged in to connect to a network requiring a certificate. |
396 if (!logged_in_ || !cert_loader_) { | 412 if (!logged_in_ || !cert_loader_) { |
397 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); | 413 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); |
398 return; | 414 return; |
399 } | 415 } |
416 | |
400 // If certificates have not been loaded yet, queue the connect request. | 417 // If certificates have not been loaded yet, queue the connect request. |
401 if (!certificates_loaded_) { | 418 if (!certificates_loaded_) { |
402 ConnectRequest* request = pending_request(service_path); | 419 ConnectRequest* request = pending_request(service_path); |
403 DCHECK(request); | 420 DCHECK(request); |
404 NET_LOG_EVENT("Connect Request Queued", service_path); | 421 NET_LOG_EVENT("Connect Request Queued", service_path); |
405 queued_connect_.reset(new ConnectRequest( | 422 queued_connect_.reset(new ConnectRequest( |
406 service_path, request->success_callback, request->error_callback)); | 423 service_path, request->success_callback, request->error_callback)); |
407 pending_requests_.erase(service_path); | 424 pending_requests_.erase(service_path); |
408 return; | 425 return; |
409 } | 426 } |
410 | 427 |
411 // Ensure the certificate is available. | 428 // Ensure the certificate is available and configured. |
412 std::string pkcs11_id; | 429 std::string pkcs11_id; |
413 if (!CertificateIsConfigured(ui_data.get(), &pkcs11_id)) { | 430 if (!CertificateIsConfigured(ui_data.get(), &pkcs11_id)) { |
414 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); | 431 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); |
415 return; | 432 return; |
416 } | 433 } |
417 | 434 |
418 // The network may not be 'Connectable' because the certificate data is | 435 if (type == flimflam::kTypeVPN) { |
gauravsh
2013/08/02 23:40:22
Lets make all property settings for a given type-v
stevenjb
2013/08/06 00:32:48
Yeah, getting this all right was a bit tricky, bit
| |
419 // not set up, so configure tpm slot/pin and pkcs11_id before connecting. | 436 if (vpn_provider_type == flimflam::kProviderOpenVpn) { |
420 // TODO(stevenjb): Remove this code once NetworkConfigurationHandler | 437 config_properties.SetStringWithoutPathExpansion( |
421 // handles this. | 438 flimflam::kOpenVPNClientCertIdProperty, pkcs11_id); |
422 NET_LOG_EVENT("Configuring Network", service_path); | 439 } else { |
440 config_properties.SetStringWithoutPathExpansion( | |
441 flimflam::kL2tpIpsecClientCertIdProperty, pkcs11_id); | |
442 } | |
443 } else if (type == flimflam::kTypeWifi) { | |
444 config_properties.SetStringWithoutPathExpansion( | |
445 flimflam::kEapCertIdProperty, pkcs11_id); | |
446 config_properties.SetStringWithoutPathExpansion( | |
447 flimflam::kEapKeyIdProperty, pkcs11_id); | |
448 } | |
449 } | |
450 | |
451 // The network may not be 'Connectable' because the TPM properties are | |
452 // not set up, so configure tpm slot/pin before connecting. | |
453 if (cert_loader_ && | |
454 (type == flimflam::kTypeVPN || | |
455 (type == flimflam::kTypeWifi && security == flimflam::kSecurity8021x))) { | |
423 const std::string& tpm_slot = cert_loader_->tpm_token_slot(); | 456 const std::string& tpm_slot = cert_loader_->tpm_token_slot(); |
424 const std::string& tpm_pin = cert_loader_->tpm_user_pin(); | 457 const std::string& tpm_pin = cert_loader_->tpm_user_pin(); |
425 base::DictionaryValue config_properties; | 458 if (type == flimflam::kTypeVPN) { |
459 // VPN Provider values are read from the "Provider" dictionary, not the | |
460 // "Provider.Type", etc keys (which are used only to set the values). | |
461 if (vpn_provider_type == flimflam::kProviderOpenVpn) { | |
462 // config_properties.SetStringWithoutPathExpansion( | |
463 // flimflam::kOpenVPNClientCertSlotProperty, tpm_slot); | |
464 config_properties.SetStringWithoutPathExpansion( | |
465 flimflam::kOpenVPNPinProperty, tpm_pin); | |
466 } else { | |
467 config_properties.SetStringWithoutPathExpansion( | |
468 flimflam::kL2tpIpsecClientCertSlotProperty, tpm_slot); | |
469 config_properties.SetStringWithoutPathExpansion( | |
470 flimflam::kL2tpIpsecPinProperty, tpm_pin); | |
471 } | |
472 } else if (type == flimflam::kTypeWifi) { | |
473 config_properties.SetStringWithoutPathExpansion( | |
474 flimflam::kEapPinProperty, cert_loader_->tpm_user_pin()); | |
475 } | |
476 } | |
477 | |
478 if (!config_properties.empty()) { | |
479 NET_LOG_EVENT("Configuring Network", service_path); | |
480 | |
426 // Set configuration properties required by Shill to identify the network. | 481 // Set configuration properties required by Shill to identify the network. |
427 config_properties.SetStringWithoutPathExpansion( | 482 config_properties.SetStringWithoutPathExpansion( |
428 flimflam::kTypeProperty, type); | 483 flimflam::kTypeProperty, type); |
429 CopyStringFromDictionary(service_properties, flimflam::kNameProperty, | 484 CopyStringFromDictionary(service_properties, flimflam::kNameProperty, |
430 &config_properties); | 485 &config_properties); |
431 CopyStringFromDictionary(service_properties, flimflam::kSecurityProperty, | |
432 &config_properties); | |
433 CopyStringFromDictionary(service_properties, flimflam::kGuidProperty, | 486 CopyStringFromDictionary(service_properties, flimflam::kGuidProperty, |
434 &config_properties); | 487 &config_properties); |
435 | |
436 if (type == flimflam::kTypeVPN) { | 488 if (type == flimflam::kTypeVPN) { |
437 // VPN Provider values are read from the "Provider" dictionary, not the | 489 config_properties.SetStringWithoutPathExpansion( |
438 // "Provider.Type", etc keys (which are used only to set the values). | 490 flimflam::kProviderTypeProperty, vpn_provider_type); |
439 std::string provider_type; | 491 config_properties.SetStringWithoutPathExpansion( |
440 const base::DictionaryValue* provider_properties; | 492 flimflam::kProviderHostProperty, vpn_provider_host); |
441 if (service_properties.GetDictionaryWithoutPathExpansion( | |
442 flimflam::kProviderProperty, &provider_properties)) { | |
443 provider_properties->GetStringWithoutPathExpansion( | |
444 flimflam::kTypeProperty, &provider_type); | |
445 } | |
446 if (provider_type.empty()) { | |
447 ErrorCallbackForPendingRequest(service_path, kErrorMissingProviderType); | |
448 return; | |
449 } | |
450 if (provider_type == flimflam::kProviderOpenVpn) { | |
451 config_properties.SetStringWithoutPathExpansion( | |
452 flimflam::kOpenVPNClientCertSlotProperty, tpm_slot); | |
453 config_properties.SetStringWithoutPathExpansion( | |
454 flimflam::kOpenVPNPinProperty, tpm_pin); | |
455 config_properties.SetStringWithoutPathExpansion( | |
456 flimflam::kOpenVPNClientCertIdProperty, pkcs11_id); | |
457 } else { | |
458 config_properties.SetStringWithoutPathExpansion( | |
459 flimflam::kL2tpIpsecClientCertSlotProperty, tpm_slot); | |
460 config_properties.SetStringWithoutPathExpansion( | |
461 flimflam::kL2tpIpsecPinProperty, tpm_pin); | |
462 config_properties.SetStringWithoutPathExpansion( | |
463 flimflam::kL2tpIpsecClientCertIdProperty, pkcs11_id); | |
464 } | |
465 } else if (type == flimflam::kTypeWifi) { | 493 } else if (type == flimflam::kTypeWifi) { |
466 config_properties.SetStringWithoutPathExpansion( | 494 config_properties.SetStringWithoutPathExpansion( |
467 flimflam::kEapPinProperty, cert_loader_->tpm_user_pin()); | 495 flimflam::kSecurityProperty, security); |
468 config_properties.SetStringWithoutPathExpansion( | |
469 flimflam::kEapCertIdProperty, pkcs11_id); | |
470 config_properties.SetStringWithoutPathExpansion( | |
471 flimflam::kEapKeyIdProperty, pkcs11_id); | |
472 } | 496 } |
497 | |
473 network_configuration_handler_->SetProperties( | 498 network_configuration_handler_->SetProperties( |
474 service_path, | 499 service_path, |
475 config_properties, | 500 config_properties, |
476 base::Bind(&NetworkConnectionHandler::CallShillConnect, | 501 base::Bind(&NetworkConnectionHandler::CallShillConnect, |
477 AsWeakPtr(), service_path), | 502 AsWeakPtr(), service_path), |
478 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, | 503 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, |
479 AsWeakPtr(), service_path)); | 504 AsWeakPtr(), service_path)); |
480 return; | 505 return; |
481 } | 506 } |
482 | 507 |
483 // Otherwise, we need to configure the network. | 508 // Otherwise, we probably still need to configure the network since |
484 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); | 509 // 'Connectable' is false. If |check_error_state| is true, signal an |
510 // error, otherwise attempt to connect to possibly gain additional error | |
511 // state from Shill (or in case 'Connectable' is improperly unset). | |
512 if (check_error_state) | |
513 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); | |
514 else | |
515 CallShillConnect(service_path); | |
485 } | 516 } |
486 | 517 |
487 void NetworkConnectionHandler::CallShillConnect( | 518 void NetworkConnectionHandler::CallShillConnect( |
488 const std::string& service_path) { | 519 const std::string& service_path) { |
489 NET_LOG_EVENT("Sending Connect Request to Shill", service_path); | 520 NET_LOG_EVENT("Sending Connect Request to Shill", service_path); |
490 DBusThreadManager::Get()->GetShillServiceClient()->Connect( | 521 DBusThreadManager::Get()->GetShillServiceClient()->Connect( |
491 dbus::ObjectPath(service_path), | 522 dbus::ObjectPath(service_path), |
492 base::Bind(&NetworkConnectionHandler::HandleShillConnectSuccess, | 523 base::Bind(&NetworkConnectionHandler::HandleShillConnectSuccess, |
493 AsWeakPtr(), service_path), | 524 AsWeakPtr(), service_path), |
494 base::Bind(&NetworkConnectionHandler::HandleShillConnectFailure, | 525 base::Bind(&NetworkConnectionHandler::HandleShillConnectFailure, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
620 void NetworkConnectionHandler::CallShillDisconnect( | 651 void NetworkConnectionHandler::CallShillDisconnect( |
621 const std::string& service_path, | 652 const std::string& service_path, |
622 const base::Closure& success_callback, | 653 const base::Closure& success_callback, |
623 const network_handler::ErrorCallback& error_callback) { | 654 const network_handler::ErrorCallback& error_callback) { |
624 NET_LOG_USER("Disconnect Request", service_path); | 655 NET_LOG_USER("Disconnect Request", service_path); |
625 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect( | 656 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect( |
626 dbus::ObjectPath(service_path), | 657 dbus::ObjectPath(service_path), |
627 base::Bind(&NetworkConnectionHandler::HandleShillDisconnectSuccess, | 658 base::Bind(&NetworkConnectionHandler::HandleShillDisconnectSuccess, |
628 AsWeakPtr(), service_path, success_callback), | 659 AsWeakPtr(), service_path, success_callback), |
629 base::Bind(&network_handler::ShillErrorCallbackFunction, | 660 base::Bind(&network_handler::ShillErrorCallbackFunction, |
630 kErrorDisconnectFailed, service_path, error_callback)); | 661 kErrorShillError, service_path, error_callback)); |
631 } | 662 } |
632 | 663 |
633 void NetworkConnectionHandler::HandleShillDisconnectSuccess( | 664 void NetworkConnectionHandler::HandleShillDisconnectSuccess( |
634 const std::string& service_path, | 665 const std::string& service_path, |
635 const base::Closure& success_callback) { | 666 const base::Closure& success_callback) { |
636 NET_LOG_EVENT("Disconnect Request Sent", service_path); | 667 NET_LOG_EVENT("Disconnect Request Sent", service_path); |
637 if (!success_callback.is_null()) | 668 if (!success_callback.is_null()) |
638 success_callback.Run(); | 669 success_callback.Run(); |
639 } | 670 } |
640 | 671 |
672 // Activate | |
673 | |
674 void NetworkConnectionHandler::CallShillActivate( | |
675 const std::string& service_path, | |
676 const std::string& carrier, | |
677 const base::Closure& success_callback, | |
678 const network_handler::ErrorCallback& error_callback) { | |
679 NET_LOG_USER("Activate Request", service_path + ": '" + carrier + "'"); | |
680 DBusThreadManager::Get()->GetShillServiceClient()->ActivateCellularModem( | |
681 dbus::ObjectPath(service_path), | |
682 carrier, | |
683 base::Bind(&NetworkConnectionHandler::HandleShillActivateSuccess, | |
684 AsWeakPtr(), service_path, success_callback), | |
685 base::Bind(&network_handler::ShillErrorCallbackFunction, | |
686 kErrorShillError, service_path, error_callback)); | |
687 } | |
688 | |
689 void NetworkConnectionHandler::HandleShillActivateSuccess( | |
690 const std::string& service_path, | |
691 const base::Closure& success_callback) { | |
692 NET_LOG_EVENT("Activate Request Sent", service_path); | |
693 if (!success_callback.is_null()) | |
694 success_callback.Run(); | |
695 } | |
696 | |
641 } // namespace chromeos | 697 } // namespace chromeos |
OLD | NEW |