report: add reportID field to reports

This uses a random high-entropy ID for reports, making it useful
when hashing the report for passing it to the Time Stamping
Authority. Reports are therefore guaranteed to be distinct from
one another.
This commit is contained in:
theogeff
2026-09-23 16:28:58 +02:00
committed by Luca Boccassi
parent 3f9d31fdc0
commit e8142670aa
+8
View File
@@ -3,6 +3,7 @@
#include "sd-json.h" #include "sd-json.h"
#include "log.h" #include "log.h"
#include "random-util.h"
#include "report.h" #include "report.h"
#include "report-generate.h" #include "report-generate.h"
#include "report-sign.h" #include "report-sign.h"
@@ -16,11 +17,18 @@ int context_build_report(Context *context, sd_json_variant **ret) {
assert(context); assert(context);
assert(ret); assert(ret);
/* Generate a unique ID for the report. */
uint8_t report_id[32];
r = crypto_random_bytes(report_id, sizeof(report_id));
if (r < 0)
return log_error_errno(r, "Failed to generate report ID: %m");
usec_t ts = now(CLOCK_REALTIME); usec_t ts = now(CLOCK_REALTIME);
_cleanup_(sd_json_variant_unrefp) sd_json_variant *report = NULL; _cleanup_(sd_json_variant_unrefp) sd_json_variant *report = NULL;
r = sd_json_buildo(&report, r = sd_json_buildo(&report,
SD_JSON_BUILD_PAIR_STRING("mediaType", "application/vnd.io.systemd.report"), SD_JSON_BUILD_PAIR_STRING("mediaType", "application/vnd.io.systemd.report"),
SD_JSON_BUILD_PAIR_BASE64("reportID", report_id, sizeof(report_id)),
SD_JSON_BUILD_PAIR("timestamp", SD_JSON_BUILD_PAIR("timestamp",
SD_JSON_BUILD_STRING(FORMAT_TIMESTAMP_STYLE(ts, TIMESTAMP_UTC))), SD_JSON_BUILD_STRING(FORMAT_TIMESTAMP_STYLE(ts, TIMESTAMP_UTC))),
SD_JSON_BUILD_PAIR("metrics", SD_JSON_BUILD_PAIR("metrics",