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 #ifndef CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_VALIDATOR_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_VALIDATOR_H_ |
6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_VALIDATOR_H_ | 6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_VALIDATOR_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 enum ValidateDMTokenOption { | 72 enum ValidateDMTokenOption { |
73 // The policy must have a non-empty DMToken. | 73 // The policy must have a non-empty DMToken. |
74 DM_TOKEN_REQUIRED, | 74 DM_TOKEN_REQUIRED, |
75 | 75 |
76 // The policy may have an empty or missing DMToken, if the expected token | 76 // The policy may have an empty or missing DMToken, if the expected token |
77 // is also empty. | 77 // is also empty. |
78 DM_TOKEN_NOT_REQUIRED, | 78 DM_TOKEN_NOT_REQUIRED, |
79 }; | 79 }; |
80 | 80 |
81 enum ValidateTimestampOption { | 81 enum ValidateTimestampOption { |
82 // The policy must have a timestamp field. | 82 // The policy must have a timestamp field and it should be checked against |
| 83 // both the start and end times. |
83 TIMESTAMP_REQUIRED, | 84 TIMESTAMP_REQUIRED, |
84 | 85 |
| 86 // The timestamp should only be compared vs the |not_before| value (this |
| 87 // is appropriate for platforms with unreliable system times, where we want |
| 88 // to ensure that fresh policy is newer than existing policy, but we can't |
| 89 // do any other validation). |
| 90 TIMESTAMP_NOT_BEFORE, |
| 91 |
85 // No timestamp field is required. | 92 // No timestamp field is required. |
86 TIMESTAMP_NOT_REQUIRED, | 93 TIMESTAMP_NOT_REQUIRED, |
87 }; | 94 }; |
88 | 95 |
89 virtual ~CloudPolicyValidatorBase(); | 96 virtual ~CloudPolicyValidatorBase(); |
90 | 97 |
91 // Validation status which can be read after completion has been signaled. | 98 // Validation status which can be read after completion has been signaled. |
92 Status status() const { return status_; } | 99 Status status() const { return status_; } |
93 bool success() const { return status_ == VALIDATION_OK; } | 100 bool success() const { return status_ == VALIDATION_OK; } |
94 | 101 |
95 // The policy objects owned by the validator. These are scoped_ptr | 102 // The policy objects owned by the validator. These are scoped_ptr |
96 // references, so ownership can be passed on once validation is complete. | 103 // references, so ownership can be passed on once validation is complete. |
97 scoped_ptr<enterprise_management::PolicyFetchResponse>& policy() { | 104 scoped_ptr<enterprise_management::PolicyFetchResponse>& policy() { |
98 return policy_; | 105 return policy_; |
99 } | 106 } |
100 scoped_ptr<enterprise_management::PolicyData>& policy_data() { | 107 scoped_ptr<enterprise_management::PolicyData>& policy_data() { |
101 return policy_data_; | 108 return policy_data_; |
102 } | 109 } |
103 | 110 |
104 // Instructs the validator to check that the policy timestamp is not before | 111 // Instructs the validator to check that the policy timestamp is not before |
105 // |not_before| and not after |now| + grace interval. If | 112 // |not_before| and not after |not_after| + grace interval. If |
106 // |timestamp_option| is set to TIMESTAMP_REQUIRED, then the policy will fail | 113 // |timestamp_option| is set to TIMESTAMP_REQUIRED, then the policy will fail |
107 // validation if it does not have a timestamp field. | 114 // validation if it does not have a timestamp field. |
108 void ValidateTimestamp(base::Time not_before, | 115 void ValidateTimestamp(base::Time not_before, |
109 base::Time now, | 116 base::Time not_after, |
110 ValidateTimestampOption timestamp_option); | 117 ValidateTimestampOption timestamp_option); |
111 | 118 |
112 // Validates the username in the policy blob matches |expected_user|. | 119 // Validates the username in the policy blob matches |expected_user|. |
113 void ValidateUsername(const std::string& expected_user); | 120 void ValidateUsername(const std::string& expected_user); |
114 | 121 |
115 // Validates the policy blob is addressed to |expected_domain|. This uses the | 122 // Validates the policy blob is addressed to |expected_domain|. This uses the |
116 // domain part of the username field in the policy for the check. | 123 // domain part of the username field in the policy for the check. |
117 void ValidateDomain(const std::string& expected_domain); | 124 void ValidateDomain(const std::string& expected_domain); |
118 | 125 |
119 // Makes sure the DM token on the policy matches |expected_token|. | 126 // Makes sure the DM token on the policy matches |expected_token|. |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 }; | 284 }; |
278 | 285 |
279 typedef CloudPolicyValidator<enterprise_management::CloudPolicySettings> | 286 typedef CloudPolicyValidator<enterprise_management::CloudPolicySettings> |
280 UserCloudPolicyValidator; | 287 UserCloudPolicyValidator; |
281 typedef CloudPolicyValidator<enterprise_management::ExternalPolicyData> | 288 typedef CloudPolicyValidator<enterprise_management::ExternalPolicyData> |
282 ComponentCloudPolicyValidator; | 289 ComponentCloudPolicyValidator; |
283 | 290 |
284 } // namespace policy | 291 } // namespace policy |
285 | 292 |
286 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_VALIDATOR_H_ | 293 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_VALIDATOR_H_ |
OLD | NEW |