Add exception handling to StepSignature
[platform/core/appfw/app-installers.git] / src / common / step / security / step_signature.cc
index d4ef988..3a63882 100644 (file)
@@ -11,6 +11,7 @@
 #include <string>
 
 #include "common/certificate_validation.h"
+#include "common/utils/file_util.h"
 
 namespace bf = boost::filesystem;
 namespace ci = common_installer;
@@ -93,15 +94,14 @@ Step::Status StepSignature::process() {
   PrivilegeLevel level = PrivilegeLevel::UNTRUSTED;
   std::string error_message;
   if (!signature_->GetPrivilegeLevel(GetSignatureRoot(),
-      &level, error_message)) {
+      &level, &error_message)) {
     on_error(Status::CERT_ERROR, error_message);
     return Status::CERT_ERROR;
   }
 
   if (level == PrivilegeLevel::UNTRUSTED) {
-    std::string error_message =
-        "Unsigned applications can not be installed";
-    on_error(Status::CERT_ERROR, error_message);
+    error_message = "Unsigned applications can not be installed";
+    on_error(Status::SIGNATURE_ERROR, error_message);
     return Status::SIGNATURE_ERROR;
   }
 
@@ -115,7 +115,7 @@ Step::Status StepSignature::process() {
     return status;
 
   if (!signature_->CheckMetadataPrivilege(level, context_->manifest_data.get(),
-                                          error_message)) {
+                                          &error_message)) {
     if (!error_message.empty()) {
       LOG(ERROR) << "error_message: " << error_message;
       on_error(Status::SIGNATURE_ERROR, error_message);
@@ -132,6 +132,9 @@ Step::Status StepSignature::process() {
 }
 
 Step::Status StepSignature::undo() {
+  if (signature_ == nullptr)
+    return Step::Status::OK;
+
   bf::remove(signature_->GetFilePath());
   if (bf::exists(signature_->GetBackupPath()))
     bf::rename(signature_->GetBackupPath(), signature_->GetFilePath());
@@ -140,8 +143,7 @@ Step::Status StepSignature::undo() {
 }
 
 Step::Status StepSignature::clean() {
-  if (bf::exists(signature_->GetBackupPath()))
-    bf::remove(signature_->GetBackupPath());
+  Remove(signature_->GetBackupPath());
 
   return Step::Status::OK;
 }