Skip to content

Commit

Permalink
Make signature range clearer and more flexible
Browse files Browse the repository at this point in the history
Rename the siginfo payload field to range, which better explains
what it means. Also make it a bitfield which allows expressing
the actual combinations: modern signature/digest items are on
header only, rpm v3 ones are on header+payload and in the future
we might have payload-only digest(s) as well.

No functional changes intended.
  • Loading branch information
pmatilai committed Feb 22, 2017
1 parent b74096a commit 6c7b85e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/rpmchecksig.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ static int rpmpkgVerifySigs(rpmKeyring keyring, rpmQueryFlags flags,
if (nodigests && sinfo.type == RPMSIG_DIGEST_TYPE)
continue;
if (rc == RPMRC_OK && sinfo.hashalgo) {
rpmDigestBundleAdd(sinfo.payload ? plbundle : hdrbundle,
rpmDigestBundleAdd((sinfo.range & RPMSIG_PAYLOAD) ?
plbundle : hdrbundle,
sinfo.hashalgo, RPMDIGEST_NONE);
}
}
Expand Down Expand Up @@ -302,7 +303,8 @@ static int rpmpkgVerifySigs(rpmKeyring keyring, rpmQueryFlags flags,
continue;

if (sinfo.type != RPMSIG_OTHER_TYPE && rc == RPMRC_OK) {
ctx = rpmDigestBundleDupCtx(sinfo.payload ? plbundle : hdrbundle,
ctx = rpmDigestBundleDupCtx((sinfo.range & RPMSIG_PAYLOAD) ?
plbundle : hdrbundle,
sinfo.hashalgo);
rc = rpmVerifySignature(keyring, &sigtd, sig, ctx, &result);
rpmDigestFinal(ctx, NULL, NULL, 0);
Expand Down
9 changes: 7 additions & 2 deletions lib/signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,43 @@ rpmRC rpmSigInfoParse(rpmtd td, const char *origin,
case RPMSIGTAG_GPG:
case RPMSIGTAG_PGP5: /* XXX legacy */
case RPMSIGTAG_PGP:
sinfo->payload = 1;
sinfo->range = RPMSIG_PAYLOAD;
/* fallthrough */
case RPMSIGTAG_RSA:
case RPMSIGTAG_DSA:
tagtype = RPM_BIN_TYPE;
sinfo->type = RPMSIG_SIGNATURE_TYPE;
/* GPG/PGP are hdr+payload, RSA/DSA are hdr-only */
sinfo->range |= RPMSIG_HEADER;
break;
case RPMSIGTAG_SHA1:
tagsize = 41; /* includes trailing \0 */
tagtype = RPM_STRING_TYPE;
hexstring = 1;
sinfo->hashalgo = PGPHASHALGO_SHA1;
sinfo->type = RPMSIG_DIGEST_TYPE;
sinfo->range = RPMSIG_HEADER;
break;
case RPMSIGTAG_MD5:
tagtype = RPM_BIN_TYPE;
tagsize = 16;
sinfo->hashalgo = PGPHASHALGO_MD5;
sinfo->type = RPMSIG_DIGEST_TYPE;
sinfo->payload = 1;
sinfo->range = (RPMSIG_HEADER|RPMSIG_PAYLOAD);
break;
case RPMSIGTAG_SIZE:
case RPMSIGTAG_PAYLOADSIZE:
tagsize = 4;
tagtype = RPM_INT32_TYPE;
sinfo->type = RPMSIG_OTHER_TYPE;
sinfo->range = RPMSIG_PAYLOAD;
break;
case RPMSIGTAG_LONGSIZE:
case RPMSIGTAG_LONGARCHIVESIZE:
tagsize = 8;
tagtype = RPM_INT64_TYPE;
sinfo->type = RPMSIG_OTHER_TYPE;
sinfo->range = RPMSIG_PAYLOAD;
break;
case RPMSIGTAG_RESERVEDSPACE:
tagtype = RPM_BIN_TYPE;
Expand Down
8 changes: 7 additions & 1 deletion lib/signature.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ enum {
RPMSIG_OTHER_TYPE = 3,
};

/* siginfo range bits */
enum {
RPMSIG_HEADER = (1 << 0),
RPMSIG_PAYLOAD = (1 << 1),
};

struct sigtInfo_s {
int hashalgo;
int payload;
int range;
int type;
};

Expand Down

0 comments on commit 6c7b85e

Please sign in to comment.