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

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

Issue 2737483006: Reland 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"
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 if (!base::PathService::Get(FILE_OWNER_KEY, &owner_key_path)) {
31 LOG(ERROR) << "Failed to obtain the path to the owner key file";
32 return false;
33 }
34 if (!base::CreateDirectory(owner_key_path.DirName())) {
35 LOG(ERROR) << "Failed to create the directory for the owner key file";
36 return false;
37 }
38 if (base::WriteFile(owner_key_path, public_key.c_str(),
39 public_key.length()) !=
40 base::checked_cast<int>(public_key.length())) {
41 LOG(ERROR) << "Failed to store the owner key file";
42 return false;
43 }
44 return true;
45 }
46
47 } // namespace
48
16 FakeSessionManagerClient::FakeSessionManagerClient() 49 FakeSessionManagerClient::FakeSessionManagerClient()
17 : start_device_wipe_call_count_(0), 50 : start_device_wipe_call_count_(0),
18 request_lock_screen_call_count_(0), 51 request_lock_screen_call_count_(0),
19 notify_lock_screen_shown_call_count_(0), 52 notify_lock_screen_shown_call_count_(0),
20 notify_lock_screen_dismissed_call_count_(0), 53 notify_lock_screen_dismissed_call_count_(0),
21 arc_available_(false) {} 54 arc_available_(false) {}
22 55
23 FakeSessionManagerClient::~FakeSessionManagerClient() { 56 FakeSessionManagerClient::~FakeSessionManagerClient() {
24 } 57 }
25 58
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } 156 }
124 157
125 std::string FakeSessionManagerClient::BlockingRetrieveDeviceLocalAccountPolicy( 158 std::string FakeSessionManagerClient::BlockingRetrieveDeviceLocalAccountPolicy(
126 const std::string& account_id) { 159 const std::string& account_id) {
127 return device_local_account_policy_[account_id]; 160 return device_local_account_policy_[account_id];
128 } 161 }
129 162
130 void FakeSessionManagerClient::StoreDevicePolicy( 163 void FakeSessionManagerClient::StoreDevicePolicy(
131 const std::string& policy_blob, 164 const std::string& policy_blob,
132 const StorePolicyCallback& callback) { 165 const StorePolicyCallback& callback) {
166 enterprise_management::PolicyFetchResponse policy;
167 if (!policy.ParseFromString(policy_blob)) {
168 LOG(ERROR) << "Unable to parse policy protobuf";
169 base::ThreadTaskRunnerHandle::Get()->PostTask(
170 FROM_HERE, base::Bind(callback, false /* success */));
171 return;
172 }
173
174 bool owner_key_store_success = false;
175 if (policy.has_new_public_key())
176 owner_key_store_success = StoreOwnerKey(policy.new_public_key());
133 device_policy_ = policy_blob; 177 device_policy_ = policy_blob;
134 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 178
135 base::Bind(callback, true)); 179 base::ThreadTaskRunnerHandle::Get()->PostTask(
180 FROM_HERE, base::Bind(callback, true /* success */));
181 if (policy.has_new_public_key()) {
182 for (auto& observer : observers_)
183 observer.OwnerKeySet(owner_key_store_success);
184 }
136 for (auto& observer : observers_) 185 for (auto& observer : observers_)
137 observer.PropertyChangeComplete(true); 186 observer.PropertyChangeComplete(true /* success */);
138 } 187 }
139 188
140 void FakeSessionManagerClient::StorePolicyForUser( 189 void FakeSessionManagerClient::StorePolicyForUser(
141 const cryptohome::Identification& cryptohome_id, 190 const cryptohome::Identification& cryptohome_id,
142 const std::string& policy_blob, 191 const std::string& policy_blob,
143 const StorePolicyCallback& callback) { 192 const StorePolicyCallback& callback) {
144 user_policies_[cryptohome_id] = policy_blob; 193 user_policies_[cryptohome_id] = policy_blob;
145 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 194 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
146 base::Bind(callback, true)); 195 base::Bind(callback, true));
147 } 196 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 const std::string& policy_blob) { 304 const std::string& policy_blob) {
256 device_local_account_policy_[account_id] = policy_blob; 305 device_local_account_policy_[account_id] = policy_blob;
257 } 306 }
258 307
259 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success) { 308 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success) {
260 for (auto& observer : observers_) 309 for (auto& observer : observers_)
261 observer.PropertyChangeComplete(success); 310 observer.PropertyChangeComplete(success);
262 } 311 }
263 312
264 } // namespace chromeos 313 } // 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