Aktualizr
C++ SOTA Client
ipuptanesecondary.h
1 #ifndef UPTANE_IPUPTANESECONDARY_H_
2 #define UPTANE_IPUPTANESECONDARY_H_
3 
4 #include "asn1/asn1_message.h"
5 #include "der_encoder.h"
6 #include "libaktualizr/secondaryinterface.h"
7 
8 namespace Uptane {
9 
11  public:
12  static SecondaryInterface::Ptr connectAndCreate(const std::string& address, unsigned short port);
13  static SecondaryInterface::Ptr create(const std::string& address, unsigned short port, int con_fd);
14 
15  static SecondaryInterface::Ptr connectAndCheck(const std::string& address, unsigned short port, EcuSerial serial,
16  HardwareIdentifier hw_id, PublicKey pub_key);
17 
18  explicit IpUptaneSecondary(const std::string& address, unsigned short port, EcuSerial serial,
19  HardwareIdentifier hw_id, PublicKey pub_key);
20 
21  std::string Type() const override { return "IP"; }
22  EcuSerial getSerial() const override { return serial_; };
23  Uptane::HardwareIdentifier getHwId() const override { return hw_id_; }
24  PublicKey getPublicKey() const override { return pub_key_; }
25 
26  void init(std::shared_ptr<SecondaryProvider> secondary_provider_in) override {
27  secondary_provider_ = std::move(secondary_provider_in);
28  }
29  data::InstallationResult putMetadata(const Target& target) override;
30  int32_t getRootVersion(bool /* director */) const override { return 0; }
31  // TODO(OTA-4552): Support multiple Root rotations.
32  data::InstallationResult putRoot(const std::string& /* root */, bool /* director */) override {
33  return data::InstallationResult(data::ResultCode::Numeric::kOk, "");
34  }
35  Manifest getManifest() const override;
36  bool ping() const override;
37  data::InstallationResult sendFirmware(const Uptane::Target& target) override;
38  data::InstallationResult install(const Uptane::Target& target) override;
39 
40  private:
41  const std::pair<std::string, uint16_t>& getAddr() const { return addr_; }
42  void getSecondaryVersion() const;
43  data::InstallationResult putMetadata_v1(const Uptane::MetaBundle& meta_bundle);
44  data::InstallationResult putMetadata_v2(const Uptane::MetaBundle& meta_bundle);
45  data::InstallationResult sendFirmware_v1(const Uptane::Target& target);
46  data::InstallationResult sendFirmware_v2(const Uptane::Target& target);
47  data::InstallationResult install_v1(const Uptane::Target& target);
48  data::InstallationResult install_v2(const Uptane::Target& target);
49  static void addMetadata(const Uptane::MetaBundle& meta_bundle, Uptane::RepositoryType repo, const Uptane::Role& role,
50  AKMetaCollection_t& collection);
51  data::InstallationResult invokeInstallOnSecondary(const Uptane::Target& target);
52  data::InstallationResult downloadOstreeRev(const Uptane::Target& target);
53  data::InstallationResult uploadFirmware(const Uptane::Target& target);
54  data::InstallationResult uploadFirmwareData(const uint8_t* data, size_t size);
55 
56  std::shared_ptr<SecondaryProvider> secondary_provider_;
57  std::pair<std::string, uint16_t> addr_;
58  const EcuSerial serial_;
59  const HardwareIdentifier hw_id_;
60  const PublicKey pub_key_;
61  mutable uint32_t protocol_version{0};
62 };
63 
64 } // namespace Uptane
65 
66 #endif // UPTANE_IPUPTANESECONDARY_H_
data::InstallationResult
Definition: types.h:277
data
General data structures.
Definition: types.h:217
Uptane::HardwareIdentifier
Definition: types.h:315
Uptane::RepositoryType
Definition: tuf.h:21
Uptane::EcuSerial
Definition: types.h:346
PublicKey
Definition: types.h:119
Uptane::IpUptaneSecondary
Definition: ipuptanesecondary.h:10
Uptane::Role
TUF Roles.
Definition: tuf.h:61
Uptane::Target
Definition: types.h:379
Uptane
Base data types that are used in The Update Framework (TUF), part of Uptane.
Definition: packagemanagerinterface.h:18
Uptane::Manifest
Definition: types.h:448
SecondaryInterface
Definition: secondaryinterface.h:9