OLD | NEW |
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_validator.h" | 5 #include "chromeos/network/onc/onc_validator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 | 379 |
380 bool Validator::ValidateToplevelConfiguration( | 380 bool Validator::ValidateToplevelConfiguration( |
381 const base::DictionaryValue& onc_object, | 381 const base::DictionaryValue& onc_object, |
382 base::DictionaryValue* result) { | 382 base::DictionaryValue* result) { |
383 if (!ValidateObjectDefault(kToplevelConfigurationSignature, | 383 if (!ValidateObjectDefault(kToplevelConfigurationSignature, |
384 onc_object, result)) { | 384 onc_object, result)) { |
385 return false; | 385 return false; |
386 } | 386 } |
387 | 387 |
388 static const char* kValidTypes[] = | 388 static const char* kValidTypes[] = |
389 { kUnencryptedConfiguration, kEncryptedConfiguration, NULL }; | 389 { toplevel_config::kUnencryptedConfiguration, |
390 if (FieldExistsAndHasNoValidValue(*result, kType, kValidTypes)) | 390 toplevel_config::kEncryptedConfiguration, |
| 391 NULL }; |
| 392 if (FieldExistsAndHasNoValidValue(*result, |
| 393 network_config::kType, |
| 394 kValidTypes)) |
391 return false; | 395 return false; |
392 | 396 |
393 bool allRequiredExist = true; | 397 bool allRequiredExist = true; |
394 | 398 |
395 // Not part of the ONC spec yet: | 399 // Not part of the ONC spec yet: |
396 // We don't require the type field and default to UnencryptedConfiguration. | 400 // We don't require the type field and default to UnencryptedConfiguration. |
397 std::string type = kUnencryptedConfiguration; | 401 std::string type = toplevel_config::kUnencryptedConfiguration; |
398 result->GetStringWithoutPathExpansion(kType, &type); | 402 result->GetStringWithoutPathExpansion(network_config::kType, &type); |
399 if (type == kUnencryptedConfiguration && | 403 if (type == toplevel_config::kUnencryptedConfiguration && |
400 !result->HasKey(kNetworkConfigurations) && | 404 !result->HasKey(toplevel_config::kNetworkConfigurations) && |
401 !result->HasKey(kCertificates)) { | 405 !result->HasKey(toplevel_config::kCertificates)) { |
402 error_or_warning_found_ = true; | 406 error_or_warning_found_ = true; |
403 std::string message = MessageHeader(error_on_missing_field_) + | 407 std::string message = MessageHeader(error_on_missing_field_) + |
404 "Neither the field '" + kNetworkConfigurations + "' nor '" + | 408 "Neither the field '" + toplevel_config::kNetworkConfigurations + |
405 kCertificates + "is present, but at least one is required."; | 409 "' nor '" + toplevel_config::kCertificates + |
| 410 "is present, but at least one is required."; |
406 if (error_on_missing_field_) | 411 if (error_on_missing_field_) |
407 LOG(ERROR) << message; | 412 LOG(ERROR) << message; |
408 else | 413 else |
409 LOG(WARNING) << message; | 414 LOG(WARNING) << message; |
410 allRequiredExist = false; | 415 allRequiredExist = false; |
411 } | 416 } |
412 | 417 |
413 return !error_on_missing_field_ || allRequiredExist; | 418 return !error_on_missing_field_ || allRequiredExist; |
414 } | 419 } |
415 | 420 |
416 bool Validator::ValidateNetworkConfiguration( | 421 bool Validator::ValidateNetworkConfiguration( |
417 const base::DictionaryValue& onc_object, | 422 const base::DictionaryValue& onc_object, |
418 base::DictionaryValue* result) { | 423 base::DictionaryValue* result) { |
419 if (!ValidateObjectDefault(kNetworkConfigurationSignature, | 424 if (!ValidateObjectDefault(kNetworkConfigurationSignature, |
420 onc_object, result)) { | 425 onc_object, result)) { |
421 return false; | 426 return false; |
422 } | 427 } |
423 | 428 |
424 static const char* kValidTypes[] = { kEthernet, kVPN, kWiFi, NULL }; | 429 static const char* kValidTypes[] = { network_type::kEthernet, |
425 if (FieldExistsAndHasNoValidValue(*result, kType, kValidTypes)) | 430 network_type::kVPN, |
| 431 network_type::kWiFi, |
| 432 NULL }; |
| 433 if (FieldExistsAndHasNoValidValue(*result, |
| 434 network_config::kType, |
| 435 kValidTypes)) |
426 return false; | 436 return false; |
427 | 437 |
428 bool allRequiredExist = RequireField(*result, kGUID); | 438 bool allRequiredExist = RequireField(*result, network_config::kGUID); |
429 | 439 |
430 bool remove = false; | 440 bool remove = false; |
431 result->GetBooleanWithoutPathExpansion(kRemove, &remove); | 441 result->GetBooleanWithoutPathExpansion(kRemove, &remove); |
432 if (!remove) { | 442 if (!remove) { |
433 allRequiredExist &= RequireField(*result, kName); | 443 allRequiredExist &= RequireField(*result, network_config::kName); |
434 allRequiredExist &= RequireField(*result, kType); | 444 allRequiredExist &= RequireField(*result, network_config::kType); |
435 | 445 |
436 std::string type; | 446 std::string type; |
437 result->GetStringWithoutPathExpansion(kType, &type); | 447 result->GetStringWithoutPathExpansion(network_config::kType, &type); |
438 | 448 |
439 // Prohibit anything but WiFi and Ethernet for device-level policy (which | 449 // Prohibit anything but WiFi and Ethernet for device-level policy (which |
440 // corresponds to shared networks). See also http://crosbug.com/28741. | 450 // corresponds to shared networks). See also http://crosbug.com/28741. |
441 if (onc_source_ == ONC_SOURCE_DEVICE_POLICY && | 451 if (onc_source_ == ONC_SOURCE_DEVICE_POLICY && |
442 type != kWiFi && | 452 type != network_type::kWiFi && |
443 type != kEthernet) { | 453 type != network_type::kEthernet) { |
444 error_or_warning_found_ = true; | 454 error_or_warning_found_ = true; |
445 LOG(ERROR) << ErrorHeader() << "Networks of type '" | 455 LOG(ERROR) << ErrorHeader() << "Networks of type '" |
446 << type << "' are prohibited in ONC device policies."; | 456 << type << "' are prohibited in ONC device policies."; |
447 return false; | 457 return false; |
448 } | 458 } |
449 allRequiredExist &= type.empty() || RequireField(*result, type); | 459 allRequiredExist &= type.empty() || RequireField(*result, type); |
450 } | 460 } |
451 | 461 |
452 return !error_on_missing_field_ || allRequiredExist; | 462 return !error_on_missing_field_ || allRequiredExist; |
453 } | 463 } |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 const base::DictionaryValue& onc_object, | 742 const base::DictionaryValue& onc_object, |
733 base::DictionaryValue* result) { | 743 base::DictionaryValue* result) { |
734 using namespace onc::certificate; | 744 using namespace onc::certificate; |
735 if (!ValidateObjectDefault(kCertificateSignature, onc_object, result)) | 745 if (!ValidateObjectDefault(kCertificateSignature, onc_object, result)) |
736 return false; | 746 return false; |
737 | 747 |
738 static const char* kValidTypes[] = { kClient, kServer, kAuthority, NULL }; | 748 static const char* kValidTypes[] = { kClient, kServer, kAuthority, NULL }; |
739 if (FieldExistsAndHasNoValidValue(*result, certificate::kType, kValidTypes)) | 749 if (FieldExistsAndHasNoValidValue(*result, certificate::kType, kValidTypes)) |
740 return false; | 750 return false; |
741 | 751 |
742 bool allRequiredExist = RequireField(*result, kGUID); | 752 bool allRequiredExist = RequireField(*result, certificate::kGUID); |
743 | 753 |
744 bool remove = false; | 754 bool remove = false; |
745 result->GetBooleanWithoutPathExpansion(kRemove, &remove); | 755 result->GetBooleanWithoutPathExpansion(kRemove, &remove); |
746 if (!remove) { | 756 if (!remove) { |
747 allRequiredExist &= RequireField(*result, certificate::kType); | 757 allRequiredExist &= RequireField(*result, certificate::kType); |
748 | 758 |
749 std::string type; | 759 std::string type; |
750 result->GetStringWithoutPathExpansion(certificate::kType, &type); | 760 result->GetStringWithoutPathExpansion(certificate::kType, &type); |
751 if (type == kClient) | 761 if (type == kClient) |
752 allRequiredExist &= RequireField(*result, kPKCS12); | 762 allRequiredExist &= RequireField(*result, kPKCS12); |
(...skipping 13 matching lines...) Expand all Loading... |
766 } | 776 } |
767 | 777 |
768 std::string Validator::MessageHeader(bool is_error) { | 778 std::string Validator::MessageHeader(bool is_error) { |
769 std::string path = path_.empty() ? "toplevel" : JoinString(path_, "."); | 779 std::string path = path_.empty() ? "toplevel" : JoinString(path_, "."); |
770 std::string message = "At " + path + ": "; | 780 std::string message = "At " + path + ": "; |
771 return message; | 781 return message; |
772 } | 782 } |
773 | 783 |
774 } // namespace onc | 784 } // namespace onc |
775 } // namespace chromeos | 785 } // namespace chromeos |
OLD | NEW |