| 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/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "chromeos/cert_loader.h" | 12 #include "chromeos/cert_loader.h" |
| 13 #include "chromeos/dbus/dbus_thread_manager.h" | 13 #include "chromeos/dbus/dbus_thread_manager.h" |
| 14 #include "chromeos/dbus/shill_manager_client.h" | 14 #include "chromeos/dbus/shill_manager_client.h" |
| 15 #include "chromeos/dbus/shill_service_client.h" | 15 #include "chromeos/dbus/shill_service_client.h" |
| 16 #include "chromeos/network/certificate_pattern.h" | 16 #include "chromeos/network/certificate_pattern.h" |
| 17 #include "chromeos/network/client_cert_resolver.h" |
| 17 #include "chromeos/network/client_cert_util.h" | 18 #include "chromeos/network/client_cert_util.h" |
| 18 #include "chromeos/network/managed_network_configuration_handler.h" | 19 #include "chromeos/network/managed_network_configuration_handler.h" |
| 19 #include "chromeos/network/network_configuration_handler.h" | 20 #include "chromeos/network/network_configuration_handler.h" |
| 20 #include "chromeos/network/network_event_log.h" | 21 #include "chromeos/network/network_event_log.h" |
| 21 #include "chromeos/network/network_handler_callbacks.h" | 22 #include "chromeos/network/network_handler_callbacks.h" |
| 22 #include "chromeos/network/network_profile_handler.h" | 23 #include "chromeos/network/network_profile_handler.h" |
| 23 #include "chromeos/network/network_state.h" | 24 #include "chromeos/network/network_state.h" |
| 24 #include "chromeos/network/network_state_handler.h" | 25 #include "chromeos/network/network_state_handler.h" |
| 25 #include "chromeos/network/shill_property_util.h" | 26 #include "chromeos/network/shill_property_util.h" |
| 26 #include "chromeos/tpm_token_loader.h" | |
| 27 #include "dbus/object_path.h" | 27 #include "dbus/object_path.h" |
| 28 #include "net/cert/x509_certificate.h" | 28 #include "net/cert/x509_certificate.h" |
| 29 #include "third_party/cros_system_api/dbus/service_constants.h" | 29 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 30 | 30 |
| 31 namespace chromeos { | 31 namespace chromeos { |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 void InvokeErrorCallback(const std::string& service_path, | 35 void InvokeErrorCallback(const std::string& service_path, |
| 36 const network_handler::ErrorCallback& error_callback, | 36 const network_handler::ErrorCallback& error_callback, |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); | 466 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); |
| 467 return; | 467 return; |
| 468 } | 468 } |
| 469 // If certificates have not been loaded yet, queue the connect request. | 469 // If certificates have not been loaded yet, queue the connect request. |
| 470 if (!certificates_loaded_) { | 470 if (!certificates_loaded_) { |
| 471 NET_LOG_EVENT("Certificates not loaded", ""); | 471 NET_LOG_EVENT("Certificates not loaded", ""); |
| 472 QueueConnectRequest(service_path); | 472 QueueConnectRequest(service_path); |
| 473 return; | 473 return; |
| 474 } | 474 } |
| 475 | 475 |
| 476 // If the client certificate must be configured, this will be set to a | |
| 477 // non-empty string. | |
| 478 std::string pkcs11_id; | |
| 479 | |
| 480 // Check certificate properties from policy. | 476 // Check certificate properties from policy. |
| 481 // Note: Wifi/VPNConfigView set the KeyID and CertID properties directly, | |
| 482 // in which case only the TPM must be configured. | |
| 483 if (cert_config_from_policy.client_cert_type == | 477 if (cert_config_from_policy.client_cert_type == |
| 484 onc::client_cert::kPattern) { | 478 onc::client_cert::kPattern) { |
| 485 pkcs11_id = CertificateIsConfigured(cert_config_from_policy.pattern); | 479 if (!ClientCertResolver::ResolveCertificatePatternSync( |
| 486 // Ensure the certificate is available and configured. | 480 client_cert_type, |
| 487 if (!cert_loader_->IsHardwareBacked() || pkcs11_id.empty()) { | 481 cert_config_from_policy.pattern, |
| 482 &config_properties)) { |
| 488 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); | 483 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); |
| 489 return; | 484 return; |
| 490 } | 485 } |
| 491 } else if (check_error_state && | 486 } else if (check_error_state && |
| 492 !client_cert::IsCertificateConfigured(client_cert_type, | 487 !client_cert::IsCertificateConfigured(client_cert_type, |
| 493 service_properties)) { | 488 service_properties)) { |
| 494 // Network may not be configured. | 489 // Network may not be configured. |
| 495 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); | 490 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); |
| 496 return; | 491 return; |
| 497 } | 492 } |
| 498 | |
| 499 // The network may not be 'Connectable' because the TPM properties are not | |
| 500 // set up, so configure tpm slot/pin before connecting. | |
| 501 if (cert_loader_ && cert_loader_->IsHardwareBacked()) { | |
| 502 // Pass NULL if pkcs11_id is empty, so that it doesn't clear any | |
| 503 // previously configured client cert. | |
| 504 client_cert::SetShillProperties( | |
| 505 client_cert_type, | |
| 506 base::IntToString(cert_loader_->TPMTokenSlotID()), | |
| 507 TPMTokenLoader::Get()->tpm_user_pin(), | |
| 508 pkcs11_id.empty() ? NULL : &pkcs11_id, | |
| 509 &config_properties); | |
| 510 } | |
| 511 } | 493 } |
| 512 | 494 |
| 513 if (type == shill::kTypeVPN) { | 495 if (type == shill::kTypeVPN) { |
| 514 // VPN may require a username, and/or passphrase to be set. (Check after | 496 // VPN may require a username, and/or passphrase to be set. (Check after |
| 515 // ensuring that any required certificates are configured). | 497 // ensuring that any required certificates are configured). |
| 516 DCHECK(provider_properties); | 498 DCHECK(provider_properties); |
| 517 if (VPNRequiresCredentials( | 499 if (VPNRequiresCredentials( |
| 518 service_path, vpn_provider_type, *provider_properties)) { | 500 service_path, vpn_provider_type, *provider_properties)) { |
| 519 NET_LOG_USER("VPN Requires Credentials", service_path); | 501 NET_LOG_USER("VPN Requires Credentials", service_path); |
| 520 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); | 502 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 InvokeErrorCallback(service_path, error_callback, error_name); | 720 InvokeErrorCallback(service_path, error_callback, error_name); |
| 739 } | 721 } |
| 740 | 722 |
| 741 void NetworkConnectionHandler::CheckAllPendingRequests() { | 723 void NetworkConnectionHandler::CheckAllPendingRequests() { |
| 742 for (std::map<std::string, ConnectRequest>::iterator iter = | 724 for (std::map<std::string, ConnectRequest>::iterator iter = |
| 743 pending_requests_.begin(); iter != pending_requests_.end(); ++iter) { | 725 pending_requests_.begin(); iter != pending_requests_.end(); ++iter) { |
| 744 CheckPendingRequest(iter->first); | 726 CheckPendingRequest(iter->first); |
| 745 } | 727 } |
| 746 } | 728 } |
| 747 | 729 |
| 748 std::string NetworkConnectionHandler::CertificateIsConfigured( | |
| 749 const CertificatePattern& pattern) { | |
| 750 if (pattern.Empty()) | |
| 751 return std::string(); | |
| 752 // Find the matching certificate. | |
| 753 scoped_refptr<net::X509Certificate> matching_cert = | |
| 754 client_cert::GetCertificateMatch(pattern, cert_loader_->cert_list()); | |
| 755 if (!matching_cert.get()) | |
| 756 return std::string(); | |
| 757 return CertLoader::GetPkcs11IdForCert(*matching_cert.get()); | |
| 758 } | |
| 759 | |
| 760 void NetworkConnectionHandler::ErrorCallbackForPendingRequest( | 730 void NetworkConnectionHandler::ErrorCallbackForPendingRequest( |
| 761 const std::string& service_path, | 731 const std::string& service_path, |
| 762 const std::string& error_name) { | 732 const std::string& error_name) { |
| 763 ConnectRequest* request = GetPendingRequest(service_path); | 733 ConnectRequest* request = GetPendingRequest(service_path); |
| 764 if (!request) { | 734 if (!request) { |
| 765 NET_LOG_ERROR("ErrorCallbackForPendingRequest with no pending request.", | 735 NET_LOG_ERROR("ErrorCallbackForPendingRequest with no pending request.", |
| 766 service_path); | 736 service_path); |
| 767 return; | 737 return; |
| 768 } | 738 } |
| 769 // Remove the entry before invoking the callback in case it triggers a retry. | 739 // Remove the entry before invoking the callback in case it triggers a retry. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 | 822 |
| 853 NET_LOG_EVENT("Disconnect Forced by Policy", network->path()); | 823 NET_LOG_EVENT("Disconnect Forced by Policy", network->path()); |
| 854 CallShillDisconnect( | 824 CallShillDisconnect( |
| 855 network->path(), base::Closure(), network_handler::ErrorCallback()); | 825 network->path(), base::Closure(), network_handler::ErrorCallback()); |
| 856 } | 826 } |
| 857 | 827 |
| 858 ConnectToBestNetworkAfterLogin(); | 828 ConnectToBestNetworkAfterLogin(); |
| 859 } | 829 } |
| 860 | 830 |
| 861 } // namespace chromeos | 831 } // namespace chromeos |
| OLD | NEW |