1 #include "ipuptanesecondary.h" 2 #include "asn1/asn1_message.h" 3 #include "der_encoder.h" 4 #include "logging/logging.h" 10 PublicKey IpUptaneSecondary::getPublicKey() {
11 LOG_INFO <<
"Getting the public key of a secondary";
14 req->present(AKIpUptaneMes_PR_publicKeyReq);
16 auto resp = Asn1Rpc(req, getAddr());
18 if (resp->present() != AKIpUptaneMes_PR_publicKeyResp) {
19 LOG_ERROR <<
"Failed to get public key response message from secondary";
22 auto r = resp->publicKeyResp();
24 std::string key = ToString(r->key);
26 auto type =
static_cast<KeyType
>(r->type);
30 bool IpUptaneSecondary::putMetadata(
const RawMetaPack& meta_pack) {
31 LOG_INFO <<
"Sending Uptane metadata to the secondary";
33 req->present(AKIpUptaneMes_PR_putMetaReq);
35 auto m = req->putMetaReq();
36 m->image.present = image_PR_json;
37 SetString(&m->image.choice.json.root, meta_pack.image_root);
38 SetString(&m->image.choice.json.targets, meta_pack.image_targets);
39 SetString(&m->image.choice.json.snapshot, meta_pack.image_snapshot);
40 SetString(&m->image.choice.json.timestamp, meta_pack.image_timestamp);
42 m->director.present = director_PR_json;
43 SetString(&m->director.choice.json.root, meta_pack.director_root);
44 SetString(&m->director.choice.json.targets, meta_pack.director_targets);
46 auto resp = Asn1Rpc(req, getAddr());
48 if (resp->present() != AKIpUptaneMes_PR_putMetaResp) {
49 LOG_ERROR <<
"Failed to get response to sending manifest to secondary";
53 auto r = resp->putMetaResp();
54 return r->result == AKInstallationResult_success;
57 bool IpUptaneSecondary::sendFirmwareAsync(
const std::shared_ptr<std::string>&
data) {
58 if (!install_future.valid() || install_future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) {
59 install_future = std::async(std::launch::async, &IpUptaneSecondary::sendFirmware,
this,
data);
65 bool IpUptaneSecondary::sendFirmware(
const std::shared_ptr<std::string>&
data) {
66 LOG_INFO <<
"Sending firmware to the secondary";
67 sendEvent(std::make_shared<event::InstallStarted>(getSerial()));
69 req->present(AKIpUptaneMes_PR_sendFirmwareReq);
71 auto m = req->sendFirmwareReq();
72 SetString(&m->firmware, *
data);
73 auto resp = Asn1Rpc(req, getAddr());
75 if (resp->present() != AKIpUptaneMes_PR_sendFirmwareResp) {
76 LOG_ERROR <<
"Failed to get response to sending firmware to secondary";
77 sendEvent(std::make_shared<event::InstallComplete>(getSerial()));
81 auto r = resp->sendFirmwareResp();
82 sendEvent(std::make_shared<event::InstallComplete>(getSerial()));
83 return r->result == AKInstallationResult_success;
86 Json::Value IpUptaneSecondary::getManifest() {
87 LOG_INFO <<
"Getting the manifest key of a secondary";
90 req->present(AKIpUptaneMes_PR_manifestReq);
92 auto resp = Asn1Rpc(req, getAddr());
94 if (resp->present() != AKIpUptaneMes_PR_manifestResp) {
95 LOG_ERROR <<
"Failed to get public key response message from secondary";
98 auto r = resp->manifestResp();
100 if (r->manifest.present != manifest_PR_json) {
101 LOG_ERROR <<
"Manifest wasn't in json format";
102 return Json::Value();
104 std::string manifest = ToString(r->manifest.choice.json);
105 return Utils::parseJSON(manifest);
static Asn1Message::Ptr Empty()
Create a new Asn1Message, in order to fill it with data and send it.
Base data types that are used in The Update Framework (TUF), part of UPTANE.