Chromium Code Reviews| Index: chrome/browser/chromeos/cros/onc_network_parser.cc |
| =================================================================== |
| --- chrome/browser/chromeos/cros/onc_network_parser.cc (revision 113491) |
| +++ chrome/browser/chromeos/cros/onc_network_parser.cc (working copy) |
| @@ -12,11 +12,13 @@ |
| #include "chrome/browser/chromeos/cros/native_network_constants.h" |
| #include "chrome/browser/chromeos/cros/native_network_parser.h" |
| #include "chrome/browser/chromeos/cros/network_library.h" |
| +#include "grit/generated_resources.h" |
| #include "net/base/cert_database.h" |
| #include "net/base/crypto_module.h" |
| #include "net/base/net_errors.h" |
| #include "net/base/x509_certificate.h" |
| #include "third_party/cros_system_api/dbus/service_constants.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| namespace chromeos { |
| @@ -231,10 +233,13 @@ |
| bool OncNetworkParser::ParseCertificate(int cert_index) { |
| CHECK(certificates_); |
| CHECK(static_cast<size_t>(cert_index) < certificates_->GetSize()); |
| - CHECK(cert_index >= 0); |
| + CHECK_GE(cert_index, 0); |
| base::DictionaryValue* certificate = NULL; |
| - certificates_->GetDictionary(cert_index, &certificate); |
| - CHECK(certificate); |
| + if (!certificates_->GetDictionary(cert_index, &certificate)) { |
| + parse_error_ = l10n_util::GetStringUTF8( |
|
kmixter1
2011/12/10 15:13:09
Currently almost all of the unit tests correctly p
|
| + IDS_NETWORK_CONFIG_ERROR_CERT_DATA_MALFORMED); |
| + return NULL; |
| + } |
| if (VLOG_IS_ON(2)) { |
| std::string certificate_json; |
| @@ -250,6 +255,8 @@ |
| if (!certificate->GetString("GUID", &guid) || guid.empty()) { |
| LOG(WARNING) << "ONC File: certificate missing identifier at index" |
| << cert_index; |
| + parse_error_ = l10n_util::GetStringUTF8( |
| + IDS_NETWORK_CONFIG_ERROR_CERT_GUID_MISSING); |
| return false; |
| } |
| @@ -257,8 +264,14 @@ |
| remove = false; |
| net::CertDatabase cert_database; |
| - if (remove) |
| - return cert_database.DeleteCertAndKeyByLabel(guid); |
| + if (remove) { |
| + if (!cert_database.DeleteCertAndKeyByLabel(guid)) { |
| + parse_error_ = l10n_util::GetStringUTF8( |
| + IDS_NETWORK_CONFIG_ERROR_CERT_DELETE); |
| + return false; |
| + } |
| + return true; |
| + } |
| // Not removing, so let's get the data we need to add this cert. |
| std::string cert_type; |
| @@ -272,15 +285,22 @@ |
| LOG(WARNING) << "ONC File: certificate of unknown type: " << cert_type |
| << " at index " << cert_index; |
| + parse_error_ = l10n_util::GetStringUTF8( |
| + IDS_NETWORK_CONFIG_ERROR_CERT_TYPE_MISSING); |
| return false; |
| } |
| Network* OncNetworkParser::ParseNetwork(int n) { |
| - if (!network_configs_) |
| - return NULL; |
| + CHECK(network_configs_); |
| + CHECK(static_cast<size_t>(n) < network_configs_->GetSize()); |
| + CHECK_GE(n, 0); |
| DictionaryValue* info = NULL; |
| - if (!network_configs_->GetDictionary(n, &info)) |
| + if (!network_configs_->GetDictionary(n, &info)) { |
| + parse_error_ = l10n_util::GetStringUTF8( |
| + IDS_NETWORK_CONFIG_ERROR_NETWORK_PROP_DICT_MALFORMED); |
|
kmixter1
2011/12/10 15:13:09
Please use JSON and ONC terminology in error messa
Charlie Lee
2011/12/14 17:02:20
I can't fix this for R17. Will remember to fix it
|
| return NULL; |
| + } |
| + |
| if (VLOG_IS_ON(2)) { |
| std::string network_json; |
| base::JSONWriter::Write(static_cast<base::Value*>(info), |
| @@ -296,8 +316,11 @@ |
| const std::string& service_path, |
| const DictionaryValue& info) { |
| ConnectionType type = ParseTypeFromDictionary(info); |
| - if (type == TYPE_UNKNOWN) // Return NULL if cannot parse network type. |
| + if (type == TYPE_UNKNOWN) { // Return NULL if cannot parse network type. |
| + parse_error_ = l10n_util::GetStringUTF8( |
| + IDS_NETWORK_CONFIG_ERROR_NETWORK_TYPE_MISSING); |
| return NULL; |
| + } |
| scoped_ptr<Network> network(CreateNewNetwork(type, service_path)); |
| if (!ParseNestedObject(network.get(), |
| "NetworkConfiguration", |
| @@ -305,6 +328,9 @@ |
| network_configuration_signature, |
| ParseNetworkConfigurationValue)) { |
| LOG(WARNING) << "Network " << network->name() << " failed to parse."; |
| + if (parse_error_.empty()) |
| + parse_error_ = l10n_util::GetStringUTF8( |
| + IDS_NETWORK_CONFIG_ERROR_NETWORK_PROP_DICT_MALFORMED); |
| return NULL; |
| } |
| if (VLOG_IS_ON(2)) { |
| @@ -363,6 +389,8 @@ |
| if (!trust_list->GetString(i, &trust_type)) { |
| LOG(WARNING) << "ONC File: certificate trust is invalid at index " |
| << cert_index; |
| + parse_error_ = l10n_util::GetStringUTF8( |
| + IDS_NETWORK_CONFIG_ERROR_CERT_TRUST_INVALID); |
| return false; |
| } |
| if (trust_type == "Web") { |
| @@ -371,6 +399,8 @@ |
| LOG(WARNING) << "ONC File: certificate contains unknown " |
| << "trust type: " << trust_type |
| << " at index " << cert_index; |
| + parse_error_ = l10n_util::GetStringUTF8( |
| + IDS_NETWORK_CONFIG_ERROR_CERT_TRUST_UNKNOWN); |
| return false; |
| } |
| } |
| @@ -381,6 +411,8 @@ |
| LOG(WARNING) << "ONC File: certificate missing appropriate " |
| << "certificate data for type: " << cert_type |
| << " at index " << cert_index; |
| + parse_error_ = l10n_util::GetStringUTF8( |
| + IDS_NETWORK_CONFIG_ERROR_CERT_DATA_MISSING); |
| return false; |
| } |
| @@ -388,6 +420,8 @@ |
| if (!base::Base64Decode(x509_data, &decoded_x509)) { |
| LOG(WARNING) << "Unable to base64 decode X509 data: \"" |
| << x509_data << "\"."; |
| + parse_error_ = l10n_util::GetStringUTF8( |
| + IDS_NETWORK_CONFIG_ERROR_CERT_DATA_MALFORMED); |
| return false; |
| } |
| @@ -396,6 +430,8 @@ |
| decoded_x509.size())); |
| if (!x509_cert.get()) { |
| LOG(WARNING) << "Unable to create X509 certificate from bytes."; |
| + parse_error_ = l10n_util::GetStringUTF8( |
| + IDS_NETWORK_CONFIG_ERROR_CERT_DATA_MALFORMED); |
| return false; |
| } |
| net::CertificateList cert_list; |
| @@ -404,7 +440,7 @@ |
| bool success = false; |
| if (cert_type == "Server") { |
| success = cert_database.ImportServerCert(cert_list, &failures); |
| - } else { // Authority cert |
| + } else { // Authority cert |
| net::CertDatabase::TrustBits trust = web_trust ? |
| net::CertDatabase::TRUSTED_SSL : |
| net::CertDatabase::UNTRUSTED; |
| @@ -415,11 +451,15 @@ |
| << net::ErrorToString(failures[0].net_error) |
| << ") importing " << cert_type << " certificate at index " |
| << cert_index; |
| + parse_error_ = l10n_util::GetStringUTF8( |
| + IDS_NETWORK_CONFIG_ERROR_CERT_IMPORT); |
| return false; |
| } |
| if (!success) { |
| LOG(WARNING) << "ONC File: Unknown error importing " << cert_type |
| << " certificate at index " << cert_index; |
| + parse_error_ = l10n_util::GetStringUTF8( |
| + IDS_NETWORK_CONFIG_ERROR_UNKNOWN); |
| return false; |
| } |
| VLOG(2) << "Successfully imported server/ca certificate at index " |
| @@ -436,6 +476,8 @@ |
| pkcs12_data.empty()) { |
| LOG(WARNING) << "ONC File: PKCS12 data is missing for Client " |
| << "certificate at index " << cert_index; |
| + parse_error_ = l10n_util::GetStringUTF8( |
| + IDS_NETWORK_CONFIG_ERROR_CERT_DATA_MISSING); |
| return false; |
| } |
| @@ -443,6 +485,8 @@ |
| if (!base::Base64Decode(pkcs12_data, &decoded_pkcs12)) { |
| LOG(WARNING) << "Unable to base64 decode PKCS#12 data: \"" |
| << pkcs12_data << "\"."; |
| + parse_error_ = l10n_util::GetStringUTF8( |
| + IDS_NETWORK_CONFIG_ERROR_CERT_DATA_MALFORMED); |
| return false; |
| } |
| @@ -454,6 +498,8 @@ |
| LOG(WARNING) << "ONC File: Unable to import Client certificate at index " |
| << cert_index |
| << " (error " << net::ErrorToString(result) << ")."; |
| + parse_error_ = l10n_util::GetStringUTF8( |
| + IDS_NETWORK_CONFIG_ERROR_CERT_IMPORT); |
| return false; |
| } |
| VLOG(2) << "Successfully imported client certificate at index " |
| @@ -469,6 +515,8 @@ |
| bool any_errors = false; |
| if (!value.IsType(base::Value::TYPE_DICTIONARY)) { |
| VLOG(1) << network->name() << ": expected object of type " << onc_type; |
| + parse_error_ = l10n_util::GetStringUTF8( |
| + IDS_NETWORK_CONFIG_ERROR_NETWORK_PROP_DICT_MALFORMED); |
| return false; |
| } |
| VLOG(2) << "Parsing nested object of type " << onc_type; |
| @@ -514,6 +562,9 @@ |
| << "(" << index << ")] = " << value_json; |
| } |
| } |
| + if (any_errors) |
| + parse_error_ = l10n_util::GetStringUTF8( |
| + IDS_NETWORK_CONFIG_ERROR_NETWORK_PROP_DICT_MALFORMED); |
| return !any_errors; |
| } |