| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/client_cert_resolver.h" | 5 #include "chromeos/network/client_cert_resolver.h" |
| 6 | 6 |
| 7 #include <cert.h> | 7 #include <cert.h> |
| 8 #include <certt.h> // for (SECCertUsageEnum) certUsageAnyCA | 8 #include <certt.h> // for (SECCertUsageEnum) certUsageAnyCA |
| 9 #include <pk11pub.h> | 9 #include <pk11pub.h> |
| 10 | 10 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/task_runner.h" | 18 #include "base/task_runner.h" |
| 19 #include "base/threading/worker_pool.h" | 19 #include "base/threading/worker_pool.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "chromeos/cert_loader.h" | 21 #include "chromeos/cert_loader.h" |
| 22 #include "chromeos/dbus/dbus_thread_manager.h" | 22 #include "chromeos/dbus/dbus_thread_manager.h" |
| 23 #include "chromeos/dbus/shill_service_client.h" | 23 #include "chromeos/dbus/shill_service_client.h" |
| 24 #include "chromeos/network/certificate_pattern.h" | 24 #include "chromeos/network/certificate_pattern.h" |
| 25 #include "chromeos/network/client_cert_util.h" | 25 #include "chromeos/network/client_cert_util.h" |
| 26 #include "chromeos/network/favorite_state.h" | |
| 27 #include "chromeos/network/managed_network_configuration_handler.h" | 26 #include "chromeos/network/managed_network_configuration_handler.h" |
| 28 #include "chromeos/network/network_state_handler.h" | 27 #include "chromeos/network/network_state.h" |
| 29 #include "chromeos/network/network_ui_data.h" | 28 #include "chromeos/network/network_ui_data.h" |
| 30 #include "chromeos/tpm_token_loader.h" | 29 #include "chromeos/tpm_token_loader.h" |
| 31 #include "components/onc/onc_constants.h" | 30 #include "components/onc/onc_constants.h" |
| 32 #include "dbus/object_path.h" | 31 #include "dbus/object_path.h" |
| 33 #include "net/cert/scoped_nss_types.h" | 32 #include "net/cert/scoped_nss_types.h" |
| 34 #include "net/cert/x509_certificate.h" | 33 #include "net/cert/x509_certificate.h" |
| 35 | 34 |
| 36 namespace chromeos { | 35 namespace chromeos { |
| 37 | 36 |
| 38 // Describes a network |network_path| for which a matching certificate |cert_id| | 37 // Describes a network |network_path| for which a matching certificate |cert_id| |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 void ClientCertResolver::NetworkListChanged() { | 301 void ClientCertResolver::NetworkListChanged() { |
| 303 VLOG(2) << "NetworkListChanged."; | 302 VLOG(2) << "NetworkListChanged."; |
| 304 if (!ClientCertificatesLoaded()) | 303 if (!ClientCertificatesLoaded()) |
| 305 return; | 304 return; |
| 306 // Configure only networks that were not configured before. | 305 // Configure only networks that were not configured before. |
| 307 | 306 |
| 308 // We'll drop networks from |resolved_networks_|, which are not known anymore. | 307 // We'll drop networks from |resolved_networks_|, which are not known anymore. |
| 309 std::set<std::string> old_resolved_networks; | 308 std::set<std::string> old_resolved_networks; |
| 310 old_resolved_networks.swap(resolved_networks_); | 309 old_resolved_networks.swap(resolved_networks_); |
| 311 | 310 |
| 312 FavoriteStateList networks; | 311 NetworkStateHandler::NetworkStateList networks; |
| 313 network_state_handler_->GetFavoriteList(&networks); | 312 network_state_handler_->GetNetworkListByType( |
| 313 NetworkTypePattern::Default(), |
| 314 true /* configured_only */, |
| 315 false /* visible_only */, |
| 316 0 /* no limit */, |
| 317 &networks); |
| 314 | 318 |
| 315 FavoriteStateList networks_to_check; | 319 NetworkStateHandler::NetworkStateList networks_to_check; |
| 316 for (FavoriteStateList::const_iterator it = networks.begin(); | 320 for (NetworkStateHandler::NetworkStateList::const_iterator it = |
| 317 it != networks.end(); ++it) { | 321 networks.begin(); it != networks.end(); ++it) { |
| 318 const std::string& service_path = (*it)->path(); | 322 const std::string& service_path = (*it)->path(); |
| 319 if (ContainsKey(old_resolved_networks, service_path)) { | 323 if (ContainsKey(old_resolved_networks, service_path)) { |
| 320 resolved_networks_.insert(service_path); | 324 resolved_networks_.insert(service_path); |
| 321 continue; | 325 continue; |
| 322 } | 326 } |
| 323 networks_to_check.push_back(*it); | 327 networks_to_check.push_back(*it); |
| 324 } | 328 } |
| 325 | 329 |
| 326 ResolveNetworks(networks_to_check); | 330 ResolveNetworks(networks_to_check); |
| 327 } | 331 } |
| 328 | 332 |
| 329 void ClientCertResolver::OnCertificatesLoaded( | 333 void ClientCertResolver::OnCertificatesLoaded( |
| 330 const net::CertificateList& cert_list, | 334 const net::CertificateList& cert_list, |
| 331 bool initial_load) { | 335 bool initial_load) { |
| 332 VLOG(2) << "OnCertificatesLoaded."; | 336 VLOG(2) << "OnCertificatesLoaded."; |
| 333 if (!ClientCertificatesLoaded()) | 337 if (!ClientCertificatesLoaded()) |
| 334 return; | 338 return; |
| 335 // Compare all networks with all certificates. | 339 // Compare all networks with all certificates. |
| 336 FavoriteStateList networks; | 340 NetworkStateHandler::NetworkStateList networks; |
| 337 network_state_handler_->GetFavoriteList(&networks); | 341 network_state_handler_->GetNetworkListByType( |
| 342 NetworkTypePattern::Default(), |
| 343 true /* configured_only */, |
| 344 false /* visible_only */, |
| 345 0 /* no limit */, |
| 346 &networks); |
| 338 ResolveNetworks(networks); | 347 ResolveNetworks(networks); |
| 339 } | 348 } |
| 340 | 349 |
| 341 void ClientCertResolver::PolicyApplied(const std::string& service_path) { | 350 void ClientCertResolver::PolicyApplied(const std::string& service_path) { |
| 342 VLOG(2) << "PolicyApplied " << service_path; | 351 VLOG(2) << "PolicyApplied " << service_path; |
| 343 if (!ClientCertificatesLoaded()) | 352 if (!ClientCertificatesLoaded()) |
| 344 return; | 353 return; |
| 345 // Compare this network with all certificates. | 354 // Compare this network with all certificates. |
| 346 const FavoriteState* network = | 355 const NetworkState* network = |
| 347 network_state_handler_->GetFavoriteStateFromServicePath( | 356 network_state_handler_->GetNetworkStateFromServicePath( |
| 348 service_path, true /* configured_only */); | 357 service_path, true /* configured_only */); |
| 349 if (!network) { | 358 if (!network) { |
| 350 LOG(ERROR) << "service path '" << service_path << "' unknown."; | 359 LOG(ERROR) << "service path '" << service_path << "' unknown."; |
| 351 return; | 360 return; |
| 352 } | 361 } |
| 353 FavoriteStateList networks; | 362 NetworkStateHandler::NetworkStateList networks; |
| 354 networks.push_back(network); | 363 networks.push_back(network); |
| 355 ResolveNetworks(networks); | 364 ResolveNetworks(networks); |
| 356 } | 365 } |
| 357 | 366 |
| 358 void ClientCertResolver::ResolveNetworks(const FavoriteStateList& networks) { | 367 void ClientCertResolver::ResolveNetworks( |
| 368 const NetworkStateHandler::NetworkStateList& networks) { |
| 359 scoped_ptr<std::vector<NetworkAndCertPattern> > networks_with_pattern( | 369 scoped_ptr<std::vector<NetworkAndCertPattern> > networks_with_pattern( |
| 360 new std::vector<NetworkAndCertPattern>); | 370 new std::vector<NetworkAndCertPattern>); |
| 361 | 371 |
| 362 // Filter networks with ClientCertPattern. As ClientCertPatterns can only be | 372 // Filter networks with ClientCertPattern. As ClientCertPatterns can only be |
| 363 // set by policy, we check there. | 373 // set by policy, we check there. |
| 364 for (FavoriteStateList::const_iterator it = networks.begin(); | 374 for (NetworkStateHandler::NetworkStateList::const_iterator it = |
| 365 it != networks.end(); ++it) { | 375 networks.begin(); it != networks.end(); ++it) { |
| 366 const FavoriteState* network = *it; | 376 const NetworkState* network = *it; |
| 367 | 377 |
| 368 // In any case, don't check this network again in NetworkListChanged. | 378 // In any case, don't check this network again in NetworkListChanged. |
| 369 resolved_networks_.insert(network->path()); | 379 resolved_networks_.insert(network->path()); |
| 370 | 380 |
| 371 // If this network is not managed, it cannot have a ClientCertPattern. | 381 // If this network is not managed, it cannot have a ClientCertPattern. |
| 372 if (network->guid().empty()) | 382 if (network->guid().empty()) |
| 373 continue; | 383 continue; |
| 374 | 384 |
| 375 if (network->profile_path().empty()) { | 385 if (network->profile_path().empty()) { |
| 376 LOG(ERROR) << "Network " << network->path() | 386 LOG(ERROR) << "Network " << network->path() |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 DBusThreadManager::Get()->GetShillServiceClient()-> | 456 DBusThreadManager::Get()->GetShillServiceClient()-> |
| 447 SetProperties(dbus::ObjectPath(it->service_path), | 457 SetProperties(dbus::ObjectPath(it->service_path), |
| 448 shill_properties, | 458 shill_properties, |
| 449 base::Bind(&base::DoNothing), | 459 base::Bind(&base::DoNothing), |
| 450 base::Bind(&LogError, it->service_path)); | 460 base::Bind(&LogError, it->service_path)); |
| 451 network_state_handler_->RequestUpdateForNetwork(it->service_path); | 461 network_state_handler_->RequestUpdateForNetwork(it->service_path); |
| 452 } | 462 } |
| 453 } | 463 } |
| 454 | 464 |
| 455 } // namespace chromeos | 465 } // namespace chromeos |
| OLD | NEW |