Chromium Code Reviews| Index: chromeos/network/client_cert_util.cc |
| diff --git a/chromeos/network/client_cert_util.cc b/chromeos/network/client_cert_util.cc |
| index c77e28606e390dbcf1985344b1e6c7dee7a65a45..7d61a8c9ee946420ddfd6d00515a8319c7473262 100644 |
| --- a/chromeos/network/client_cert_util.cc |
| +++ b/chromeos/network/client_cert_util.cc |
| @@ -14,6 +14,7 @@ |
| #include "base/values.h" |
| #include "chromeos/network/certificate_pattern.h" |
| #include "chromeos/network/network_event_log.h" |
| +#include "components/onc/onc_constants.h" |
| #include "net/base/net_errors.h" |
| #include "net/cert/cert_database.h" |
| #include "net/cert/nss_cert_database.h" |
| @@ -101,6 +102,24 @@ std::string GetStringFromDictionary(const base::DictionaryValue& dict, |
| return s; |
| } |
| +void GetClientCertTypeAndPattern( |
| + const base::DictionaryValue& dict_with_client_cert, |
| + ClientCertConfig* cert_config) { |
| + using namespace ::onc::client_cert; |
| + dict_with_client_cert.GetStringWithoutPathExpansion( |
| + kClientCertType, &cert_config->client_cert_type); |
| + |
| + if (cert_config->client_cert_type == kPattern) { |
| + const base::DictionaryValue* pattern = NULL; |
| + dict_with_client_cert.GetDictionaryWithoutPathExpansion(kClientCertPattern, |
| + &pattern); |
| + if (pattern) { |
| + bool success = cert_config->pattern.ReadFromONCDictionary(*pattern); |
| + DCHECK(success); |
| + } |
| + } |
| +} |
| + |
| } // namespace |
| // Returns true only if any fields set in this pattern match exactly with |
| @@ -199,7 +218,7 @@ scoped_refptr<net::X509Certificate> GetCertificateMatch( |
| return latest; |
| } |
| -void SetShillProperties(const client_cert::ConfigType cert_config_type, |
| +void SetShillProperties(const ConfigType cert_config_type, |
| const std::string& tpm_slot, |
| const std::string& tpm_pin, |
| const std::string* pkcs11_id, |
| @@ -254,7 +273,66 @@ void SetShillProperties(const client_cert::ConfigType cert_config_type, |
| properties->SetStringWithoutPathExpansion(tpm_pin_property, tpm_pin); |
| } |
| -bool IsCertificateConfigured(const client_cert::ConfigType cert_config_type, |
| +ClientCertConfig::ClientCertConfig() |
| + : 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.
|
| +} |
| + |
| +void OncToClientCertConfig(const base::DictionaryValue& network_config, |
| + ClientCertConfig* cert_config) { |
| + using namespace ::onc; |
| + |
| + *cert_config = ClientCertConfig(); |
|
stevenjb
2014/07/07 19:34:05
nit: If we're clearing this anyway, maybe just ret
|
| + |
| + const base::DictionaryValue* dict_with_client_cert = NULL; |
| + |
| + const base::DictionaryValue* wifi = NULL; |
| + network_config.GetDictionaryWithoutPathExpansion(network_config::kWiFi, |
| + &wifi); |
| + if (wifi) { |
| + const base::DictionaryValue* eap = NULL; |
| + wifi->GetDictionaryWithoutPathExpansion(wifi::kEAP, &eap); |
| + if (!eap) |
| + return; |
| + |
| + dict_with_client_cert = eap; |
| + cert_config->location = CONFIG_TYPE_EAP; |
| + } |
| + |
| + const base::DictionaryValue* vpn = NULL; |
| + network_config.GetDictionaryWithoutPathExpansion(network_config::kVPN, &vpn); |
| + if (vpn) { |
| + const base::DictionaryValue* openvpn = NULL; |
| + vpn->GetDictionaryWithoutPathExpansion(vpn::kOpenVPN, &openvpn); |
| + const base::DictionaryValue* ipsec = NULL; |
| + vpn->GetDictionaryWithoutPathExpansion(vpn::kIPsec, &ipsec); |
| + if (openvpn) { |
| + dict_with_client_cert = openvpn; |
| + cert_config->location = CONFIG_TYPE_OPENVPN; |
| + } else if (ipsec) { |
| + dict_with_client_cert = ipsec; |
| + cert_config->location = CONFIG_TYPE_IPSEC; |
| + } else { |
| + return; |
| + } |
| + } |
| + |
| + const base::DictionaryValue* ethernet = NULL; |
| + network_config.GetDictionaryWithoutPathExpansion(network_config::kEthernet, |
| + ðernet); |
| + if (ethernet) { |
| + const base::DictionaryValue* eap = NULL; |
| + ethernet->GetDictionaryWithoutPathExpansion(wifi::kEAP, &eap); |
| + if (!eap) |
| + return; |
| + dict_with_client_cert = eap; |
| + cert_config->location = CONFIG_TYPE_EAP; |
| + } |
| + |
| + if (dict_with_client_cert) |
| + GetClientCertTypeAndPattern(*dict_with_client_cert, cert_config); |
| +} |
| + |
| +bool IsCertificateConfigured(const ConfigType cert_config_type, |
| const base::DictionaryValue& service_properties) { |
| // VPN certificate properties are read from the Provider dictionary. |
| const base::DictionaryValue* provider_properties = NULL; |