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

Side by Side Diff: chrome/browser/chromeos/cros/onc_network_parser.cc

Issue 8734013: Resubmit CL. See 8429004. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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
« no previous file with comments | « chrome/browser/chromeos/cros/onc_network_parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
22 namespace { 23 namespace {
23 24
24 EnumMapper<PropertyIndex>::Pair property_index_table[] = { 25 EnumMapper<PropertyIndex>::Pair property_index_table[] = {
25 { "GUID", PROPERTY_INDEX_GUID }, 26 { "GUID", PROPERTY_INDEX_GUID },
26 { "Name", PROPERTY_INDEX_NAME }, 27 { "Name", PROPERTY_INDEX_NAME },
27 { "Remove", PROPERTY_INDEX_REMOVE }, 28 { "Remove", PROPERTY_INDEX_REMOVE },
28 { "ProxyURL", PROPERTY_INDEX_PROXY_CONFIG }, 29 { "ProxyURL", PROPERTY_INDEX_PROXY_CONFIG },
29 { "Type", PROPERTY_INDEX_TYPE }, 30 { "Type", PROPERTY_INDEX_TYPE },
30 { "SSID", PROPERTY_INDEX_NAME }, 31 { "SSID", PROPERTY_INDEX_SSID },
31 { "Passphrase", PROPERTY_INDEX_PASSPHRASE }, 32 { "Passphrase", PROPERTY_INDEX_PASSPHRASE },
32 { "AutoConnect", PROPERTY_INDEX_AUTO_CONNECT }, 33 { "AutoConnect", PROPERTY_INDEX_AUTO_CONNECT },
33 { "HiddenSSID", PROPERTY_INDEX_HIDDEN_SSID }, 34 { "HiddenSSID", PROPERTY_INDEX_HIDDEN_SSID },
34 { "Security", PROPERTY_INDEX_SECURITY }, 35 { "Security", PROPERTY_INDEX_SECURITY },
35 { "EAP", PROPERTY_INDEX_EAP }, 36 { "EAP", PROPERTY_INDEX_EAP },
36 { "Outer", PROPERTY_INDEX_EAP_METHOD }, 37 { "Outer", PROPERTY_INDEX_EAP_METHOD },
37 { "Inner", PROPERTY_INDEX_EAP_PHASE_2_AUTH }, 38 { "Inner", PROPERTY_INDEX_EAP_PHASE_2_AUTH },
38 { "UseSystemCAs", PROPERTY_INDEX_EAP_USE_SYSTEM_CAS }, 39 { "UseSystemCAs", PROPERTY_INDEX_EAP_USE_SYSTEM_CAS },
39 { "ServerCARef", PROPERTY_INDEX_EAP_CA_CERT }, 40 { "ServerCARef", PROPERTY_INDEX_EAP_CA_CERT },
40 { "ClientCARef", PROPERTY_INDEX_EAP_CLIENT_CERT }, 41 { "ClientCARef", PROPERTY_INDEX_EAP_CLIENT_CERT },
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::network_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
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 346
333 OncWifiNetworkParser::OncWifiNetworkParser() {} 347 OncWifiNetworkParser::OncWifiNetworkParser() {}
334 OncWifiNetworkParser::~OncWifiNetworkParser() {} 348 OncWifiNetworkParser::~OncWifiNetworkParser() {}
335 349
336 bool OncWifiNetworkParser::ParseValue(PropertyIndex index, 350 bool OncWifiNetworkParser::ParseValue(PropertyIndex index,
337 const base::Value& value, 351 const base::Value& value,
338 Network* network) { 352 Network* network) {
339 DCHECK_EQ(TYPE_WIFI, network->type()); 353 DCHECK_EQ(TYPE_WIFI, network->type());
340 WifiNetwork* wifi_network = static_cast<WifiNetwork*>(network); 354 WifiNetwork* wifi_network = static_cast<WifiNetwork*>(network);
341 switch (index) { 355 switch (index) {
342 case PROPERTY_INDEX_NAME: { 356 case PROPERTY_INDEX_SSID: {
343 return OncWirelessNetworkParser::ParseValue(index, value, network); 357 std::string ssid;
358 if (!value.GetAsString(&ssid))
359 break;
360 wifi_network->SetName(ssid);
361 return true;
344 } 362 }
345 case PROPERTY_INDEX_GUID: { 363 case PROPERTY_INDEX_GUID: {
346 std::string unique_id; 364 std::string unique_id;
347 if (!value.GetAsString(&unique_id)) 365 if (!value.GetAsString(&unique_id))
348 break; 366 break;
349 wifi_network->set_unique_id(unique_id); 367 wifi_network->set_unique_id(unique_id);
350 return true; 368 return true;
351 } 369 }
352 case PROPERTY_INDEX_SECURITY: { 370 case PROPERTY_INDEX_SECURITY: {
353 std::string security_string; 371 std::string security_string;
354 if (!value.GetAsString(&security_string)) 372 if (!value.GetAsString(&security_string))
355 break; 373 break;
356 wifi_network->set_encryption(ParseSecurity(security_string)); 374 ConnectionSecurity security = ParseSecurity(security_string);
375 wifi_network->set_encryption(security);
376 // Also update property with native value for security.
377 std::string str =
378 NativeNetworkParser::network_security_mapper()->GetKey(security);
379 scoped_ptr<StringValue> val(Value::CreateStringValue(str));
380 wifi_network->UpdatePropertyMap(index, *val.get());
357 return true; 381 return true;
358 } 382 }
359 case PROPERTY_INDEX_PASSPHRASE: { 383 case PROPERTY_INDEX_PASSPHRASE: {
360 std::string passphrase; 384 std::string passphrase;
361 if (!value.GetAsString(&passphrase)) 385 if (!value.GetAsString(&passphrase))
362 break; 386 break;
363 wifi_network->set_passphrase(passphrase); 387 wifi_network->set_passphrase(passphrase);
364 return true; 388 return true;
365 } 389 }
366 case PROPERTY_INDEX_IDENTITY: { 390 case PROPERTY_INDEX_IDENTITY: {
367 std::string identity; 391 std::string identity;
368 if (!value.GetAsString(&identity)) 392 if (!value.GetAsString(&identity))
369 break; 393 break;
370 wifi_network->set_identity(identity); 394 wifi_network->set_identity(identity);
371 return true; 395 return true;
372 } 396 }
373 case PROPERTY_INDEX_EAP: { 397 case PROPERTY_INDEX_EAP: {
374 DCHECK_EQ(value.GetType(), Value::TYPE_DICTIONARY); 398 DCHECK_EQ(value.GetType(), Value::TYPE_DICTIONARY);
375 const DictionaryValue& dict = static_cast<const DictionaryValue&>(value); 399 const DictionaryValue& dict = static_cast<const DictionaryValue&>(value);
376 for (DictionaryValue::key_iterator iter = dict.begin_keys(); 400 for (DictionaryValue::key_iterator iter = dict.begin_keys();
377 iter != dict.end_keys(); ++iter) { 401 iter != dict.end_keys(); ++iter) {
378 const std::string& key = *iter; 402 const std::string& key = *iter;
379 base::Value* eap_value; 403 base::Value* eap_value;
380 bool res = dict.GetWithoutPathExpansion(key, &eap_value); 404 bool res = dict.GetWithoutPathExpansion(key, &eap_value);
381 DCHECK(res); 405 DCHECK(res);
382 if (res) { 406 if (res) {
383 PropertyIndex index = mapper().Get(key); 407 PropertyIndex index = mapper().Get(key);
408 wifi_network->UpdatePropertyMap(index, *eap_value);
384 if (!ParseEAPValue(index, *eap_value, wifi_network)) 409 if (!ParseEAPValue(index, *eap_value, wifi_network))
385 VLOG(1) << network->name() << ": EAP unhandled key: " << key 410 VLOG(1) << network->name() << ": EAP unhandled key: " << key
386 << " Type: " << eap_value->GetType(); 411 << " Type: " << eap_value->GetType();
387 } 412 }
388 } 413 }
389 return true; 414 return true;
390 } 415 }
391 default: 416 default:
392 return OncWirelessNetworkParser::ParseValue(index, value, network); 417 return OncWirelessNetworkParser::ParseValue(index, value, network);
393 } 418 }
394 return false; 419 return false;
395 } 420 }
396 421
397 422
398 bool OncWifiNetworkParser::ParseEAPValue(PropertyIndex index, 423 bool OncWifiNetworkParser::ParseEAPValue(PropertyIndex index,
399 const base::Value& value, 424 const base::Value& value,
400 WifiNetwork* wifi_network) { 425 WifiNetwork* wifi_network) {
401 switch (index) { 426 switch (index) {
402 case PROPERTY_INDEX_EAP_IDENTITY: { 427 case PROPERTY_INDEX_EAP_IDENTITY: {
403 std::string eap_identity; 428 std::string eap_identity;
404 if (!value.GetAsString(&eap_identity)) 429 if (!value.GetAsString(&eap_identity))
405 break; 430 break;
406 wifi_network->set_eap_identity(eap_identity); 431 wifi_network->set_eap_identity(eap_identity);
407 return true; 432 return true;
408 } 433 }
409 case PROPERTY_INDEX_EAP_METHOD: { 434 case PROPERTY_INDEX_EAP_METHOD: {
410 std::string eap_method; 435 std::string eap_method_str;
411 if (!value.GetAsString(&eap_method)) 436 if (!value.GetAsString(&eap_method_str))
412 break; 437 break;
413 wifi_network->set_eap_method(ParseEAPMethod(eap_method)); 438 EAPMethod eap_method = ParseEAPMethod(eap_method_str);
439 wifi_network->set_eap_method(eap_method);
440 // Also update property with native value for EAP method.
441 std::string str =
442 NativeNetworkParser::network_eap_method_mapper()->GetKey(eap_method);
443 scoped_ptr<StringValue> val(Value::CreateStringValue(str));
444 wifi_network->UpdatePropertyMap(index, *val.get());
414 return true; 445 return true;
415 } 446 }
416 case PROPERTY_INDEX_EAP_PHASE_2_AUTH: { 447 case PROPERTY_INDEX_EAP_PHASE_2_AUTH: {
417 std::string eap_phase_2_auth; 448 std::string eap_phase_2_auth_str;
418 if (!value.GetAsString(&eap_phase_2_auth)) 449 if (!value.GetAsString(&eap_phase_2_auth_str))
419 break; 450 break;
420 wifi_network->set_eap_phase_2_auth(ParseEAPPhase2Auth(eap_phase_2_auth)); 451 EAPPhase2Auth eap_phase_2_auth = ParseEAPPhase2Auth(eap_phase_2_auth_str);
452 wifi_network->set_eap_phase_2_auth(eap_phase_2_auth);
453 // Also update property with native value for EAP phase 2 auth.
454 std::string str = NativeNetworkParser::network_eap_auth_mapper()->GetKey(
455 eap_phase_2_auth);
456 scoped_ptr<StringValue> val(Value::CreateStringValue(str));
457 wifi_network->UpdatePropertyMap(index, *val.get());
421 return true; 458 return true;
422 } 459 }
423 case PROPERTY_INDEX_EAP_ANONYMOUS_IDENTITY: { 460 case PROPERTY_INDEX_EAP_ANONYMOUS_IDENTITY: {
424 std::string eap_anonymous_identity; 461 std::string eap_anonymous_identity;
425 if (!value.GetAsString(&eap_anonymous_identity)) 462 if (!value.GetAsString(&eap_anonymous_identity))
426 break; 463 break;
427 wifi_network->set_eap_anonymous_identity(eap_anonymous_identity); 464 wifi_network->set_eap_anonymous_identity(eap_anonymous_identity);
428 return true; 465 return true;
429 } 466 }
430 case PROPERTY_INDEX_EAP_CERT_ID: { 467 case PROPERTY_INDEX_EAP_CERT_ID: {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 static EnumMapper<ProviderType>::Pair table[] = { 670 static EnumMapper<ProviderType>::Pair table[] = {
634 { flimflam::kProviderL2tpIpsec, PROVIDER_TYPE_L2TP_IPSEC_PSK }, 671 { flimflam::kProviderL2tpIpsec, PROVIDER_TYPE_L2TP_IPSEC_PSK },
635 { flimflam::kProviderOpenVpn, PROVIDER_TYPE_OPEN_VPN }, 672 { flimflam::kProviderOpenVpn, PROVIDER_TYPE_OPEN_VPN },
636 }; 673 };
637 CR_DEFINE_STATIC_LOCAL(EnumMapper<ProviderType>, parser, 674 CR_DEFINE_STATIC_LOCAL(EnumMapper<ProviderType>, parser,
638 (table, arraysize(table), PROVIDER_TYPE_MAX)); 675 (table, arraysize(table), PROVIDER_TYPE_MAX));
639 return parser.Get(type); 676 return parser.Get(type);
640 } 677 }
641 678
642 } // namespace chromeos 679 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/onc_network_parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698