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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
380 error_or_warning_found_ = true; | 380 error_or_warning_found_ = true; |
381 std::string message = MessageHeader() + "The required field '" + field_name + | 381 std::string message = MessageHeader() + "The required field '" + field_name + |
382 "' is missing."; | 382 "' is missing."; |
383 if (error_on_missing_field_) | 383 if (error_on_missing_field_) |
384 LOG(ERROR) << message; | 384 LOG(ERROR) << message; |
385 else | 385 else |
386 LOG(WARNING) << message; | 386 LOG(WARNING) << message; |
387 return false; | 387 return false; |
388 } | 388 } |
389 | 389 |
390 bool Validator::VerifyGuidUniqueAndAddToHash(const base::DictionaryValue& dict, | |
391 const std::string& key_guid, | |
392 std::set<std::string> *guids) { | |
393 std::string guid; | |
394 if (dict.GetStringWithoutPathExpansion(key_guid, &guid)) { | |
395 if (guids->count(guid) != 0) { | |
396 error_or_warning_found_ = true; | |
pneubeck (no reviews)
2014/02/17 10:11:36
Log an error (it's always an error and not a warni
kaliamoorthi
2014/02/17 15:06:49
Done.
| |
397 return false; | |
398 } | |
399 guids->insert(guid); | |
400 } | |
401 return true; | |
402 } | |
403 | |
390 bool Validator::IsCertPatternInDevicePolicy(const std::string& cert_type) { | 404 bool Validator::IsCertPatternInDevicePolicy(const std::string& cert_type) { |
391 if (cert_type == ::onc::certificate::kPattern && | 405 if (cert_type == ::onc::certificate::kPattern && |
392 onc_source_ == ::onc::ONC_SOURCE_DEVICE_POLICY) { | 406 onc_source_ == ::onc::ONC_SOURCE_DEVICE_POLICY) { |
393 error_or_warning_found_ = true; | 407 error_or_warning_found_ = true; |
394 LOG(ERROR) << MessageHeader() << "Client certificate patterns are " | 408 LOG(ERROR) << MessageHeader() << "Client certificate patterns are " |
395 << "prohibited in ONC device policies."; | 409 << "prohibited in ONC device policies."; |
396 return true; | 410 return true; |
397 } | 411 } |
398 return false; | 412 return false; |
399 } | 413 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 static const char* kValidTypes[] = { ::onc::network_type::kEthernet, | 465 static const char* kValidTypes[] = { ::onc::network_type::kEthernet, |
452 ::onc::network_type::kVPN, | 466 ::onc::network_type::kVPN, |
453 ::onc::network_type::kWiFi, | 467 ::onc::network_type::kWiFi, |
454 ::onc::network_type::kCellular, | 468 ::onc::network_type::kCellular, |
455 NULL }; | 469 NULL }; |
456 if (FieldExistsAndHasNoValidValue(*result, kType, kValidTypes) || | 470 if (FieldExistsAndHasNoValidValue(*result, kType, kValidTypes) || |
457 FieldExistsAndIsEmpty(*result, kGUID)) { | 471 FieldExistsAndIsEmpty(*result, kGUID)) { |
458 return false; | 472 return false; |
459 } | 473 } |
460 | 474 |
475 if (!VerifyGuidUniqueAndAddToHash(*result, kGUID, &network_guids_)) | |
476 return false; | |
477 | |
461 bool all_required_exist = RequireField(*result, kGUID); | 478 bool all_required_exist = RequireField(*result, kGUID); |
462 | 479 |
463 bool remove = false; | 480 bool remove = false; |
464 result->GetBooleanWithoutPathExpansion(::onc::kRemove, &remove); | 481 result->GetBooleanWithoutPathExpansion(::onc::kRemove, &remove); |
465 if (!remove) { | 482 if (!remove) { |
466 all_required_exist &= | 483 all_required_exist &= |
467 RequireField(*result, kName) && RequireField(*result, kType); | 484 RequireField(*result, kName) && RequireField(*result, kType); |
468 | 485 |
469 std::string type; | 486 std::string type; |
470 result->GetStringWithoutPathExpansion(kType, &type); | 487 result->GetStringWithoutPathExpansion(kType, &type); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
805 std::string type; | 822 std::string type; |
806 result->GetStringWithoutPathExpansion(kType, &type); | 823 result->GetStringWithoutPathExpansion(kType, &type); |
807 if (onc_source_ == ::onc::ONC_SOURCE_DEVICE_POLICY && | 824 if (onc_source_ == ::onc::ONC_SOURCE_DEVICE_POLICY && |
808 (type == kServer || type == kAuthority)) { | 825 (type == kServer || type == kAuthority)) { |
809 error_or_warning_found_ = true; | 826 error_or_warning_found_ = true; |
810 LOG(ERROR) << MessageHeader() << "Server and authority certificates are " | 827 LOG(ERROR) << MessageHeader() << "Server and authority certificates are " |
811 << "prohibited in ONC device policies."; | 828 << "prohibited in ONC device policies."; |
812 return false; | 829 return false; |
813 } | 830 } |
814 | 831 |
832 if (!VerifyGuidUniqueAndAddToHash(*result, kGUID, &certificate_guids_)) | |
833 return false; | |
834 | |
815 bool all_required_exist = RequireField(*result, kGUID); | 835 bool all_required_exist = RequireField(*result, kGUID); |
816 | 836 |
817 bool remove = false; | 837 bool remove = false; |
818 result->GetBooleanWithoutPathExpansion(::onc::kRemove, &remove); | 838 result->GetBooleanWithoutPathExpansion(::onc::kRemove, &remove); |
819 if (!remove) { | 839 if (!remove) { |
820 all_required_exist &= RequireField(*result, kType); | 840 all_required_exist &= RequireField(*result, kType); |
821 | 841 |
822 if (type == kClient) | 842 if (type == kClient) |
823 all_required_exist &= RequireField(*result, kPKCS12); | 843 all_required_exist &= RequireField(*result, kPKCS12); |
824 else if (type == kServer || type == kAuthority) | 844 else if (type == kServer || type == kAuthority) |
825 all_required_exist &= RequireField(*result, kX509); | 845 all_required_exist &= RequireField(*result, kX509); |
826 } | 846 } |
827 | 847 |
828 return !error_on_missing_field_ || all_required_exist; | 848 return !error_on_missing_field_ || all_required_exist; |
829 } | 849 } |
830 | 850 |
831 std::string Validator::MessageHeader() { | 851 std::string Validator::MessageHeader() { |
832 std::string path = path_.empty() ? "toplevel" : JoinString(path_, "."); | 852 std::string path = path_.empty() ? "toplevel" : JoinString(path_, "."); |
833 std::string message = "At " + path + ": "; | 853 std::string message = "At " + path + ": "; |
834 return message; | 854 return message; |
835 } | 855 } |
836 | 856 |
837 } // namespace onc | 857 } // namespace onc |
838 } // namespace chromeos | 858 } // namespace chromeos |
OLD | NEW |