| 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 <pk11pub.h> | 7 #include <pk11pub.h> |
| 8 #include <keyhi.h> | 8 #include <keyhi.h> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| 11 #include "base/json/json_value_serializer.h" | 11 #include "base/json/json_value_serializer.h" |
| 12 #include "base/json/json_writer.h" // for debug output only. | 12 #include "base/json/json_writer.h" // for debug output only. |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/chromeos/cros/native_network_constants.h" | 15 #include "chrome/browser/chromeos/cros/native_network_constants.h" |
| 16 #include "chrome/browser/chromeos/cros/native_network_parser.h" | 16 #include "chrome/browser/chromeos/cros/native_network_parser.h" |
| 17 #include "chrome/browser/chromeos/cros/network_library.h" | 17 #include "chrome/browser/chromeos/cros/network_library.h" |
| 18 #include "chrome/common/net/x509_certificate_model.h" | 18 #include "chrome/common/net/x509_certificate_model.h" |
| 19 #include "grit/generated_resources.h" | |
| 20 #include "net/base/cert_database.h" | 19 #include "net/base/cert_database.h" |
| 21 #include "net/base/crypto_module.h" | 20 #include "net/base/crypto_module.h" |
| 22 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 23 #include "net/base/x509_certificate.h" | 22 #include "net/base/x509_certificate.h" |
| 24 #include "third_party/cros_system_api/dbus/service_constants.h" | 23 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | |
| 26 | 24 |
| 27 namespace chromeos { | 25 namespace chromeos { |
| 28 | 26 |
| 29 // Local constants. | 27 // Local constants. |
| 30 namespace { | 28 namespace { |
| 31 | 29 |
| 32 const base::Value::Type TYPE_BOOLEAN = base::Value::TYPE_BOOLEAN; | 30 const base::Value::Type TYPE_BOOLEAN = base::Value::TYPE_BOOLEAN; |
| 33 const base::Value::Type TYPE_DICTIONARY = base::Value::TYPE_DICTIONARY; | 31 const base::Value::Type TYPE_DICTIONARY = base::Value::TYPE_DICTIONARY; |
| 34 const base::Value::Type TYPE_INTEGER = base::Value::TYPE_INTEGER; | 32 const base::Value::Type TYPE_INTEGER = base::Value::TYPE_INTEGER; |
| 35 const base::Value::Type TYPE_LIST = base::Value::TYPE_LIST; | 33 const base::Value::Type TYPE_LIST = base::Value::TYPE_LIST; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 } | 228 } |
| 231 | 229 |
| 232 int OncNetworkParser::GetCertificatesSize() const { | 230 int OncNetworkParser::GetCertificatesSize() const { |
| 233 return certificates_ ? certificates_->GetSize() : 0; | 231 return certificates_ ? certificates_->GetSize() : 0; |
| 234 } | 232 } |
| 235 | 233 |
| 236 scoped_refptr<net::X509Certificate> OncNetworkParser::ParseCertificate( | 234 scoped_refptr<net::X509Certificate> OncNetworkParser::ParseCertificate( |
| 237 int cert_index) { | 235 int cert_index) { |
| 238 CHECK(certificates_); | 236 CHECK(certificates_); |
| 239 CHECK(static_cast<size_t>(cert_index) < certificates_->GetSize()); | 237 CHECK(static_cast<size_t>(cert_index) < certificates_->GetSize()); |
| 240 CHECK_GE(cert_index, 0); | 238 CHECK(cert_index >= 0); |
| 241 base::DictionaryValue* certificate = NULL; | 239 base::DictionaryValue* certificate = NULL; |
| 242 if (!certificates_->GetDictionary(cert_index, &certificate)) { | 240 certificates_->GetDictionary(cert_index, &certificate); |
| 243 parse_error_ = l10n_util::GetStringUTF8( | 241 CHECK(certificate); |
| 244 IDS_NETWORK_CONFIG_ERROR_CERT_DATA_MALFORMED); | |
| 245 return NULL; | |
| 246 } | |
| 247 | 242 |
| 248 if (VLOG_IS_ON(2)) { | 243 if (VLOG_IS_ON(2)) { |
| 249 std::string certificate_json; | 244 std::string certificate_json; |
| 250 base::JSONWriter::Write(static_cast<base::Value*>(certificate), | 245 base::JSONWriter::Write(static_cast<base::Value*>(certificate), |
| 251 true, &certificate_json); | 246 true, &certificate_json); |
| 252 VLOG(2) << "Parsing certificate at index " << cert_index | 247 VLOG(2) << "Parsing certificate at index " << cert_index |
| 253 << ": " << certificate_json; | 248 << ": " << certificate_json; |
| 254 } | 249 } |
| 255 | 250 |
| 256 // Get out the attributes of the given certificate. | 251 // Get out the attributes of the given certificate. |
| 257 std::string guid; | 252 std::string guid; |
| 258 bool remove = false; | 253 bool remove = false; |
| 259 if (!certificate->GetString("GUID", &guid) || guid.empty()) { | 254 if (!certificate->GetString("GUID", &guid) || guid.empty()) { |
| 260 LOG(WARNING) << "ONC File: certificate missing identifier at index" | 255 LOG(WARNING) << "ONC File: certificate missing identifier at index" |
| 261 << cert_index; | 256 << cert_index; |
| 262 parse_error_ = l10n_util::GetStringUTF8( | |
| 263 IDS_NETWORK_CONFIG_ERROR_CERT_GUID_MISSING); | |
| 264 return NULL; | 257 return NULL; |
| 265 } | 258 } |
| 266 | 259 |
| 267 if (!certificate->GetBoolean("Remove", &remove)) | 260 if (!certificate->GetBoolean("Remove", &remove)) |
| 268 remove = false; | 261 remove = false; |
| 269 | 262 |
| 270 net::CertDatabase cert_database; | 263 net::CertDatabase cert_database; |
| 271 if (remove) { | 264 if (remove) { |
| 272 if (!DeleteCertAndKeyByNickname(guid)) { | 265 bool success = DeleteCertAndKeyByNickname(guid); |
| 273 parse_error_ = l10n_util::GetStringUTF8( | 266 DCHECK(success); |
| 274 IDS_NETWORK_CONFIG_ERROR_CERT_DELETE); | 267 // TODO(gspencer): return removed certificate? |
| 275 } | |
| 276 return NULL; | 268 return NULL; |
| 277 } | 269 } |
| 278 | 270 |
| 279 // Not removing, so let's get the data we need to add this certificate. | 271 // Not removing, so let's get the data we need to add this certificate. |
| 280 std::string cert_type; | 272 std::string cert_type; |
| 281 certificate->GetString("Type", &cert_type); | 273 certificate->GetString("Type", &cert_type); |
| 282 if (cert_type == "Server" || cert_type == "Authority") { | 274 if (cert_type == "Server" || cert_type == "Authority") { |
| 283 return ParseServerOrCaCertificate(cert_index, cert_type, guid, certificate); | 275 return ParseServerOrCaCertificate(cert_index, cert_type, guid, certificate); |
| 284 } | 276 } |
| 285 if (cert_type == "Client") { | 277 if (cert_type == "Client") { |
| 286 return ParseClientCertificate(cert_index, guid, certificate); | 278 return ParseClientCertificate(cert_index, guid, certificate); |
| 287 } | 279 } |
| 288 | 280 |
| 289 LOG(WARNING) << "ONC File: certificate of unknown type: " << cert_type | 281 LOG(WARNING) << "ONC File: certificate of unknown type: " << cert_type |
| 290 << " at index " << cert_index; | 282 << " at index " << cert_index; |
| 291 parse_error_ = l10n_util::GetStringUTF8( | |
| 292 IDS_NETWORK_CONFIG_ERROR_CERT_TYPE_MISSING); | |
| 293 return NULL; | 283 return NULL; |
| 294 } | 284 } |
| 295 | 285 |
| 296 Network* OncNetworkParser::ParseNetwork(int n) { | 286 Network* OncNetworkParser::ParseNetwork(int n) { |
| 297 CHECK(network_configs_); | 287 if (!network_configs_) |
| 298 CHECK(static_cast<size_t>(n) < network_configs_->GetSize()); | 288 return NULL; |
| 299 CHECK_GE(n, 0); | |
| 300 DictionaryValue* info = NULL; | 289 DictionaryValue* info = NULL; |
| 301 if (!network_configs_->GetDictionary(n, &info)) { | 290 if (!network_configs_->GetDictionary(n, &info)) |
| 302 parse_error_ = l10n_util::GetStringUTF8( | |
| 303 IDS_NETWORK_CONFIG_ERROR_NETWORK_PROP_DICT_MALFORMED); | |
| 304 return NULL; | 291 return NULL; |
| 305 } | |
| 306 | |
| 307 if (VLOG_IS_ON(2)) { | 292 if (VLOG_IS_ON(2)) { |
| 308 std::string network_json; | 293 std::string network_json; |
| 309 base::JSONWriter::Write(static_cast<base::Value*>(info), | 294 base::JSONWriter::Write(static_cast<base::Value*>(info), |
| 310 true, &network_json); | 295 true, &network_json); |
| 311 VLOG(2) << "Parsing network at index " << n | 296 VLOG(2) << "Parsing network at index " << n |
| 312 << ": " << network_json; | 297 << ": " << network_json; |
| 313 } | 298 } |
| 314 | 299 |
| 315 return CreateNetworkFromInfo(std::string(), *info); | 300 return CreateNetworkFromInfo(std::string(), *info); |
| 316 } | 301 } |
| 317 | 302 |
| 318 Network* OncNetworkParser::CreateNetworkFromInfo( | 303 Network* OncNetworkParser::CreateNetworkFromInfo( |
| 319 const std::string& service_path, | 304 const std::string& service_path, |
| 320 const DictionaryValue& info) { | 305 const DictionaryValue& info) { |
| 321 ConnectionType type = ParseTypeFromDictionary(info); | 306 ConnectionType type = ParseTypeFromDictionary(info); |
| 322 if (type == TYPE_UNKNOWN) { // Return NULL if cannot parse network type. | 307 if (type == TYPE_UNKNOWN) // Return NULL if cannot parse network type. |
| 323 parse_error_ = l10n_util::GetStringUTF8( | |
| 324 IDS_NETWORK_CONFIG_ERROR_NETWORK_TYPE_MISSING); | |
| 325 return NULL; | 308 return NULL; |
| 326 } | |
| 327 scoped_ptr<Network> network(CreateNewNetwork(type, service_path)); | 309 scoped_ptr<Network> network(CreateNewNetwork(type, service_path)); |
| 328 if (!ParseNestedObject(network.get(), | 310 if (!ParseNestedObject(network.get(), |
| 329 "NetworkConfiguration", | 311 "NetworkConfiguration", |
| 330 static_cast<const base::Value&>(info), | 312 static_cast<const base::Value&>(info), |
| 331 network_configuration_signature, | 313 network_configuration_signature, |
| 332 ParseNetworkConfigurationValue)) { | 314 ParseNetworkConfigurationValue)) { |
| 333 LOG(WARNING) << "Network " << network->name() << " failed to parse."; | 315 LOG(WARNING) << "Network " << network->name() << " failed to parse."; |
| 334 if (parse_error_.empty()) | |
| 335 parse_error_ = l10n_util::GetStringUTF8( | |
| 336 IDS_NETWORK_CONFIG_ERROR_NETWORK_PROP_DICT_MALFORMED); | |
| 337 return NULL; | 316 return NULL; |
| 338 } | 317 } |
| 339 if (VLOG_IS_ON(2)) { | 318 if (VLOG_IS_ON(2)) { |
| 340 VLOG(2) << "Created Network '" << network->name() | 319 VLOG(2) << "Created Network '" << network->name() |
| 341 << "' from info. Path:" << service_path | 320 << "' from info. Path:" << service_path |
| 342 << " Type:" << ConnectionTypeToString(type); | 321 << " Type:" << ConnectionTypeToString(type); |
| 343 } | 322 } |
| 344 return network.release(); | 323 return network.release(); |
| 345 } | 324 } |
| 346 | 325 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 base::DictionaryValue* certificate) { | 366 base::DictionaryValue* certificate) { |
| 388 net::CertDatabase cert_database; | 367 net::CertDatabase cert_database; |
| 389 bool web_trust = false; | 368 bool web_trust = false; |
| 390 base::ListValue* trust_list = NULL; | 369 base::ListValue* trust_list = NULL; |
| 391 if (certificate->GetList("Trust", &trust_list)) { | 370 if (certificate->GetList("Trust", &trust_list)) { |
| 392 for (size_t i = 0; i < trust_list->GetSize(); ++i) { | 371 for (size_t i = 0; i < trust_list->GetSize(); ++i) { |
| 393 std::string trust_type; | 372 std::string trust_type; |
| 394 if (!trust_list->GetString(i, &trust_type)) { | 373 if (!trust_list->GetString(i, &trust_type)) { |
| 395 LOG(WARNING) << "ONC File: certificate trust is invalid at index " | 374 LOG(WARNING) << "ONC File: certificate trust is invalid at index " |
| 396 << cert_index; | 375 << cert_index; |
| 397 parse_error_ = l10n_util::GetStringUTF8( | |
| 398 IDS_NETWORK_CONFIG_ERROR_CERT_TRUST_INVALID); | |
| 399 return NULL; | 376 return NULL; |
| 400 } | 377 } |
| 401 if (trust_type == "Web") { | 378 if (trust_type == "Web") { |
| 402 web_trust = true; | 379 web_trust = true; |
| 403 } else { | 380 } else { |
| 404 LOG(WARNING) << "ONC File: certificate contains unknown " | 381 LOG(WARNING) << "ONC File: certificate contains unknown " |
| 405 << "trust type: " << trust_type | 382 << "trust type: " << trust_type |
| 406 << " at index " << cert_index; | 383 << " at index " << cert_index; |
| 407 parse_error_ = l10n_util::GetStringUTF8( | |
| 408 IDS_NETWORK_CONFIG_ERROR_CERT_TRUST_UNKNOWN); | |
| 409 return NULL; | 384 return NULL; |
| 410 } | 385 } |
| 411 } | 386 } |
| 412 } | 387 } |
| 413 | 388 |
| 414 std::string x509_data; | 389 std::string x509_data; |
| 415 if (!certificate->GetString("X509", &x509_data) || x509_data.empty()) { | 390 if (!certificate->GetString("X509", &x509_data) || x509_data.empty()) { |
| 416 LOG(WARNING) << "ONC File: certificate missing appropriate " | 391 LOG(WARNING) << "ONC File: certificate missing appropriate " |
| 417 << "certificate data for type: " << cert_type | 392 << "certificate data for type: " << cert_type |
| 418 << " at index " << cert_index; | 393 << " at index " << cert_index; |
| 419 parse_error_ = l10n_util::GetStringUTF8( | |
| 420 IDS_NETWORK_CONFIG_ERROR_CERT_DATA_MISSING); | |
| 421 return NULL; | 394 return NULL; |
| 422 } | 395 } |
| 423 | 396 |
| 424 std::string decoded_x509; | 397 std::string decoded_x509; |
| 425 if (!base::Base64Decode(x509_data, &decoded_x509)) { | 398 if (!base::Base64Decode(x509_data, &decoded_x509)) { |
| 426 LOG(WARNING) << "Unable to base64 decode X509 data: \"" | 399 LOG(WARNING) << "Unable to base64 decode X509 data: \"" |
| 427 << x509_data << "\"."; | 400 << x509_data << "\"."; |
| 428 parse_error_ = l10n_util::GetStringUTF8( | |
| 429 IDS_NETWORK_CONFIG_ERROR_CERT_DATA_MALFORMED); | |
| 430 return NULL; | 401 return NULL; |
| 431 } | 402 } |
| 432 | 403 |
| 433 scoped_refptr<net::X509Certificate> x509_cert = | 404 scoped_refptr<net::X509Certificate> x509_cert = |
| 434 net::X509Certificate::CreateFromBytesWithNickname( | 405 net::X509Certificate::CreateFromBytesWithNickname( |
| 435 decoded_x509.c_str(), | 406 decoded_x509.c_str(), |
| 436 decoded_x509.size(), | 407 decoded_x509.size(), |
| 437 guid.c_str()); | 408 guid.c_str()); |
| 438 if (!x509_cert.get()) { | 409 if (!x509_cert.get()) { |
| 439 LOG(WARNING) << "Unable to create X509 certificate from bytes."; | 410 LOG(WARNING) << "Unable to create X509 certificate from bytes."; |
| 440 parse_error_ = l10n_util::GetStringUTF8( | |
| 441 IDS_NETWORK_CONFIG_ERROR_CERT_DATA_MALFORMED); | |
| 442 return NULL; | 411 return NULL; |
| 443 } | 412 } |
| 444 | 413 |
| 445 net::CertificateList cert_list; | 414 net::CertificateList cert_list; |
| 446 cert_list.push_back(x509_cert); | 415 cert_list.push_back(x509_cert); |
| 447 net::CertDatabase::ImportCertFailureList failures; | 416 net::CertDatabase::ImportCertFailureList failures; |
| 448 bool success = false; | 417 bool success = false; |
| 449 if (cert_type == "Server") { | 418 if (cert_type == "Server") { |
| 450 success = cert_database.ImportServerCert(cert_list, &failures); | 419 success = cert_database.ImportServerCert(cert_list, &failures); |
| 451 } else { // Authority cert | 420 } else { // Authority cert |
| 452 net::CertDatabase::TrustBits trust = web_trust ? | 421 net::CertDatabase::TrustBits trust = web_trust ? |
| 453 net::CertDatabase::TRUSTED_SSL : | 422 net::CertDatabase::TRUSTED_SSL : |
| 454 net::CertDatabase::UNTRUSTED; | 423 net::CertDatabase::UNTRUSTED; |
| 455 success = cert_database.ImportCACerts(cert_list, trust, &failures); | 424 success = cert_database.ImportCACerts(cert_list, trust, &failures); |
| 456 } | 425 } |
| 457 if (!failures.empty()) { | 426 if (!failures.empty()) { |
| 458 LOG(WARNING) << "ONC File: Error (" | 427 LOG(WARNING) << "ONC File: Error (" |
| 459 << net::ErrorToString(failures[0].net_error) | 428 << net::ErrorToString(failures[0].net_error) |
| 460 << ") importing " << cert_type << " certificate at index " | 429 << ") importing " << cert_type << " certificate at index " |
| 461 << cert_index; | 430 << cert_index; |
| 462 parse_error_ = l10n_util::GetStringUTF8( | |
| 463 IDS_NETWORK_CONFIG_ERROR_CERT_IMPORT); | |
| 464 return NULL; | 431 return NULL; |
| 465 } | 432 } |
| 466 if (!success) { | 433 if (!success) { |
| 467 LOG(WARNING) << "ONC File: Unknown error importing " << cert_type | 434 LOG(WARNING) << "ONC File: Unknown error importing " << cert_type |
| 468 << " certificate at index " << cert_index; | 435 << " certificate at index " << cert_index; |
| 469 parse_error_ = l10n_util::GetStringUTF8( | |
| 470 IDS_NETWORK_CONFIG_ERROR_UNKNOWN); | |
| 471 return NULL; | 436 return NULL; |
| 472 } | 437 } |
| 473 VLOG(2) << "Successfully imported server/ca certificate at index " | 438 VLOG(2) << "Successfully imported server/ca certificate at index " |
| 474 << cert_index; | 439 << cert_index; |
| 475 | 440 |
| 476 return x509_cert; | 441 return x509_cert; |
| 477 } | 442 } |
| 478 | 443 |
| 479 scoped_refptr<net::X509Certificate> OncNetworkParser::ParseClientCertificate( | 444 scoped_refptr<net::X509Certificate> OncNetworkParser::ParseClientCertificate( |
| 480 int cert_index, | 445 int cert_index, |
| 481 const std::string& guid, | 446 const std::string& guid, |
| 482 base::DictionaryValue* certificate) { | 447 base::DictionaryValue* certificate) { |
| 483 net::CertDatabase cert_database; | 448 net::CertDatabase cert_database; |
| 484 std::string pkcs12_data; | 449 std::string pkcs12_data; |
| 485 if (!certificate->GetString("PKCS12", &pkcs12_data) || | 450 if (!certificate->GetString("PKCS12", &pkcs12_data) || |
| 486 pkcs12_data.empty()) { | 451 pkcs12_data.empty()) { |
| 487 LOG(WARNING) << "ONC File: PKCS12 data is missing for Client " | 452 LOG(WARNING) << "ONC File: PKCS12 data is missing for Client " |
| 488 << "certificate at index " << cert_index; | 453 << "certificate at index " << cert_index; |
| 489 parse_error_ = l10n_util::GetStringUTF8( | |
| 490 IDS_NETWORK_CONFIG_ERROR_CERT_DATA_MISSING); | |
| 491 return NULL; | 454 return NULL; |
| 492 } | 455 } |
| 493 | 456 |
| 494 std::string decoded_pkcs12; | 457 std::string decoded_pkcs12; |
| 495 if (!base::Base64Decode(pkcs12_data, &decoded_pkcs12)) { | 458 if (!base::Base64Decode(pkcs12_data, &decoded_pkcs12)) { |
| 496 LOG(WARNING) << "Unable to base64 decode PKCS#12 data: \"" | 459 LOG(WARNING) << "Unable to base64 decode PKCS#12 data: \"" |
| 497 << pkcs12_data << "\"."; | 460 << pkcs12_data << "\"."; |
| 498 parse_error_ = l10n_util::GetStringUTF8( | |
| 499 IDS_NETWORK_CONFIG_ERROR_CERT_DATA_MALFORMED); | |
| 500 return NULL; | 461 return NULL; |
| 501 } | 462 } |
| 502 | 463 |
| 503 // Since this has a private key, always use the private module. | 464 // Since this has a private key, always use the private module. |
| 504 scoped_refptr<net::CryptoModule> module(cert_database.GetPrivateModule()); | 465 scoped_refptr<net::CryptoModule> module(cert_database.GetPrivateModule()); |
| 505 net::CertificateList imported_certs; | 466 net::CertificateList imported_certs; |
| 506 | 467 |
| 507 int result = cert_database.ImportFromPKCS12( | 468 int result = cert_database.ImportFromPKCS12( |
| 508 module.get(), decoded_pkcs12, string16(), false, &imported_certs); | 469 module.get(), decoded_pkcs12, string16(), false, &imported_certs); |
| 509 if (result != net::OK) { | 470 if (result != net::OK) { |
| 510 LOG(WARNING) << "ONC File: Unable to import Client certificate at index " | 471 LOG(WARNING) << "ONC File: Unable to import Client certificate at index " |
| 511 << cert_index | 472 << cert_index |
| 512 << " (error " << net::ErrorToString(result) << ")."; | 473 << " (error " << net::ErrorToString(result) << ")."; |
| 513 parse_error_ = l10n_util::GetStringUTF8( | |
| 514 IDS_NETWORK_CONFIG_ERROR_CERT_IMPORT); | |
| 515 return NULL; | 474 return NULL; |
| 516 } | 475 } |
| 517 | 476 |
| 518 if (imported_certs.size() == 0) { | 477 if (imported_certs.size() == 0) { |
| 519 LOG(WARNING) << "ONC File: PKCS12 data contains no importable certificates" | 478 LOG(WARNING) << "ONC File: PKCS12 data contains no importable certificates" |
| 520 << " at index " << cert_index; | 479 << " at index " << cert_index; |
| 521 return NULL; | 480 return NULL; |
| 522 } | 481 } |
| 523 | 482 |
| 524 if (imported_certs.size() != 1) { | 483 if (imported_certs.size() != 1) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 549 } | 508 } |
| 550 | 509 |
| 551 bool OncNetworkParser::ParseNestedObject(Network* network, | 510 bool OncNetworkParser::ParseNestedObject(Network* network, |
| 552 const std::string& onc_type, | 511 const std::string& onc_type, |
| 553 const base::Value& value, | 512 const base::Value& value, |
| 554 OncValueSignature* signature, | 513 OncValueSignature* signature, |
| 555 ParserPointer parser) { | 514 ParserPointer parser) { |
| 556 bool any_errors = false; | 515 bool any_errors = false; |
| 557 if (!value.IsType(base::Value::TYPE_DICTIONARY)) { | 516 if (!value.IsType(base::Value::TYPE_DICTIONARY)) { |
| 558 VLOG(1) << network->name() << ": expected object of type " << onc_type; | 517 VLOG(1) << network->name() << ": expected object of type " << onc_type; |
| 559 parse_error_ = l10n_util::GetStringUTF8( | |
| 560 IDS_NETWORK_CONFIG_ERROR_NETWORK_PROP_DICT_MALFORMED); | |
| 561 return false; | 518 return false; |
| 562 } | 519 } |
| 563 VLOG(2) << "Parsing nested object of type " << onc_type; | 520 VLOG(2) << "Parsing nested object of type " << onc_type; |
| 564 const DictionaryValue* dict = NULL; | 521 const DictionaryValue* dict = NULL; |
| 565 value.GetAsDictionary(&dict); | 522 value.GetAsDictionary(&dict); |
| 566 for (DictionaryValue::key_iterator iter = dict->begin_keys(); | 523 for (DictionaryValue::key_iterator iter = dict->begin_keys(); |
| 567 iter != dict->end_keys(); ++iter) { | 524 iter != dict->end_keys(); ++iter) { |
| 568 const std::string& key = *iter; | 525 const std::string& key = *iter; |
| 569 base::Value* inner_value = NULL; | 526 base::Value* inner_value = NULL; |
| 570 dict->GetWithoutPathExpansion(key, &inner_value); | 527 dict->GetWithoutPathExpansion(key, &inner_value); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 596 any_errors = true; | 553 any_errors = true; |
| 597 continue; | 554 continue; |
| 598 } | 555 } |
| 599 if (VLOG_IS_ON(2)) { | 556 if (VLOG_IS_ON(2)) { |
| 600 std::string value_json; | 557 std::string value_json; |
| 601 base::JSONWriter::Write(inner_value, true, &value_json); | 558 base::JSONWriter::Write(inner_value, true, &value_json); |
| 602 VLOG(2) << network->name() << ": Successfully parsed [" << key | 559 VLOG(2) << network->name() << ": Successfully parsed [" << key |
| 603 << "(" << index << ")] = " << value_json; | 560 << "(" << index << ")] = " << value_json; |
| 604 } | 561 } |
| 605 } | 562 } |
| 606 if (any_errors) | |
| 607 parse_error_ = l10n_util::GetStringUTF8( | |
| 608 IDS_NETWORK_CONFIG_ERROR_NETWORK_PROP_DICT_MALFORMED); | |
| 609 return !any_errors; | 563 return !any_errors; |
| 610 } | 564 } |
| 611 | 565 |
| 612 // static | 566 // static |
| 613 bool OncNetworkParser::CheckNetworkType(Network* network, | 567 bool OncNetworkParser::CheckNetworkType(Network* network, |
| 614 ConnectionType expected, | 568 ConnectionType expected, |
| 615 const std::string& onc_type) { | 569 const std::string& onc_type) { |
| 616 if (expected != network->type()) { | 570 if (expected != network->type()) { |
| 617 LOG(WARNING) << network->name() << ": " | 571 LOG(WARNING) << network->name() << ": " |
| 618 << onc_type << " field unexpected for this type network"; | 572 << onc_type << " field unexpected for this type network"; |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 // on the value of AuthenticationType. | 1180 // on the value of AuthenticationType. |
| 1227 { "L2TP-IPsec", PROVIDER_TYPE_L2TP_IPSEC_PSK }, | 1181 { "L2TP-IPsec", PROVIDER_TYPE_L2TP_IPSEC_PSK }, |
| 1228 { "OpenVPN", PROVIDER_TYPE_OPEN_VPN }, | 1182 { "OpenVPN", PROVIDER_TYPE_OPEN_VPN }, |
| 1229 }; | 1183 }; |
| 1230 CR_DEFINE_STATIC_LOCAL(EnumMapper<ProviderType>, parser, | 1184 CR_DEFINE_STATIC_LOCAL(EnumMapper<ProviderType>, parser, |
| 1231 (table, arraysize(table), PROVIDER_TYPE_MAX)); | 1185 (table, arraysize(table), PROVIDER_TYPE_MAX)); |
| 1232 return parser.Get(type); | 1186 return parser.Get(type); |
| 1233 } | 1187 } |
| 1234 | 1188 |
| 1235 } // namespace chromeos | 1189 } // namespace chromeos |
| OLD | NEW |