Skip to content

Commit

Permalink
Improve pgpVerifySelf() API
Browse files Browse the repository at this point in the history
The pgpVerifySelf() API was rather clumsy.  The type of the data packet
should determine the type of its self-signature, not the other way
around.  This makes detecting wrongly-typed self-signatures much
simpler.

Now that pgpPrtParamsSubkeys() checks the type of self-signatures,
subkey revocation signatures can be checked too.  This allows importing
keys that have revoked subkeys.  Also add a bounds-check in
pgpVerifySelf() in case the index passed is wrong.
  • Loading branch information
DemiMarie committed Apr 12, 2022
1 parent 2a014ce commit 2e8ba35
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions rpmio/rpmpgp_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -888,13 +888,20 @@ static int hashKey(DIGEST_CTX hash, const struct pgpPkt *pkt, int exptag)
}

static int pgpVerifySelf(pgpDigParams key, pgpDigParams selfsig,
const struct pgpPkt *all, int i)
const struct pgpPkt *all, int i, uint8_t tag)
{
int rc = -1;
DIGEST_CTX hash = NULL;

switch (selfsig->sigtype) {
case PGPSIGTYPE_SUBKEY_BINDING:
switch (tag) {
case PGPTAG_PUBLIC_SUBKEY:
if (i < 2)
break;
if (selfsig->sigtype != PGPSIGTYPE_SUBKEY_BINDING &&
selfsig->sigtype != PGPSIGTYPE_SUBKEY_REVOKE)
{
break;
}
hash = rpmDigestInit(selfsig->hash_algo, 0);
if (hash) {
rc = hashKey(hash, &all[0], PGPTAG_PUBLIC_KEY);
Expand Down Expand Up @@ -997,12 +1004,8 @@ int pgpPrtParams(const uint8_t * pkts, size_t pktlen, unsigned int pkttype,
break;

if (selfsig) {
/* subkeys must be followed by binding signature */
int xx = 1; /* assume failure */

if (!(prevtag == PGPTAG_PUBLIC_SUBKEY &&
selfsig->sigtype != PGPSIGTYPE_SUBKEY_BINDING))
xx = pgpVerifySelf(digp, selfsig, all, i);
/* subkeys must be followed by binding or revocation signature */
int xx = pgpVerifySelf(digp, selfsig, all, i, prevtag);

selfsig = pgpDigParamsFree(selfsig);
if (xx)
Expand Down

0 comments on commit 2e8ba35

Please sign in to comment.