Commit 5fabb2c2 authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

Convert onc::ReadDictionaryFromJson to use base::Value

This includes some partial conversion to base::Value in onc_utils.cc,
as part of a long term effort to convert network config and ONC code
to non deprecated base::Value patterns.

Bug: 651157
Change-Id: Ic0456f9221fedaf95a78ce670af9f4be4bc95ad1
Reviewed-on: https://chromium-review.googlesource.com/1144196
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarToni Barzic <tbarzic@chromium.org>
Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577997}
parent 60f80879
...@@ -200,9 +200,9 @@ bool NetworkConfigurationPolicyHandler::CheckPolicySettings( ...@@ -200,9 +200,9 @@ bool NetworkConfigurationPolicyHandler::CheckPolicySettings(
if (value) { if (value) {
std::string onc_blob; std::string onc_blob;
value->GetAsString(&onc_blob); value->GetAsString(&onc_blob);
std::unique_ptr<base::DictionaryValue> root_dict = std::unique_ptr<base::Value> root_dict =
chromeos::onc::ReadDictionaryFromJson(onc_blob); chromeos::onc::ReadDictionaryFromJson(onc_blob);
if (root_dict.get() == NULL) { if (!root_dict) {
errors->AddError(policy_name(), IDS_POLICY_NETWORK_CONFIG_PARSE_FAILED); errors->AddError(policy_name(), IDS_POLICY_NETWORK_CONFIG_PARSE_FAILED);
return false; return false;
} }
...@@ -289,9 +289,10 @@ NetworkConfigurationPolicyHandler::SanitizeNetworkConfig( ...@@ -289,9 +289,10 @@ NetworkConfigurationPolicyHandler::SanitizeNetworkConfig(
return NULL; return NULL;
std::unique_ptr<base::DictionaryValue> toplevel_dict = std::unique_ptr<base::DictionaryValue> toplevel_dict =
chromeos::onc::ReadDictionaryFromJson(json_string); base::DictionaryValue::From(
chromeos::onc::ReadDictionaryFromJson(json_string));
if (!toplevel_dict) if (!toplevel_dict)
return NULL; return nullptr;
// Placeholder to insert in place of the filtered setting. // Placeholder to insert in place of the filtered setting.
const char kPlaceholder[] = "********"; const char kPlaceholder[] = "********";
......
...@@ -248,17 +248,18 @@ class NetworkConfigurationUpdaterTest : public testing::Test { ...@@ -248,17 +248,18 @@ class NetworkConfigurationUpdaterTest : public testing::Test {
providers.push_back(&provider_); providers.push_back(&provider_);
policy_service_ = std::make_unique<PolicyServiceImpl>(std::move(providers)); policy_service_ = std::make_unique<PolicyServiceImpl>(std::move(providers));
std::unique_ptr<base::DictionaryValue> fake_toplevel_onc = std::unique_ptr<base::Value> fake_toplevel_onc =
chromeos::onc::ReadDictionaryFromJson(kFakeONC); chromeos::onc::ReadDictionaryFromJson(kFakeONC);
base::DictionaryValue* global_config = NULL; base::DictionaryValue* global_config = nullptr;
fake_toplevel_onc->GetDictionaryWithoutPathExpansion( fake_toplevel_onc
onc::toplevel_config::kGlobalNetworkConfiguration, &global_config); ->FindKey(onc::toplevel_config::kGlobalNetworkConfiguration)
->GetAsDictionary(&global_config);
fake_global_network_config_.MergeDictionary(global_config); fake_global_network_config_.MergeDictionary(global_config);
base::ListValue* certs = NULL; base::ListValue* certs = nullptr;
fake_toplevel_onc->GetListWithoutPathExpansion( fake_toplevel_onc->FindKey(onc::toplevel_config::kCertificates)
onc::toplevel_config::kCertificates, &certs); ->GetAsList(&certs);
fake_certificates_ = fake_certificates_ =
std::make_unique<chromeos::onc::OncParsedCertificates>(*certs); std::make_unique<chromeos::onc::OncParsedCertificates>(*certs);
...@@ -267,7 +268,7 @@ class NetworkConfigurationUpdaterTest : public testing::Test { ...@@ -267,7 +268,7 @@ class NetworkConfigurationUpdaterTest : public testing::Test {
} }
base::Value* GetExpectedFakeNetworkConfigs(::onc::ONCSource source) { base::Value* GetExpectedFakeNetworkConfigs(::onc::ONCSource source) {
std::unique_ptr<base::DictionaryValue> fake_toplevel_onc = std::unique_ptr<base::Value> fake_toplevel_onc =
chromeos::onc::ReadDictionaryFromJson(kFakeONC); chromeos::onc::ReadDictionaryFromJson(kFakeONC);
fake_network_configs_ = fake_network_configs_ =
fake_toplevel_onc->FindKey(onc::toplevel_config::kNetworkConfigurations) fake_toplevel_onc->FindKey(onc::toplevel_config::kNetworkConfigurations)
......
...@@ -514,8 +514,8 @@ TEST_F(ProxyConfigServiceImplTest, SharedEthernetAndUserPolicy) { ...@@ -514,8 +514,8 @@ TEST_F(ProxyConfigServiceImplTest, SharedEthernetAndUserPolicy) {
SetUpSharedEthernet(); SetUpSharedEthernet();
SetUpProxyConfigService(&profile_prefs_); SetUpProxyConfigService(&profile_prefs_);
std::unique_ptr<base::DictionaryValue> ethernet_policy( std::unique_ptr<base::Value> ethernet_policy =
chromeos::onc::ReadDictionaryFromJson(kEthernetPolicy)); chromeos::onc::ReadDictionaryFromJson(kEthernetPolicy);
std::unique_ptr<base::ListValue> network_configs(new base::ListValue); std::unique_ptr<base::ListValue> network_configs(new base::ListValue);
network_configs->Append(std::move(ethernet_policy)); network_configs->Append(std::move(ethernet_policy));
......
...@@ -146,7 +146,8 @@ class ManagedNetworkConfigurationHandlerTest : public testing::Test { ...@@ -146,7 +146,8 @@ class ManagedNetworkConfigurationHandlerTest : public testing::Test {
const std::string& path_to_onc) { const std::string& path_to_onc) {
std::unique_ptr<base::DictionaryValue> policy = std::unique_ptr<base::DictionaryValue> policy =
path_to_onc.empty() path_to_onc.empty()
? onc::ReadDictionaryFromJson(onc::kEmptyUnencryptedConfiguration) ? base::DictionaryValue::From(onc::ReadDictionaryFromJson(
onc::kEmptyUnencryptedConfiguration))
: test_utils::ReadTestDictionary(path_to_onc); : test_utils::ReadTestDictionary(path_to_onc);
base::ListValue validated_network_configs; base::ListValue validated_network_configs;
......
...@@ -162,14 +162,11 @@ bool NetworkState::PropertyChanged(const std::string& key, ...@@ -162,14 +162,11 @@ bool NetworkState::PropertyChanged(const std::string& key,
if (proxy_config_str.empty()) if (proxy_config_str.empty())
return true; return true;
std::unique_ptr<base::DictionaryValue> proxy_config_dict( std::unique_ptr<base::Value> proxy_config_dict(
onc::ReadDictionaryFromJson(proxy_config_str)); onc::ReadDictionaryFromJson(proxy_config_str));
if (proxy_config_dict) { if (proxy_config_dict) {
// Warning: The DictionaryValue returned from proxy_config_.MergeDictionary(
// ReadDictionaryFromJson/JSONParser is an optimized derived class that base::DictionaryValue::From(std::move(proxy_config_dict)).get());
// doesn't allow releasing ownership of nested values. A Swap in the wrong
// order leads to memory access errors.
proxy_config_.MergeDictionary(proxy_config_dict.get());
} else { } else {
NET_LOG(ERROR) << "Failed to parse " << path() << "." << key; NET_LOG(ERROR) << "Failed to parse " << path() << "." << key;
} }
......
...@@ -62,7 +62,8 @@ std::string NetworkStateTest::ConfigureService( ...@@ -62,7 +62,8 @@ std::string NetworkStateTest::ConfigureService(
last_created_service_path_ = ""; last_created_service_path_ = "";
std::unique_ptr<base::DictionaryValue> shill_json_dict = std::unique_ptr<base::DictionaryValue> shill_json_dict =
onc::ReadDictionaryFromJson(shill_json_string); base::DictionaryValue::From(
onc::ReadDictionaryFromJson(shill_json_string));
if (!shill_json_dict) { if (!shill_json_dict) {
LOG(ERROR) << "Error parsing json: " << shill_json_string; LOG(ERROR) << "Error parsing json: " << shill_json_string;
return last_created_service_path_; return last_created_service_path_;
......
...@@ -623,10 +623,10 @@ void ShillToONCTranslator::TranslateNetworkWithState() { ...@@ -623,10 +623,10 @@ void ShillToONCTranslator::TranslateNetworkWithState() {
if (shill_dictionary_->GetStringWithoutPathExpansion( if (shill_dictionary_->GetStringWithoutPathExpansion(
shill::kProxyConfigProperty, &proxy_config_str) && shill::kProxyConfigProperty, &proxy_config_str) &&
!proxy_config_str.empty()) { !proxy_config_str.empty()) {
std::unique_ptr<base::DictionaryValue> proxy_config_value( std::unique_ptr<base::Value> proxy_config_value(
ReadDictionaryFromJson(proxy_config_str)); ReadDictionaryFromJson(proxy_config_str));
if (proxy_config_value) { if (proxy_config_value) {
std::unique_ptr<base::DictionaryValue> proxy_settings = std::unique_ptr<base::Value> proxy_settings =
ConvertProxyConfigToOncProxySettings(std::move(proxy_config_value)); ConvertProxyConfigToOncProxySettings(std::move(proxy_config_value));
if (proxy_settings) { if (proxy_settings) {
onc_object_->SetWithoutPathExpansion( onc_object_->SetWithoutPathExpansion(
......
...@@ -167,13 +167,9 @@ CertPEMsByGUIDMap GetServerAndCACertsByGUID( ...@@ -167,13 +167,9 @@ CertPEMsByGUIDMap GetServerAndCACertsByGUID(
} }
// Fills HexSSID fields in all entries in the |network_configs| list. // Fills HexSSID fields in all entries in the |network_configs| list.
void FillInHexSSIDFieldsInNetworks(base::ListValue* network_configs) { void FillInHexSSIDFieldsInNetworks(base::Value* network_configs) {
for (auto& entry : *network_configs) { for (auto& network : network_configs->GetList())
base::DictionaryValue* network = nullptr; FillInHexSSIDFieldsInOncObject(kNetworkConfigurationSignature, &network);
entry.GetAsDictionary(&network);
DCHECK(network);
FillInHexSSIDFieldsInOncObject(kNetworkConfigurationSignature, network);
}
} }
// Given a GUID->PEM certificate mapping |certs_by_guid|, looks up the PEM // Given a GUID->PEM certificate mapping |certs_by_guid|, looks up the PEM
...@@ -626,30 +622,45 @@ const base::DictionaryValue* GetGlobalConfigFromPolicy(bool for_active_user) { ...@@ -626,30 +622,45 @@ const base::DictionaryValue* GetGlobalConfigFromPolicy(bool for_active_user) {
->GetGlobalConfigFromPolicy(username_hash); ->GetGlobalConfigFromPolicy(username_hash);
} }
bool GetStringFromDictionary(const base::Value& dict,
const char* key,
std::string* result) {
const base::Value* value = dict.FindKey(key);
if (!value || !value->is_string())
return false;
*result = value->GetString();
return true;
}
bool GetIntFromDictionary(const base::Value& dict,
const char* key,
int* result) {
const base::Value* value = dict.FindKey(key);
if (!value || !value->is_int())
return false;
*result = value->GetInt();
return true;
}
} // namespace } // namespace
const char kEmptyUnencryptedConfiguration[] = const char kEmptyUnencryptedConfiguration[] =
"{\"Type\":\"UnencryptedConfiguration\",\"NetworkConfigurations\":[]," "{\"Type\":\"UnencryptedConfiguration\",\"NetworkConfigurations\":[],"
"\"Certificates\":[]}"; "\"Certificates\":[]}";
std::unique_ptr<base::DictionaryValue> ReadDictionaryFromJson( std::unique_ptr<base::Value> ReadDictionaryFromJson(const std::string& json) {
const std::string& json) {
std::string error; std::string error;
std::unique_ptr<base::Value> root = base::JSONReader::ReadAndReturnError( std::unique_ptr<base::Value> root = base::JSONReader::ReadAndReturnError(
json, base::JSON_ALLOW_TRAILING_COMMAS, nullptr, &error); json, base::JSON_ALLOW_TRAILING_COMMAS, nullptr, &error);
if (!root || !root->is_dict()) {
base::DictionaryValue* dict_ptr = nullptr;
if (!root || !root->GetAsDictionary(&dict_ptr)) {
NET_LOG(ERROR) << "Invalid JSON Dictionary: " << error; NET_LOG(ERROR) << "Invalid JSON Dictionary: " << error;
return nullptr; return nullptr;
} }
ignore_result(root.release()); return root;
return base::WrapUnique(dict_ptr);
} }
std::unique_ptr<base::DictionaryValue> Decrypt( std::unique_ptr<base::Value> Decrypt(const std::string& passphrase,
const std::string& passphrase, const base::Value& root) {
const base::DictionaryValue& root) {
const int kKeySizeInBits = 256; const int kKeySizeInBits = 256;
const int kMaxIterationCount = 500000; const int kMaxIterationCount = 500000;
std::string onc_type; std::string onc_type;
...@@ -662,15 +673,15 @@ std::unique_ptr<base::DictionaryValue> Decrypt( ...@@ -662,15 +673,15 @@ std::unique_ptr<base::DictionaryValue> Decrypt(
int iterations; int iterations;
std::string ciphertext; std::string ciphertext;
if (!root.GetString(encrypted::kCiphertext, &ciphertext) || if (!GetStringFromDictionary(root, encrypted::kCiphertext, &ciphertext) ||
!root.GetString(encrypted::kCipher, &cipher) || !GetStringFromDictionary(root, encrypted::kCipher, &cipher) ||
!root.GetString(encrypted::kHMAC, &hmac) || !GetStringFromDictionary(root, encrypted::kHMAC, &hmac) ||
!root.GetString(encrypted::kHMACMethod, &hmac_method) || !GetStringFromDictionary(root, encrypted::kHMACMethod, &hmac_method) ||
!root.GetString(encrypted::kIV, &initial_vector) || !GetStringFromDictionary(root, encrypted::kIV, &initial_vector) ||
!root.GetInteger(encrypted::kIterations, &iterations) || !GetIntFromDictionary(root, encrypted::kIterations, &iterations) ||
!root.GetString(encrypted::kSalt, &salt) || !GetStringFromDictionary(root, encrypted::kSalt, &salt) ||
!root.GetString(encrypted::kStretch, &stretch_method) || !GetStringFromDictionary(root, encrypted::kStretch, &stretch_method) ||
!root.GetString(toplevel_config::kType, &onc_type) || !GetStringFromDictionary(root, toplevel_config::kType, &onc_type) ||
onc_type != toplevel_config::kEncryptedConfiguration) { onc_type != toplevel_config::kEncryptedConfiguration) {
NET_LOG(ERROR) << "Encrypted ONC malformed."; NET_LOG(ERROR) << "Encrypted ONC malformed.";
return nullptr; return nullptr;
...@@ -737,8 +748,7 @@ std::unique_ptr<base::DictionaryValue> Decrypt( ...@@ -737,8 +748,7 @@ std::unique_ptr<base::DictionaryValue> Decrypt(
return nullptr; return nullptr;
} }
std::unique_ptr<base::DictionaryValue> new_root = std::unique_ptr<base::Value> new_root = ReadDictionaryFromJson(plaintext);
ReadDictionaryFromJson(plaintext);
if (!new_root) { if (!new_root) {
NET_LOG(ERROR) << "Property dictionary malformed."; NET_LOG(ERROR) << "Property dictionary malformed.";
return nullptr; return nullptr;
...@@ -804,34 +814,34 @@ void ExpandStringsInNetworks(const VariableExpander& variable_expander, ...@@ -804,34 +814,34 @@ void ExpandStringsInNetworks(const VariableExpander& variable_expander,
} }
void FillInHexSSIDFieldsInOncObject(const OncValueSignature& signature, void FillInHexSSIDFieldsInOncObject(const OncValueSignature& signature,
base::DictionaryValue* onc_object) { base::Value* onc_object) {
DCHECK(onc_object->is_dict());
if (&signature == &kWiFiSignature) if (&signature == &kWiFiSignature)
FillInHexSSIDField(onc_object); FillInHexSSIDField(onc_object);
// Recurse into nested objects. // Recurse into nested objects.
for (base::DictionaryValue::Iterator it(*onc_object); !it.IsAtEnd(); for (auto it : onc_object->DictItems()) {
it.Advance()) { if (!it.second.is_dict())
base::DictionaryValue* inner_object = nullptr;
if (!onc_object->GetDictionaryWithoutPathExpansion(it.key(), &inner_object))
continue; continue;
const OncFieldSignature* field_signature = const OncFieldSignature* field_signature =
GetFieldSignature(signature, it.key()); GetFieldSignature(signature, it.first);
if (!field_signature) if (!field_signature)
continue; continue;
FillInHexSSIDFieldsInOncObject(*field_signature->value_signature, FillInHexSSIDFieldsInOncObject(*field_signature->value_signature,
inner_object); &it.second);
} }
} }
void FillInHexSSIDField(base::DictionaryValue* wifi_fields) { void FillInHexSSIDField(base::Value* wifi_fields) {
std::string ssid_string; if (wifi_fields->FindKey(::onc::wifi::kHexSSID))
if (wifi_fields->HasKey(::onc::wifi::kHexSSID) ||
!wifi_fields->GetStringWithoutPathExpansion(::onc::wifi::kSSID,
&ssid_string)) {
return; return;
} base::Value* ssid =
wifi_fields->FindKeyOfType(::onc::wifi::kSSID, base::Value::Type::STRING);
if (!ssid)
return;
std::string ssid_string = ssid->GetString();
if (ssid_string.empty()) { if (ssid_string.empty()) {
NET_LOG(ERROR) << "Found empty SSID field."; NET_LOG(ERROR) << "Found empty SSID field.";
return; return;
...@@ -890,8 +900,7 @@ bool ParseAndValidateOncForImport(const std::string& onc_blob, ...@@ -890,8 +900,7 @@ bool ParseAndValidateOncForImport(const std::string& onc_blob,
if (onc_blob.empty()) if (onc_blob.empty())
return true; return true;
std::unique_ptr<base::DictionaryValue> toplevel_onc = std::unique_ptr<base::Value> toplevel_onc = ReadDictionaryFromJson(onc_blob);
ReadDictionaryFromJson(onc_blob);
if (!toplevel_onc) { if (!toplevel_onc) {
LOG(ERROR) << "ONC loaded from " << GetSourceAsString(onc_source) LOG(ERROR) << "ONC loaded from " << GetSourceAsString(onc_source)
<< " is not a valid JSON dictionary."; << " is not a valid JSON dictionary.";
...@@ -900,9 +909,9 @@ bool ParseAndValidateOncForImport(const std::string& onc_blob, ...@@ -900,9 +909,9 @@ bool ParseAndValidateOncForImport(const std::string& onc_blob,
// Check and see if this is an encrypted ONC file. If so, decrypt it. // Check and see if this is an encrypted ONC file. If so, decrypt it.
std::string onc_type; std::string onc_type;
toplevel_onc->GetStringWithoutPathExpansion(toplevel_config::kType, if (GetStringFromDictionary(*toplevel_onc, toplevel_config::kType,
&onc_type); &onc_type) &&
if (onc_type == toplevel_config::kEncryptedConfiguration) { onc_type == toplevel_config::kEncryptedConfiguration) {
toplevel_onc = Decrypt(passphrase, *toplevel_onc); toplevel_onc = Decrypt(passphrase, *toplevel_onc);
if (!toplevel_onc) { if (!toplevel_onc) {
LOG(ERROR) << "Couldn't decrypt the ONC from " LOG(ERROR) << "Couldn't decrypt the ONC from "
...@@ -923,8 +932,10 @@ bool ParseAndValidateOncForImport(const std::string& onc_blob, ...@@ -923,8 +932,10 @@ bool ParseAndValidateOncForImport(const std::string& onc_blob,
validator.SetOncSource(onc_source); validator.SetOncSource(onc_source);
Validator::Result validation_result; Validator::Result validation_result;
std::unique_ptr<base::DictionaryValue> toplevel_onc_dict =
base::DictionaryValue::From(std::move(toplevel_onc));
toplevel_onc = validator.ValidateAndRepairObject( toplevel_onc = validator.ValidateAndRepairObject(
&kToplevelConfigurationSignature, *toplevel_onc, &validation_result); &kToplevelConfigurationSignature, *toplevel_onc_dict, &validation_result);
if (from_policy) { if (from_policy) {
UMA_HISTOGRAM_BOOLEAN("Enterprise.ONC.PolicyValidation", UMA_HISTOGRAM_BOOLEAN("Enterprise.ONC.PolicyValidation",
...@@ -942,40 +953,49 @@ bool ParseAndValidateOncForImport(const std::string& onc_blob, ...@@ -942,40 +953,49 @@ bool ParseAndValidateOncForImport(const std::string& onc_blob,
return false; return false;
} }
base::ListValue* validated_certs = nullptr; if (certificates) {
if (certificates && toplevel_onc->GetListWithoutPathExpansion( base::Value* validated_certs = toplevel_onc->FindKeyOfType(
toplevel_config::kCertificates, &validated_certs)) { toplevel_config::kCertificates, base::Value::Type::LIST);
certificates->Swap(validated_certs); if (validated_certs)
certificates->GetList().swap(validated_certs->GetList());
} }
base::ListValue* validated_networks = nullptr;
// Note that this processing is performed even if |network_configs| is // Note that this processing is performed even if |network_configs| is
// nullptr, because ResolveServerCertRefsInNetworks could affect the return // nullptr, because ResolveServerCertRefsInNetworks could affect the return
// value of the function (which is supposed to aggregate validation issues in // value of the function (which is supposed to aggregate validation issues in
// all segments of the ONC blob). // all segments of the ONC blob).
if (toplevel_onc->GetListWithoutPathExpansion( base::Value* validated_networks = toplevel_onc->FindKeyOfType(
toplevel_config::kNetworkConfigurations, &validated_networks)) { toplevel_config::kNetworkConfigurations, base::Value::Type::LIST);
FillInHexSSIDFieldsInNetworks(validated_networks); base::ListValue* validated_networks_list;
if (validated_networks &&
validated_networks->GetAsList(&validated_networks_list)) {
FillInHexSSIDFieldsInNetworks(validated_networks_list);
CertPEMsByGUIDMap server_and_ca_certs = CertPEMsByGUIDMap server_and_ca_certs =
GetServerAndCACertsByGUID(*certificates); GetServerAndCACertsByGUID(*certificates);
if (!ResolveServerCertRefsInNetworks(server_and_ca_certs, if (!ResolveServerCertRefsInNetworks(server_and_ca_certs,
validated_networks)) { validated_networks_list)) {
LOG(ERROR) << "Some certificate references in the ONC policy for source " LOG(ERROR) << "Some certificate references in the ONC policy for source "
<< GetSourceAsString(onc_source) << " could not be resolved."; << GetSourceAsString(onc_source) << " could not be resolved.";
success = false; success = false;
} }
if (network_configs) if (network_configs)
network_configs->Swap(validated_networks); network_configs->Swap(validated_networks_list);
} }
base::DictionaryValue* validated_global_config = nullptr; if (global_network_config) {
if (global_network_config && toplevel_onc->GetDictionaryWithoutPathExpansion( base::Value* validated_global_config = toplevel_onc->FindKeyOfType(
toplevel_config::kGlobalNetworkConfiguration, toplevel_config::kGlobalNetworkConfiguration,
&validated_global_config)) { base::Value::Type::DICTIONARY);
global_network_config->Swap(validated_global_config); if (validated_global_config) {
base::DictionaryValue* validated_global_config_dict = nullptr;
if (validated_global_config->GetAsDictionary(
&validated_global_config_dict)) {
global_network_config->Swap(validated_global_config_dict);
}
}
} }
return success; return success;
...@@ -1086,15 +1106,15 @@ std::unique_ptr<base::DictionaryValue> ConvertOncProxySettingsToProxyConfig( ...@@ -1086,15 +1106,15 @@ std::unique_ptr<base::DictionaryValue> ConvertOncProxySettingsToProxyConfig(
return proxy_dict; return proxy_dict;
} }
std::unique_ptr<base::DictionaryValue> ConvertProxyConfigToOncProxySettings( std::unique_ptr<base::Value> ConvertProxyConfigToOncProxySettings(
std::unique_ptr<base::DictionaryValue> proxy_config_value) { std::unique_ptr<base::Value> proxy_config_value) {
// Create a ProxyConfigDictionary from the DictionaryValue. // Create a ProxyConfigDictionary from the dictionary.
auto proxy_config = auto proxy_config = std::make_unique<ProxyConfigDictionary>(
std::make_unique<ProxyConfigDictionary>(std::move(proxy_config_value)); base::DictionaryValue::From(std::move(proxy_config_value)));
// Create the result DictionaryValue and populate it. // Create the result DictionaryValue and populate it.
std::unique_ptr<base::DictionaryValue> proxy_settings( auto proxy_settings =
new base::DictionaryValue); std::make_unique<base::Value>(base::Value::Type::DICTIONARY);
ProxyPrefs::ProxyMode mode; ProxyPrefs::ProxyMode mode;
if (!proxy_config->GetMode(&mode)) if (!proxy_config->GetMode(&mode))
return nullptr; return nullptr;
...@@ -1118,34 +1138,34 @@ std::unique_ptr<base::DictionaryValue> ConvertProxyConfigToOncProxySettings( ...@@ -1118,34 +1138,34 @@ std::unique_ptr<base::DictionaryValue> ConvertProxyConfigToOncProxySettings(
break; break;
} }
case ProxyPrefs::MODE_FIXED_SERVERS: { case ProxyPrefs::MODE_FIXED_SERVERS: {
proxy_settings->SetString(::onc::proxy::kType, ::onc::proxy::kManual); proxy_settings->SetKey(::onc::proxy::kType,
std::unique_ptr<base::DictionaryValue> manual(new base::DictionaryValue); base::Value(::onc::proxy::kManual));
base::DictionaryValue manual;
std::string proxy_rules_string; std::string proxy_rules_string;
if (proxy_config->GetProxyServer(&proxy_rules_string)) { if (proxy_config->GetProxyServer(&proxy_rules_string)) {
net::ProxyConfig::ProxyRules proxy_rules; net::ProxyConfig::ProxyRules proxy_rules;
proxy_rules.ParseFromString(proxy_rules_string); proxy_rules.ParseFromString(proxy_rules_string);
SetProxyForScheme(proxy_rules, url::kFtpScheme, ::onc::proxy::kFtp, SetProxyForScheme(proxy_rules, url::kFtpScheme, ::onc::proxy::kFtp,
manual.get()); &manual);
SetProxyForScheme(proxy_rules, url::kHttpScheme, ::onc::proxy::kHttp, SetProxyForScheme(proxy_rules, url::kHttpScheme, ::onc::proxy::kHttp,
manual.get()); &manual);
SetProxyForScheme(proxy_rules, url::kHttpsScheme, ::onc::proxy::kHttps, SetProxyForScheme(proxy_rules, url::kHttpsScheme, ::onc::proxy::kHttps,
manual.get()); &manual);
SetProxyForScheme(proxy_rules, kSocksScheme, ::onc::proxy::kSocks, SetProxyForScheme(proxy_rules, kSocksScheme, ::onc::proxy::kSocks,
manual.get()); &manual);
} }
proxy_settings->SetWithoutPathExpansion(::onc::proxy::kManual, proxy_settings->SetKey(::onc::proxy::kManual, std::move(manual));
std::move(manual));
// Convert the 'bypass_list' string into dictionary entries. // Convert the 'bypass_list' string into dictionary entries.
std::string bypass_rules_string; std::string bypass_rules_string;
if (proxy_config->GetBypassList(&bypass_rules_string)) { if (proxy_config->GetBypassList(&bypass_rules_string)) {
net::ProxyBypassRules bypass_rules; net::ProxyBypassRules bypass_rules;
bypass_rules.ParseFromString(bypass_rules_string); bypass_rules.ParseFromString(bypass_rules_string);
std::unique_ptr<base::ListValue> exclude_domains(new base::ListValue); base::ListValue exclude_domains;
for (const auto& rule : bypass_rules.rules()) for (const auto& rule : bypass_rules.rules())
exclude_domains->AppendString(rule->ToString()); exclude_domains.AppendString(rule->ToString());
if (!exclude_domains->empty()) { if (!exclude_domains.empty()) {
proxy_settings->SetWithoutPathExpansion(::onc::proxy::kExcludeDomains, proxy_settings->SetKey(::onc::proxy::kExcludeDomains,
std::move(exclude_domains)); std::move(exclude_domains));
} }
} }
......
...@@ -43,17 +43,17 @@ CHROMEOS_EXPORT extern const char kEmptyUnencryptedConfiguration[]; ...@@ -43,17 +43,17 @@ CHROMEOS_EXPORT extern const char kEmptyUnencryptedConfiguration[];
typedef std::map<std::string, std::string> CertPEMsByGUIDMap; typedef std::map<std::string, std::string> CertPEMsByGUIDMap;
// Parses |json| according to the JSON format. If |json| is a JSON formatted // Parses |json| according to the JSON format. If |json| is a JSON formatted
// dictionary, the function returns the dictionary as a DictionaryValue. // dictionary, the function returns the dictionary value, otherwise returns
// Otherwise returns NULL. // null.
CHROMEOS_EXPORT std::unique_ptr<base::DictionaryValue> ReadDictionaryFromJson( CHROMEOS_EXPORT std::unique_ptr<base::Value> ReadDictionaryFromJson(
const std::string& json); const std::string& json);
// Decrypts the given EncryptedConfiguration |onc| (see the ONC specification) // Decrypts the given EncryptedConfiguration |onc| (see the ONC specification)
// using |passphrase|. The resulting UnencryptedConfiguration is returned. If an // using |passphrase|. The resulting UnencryptedConfiguration is returned. If an
// error occurs, returns NULL. // error occurs, returns null.
CHROMEOS_EXPORT std::unique_ptr<base::DictionaryValue> Decrypt( CHROMEOS_EXPORT std::unique_ptr<base::Value> Decrypt(
const std::string& passphrase, const std::string& passphrase,
const base::DictionaryValue& onc); const base::Value& onc);
// For logging only: strings not user facing. // For logging only: strings not user facing.
CHROMEOS_EXPORT std::string GetSourceAsString(::onc::ONCSource source); CHROMEOS_EXPORT std::string GetSourceAsString(::onc::ONCSource source);
...@@ -77,12 +77,12 @@ CHROMEOS_EXPORT void ExpandStringsInNetworks( ...@@ -77,12 +77,12 @@ CHROMEOS_EXPORT void ExpandStringsInNetworks(
// specification. The object of |onc_object| is modified in place. // specification. The object of |onc_object| is modified in place.
CHROMEOS_EXPORT void FillInHexSSIDFieldsInOncObject( CHROMEOS_EXPORT void FillInHexSSIDFieldsInOncObject(
const OncValueSignature& signature, const OncValueSignature& signature,
base::DictionaryValue* onc_object); base::Value* onc_object);
// If the SSID field is set, but HexSSID is not, converts the contents of the // If the SSID field is set, but HexSSID is not, converts the contents of the
// SSID field to UTF-8 encoding, creates the hex representation and assigns the // SSID field to UTF-8 encoding, creates the hex representation and assigns the
// result to HexSSID. // result to HexSSID.
CHROMEOS_EXPORT void FillInHexSSIDField(base::DictionaryValue* wifi_fields); CHROMEOS_EXPORT void FillInHexSSIDField(base::Value* wifi_fields);
// Creates a copy of |onc_object| with all values of sensitive fields replaced // Creates a copy of |onc_object| with all values of sensitive fields replaced
// by |mask|. To find sensitive fields, signature and field name are checked // by |mask|. To find sensitive fields, signature and field name are checked
...@@ -146,9 +146,9 @@ ConvertOncProxySettingsToProxyConfig( ...@@ -146,9 +146,9 @@ ConvertOncProxySettingsToProxyConfig(
// Translates |proxy_config_value|, which must be a valid ProxyConfig dictionary // Translates |proxy_config_value|, which must be a valid ProxyConfig dictionary
// (see proxy_config_dictionary.h) to an ONC ProxySettings dictionary. // (see proxy_config_dictionary.h) to an ONC ProxySettings dictionary.
CHROMEOS_EXPORT std::unique_ptr<base::DictionaryValue> CHROMEOS_EXPORT std::unique_ptr<base::Value>
ConvertProxyConfigToOncProxySettings( ConvertProxyConfigToOncProxySettings(
std::unique_ptr<base::DictionaryValue> proxy_config_value); std::unique_ptr<base::Value> proxy_config_value);
// Replaces user-specific string placeholders in |network_configs|, which must // Replaces user-specific string placeholders in |network_configs|, which must
// be a list of ONC NetworkConfigurations. Currently only user name placeholders // be a list of ONC NetworkConfigurations. Currently only user name placeholders
......
...@@ -44,37 +44,37 @@ std::unique_ptr<base::Value> ReadTestJson(const std::string& filename) { ...@@ -44,37 +44,37 @@ std::unique_ptr<base::Value> ReadTestJson(const std::string& filename) {
namespace onc { namespace onc {
TEST(ONCDecrypterTest, BrokenEncryptionIterations) { TEST(ONCDecrypterTest, BrokenEncryptionIterations) {
std::unique_ptr<base::DictionaryValue> encrypted_onc = std::unique_ptr<base::Value> encrypted_onc =
test_utils::ReadTestDictionary("broken-encrypted-iterations.onc"); test_utils::ReadTestDictionary("broken-encrypted-iterations.onc");
std::unique_ptr<base::DictionaryValue> decrypted_onc = std::unique_ptr<base::Value> decrypted_onc =
Decrypt("test0000", *encrypted_onc); Decrypt("test0000", *encrypted_onc);
EXPECT_EQ(NULL, decrypted_onc.get()); EXPECT_EQ(nullptr, decrypted_onc.get());
} }
TEST(ONCDecrypterTest, BrokenEncryptionZeroIterations) { TEST(ONCDecrypterTest, BrokenEncryptionZeroIterations) {
std::unique_ptr<base::DictionaryValue> encrypted_onc = std::unique_ptr<base::Value> encrypted_onc =
test_utils::ReadTestDictionary("broken-encrypted-zero-iterations.onc"); test_utils::ReadTestDictionary("broken-encrypted-zero-iterations.onc");
std::string error; std::string error;
std::unique_ptr<base::DictionaryValue> decrypted_onc = std::unique_ptr<base::Value> decrypted_onc =
Decrypt("test0000", *encrypted_onc); Decrypt("test0000", *encrypted_onc);
EXPECT_EQ(NULL, decrypted_onc.get()); EXPECT_EQ(nullptr, decrypted_onc.get());
} }
TEST(ONCDecrypterTest, LoadEncryptedOnc) { TEST(ONCDecrypterTest, LoadEncryptedOnc) {
std::unique_ptr<base::DictionaryValue> encrypted_onc = std::unique_ptr<base::Value> encrypted_onc =
test_utils::ReadTestDictionary("encrypted.onc"); test_utils::ReadTestDictionary("encrypted.onc");
std::unique_ptr<base::DictionaryValue> expected_decrypted_onc = std::unique_ptr<base::Value> expected_decrypted_onc =
test_utils::ReadTestDictionary("decrypted.onc"); test_utils::ReadTestDictionary("decrypted.onc");
std::string error; std::string error;
std::unique_ptr<base::DictionaryValue> actual_decrypted_onc = std::unique_ptr<base::Value> actual_decrypted_onc =
Decrypt("test0000", *encrypted_onc); Decrypt("test0000", *encrypted_onc);
base::DictionaryValue emptyDict; base::Value emptyDict;
EXPECT_TRUE(test_utils::Equals(expected_decrypted_onc.get(), EXPECT_TRUE(test_utils::Equals(expected_decrypted_onc.get(),
actual_decrypted_onc.get())); actual_decrypted_onc.get()));
} }
...@@ -216,8 +216,8 @@ TEST(ONCUtils, ProxyConfigToOncProxySettings) { ...@@ -216,8 +216,8 @@ TEST(ONCUtils, ProxyConfigToOncProxySettings) {
test_case->GetDictionary("ONC_ProxySettings", &onc_proxy_settings); test_case->GetDictionary("ONC_ProxySettings", &onc_proxy_settings);
std::unique_ptr<base::DictionaryValue> actual_proxy_settings = std::unique_ptr<base::DictionaryValue> actual_proxy_settings =
ConvertProxyConfigToOncProxySettings( base::DictionaryValue::From(ConvertProxyConfigToOncProxySettings(
shill_proxy_config->CreateDeepCopy()); shill_proxy_config->CreateDeepCopy()));
EXPECT_TRUE( EXPECT_TRUE(
test_utils::Equals(onc_proxy_settings, actual_proxy_settings.get())); test_utils::Equals(onc_proxy_settings, actual_proxy_settings.get()));
} }
......
...@@ -28,7 +28,7 @@ class ONCValidatorTest : public ::testing::Test { ...@@ -28,7 +28,7 @@ class ONCValidatorTest : public ::testing::Test {
// validation is stored, so that expectations can be checked afterwards using // validation is stored, so that expectations can be checked afterwards using
// one of the Expect* functions below. // one of the Expect* functions below.
void Validate(bool strict, void Validate(bool strict,
std::unique_ptr<base::DictionaryValue> onc_object, std::unique_ptr<base::Value> onc_object,
const OncValueSignature* signature, const OncValueSignature* signature,
bool managed_onc, bool managed_onc,
::onc::ONCSource onc_source) { ::onc::ONCSource onc_source) {
...@@ -41,7 +41,7 @@ class ONCValidatorTest : public ::testing::Test { ...@@ -41,7 +41,7 @@ class ONCValidatorTest : public ::testing::Test {
validator.reset(new Validator(false, false, false, managed_onc)); validator.reset(new Validator(false, false, false, managed_onc));
} }
validator->SetOncSource(onc_source); validator->SetOncSource(onc_source);
original_object_ = std::move(onc_object); original_object_ = base::DictionaryValue::From(std::move(onc_object));
repaired_object_ = validator->ValidateAndRepairObject(signature, repaired_object_ = validator->ValidateAndRepairObject(signature,
*original_object_, *original_object_,
&validation_result_); &validation_result_);
......
...@@ -197,7 +197,7 @@ std::unique_ptr<NetworkUIData> GetUIDataFromValue( ...@@ -197,7 +197,7 @@ std::unique_ptr<NetworkUIData> GetUIDataFromValue(
return std::unique_ptr<NetworkUIData>(); return std::unique_ptr<NetworkUIData>();
if (ui_data_str.empty()) if (ui_data_str.empty())
return std::make_unique<NetworkUIData>(); return std::make_unique<NetworkUIData>();
std::unique_ptr<base::DictionaryValue> ui_data_dict( std::unique_ptr<base::Value> ui_data_dict(
chromeos::onc::ReadDictionaryFromJson(ui_data_str)); chromeos::onc::ReadDictionaryFromJson(ui_data_str));
if (!ui_data_dict) if (!ui_data_dict)
return std::unique_ptr<NetworkUIData>(); return std::unique_ptr<NetworkUIData>();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment