2017-04-28 15:32:24 +08:00
|
|
|
#include "system.h"
|
|
|
|
|
|
|
|
#include <rpm/rpmkeyring.h>
|
|
|
|
#include "lib/rpmvs.h"
|
|
|
|
#include "rpmio/digest.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
struct rpmvs_s {
|
|
|
|
struct rpmsinfo_s *sigs;
|
|
|
|
int nsigs;
|
2017-05-22 17:32:32 +08:00
|
|
|
int nalloced;
|
2018-04-05 19:10:37 +08:00
|
|
|
rpmVSFlags vsflags;
|
2017-04-28 15:32:24 +08:00
|
|
|
};
|
|
|
|
|
2017-05-11 15:40:28 +08:00
|
|
|
struct vfytag_s {
|
|
|
|
rpmTagVal tag;
|
|
|
|
rpmTagType tagtype;
|
|
|
|
rpm_count_t tagcount;
|
|
|
|
rpm_count_t tagsize;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct vfytag_s rpmvfytags[] = {
|
|
|
|
{ RPMSIGTAG_SIZE, RPM_BIN_TYPE, 0, 0, },
|
|
|
|
{ RPMSIGTAG_PGP, RPM_BIN_TYPE, 0, 0, },
|
|
|
|
{ RPMSIGTAG_MD5, RPM_BIN_TYPE, 0, 16, },
|
|
|
|
{ RPMSIGTAG_GPG, RPM_BIN_TYPE, 0, 0, },
|
|
|
|
{ RPMSIGTAG_PGP5, RPM_BIN_TYPE, 0, 0, },
|
|
|
|
{ RPMSIGTAG_PAYLOADSIZE, RPM_INT32_TYPE, 1, 4, },
|
|
|
|
{ RPMSIGTAG_RESERVEDSPACE, RPM_BIN_TYPE, 0, 0, },
|
|
|
|
{ RPMTAG_DSAHEADER, RPM_BIN_TYPE, 0, 0, },
|
|
|
|
{ RPMTAG_RSAHEADER, RPM_BIN_TYPE, 0, 0, },
|
|
|
|
{ RPMTAG_SHA1HEADER, RPM_STRING_TYPE, 1, 41, },
|
|
|
|
{ RPMSIGTAG_LONGSIZE, RPM_INT64_TYPE, 1, 8, },
|
|
|
|
{ RPMSIGTAG_LONGARCHIVESIZE, RPM_INT64_TYPE, 1, 8, },
|
|
|
|
{ RPMTAG_SHA256HEADER, RPM_STRING_TYPE, 1, 65, },
|
|
|
|
{ RPMTAG_PAYLOADDIGEST, RPM_STRING_ARRAY_TYPE, 0, 0, },
|
|
|
|
{ 0 } /* sentinel */
|
|
|
|
};
|
|
|
|
|
2017-05-15 16:44:47 +08:00
|
|
|
struct vfyinfo_s {
|
|
|
|
rpmTagVal tag;
|
|
|
|
struct rpmsinfo_s vi;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct vfyinfo_s rpmvfyitems[] = {
|
2017-05-11 15:40:28 +08:00
|
|
|
{ RPMSIGTAG_SIZE,
|
2017-05-15 16:44:47 +08:00
|
|
|
{ RPMSIG_OTHER_TYPE, 0,
|
|
|
|
(RPMSIG_HEADER|RPMSIG_PAYLOAD), 0, }, },
|
2017-05-11 15:40:28 +08:00
|
|
|
{ RPMSIGTAG_PGP,
|
2017-05-15 16:44:47 +08:00
|
|
|
{ RPMSIG_SIGNATURE_TYPE, RPMVSF_NORSA,
|
|
|
|
(RPMSIG_HEADER|RPMSIG_PAYLOAD), 0, }, },
|
2017-05-11 15:40:28 +08:00
|
|
|
{ RPMSIGTAG_MD5,
|
2017-05-15 16:44:47 +08:00
|
|
|
{ RPMSIG_DIGEST_TYPE, RPMVSF_NOMD5,
|
|
|
|
(RPMSIG_HEADER|RPMSIG_PAYLOAD), PGPHASHALGO_MD5, }, },
|
2017-05-11 15:40:28 +08:00
|
|
|
{ RPMSIGTAG_GPG,
|
2017-05-15 16:44:47 +08:00
|
|
|
{ RPMSIG_SIGNATURE_TYPE, RPMVSF_NODSA,
|
|
|
|
(RPMSIG_HEADER|RPMSIG_PAYLOAD), 0, }, },
|
2017-05-11 15:40:28 +08:00
|
|
|
{ RPMSIGTAG_PGP5,
|
2017-05-15 16:44:47 +08:00
|
|
|
{ RPMSIG_SIGNATURE_TYPE, RPMVSF_NORSA,
|
|
|
|
(RPMSIG_HEADER|RPMSIG_PAYLOAD), 0, }, },
|
2017-05-11 15:40:28 +08:00
|
|
|
{ RPMSIGTAG_PAYLOADSIZE,
|
2017-05-15 16:44:47 +08:00
|
|
|
{ RPMSIG_OTHER_TYPE, 0,
|
|
|
|
(RPMSIG_PAYLOAD), 0, }, },
|
2017-05-11 15:40:28 +08:00
|
|
|
{ RPMSIGTAG_RESERVEDSPACE,
|
2017-05-15 16:44:47 +08:00
|
|
|
{ RPMSIG_OTHER_TYPE, 0,
|
|
|
|
0, 0, }, },
|
2017-05-11 15:40:28 +08:00
|
|
|
{ RPMTAG_DSAHEADER,
|
2017-05-15 16:44:47 +08:00
|
|
|
{ RPMSIG_SIGNATURE_TYPE, RPMVSF_NODSAHEADER,
|
|
|
|
(RPMSIG_HEADER), 0, }, },
|
2017-05-11 15:40:28 +08:00
|
|
|
{ RPMTAG_RSAHEADER,
|
2017-05-15 16:44:47 +08:00
|
|
|
{ RPMSIG_SIGNATURE_TYPE, RPMVSF_NORSAHEADER,
|
|
|
|
(RPMSIG_HEADER), 0, }, },
|
2017-05-11 15:40:28 +08:00
|
|
|
{ RPMTAG_SHA1HEADER,
|
2017-05-15 16:44:47 +08:00
|
|
|
{ RPMSIG_DIGEST_TYPE, RPMVSF_NOSHA1HEADER,
|
|
|
|
(RPMSIG_HEADER), PGPHASHALGO_SHA1, }, },
|
2017-05-11 15:40:28 +08:00
|
|
|
{ RPMSIGTAG_LONGSIZE,
|
2017-05-15 16:44:47 +08:00
|
|
|
{ RPMSIG_OTHER_TYPE, 0,
|
|
|
|
(RPMSIG_HEADER|RPMSIG_PAYLOAD), 0, }, },
|
2017-05-11 15:40:28 +08:00
|
|
|
{ RPMSIGTAG_LONGARCHIVESIZE,
|
2017-05-15 16:44:47 +08:00
|
|
|
{ RPMSIG_OTHER_TYPE, 0,
|
|
|
|
(RPMSIG_HEADER|RPMSIG_PAYLOAD), 0, }, },
|
2017-05-11 15:40:28 +08:00
|
|
|
{ RPMTAG_SHA256HEADER,
|
2017-05-15 16:44:47 +08:00
|
|
|
{ RPMSIG_DIGEST_TYPE, RPMVSF_NOSHA256HEADER,
|
|
|
|
(RPMSIG_HEADER), PGPHASHALGO_SHA256, }, },
|
2017-05-11 15:40:28 +08:00
|
|
|
{ RPMTAG_PAYLOADDIGEST,
|
2017-05-15 16:44:47 +08:00
|
|
|
{ RPMSIG_DIGEST_TYPE, RPMVSF_NOPAYLOAD,
|
|
|
|
(RPMSIG_PAYLOAD), PGPHASHALGO_SHA256, }, },
|
2017-04-28 15:32:24 +08:00
|
|
|
{ 0 } /* sentinel */
|
|
|
|
};
|
|
|
|
|
2017-05-24 16:20:35 +08:00
|
|
|
static const char *rangeName(int range);
|
2017-05-24 17:17:46 +08:00
|
|
|
static const char * rpmSigString(rpmRC res);
|
2018-04-05 19:46:36 +08:00
|
|
|
static void rpmVerifySignature(rpmKeyring keyring, struct rpmsinfo_s *sinfo,
|
|
|
|
DIGEST_CTX ctx);
|
2017-05-12 18:05:20 +08:00
|
|
|
|
2017-05-11 15:18:00 +08:00
|
|
|
static int sinfoLookup(rpmTagVal tag)
|
2017-04-28 15:32:24 +08:00
|
|
|
{
|
2017-05-15 16:44:47 +08:00
|
|
|
const struct vfyinfo_s *start = &rpmvfyitems[0];
|
2017-05-11 15:18:00 +08:00
|
|
|
int ix = -1;
|
2017-05-15 16:44:47 +08:00
|
|
|
for (const struct vfyinfo_s *si = start; si->tag; si++) {
|
2017-04-28 15:32:24 +08:00
|
|
|
if (tag == si->tag) {
|
2017-05-11 15:18:00 +08:00
|
|
|
ix = si - start;
|
2017-04-28 15:32:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-05-11 15:18:00 +08:00
|
|
|
return ix;
|
2017-04-28 15:32:24 +08:00
|
|
|
}
|
|
|
|
|
2017-05-30 15:16:05 +08:00
|
|
|
static int validHex(const char *str, size_t slen)
|
|
|
|
{
|
|
|
|
int valid = 0; /* Assume invalid */
|
|
|
|
const char *b;
|
|
|
|
|
|
|
|
/* Our hex data is always even sized and at least sha-1 long */
|
|
|
|
if (slen % 2 || slen < 40)
|
|
|
|
goto exit;
|
|
|
|
|
|
|
|
for (b = str ; *b != '\0'; b++) {
|
|
|
|
if (strchr("0123456789abcdefABCDEF", *b) == NULL)
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
valid = 1;
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
2018-04-05 19:46:36 +08:00
|
|
|
static void rpmsinfoInit(const struct vfyinfo_s *vinfo,
|
2018-04-05 18:58:44 +08:00
|
|
|
const struct vfytag_s *tinfo,
|
|
|
|
rpmtd td, const char *origin,
|
2018-04-05 19:46:36 +08:00
|
|
|
struct rpmsinfo_s *sinfo)
|
2017-04-28 15:32:24 +08:00
|
|
|
{
|
|
|
|
rpmRC rc = RPMRC_FAIL;
|
|
|
|
const void *data = NULL;
|
|
|
|
rpm_count_t dlen = 0;
|
|
|
|
|
2018-04-05 18:58:44 +08:00
|
|
|
*sinfo = vinfo->vi; /* struct assignment */
|
2017-04-28 15:32:24 +08:00
|
|
|
|
2017-05-11 15:40:28 +08:00
|
|
|
if (tinfo->tagtype && tinfo->tagtype != td->type) {
|
2018-04-05 19:46:36 +08:00
|
|
|
rasprintf(&sinfo->msg, _("%s tag %u: invalid type %u"),
|
2017-04-28 15:32:24 +08:00
|
|
|
origin, td->tag, td->type);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2017-05-11 15:40:28 +08:00
|
|
|
if (tinfo->tagcount && tinfo->tagcount != td->count) {
|
2018-04-05 19:46:36 +08:00
|
|
|
rasprintf(&sinfo->msg, _("%s: tag %u: invalid count %u"),
|
2017-04-28 15:32:24 +08:00
|
|
|
origin, td->tag, td->count);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (td->type) {
|
|
|
|
case RPM_STRING_TYPE:
|
|
|
|
case RPM_STRING_ARRAY_TYPE:
|
|
|
|
data = rpmtdGetString(td);
|
|
|
|
if (data)
|
|
|
|
dlen = strlen(data);
|
|
|
|
break;
|
|
|
|
case RPM_BIN_TYPE:
|
|
|
|
data = td->data;
|
|
|
|
dlen = td->count;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* MD5 has data length of 16, everything else is (much) larger */
|
|
|
|
if (sinfo->hashalgo && (data == NULL || dlen < 16)) {
|
2018-04-05 19:46:36 +08:00
|
|
|
rasprintf(&sinfo->msg, _("%s tag %u: invalid data %p (%u)"),
|
2017-04-28 15:32:24 +08:00
|
|
|
origin, td->tag, data, dlen);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (td->type == RPM_STRING_TYPE && td->size == 0)
|
|
|
|
td->size = dlen + 1;
|
|
|
|
|
2017-05-11 15:40:28 +08:00
|
|
|
if (tinfo->tagsize && (td->flags & RPMTD_IMMUTABLE) &&
|
|
|
|
tinfo->tagsize != td->size) {
|
2018-04-05 19:46:36 +08:00
|
|
|
rasprintf(&sinfo->msg, _("%s tag %u: invalid size %u"),
|
2017-04-28 15:32:24 +08:00
|
|
|
origin, td->tag, td->size);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sinfo->type == RPMSIG_SIGNATURE_TYPE) {
|
|
|
|
if (pgpPrtParams(data, dlen, PGPTAG_SIGNATURE, &sinfo->sig)) {
|
2018-04-05 19:46:36 +08:00
|
|
|
rasprintf(&sinfo->msg, _("%s tag %u: invalid OpenPGP signature"),
|
2017-04-28 15:32:24 +08:00
|
|
|
origin, td->tag);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
sinfo->hashalgo = pgpDigParamsAlgo(sinfo->sig, PGPVAL_HASHALGO);
|
|
|
|
sinfo->keyid = pgpGrab(sinfo->sig->signid+4, 4);
|
|
|
|
} else if (sinfo->type == RPMSIG_DIGEST_TYPE) {
|
2017-05-30 17:31:49 +08:00
|
|
|
if (td->type == RPM_BIN_TYPE) {
|
2017-04-28 15:32:24 +08:00
|
|
|
sinfo->dig = pgpHexStr(data, dlen);
|
2017-05-30 17:31:49 +08:00
|
|
|
} else {
|
|
|
|
if (!validHex(data, dlen)) {
|
2018-04-05 19:46:36 +08:00
|
|
|
rasprintf(&sinfo->msg,
|
|
|
|
_("%s: tag %u: invalid hex"), origin, td->tag);
|
2017-05-30 17:31:49 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
2017-04-28 15:32:24 +08:00
|
|
|
sinfo->dig = xstrdup(data);
|
2017-05-30 17:31:49 +08:00
|
|
|
}
|
2017-04-28 15:32:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sinfo->hashalgo)
|
2017-05-15 16:14:18 +08:00
|
|
|
sinfo->id = (td->tag << 16) | rpmtdGetIndex(td);
|
2017-04-28 15:32:24 +08:00
|
|
|
|
|
|
|
rc = RPMRC_OK;
|
|
|
|
|
|
|
|
exit:
|
2018-04-05 19:46:36 +08:00
|
|
|
sinfo->rc = rc;
|
|
|
|
return;
|
2017-04-28 15:32:24 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 18:05:20 +08:00
|
|
|
static void rpmsinfoFini(struct rpmsinfo_s *sinfo)
|
2017-04-28 15:32:24 +08:00
|
|
|
{
|
|
|
|
if (sinfo) {
|
|
|
|
if (sinfo->type == RPMSIG_SIGNATURE_TYPE)
|
|
|
|
pgpDigParamsFree(sinfo->sig);
|
|
|
|
else if (sinfo->type == RPMSIG_DIGEST_TYPE)
|
|
|
|
free(sinfo->dig);
|
2018-04-05 19:46:36 +08:00
|
|
|
free(sinfo->msg);
|
2017-05-24 16:20:35 +08:00
|
|
|
free(sinfo->descr);
|
2017-04-28 15:32:24 +08:00
|
|
|
memset(sinfo, 0, sizeof(*sinfo));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-12 18:05:20 +08:00
|
|
|
static int rpmsinfoDisabled(const struct rpmsinfo_s *sinfo, rpmVSFlags vsflags)
|
2017-04-28 15:32:24 +08:00
|
|
|
{
|
|
|
|
if (!(sinfo->type & RPMSIG_VERIFIABLE_TYPE))
|
|
|
|
return 1;
|
|
|
|
if (vsflags & sinfo->disabler)
|
|
|
|
return 1;
|
|
|
|
if ((vsflags & RPMVSF_NEEDPAYLOAD) && (sinfo->range & RPMSIG_PAYLOAD))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-22 17:32:32 +08:00
|
|
|
static void rpmvsReserve(struct rpmvs_s *vs, int n)
|
|
|
|
{
|
|
|
|
if (vs->nsigs + n >= vs->nalloced) {
|
|
|
|
vs->nalloced = (vs->nsigs * 2) + n;
|
|
|
|
vs->sigs = xrealloc(vs->sigs, vs->nalloced * sizeof(*vs->sigs));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-24 16:20:35 +08:00
|
|
|
const char *rpmsinfoDescr(struct rpmsinfo_s *sinfo)
|
|
|
|
{
|
|
|
|
if (sinfo->descr == NULL) {
|
|
|
|
char *t;
|
|
|
|
switch (sinfo->type) {
|
|
|
|
case RPMSIG_DIGEST_TYPE:
|
|
|
|
rasprintf(&sinfo->descr, _("%s%s %s"),
|
|
|
|
rangeName(sinfo->range),
|
|
|
|
pgpValString(PGPVAL_HASHALGO, sinfo->hashalgo),
|
|
|
|
_("digest"));
|
|
|
|
break;
|
|
|
|
case RPMSIG_SIGNATURE_TYPE:
|
|
|
|
t = sinfo->sig ? pgpIdentItem(sinfo->sig) : NULL;
|
|
|
|
rasprintf(&sinfo->descr, _("%s%s"),
|
|
|
|
rangeName(sinfo->range), t ? t : _("signature"));
|
|
|
|
free(t);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sinfo->descr;
|
|
|
|
}
|
|
|
|
|
2018-04-05 19:46:36 +08:00
|
|
|
char *rpmsinfoMsg(struct rpmsinfo_s *sinfo)
|
2017-05-24 17:17:46 +08:00
|
|
|
{
|
|
|
|
char *msg = NULL;
|
2018-04-05 19:46:36 +08:00
|
|
|
if (sinfo->msg) {
|
2017-05-24 17:17:46 +08:00
|
|
|
rasprintf(&msg, "%s: %s (%s)",
|
2018-04-05 19:46:36 +08:00
|
|
|
rpmsinfoDescr(sinfo), rpmSigString(sinfo->rc), sinfo->msg);
|
2017-05-24 17:17:46 +08:00
|
|
|
} else {
|
2018-04-05 19:46:36 +08:00
|
|
|
rasprintf(&msg, "%s: %s",
|
|
|
|
rpmsinfoDescr(sinfo), rpmSigString(sinfo->rc));
|
2017-05-24 17:17:46 +08:00
|
|
|
}
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2018-04-05 18:58:44 +08:00
|
|
|
static void rpmvsAppend(struct rpmvs_s *sis, hdrblob blob,
|
|
|
|
const struct vfyinfo_s *vi, const struct vfytag_s *ti)
|
2017-04-28 15:32:24 +08:00
|
|
|
{
|
2018-04-05 19:10:37 +08:00
|
|
|
if (rpmsinfoDisabled(&vi->vi, sis->vsflags))
|
|
|
|
return;
|
|
|
|
|
2017-04-28 15:32:24 +08:00
|
|
|
struct rpmtd_s td;
|
2018-04-05 18:58:44 +08:00
|
|
|
rpmRC rc = hdrblobGet(blob, vi->tag, &td);
|
2017-05-22 17:32:32 +08:00
|
|
|
|
|
|
|
if (rc == RPMRC_OK) {
|
2017-05-12 16:25:19 +08:00
|
|
|
const char *o = (blob->il > blob->ril) ? _("header") : _("package");
|
2017-04-28 15:32:24 +08:00
|
|
|
int ix;
|
2017-05-22 17:32:32 +08:00
|
|
|
|
|
|
|
rpmvsReserve(sis, rpmtdCount(&td));
|
|
|
|
|
|
|
|
while ((ix = rpmtdNext(&td)) >= 0) {
|
2018-04-05 19:46:36 +08:00
|
|
|
rpmsinfoInit(vi, ti, &td, o, &sis->sigs[sis->nsigs]);
|
2017-04-28 15:32:24 +08:00
|
|
|
sis->nsigs++;
|
|
|
|
}
|
|
|
|
rpmtdFreeData(&td);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-05 18:58:44 +08:00
|
|
|
void rpmvsAppendTag(struct rpmvs_s *vs, hdrblob blob, rpmTagVal tag)
|
|
|
|
{
|
|
|
|
int ix = sinfoLookup(tag);
|
|
|
|
if (ix >= 0) {
|
|
|
|
const struct vfyinfo_s *vi = &rpmvfyitems[ix];
|
|
|
|
const struct vfytag_s *ti = &rpmvfytags[ix];
|
|
|
|
rpmvsAppend(vs, blob, vi, ti);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-28 15:32:24 +08:00
|
|
|
struct rpmvs_s *rpmvsCreate(hdrblob blob, rpmVSFlags vsflags)
|
|
|
|
{
|
2018-04-05 18:58:44 +08:00
|
|
|
const struct vfyinfo_s *si = &rpmvfyitems[0];
|
|
|
|
const struct vfytag_s *ti = &rpmvfytags[0];
|
2017-04-28 15:32:24 +08:00
|
|
|
struct rpmvs_s *sis = xcalloc(1, sizeof(*sis));
|
2018-04-05 19:10:37 +08:00
|
|
|
sis->vsflags = vsflags;
|
2017-04-28 15:32:24 +08:00
|
|
|
|
2017-05-22 17:32:32 +08:00
|
|
|
rpmvsReserve(sis, 2); /* XXX bump this up later */
|
2017-04-28 15:32:24 +08:00
|
|
|
|
2018-04-05 18:58:44 +08:00
|
|
|
for (; si->tag && ti->tag; si++, ti++) {
|
|
|
|
rpmvsAppend(sis, blob, si, ti);
|
2017-04-28 15:32:24 +08:00
|
|
|
}
|
|
|
|
return sis;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct rpmvs_s *rpmvsFree(struct rpmvs_s *sis)
|
|
|
|
{
|
|
|
|
if (sis) {
|
|
|
|
for (int i = 0; i < sis->nsigs; i++) {
|
|
|
|
rpmsinfoFini(&sis->sigs[i]);
|
|
|
|
}
|
|
|
|
free(sis->sigs);
|
|
|
|
free(sis);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rpmvsInitDigests(struct rpmvs_s *sis, int range, rpmDigestBundle bundle)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < sis->nsigs; i++) {
|
|
|
|
struct rpmsinfo_s *sinfo = &sis->sigs[i];
|
|
|
|
if (sinfo->range & range) {
|
2018-04-05 19:46:36 +08:00
|
|
|
if (sinfo->rc == RPMRC_OK)
|
2017-04-28 15:32:24 +08:00
|
|
|
rpmDigestBundleAddID(bundle, sinfo->hashalgo, sinfo->id, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int rpmvsVerifyItems(struct rpmvs_s *sis, int range, rpmDigestBundle bundle,
|
|
|
|
rpmKeyring keyring, rpmsinfoCb cb, void *cbdata)
|
|
|
|
{
|
|
|
|
int failed = 0;
|
2018-03-08 19:22:49 +08:00
|
|
|
int cont = 1;
|
2017-04-28 15:32:24 +08:00
|
|
|
|
2018-03-08 19:22:49 +08:00
|
|
|
for (int i = 0; i < sis->nsigs && cont; i++) {
|
2017-04-28 15:32:24 +08:00
|
|
|
struct rpmsinfo_s *sinfo = &sis->sigs[i];
|
|
|
|
|
|
|
|
if (sinfo->range == range) {
|
2018-04-05 19:46:36 +08:00
|
|
|
if (sinfo->rc == RPMRC_OK) {
|
2017-04-28 15:32:24 +08:00
|
|
|
DIGEST_CTX ctx = rpmDigestBundleDupCtx(bundle, sinfo->id);
|
2018-04-05 19:46:36 +08:00
|
|
|
rpmVerifySignature(keyring, sinfo, ctx);
|
2017-04-28 15:32:24 +08:00
|
|
|
rpmDigestFinal(ctx, NULL, NULL, 0);
|
|
|
|
rpmDigestBundleFinal(bundle, sinfo->id, NULL, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cb)
|
2018-04-05 19:46:36 +08:00
|
|
|
cont = cb(sinfo, cbdata);
|
2017-04-28 15:32:24 +08:00
|
|
|
|
2018-04-05 19:46:36 +08:00
|
|
|
if (sinfo->rc != RPMRC_OK)
|
2017-04-28 15:32:24 +08:00
|
|
|
failed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char * rpmSigString(rpmRC res)
|
|
|
|
{
|
|
|
|
const char * str;
|
|
|
|
switch (res) {
|
|
|
|
case RPMRC_OK: str = "OK"; break;
|
|
|
|
case RPMRC_FAIL: str = "BAD"; break;
|
|
|
|
case RPMRC_NOKEY: str = "NOKEY"; break;
|
|
|
|
case RPMRC_NOTTRUSTED: str = "NOTTRUSTED"; break;
|
|
|
|
default:
|
|
|
|
case RPMRC_NOTFOUND: str = "UNKNOWN"; break;
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *rangeName(int range)
|
|
|
|
{
|
|
|
|
switch (range) {
|
|
|
|
case RPMSIG_HEADER: return _("Header ");
|
|
|
|
case RPMSIG_PAYLOAD: return _("Payload ");
|
|
|
|
}
|
|
|
|
/* trad. output for (RPMSIG_HEADER|RPMSIG_PAYLOAD) range is "" */
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2018-04-05 19:46:36 +08:00
|
|
|
static rpmRC verifyDigest(struct rpmsinfo_s *sinfo, DIGEST_CTX digctx)
|
2017-04-28 15:32:24 +08:00
|
|
|
{
|
|
|
|
rpmRC res = RPMRC_FAIL; /* assume failure */
|
|
|
|
char * dig = NULL;
|
|
|
|
size_t diglen = 0;
|
|
|
|
DIGEST_CTX ctx = rpmDigestDup(digctx);
|
|
|
|
|
2017-05-24 16:23:48 +08:00
|
|
|
if (rpmDigestFinal(ctx, (void **)&dig, &diglen, 1) || diglen == 0)
|
2017-04-28 15:32:24 +08:00
|
|
|
goto exit;
|
|
|
|
|
|
|
|
if (strcasecmp(sinfo->dig, dig) == 0) {
|
|
|
|
res = RPMRC_OK;
|
|
|
|
} else {
|
2018-04-05 19:46:36 +08:00
|
|
|
rasprintf(&sinfo->msg, "Expected %s != %s", sinfo->dig, dig);
|
2017-04-28 15:32:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
free(dig);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify DSA/RSA signature.
|
|
|
|
* @param keyring pubkey keyring
|
|
|
|
* @param sinfo OpenPGP signature parameters
|
|
|
|
* @param hashctx digest context
|
|
|
|
* @retval msg verbose success/failure text
|
|
|
|
* @return RPMRC_OK on success
|
|
|
|
*/
|
|
|
|
static rpmRC
|
|
|
|
verifySignature(rpmKeyring keyring, struct rpmsinfo_s *sinfo,
|
2018-04-05 19:46:36 +08:00
|
|
|
DIGEST_CTX hashctx)
|
2017-04-28 15:32:24 +08:00
|
|
|
{
|
|
|
|
rpmRC res = rpmKeyringVerifySig(keyring, sinfo->sig, hashctx);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2018-04-05 19:46:36 +08:00
|
|
|
static void
|
|
|
|
rpmVerifySignature(rpmKeyring keyring, struct rpmsinfo_s *sinfo, DIGEST_CTX ctx)
|
2017-04-28 15:32:24 +08:00
|
|
|
{
|
|
|
|
if (sinfo->type == RPMSIG_DIGEST_TYPE)
|
2018-04-05 19:46:36 +08:00
|
|
|
sinfo->rc = verifyDigest(sinfo, ctx);
|
2017-04-28 15:32:24 +08:00
|
|
|
else if (sinfo->type == RPMSIG_SIGNATURE_TYPE)
|
2018-04-05 19:46:36 +08:00
|
|
|
sinfo->rc = verifySignature(keyring, sinfo, ctx);
|
|
|
|
else
|
|
|
|
sinfo->rc = RPMRC_FAIL;
|
2017-04-28 15:32:24 +08:00
|
|
|
}
|