From 200efd7d44cfc490d2bbca7e09d494e851e6c890 Mon Sep 17 00:00:00 2001 From: Denis Pynkin Date: Tue, 29 Oct 2019 22:16:09 +0300 Subject: [PATCH] builtin/sign: add option 'keys-dir' Option '--keys-dir' is used for redefinition of default directories with public/revoked keys. If keys directory is set then default directories are ignored and target directory is expected to contain following structure for ed25519 signature mechanism: dir/ trusted.ed25519 <- file with trusted keys revoked.ed25519 <- file with revoked keys trusted.ed25519.d/ <- directory with files containing trusted keys revoked.ed25519.d/ <- directory with files containing revoked keys Signed-off-by: Denis Pynkin --- src/ostree/ot-builtin-sign.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/ostree/ot-builtin-sign.c b/src/ostree/ot-builtin-sign.c index f673631d..73561b43 100644 --- a/src/ostree/ot-builtin-sign.c +++ b/src/ostree/ot-builtin-sign.c @@ -37,6 +37,7 @@ static gboolean opt_delete; static gboolean opt_verify; static char *opt_sign_name; static char *opt_filename; +static char *opt_keysdir; /* ATTENTION: * Please remember to update the bash-completion script (bash/ostree) and @@ -48,9 +49,10 @@ static GOptionEntry options[] = { { "verify", 0, 0, G_OPTION_ARG_NONE, &opt_verify, "Verify signatures", NULL}, { "sign-type", 's', 0, G_OPTION_ARG_STRING, &opt_sign_name, "Signature type to use (defaults to 'ed25519')", "NAME"}, #if defined(HAVE_LIBSODIUM) - { "keys-file", 's', 0, G_OPTION_ARG_STRING, &opt_filename, "Read key(s) from file", "NAME"}, + { "keys-file", 0, 0, G_OPTION_ARG_STRING, &opt_filename, "Read key(s) from file", "NAME"}, + { "keys-dir", 0, 0, G_OPTION_ARG_STRING, &opt_keysdir, "Redefine system-wide directories with public and revoked keys for verification", "NAME"}, #endif - { NULL } + { NULL } }; static void @@ -131,7 +133,10 @@ ostree_builtin_sign (int argc, char **argv, OstreeCommandInvocation *invocation, resolved_commit, cancellable, &local_error)) - ret = TRUE; + { + ret = TRUE; + goto out; + } } else { @@ -162,6 +167,9 @@ ostree_builtin_sign (int argc, char **argv, OstreeCommandInvocation *invocation, g_autoptr (GVariant) options = NULL; builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); + /* Use custom directory with public and revoked keys instead of system-wide directories */ + if (opt_keysdir) + g_variant_builder_add (builder, "{sv}", "basedir", g_variant_new_string (opt_keysdir)); /* The last chance for verification source -- system files */ if (opt_filename) g_variant_builder_add (builder, "{sv}", "filename", g_variant_new_string (opt_filename)); @@ -235,9 +243,8 @@ ostree_builtin_sign (int argc, char **argv, OstreeCommandInvocation *invocation, } } } - // No valid signature found - if (opt_verify && (ret != TRUE)) + if (opt_verify && (ret != TRUE) && (*error == NULL)) g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "No valid signatures found");