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

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

Issue 2727863004: Revert of Fix handling of device cloud signing policy key rotation (Closed)
Patch Set: 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"
10 #include "base/location.h" 8 #include "base/location.h"
11 #include "base/numerics/safe_conversions.h"
12 #include "base/path_service.h"
13 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
14 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
15 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
16 #include "chromeos/chromeos_paths.h"
17 #include "chromeos/dbus/cryptohome_client.h" 12 #include "chromeos/dbus/cryptohome_client.h"
18 #include "components/policy/proto/device_management_backend.pb.h"
19 13
20 namespace chromeos { 14 namespace chromeos {
21 15
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
46 FakeSessionManagerClient::FakeSessionManagerClient() 16 FakeSessionManagerClient::FakeSessionManagerClient()
47 : start_device_wipe_call_count_(0), 17 : start_device_wipe_call_count_(0),
48 request_lock_screen_call_count_(0), 18 request_lock_screen_call_count_(0),
49 notify_lock_screen_shown_call_count_(0), 19 notify_lock_screen_shown_call_count_(0),
50 notify_lock_screen_dismissed_call_count_(0), 20 notify_lock_screen_dismissed_call_count_(0),
51 arc_available_(false) {} 21 arc_available_(false) {}
52 22
53 FakeSessionManagerClient::~FakeSessionManagerClient() { 23 FakeSessionManagerClient::~FakeSessionManagerClient() {
54 } 24 }
55 25
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 const std::string& account_id, 114 const std::string& account_id,
145 const RetrievePolicyCallback& callback) { 115 const RetrievePolicyCallback& callback) {
146 base::ThreadTaskRunnerHandle::Get()->PostTask( 116 base::ThreadTaskRunnerHandle::Get()->PostTask(
147 FROM_HERE, 117 FROM_HERE,
148 base::Bind(callback, device_local_account_policy_[account_id])); 118 base::Bind(callback, device_local_account_policy_[account_id]));
149 } 119 }
150 120
151 void FakeSessionManagerClient::StoreDevicePolicy( 121 void FakeSessionManagerClient::StoreDevicePolicy(
152 const std::string& policy_blob, 122 const std::string& policy_blob,
153 const StorePolicyCallback& callback) { 123 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());
165 device_policy_ = policy_blob; 124 device_policy_ = policy_blob;
166 125 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
167 base::ThreadTaskRunnerHandle::Get()->PostTask( 126 base::Bind(callback, true));
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 }
173 for (auto& observer : observers_) 127 for (auto& observer : observers_)
174 observer.PropertyChangeComplete(true /* success */); 128 observer.PropertyChangeComplete(true);
175 } 129 }
176 130
177 void FakeSessionManagerClient::StorePolicyForUser( 131 void FakeSessionManagerClient::StorePolicyForUser(
178 const cryptohome::Identification& cryptohome_id, 132 const cryptohome::Identification& cryptohome_id,
179 const std::string& policy_blob, 133 const std::string& policy_blob,
180 const StorePolicyCallback& callback) { 134 const StorePolicyCallback& callback) {
181 user_policies_[cryptohome_id] = policy_blob; 135 user_policies_[cryptohome_id] = policy_blob;
182 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 136 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
183 base::Bind(callback, true)); 137 base::Bind(callback, true));
184 } 138 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 const std::string& policy_blob) { 246 const std::string& policy_blob) {
293 device_local_account_policy_[account_id] = policy_blob; 247 device_local_account_policy_[account_id] = policy_blob;
294 } 248 }
295 249
296 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success) { 250 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success) {
297 for (auto& observer : observers_) 251 for (auto& observer : observers_)
298 observer.PropertyChangeComplete(success); 252 observer.PropertyChangeComplete(success);
299 } 253 }
300 254
301 } // namespace chromeos 255 } // 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