| 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 "base/location.h" | 10 #include "base/location.h" |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 // been recently configured), we need to check Connectable again. | 367 // been recently configured), we need to check Connectable again. |
| 368 if (connectable && type != shill::kTypeVPN) { | 368 if (connectable && type != shill::kTypeVPN) { |
| 369 // TODO(stevenjb): Shill needs to properly set Connectable for VPN. | 369 // TODO(stevenjb): Shill needs to properly set Connectable for VPN. |
| 370 CallShillConnect(service_path); | 370 CallShillConnect(service_path); |
| 371 return; | 371 return; |
| 372 } | 372 } |
| 373 | 373 |
| 374 // Get VPN provider type and host (required for configuration) and ensure | 374 // Get VPN provider type and host (required for configuration) and ensure |
| 375 // that required VPN non-cert properties are set. | 375 // that required VPN non-cert properties are set. |
| 376 const base::DictionaryValue* provider_properties = NULL; | 376 const base::DictionaryValue* provider_properties = NULL; |
| 377 std::string vpn_provider_type, vpn_provider_host; | 377 std::string vpn_provider_type, vpn_provider_host, vpn_client_cert_id; |
| 378 if (type == shill::kTypeVPN) { | 378 if (type == shill::kTypeVPN) { |
| 379 // VPN Provider values are read from the "Provider" dictionary, not the | 379 // VPN Provider values are read from the "Provider" dictionary, not the |
| 380 // "Provider.Type", etc keys (which are used only to set the values). | 380 // "Provider.Type", etc keys (which are used only to set the values). |
| 381 if (service_properties.GetDictionaryWithoutPathExpansion( | 381 if (service_properties.GetDictionaryWithoutPathExpansion( |
| 382 shill::kProviderProperty, &provider_properties)) { | 382 shill::kProviderProperty, &provider_properties)) { |
| 383 provider_properties->GetStringWithoutPathExpansion( | 383 provider_properties->GetStringWithoutPathExpansion( |
| 384 shill::kTypeProperty, &vpn_provider_type); | 384 shill::kTypeProperty, &vpn_provider_type); |
| 385 provider_properties->GetStringWithoutPathExpansion( | 385 provider_properties->GetStringWithoutPathExpansion( |
| 386 shill::kHostProperty, &vpn_provider_host); | 386 shill::kHostProperty, &vpn_provider_host); |
| 387 provider_properties->GetStringWithoutPathExpansion( |
| 388 shill::kL2tpIpsecClientCertIdProperty, &vpn_client_cert_id); |
| 387 } | 389 } |
| 388 if (vpn_provider_type.empty() || vpn_provider_host.empty()) { | 390 if (vpn_provider_type.empty() || vpn_provider_host.empty()) { |
| 389 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); | 391 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); |
| 390 return; | 392 return; |
| 391 } | 393 } |
| 392 } | 394 } |
| 393 | 395 |
| 396 scoped_ptr<NetworkUIData> ui_data = |
| 397 shill_property_util::GetUIDataFromProperties(service_properties); |
| 398 |
| 394 client_cert::ConfigType client_cert_type = client_cert::CONFIG_TYPE_NONE; | 399 client_cert::ConfigType client_cert_type = client_cert::CONFIG_TYPE_NONE; |
| 395 if (type == shill::kTypeVPN) { | 400 if (type == shill::kTypeVPN) { |
| 396 if (vpn_provider_type == shill::kProviderOpenVpn) | 401 if (vpn_provider_type == shill::kProviderOpenVpn) { |
| 397 client_cert_type = client_cert::CONFIG_TYPE_OPENVPN; | 402 client_cert_type = client_cert::CONFIG_TYPE_OPENVPN; |
| 398 else | 403 } else { |
| 399 client_cert_type = client_cert::CONFIG_TYPE_IPSEC; | 404 // L2TP/IPSec only requires a certificate if one is specified in ONC |
| 405 // or one was configured by the UI. Otherwise it is L2TP/IPSec with |
| 406 // PSK and doesn't require a certificate. |
| 407 // |
| 408 // TODO(benchan): Modify shill to specify the authentication type via |
| 409 // the kL2tpIpsecAuthenticationType property, so that Chrome doesn't need |
| 410 // to deduce the authentication type based on the |
| 411 // kL2tpIpsecClientCertIdProperty here (and also in VPNConfigView). |
| 412 if (!vpn_client_cert_id.empty() || |
| 413 (ui_data && ui_data->certificate_type() != CLIENT_CERT_TYPE_NONE)) |
| 414 client_cert_type = client_cert::CONFIG_TYPE_IPSEC; |
| 415 } |
| 400 } else if (type == shill::kTypeWifi && security == shill::kSecurity8021x) { | 416 } else if (type == shill::kTypeWifi && security == shill::kSecurity8021x) { |
| 401 client_cert_type = client_cert::CONFIG_TYPE_EAP; | 417 client_cert_type = client_cert::CONFIG_TYPE_EAP; |
| 402 } | 418 } |
| 403 | 419 |
| 404 base::DictionaryValue config_properties; | 420 base::DictionaryValue config_properties; |
| 405 if (client_cert_type != client_cert::CONFIG_TYPE_NONE) { | 421 if (client_cert_type != client_cert::CONFIG_TYPE_NONE) { |
| 406 // If the client certificate must be configured, this will be set to a | 422 // If the client certificate must be configured, this will be set to a |
| 407 // non-empty string. | 423 // non-empty string. |
| 408 std::string pkcs11_id; | 424 std::string pkcs11_id; |
| 409 | 425 |
| 410 // Check certificate properties in kUIDataProperty if configured. | 426 // Check certificate properties in kUIDataProperty if configured. |
| 411 // Note: Wifi/VPNConfigView set these properties explicitly, in which case | 427 // Note: Wifi/VPNConfigView set these properties explicitly, in which case |
| 412 // only the TPM must be configured. | 428 // only the TPM must be configured. |
| 413 scoped_ptr<NetworkUIData> ui_data = | |
| 414 shill_property_util::GetUIDataFromProperties(service_properties); | |
| 415 if (ui_data && ui_data->certificate_type() == CLIENT_CERT_TYPE_PATTERN) { | 429 if (ui_data && ui_data->certificate_type() == CLIENT_CERT_TYPE_PATTERN) { |
| 416 // User must be logged in to connect to a network requiring a certificate. | 430 // User must be logged in to connect to a network requiring a certificate. |
| 417 if (!logged_in_ || !cert_loader_) { | 431 if (!logged_in_ || !cert_loader_) { |
| 418 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); | 432 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); |
| 419 return; | 433 return; |
| 420 } | 434 } |
| 421 | 435 |
| 422 // If certificates have not been loaded yet, queue the connect request. | 436 // If certificates have not been loaded yet, queue the connect request. |
| 423 if (!certificates_loaded_) { | 437 if (!certificates_loaded_) { |
| 424 NET_LOG_EVENT("Certificates not loaded", ""); | 438 NET_LOG_EVENT("Certificates not loaded", ""); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 if (type == shill::kTypeVPN) { | 480 if (type == shill::kTypeVPN) { |
| 467 // VPN may require a username, and/or passphrase to be set. (Check after | 481 // VPN may require a username, and/or passphrase to be set. (Check after |
| 468 // ensuring that any required certificates are configured). | 482 // ensuring that any required certificates are configured). |
| 469 DCHECK(provider_properties); | 483 DCHECK(provider_properties); |
| 470 if (VPNRequiresCredentials( | 484 if (VPNRequiresCredentials( |
| 471 service_path, vpn_provider_type, *provider_properties)) { | 485 service_path, vpn_provider_type, *provider_properties)) { |
| 472 NET_LOG_USER("VPN Requires Credentials", service_path); | 486 NET_LOG_USER("VPN Requires Credentials", service_path); |
| 473 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); | 487 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); |
| 474 return; | 488 return; |
| 475 } | 489 } |
| 490 |
| 491 // If it's L2TP/IPsec PSK, there is no properties to configure, so proceed |
| 492 // to connect. |
| 493 if (client_cert_type == client_cert::CONFIG_TYPE_NONE) { |
| 494 CallShillConnect(service_path); |
| 495 return; |
| 496 } |
| 476 } | 497 } |
| 477 | 498 |
| 478 if (!config_properties.empty()) { | 499 if (!config_properties.empty()) { |
| 479 NET_LOG_EVENT("Configuring Network", service_path); | 500 NET_LOG_EVENT("Configuring Network", service_path); |
| 480 network_configuration_handler_->SetProperties( | 501 network_configuration_handler_->SetProperties( |
| 481 service_path, | 502 service_path, |
| 482 config_properties, | 503 config_properties, |
| 483 base::Bind(&NetworkConnectionHandler::CallShillConnect, | 504 base::Bind(&NetworkConnectionHandler::CallShillConnect, |
| 484 AsWeakPtr(), | 505 AsWeakPtr(), |
| 485 service_path), | 506 service_path), |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 | 697 |
| 677 void NetworkConnectionHandler::HandleShillDisconnectSuccess( | 698 void NetworkConnectionHandler::HandleShillDisconnectSuccess( |
| 678 const std::string& service_path, | 699 const std::string& service_path, |
| 679 const base::Closure& success_callback) { | 700 const base::Closure& success_callback) { |
| 680 NET_LOG_EVENT("Disconnect Request Sent", service_path); | 701 NET_LOG_EVENT("Disconnect Request Sent", service_path); |
| 681 if (!success_callback.is_null()) | 702 if (!success_callback.is_null()) |
| 682 success_callback.Run(); | 703 success_callback.Run(); |
| 683 } | 704 } |
| 684 | 705 |
| 685 } // namespace chromeos | 706 } // namespace chromeos |
| OLD | NEW |