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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/dbus/fake_session_manager_client.cc
diff --git a/chromeos/dbus/fake_session_manager_client.cc b/chromeos/dbus/fake_session_manager_client.cc
index d0355fc326df9333cf6da6a3a81bd1f4998777d2..53f5796727e42fda19156a3832e5c3c05da10297 100644
--- a/chromeos/dbus/fake_session_manager_client.cc
+++ b/chromeos/dbus/fake_session_manager_client.cc
@@ -5,14 +5,47 @@
#include "chromeos/dbus/fake_session_manager_client.h"
#include "base/bind.h"
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
#include "base/location.h"
+#include "base/numerics/safe_conversions.h"
+#include "base/path_service.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_util.h"
#include "base/threading/thread_task_runner_handle.h"
+#include "chromeos/chromeos_paths.h"
#include "chromeos/dbus/cryptohome_client.h"
+#include "components/policy/proto/device_management_backend.pb.h"
namespace chromeos {
+namespace {
+
+// Store the owner key in a file on the disk, so that it can be loaded by
+// DeviceSettingsService and used e.g. for validating policy signatures in the
+// integration tests. This is done on behalf of the real session manager, that
+// would be managing the owner key file on Chrome OS.
+bool StoreOwnerKey(const std::string& public_key) {
+ base::FilePath owner_key_path;
+ if (!base::PathService::Get(FILE_OWNER_KEY, &owner_key_path)) {
+ LOG(ERROR) << "Failed to obtain the path to the owner key file";
+ return false;
+ }
+ if (!base::CreateDirectory(owner_key_path.DirName())) {
+ LOG(ERROR) << "Failed to create the directory for the owner key file";
+ return false;
+ }
+ if (base::WriteFile(owner_key_path, public_key.c_str(),
+ public_key.length()) !=
+ base::checked_cast<int>(public_key.length())) {
+ LOG(ERROR) << "Failed to store the owner key file";
+ return false;
+ }
+ return true;
+}
+
+} // namespace
+
FakeSessionManagerClient::FakeSessionManagerClient()
: start_device_wipe_call_count_(0),
request_lock_screen_call_count_(0),
@@ -130,11 +163,27 @@ std::string FakeSessionManagerClient::BlockingRetrieveDeviceLocalAccountPolicy(
void FakeSessionManagerClient::StoreDevicePolicy(
const std::string& policy_blob,
const StorePolicyCallback& callback) {
+ enterprise_management::PolicyFetchResponse policy;
+ if (!policy.ParseFromString(policy_blob)) {
+ LOG(ERROR) << "Unable to parse policy protobuf";
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(callback, false /* success */));
+ return;
+ }
+
+ bool owner_key_store_success = false;
+ if (policy.has_new_public_key())
+ owner_key_store_success = StoreOwnerKey(policy.new_public_key());
device_policy_ = policy_blob;
- base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
- base::Bind(callback, true));
+
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(callback, true /* success */));
+ if (policy.has_new_public_key()) {
+ for (auto& observer : observers_)
+ observer.OwnerKeySet(owner_key_store_success);
+ }
for (auto& observer : observers_)
- observer.PropertyChangeComplete(true);
+ observer.PropertyChangeComplete(true /* success */);
}
void FakeSessionManagerClient::StorePolicyForUser(
« 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