| 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/settings/session_manager_operation.h" | 5 #include "chrome/browser/chromeos/settings/session_manager_operation.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/task_runner_util.h" | 12 #include "base/task_runner_util.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "chrome/browser/chromeos/login/user.h" |
| 15 #include "chrome/browser/chromeos/login/user_manager.h" |
| 14 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 16 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
| 15 #include "chrome/browser/chromeos/settings/owner_key_util.h" | 17 #include "chrome/browser/chromeos/settings/owner_key_util.h" |
| 18 #include "chrome/browser/net/nss_context.h" |
| 16 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 19 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 17 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 18 #include "crypto/rsa_private_key.h" | 21 #include "crypto/rsa_private_key.h" |
| 19 #include "crypto/signature_creator.h" | 22 #include "crypto/signature_creator.h" |
| 20 #include "policy/proto/device_management_backend.pb.h" | 23 #include "policy/proto/device_management_backend.pb.h" |
| 21 | 24 |
| 22 namespace em = enterprise_management; | 25 namespace em = enterprise_management; |
| 23 | 26 |
| 24 namespace chromeos { | 27 namespace chromeos { |
| 25 | 28 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 68 } |
| 66 | 69 |
| 67 void SessionManagerOperation::ReportResult( | 70 void SessionManagerOperation::ReportResult( |
| 68 DeviceSettingsService::Status status) { | 71 DeviceSettingsService::Status status) { |
| 69 callback_.Run(this, status); | 72 callback_.Run(this, status); |
| 70 } | 73 } |
| 71 | 74 |
| 72 void SessionManagerOperation::EnsureOwnerKey(const base::Closure& callback) { | 75 void SessionManagerOperation::EnsureOwnerKey(const base::Closure& callback) { |
| 73 if (force_key_load_ || !owner_key_.get() || !owner_key_->public_key()) { | 76 if (force_key_load_ || !owner_key_.get() || !owner_key_->public_key()) { |
| 74 scoped_refptr<base::TaskRunner> task_runner = | 77 scoped_refptr<base::TaskRunner> task_runner = |
| 75 content::BrowserThread::GetBlockingPool()-> | 78 content::BrowserThread::GetBlockingPool() |
| 76 GetTaskRunnerWithShutdownBehavior( | 79 ->GetTaskRunnerWithShutdownBehavior( |
| 77 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 80 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 78 base::PostTaskAndReplyWithResult( | 81 base::PostTaskAndReplyWithResult( |
| 79 task_runner.get(), | 82 task_runner.get(), |
| 80 FROM_HERE, | 83 FROM_HERE, |
| 81 base::Bind(&SessionManagerOperation::LoadOwnerKey, | 84 base::Bind(&SessionManagerOperation::LoadOwnerKey, |
| 82 owner_key_util_, owner_key_), | 85 owner_key_util_, |
| 86 owner_key_, |
| 87 slot_), |
| 83 base::Bind(&SessionManagerOperation::StoreOwnerKey, | 88 base::Bind(&SessionManagerOperation::StoreOwnerKey, |
| 84 weak_factory_.GetWeakPtr(), callback)); | 89 weak_factory_.GetWeakPtr(), |
| 90 callback)); |
| 85 } else { | 91 } else { |
| 86 callback.Run(); | 92 callback.Run(); |
| 87 } | 93 } |
| 88 } | 94 } |
| 89 | 95 |
| 90 // static | 96 // static |
| 91 scoped_refptr<OwnerKey> SessionManagerOperation::LoadOwnerKey( | 97 scoped_refptr<OwnerKey> SessionManagerOperation::LoadOwnerKey( |
| 92 scoped_refptr<OwnerKeyUtil> util, | 98 scoped_refptr<OwnerKeyUtil> util, |
| 93 scoped_refptr<OwnerKey> current_key) { | 99 scoped_refptr<OwnerKey> current_key, |
| 100 PK11SlotInfo* slot) { |
| 94 scoped_ptr<std::vector<uint8> > public_key; | 101 scoped_ptr<std::vector<uint8> > public_key; |
| 95 scoped_ptr<crypto::RSAPrivateKey> private_key; | 102 scoped_ptr<crypto::RSAPrivateKey> private_key; |
| 96 | 103 |
| 97 // Keep any already-existing keys. | 104 // Keep any already-existing keys. |
| 98 if (current_key.get()) { | 105 if (current_key.get()) { |
| 99 if (current_key->public_key()) | 106 if (current_key->public_key()) |
| 100 public_key.reset(new std::vector<uint8>(*current_key->public_key())); | 107 public_key.reset(new std::vector<uint8>(*current_key->public_key())); |
| 101 if (current_key->private_key()) | 108 if (current_key->private_key()) |
| 102 private_key.reset(current_key->private_key()->Copy()); | 109 private_key.reset(current_key->private_key()->Copy()); |
| 103 } | 110 } |
| 104 | 111 |
| 105 if (!public_key.get() && util->IsPublicKeyPresent()) { | 112 if (!public_key.get() && util->IsPublicKeyPresent()) { |
| 106 public_key.reset(new std::vector<uint8>()); | 113 public_key.reset(new std::vector<uint8>()); |
| 107 if (!util->ImportPublicKey(public_key.get())) | 114 if (!util->ImportPublicKey(public_key.get())) |
| 108 LOG(ERROR) << "Failed to load public owner key."; | 115 LOG(ERROR) << "Failed to load public owner key."; |
| 109 } | 116 } |
| 110 | 117 |
| 111 if (public_key.get() && !private_key.get()) { | 118 if (public_key.get() && !private_key.get()) { |
| 112 private_key.reset(util->FindPrivateKey(*public_key)); | 119 private_key.reset(util->FindPrivateKeyInSlot(*public_key, slot)); |
| 113 if (!private_key.get()) | 120 if (!private_key.get()) |
| 114 VLOG(1) << "Failed to load private owner key."; | 121 VLOG(1) << "Failed to load private owner key."; |
| 115 } | 122 } |
| 116 | 123 |
| 117 return new OwnerKey(public_key.Pass(), private_key.Pass()); | 124 return new OwnerKey(public_key.Pass(), private_key.Pass()); |
| 118 } | 125 } |
| 119 | 126 |
| 120 void SessionManagerOperation::StoreOwnerKey(const base::Closure& callback, | 127 void SessionManagerOperation::StoreOwnerKey(const base::Closure& callback, |
| 121 scoped_refptr<OwnerKey> new_key) { | 128 scoped_refptr<OwnerKey> new_key) { |
| 122 force_key_load_ = false; | 129 force_key_load_ = false; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 } | 329 } |
| 323 | 330 |
| 324 void SignAndStoreSettingsOperation::HandleStoreResult(bool success) { | 331 void SignAndStoreSettingsOperation::HandleStoreResult(bool success) { |
| 325 if (!success) | 332 if (!success) |
| 326 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED); | 333 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED); |
| 327 else | 334 else |
| 328 StartLoading(); | 335 StartLoading(); |
| 329 } | 336 } |
| 330 | 337 |
| 331 } // namespace chromeos | 338 } // namespace chromeos |
| OLD | NEW |