Replace deprecated security-manager api
[platform/core/appfw/app-installers.git] / src / common / step / security / step_recover_security.cc
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.
4
5 #include "common/step/security/step_recover_security.h"
6
7 #include <boost/filesystem.hpp>
8 #include <string>
9
10 #include "common/security_registration.h"
11
12 namespace common_installer {
13 namespace security {
14
15 bool StepRecoverSecurity::Check() {
16   if (context_->pkg_path.get().empty())
17     return false;
18   if (!boost::filesystem::exists(context_->pkg_path.get()))
19     return false;
20   if (context_->pkgid.get().empty())
21     return false;
22   if (!context_->manifest_data.get())
23     return false;
24   return true;
25 }
26
27 Step::Status StepRecoverSecurity::RecoveryNew() {
28   if (!Check())
29     return Status::OK;
30   std::string error_message;
31   if (!UnregisterSecurityContextForManifest(
32       context_->pkgid.get(), context_->uid.get(),
33       context_->manifest_data.get(), &error_message)) {
34     LOG(ERROR) << "Unsuccessful install";
35     if (!error_message.empty()) {
36       LOG(ERROR) << "error_message: " << error_message;
37       on_error(Status::RECOVERY_ERROR, error_message);
38     }
39     return Status::RECOVERY_ERROR;
40   }
41   return Status::OK;
42 }
43
44 Step::Status StepRecoverSecurity::RecoveryUpdate() {
45   if (!Check()) {
46     LOG(ERROR) << "Invalid parameters";
47     return Status::INVALID_VALUE;
48   }
49   std::string error_message;
50   if (!RegisterSecurityContextForManifest(
51       context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(),
52       &context_->certificate_info.get(), context_->manifest_data.get(),
53       &error_message)) {
54     LOG(ERROR) << "Unsuccessful update";
55     if (!error_message.empty()) {
56       LOG(ERROR) << "error_message: " << error_message;
57       on_error(Status::RECOVERY_ERROR, error_message);
58     }
59     return Status::RECOVERY_ERROR;
60   }
61   if (!RegisterSecurityContextForPath(
62       context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(),
63       &error_message)) {
64     if (!error_message.empty()) {
65       LOG(ERROR) << "error_message: " << error_message;
66       on_error(Status::SECURITY_ERROR, error_message);
67     }
68     return Status::RECOVERY_ERROR;
69   }
70   return Status::OK;
71 }
72 }  // namespace security
73 }  // namespace common_installer