bin/remote: Add list-gpg-keys subcommand
This provides a wrapper for the `ostree_repo_remote_get_gpg_keys` function to show the GPG keys associated with a remote. This is particularly useful for validating that GPG key updates have been applied. Tests are added, which checks the `ostree_repo_remote_get_gpg_keys` API by extension.
This commit is contained in:
1 parent
a50f6d0b9f
commit
74fb0c5f78
10 files changed
+373
-3
No files matched your search
@@ -44,6 +44,9 @@ static OstreeCommand remote_subcommands[] = {
|
||||
{ "gpg-import", OSTREE_BUILTIN_FLAG_NONE,
|
||||
ot_remote_builtin_gpg_import,
|
||||
"Import GPG keys" },
|
||||
{ "list-gpg-keys", OSTREE_BUILTIN_FLAG_NONE,
|
||||
ot_remote_builtin_list_gpg_keys,
|
||||
"Show remote GPG keys" },
|
||||
#endif /* OSTREE_DISABLE_GPGME */
|
||||
#ifdef HAVE_LIBCURL_OR_LIBSOUP
|
||||
{ "add-cookie", OSTREE_BUILTIN_FLAG_NONE,
|
||||
|
||||
+111
-2
@@ -53,6 +53,7 @@ ot_dump_variant (GVariant *variant)
|
||||
|
||||
static gchar *
|
||||
format_timestamp (guint64 timestamp,
|
||||
gboolean local_tz,
|
||||
GError **error)
|
||||
{
|
||||
GDateTime *dt;
|
||||
@@ -66,7 +67,19 @@ format_timestamp (guint64 timestamp,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
str = g_date_time_format (dt, "%Y-%m-%d %H:%M:%S +0000");
|
||||
if (local_tz)
|
||||
{
|
||||
/* Convert to local time and display in the locale's preferred
|
||||
* representation.
|
||||
*/
|
||||
g_autoptr(GDateTime) dt_local = g_date_time_to_local (dt);
|
||||
str = g_date_time_format (dt_local, "%c");
|
||||
}
|
||||
else
|
||||
{
|
||||
str = g_date_time_format (dt, "%Y-%m-%d %H:%M:%S +0000");
|
||||
}
|
||||
|
||||
g_date_time_unref (dt);
|
||||
|
||||
return str;
|
||||
@@ -124,7 +137,7 @@ dump_commit (GVariant *variant,
|
||||
&subject, &body, ×tamp, NULL, NULL);
|
||||
|
||||
timestamp = GUINT64_FROM_BE (timestamp);
|
||||
str = format_timestamp (timestamp, &local_error);
|
||||
str = format_timestamp (timestamp, FALSE, &local_error);
|
||||
if (!str)
|
||||
{
|
||||
g_assert (local_error); /* Pacify static analysis */
|
||||
@@ -390,3 +403,99 @@ ot_dump_summary_bytes (GBytes *summary_bytes,
|
||||
g_print ("%s: %s\n", key, value_str);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
dump_gpg_subkey (GVariant *subkey,
|
||||
gboolean primary,
|
||||
GError **error)
|
||||
{
|
||||
const gchar *fingerprint = NULL;
|
||||
gint64 created = 0;
|
||||
gint64 expires = 0;
|
||||
gboolean revoked = FALSE;
|
||||
gboolean expired = FALSE;
|
||||
gboolean invalid = FALSE;
|
||||
(void) g_variant_lookup (subkey, "fingerprint", "&s", &fingerprint);
|
||||
(void) g_variant_lookup (subkey, "created", "x", &created);
|
||||
(void) g_variant_lookup (subkey, "expires", "x", &expires);
|
||||
(void) g_variant_lookup (subkey, "revoked", "b", &revoked);
|
||||
(void) g_variant_lookup (subkey, "expired", "b", &expired);
|
||||
(void) g_variant_lookup (subkey, "invalid", "b", &invalid);
|
||||
|
||||
/* Convert timestamps from big endian if needed */
|
||||
created = GINT64_FROM_BE (created);
|
||||
expires = GINT64_FROM_BE (expires);
|
||||
|
||||
g_print ("%s: %s%s%s\n",
|
||||
primary ? "Key" : " Subkey",
|
||||
fingerprint,
|
||||
revoked ? " (revoked)" : "",
|
||||
invalid ? " (invalid)" : "");
|
||||
|
||||
g_autofree gchar *created_str = format_timestamp (created, TRUE,
|
||||
error);
|
||||
if (created_str == NULL)
|
||||
return FALSE;
|
||||
g_print ("%sCreated: %s\n",
|
||||
primary ? " " : " ",
|
||||
created_str);
|
||||
|
||||
if (expires > 0)
|
||||
{
|
||||
g_autofree gchar *expires_str = format_timestamp (expires, TRUE,
|
||||
error);
|
||||
if (expires_str == NULL)
|
||||
return FALSE;
|
||||
g_print ("%s%s: %s\n",
|
||||
primary ? " " : " ",
|
||||
expired ? "Expired" : "Expires",
|
||||
expires_str);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
ot_dump_gpg_key (GVariant *key,
|
||||
GError **error)
|
||||
{
|
||||
if (!g_variant_is_of_type (key, OSTREE_GPG_KEY_GVARIANT_FORMAT))
|
||||
return glnx_throw (error, "GPG key variant type doesn't match '%s'",
|
||||
OSTREE_GPG_KEY_GVARIANT_STRING);
|
||||
|
||||
g_autoptr(GVariant) subkeys_v = g_variant_get_child_value (key, 0);
|
||||
GVariantIter subkeys_iter;
|
||||
g_variant_iter_init (&subkeys_iter, subkeys_v);
|
||||
|
||||
g_autoptr(GVariant) primary_key = NULL;
|
||||
g_variant_iter_next (&subkeys_iter, "(@a{sv})", &primary_key);
|
||||
if (!dump_gpg_subkey (primary_key, TRUE, error))
|
||||
return FALSE;
|
||||
|
||||
g_autoptr(GVariant) uids_v = g_variant_get_child_value (key, 1);
|
||||
GVariantIter uids_iter;
|
||||
g_variant_iter_init (&uids_iter, uids_v);
|
||||
GVariant *uid_v = NULL;
|
||||
while (g_variant_iter_loop (&uids_iter, "(@a{sv})", &uid_v))
|
||||
{
|
||||
const gchar *uid = NULL;
|
||||
gboolean revoked = FALSE;
|
||||
gboolean invalid = FALSE;
|
||||
(void) g_variant_lookup (uid_v, "uid", "&s", &uid);
|
||||
(void) g_variant_lookup (uid_v, "revoked", "b", &revoked);
|
||||
(void) g_variant_lookup (uid_v, "invalid", "b", &invalid);
|
||||
g_print (" UID: %s%s%s\n",
|
||||
uid,
|
||||
revoked ? " (revoked)" : "",
|
||||
invalid ? " (invalid)" : "");
|
||||
}
|
||||
|
||||
GVariant *subkey = NULL;
|
||||
while (g_variant_iter_loop (&subkeys_iter, "(@a{sv})", &subkey))
|
||||
{
|
||||
if (!dump_gpg_subkey (subkey, FALSE, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -42,3 +42,6 @@ void ot_dump_object (OstreeObjectType objtype,
|
||||
|
||||
void ot_dump_summary_bytes (GBytes *summary_bytes,
|
||||
OstreeDumpFlags flags);
|
||||
|
||||
gboolean ot_dump_gpg_key (GVariant *key,
|
||||
GError **error);
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Red Hat, Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.0+
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "otutil.h"
|
||||
|
||||
#include "ot-main.h"
|
||||
#include "ot-dump.h"
|
||||
#include "ot-remote-builtins.h"
|
||||
|
||||
/* ATTENTION:
|
||||
* Please remember to update the bash-completion script (bash/ostree) and
|
||||
* man page (man/ostree-remote.xml) when changing the option list.
|
||||
*/
|
||||
|
||||
static GOptionEntry option_entries[] = {
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
gboolean
|
||||
ot_remote_builtin_list_gpg_keys (int argc,
|
||||
char **argv,
|
||||
OstreeCommandInvocation *invocation,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GOptionContext) context = g_option_context_new ("NAME");
|
||||
g_autoptr(OstreeRepo) repo = NULL;
|
||||
if (!ostree_option_context_parse (context, option_entries, &argc, &argv,
|
||||
invocation, &repo, cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
const char *remote_name = (argc > 1) ? argv[1] : NULL;
|
||||
|
||||
g_autoptr(GPtrArray) keys = NULL;
|
||||
if (!ostree_repo_remote_get_gpg_keys (repo, remote_name, NULL, &keys,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
for (guint i = 0; i < keys->len; i++)
|
||||
{
|
||||
if (!ot_dump_gpg_key (keys->pdata[i], error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -32,6 +32,7 @@ G_BEGIN_DECLS
|
||||
BUILTINPROTO(add);
|
||||
BUILTINPROTO(delete);
|
||||
BUILTINPROTO(gpg_import);
|
||||
BUILTINPROTO(list_gpg_keys);
|
||||
BUILTINPROTO(list);
|
||||
#ifdef HAVE_LIBCURL_OR_LIBSOUP
|
||||
BUILTINPROTO(add_cookie);
|
||||
|
||||
Reference in new issue
Block a user