Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / step / security / step_unregister_trust_anchor.cc
1 // Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by a apache 2.0 license that can be
3 // found in the LICENSE file.
4
5 #include "common/step/security/step_unregister_trust_anchor.h"
6
7 #include <trust-anchor.h>
8
9 #include <filesystem>
10 #include <string>
11
12 namespace common_installer {
13 namespace security {
14
15 namespace fs = std::filesystem;
16
17 const char kTpkTrustAnchorPath[] = "res/.trust-anchor";
18
19 Step::Status StepUnregisterTrustAnchor::precheck() {
20   if (!context_->manifest_data.get()) {
21     LOG(ERROR) << "manifest_data attribute is empty";
22     return Step::Status::INVALID_VALUE;
23   }
24
25   return Step::Status::OK;
26 }
27
28 Step::Status StepUnregisterTrustAnchor::process() {
29   manifest_x* manifest = context_->manifest_data.get();
30
31   if (!manifest->use_system_certs)
32     return Step::Status::OK;
33
34   int ret = trust_anchor_uninstall(context_->pkgid.get().c_str(),
35       context_->uid.get());
36   if (ret != TRUST_ANCHOR_ERROR_NONE) {
37     LOG(ERROR) << "Failed to unregister trust anchor. error : " << ret;
38     return Step::Status::SECURITY_ERROR;
39   }
40
41   return Step::Status::OK;
42 }
43
44 Step::Status StepUnregisterTrustAnchor::undo() {
45   manifest_x* manifest = context_->manifest_data.get();
46
47   if (!manifest->use_system_certs)
48     return Step::Status::OK;
49
50   fs::path pkg_certs_path = context_->GetPkgPath() / kTpkTrustAnchorPath;
51   int ret = trust_anchor_install(context_->pkgid.get().c_str(),
52       context_->uid.get(), pkg_certs_path.c_str(),
53       (strcasecmp(manifest->use_system_certs, "true") == 0) ? true : false);
54
55   if (ret != TRUST_ANCHOR_ERROR_NONE) {
56     LOG(ERROR) << "Failed to register trust anchor. error : " << ret;
57     return Step::Status::SECURITY_ERROR;
58   }
59
60   return Step::Status::OK;
61 }
62
63 }  // namespace security
64 }  // namespace common_installer