24847f613ebe1104ad9636e1fa10508185860c0c
[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 <boost/iostreams/stream.hpp>
11 #include <boost/iostreams/device/file_descriptor.hpp>
12
13 #include <string>
14
15 #include "common/installer_context.h"
16
17 namespace bf = boost::filesystem;
18 namespace bi = boost::iostreams;
19
20 namespace common_installer {
21
22 class Signature {
23  public:
24   Signature(RequestType request_type, std::string pkgid,
25             bool is_readonly_package, bool skip_check_reference,
26             CertificateInfo* cert_info) :
27             request_type_(request_type), pkgid_(pkgid),
28             is_readonly_package_(is_readonly_package),
29             skip_check_reference_(skip_check_reference),
30             cert_info_(cert_info) {}
31   virtual ~Signature() = default;
32
33   virtual bool CheckSignatures(bool check_reference, PrivilegeLevel* level,
34                                boost::filesystem::path sig_root_path,
35                                std::string* error_message);
36   bool GetPrivilegeLevel(boost::filesystem::path sig_root_path,
37                         PrivilegeLevel* level,
38                         std::string* error_message);
39   bool CheckMetadataPrivilege(PrivilegeLevel level, manifest_x* manifest,
40                              std::string* error_message);
41   bool CheckSignatureMismatch(std::string* error_message);
42   bool SetPath();
43   bool StoreSignature(bi::stream<bi::file_descriptor_sink> *ofs,
44       const ValidationCore::CertificatePtr& cert,
45       const ValidationCore::CertificatePtr& im_cert,
46       const ValidationCore::CertificatePtr& root_cert);
47   bool Store();
48   bool RemoveSignature(const bf::path& path);
49   bool SaveSignature(const bf::path& path);
50   const bf::path& GetFilePath() const;
51   const bf::path& GetBackupPath() const;
52
53  protected:
54   RequestType request_type_;
55   std::string pkgid_;
56   bool is_readonly_package_;
57   bool skip_check_reference_;
58   CertificateInfo* cert_info_;
59   bf::path file_path_;
60   bf::path backup_path_;
61 };
62
63 }  // namespace common_installer
64
65 #endif  // COMMON_SIGNATURE_H_