1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
5 #include "common/step/security/step_recover_security.h"
7 #include <boost/filesystem.hpp>
10 #include "common/security_registration.h"
12 namespace common_installer {
15 bool StepRecoverSecurity::Check(bool is_update) {
16 if (context_->GetPkgPath().empty())
18 if (!boost::filesystem::exists(context_->GetPkgPath()) && is_update)
20 if (context_->pkgid.get().empty())
25 Step::Status StepRecoverSecurity::RecoveryNew() {
28 recovery::RecoveryFile* recovery_file =
29 context_->recovery_info.get().recovery_file.get();
30 if (!recovery_file->security_operation_done()) {
31 LOG(DEBUG) << "security_operation_done false skip recover security";
34 std::string error_message;
35 if (!context_->manifest_data.get()) {
36 if (!UnregisterSecurityContextForPkgId(context_->pkgid.get(),
37 context_->pkg_type.get(), context_->uid.get(), &error_message, true)) {
38 LOG(ERROR) << "Unsuccessful install";
39 if (!error_message.empty()) {
40 LOG(ERROR) << "error_message: " << error_message;
41 on_error(Status::RECOVERY_ERROR, error_message);
43 return Status::RECOVERY_ERROR;
45 } else if (!UnregisterSecurityContextForManifest(
46 context_->pkgid.get(), context_->pkg_type.get(), context_->uid.get(),
47 context_->manifest_data.get(), &error_message)) {
48 LOG(ERROR) << "Unsuccessful install";
49 if (!error_message.empty()) {
50 LOG(ERROR) << "error_message: " << error_message;
51 on_error(Status::RECOVERY_ERROR, error_message);
53 return Status::RECOVERY_ERROR;
58 Step::Status StepRecoverSecurity::RecoveryUpdate() {
60 LOG(ERROR) << "Invalid parameters";
61 return Status::INVALID_VALUE;
63 recovery::RecoveryFile* recovery_file =
64 context_->recovery_info.get().recovery_file.get();
65 if (!recovery_file->security_operation_done()) {
66 LOG(DEBUG) << "security_operation_done false skip recover security";
69 std::string error_message;
70 if (!RegisterSecurityContextForManifest(context_, &error_message)) {
71 LOG(ERROR) << "Unsuccessful update";
72 if (!error_message.empty()) {
73 LOG(ERROR) << "error_message: " << error_message;
74 on_error(Status::RECOVERY_ERROR, error_message);
76 return Status::RECOVERY_ERROR;
78 if (!RegisterSecurityContextForPath(
79 context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
80 context_->is_readonly_package.get(), &error_message)) {
81 if (!error_message.empty()) {
82 LOG(ERROR) << "error_message: " << error_message;
83 on_error(Status::RECOVERY_ERROR, error_message);
85 return Status::RECOVERY_ERROR;
90 Step::Status StepRecoverSecurity::RecoveryReadonlyUpdateInstall() {
92 LOG(ERROR) << "Invalid parameters";
93 return Status::INVALID_VALUE;
95 recovery::RecoveryFile* recovery_file =
96 context_->recovery_info.get().recovery_file.get();
97 if (!recovery_file->security_operation_done()) {
98 LOG(DEBUG) << "security_operation_done false skip recover security";
101 std::string error_message;
102 if (!RegisterSecurityContextForManifest(context_, &error_message)) {
103 LOG(ERROR) << "Unsuccessful update";
104 if (!error_message.empty()) {
105 LOG(ERROR) << "error_message: " << error_message;
106 on_error(Status::RECOVERY_ERROR, error_message);
108 return Status::RECOVERY_ERROR;
113 } // namespace security
114 } // namespace common_installer