Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / signature.h
1 // Copyright (c) 2019 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 #ifndef COMMON_SIGNATURE_H_
6 #define COMMON_SIGNATURE_H_
7
8 #include <pkgmgrinfo_basic.h>
9
10 #include <filesystem>
11 #include <string>
12
13 #include "common/installer_context.h"
14
15 namespace fs = std::filesystem;
16
17 namespace common_installer {
18
19 class Signature {
20  public:
21   Signature(RequestType request_type, std::string pkgid,
22             bool is_readonly_package, bool skip_check_reference,
23             CertificateInfo* cert_info) :
24             request_type_(request_type), pkgid_(pkgid),
25             is_readonly_package_(is_readonly_package),
26             skip_check_reference_(skip_check_reference),
27             cert_info_(cert_info) {}
28   virtual ~Signature() = default;
29
30   virtual bool CheckSignatures(bool check_reference, PrivilegeLevel* level,
31                                std::filesystem::path sig_root_path,
32                                std::string* error_message);
33   bool GetPrivilegeLevel(std::filesystem::path sig_root_path,
34                         PrivilegeLevel* level,
35                         std::string* error_message);
36   bool CheckMetadataPrivilege(PrivilegeLevel level, manifest_x* manifest,
37                              std::string* error_message);
38   bool CheckSignatureMismatch(std::string* error_message);
39   bool SetPath();
40   bool StoreSignature(std::ofstream* ofs,
41       const ValidationCore::CertificatePtr& cert,
42       const ValidationCore::CertificatePtr& im_cert,
43       const ValidationCore::CertificatePtr& root_cert);
44   bool Store();
45   bool RemoveSignature(const fs::path& path);
46   bool SaveSignature(const fs::path& path);
47   const fs::path& GetFilePath() const;
48   const fs::path& GetBackupPath() const;
49
50  protected:
51   RequestType request_type_;
52   std::string pkgid_;
53   bool is_readonly_package_;
54   bool skip_check_reference_;
55   CertificateInfo* cert_info_;
56   fs::path file_path_;
57   fs::path backup_path_;
58 };
59
60 }  // namespace common_installer
61
62 #endif  // COMMON_SIGNATURE_H_