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