Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
initializer.h
1 #ifndef INITIALIZER_H_
2 #define INITIALIZER_H_
3 
4 #include "config/config.h"
5 #include "crypto/keymanager.h"
6 #include "http/httpinterface.h"
7 #include "storage/invstorage.h"
8 #include "uptane/secondaryinterface.h"
9 
10 const int MaxInitializationAttempts = 3;
11 
12 class Initializer {
13  public:
14  Initializer(const ProvisionConfig& config_in, std::shared_ptr<INvStorage> storage_in,
15  std::shared_ptr<HttpInterface> http_client_in, KeyManager& keys_in,
16  const std::map<Uptane::EcuSerial, std::shared_ptr<Uptane::SecondaryInterface> >& secondaries_in);
17 
18  class Error : public std::runtime_error {
19  public:
20  Error(const std::string& what) : std::runtime_error(std::string("Initializer error: ") + what) {}
21  };
22  class KeyGenerationError : public Error {
23  public:
24  KeyGenerationError(const std::string& what) : Error(std::string("Could not generate uptane key pair: ") + what) {}
25  };
26  class StorageError : public Error {
27  public:
28  StorageError(const std::string& what) : Error(std::string("Storage error: ") + what) {}
29  };
30  class ServerError : public Error {
31  public:
32  ServerError(const std::string& what) : Error(std::string("Server error: ") + what) {}
33  };
34  class ServerOccupied : public Error {
35  public:
36  ServerOccupied() : Error("") {}
37  };
38 
39  private:
40  const ProvisionConfig& config_;
41  std::shared_ptr<INvStorage> storage_;
42  std::shared_ptr<HttpInterface> http_client_;
43  KeyManager& keys_;
44  const std::map<Uptane::EcuSerial, Uptane::SecondaryInterface::Ptr>& secondaries_;
45  std::vector<SecondaryInfo> sec_info_;
46 
47  void initDeviceId();
48  void resetDeviceId();
49  void initEcuSerials();
50  void resetEcuSerials();
51  void initPrimaryEcuKeys();
52  void resetEcuKeys();
53  void initTlsCreds();
54  void resetTlsCreds();
55  void initSecondaryInfo();
56  void initEcuRegister();
57  bool loadSetTlsCreds();
58  void initEcuReportCounter();
59 };
60 
61 #endif // INITIALIZER_H_