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