| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 // The policy objects owned by the validator. These are scoped_ptr | 95 // The policy objects owned by the validator. These are scoped_ptr |
| 96 // references, so ownership can be passed on once validation is complete. | 96 // references, so ownership can be passed on once validation is complete. |
| 97 scoped_ptr<enterprise_management::PolicyFetchResponse>& policy() { | 97 scoped_ptr<enterprise_management::PolicyFetchResponse>& policy() { |
| 98 return policy_; | 98 return policy_; |
| 99 } | 99 } |
| 100 scoped_ptr<enterprise_management::PolicyData>& policy_data() { | 100 scoped_ptr<enterprise_management::PolicyData>& policy_data() { |
| 101 return policy_data_; | 101 return policy_data_; |
| 102 } | 102 } |
| 103 | 103 |
| 104 // If ValidateHashValue() is called, the hash value of the policy value can |
| 105 // be read with this method after completion has been signaled. |
| 106 uint32 hash_value() const { |
| 107 return hash_value_; |
| 108 } |
| 109 |
| 104 // Instructs the validator to check that the policy timestamp is not before | 110 // Instructs the validator to check that the policy timestamp is not before |
| 105 // |not_before| and not after |now| + grace interval. If | 111 // |not_before| and not after |now| + grace interval. If |
| 106 // |timestamp_option| is set to TIMESTAMP_REQUIRED, then the policy will fail | 112 // |timestamp_option| is set to TIMESTAMP_REQUIRED, then the policy will fail |
| 107 // validation if it does not have a timestamp field. | 113 // validation if it does not have a timestamp field. |
| 108 void ValidateTimestamp(base::Time not_before, | 114 void ValidateTimestamp(base::Time not_before, |
| 109 base::Time now, | 115 base::Time now, |
| 110 ValidateTimestampOption timestamp_option); | 116 ValidateTimestampOption timestamp_option); |
| 111 | 117 |
| 112 // Validates the username in the policy blob matches |expected_user|. | 118 // Validates the username in the policy blob matches |expected_user|. |
| 113 void ValidateUsername(const std::string& expected_user); | 119 void ValidateUsername(const std::string& expected_user); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 138 void ValidateSignature(const std::vector<uint8>& key, | 144 void ValidateSignature(const std::vector<uint8>& key, |
| 139 bool allow_key_rotation); | 145 bool allow_key_rotation); |
| 140 | 146 |
| 141 // Similar to StartSignatureVerification(), this checks the signature on the | 147 // Similar to StartSignatureVerification(), this checks the signature on the |
| 142 // policy blob. However, this variant expects a new policy key set in the | 148 // policy blob. However, this variant expects a new policy key set in the |
| 143 // policy blob and makes sure the policy is signed using that key. This should | 149 // policy blob and makes sure the policy is signed using that key. This should |
| 144 // be called at setup time when there is no existing policy key present to | 150 // be called at setup time when there is no existing policy key present to |
| 145 // check against. | 151 // check against. |
| 146 void ValidateInitialKey(); | 152 void ValidateInitialKey(); |
| 147 | 153 |
| 154 // Causes the validator to calculate the hash value of the policy value. |
| 155 // This can be used to determine if two policies are different. |
| 156 void ValidateHashValue(); |
| 157 |
| 148 // Convenience helper that configures timestamp and token validation based on | 158 // Convenience helper that configures timestamp and token validation based on |
| 149 // the current policy blob. |policy_data| may be NULL, in which case the | 159 // the current policy blob. |policy_data| may be NULL, in which case the |
| 150 // timestamp validation will drop the lower bound. |dm_token_option| | 160 // timestamp validation will drop the lower bound. |dm_token_option| |
| 151 // and |timestamp_option| have the same effect as the corresponding | 161 // and |timestamp_option| have the same effect as the corresponding |
| 152 // parameters for ValidateTimestamp() and ValidateDMToken(). | 162 // parameters for ValidateTimestamp() and ValidateDMToken(). |
| 153 void ValidateAgainstCurrentPolicy( | 163 void ValidateAgainstCurrentPolicy( |
| 154 const enterprise_management::PolicyData* policy_data, | 164 const enterprise_management::PolicyData* policy_data, |
| 155 ValidateTimestampOption timestamp_option, | 165 ValidateTimestampOption timestamp_option, |
| 156 ValidateDMTokenOption dm_token_option); | 166 ValidateDMTokenOption dm_token_option); |
| 157 | 167 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 175 enum ValidationFlags { | 185 enum ValidationFlags { |
| 176 VALIDATE_TIMESTAMP = 1 << 0, | 186 VALIDATE_TIMESTAMP = 1 << 0, |
| 177 VALIDATE_USERNAME = 1 << 1, | 187 VALIDATE_USERNAME = 1 << 1, |
| 178 VALIDATE_DOMAIN = 1 << 2, | 188 VALIDATE_DOMAIN = 1 << 2, |
| 179 VALIDATE_TOKEN = 1 << 3, | 189 VALIDATE_TOKEN = 1 << 3, |
| 180 VALIDATE_POLICY_TYPE = 1 << 4, | 190 VALIDATE_POLICY_TYPE = 1 << 4, |
| 181 VALIDATE_ENTITY_ID = 1 << 5, | 191 VALIDATE_ENTITY_ID = 1 << 5, |
| 182 VALIDATE_PAYLOAD = 1 << 6, | 192 VALIDATE_PAYLOAD = 1 << 6, |
| 183 VALIDATE_SIGNATURE = 1 << 7, | 193 VALIDATE_SIGNATURE = 1 << 7, |
| 184 VALIDATE_INITIAL_KEY = 1 << 8, | 194 VALIDATE_INITIAL_KEY = 1 << 8, |
| 195 VALIDATE_HASH_VALUE = 1 << 9, |
| 185 }; | 196 }; |
| 186 | 197 |
| 187 // Performs validation, called on a background thread. | 198 // Performs validation, called on a background thread. |
| 188 static void PerformValidation( | 199 static void PerformValidation( |
| 189 scoped_ptr<CloudPolicyValidatorBase> self, | 200 scoped_ptr<CloudPolicyValidatorBase> self, |
| 190 scoped_refptr<base::MessageLoopProxy> message_loop, | 201 scoped_refptr<base::MessageLoopProxy> message_loop, |
| 191 const base::Closure& completion_callback); | 202 const base::Closure& completion_callback); |
| 192 | 203 |
| 193 // Reports completion to the |completion_callback_|. | 204 // Reports completion to the |completion_callback_|. |
| 194 static void ReportCompletion(scoped_ptr<CloudPolicyValidatorBase> self, | 205 static void ReportCompletion(scoped_ptr<CloudPolicyValidatorBase> self, |
| 195 const base::Closure& completion_callback); | 206 const base::Closure& completion_callback); |
| 196 | 207 |
| 197 // Invokes all the checks and reports the result. | 208 // Invokes all the checks and reports the result. |
| 198 void RunChecks(); | 209 void RunChecks(); |
| 199 | 210 |
| 200 // Helper functions implementing individual checks. | 211 // Helper functions implementing individual checks. |
| 201 Status CheckTimestamp(); | 212 Status CheckTimestamp(); |
| 202 Status CheckUsername(); | 213 Status CheckUsername(); |
| 203 Status CheckDomain(); | 214 Status CheckDomain(); |
| 204 Status CheckToken(); | 215 Status CheckToken(); |
| 205 Status CheckPolicyType(); | 216 Status CheckPolicyType(); |
| 206 Status CheckEntityId(); | 217 Status CheckEntityId(); |
| 207 Status CheckPayload(); | 218 Status CheckPayload(); |
| 208 Status CheckSignature(); | 219 Status CheckSignature(); |
| 209 Status CheckInitialKey(); | 220 Status CheckInitialKey(); |
| 221 Status CheckHashValue(); |
| 210 | 222 |
| 211 // Verifies the SHA1/RSA |signature| on |data| against |key|. | 223 // Verifies the SHA1/RSA |signature| on |data| against |key|. |
| 212 static bool VerifySignature(const std::string& data, | 224 static bool VerifySignature(const std::string& data, |
| 213 const std::string& key, | 225 const std::string& key, |
| 214 const std::string& signature); | 226 const std::string& signature); |
| 215 | 227 |
| 216 Status status_; | 228 Status status_; |
| 217 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_; | 229 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_; |
| 218 scoped_ptr<enterprise_management::PolicyData> policy_data_; | 230 scoped_ptr<enterprise_management::PolicyData> policy_data_; |
| 219 google::protobuf::MessageLite* payload_; | 231 google::protobuf::MessageLite* payload_; |
| 232 uint32 hash_value_; |
| 220 | 233 |
| 221 int validation_flags_; | 234 int validation_flags_; |
| 222 int64 timestamp_not_before_; | 235 int64 timestamp_not_before_; |
| 223 int64 timestamp_not_after_; | 236 int64 timestamp_not_after_; |
| 224 ValidateTimestampOption timestamp_option_; | 237 ValidateTimestampOption timestamp_option_; |
| 225 ValidateDMTokenOption dm_token_option_; | 238 ValidateDMTokenOption dm_token_option_; |
| 226 std::string user_; | 239 std::string user_; |
| 227 std::string domain_; | 240 std::string domain_; |
| 228 std::string token_; | 241 std::string token_; |
| 229 std::string policy_type_; | 242 std::string policy_type_; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 }; | 290 }; |
| 278 | 291 |
| 279 typedef CloudPolicyValidator<enterprise_management::CloudPolicySettings> | 292 typedef CloudPolicyValidator<enterprise_management::CloudPolicySettings> |
| 280 UserCloudPolicyValidator; | 293 UserCloudPolicyValidator; |
| 281 typedef CloudPolicyValidator<enterprise_management::ExternalPolicyData> | 294 typedef CloudPolicyValidator<enterprise_management::ExternalPolicyData> |
| 282 ComponentCloudPolicyValidator; | 295 ComponentCloudPolicyValidator; |
| 283 | 296 |
| 284 } // namespace policy | 297 } // namespace policy |
| 285 | 298 |
| 286 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_VALIDATOR_H_ | 299 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_VALIDATOR_H_ |
| OLD | NEW |