Aktualizr
C++ SOTA Client
keymanager.h
1 #ifndef KEYMANAGER_H_
2 #define KEYMANAGER_H_
3 
4 #include "libaktualizr/config.h"
5 
6 #include "crypto.h"
7 #include "http/httpinterface.h"
8 #include "p11engine.h"
9 #include "utilities/utils.h"
10 
11 class INvStorage;
12 
13 class KeyManager {
14  public:
15  // std::string RSAPSSSign(const std::string &message);
16  // Contains the logic from HttpClient::setCerts()
17  void copyCertsToCurl(HttpInterface &http) const;
18  KeyManager(std::shared_ptr<INvStorage> backend, KeyManagerConfig config);
19  void loadKeys(const std::string *pkey_content = nullptr, const std::string *cert_content = nullptr,
20  const std::string *ca_content = nullptr);
21  std::string getPkeyFile() const;
22  std::string getCertFile() const;
23  std::string getCaFile() const;
24  std::string getPkey() const;
25  std::string getCert() const;
26  std::string getCa() const;
27  std::string getCN() const;
28  void getCertInfo(std::string *subject, std::string *issuer, std::string *not_before, std::string *not_after) const;
29  bool isOk() const { return ((getPkey().size() != 0U) && (getCert().size() != 0U) && (getCa().size() != 0U)); }
30  std::string generateUptaneKeyPair();
31  KeyType getUptaneKeyType() const { return config_.uptane_key_type; }
32  Json::Value signTuf(const Json::Value &in_data) const;
33 
34  PublicKey UptanePublicKey() const;
35 
36  private:
37  std::shared_ptr<INvStorage> backend_;
38  const KeyManagerConfig config_;
39  std::unique_ptr<P11EngineGuard> p11_;
40  std::unique_ptr<TemporaryFile> tmp_pkey_file;
41  std::unique_ptr<TemporaryFile> tmp_cert_file;
42  std::unique_ptr<TemporaryFile> tmp_ca_file;
43 };
44 
45 #endif // KEYMANAGER_H_
KeyManager
Definition: keymanager.h:13
HttpInterface
Definition: httpinterface.h:38
PublicKey
Definition: types.h:119
KeyManagerConfig
Definition: config.h:168
INvStorage
Definition: invstorage.h:43