Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_util.h" | 5 #include "chromeos/network/client_cert_util.h" |
| 6 | 6 |
| 7 #include <cert.h> | 7 #include <cert.h> |
| 8 #include <pk11pub.h> | 8 #include <pk11pub.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chromeos/network/certificate_pattern.h" | 15 #include "chromeos/network/certificate_pattern.h" |
| 16 #include "chromeos/network/network_event_log.h" | 16 #include "chromeos/network/network_event_log.h" |
| 17 #include "components/onc/onc_constants.h" | |
| 17 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
| 18 #include "net/cert/cert_database.h" | 19 #include "net/cert/cert_database.h" |
| 19 #include "net/cert/nss_cert_database.h" | 20 #include "net/cert/nss_cert_database.h" |
| 20 #include "net/cert/scoped_nss_types.h" | 21 #include "net/cert/scoped_nss_types.h" |
| 21 #include "net/cert/x509_cert_types.h" | 22 #include "net/cert/x509_cert_types.h" |
| 22 #include "net/cert/x509_certificate.h" | 23 #include "net/cert/x509_certificate.h" |
| 23 #include "third_party/cros_system_api/dbus/service_constants.h" | 24 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 24 | 25 |
| 25 namespace chromeos { | 26 namespace chromeos { |
| 26 | 27 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 const std::vector<std::string>& issuer_ca_pems_; | 95 const std::vector<std::string>& issuer_ca_pems_; |
| 95 }; | 96 }; |
| 96 | 97 |
| 97 std::string GetStringFromDictionary(const base::DictionaryValue& dict, | 98 std::string GetStringFromDictionary(const base::DictionaryValue& dict, |
| 98 const std::string& key) { | 99 const std::string& key) { |
| 99 std::string s; | 100 std::string s; |
| 100 dict.GetStringWithoutPathExpansion(key, &s); | 101 dict.GetStringWithoutPathExpansion(key, &s); |
| 101 return s; | 102 return s; |
| 102 } | 103 } |
| 103 | 104 |
| 105 void GetClientCertTypeAndPattern( | |
| 106 const base::DictionaryValue& dict_with_client_cert, | |
| 107 ClientCertConfig* cert_config) { | |
| 108 using namespace ::onc::client_cert; | |
| 109 dict_with_client_cert.GetStringWithoutPathExpansion( | |
| 110 kClientCertType, &cert_config->client_cert_type); | |
| 111 | |
| 112 if (cert_config->client_cert_type == kPattern) { | |
| 113 const base::DictionaryValue* pattern = NULL; | |
| 114 dict_with_client_cert.GetDictionaryWithoutPathExpansion(kClientCertPattern, | |
| 115 &pattern); | |
| 116 if (pattern) { | |
| 117 bool success = cert_config->pattern.ReadFromONCDictionary(*pattern); | |
| 118 DCHECK(success); | |
| 119 } | |
| 120 } | |
| 121 } | |
| 122 | |
| 104 } // namespace | 123 } // namespace |
| 105 | 124 |
| 106 // Returns true only if any fields set in this pattern match exactly with | 125 // Returns true only if any fields set in this pattern match exactly with |
| 107 // similar fields in the principal. If organization_ or organizational_unit_ | 126 // similar fields in the principal. If organization_ or organizational_unit_ |
| 108 // are set, then at least one of the organizations or units in the principal | 127 // are set, then at least one of the organizations or units in the principal |
| 109 // must match. | 128 // must match. |
| 110 bool CertPrincipalMatches(const IssuerSubjectPattern& pattern, | 129 bool CertPrincipalMatches(const IssuerSubjectPattern& pattern, |
| 111 const net::CertPrincipal& principal) { | 130 const net::CertPrincipal& principal) { |
| 112 if (!pattern.common_name().empty() && | 131 if (!pattern.common_name().empty() && |
| 113 pattern.common_name() != principal.common_name) { | 132 pattern.common_name() != principal.common_name) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 // Iterate over the rest looking for the one that was issued latest. | 211 // Iterate over the rest looking for the one that was issued latest. |
| 193 for (CertificateStlList::iterator iter = matching_certs.begin(); | 212 for (CertificateStlList::iterator iter = matching_certs.begin(); |
| 194 iter != matching_certs.end(); ++iter) { | 213 iter != matching_certs.end(); ++iter) { |
| 195 if (!latest.get() || (*iter)->valid_start() > latest->valid_start()) | 214 if (!latest.get() || (*iter)->valid_start() > latest->valid_start()) |
| 196 latest = *iter; | 215 latest = *iter; |
| 197 } | 216 } |
| 198 | 217 |
| 199 return latest; | 218 return latest; |
| 200 } | 219 } |
| 201 | 220 |
| 202 void SetShillProperties(const client_cert::ConfigType cert_config_type, | 221 void SetShillProperties(const ConfigType cert_config_type, |
| 203 const std::string& tpm_slot, | 222 const std::string& tpm_slot, |
| 204 const std::string& tpm_pin, | 223 const std::string& tpm_pin, |
| 205 const std::string* pkcs11_id, | 224 const std::string* pkcs11_id, |
| 206 base::DictionaryValue* properties) { | 225 base::DictionaryValue* properties) { |
| 207 const char* tpm_pin_property = NULL; | 226 const char* tpm_pin_property = NULL; |
| 208 switch (cert_config_type) { | 227 switch (cert_config_type) { |
| 209 case CONFIG_TYPE_NONE: { | 228 case CONFIG_TYPE_NONE: { |
| 210 return; | 229 return; |
| 211 } | 230 } |
| 212 case CONFIG_TYPE_OPENVPN: { | 231 case CONFIG_TYPE_OPENVPN: { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 key_id); | 266 key_id); |
| 248 } | 267 } |
| 249 break; | 268 break; |
| 250 } | 269 } |
| 251 } | 270 } |
| 252 DCHECK(tpm_pin_property); | 271 DCHECK(tpm_pin_property); |
| 253 if (!tpm_pin.empty()) | 272 if (!tpm_pin.empty()) |
| 254 properties->SetStringWithoutPathExpansion(tpm_pin_property, tpm_pin); | 273 properties->SetStringWithoutPathExpansion(tpm_pin_property, tpm_pin); |
| 255 } | 274 } |
| 256 | 275 |
| 257 bool IsCertificateConfigured(const client_cert::ConfigType cert_config_type, | 276 ClientCertConfig::ClientCertConfig() |
| 277 : location(CONFIG_TYPE_NONE), client_cert_type(onc::client_cert::kNone) { | |
|
stevenjb
2014/07/07 19:34:05
nit: one arg per line
pneubeck (no reviews)
2014/07/09 07:51:26
Done.
| |
| 278 } | |
| 279 | |
| 280 void OncToClientCertConfig(const base::DictionaryValue& network_config, | |
| 281 ClientCertConfig* cert_config) { | |
| 282 using namespace ::onc; | |
| 283 | |
| 284 *cert_config = ClientCertConfig(); | |
|
stevenjb
2014/07/07 19:34:05
nit: If we're clearing this anyway, maybe just ret
| |
| 285 | |
| 286 const base::DictionaryValue* dict_with_client_cert = NULL; | |
| 287 | |
| 288 const base::DictionaryValue* wifi = NULL; | |
| 289 network_config.GetDictionaryWithoutPathExpansion(network_config::kWiFi, | |
| 290 &wifi); | |
| 291 if (wifi) { | |
| 292 const base::DictionaryValue* eap = NULL; | |
| 293 wifi->GetDictionaryWithoutPathExpansion(wifi::kEAP, &eap); | |
| 294 if (!eap) | |
| 295 return; | |
| 296 | |
| 297 dict_with_client_cert = eap; | |
| 298 cert_config->location = CONFIG_TYPE_EAP; | |
| 299 } | |
| 300 | |
| 301 const base::DictionaryValue* vpn = NULL; | |
| 302 network_config.GetDictionaryWithoutPathExpansion(network_config::kVPN, &vpn); | |
| 303 if (vpn) { | |
| 304 const base::DictionaryValue* openvpn = NULL; | |
| 305 vpn->GetDictionaryWithoutPathExpansion(vpn::kOpenVPN, &openvpn); | |
| 306 const base::DictionaryValue* ipsec = NULL; | |
| 307 vpn->GetDictionaryWithoutPathExpansion(vpn::kIPsec, &ipsec); | |
| 308 if (openvpn) { | |
| 309 dict_with_client_cert = openvpn; | |
| 310 cert_config->location = CONFIG_TYPE_OPENVPN; | |
| 311 } else if (ipsec) { | |
| 312 dict_with_client_cert = ipsec; | |
| 313 cert_config->location = CONFIG_TYPE_IPSEC; | |
| 314 } else { | |
| 315 return; | |
| 316 } | |
| 317 } | |
| 318 | |
| 319 const base::DictionaryValue* ethernet = NULL; | |
| 320 network_config.GetDictionaryWithoutPathExpansion(network_config::kEthernet, | |
| 321 ðernet); | |
| 322 if (ethernet) { | |
| 323 const base::DictionaryValue* eap = NULL; | |
| 324 ethernet->GetDictionaryWithoutPathExpansion(wifi::kEAP, &eap); | |
| 325 if (!eap) | |
| 326 return; | |
| 327 dict_with_client_cert = eap; | |
| 328 cert_config->location = CONFIG_TYPE_EAP; | |
| 329 } | |
| 330 | |
| 331 if (dict_with_client_cert) | |
| 332 GetClientCertTypeAndPattern(*dict_with_client_cert, cert_config); | |
| 333 } | |
| 334 | |
| 335 bool IsCertificateConfigured(const ConfigType cert_config_type, | |
| 258 const base::DictionaryValue& service_properties) { | 336 const base::DictionaryValue& service_properties) { |
| 259 // VPN certificate properties are read from the Provider dictionary. | 337 // VPN certificate properties are read from the Provider dictionary. |
| 260 const base::DictionaryValue* provider_properties = NULL; | 338 const base::DictionaryValue* provider_properties = NULL; |
| 261 service_properties.GetDictionaryWithoutPathExpansion( | 339 service_properties.GetDictionaryWithoutPathExpansion( |
| 262 shill::kProviderProperty, &provider_properties); | 340 shill::kProviderProperty, &provider_properties); |
| 263 switch (cert_config_type) { | 341 switch (cert_config_type) { |
| 264 case CONFIG_TYPE_NONE: | 342 case CONFIG_TYPE_NONE: |
| 265 return true; | 343 return true; |
| 266 case CONFIG_TYPE_OPENVPN: | 344 case CONFIG_TYPE_OPENVPN: |
| 267 // OpenVPN generally requires a passphrase and we don't know whether or | 345 // OpenVPN generally requires a passphrase and we don't know whether or |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 286 return !cert_id.empty() && !key_id.empty() && !identity.empty(); | 364 return !cert_id.empty() && !key_id.empty() && !identity.empty(); |
| 287 } | 365 } |
| 288 } | 366 } |
| 289 NOTREACHED(); | 367 NOTREACHED(); |
| 290 return false; | 368 return false; |
| 291 } | 369 } |
| 292 | 370 |
| 293 } // namespace client_cert | 371 } // namespace client_cert |
| 294 | 372 |
| 295 } // namespace chromeos | 373 } // namespace chromeos |
| OLD | NEW |