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

Side by Side Diff: chromeos/network/onc/onc_utils.cc

Issue 759663004: ONC: add support for non-utf-8 SSIDs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: adjusted onc_spec.html Created 6 years 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
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 "chromeos/network/onc/onc_utils.h" 5 #include "chromeos/network/onc/onc_utils.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "chromeos/network/network_event_log.h" 14 #include "chromeos/network/network_event_log.h"
14 #include "chromeos/network/onc/onc_mapper.h" 15 #include "chromeos/network/onc/onc_mapper.h"
15 #include "chromeos/network/onc/onc_signature.h" 16 #include "chromeos/network/onc/onc_signature.h"
16 #include "chromeos/network/onc/onc_utils.h" 17 #include "chromeos/network/onc/onc_utils.h"
17 #include "chromeos/network/onc/onc_validator.h" 18 #include "chromeos/network/onc/onc_validator.h"
18 #include "crypto/encryptor.h" 19 #include "crypto/encryptor.h"
19 #include "crypto/hmac.h" 20 #include "crypto/hmac.h"
20 #include "crypto/symmetric_key.h" 21 #include "crypto/symmetric_key.h"
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 for (base::ListValue::iterator it = network_configs->begin(); 234 for (base::ListValue::iterator it = network_configs->begin();
234 it != network_configs->end(); ++it) { 235 it != network_configs->end(); ++it) {
235 base::DictionaryValue* network = NULL; 236 base::DictionaryValue* network = NULL;
236 (*it)->GetAsDictionary(&network); 237 (*it)->GetAsDictionary(&network);
237 DCHECK(network); 238 DCHECK(network);
238 ExpandStringsInOncObject( 239 ExpandStringsInOncObject(
239 kNetworkConfigurationSignature, substitution, network); 240 kNetworkConfigurationSignature, substitution, network);
240 } 241 }
241 } 242 }
242 243
244 void FillInHexSSIDFieldsInOncObject(const OncValueSignature& signature,
245 base::DictionaryValue* onc_object) {
246 if (&signature == &kWiFiSignature)
247 FillInHexSSIDField(onc_object);
248
249 // Recurse into nested objects.
250 for (base::DictionaryValue::Iterator it(*onc_object); !it.IsAtEnd();
251 it.Advance()) {
252 base::DictionaryValue* inner_object = NULL;
pneubeck (no reviews) 2014/11/27 14:49:02 nit: NULL -> nullptr (please check in the whole CL
cschuet (SLOW) 2014/11/27 15:44:31 Done.
253 if (!onc_object->GetDictionaryWithoutPathExpansion(it.key(), &inner_object))
254 continue;
255
256 const OncFieldSignature* field_signature =
257 GetFieldSignature(signature, it.key());
258 if (!field_signature)
259 continue;
260
261 FillInHexSSIDFieldsInOncObject(*field_signature->value_signature,
262 inner_object);
263 }
264 }
265
266 void FillInHexSSIDField(base::DictionaryValue* wifi_fields) {
267 if (!wifi_fields->HasKey(::onc::wifi::kHexSSID)) {
268 std::string ssid_string;
269 wifi_fields->GetStringWithoutPathExpansion(::onc::wifi::kSSID,
270 &ssid_string);
271 wifi_fields->SetStringWithoutPathExpansion(
272 ::onc::wifi::kHexSSID,
273 base::HexEncode(ssid_string.c_str(), ssid_string.size()));
274 }
275 }
276
243 namespace { 277 namespace {
244 278
245 class OncMaskValues : public Mapper { 279 class OncMaskValues : public Mapper {
246 public: 280 public:
247 static scoped_ptr<base::DictionaryValue> Mask( 281 static scoped_ptr<base::DictionaryValue> Mask(
248 const OncValueSignature& signature, 282 const OncValueSignature& signature,
249 const base::DictionaryValue& onc_object, 283 const base::DictionaryValue& onc_object,
250 const std::string& mask) { 284 const std::string& mask) {
251 OncMaskValues masker(mask); 285 OncMaskValues masker(mask);
252 bool unused_error; 286 bool unused_error;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 true, // Fail on missing fields. 425 true, // Fail on missing fields.
392 from_policy); 426 from_policy);
393 validator.SetOncSource(onc_source); 427 validator.SetOncSource(onc_source);
394 428
395 Validator::Result validation_result; 429 Validator::Result validation_result;
396 toplevel_onc = validator.ValidateAndRepairObject( 430 toplevel_onc = validator.ValidateAndRepairObject(
397 &kToplevelConfigurationSignature, 431 &kToplevelConfigurationSignature,
398 *toplevel_onc, 432 *toplevel_onc,
399 &validation_result); 433 &validation_result);
400 434
435 FillInHexSSIDFieldsInOncObject(kToplevelConfigurationSignature,
436 toplevel_onc.get());
437
401 if (from_policy) { 438 if (from_policy) {
402 UMA_HISTOGRAM_BOOLEAN("Enterprise.ONC.PolicyValidation", 439 UMA_HISTOGRAM_BOOLEAN("Enterprise.ONC.PolicyValidation",
403 validation_result == Validator::VALID); 440 validation_result == Validator::VALID);
404 } 441 }
405 442
406 bool success = true; 443 bool success = true;
407 if (validation_result == Validator::VALID_WITH_WARNINGS) { 444 if (validation_result == Validator::VALID_WITH_WARNINGS) {
408 LOG(WARNING) << "ONC from " << GetSourceAsString(onc_source) 445 LOG(WARNING) << "ONC from " << GetSourceAsString(onc_source)
409 << " produced warnings."; 446 << " produced warnings.";
410 success = false; 447 success = false;
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 } 727 }
691 728
692 const base::ListValue* recommended_keys = NULL; 729 const base::ListValue* recommended_keys = NULL;
693 return (onc->GetList(recommended_property_key, &recommended_keys) && 730 return (onc->GetList(recommended_property_key, &recommended_keys) &&
694 recommended_keys->Find(base::StringValue(property_basename)) != 731 recommended_keys->Find(base::StringValue(property_basename)) !=
695 recommended_keys->end()); 732 recommended_keys->end());
696 } 733 }
697 734
698 } // namespace onc 735 } // namespace onc
699 } // namespace chromeos 736 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698