Skip to content

Commit

Permalink
Update rpmkeys to use rpmtxnDeletePubkey() for --delete
Browse files Browse the repository at this point in the history
  • Loading branch information
pmatilai authored and ffesti committed Oct 10, 2024
1 parent 9469bf8 commit a715e7e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 5 deletions.
56 changes: 55 additions & 1 deletion tests/rpmsigdig.at
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ runroot rpmkeys -Kv /data/RPMS/hello-1.0-1.i386.rpm
[])
RPMTEST_CLEANUP

AT_SETUP([rpmkeys key update (rpmdb)])
AT_SETUP([rpmkeys key update and delete (rpmdb)])
AT_KEYWORDS([rpmkeys signature])
RPMDB_INIT
# currently the default but make it explicit
Expand Down Expand Up @@ -74,6 +74,34 @@ runroot rpmkeys -Kv /data/RPMS/hello-2.0-1.x86_64-signed-with-new-subkey.rpm
Payload SHA256 digest: OK
],
[])

RPMTEST_CHECK([
runroot rpmkeys --delete abcd gimmekey 1111aaaa2222bbbb
],
[3],
[],
[error: invalid key id: abcd
error: invalid key id: gimmekey
error: key not found: 1111aaaa2222bbbb
])

RPMTEST_CHECK([
runroot rpmkeys --delete 1964c5fc
],
[0],
[],
[])

RPMTEST_CHECK([
# XXX rpmkeys on rpmdb returns "package gpg-pubkey is not installed" with
# and error code when no keys are present, paper over
runroot rpmkeys --list | grep -v "not installed" | wc -l
exit 0
],
[0],
[0
],
[])
RPMTEST_CLEANUP

AT_SETUP([rpmkeys key update (fs)])
Expand Down Expand Up @@ -115,6 +143,32 @@ runroot rpmkeys -Kv /data/RPMS/hello-2.0-1.x86_64-signed-with-new-subkey.rpm
Payload SHA256 digest: OK
],
[])

RPMTEST_CHECK([
runroot rpmkeys --delete abcd gimmekey 1111aaaa2222bbbb
],
[3],
[],
[error: invalid key id: abcd
error: invalid key id: gimmekey
error: key not found: 1111aaaa2222bbbb
])

RPMTEST_CHECK([
runroot rpmkeys --delete 1964c5fc
],
[0],
[],
[])

RPMTEST_CHECK([
# XXX rpmkeys --list doesn't yet work with fs keystore
runroot_other find /usr/lib/sysimage/rpm/pubkeys -name "*.key" | wc -l
],
[0],
[0
],
[])
RPMTEST_CLEANUP
# ------------------------------
# Test rpmkeys write errors
Expand Down
23 changes: 19 additions & 4 deletions tools/rpmkeys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <popt.h>
#include <rpm/rpmcli.h>
#include <rpm/rpmstring.h>
#include <rpm/rpmlog.h>
#include "cliutils.hh"
#include "debug.h"

Expand Down Expand Up @@ -89,10 +90,24 @@ int main(int argc, char *argv[])
break;
case MODE_DELKEY:
{
struct rpmInstallArguments_s * ia = &rpmIArgs;
ARGV_t gpgargs = gpgkeyargs(args);
ec = rpmErase(ts, ia, gpgargs);
argvFree(gpgargs);
rpmtxn txn = rpmtxnBegin(ts, RPMTXN_WRITE);
if (txn) {
int nfail = 0;
for (char const * const *arg = args; *arg && **arg; arg++) {
rpmRC delrc = rpmtxnDeletePubkey(txn, *arg);
if (delrc) {
if (delrc == RPMRC_NOTFOUND)
rpmlog(RPMLOG_ERR, ("key not found: %s\n"), *arg);
else if (delrc == RPMRC_NOKEY)
rpmlog(RPMLOG_ERR, ("invalid key id: %s\n"), *arg);
else if (delrc == RPMRC_FAIL)
rpmlog(RPMLOG_ERR, ("failed to delete key: %s\n"), *arg);
nfail++;
}
}
ec = nfail;
rpmtxnEnd(txn);
}
break;
}
case MODE_LISTKEY:
Expand Down

0 comments on commit a715e7e

Please sign in to comment.