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

Side by Side Diff: chrome/browser/policy/configuration_policy_handler_chromeos.cc

Issue 10823234: Fix ONC password filtering in about:policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix one base::Value that I had missed. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/policy/configuration_policy_handler_chromeos.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/policy/configuration_policy_handler_chromeos.h" 5 #include "chrome/browser/policy/configuration_policy_handler_chromeos.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/values.h"
14 #include "chrome/browser/chromeos/cros/onc_constants.h"
13 #include "chrome/browser/chromeos/cros/onc_network_parser.h" 15 #include "chrome/browser/chromeos/cros/onc_network_parser.h"
14 #include "chrome/browser/policy/policy_error_map.h" 16 #include "chrome/browser/policy/policy_error_map.h"
15 #include "chrome/browser/policy/policy_map.h" 17 #include "chrome/browser/policy/policy_map.h"
16 #include "chrome/browser/prefs/pref_value_map.h" 18 #include "chrome/browser/prefs/pref_value_map.h"
17 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" 19 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
18 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
19 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
20 #include "policy/policy_constants.h" 22 #include "policy/policy_constants.h"
21 23
24 namespace onc = chromeos::onc;
25
22 namespace policy { 26 namespace policy {
23 27
24 NetworkConfigurationPolicyHandler::NetworkConfigurationPolicyHandler( 28 NetworkConfigurationPolicyHandler::NetworkConfigurationPolicyHandler(
25 const char* policy_name, 29 const char* policy_name,
26 chromeos::NetworkUIData::ONCSource onc_source) 30 chromeos::NetworkUIData::ONCSource onc_source)
27 : TypeCheckingPolicyHandler(policy_name, Value::TYPE_STRING), 31 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_STRING),
28 onc_source_(onc_source) {} 32 onc_source_(onc_source) {}
29 33
30 NetworkConfigurationPolicyHandler::~NetworkConfigurationPolicyHandler() {} 34 NetworkConfigurationPolicyHandler::~NetworkConfigurationPolicyHandler() {}
31 35
32 bool NetworkConfigurationPolicyHandler::CheckPolicySettings( 36 bool NetworkConfigurationPolicyHandler::CheckPolicySettings(
33 const PolicyMap& policies, 37 const PolicyMap& policies,
34 PolicyErrorMap* errors) { 38 PolicyErrorMap* errors) {
35 const Value* value; 39 const base::Value* value;
36 if (!CheckAndGetValue(policies, errors, &value)) 40 if (!CheckAndGetValue(policies, errors, &value))
37 return false; 41 return false;
38 42
39 if (value) { 43 if (value) {
40 std::string onc_blob; 44 std::string onc_blob;
41 value->GetAsString(&onc_blob); 45 value->GetAsString(&onc_blob);
42 // Policy-based ONC blobs cannot have a passphrase. 46 // Policy-based ONC blobs cannot have a passphrase.
43 chromeos::OncNetworkParser parser(onc_blob, "", onc_source_); 47 chromeos::OncNetworkParser parser(onc_blob, "", onc_source_);
44 if (!parser.parse_error().empty()) { 48 if (!parser.parse_error().empty()) {
45 errors->AddError(policy_name(), 49 errors->AddError(policy_name(),
(...skipping 11 matching lines...) Expand all
57 PrefValueMap* prefs) { 61 PrefValueMap* prefs) {
58 // Network policy is read directly from the provider and injected into 62 // Network policy is read directly from the provider and injected into
59 // NetworkLibrary, so no need to convert the policy settings into prefs. 63 // NetworkLibrary, so no need to convert the policy settings into prefs.
60 } 64 }
61 65
62 void NetworkConfigurationPolicyHandler::PrepareForDisplaying( 66 void NetworkConfigurationPolicyHandler::PrepareForDisplaying(
63 PolicyMap* policies) const { 67 PolicyMap* policies) const {
64 const PolicyMap::Entry* entry = policies->Get(policy_name()); 68 const PolicyMap::Entry* entry = policies->Get(policy_name());
65 if (!entry) 69 if (!entry)
66 return; 70 return;
67 Value* sanitized_config = SanitizeNetworkConfig(entry->value); 71 base::Value* sanitized_config = SanitizeNetworkConfig(entry->value);
68 if (!sanitized_config) 72 if (!sanitized_config)
69 sanitized_config = Value::CreateNullValue(); 73 sanitized_config = base::Value::CreateNullValue();
70 74
71 policies->Set(policy_name(), entry->level, entry->scope, sanitized_config); 75 policies->Set(policy_name(), entry->level, entry->scope, sanitized_config);
72 } 76 }
73 77
74 // static 78 // static
75 Value* NetworkConfigurationPolicyHandler::SanitizeNetworkConfig( 79 base::Value* NetworkConfigurationPolicyHandler::SanitizeNetworkConfig(
76 const Value* config) { 80 const base::Value* config) {
77 std::string json_string; 81 std::string json_string;
78 if (!config->GetAsString(&json_string)) 82 if (!config->GetAsString(&json_string))
79 return NULL; 83 return NULL;
80 84
81 scoped_ptr<Value> json_value( 85 scoped_ptr<base::Value> json_value(
82 base::JSONReader::Read(json_string, base::JSON_ALLOW_TRAILING_COMMAS)); 86 base::JSONReader::Read(json_string, base::JSON_ALLOW_TRAILING_COMMAS));
83 if (!json_value.get() || !json_value->IsType(base::Value::TYPE_DICTIONARY)) 87 if (!json_value.get() || !json_value->IsType(base::Value::TYPE_DICTIONARY))
84 return NULL; 88 return NULL;
85 89
86 DictionaryValue* config_dict = 90 base::DictionaryValue* config_dict =
87 static_cast<DictionaryValue*>(json_value.get()); 91 static_cast<base::DictionaryValue*>(json_value.get());
88 92
89 // Strip any sensitive information from the JSON dictionary. 93 // Strip any sensitive information from the JSON dictionary.
90 base::ListValue* config_list = NULL; 94 base::ListValue* config_list = NULL;
91 if (config_dict->GetList("NetworkConfigurations", &config_list)) { 95 if (config_dict->GetList("NetworkConfigurations", &config_list)) {
92 for (base::ListValue::const_iterator network_entry = config_list->begin(); 96 for (base::ListValue::const_iterator network_entry = config_list->begin();
93 network_entry != config_list->end(); 97 network_entry != config_list->end();
94 ++network_entry) { 98 ++network_entry) {
95 if ((*network_entry) && 99 if ((*network_entry) &&
96 (*network_entry)->IsType(base::Value::TYPE_DICTIONARY)) { 100 (*network_entry)->IsType(base::Value::TYPE_DICTIONARY)) {
97 StripSensitiveValues(static_cast<DictionaryValue*>(*network_entry)); 101 MaskSensitiveValues(
102 static_cast<base::DictionaryValue*>(*network_entry));
98 } 103 }
99 } 104 }
100 } 105 }
101 106
102 // Convert back to a string, pretty printing the contents. 107 // Convert back to a string, pretty printing the contents.
103 base::JSONWriter::WriteWithOptions(config_dict, 108 base::JSONWriter::WriteWithOptions(config_dict,
104 base::JSONWriter::OPTIONS_DO_NOT_ESCAPE | 109 base::JSONWriter::OPTIONS_DO_NOT_ESCAPE |
105 base::JSONWriter::OPTIONS_PRETTY_PRINT, 110 base::JSONWriter::OPTIONS_PRETTY_PRINT,
106 &json_string); 111 &json_string);
107 return Value::CreateStringValue(json_string); 112 return base::Value::CreateStringValue(json_string);
108 } 113 }
109 114
110 // static 115 // static
111 void NetworkConfigurationPolicyHandler::StripSensitiveValues( 116 void NetworkConfigurationPolicyHandler::MaskSensitiveValues(
112 DictionaryValue* network_dict) { 117 base::DictionaryValue* network_dict) {
113 // List of settings we filter from the network dictionary. 118 // Paths of the properties to be replaced by the placeholder. Each entry
114 static const char* kFilteredSettings[] = { 119 // specifies dictionary key paths.
115 "WiFi.Passphrase", 120 static const int kMaxComponents = 3;
116 "IPsec.EAP.Password", 121 static const char* kFilteredSettings[][kMaxComponents] = {
117 "IPsec.EAP.Password", 122 { onc::kEthernet, onc::ethernet::kEAP, onc::eap::kPassword },
118 "IPsec.XAUTH.Password", 123 { onc::kVPN, onc::vpn::kIPsec, onc::vpn::kPSK },
119 "L2TP.Password", 124 { onc::kVPN, onc::vpn::kL2TP, onc::vpn::kPassword },
125 { onc::kVPN, onc::vpn::kOpenVPN, onc::vpn::kPassword },
126 { onc::kWiFi, onc::wifi::kEAP, onc::eap::kPassword },
127 { onc::kWiFi, onc::wifi::kPassphrase },
120 }; 128 };
129
121 // Placeholder to insert in place of the filtered setting. 130 // Placeholder to insert in place of the filtered setting.
122 static const char kPlaceholder[] = "********"; 131 static const char kPlaceholder[] = "********";
123 132
124 for (size_t i = 0; i < arraysize(kFilteredSettings); ++i) { 133 for (size_t i = 0; i < arraysize(kFilteredSettings); ++i) {
125 if (network_dict->Remove(kFilteredSettings[i], NULL)) { 134 const char** path = kFilteredSettings[i];
126 network_dict->Set(kFilteredSettings[i], 135 base::DictionaryValue* dict = network_dict;
127 Value::CreateStringValue(kPlaceholder)); 136 int j = 0;
137 for (j = 0; path[j + 1] != NULL && j + 1 < kMaxComponents; ++j) {
138 if (!dict->GetDictionaryWithoutPathExpansion(path[j], &dict)) {
139 dict = NULL;
140 break;
141 }
142 }
143 if (dict && dict->RemoveWithoutPathExpansion(path[j], NULL)) {
144 dict->SetWithoutPathExpansion(
145 path[j], base::Value::CreateStringValue(kPlaceholder));
128 } 146 }
129 } 147 }
130 } 148 }
131 149
132 PinnedLauncherAppsPolicyHandler::PinnedLauncherAppsPolicyHandler() 150 PinnedLauncherAppsPolicyHandler::PinnedLauncherAppsPolicyHandler()
133 : ExtensionListPolicyHandler(key::kPinnedLauncherApps, 151 : ExtensionListPolicyHandler(key::kPinnedLauncherApps,
134 prefs::kPinnedLauncherApps, 152 prefs::kPinnedLauncherApps,
135 false) {} 153 false) {}
136 154
137 PinnedLauncherAppsPolicyHandler::~PinnedLauncherAppsPolicyHandler() {} 155 PinnedLauncherAppsPolicyHandler::~PinnedLauncherAppsPolicyHandler() {}
(...skipping 13 matching lines...) Expand all
151 base::DictionaryValue* app_dict = new base::DictionaryValue(); 169 base::DictionaryValue* app_dict = new base::DictionaryValue();
152 app_dict->SetString(ash::kPinnedAppsPrefAppIDPath, id); 170 app_dict->SetString(ash::kPinnedAppsPrefAppIDPath, id);
153 pinned_apps_list->Append(app_dict); 171 pinned_apps_list->Append(app_dict);
154 } 172 }
155 } 173 }
156 prefs->SetValue(pref_path(), pinned_apps_list); 174 prefs->SetValue(pref_path(), pinned_apps_list);
157 } 175 }
158 } 176 }
159 177
160 } // namespace policy 178 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/configuration_policy_handler_chromeos.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698