Skip to content

Commit

Permalink
Use full key fingerprint for gpg-pubkey version and keystore
Browse files Browse the repository at this point in the history
Change the gpg-pubkey version from short keyid to full fingerprint.
As the header is currently used for formatting the fs keystore filename
too, this changes both keystores to saving by fingerprint.

Update tests accordingly.

Fixes: rpm-software-management#3360
  • Loading branch information
pmatilai authored and ffesti committed Oct 21, 2024
1 parent 4c61c1f commit f81278f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
12 changes: 7 additions & 5 deletions lib/rpmts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ static void addGpgProvide(Header h, const char *n, const char *v)
}

struct pgpdata_s {
const char *fingerprint;
const char *signid;
char *timestr;
char *verid;
Expand All @@ -433,6 +434,7 @@ static void initPgpData(rpmPubkey key, struct pgpdata_s *pd)
{
pgpDigParams pubp = rpmPubkeyPgpDigParams(key);
memset(pd, 0, sizeof(*pd));
pd->fingerprint = rpmPubkeyFingerprintAsHex(key);
pd->signid = rpmPubkeyKeyIDAsHex(key);
pd->shortid = pd->signid + 8;
pd->userid = pgpDigParamsUserID(pubp);
Expand All @@ -442,7 +444,7 @@ static void initPgpData(rpmPubkey key, struct pgpdata_s *pd)
pd->time = pgpDigParamsCreationTime(pubp);

rasprintf(&pd->timestr, "%x", pd->time);
rasprintf(&pd->verid, "%d:%s-%s", pgpDigParamsVersion(pubp), pd->signid, pd->timestr);
rasprintf(&pd->verid, "%d:%s-%s", pgpDigParamsVersion(pubp), pd->fingerprint, pd->timestr);
}

static void finiPgpData(struct pgpdata_s *pd)
Expand Down Expand Up @@ -517,7 +519,7 @@ static int makePubkeyHeader(rpmts ts, rpmPubkey key, rpmPubkey *subkeys,
goto exit;

headerPutString(h, RPMTAG_NAME, "gpg-pubkey");
headerPutString(h, RPMTAG_VERSION, kd.shortid);
headerPutString(h, RPMTAG_VERSION, kd.fingerprint);
headerPutString(h, RPMTAG_RELEASE, kd.timestr);
headerPutString(h, RPMTAG_DESCRIPTION, d);
headerPutString(h, RPMTAG_GROUP, group);
Expand Down Expand Up @@ -779,11 +781,11 @@ rpmRC rpmtxnDeletePubkey(rpmtxn txn, rpmPubkey key)
/* Both import and delete just return OK on test-transaction */
rc = RPMRC_OK;
if (!(rpmtsFlags(txn->ts) & RPMTRANS_FLAG_TEST)) {
const char *keyid = rpmPubkeyKeyIDAsHex(key);
const char *fp = rpmPubkeyFingerprintAsHex(key);
if (txn->ts->keyringtype == KEYRING_FS)
rc = rpmtsDeleteFSKey(txn, keyid+8);
rc = rpmtsDeleteFSKey(txn, fp);
else
rc = rpmtsDeleteDBKey(txn, keyid+8);
rc = rpmtsDeleteDBKey(txn, fp);
}
rpmKeyringFree(keyring);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/rpmdb.at
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ runroot rpm -qa | sort
],
[0],
[foo-1.0-1.noarch
gpg-pubkey-1964c5fc-58e63918
gpg-pubkey-757bf69e-661d22a8
gpg-pubkey-eb04e625-62521e00
gpg-pubkey-152bb32fd9ca982797e835cfb0645aec757bf69e-661d22a8
gpg-pubkey-771b18d3d7baa28734333c424344591e1964c5fc-58e63918
gpg-pubkey-b6542f92f30650c36b6f41bcb3a771bfeb04e625-62521e00
hello-2.0-1.x86_64
],
[])
Expand Down
24 changes: 12 additions & 12 deletions tests/rpmsigdig.at
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,11 @@ RPMDB_INIT
runroot rpmkeys \
--define "_keyring rpmdb" \
--import /data/keys/rpm.org-rsa-2048-test.pub
runroot rpm -qi gpg-pubkey-1964c5fc-58e63918|grep -v Date|grep -v Version:
runroot rpm -q --provides gpg-pubkey-1964c5fc-58e63918],
runroot rpm -qi gpg-pubkey-771b18d3d7baa28734333c424344591e1964c5fc-58e63918|grep -v Date|grep -v Version:
runroot rpm -q --provides gpg-pubkey-771b18d3d7baa28734333c424344591e1964c5fc-58e63918],
[0],
[Name : gpg-pubkey
Version : 1964c5fc
Version : 771b18d3d7baa28734333c424344591e1964c5fc
Release : 58e63918
Architecture: (none)
Group : Public Keys
Expand Down Expand Up @@ -393,9 +393,9 @@ UNW2iqnN3BA7guhOv6OMiROF1+I7Q5nWT63mQC7IgQ==
=Z6nu
-----END PGP PUBLIC KEY BLOCK-----

gpg(rpm.org RSA testkey <[email protected]>) = 4:4344591e1964c5fc-58e63918
gpg(1964c5fc) = 4:4344591e1964c5fc-58e63918
gpg(4344591e1964c5fc) = 4:4344591e1964c5fc-58e63918
gpg(rpm.org RSA testkey <[email protected]>) = 4:771b18d3d7baa28734333c424344591e1964c5fc-58e63918
gpg(1964c5fc) = 4:771b18d3d7baa28734333c424344591e1964c5fc-58e63918
gpg(4344591e1964c5fc) = 4:771b18d3d7baa28734333c424344591e1964c5fc-58e63918
],
[])
RPMTEST_CLEANUP
Expand All @@ -410,7 +410,7 @@ runroot rpmkeys \
--define "_keyringpath /tmp/kr" \
--define "_keyring fs" \
--import /data/keys/rpm.org-rsa-2048-test.pub
runroot_other cat /tmp/kr/gpg-pubkey-1964c5fc-58e63918.key | grep -v 'Version: '
runroot_other cat /tmp/kr/gpg-pubkey-771b18d3d7baa28734333c424344591e1964c5fc-58e63918.key | grep -v 'Version: '
],
[0],
[-----BEGIN PGP PUBLIC KEY BLOCK-----
Expand Down Expand Up @@ -703,12 +703,12 @@ RPMTEST_CHECK([
runroot rpmkeys \
--define "_keyring rpmdb" \
--import /data/keys/different-creation-times.asc
runroot rpm -qi gpg-pubkey-62837bea-62553e62|grep -v Date|grep -v Version:
runroot rpm -qi gpg-pubkey-2f38916f5e77cf307b338596a72b7d4f62837bea-62553e62|grep -v Date|grep -v Version:
runroot rpm -q --provides gpg-pubkey
],
[0],
[[Name : gpg-pubkey
Version : 62837bea
Version : 2f38916f5e77cf307b338596a72b7d4f62837bea
Release : 62553e62
Architecture: (none)
Group : Public Keys
Expand Down Expand Up @@ -744,9 +744,9 @@ AfWOO/Uikf26AHEXoaPWBqecM0pPehlX21lJ3ambpMB2T885Sg==
=IEYU
-----END PGP PUBLIC KEY BLOCK-----

gpg(Alice Lovelace <[email protected]>) = 4:a72b7d4f62837bea-62553e62
gpg(62837bea) = 4:a72b7d4f62837bea-62553e62
gpg(a72b7d4f62837bea) = 4:a72b7d4f62837bea-62553e62
gpg(Alice Lovelace <[email protected]>) = 4:2f38916f5e77cf307b338596a72b7d4f62837bea-62553e62
gpg(62837bea) = 4:2f38916f5e77cf307b338596a72b7d4f62837bea-62553e62
gpg(a72b7d4f62837bea) = 4:2f38916f5e77cf307b338596a72b7d4f62837bea-62553e62
]],
[])
RPMTEST_CLEANUP
Expand Down

0 comments on commit f81278f

Please sign in to comment.