Skip to content

Commit

Permalink
Add --list and --delete to rpmkeys
Browse files Browse the repository at this point in the history
This is a  bit of a hack as it manipulates the parsed cli parameters to
to the "right thing" and then calls rpmcliQuery and rpmErase.
  • Loading branch information
ffesti committed Feb 21, 2024
1 parent 1fcfcb5 commit 4470904
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 10 deletions.
18 changes: 15 additions & 3 deletions docs/man/rpmkeys.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ rpmkeys - RPM Keyring
SYNOPSIS
========

**rpmkeys** {**\--import\|\--checksig**}
**rpmkeys** {**\--list\|\--import\|\--delete\|\--checksig**}

DESCRIPTION
===========
Expand All @@ -23,6 +23,10 @@ The general forms of rpm digital signature commands are

**rpmkeys** {**-K\|\--checksig**} *PACKAGE\_FILE \...*

**rpmkeys** **\--list** \[*KEYHASH \...*\]

**rpmkeys** **\--delete** *KEYHASH \...*

The **\--checksig** option checks all the digests and signatures
contained in *PACKAGE\_FILE* to ensure the integrity and origin of the
package. Note that signatures are now verified whenever a package is
Expand All @@ -37,13 +41,21 @@ example, all currently imported public keys can be displayed by:

**rpm -q gpg-pubkey**

Details about a specific public key, when imported, can be displayed by
A more convenient way to display them is

**rpmkeys** **\--list**

More details about a specific public key, when imported, can be displayed by
querying. Here\'s information about the Red Hat GPG/DSA key:

**rpm -qi gpg-pubkey-db42a60e**

Finally, public keys can be erased after importing just like packages.
Here\'s how to remove the Red Hat GPG/DSA key
Here\'s how to remove the Red Hat GPG/DSA key:

**rpmkeys** **\--delete db42a60e**

Or alternatively:

**rpm -e gpg-pubkey-db42a60e**

Expand Down
37 changes: 36 additions & 1 deletion tests/rpmdb.at
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ runroot rpm \
[ignore])
RPMTEST_CLEANUP

AT_SETUP([rpm -qa 3])
AT_SETUP([rpm -qa and rpmkeys])
AT_KEYWORDS([rpmdb query])
RPMDB_INIT

Expand All @@ -82,8 +82,43 @@ gpg-pubkey-1964c5fc-58e63918
hello-2.0-1.x86_64
],
[])

RPMTEST_CHECK([
runroot rpmkeys --list
],
[0],
[1964c5fc-58e63918: rpm.org RSA testkey <[email protected]> public key
],
[])

RPMTEST_CHECK([
runroot rpmkeys --list 1964c5fc
],
[0],
[1964c5fc-58e63918: rpm.org RSA testkey <[email protected]> public key
],
[])

RPMTEST_CHECK([
runroot rpmkeys --list XXX
],
[1],
[package gpg-pubkey-XXX is not installed
],
[])

RPMTEST_CHECK([
runroot rpmkeys --delete 1964c5fc
runroot rpmkeys --list
],
[1],
[package gpg-pubkey is not installed
],
[])
RPMTEST_CLEANUP



# ------------------------------
# Run rpm -q <package> where <package> exists in the db.
AT_SETUP([rpm -q foo])
Expand Down
39 changes: 33 additions & 6 deletions tools/rpmkeys.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <popt.h>
#include <rpm/rpmcli.h>
#include <rpm/rpmstring.h>
#include "cliutils.h"
#include "debug.h"

Expand All @@ -22,12 +23,10 @@ static struct poptOption keyOptsTable[] = {
N_("import an armored public key"), NULL },
{ "test", '\0', POPT_ARG_NONE, &test, 0,
N_("don't import, but tell if it would work or not"), NULL },
#if 0
{ "delete-key", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_DELKEY,
{ "delete", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_DELKEY,
N_("delete keys from RPM keyring"), NULL },
{ "list", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_LISTKEY,
N_("list keys from RPM keyring"), NULL },
{ "list-keys", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_LISTKEY,
N_("list keys from RPM keyring"), NULL },
#endif
POPT_TABLEEND
};

Expand All @@ -42,6 +41,20 @@ static struct poptOption optionsTable[] = {
POPT_TABLEEND
};

static ARGV_t gpgkeyargs(ARGV_const_t args) {
ARGV_t gpgargs = argvNew();
for (char * const * arg = args; *arg; arg++) {
if (strncmp(*arg, "gpg-pubkey-", 11)) {
char * gpgarg = rpmExpand("gpg-pubkey-", *arg, NULL);
argvAdd(&gpgargs, gpgarg);
free(gpgarg);
} else {
argvAdd(&gpgargs, *arg);
}
}
return gpgargs;
}

int main(int argc, char *argv[])
{
int ec = EXIT_FAILURE;
Expand Down Expand Up @@ -73,9 +86,23 @@ int main(int argc, char *argv[])
rpmtsSetFlags(ts, (rpmtsFlags(ts)|RPMTRANS_FLAG_TEST));
ec = rpmcliImportPubkeys(ts, args);
break;
/* XXX TODO: actually implement these... */
case MODE_DELKEY:
struct rpmInstallArguments_s * ia = &rpmIArgs;
ARGV_t gpgargs = gpgkeyargs(args);
ec = rpmErase(ts, ia, gpgargs);
argvFree(gpgargs);
break;
case MODE_LISTKEY:
ARGV_t query = NULL;
if (args != NULL) {
query = gpgkeyargs(args);
} else {
argvAdd(&query, "gpg-pubkey");
}
QVA_t qva = &rpmQVKArgs;
rstrcat(&qva->qva_queryFormat, "%{version}-%{release}: %{summary}\n");
ec = rpmcliQuery(ts, &rpmQVKArgs, (ARGV_const_t) query);
query = argvFree(query);
break;
default:
argerror(_("only one major mode may be specified"));
Expand Down

0 comments on commit 4470904

Please sign in to comment.