Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/cros/onc_network_parser.h" | 5 #include "chrome/browser/chromeos/cros/onc_network_parser.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/json/json_value_serializer.h" | 8 #include "base/json/json_value_serializer.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/chromeos/cros/native_network_constants.h" | 11 #include "chrome/browser/chromeos/cros/native_network_constants.h" |
| 12 #include "chrome/browser/chromeos/cros/native_network_parser.h" | |
| 12 #include "chrome/browser/chromeos/cros/network_library.h" | 13 #include "chrome/browser/chromeos/cros/network_library.h" |
| 13 #include "net/base/cert_database.h" | 14 #include "net/base/cert_database.h" |
| 14 #include "net/base/crypto_module.h" | 15 #include "net/base/crypto_module.h" |
| 15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 16 #include "net/base/x509_certificate.h" | 17 #include "net/base/x509_certificate.h" |
| 17 #include "third_party/cros_system_api/dbus/service_constants.h" | 18 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 18 | 19 |
| 19 namespace chromeos { | 20 namespace chromeos { |
| 20 | 21 |
| 21 // Local constants. | 22 // Local constants. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 if (cert_type == "Client") { | 143 if (cert_type == "Client") { |
| 143 return ParseClientCertificate(cert_index, certificate); | 144 return ParseClientCertificate(cert_index, certificate); |
| 144 } | 145 } |
| 145 | 146 |
| 146 LOG(WARNING) << "ONC File: certificate of unknown type: " << cert_type | 147 LOG(WARNING) << "ONC File: certificate of unknown type: " << cert_type |
| 147 << " at index " << cert_index; | 148 << " at index " << cert_index; |
| 148 return false; | 149 return false; |
| 149 } | 150 } |
| 150 | 151 |
| 151 Network* OncNetworkParser::ParseNetwork(int n) { | 152 Network* OncNetworkParser::ParseNetwork(int n) { |
| 152 // TODO(chocobo): Change this to parse network into a dictionary. | |
| 153 if (!network_configs_) | 153 if (!network_configs_) |
| 154 return NULL; | 154 return NULL; |
| 155 DictionaryValue* info = NULL; | 155 DictionaryValue* info = NULL; |
| 156 if (!network_configs_->GetDictionary(n, &info)) | 156 if (!network_configs_->GetDictionary(n, &info)) |
| 157 return NULL; | 157 return NULL; |
| 158 // Parse Open Network Configuration blob into a temporary Network object. | 158 // Parse Open Network Configuration blob into a temporary Network object. |
| 159 return CreateNetworkFromInfo(std::string(), *info); | 159 return CreateNetworkFromInfo(std::string(), *info); |
| 160 } | 160 } |
| 161 | 161 |
| 162 Network* OncNetworkParser::CreateNetworkFromInfo( | 162 Network* OncNetworkParser::CreateNetworkFromInfo( |
| 163 const std::string& service_path, | 163 const std::string& service_path, |
| 164 const DictionaryValue& info) { | 164 const DictionaryValue& info) { |
| 165 ConnectionType type = ParseTypeFromDictionary(info); | 165 ConnectionType type = ParseTypeFromDictionary(info); |
| 166 if (type == TYPE_UNKNOWN) // Return NULL if cannot parse network type. | 166 if (type == TYPE_UNKNOWN) // Return NULL if cannot parse network type. |
| 167 return NULL; | 167 return NULL; |
| 168 scoped_ptr<Network> network(CreateNewNetwork(type, service_path)); | 168 scoped_ptr<Network> network(CreateNewNetwork(type, service_path)); |
| 169 // Update property with native value for type. | |
| 170 std::string str = NativeNetworkParser::type_mapper()->GetKey(type); | |
| 171 scoped_ptr<StringValue> val(Value::CreateStringValue(str)); | |
| 172 network->UpdatePropertyMap(PROPERTY_INDEX_TYPE, *val.get()); | |
| 169 | 173 |
| 170 // Get the child dictionary with properties for the network. | 174 // Get the child dictionary with properties for the network. |
| 171 // And copy all the values from this network type dictionary to parent. | 175 // And copy all the values from this network type dictionary to parent. |
| 172 DictionaryValue* dict; | 176 DictionaryValue* dict; |
| 173 if (!info.GetDictionary(GetTypeFromDictionary(info), &dict)) | 177 if (!info.GetDictionary(GetTypeFromDictionary(info), &dict)) |
| 174 return NULL; | 178 return NULL; |
| 175 | 179 |
| 180 // Add GUID from the parent dictionary. | |
| 181 dict->SetString("GUID", GetGuidFromDictionary(info)); | |
| 182 | |
| 176 UpdateNetworkFromInfo(*dict, network.get()); | 183 UpdateNetworkFromInfo(*dict, network.get()); |
| 177 VLOG(2) << "Created Network '" << network->name() | 184 VLOG(2) << "Created Network '" << network->name() |
| 178 << "' from info. Path:" << service_path | 185 << "' from info. Path:" << service_path |
| 179 << " Type:" << ConnectionTypeToString(type); | 186 << " Type:" << ConnectionTypeToString(type); |
| 180 return network.release(); | 187 return network.release(); |
| 181 } | 188 } |
| 182 | 189 |
| 183 Network* OncNetworkParser::CreateNewNetwork( | 190 Network* OncNetworkParser::CreateNewNetwork( |
| 184 ConnectionType type, const std::string& service_path) { | 191 ConnectionType type, const std::string& service_path) { |
| 185 Network* network = NetworkParser::CreateNewNetwork(type, service_path); | 192 Network* network = NetworkParser::CreateNewNetwork(type, service_path); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 201 return ParseType(GetTypeFromDictionary(info)); | 208 return ParseType(GetTypeFromDictionary(info)); |
| 202 } | 209 } |
| 203 | 210 |
| 204 std::string OncNetworkParser::GetTypeFromDictionary( | 211 std::string OncNetworkParser::GetTypeFromDictionary( |
| 205 const base::DictionaryValue& info) { | 212 const base::DictionaryValue& info) { |
| 206 std::string type_string; | 213 std::string type_string; |
| 207 info.GetString("Type", &type_string); | 214 info.GetString("Type", &type_string); |
| 208 return type_string; | 215 return type_string; |
| 209 } | 216 } |
| 210 | 217 |
| 218 std::string OncNetworkParser::GetGuidFromDictionary( | |
| 219 const base::DictionaryValue& info) { | |
| 220 std::string guid_string; | |
| 221 info.GetString("GUID", &guid_string); | |
| 222 return guid_string; | |
| 223 } | |
| 224 | |
| 211 bool OncNetworkParser::ParseServerOrCaCertificate( | 225 bool OncNetworkParser::ParseServerOrCaCertificate( |
| 212 int cert_index, | 226 int cert_index, |
| 213 const std::string& cert_type, | 227 const std::string& cert_type, |
| 214 base::DictionaryValue* certificate) { | 228 base::DictionaryValue* certificate) { |
| 215 net::CertDatabase cert_database; | 229 net::CertDatabase cert_database; |
| 216 bool web_trust = false; | 230 bool web_trust = false; |
| 217 base::ListValue* trust_list = NULL; | 231 base::ListValue* trust_list = NULL; |
| 218 if (certificate->GetList("Trust", &trust_list)) { | 232 if (certificate->GetList("Trust", &trust_list)) { |
| 219 for (size_t i = 0; i < trust_list->GetSize(); ++i) { | 233 for (size_t i = 0; i < trust_list->GetSize(); ++i) { |
| 220 std::string trust_type; | 234 std::string trust_type; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 std::string unique_id; | 360 std::string unique_id; |
| 347 if (!value.GetAsString(&unique_id)) | 361 if (!value.GetAsString(&unique_id)) |
| 348 break; | 362 break; |
| 349 wifi_network->set_unique_id(unique_id); | 363 wifi_network->set_unique_id(unique_id); |
| 350 return true; | 364 return true; |
| 351 } | 365 } |
| 352 case PROPERTY_INDEX_SECURITY: { | 366 case PROPERTY_INDEX_SECURITY: { |
| 353 std::string security_string; | 367 std::string security_string; |
| 354 if (!value.GetAsString(&security_string)) | 368 if (!value.GetAsString(&security_string)) |
| 355 break; | 369 break; |
| 356 wifi_network->set_encryption(ParseSecurity(security_string)); | 370 ConnectionSecurity security = ParseSecurity(security_string); |
| 371 wifi_network->set_encryption(security); | |
| 372 // Also update property with native value for security. | |
| 373 std::string str = | |
| 374 NativeNetworkParser::security_mapper()->GetKey(security); | |
| 375 scoped_ptr<StringValue> val(Value::CreateStringValue(str)); | |
| 376 wifi_network->UpdatePropertyMap(index, *val.get()); | |
| 357 return true; | 377 return true; |
| 358 } | 378 } |
| 359 case PROPERTY_INDEX_PASSPHRASE: { | 379 case PROPERTY_INDEX_PASSPHRASE: { |
| 360 std::string passphrase; | 380 std::string passphrase; |
| 361 if (!value.GetAsString(&passphrase)) | 381 if (!value.GetAsString(&passphrase)) |
| 362 break; | 382 break; |
| 363 wifi_network->set_passphrase(passphrase); | 383 wifi_network->set_passphrase(passphrase); |
| 364 return true; | 384 return true; |
| 365 } | 385 } |
| 366 case PROPERTY_INDEX_IDENTITY: { | 386 case PROPERTY_INDEX_IDENTITY: { |
| 367 std::string identity; | 387 std::string identity; |
| 368 if (!value.GetAsString(&identity)) | 388 if (!value.GetAsString(&identity)) |
| 369 break; | 389 break; |
| 370 wifi_network->set_identity(identity); | 390 wifi_network->set_identity(identity); |
| 371 return true; | 391 return true; |
| 372 } | 392 } |
| 373 case PROPERTY_INDEX_EAP: { | 393 case PROPERTY_INDEX_EAP: { |
| 374 DCHECK_EQ(value.GetType(), Value::TYPE_DICTIONARY); | 394 DCHECK_EQ(value.GetType(), Value::TYPE_DICTIONARY); |
| 375 const DictionaryValue& dict = static_cast<const DictionaryValue&>(value); | 395 const DictionaryValue& dict = static_cast<const DictionaryValue&>(value); |
| 376 for (DictionaryValue::key_iterator iter = dict.begin_keys(); | 396 for (DictionaryValue::key_iterator iter = dict.begin_keys(); |
| 377 iter != dict.end_keys(); ++iter) { | 397 iter != dict.end_keys(); ++iter) { |
| 378 const std::string& key = *iter; | 398 const std::string& key = *iter; |
| 379 base::Value* eap_value; | 399 base::Value* eap_value; |
| 380 bool res = dict.GetWithoutPathExpansion(key, &eap_value); | 400 bool res = dict.GetWithoutPathExpansion(key, &eap_value); |
| 381 DCHECK(res); | 401 DCHECK(res); |
| 382 if (res) { | 402 if (res) { |
| 383 PropertyIndex index = mapper().Get(key); | 403 PropertyIndex index = mapper().Get(key); |
| 404 wifi_network->UpdatePropertyMap(index, *eap_value); | |
| 384 if (!ParseEAPValue(index, *eap_value, wifi_network)) | 405 if (!ParseEAPValue(index, *eap_value, wifi_network)) |
| 385 VLOG(1) << network->name() << ": EAP unhandled key: " << key | 406 VLOG(1) << network->name() << ": EAP unhandled key: " << key |
| 386 << " Type: " << eap_value->GetType(); | 407 << " Type: " << eap_value->GetType(); |
| 387 } | 408 } |
| 388 } | 409 } |
| 389 return true; | 410 return true; |
| 390 } | 411 } |
| 391 default: | 412 default: |
| 392 return OncWirelessNetworkParser::ParseValue(index, value, network); | 413 return OncWirelessNetworkParser::ParseValue(index, value, network); |
| 393 } | 414 } |
| 394 return false; | 415 return false; |
| 395 } | 416 } |
| 396 | 417 |
| 397 | 418 |
| 398 bool OncWifiNetworkParser::ParseEAPValue(PropertyIndex index, | 419 bool OncWifiNetworkParser::ParseEAPValue(PropertyIndex index, |
| 399 const base::Value& value, | 420 const base::Value& value, |
| 400 WifiNetwork* wifi_network) { | 421 WifiNetwork* wifi_network) { |
| 401 switch (index) { | 422 switch (index) { |
| 402 case PROPERTY_INDEX_EAP_IDENTITY: { | 423 case PROPERTY_INDEX_EAP_IDENTITY: { |
| 403 std::string eap_identity; | 424 std::string eap_identity; |
| 404 if (!value.GetAsString(&eap_identity)) | 425 if (!value.GetAsString(&eap_identity)) |
| 405 break; | 426 break; |
| 406 wifi_network->set_eap_identity(eap_identity); | 427 wifi_network->set_eap_identity(eap_identity); |
|
stevenjb
2011/11/30 17:36:20
I believe that ken said something about saving EAP
kmixter1
2011/11/30 17:39:01
No need. The property map is updated in UpdateSta
Charlie Lee
2011/11/30 18:01:21
Yes, exactly.
| |
| 407 return true; | 428 return true; |
| 408 } | 429 } |
| 409 case PROPERTY_INDEX_EAP_METHOD: { | 430 case PROPERTY_INDEX_EAP_METHOD: { |
| 410 std::string eap_method; | 431 std::string eap_method_str; |
| 411 if (!value.GetAsString(&eap_method)) | 432 if (!value.GetAsString(&eap_method_str)) |
| 412 break; | 433 break; |
| 413 wifi_network->set_eap_method(ParseEAPMethod(eap_method)); | 434 EAPMethod eap_method = ParseEAPMethod(eap_method_str); |
| 435 wifi_network->set_eap_method(eap_method); | |
| 436 // Also update property with native value for EAP method. | |
| 437 std::string str = | |
| 438 NativeNetworkParser::eap_method_mapper()->GetKey(eap_method); | |
| 439 scoped_ptr<StringValue> val(Value::CreateStringValue(str)); | |
| 440 wifi_network->UpdatePropertyMap(index, *val.get()); | |
| 414 return true; | 441 return true; |
| 415 } | 442 } |
| 416 case PROPERTY_INDEX_EAP_PHASE_2_AUTH: { | 443 case PROPERTY_INDEX_EAP_PHASE_2_AUTH: { |
| 417 std::string eap_phase_2_auth; | 444 std::string eap_phase_2_auth_str; |
| 418 if (!value.GetAsString(&eap_phase_2_auth)) | 445 if (!value.GetAsString(&eap_phase_2_auth_str)) |
| 419 break; | 446 break; |
| 420 wifi_network->set_eap_phase_2_auth(ParseEAPPhase2Auth(eap_phase_2_auth)); | 447 EAPPhase2Auth eap_phase_2_auth = ParseEAPPhase2Auth(eap_phase_2_auth_str); |
| 448 wifi_network->set_eap_phase_2_auth(eap_phase_2_auth); | |
| 449 // Also update property with native value for EAP phase 2 auth. | |
| 450 std::string str = | |
| 451 NativeNetworkParser::eap_auth_mapper()->GetKey(eap_phase_2_auth); | |
| 452 scoped_ptr<StringValue> val(Value::CreateStringValue(str)); | |
| 453 wifi_network->UpdatePropertyMap(index, *val.get()); | |
| 421 return true; | 454 return true; |
| 422 } | 455 } |
| 423 case PROPERTY_INDEX_EAP_ANONYMOUS_IDENTITY: { | 456 case PROPERTY_INDEX_EAP_ANONYMOUS_IDENTITY: { |
| 424 std::string eap_anonymous_identity; | 457 std::string eap_anonymous_identity; |
| 425 if (!value.GetAsString(&eap_anonymous_identity)) | 458 if (!value.GetAsString(&eap_anonymous_identity)) |
| 426 break; | 459 break; |
| 427 wifi_network->set_eap_anonymous_identity(eap_anonymous_identity); | 460 wifi_network->set_eap_anonymous_identity(eap_anonymous_identity); |
| 428 return true; | 461 return true; |
| 429 } | 462 } |
| 430 case PROPERTY_INDEX_EAP_CERT_ID: { | 463 case PROPERTY_INDEX_EAP_CERT_ID: { |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 633 static EnumMapper<ProviderType>::Pair table[] = { | 666 static EnumMapper<ProviderType>::Pair table[] = { |
| 634 { flimflam::kProviderL2tpIpsec, PROVIDER_TYPE_L2TP_IPSEC_PSK }, | 667 { flimflam::kProviderL2tpIpsec, PROVIDER_TYPE_L2TP_IPSEC_PSK }, |
| 635 { flimflam::kProviderOpenVpn, PROVIDER_TYPE_OPEN_VPN }, | 668 { flimflam::kProviderOpenVpn, PROVIDER_TYPE_OPEN_VPN }, |
| 636 }; | 669 }; |
| 637 CR_DEFINE_STATIC_LOCAL(EnumMapper<ProviderType>, parser, | 670 CR_DEFINE_STATIC_LOCAL(EnumMapper<ProviderType>, parser, |
| 638 (table, arraysize(table), PROVIDER_TYPE_MAX)); | 671 (table, arraysize(table), PROVIDER_TYPE_MAX)); |
| 639 return parser.Get(type); | 672 return parser.Get(type); |
| 640 } | 673 } |
| 641 | 674 |
| 642 } // namespace chromeos | 675 } // namespace chromeos |
| OLD | NEW |