Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chromeos/dbus/fake_session_manager_client.cc

Issue 2558543003: Fix handling of device cloud signing policy key rotation (Closed)
Patch Set: Comment update Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromeos/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/dbus/fake_session_manager_client.h" 5 #include "chromeos/dbus/fake_session_manager_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h"
8 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/numerics/safe_conversions.h"
12 #include "base/path_service.h"
9 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
10 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
11 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "chromeos/chromeos_paths.h"
12 #include "chromeos/dbus/cryptohome_client.h" 17 #include "chromeos/dbus/cryptohome_client.h"
18 #include "components/policy/proto/device_management_backend.pb.h"
13 19
14 namespace chromeos { 20 namespace chromeos {
15 21
22 namespace {
23
24 // Store the owner key in a file on the disk, so that it can be loaded by
25 // DeviceSettingsService and used e.g. for validating policy signatures in the
26 // integration tests. This is done on behalf of the real session manager, that
27 // would be managing the owner key file on Chrome OS.
28 bool StoreOwnerKey(const std::string& public_key) {
29 base::FilePath owner_key_path;
30 DCHECK(base::PathService::Get(FILE_OWNER_KEY, &owner_key_path));
31 if (!base::CreateDirectory(owner_key_path.DirName())) {
32 LOG(ERROR) << "Failed to create the directory for the owner key file";
33 return false;
34 }
35 if (base::WriteFile(owner_key_path, public_key.c_str(),
36 public_key.length()) !=
37 base::checked_cast<int>(public_key.length())) {
38 LOG(ERROR) << "Failed to store the owner key file";
39 return false;
40 }
41 return true;
42 }
43
44 } // namespace
45
16 FakeSessionManagerClient::FakeSessionManagerClient() 46 FakeSessionManagerClient::FakeSessionManagerClient()
17 : start_device_wipe_call_count_(0), 47 : start_device_wipe_call_count_(0),
18 request_lock_screen_call_count_(0), 48 request_lock_screen_call_count_(0),
19 notify_lock_screen_shown_call_count_(0), 49 notify_lock_screen_shown_call_count_(0),
20 notify_lock_screen_dismissed_call_count_(0), 50 notify_lock_screen_dismissed_call_count_(0),
21 arc_available_(false) {} 51 arc_available_(false) {}
22 52
23 FakeSessionManagerClient::~FakeSessionManagerClient() { 53 FakeSessionManagerClient::~FakeSessionManagerClient() {
24 } 54 }
25 55
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 const std::string& account_id, 144 const std::string& account_id,
115 const RetrievePolicyCallback& callback) { 145 const RetrievePolicyCallback& callback) {
116 base::ThreadTaskRunnerHandle::Get()->PostTask( 146 base::ThreadTaskRunnerHandle::Get()->PostTask(
117 FROM_HERE, 147 FROM_HERE,
118 base::Bind(callback, device_local_account_policy_[account_id])); 148 base::Bind(callback, device_local_account_policy_[account_id]));
119 } 149 }
120 150
121 void FakeSessionManagerClient::StoreDevicePolicy( 151 void FakeSessionManagerClient::StoreDevicePolicy(
122 const std::string& policy_blob, 152 const std::string& policy_blob,
123 const StorePolicyCallback& callback) { 153 const StorePolicyCallback& callback) {
154 enterprise_management::PolicyFetchResponse policy;
155 if (!policy.ParseFromString(policy_blob)) {
156 LOG(ERROR) << "Unable to parse policy protobuf";
157 base::ThreadTaskRunnerHandle::Get()->PostTask(
158 FROM_HERE, base::Bind(callback, false /* success */));
159 return;
160 }
161
162 bool owner_key_store_success = false;
163 if (policy.has_new_public_key())
164 owner_key_store_success = StoreOwnerKey(policy.new_public_key());
124 device_policy_ = policy_blob; 165 device_policy_ = policy_blob;
125 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 166
126 base::Bind(callback, true)); 167 base::ThreadTaskRunnerHandle::Get()->PostTask(
168 FROM_HERE, base::Bind(callback, true /* success */));
169 if (policy.has_new_public_key()) {
170 for (auto& observer : observers_)
171 observer.OwnerKeySet(owner_key_store_success);
172 }
127 for (auto& observer : observers_) 173 for (auto& observer : observers_)
128 observer.PropertyChangeComplete(true); 174 observer.PropertyChangeComplete(true /* success */);
129 } 175 }
130 176
131 void FakeSessionManagerClient::StorePolicyForUser( 177 void FakeSessionManagerClient::StorePolicyForUser(
132 const cryptohome::Identification& cryptohome_id, 178 const cryptohome::Identification& cryptohome_id,
133 const std::string& policy_blob, 179 const std::string& policy_blob,
134 const StorePolicyCallback& callback) { 180 const StorePolicyCallback& callback) {
135 user_policies_[cryptohome_id] = policy_blob; 181 user_policies_[cryptohome_id] = policy_blob;
136 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 182 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
137 base::Bind(callback, true)); 183 base::Bind(callback, true));
138 } 184 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 const std::string& policy_blob) { 292 const std::string& policy_blob) {
247 device_local_account_policy_[account_id] = policy_blob; 293 device_local_account_policy_[account_id] = policy_blob;
248 } 294 }
249 295
250 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success) { 296 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success) {
251 for (auto& observer : observers_) 297 for (auto& observer : observers_)
252 observer.PropertyChangeComplete(success); 298 observer.PropertyChangeComplete(success);
253 } 299 }
254 300
255 } // namespace chromeos 301 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698