3 #include "crypto/keymanager.h"
7 std::string Manifest::filepath()
const {
9 return (*
this)[
"signed"][
"installed_image"][
"filepath"].asString();
10 }
catch (
const std::exception &ex) {
11 LOG_ERROR <<
"Unable to parse manifest: " << ex.what();
16 Hash Manifest::installedImageHash()
const {
18 return Hash(Hash::Type::kSha256, (*
this)[
"signed"][
"installed_image"][
"fileinfo"][
"hashes"][
"sha256"].asString());
19 }
catch (
const std::exception &ex) {
20 LOG_ERROR <<
"Unable to parse manifest: " << ex.what();
21 return Hash(Hash::Type::kUnknownAlgorithm,
"");
25 std::string Manifest::signature()
const {
27 return (*
this)[
"signatures"][0][
"sig"].asString();
28 }
catch (
const std::exception &ex) {
29 LOG_ERROR <<
"Unable to parse manifest: " << ex.what();
34 std::string Manifest::signedBody()
const {
36 return Utils::jsonToCanonicalStr((*
this)[
"signed"]);
37 }
catch (
const std::exception &ex) {
38 LOG_ERROR <<
"Unable to parse manifest: " << ex.what();
43 bool Manifest::verifySignature(
const PublicKey &pub_key)
const {
44 if (!(isMember(
"signatures") && isMember(
"signed"))) {
45 LOG_ERROR <<
"Missing either signature or the signing body/subject: " << *
this;
52 Manifest ManifestIssuer::sign(
const Manifest &manifest,
const std::string &report_counter)
const {
53 Manifest manifest_to_sign = manifest;
54 if (!report_counter.empty()) {
55 manifest_to_sign[
"report_counter"] = report_counter;
57 return key_mngr_->signTuf(manifest_to_sign);
60 Manifest ManifestIssuer::assembleManifest(
const InstalledImageInfo &installed_image_info,
62 Json::Value installed_image;
63 installed_image[
"filepath"] = installed_image_info.name;
64 installed_image[
"fileinfo"][
"length"] = Json::UInt64(installed_image_info.len);
65 installed_image[
"fileinfo"][
"hashes"][
"sha256"] = installed_image_info.hash;
67 Json::Value unsigned_ecu_version;
68 unsigned_ecu_version[
"attacks_detected"] =
"";
69 unsigned_ecu_version[
"installed_image"] = installed_image;
70 unsigned_ecu_version[
"ecu_serial"] = ecu_serial.ToString();
71 unsigned_ecu_version[
"previous_timeserver_time"] =
"1970-01-01T00:00:00Z";
72 unsigned_ecu_version[
"timeserver_time"] =
"1970-01-01T00:00:00Z";
73 return unsigned_ecu_version;
76 Hash ManifestIssuer::generateVersionHash(
const std::string &
data) {
return Hash::generate(Hash::Type::kSha256,
data); }
78 std::string ManifestIssuer::generateVersionHashStr(
const std::string &
data) {
80 return boost::algorithm::to_lower_copy(generateVersionHash(
data).HashString());
83 Manifest ManifestIssuer::assembleManifest(
const InstalledImageInfo &installed_image_info)
const {
84 return assembleManifest(installed_image_info, ecu_serial_);
87 Manifest ManifestIssuer::assembleManifest(
const Uptane::Target &target)
const {
88 return assembleManifest(target.getTargetImageInfo());
91 Manifest ManifestIssuer::assembleAndSignManifest(
const InstalledImageInfo &installed_image_info)
const {
92 return key_mngr_->signTuf(assembleManifest(installed_image_info));