From: Zbigniew Jędrzejewski-Szmek Date: Fri, 27 Jun 2025 12:20:51 +0000 (+0200) Subject: shared/bus-unit-util: define helper for RootHashSignature= X-Git-Tag: v258-rc1~183^2~25 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5517273715556c4b4fa32eb16fe831d586ef3b79;p=thirdparty%2Fsystemd.git shared/bus-unit-util: define helper for RootHashSignature= --- diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index ba4ba65dfa3..a8925c1a002 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -1619,6 +1619,29 @@ static int bus_append_root_hash(sd_bus_message *m, const char *field, const char return bus_append_byte_array(m, field, roothash_decoded, roothash_decoded_size); } +static int bus_append_root_hash_signature(sd_bus_message *m, const char *field, const char *eq) { + char *value; + _cleanup_free_ void *roothash_sig_decoded = NULL; + size_t roothash_sig_decoded_size = 0; + int r; + + /* We have the path to a roothash signature to load and decode, eg: RootHash=/foo/bar.roothash.p7s */ + if (path_is_absolute(eq)) + return bus_append_string(m, "RootHashSignaturePath", eq); + + if (!(value = startswith(eq, "base64:"))) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Failed to decode %s=%s: neither a path nor starts with 'base64:'.", + field, eq); + + /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */ + r = unbase64mem(value, &roothash_sig_decoded, &roothash_sig_decoded_size); + if (r < 0) + return log_error_errno(r, "Failed to decode %s=%s: %m", field, eq); + + return bus_append_byte_array(m, field, roothash_sig_decoded, roothash_sig_decoded_size); +} + static int bus_append_cgroup_property(sd_bus_message *m, const char *field, const char *eq) { if (STR_IN_SET(field, "DevicePolicy", "Slice", @@ -1968,25 +1991,8 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con if (streq(field, "RootHash")) return bus_append_root_hash(m, field, eq); - if (streq(field, "RootHashSignature")) { - _cleanup_free_ void *roothash_sig_decoded = NULL; - char *value; - size_t roothash_sig_decoded_size = 0; - - /* We have the path to a roothash signature to load and decode, eg: RootHash=/foo/bar.roothash.p7s */ - if (path_is_absolute(eq)) - return bus_append_string(m, "RootHashSignaturePath", eq); - - if (!(value = startswith(eq, "base64:"))) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to decode RootHashSignature= '%s', not a path but doesn't start with 'base64:'.", eq); - - /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */ - r = unbase64mem(value, &roothash_sig_decoded, &roothash_sig_decoded_size); - if (r < 0) - return log_error_errno(r, "Failed to decode RootHashSignature= '%s': %m", eq); - - return bus_append_byte_array(m, field, roothash_sig_decoded, roothash_sig_decoded_size); - } + if (streq(field, "RootHashSignature")) + return bus_append_root_hash_signature(m, field, eq); if (streq(field, "RootImageOptions")) { _cleanup_strv_free_ char **l = NULL;