Skip to content

Commit

Permalink
Check not configured keystore backends for keys
Browse files Browse the repository at this point in the history
Give an warning if they contain public keys. This allows the user to
detect misconfigurations or missing conversion from one backend to
another.
  • Loading branch information
ffesti committed Dec 13, 2024
1 parent 3ebd9be commit e53a2d5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/keystore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,27 @@ static rpmRC write_key_to_disk(rpmPubkey key, string & dir, string & filename, i
return rc;
}

rpmRC rpm::check_backends(rpmtxn txn, rpmts ts)
{
rpmRC rc = RPMRC_OK;

keystore_fs ks_fs = {};
keystore_rpmdb ks_rpmdb = {};
keystore_openpgp_cert_d ks_opengpg = {};

for (keystore *ks : std::vector<keystore*> {&ks_fs, &ks_rpmdb, &ks_opengpg}) {
if (ks->get_name() == ts->keystore->get_name())
continue;
rpmKeyring keyring = rpmKeyringNew();
ks->load_keys(txn, keyring);
if (!rpmKeyringIsEmpty(keyring)) {
rpmlog(RPMLOG_WARNING, _("there are public keys in the %s backend which is not the one configured (%s); use rpmkeys --rebuild to integrate or discard them\n"), ks->get_name().c_str(), ts->keystore->get_name().c_str());
rc = RPMRC_FAIL;
}
rpmKeyringFree(keyring);
}
return rc;
}

/*****************************************************************************/

Expand Down
2 changes: 2 additions & 0 deletions lib/keystore.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace rpm {

rpmRC check_backends(rpmtxn txn, rpmts ts);

class keystore {
public:
virtual std::string get_name() { return "None"; };
Expand Down
1 change: 1 addition & 0 deletions lib/rpmts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ static void loadKeyring(rpmts ts)
rpmtxn txn = rpmtxnBegin(ts, RPMTXN_READ);
if (txn) {
ts->keystore->load_keys(txn, ts->keyring);
check_backends(txn, ts);
rpmtxnEnd(txn);
}
}
Expand Down

0 comments on commit e53a2d5

Please sign in to comment.