Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: chromeos/network/client_cert_resolver.cc

Issue 370623002: Remove most of NetworkUIData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/managed_network_configuration_handler.h" 26 #include "chromeos/network/managed_network_configuration_handler.h"
27 #include "chromeos/network/network_state.h" 27 #include "chromeos/network/network_state.h"
28 #include "chromeos/network/network_ui_data.h"
29 #include "chromeos/tpm_token_loader.h" 28 #include "chromeos/tpm_token_loader.h"
30 #include "components/onc/onc_constants.h" 29 #include "components/onc/onc_constants.h"
31 #include "dbus/object_path.h" 30 #include "dbus/object_path.h"
32 #include "net/cert/scoped_nss_types.h" 31 #include "net/cert/scoped_nss_types.h"
33 #include "net/cert/x509_certificate.h" 32 #include "net/cert/x509_certificate.h"
34 33
35 namespace chromeos { 34 namespace chromeos {
36 35
37 // Describes a network |network_path| for which a matching certificate |cert_id| 36 // Describes a network |network_path| for which a matching certificate |cert_id|
38 // was found. 37 // was found.
39 struct ClientCertResolver::NetworkAndMatchingCert { 38 struct ClientCertResolver::NetworkAndMatchingCert {
40 NetworkAndMatchingCert(const std::string& network_path, 39 NetworkAndMatchingCert(const std::string& network_path,
41 client_cert::ConfigType config_type, 40 client_cert::ConfigType config_type,
42 const std::string& cert_id) 41 const std::string& cert_id)
43 : service_path(network_path), 42 : service_path(network_path),
44 cert_config_type(config_type), 43 cert_config_type(config_type),
45 pkcs11_id(cert_id) {} 44 pkcs11_id(cert_id) {}
46 45
47 std::string service_path; 46 std::string service_path;
48 client_cert::ConfigType cert_config_type; 47 client_cert::ConfigType cert_config_type;
48
49 // The id of the matching certificate. 49 // The id of the matching certificate.
50 std::string pkcs11_id; 50 std::string pkcs11_id;
51 }; 51 };
52 52
53 typedef std::vector<ClientCertResolver::NetworkAndMatchingCert> 53 typedef std::vector<ClientCertResolver::NetworkAndMatchingCert>
54 NetworkCertMatches; 54 NetworkCertMatches;
55 55
56 namespace { 56 namespace {
57 57
58 // Returns true if |vector| contains |value|. 58 // Returns true if |vector| contains |value|.
(...skipping 25 matching lines...) Expand all
84 84
85 bool CompareCertExpiration(const CertAndIssuer& a, 85 bool CompareCertExpiration(const CertAndIssuer& a,
86 const CertAndIssuer& b) { 86 const CertAndIssuer& b) {
87 return (a.cert->valid_expiry() > b.cert->valid_expiry()); 87 return (a.cert->valid_expiry() > b.cert->valid_expiry());
88 } 88 }
89 89
90 // Describes a network that is configured with the certificate pattern 90 // Describes a network that is configured with the certificate pattern
91 // |client_cert_pattern|. 91 // |client_cert_pattern|.
92 struct NetworkAndCertPattern { 92 struct NetworkAndCertPattern {
93 NetworkAndCertPattern(const std::string& network_path, 93 NetworkAndCertPattern(const std::string& network_path,
94 client_cert::ConfigType config_type, 94 const client_cert::ClientCertConfig& client_cert_config)
95 const CertificatePattern& pattern)
96 : service_path(network_path), 95 : service_path(network_path),
97 cert_config_type(config_type), 96 cert_config(client_cert_config) {}
98 client_cert_pattern(pattern) {} 97
99 std::string service_path; 98 std::string service_path;
100 client_cert::ConfigType cert_config_type; 99 client_cert::ClientCertConfig cert_config;
101 CertificatePattern client_cert_pattern;
102 }; 100 };
103 101
104 // A unary predicate that returns true if the given CertAndIssuer matches the 102 // A unary predicate that returns true if the given CertAndIssuer matches the
105 // certificate pattern of the NetworkAndCertPattern. 103 // certificate pattern of the NetworkAndCertPattern.
106 struct MatchCertWithPattern { 104 struct MatchCertWithPattern {
107 explicit MatchCertWithPattern(const NetworkAndCertPattern& pattern) 105 explicit MatchCertWithPattern(const NetworkAndCertPattern& pattern)
108 : net_and_pattern(pattern) {} 106 : net_and_pattern(pattern) {}
109 107
110 bool operator()(const CertAndIssuer& cert_and_issuer) { 108 bool operator()(const CertAndIssuer& cert_and_issuer) {
111 const CertificatePattern& pattern = net_and_pattern.client_cert_pattern; 109 const CertificatePattern& pattern = net_and_pattern.cert_config.pattern;
112 if (!pattern.issuer().Empty() && 110 if (!pattern.issuer().Empty() &&
113 !client_cert::CertPrincipalMatches(pattern.issuer(), 111 !client_cert::CertPrincipalMatches(pattern.issuer(),
114 cert_and_issuer.cert->issuer())) { 112 cert_and_issuer.cert->issuer())) {
115 return false; 113 return false;
116 } 114 }
117 if (!pattern.subject().Empty() && 115 if (!pattern.subject().Empty() &&
118 !client_cert::CertPrincipalMatches(pattern.subject(), 116 !client_cert::CertPrincipalMatches(pattern.subject(),
119 cert_and_issuer.cert->subject())) { 117 cert_and_issuer.cert->subject())) {
120 return false; 118 return false;
121 } 119 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 LOG(WARNING) << "Couldn't find a matching client cert for network " 179 LOG(WARNING) << "Couldn't find a matching client cert for network "
182 << it->service_path; 180 << it->service_path;
183 continue; 181 continue;
184 } 182 }
185 std::string pkcs11_id = CertLoader::GetPkcs11IdForCert(*cert_it->cert); 183 std::string pkcs11_id = CertLoader::GetPkcs11IdForCert(*cert_it->cert);
186 if (pkcs11_id.empty()) { 184 if (pkcs11_id.empty()) {
187 LOG(ERROR) << "Couldn't determine PKCS#11 ID."; 185 LOG(ERROR) << "Couldn't determine PKCS#11 ID.";
188 continue; 186 continue;
189 } 187 }
190 matches->push_back(ClientCertResolver::NetworkAndMatchingCert( 188 matches->push_back(ClientCertResolver::NetworkAndMatchingCert(
191 it->service_path, it->cert_config_type, pkcs11_id)); 189 it->service_path, it->cert_config.location, pkcs11_id));
192 } 190 }
193 } 191 }
194 192
195 // Determines the type of the CertificatePattern configuration, i.e. is it a
196 // pattern within an EAP, IPsec or OpenVPN configuration.
197 client_cert::ConfigType OncToClientCertConfigurationType(
198 const base::DictionaryValue& network_config) {
199 using namespace ::onc;
200
201 const base::DictionaryValue* wifi = NULL;
202 network_config.GetDictionaryWithoutPathExpansion(network_config::kWiFi,
203 &wifi);
204 if (wifi) {
205 const base::DictionaryValue* eap = NULL;
206 wifi->GetDictionaryWithoutPathExpansion(wifi::kEAP, &eap);
207 if (!eap)
208 return client_cert::CONFIG_TYPE_NONE;
209 return client_cert::CONFIG_TYPE_EAP;
210 }
211
212 const base::DictionaryValue* vpn = NULL;
213 network_config.GetDictionaryWithoutPathExpansion(network_config::kVPN, &vpn);
214 if (vpn) {
215 const base::DictionaryValue* openvpn = NULL;
216 vpn->GetDictionaryWithoutPathExpansion(vpn::kOpenVPN, &openvpn);
217 if (openvpn)
218 return client_cert::CONFIG_TYPE_OPENVPN;
219
220 const base::DictionaryValue* ipsec = NULL;
221 vpn->GetDictionaryWithoutPathExpansion(vpn::kIPsec, &ipsec);
222 if (ipsec)
223 return client_cert::CONFIG_TYPE_IPSEC;
224
225 return client_cert::CONFIG_TYPE_NONE;
226 }
227
228 const base::DictionaryValue* ethernet = NULL;
229 network_config.GetDictionaryWithoutPathExpansion(network_config::kEthernet,
230 &ethernet);
231 if (ethernet) {
232 const base::DictionaryValue* eap = NULL;
233 ethernet->GetDictionaryWithoutPathExpansion(wifi::kEAP, &eap);
234 if (eap)
235 return client_cert::CONFIG_TYPE_EAP;
236 return client_cert::CONFIG_TYPE_NONE;
237 }
238
239 return client_cert::CONFIG_TYPE_NONE;
240 }
241
242 void LogError(const std::string& service_path, 193 void LogError(const std::string& service_path,
243 const std::string& dbus_error_name, 194 const std::string& dbus_error_name,
244 const std::string& dbus_error_message) { 195 const std::string& dbus_error_message) {
245 network_handler::ShillErrorCallbackFunction( 196 network_handler::ShillErrorCallbackFunction(
246 "ClientCertResolver.SetProperties failed", 197 "ClientCertResolver.SetProperties failed",
247 service_path, 198 service_path,
248 network_handler::ErrorCallback(), 199 network_handler::ErrorCallback(),
249 dbus_error_name, 200 dbus_error_name,
250 dbus_error_message); 201 dbus_error_message);
251 } 202 }
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 344
394 if (!policy) { 345 if (!policy) {
395 VLOG(1) << "The policy for network " << network->path() << " with GUID " 346 VLOG(1) << "The policy for network " << network->path() << " with GUID "
396 << network->guid() << " is not available yet."; 347 << network->guid() << " is not available yet.";
397 // Skip this network for now. Once the policy is loaded, PolicyApplied() 348 // Skip this network for now. Once the policy is loaded, PolicyApplied()
398 // will retry. 349 // will retry.
399 continue; 350 continue;
400 } 351 }
401 352
402 VLOG(2) << "Inspecting network " << network->path(); 353 VLOG(2) << "Inspecting network " << network->path();
403 // TODO(pneubeck): Access the ClientCertPattern without relying on 354 client_cert::ClientCertConfig cert_config;
404 // NetworkUIData, which also parses other things that we don't need here. 355 OncToClientCertConfig(*policy, &cert_config);
405 // The ONCSource is irrelevant here.
406 scoped_ptr<NetworkUIData> ui_data(
407 NetworkUIData::CreateFromONC(onc::ONC_SOURCE_NONE, *policy));
408 356
409 // Skip networks that don't have a ClientCertPattern. 357 // Skip networks that don't have a ClientCertPattern.
410 if (ui_data->certificate_type() != CLIENT_CERT_TYPE_PATTERN) 358 if (cert_config.client_cert_type != ::onc::client_cert::kPattern)
411 continue; 359 continue;
412 360
413 client_cert::ConfigType config_type = 361 networks_with_pattern->push_back(
414 OncToClientCertConfigurationType(*policy); 362 NetworkAndCertPattern(network->path(), cert_config));
415 if (config_type == client_cert::CONFIG_TYPE_NONE) {
416 LOG(ERROR) << "UIData contains a CertificatePattern, but the policy "
417 << "doesn't. Network: " << network->path();
418 continue;
419 }
420
421 networks_with_pattern->push_back(NetworkAndCertPattern(
422 network->path(), config_type, ui_data->certificate_pattern()));
423 } 363 }
424 if (networks_with_pattern->empty()) 364 if (networks_with_pattern->empty())
425 return; 365 return;
426 366
427 VLOG(2) << "Start task for resolving client cert patterns."; 367 VLOG(2) << "Start task for resolving client cert patterns.";
428 base::TaskRunner* task_runner = slow_task_runner_for_test_.get(); 368 base::TaskRunner* task_runner = slow_task_runner_for_test_.get();
429 if (!task_runner) 369 if (!task_runner)
430 task_runner = base::WorkerPool::GetTaskRunner(true /* task is slow */); 370 task_runner = base::WorkerPool::GetTaskRunner(true /* task is slow */);
431 371
432 NetworkCertMatches* matches = new NetworkCertMatches; 372 NetworkCertMatches* matches = new NetworkCertMatches;
(...skipping 23 matching lines...) Expand all
456 DBusThreadManager::Get()->GetShillServiceClient()-> 396 DBusThreadManager::Get()->GetShillServiceClient()->
457 SetProperties(dbus::ObjectPath(it->service_path), 397 SetProperties(dbus::ObjectPath(it->service_path),
458 shill_properties, 398 shill_properties,
459 base::Bind(&base::DoNothing), 399 base::Bind(&base::DoNothing),
460 base::Bind(&LogError, it->service_path)); 400 base::Bind(&LogError, it->service_path));
461 network_state_handler_->RequestUpdateForNetwork(it->service_path); 401 network_state_handler_->RequestUpdateForNetwork(it->service_path);
462 } 402 }
463 } 403 }
464 404
465 } // namespace chromeos 405 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698