6c8357a83286cb2bc18c49a207a3ffe634ab684c
[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
32   virtual bool CheckSignatures(bool check_reference, PrivilegeLevel* level,
33                                boost::filesystem::path sig_root_path,
34                                std::string* error_message);
35   bool GetPrivilegeLevel(boost::filesystem::path sig_root_path,
36                         PrivilegeLevel* level,
37                         std::string* error_message);
38   bool CheckMetadataPrivilege(PrivilegeLevel level, manifest_x* manifest,
39                              std::string* error_message);
40   bool CheckSignatureMismatch(std::string* error_message);
41   bool SetPath();
42   bool StoreSignature(bi::stream<bi::file_descriptor_sink> *ofs,
43       const ValidationCore::CertificatePtr& cert,
44       const ValidationCore::CertificatePtr& im_cert,
45       const ValidationCore::CertificatePtr& root_cert);
46   bool Store();
47   bool RemoveSignature(const bf::path& path);
48   bool SaveSignature(const bf::path& path);
49   const bf::path& GetFilePath() const;
50   const bf::path& GetBackupPath() const;
51
52  protected:
53   RequestType request_type_;
54   std::string pkgid_;
55   bool is_readonly_package_;
56   bool skip_check_reference_;
57   CertificateInfo* cert_info_;
58   bf::path file_path_;
59   bf::path backup_path_;
60 };
61
62 }  // namespace common_installer
63
64 #endif  // COMMON_SIGNATURE_H_