[Recovery] StepRecoverSecurity 16/45716/3
authorWojciech Kosowicz <w.kosowicz@samsung.com>
Tue, 4 Aug 2015 09:10:04 +0000 (11:10 +0200)
committerPawel Sikorski <p.sikorski@samsung.com>
Tue, 11 Aug 2015 09:38:34 +0000 (11:38 +0200)
Change-Id: Ibeed82bcafdbe9916a3593cf5e0795a3672d9cf2

src/common/CMakeLists.txt
src/common/step/step_recover_security.cc [new file with mode: 0644]
src/common/step/step_recover_security.h [new file with mode: 0644]

index e9c876a..8ea7bed 100644 (file)
@@ -23,6 +23,7 @@ SET(SRCS
   step/step_recover_files.cc
   step/step_recover_icons.cc
   step/step_recover_manifest.cc
+  step/step_recover_security.cc
   step/step_recover_storage_directories.cc
   step/step_recovery.cc
   step/step_register_app.cc
diff --git a/src/common/step/step_recover_security.cc b/src/common/step/step_recover_security.cc
new file mode 100644 (file)
index 0000000..4c53fff
--- /dev/null
@@ -0,0 +1,48 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/step/step_recover_security.h"
+
+#include <boost/filesystem.hpp>
+
+#include "common/security_registration.h"
+
+namespace common_installer {
+namespace security {
+
+bool StepRecoverSecurity::Check() {
+  if (context_->pkg_path.get().empty())
+    return false;
+  if (!boost::filesystem::exists(context_->pkg_path.get()))
+    return false;
+  if (context_->pkgid.get().empty())
+    return false;
+  if (!context_->manifest_data.get())
+    return false;
+  return true;
+}
+
+Step::Status StepRecoverSecurity::RecoveryNew() {
+  if (!Check())
+    return Status::OK;
+  UnregisterSecurityContextForApps(
+        context_->pkgid.get(), context_->manifest_data.get());
+  return Status::OK;
+}
+
+Step::Status StepRecoverSecurity::RecoveryUpdate() {
+  if (!Check()) {
+    LOG(ERROR) << "Invalid parameters";
+    return Status::ERROR;
+  }
+  if (!RegisterSecurityContextForApps(
+      context_->pkgid.get(), context_->pkg_path.get(),
+      context_->manifest_data.get())) {
+    LOG(ERROR) << "Unsuccessful update";
+    return Status::ERROR;
+  }
+  return Status::OK;
+}
+}  // namespace security
+}  // namespace common_installer
diff --git a/src/common/step/step_recover_security.h b/src/common/step/step_recover_security.h
new file mode 100644 (file)
index 0000000..5090d72
--- /dev/null
@@ -0,0 +1,40 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_STEP_STEP_RECOVER_SECURITY_H_
+#define COMMON_STEP_STEP_RECOVER_SECURITY_H_
+
+#include "common/context_installer.h"
+#include "common/step/step_recovery.h"
+#include "common/utils/logging.h"
+
+namespace common_installer {
+namespace security {
+
+/**
+ * @brief responsible for restoring security
+ *        rules
+ *
+ * Part of Recovery Mode. In case of partial
+ * installation security rules get unregistered
+ * In case of unsuccessful partial update
+ * security rules for the app before update
+ * gets restored
+ */
+class StepRecoverSecurity : public recovery::StepRecovery {
+ public:
+  using StepRecovery::StepRecovery;
+
+  Status RecoveryNew() override;
+  Status RecoveryUpdate() override;
+ private:
+  bool Check();
+
+  SCOPE_LOG_TAG(RecoverSecurity)
+};
+
+}  // namespace security
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_STEP_RECOVER_SECURITY_H_