| 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 "chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 return gaia::ExtractDomainName(gaia::CanonicalizeEmail(username)); | 59 return gaia::ExtractDomainName(gaia::CanonicalizeEmail(username)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 } // namespace | 62 } // namespace |
| 63 | 63 |
| 64 UserCloudPolicyStoreChromeOS::UserCloudPolicyStoreChromeOS( | 64 UserCloudPolicyStoreChromeOS::UserCloudPolicyStoreChromeOS( |
| 65 chromeos::CryptohomeClient* cryptohome_client, | 65 chromeos::CryptohomeClient* cryptohome_client, |
| 66 chromeos::SessionManagerClient* session_manager_client, | 66 chromeos::SessionManagerClient* session_manager_client, |
| 67 scoped_refptr<base::SequencedTaskRunner> background_task_runner, | 67 scoped_refptr<base::SequencedTaskRunner> background_task_runner, |
| 68 const AccountId& account_id, | 68 const AccountId& account_id, |
| 69 const base::FilePath& user_policy_key_dir) | 69 const base::FilePath& user_policy_key_dir, |
| 70 bool is_active_directory) |
| 70 : UserCloudPolicyStoreBase(background_task_runner), | 71 : UserCloudPolicyStoreBase(background_task_runner), |
| 71 cryptohome_client_(cryptohome_client), | 72 cryptohome_client_(cryptohome_client), |
| 72 session_manager_client_(session_manager_client), | 73 session_manager_client_(session_manager_client), |
| 73 account_id_(account_id), | 74 account_id_(account_id), |
| 74 user_policy_key_dir_(user_policy_key_dir), | 75 user_policy_key_dir_(user_policy_key_dir), |
| 76 is_active_directory_(is_active_directory), |
| 75 weak_factory_(this) {} | 77 weak_factory_(this) {} |
| 76 | 78 |
| 77 UserCloudPolicyStoreChromeOS::~UserCloudPolicyStoreChromeOS() {} | 79 UserCloudPolicyStoreChromeOS::~UserCloudPolicyStoreChromeOS() {} |
| 78 | 80 |
| 79 void UserCloudPolicyStoreChromeOS::Store( | 81 void UserCloudPolicyStoreChromeOS::Store( |
| 80 const em::PolicyFetchResponse& policy) { | 82 const em::PolicyFetchResponse& policy) { |
| 83 DCHECK(!is_active_directory_); |
| 84 |
| 81 // Cancel all pending requests. | 85 // Cancel all pending requests. |
| 82 weak_factory_.InvalidateWeakPtrs(); | 86 weak_factory_.InvalidateWeakPtrs(); |
| 83 std::unique_ptr<em::PolicyFetchResponse> response( | 87 std::unique_ptr<em::PolicyFetchResponse> response( |
| 84 new em::PolicyFetchResponse(policy)); | 88 new em::PolicyFetchResponse(policy)); |
| 85 EnsurePolicyKeyLoaded( | 89 EnsurePolicyKeyLoaded( |
| 86 base::Bind(&UserCloudPolicyStoreChromeOS::ValidatePolicyForStore, | 90 base::Bind(&UserCloudPolicyStoreChromeOS::ValidatePolicyForStore, |
| 87 weak_factory_.GetWeakPtr(), | 91 weak_factory_.GetWeakPtr(), |
| 88 base::Passed(&response))); | 92 base::Passed(&response))); |
| 89 } | 93 } |
| 90 | 94 |
| 91 void UserCloudPolicyStoreChromeOS::Load() { | 95 void UserCloudPolicyStoreChromeOS::Load() { |
| 92 // Cancel all pending requests. | 96 // Cancel all pending requests. |
| 93 weak_factory_.InvalidateWeakPtrs(); | 97 weak_factory_.InvalidateWeakPtrs(); |
| 94 session_manager_client_->RetrievePolicyForUser( | 98 session_manager_client_->RetrievePolicyForUser( |
| 95 cryptohome::Identification(account_id_), | 99 cryptohome::Identification(account_id_), |
| 96 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyRetrieved, | 100 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyRetrieved, |
| 97 weak_factory_.GetWeakPtr())); | 101 weak_factory_.GetWeakPtr())); |
| 98 } | 102 } |
| 99 | 103 |
| 100 void UserCloudPolicyStoreChromeOS::LoadImmediately() { | 104 void UserCloudPolicyStoreChromeOS::LoadImmediately() { |
| 101 // This blocking DBus call is in the startup path and will block the UI | 105 // This blocking D-Bus call is in the startup path and will block the UI |
| 102 // thread. This only happens when the Profile is created synchronously, which | 106 // thread. This only happens when the Profile is created synchronously, which |
| 103 // on ChromeOS happens whenever the browser is restarted into the same | 107 // on Chrome OS happens whenever the browser is restarted into the same |
| 104 // session. That happens when the browser crashes, or right after signin if | 108 // session. That happens when the browser crashes, or right after signin if |
| 105 // the user has flags configured in about:flags. | 109 // the user has flags configured in about:flags. |
| 106 // However, on those paths we must load policy synchronously so that the | 110 // However, on those paths we must load policy synchronously so that the |
| 107 // Profile initialization never sees unmanaged prefs, which would lead to | 111 // Profile initialization never sees unmanaged prefs, which would lead to |
| 108 // data loss. http://crbug.com/263061 | 112 // data loss. http://crbug.com/263061 |
| 109 std::string policy_blob = | 113 std::string policy_blob = |
| 110 session_manager_client_->BlockingRetrievePolicyForUser( | 114 session_manager_client_->BlockingRetrievePolicyForUser( |
| 111 cryptohome::Identification(account_id_)); | 115 cryptohome::Identification(account_id_)); |
| 112 if (policy_blob.empty()) { | 116 if (policy_blob.empty()) { |
| 113 // The session manager doesn't have policy, or the call failed. | 117 // The session manager doesn't have policy, or the call failed. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 138 cached_policy_key_loaded_ = true; | 142 cached_policy_key_loaded_ = true; |
| 139 | 143 |
| 140 std::unique_ptr<UserCloudPolicyValidator> validator = | 144 std::unique_ptr<UserCloudPolicyValidator> validator = |
| 141 CreateValidatorForLoad(std::move(policy)); | 145 CreateValidatorForLoad(std::move(policy)); |
| 142 validator->RunValidation(); | 146 validator->RunValidation(); |
| 143 OnRetrievedPolicyValidated(validator.get()); | 147 OnRetrievedPolicyValidated(validator.get()); |
| 144 } | 148 } |
| 145 | 149 |
| 146 void UserCloudPolicyStoreChromeOS::ValidatePolicyForStore( | 150 void UserCloudPolicyStoreChromeOS::ValidatePolicyForStore( |
| 147 std::unique_ptr<em::PolicyFetchResponse> policy) { | 151 std::unique_ptr<em::PolicyFetchResponse> policy) { |
| 152 DCHECK(!is_active_directory_); |
| 153 |
| 148 // Create and configure a validator. | 154 // Create and configure a validator. |
| 149 std::unique_ptr<UserCloudPolicyValidator> validator = CreateValidator( | 155 std::unique_ptr<UserCloudPolicyValidator> validator = CreateValidator( |
| 150 std::move(policy), CloudPolicyValidatorBase::TIMESTAMP_FULLY_VALIDATED); | 156 std::move(policy), CloudPolicyValidatorBase::TIMESTAMP_FULLY_VALIDATED); |
| 151 validator->ValidateUsername(account_id_.GetUserEmail(), true); | 157 validator->ValidateUsername(account_id_.GetUserEmail(), true); |
| 152 if (cached_policy_key_.empty()) { | 158 if (cached_policy_key_.empty()) { |
| 153 validator->ValidateInitialKey(ExtractDomain(account_id_.GetUserEmail())); | 159 validator->ValidateInitialKey(ExtractDomain(account_id_.GetUserEmail())); |
| 154 } else { | 160 } else { |
| 155 validator->ValidateSignatureAllowingRotation( | 161 validator->ValidateSignatureAllowingRotation( |
| 156 cached_policy_key_, ExtractDomain(account_id_.GetUserEmail())); | 162 cached_policy_key_, ExtractDomain(account_id_.GetUserEmail())); |
| 157 } | 163 } |
| 158 | 164 |
| 159 // Start validation. The Validator will delete itself once validation is | 165 // Start validation. The Validator will delete itself once validation is |
| 160 // complete. | 166 // complete. |
| 161 validator.release()->StartValidation( | 167 validator.release()->StartValidation( |
| 162 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyToStoreValidated, | 168 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyToStoreValidated, |
| 163 weak_factory_.GetWeakPtr())); | 169 weak_factory_.GetWeakPtr())); |
| 164 } | 170 } |
| 165 | 171 |
| 166 void UserCloudPolicyStoreChromeOS::OnPolicyToStoreValidated( | 172 void UserCloudPolicyStoreChromeOS::OnPolicyToStoreValidated( |
| 167 UserCloudPolicyValidator* validator) { | 173 UserCloudPolicyValidator* validator) { |
| 174 DCHECK(!is_active_directory_); |
| 175 |
| 168 validation_status_ = validator->status(); | 176 validation_status_ = validator->status(); |
| 169 | 177 |
| 170 UMA_HISTOGRAM_ENUMERATION( | 178 UMA_HISTOGRAM_ENUMERATION( |
| 171 "Enterprise.UserPolicyValidationStoreStatus", | 179 "Enterprise.UserPolicyValidationStoreStatus", |
| 172 validation_status_, | 180 validation_status_, |
| 173 UserCloudPolicyValidator::VALIDATION_STATUS_SIZE); | 181 UserCloudPolicyValidator::VALIDATION_STATUS_SIZE); |
| 174 | 182 |
| 175 if (!validator->success()) { | 183 if (!validator->success()) { |
| 176 status_ = STATUS_VALIDATION_ERROR; | 184 status_ = STATUS_VALIDATION_ERROR; |
| 177 NotifyStoreError(); | 185 NotifyStoreError(); |
| 178 return; | 186 return; |
| 179 } | 187 } |
| 180 | 188 |
| 181 std::string policy_blob; | 189 std::string policy_blob; |
| 182 if (!validator->policy()->SerializeToString(&policy_blob)) { | 190 if (!validator->policy()->SerializeToString(&policy_blob)) { |
| 183 status_ = STATUS_SERIALIZE_ERROR; | 191 status_ = STATUS_SERIALIZE_ERROR; |
| 184 NotifyStoreError(); | 192 NotifyStoreError(); |
| 185 return; | 193 return; |
| 186 } | 194 } |
| 187 | 195 |
| 188 session_manager_client_->StorePolicyForUser( | 196 session_manager_client_->StorePolicyForUser( |
| 189 cryptohome::Identification(account_id_), policy_blob, | 197 cryptohome::Identification(account_id_), policy_blob, |
| 190 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyStored, | 198 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyStored, |
| 191 weak_factory_.GetWeakPtr())); | 199 weak_factory_.GetWeakPtr())); |
| 192 } | 200 } |
| 193 | 201 |
| 194 void UserCloudPolicyStoreChromeOS::OnPolicyStored(bool success) { | 202 void UserCloudPolicyStoreChromeOS::OnPolicyStored(bool success) { |
| 203 DCHECK(!is_active_directory_); |
| 204 |
| 195 if (!success) { | 205 if (!success) { |
| 196 status_ = STATUS_STORE_ERROR; | 206 status_ = STATUS_STORE_ERROR; |
| 197 NotifyStoreError(); | 207 NotifyStoreError(); |
| 198 } else { | 208 } else { |
| 199 // Load the policy right after storing it, to make sure it was accepted by | 209 // Load the policy right after storing it, to make sure it was accepted by |
| 200 // the session manager. An additional validation is performed after the | 210 // the session manager. An additional validation is performed after the |
| 201 // load; reload the key for that validation too, in case it was rotated. | 211 // load; reload the key for that validation too, in case it was rotated. |
| 202 ReloadPolicyKey(base::Bind(&UserCloudPolicyStoreChromeOS::Load, | 212 ReloadPolicyKey(base::Bind(&UserCloudPolicyStoreChromeOS::Load, |
| 203 weak_factory_.GetWeakPtr())); | 213 weak_factory_.GetWeakPtr())); |
| 204 } | 214 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 218 | 228 |
| 219 std::unique_ptr<em::PolicyFetchResponse> policy( | 229 std::unique_ptr<em::PolicyFetchResponse> policy( |
| 220 new em::PolicyFetchResponse()); | 230 new em::PolicyFetchResponse()); |
| 221 if (!policy->ParseFromString(policy_blob)) { | 231 if (!policy->ParseFromString(policy_blob)) { |
| 222 status_ = STATUS_PARSE_ERROR; | 232 status_ = STATUS_PARSE_ERROR; |
| 223 NotifyStoreError(); | 233 NotifyStoreError(); |
| 224 return; | 234 return; |
| 225 } | 235 } |
| 226 | 236 |
| 227 // Load |cached_policy_key_| to verify the loaded policy. | 237 // Load |cached_policy_key_| to verify the loaded policy. |
| 228 EnsurePolicyKeyLoaded( | 238 if (is_active_directory_) { |
| 229 base::Bind(&UserCloudPolicyStoreChromeOS::ValidateRetrievedPolicy, | 239 ValidateRetrievedPolicy(std::move(policy)); |
| 230 weak_factory_.GetWeakPtr(), | 240 } else { |
| 231 base::Passed(&policy))); | 241 EnsurePolicyKeyLoaded( |
| 242 base::Bind(&UserCloudPolicyStoreChromeOS::ValidateRetrievedPolicy, |
| 243 weak_factory_.GetWeakPtr(), base::Passed(&policy))); |
| 244 } |
| 232 } | 245 } |
| 233 | 246 |
| 234 void UserCloudPolicyStoreChromeOS::ValidateRetrievedPolicy( | 247 void UserCloudPolicyStoreChromeOS::ValidateRetrievedPolicy( |
| 235 std::unique_ptr<em::PolicyFetchResponse> policy) { | 248 std::unique_ptr<em::PolicyFetchResponse> policy) { |
| 236 // Create and configure a validator for the loaded policy. | 249 // Create and configure a validator for the loaded policy. |
| 237 std::unique_ptr<UserCloudPolicyValidator> validator = | 250 std::unique_ptr<UserCloudPolicyValidator> validator = |
| 238 CreateValidatorForLoad(std::move(policy)); | 251 CreateValidatorForLoad(std::move(policy)); |
| 239 // Start validation. The Validator will delete itself once validation is | 252 // Start validation. The Validator will delete itself once validation is |
| 240 // complete. | 253 // complete. |
| 241 validator.release()->StartValidation( | 254 validator.release()->StartValidation( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 260 | 273 |
| 261 InstallPolicy(std::move(validator->policy_data()), | 274 InstallPolicy(std::move(validator->policy_data()), |
| 262 std::move(validator->payload()), cached_policy_key_); | 275 std::move(validator->payload()), cached_policy_key_); |
| 263 status_ = STATUS_OK; | 276 status_ = STATUS_OK; |
| 264 | 277 |
| 265 NotifyStoreLoaded(); | 278 NotifyStoreLoaded(); |
| 266 } | 279 } |
| 267 | 280 |
| 268 void UserCloudPolicyStoreChromeOS::ReloadPolicyKey( | 281 void UserCloudPolicyStoreChromeOS::ReloadPolicyKey( |
| 269 const base::Closure& callback) { | 282 const base::Closure& callback) { |
| 283 DCHECK(!is_active_directory_); |
| 284 |
| 270 std::string* key = new std::string(); | 285 std::string* key = new std::string(); |
| 271 background_task_runner()->PostTaskAndReply( | 286 background_task_runner()->PostTaskAndReply( |
| 272 FROM_HERE, base::Bind(&UserCloudPolicyStoreChromeOS::LoadPolicyKey, | 287 FROM_HERE, base::Bind(&UserCloudPolicyStoreChromeOS::LoadPolicyKey, |
| 273 cached_policy_key_path_, key), | 288 cached_policy_key_path_, key), |
| 274 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyKeyReloaded, | 289 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyKeyReloaded, |
| 275 weak_factory_.GetWeakPtr(), base::Owned(key), callback)); | 290 weak_factory_.GetWeakPtr(), base::Owned(key), callback)); |
| 276 } | 291 } |
| 277 | 292 |
| 278 // static | 293 // static |
| 279 void UserCloudPolicyStoreChromeOS::LoadPolicyKey(const base::FilePath& path, | 294 void UserCloudPolicyStoreChromeOS::LoadPolicyKey(const base::FilePath& path, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 299 LOG(ERROR) << "Failed to read key at " << path.value(); | 314 LOG(ERROR) << "Failed to read key at " << path.value(); |
| 300 } | 315 } |
| 301 | 316 |
| 302 if (key->empty()) | 317 if (key->empty()) |
| 303 SampleValidationFailure(VALIDATION_FAILURE_LOAD_KEY); | 318 SampleValidationFailure(VALIDATION_FAILURE_LOAD_KEY); |
| 304 } | 319 } |
| 305 | 320 |
| 306 void UserCloudPolicyStoreChromeOS::OnPolicyKeyReloaded( | 321 void UserCloudPolicyStoreChromeOS::OnPolicyKeyReloaded( |
| 307 std::string* key, | 322 std::string* key, |
| 308 const base::Closure& callback) { | 323 const base::Closure& callback) { |
| 324 DCHECK(!is_active_directory_); |
| 325 |
| 309 cached_policy_key_ = *key; | 326 cached_policy_key_ = *key; |
| 310 cached_policy_key_loaded_ = true; | 327 cached_policy_key_loaded_ = true; |
| 311 callback.Run(); | 328 callback.Run(); |
| 312 } | 329 } |
| 313 | 330 |
| 314 void UserCloudPolicyStoreChromeOS::EnsurePolicyKeyLoaded( | 331 void UserCloudPolicyStoreChromeOS::EnsurePolicyKeyLoaded( |
| 315 const base::Closure& callback) { | 332 const base::Closure& callback) { |
| 333 DCHECK(!is_active_directory_); |
| 334 |
| 316 if (cached_policy_key_loaded_) { | 335 if (cached_policy_key_loaded_) { |
| 317 callback.Run(); | 336 callback.Run(); |
| 318 } else { | 337 } else { |
| 319 // Get the hashed username that's part of the key's path, to determine | 338 // Get the hashed username that's part of the key's path, to determine |
| 320 // |cached_policy_key_path_|. | 339 // |cached_policy_key_path_|. |
| 321 cryptohome_client_->GetSanitizedUsername( | 340 cryptohome_client_->GetSanitizedUsername( |
| 322 cryptohome::Identification(account_id_), | 341 cryptohome::Identification(account_id_), |
| 323 base::Bind(&UserCloudPolicyStoreChromeOS::OnGetSanitizedUsername, | 342 base::Bind(&UserCloudPolicyStoreChromeOS::OnGetSanitizedUsername, |
| 324 weak_factory_.GetWeakPtr(), callback)); | 343 weak_factory_.GetWeakPtr(), callback)); |
| 325 } | 344 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 338 SampleValidationFailure(VALIDATION_FAILURE_DBUS); | 357 SampleValidationFailure(VALIDATION_FAILURE_DBUS); |
| 339 } | 358 } |
| 340 ReloadPolicyKey(callback); | 359 ReloadPolicyKey(callback); |
| 341 } | 360 } |
| 342 | 361 |
| 343 std::unique_ptr<UserCloudPolicyValidator> | 362 std::unique_ptr<UserCloudPolicyValidator> |
| 344 UserCloudPolicyStoreChromeOS::CreateValidatorForLoad( | 363 UserCloudPolicyStoreChromeOS::CreateValidatorForLoad( |
| 345 std::unique_ptr<em::PolicyFetchResponse> policy) { | 364 std::unique_ptr<em::PolicyFetchResponse> policy) { |
| 346 std::unique_ptr<UserCloudPolicyValidator> validator = CreateValidator( | 365 std::unique_ptr<UserCloudPolicyValidator> validator = CreateValidator( |
| 347 std::move(policy), CloudPolicyValidatorBase::TIMESTAMP_NOT_BEFORE); | 366 std::move(policy), CloudPolicyValidatorBase::TIMESTAMP_NOT_BEFORE); |
| 348 validator->ValidateUsername(account_id_.GetUserEmail(), true); | 367 if (is_active_directory_) { |
| 349 // The policy loaded from session manager need not be validated using the | 368 validator->ValidateTimestamp( |
| 350 // verification key since it is secure, and since there may be legacy policy | 369 base::Time(), base::Time(), |
| 351 // data that was stored without a verification key. | 370 CloudPolicyValidatorBase::TIMESTAMP_NOT_VALIDATED); |
| 352 validator->ValidateSignature(cached_policy_key_); | 371 validator->ValidateDMToken(std::string(), |
| 372 CloudPolicyValidatorBase::DM_TOKEN_NOT_REQUIRED); |
| 373 validator->ValidateDeviceId( |
| 374 std::string(), CloudPolicyValidatorBase::DEVICE_ID_NOT_REQUIRED); |
| 375 } else { |
| 376 validator->ValidateUsername(account_id_.GetUserEmail(), true); |
| 377 // The policy loaded from session manager need not be validated using the |
| 378 // verification key since it is secure, and since there may be legacy policy |
| 379 // data that was stored without a verification key. |
| 380 validator->ValidateSignature(cached_policy_key_); |
| 381 } |
| 353 return validator; | 382 return validator; |
| 354 } | 383 } |
| 355 | 384 |
| 356 } // namespace policy | 385 } // namespace policy |
| OLD | NEW |