diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/package.c | 35 | ||||
-rw-r--r-- | lib/rpmchecksig.c | 10 | ||||
-rw-r--r-- | lib/signature.h | 6 |
3 files changed, 17 insertions, 34 deletions
diff --git a/lib/package.c b/lib/package.c index b5e238e20..3df81c97a 100644 --- a/lib/package.c +++ b/lib/package.c @@ -20,8 +20,6 @@ #include "debug.h" -static int _print_pkts = 0; - static const unsigned int nkeyids_max = 256; static unsigned int nkeyids = 0; static unsigned int nextkeyid = 0; @@ -137,19 +135,12 @@ static int stashKeyid(pgpDigParams sigp) return 0; } -pgpDigParams parsePGPSig(rpmtd sigtd, const char *type, const char *fn, - pgpDig *digp) +int parsePGPSig(rpmtd sigtd, const char *type, const char *fn, + pgpDigParams *sig) { - int debug = (_print_pkts & rpmIsDebug()); - pgpDig dig = pgpNewDig(); - pgpDigParams sig = NULL; - - if ((pgpPrtPkts(sigtd->data, sigtd->count, dig, debug) == 0)) - sig = pgpDigGetParams(dig, PGPTAG_SIGNATURE); + int rc = pgpPrtParams(sigtd->data, sigtd->count, PGPTAG_SIGNATURE, sig); - if (sig) { - *digp = dig; - } else { + if (rc != 0) { if (type && fn) { rpmlog(RPMLOG_ERR, _("skipping %s %s with unverifiable signature\n"), type, fn); @@ -157,9 +148,8 @@ pgpDigParams parsePGPSig(rpmtd sigtd, const char *type, const char *fn, rpmlog(RPMLOG_ERR, _("skipping %s with unverifiable signature\n"), type); } - pgpFreeDig(dig); } - return sig; + return rc; } /* @@ -173,7 +163,6 @@ static rpmRC headerSigVerify(rpmKeyring keyring, rpmVSFlags vsflags, { size_t siglen = 0; rpmRC rc = RPMRC_FAIL; - pgpDig dig = NULL; pgpDigParams sig = NULL; struct rpmtd_s sigtd; struct entryInfo_s info, einfo; @@ -254,8 +243,7 @@ static rpmRC headerSigVerify(rpmKeyring keyring, rpmVSFlags vsflags, switch (info.tag) { case RPMTAG_RSAHEADER: case RPMTAG_DSAHEADER: - sig = parsePGPSig(&sigtd, "header", NULL, &dig); - if (sig == NULL) + if (parsePGPSig(&sigtd, "header", NULL, &sig)) goto exit; hashalgo = pgpDigParamsAlgo(sig, PGPVAL_HASHALGO); break; @@ -282,7 +270,7 @@ static rpmRC headerSigVerify(rpmKeyring keyring, rpmVSFlags vsflags, exit: rpmtdFreeData(&sigtd); - pgpFreeDig(dig); + pgpDigParamsFree(sig); return rc; } @@ -503,7 +491,6 @@ rpmRC rpmReadHeader(rpmts ts, FD_t fd, Header *hdrp, char ** msg) static rpmRC rpmpkgRead(rpmKeyring keyring, rpmVSFlags vsflags, FD_t fd, const char * fn, Header * hdrp) { - pgpDig dig = NULL; pgpDigParams sig = NULL; char buf[8*BUFSIZ]; ssize_t count; @@ -606,8 +593,7 @@ static rpmRC rpmpkgRead(rpmKeyring keyring, rpmVSFlags vsflags, switch (sigtag) { case RPMSIGTAG_RSA: case RPMSIGTAG_DSA: - sig = parsePGPSig(&sigtd, "package", fn, &dig); - if (sig == NULL) + if (parsePGPSig(&sigtd, "package", fn, &sig)) goto exit; /* fallthrough */ case RPMSIGTAG_SHA1: @@ -626,8 +612,7 @@ static rpmRC rpmpkgRead(rpmKeyring keyring, rpmVSFlags vsflags, case RPMSIGTAG_GPG: case RPMSIGTAG_PGP5: /* XXX legacy */ case RPMSIGTAG_PGP: - sig = parsePGPSig(&sigtd, "package", fn, &dig); - if (sig == NULL) + if (parsePGPSig(&sigtd, "package", fn, &sig)) goto exit; /* fallthrough */ case RPMSIGTAG_MD5: @@ -704,7 +689,7 @@ exit: rpmtdFreeData(&sigtd); rpmDigestFinal(ctx, NULL, NULL, 0); h = headerFree(h); - pgpFreeDig(dig); + pgpDigParamsFree(sig); sigh = rpmFreeSignature(sigh); return rc; } diff --git a/lib/rpmchecksig.c b/lib/rpmchecksig.c index 3624f41dc..d143bc8ef 100644 --- a/lib/rpmchecksig.c +++ b/lib/rpmchecksig.c @@ -248,7 +248,6 @@ static int rpmpkgVerifySigs(rpmKeyring keyring, rpmQueryFlags flags, char *untrustedKeys = NULL; struct rpmtd_s sigtd; rpmTagVal sigtag; - pgpDig dig = NULL; pgpDigParams sig = NULL; Header sigh = NULL; HeaderIterator hi = NULL; @@ -292,7 +291,7 @@ static int rpmpkgVerifySigs(rpmKeyring keyring, rpmQueryFlags flags, sigtag == RPMSIGTAG_DSA || sigtag == RPMSIGTAG_GPG) { unsigned int hashalgo; if (headerGet(sigh, sigtag, &sigtd, HEADERGET_DEFAULT)) { - sig = parsePGPSig(&sigtd, "package", fn, &dig); + parsePGPSig(&sigtd, "package", fn, &sig); rpmtdFreeData(&sigtd); } if (sig == NULL) goto exit; @@ -332,7 +331,7 @@ static int rpmpkgVerifySigs(rpmKeyring keyring, rpmQueryFlags flags, continue; /* Clean up parameters from previous sigtag. */ - pgpCleanDig(dig); + sig = pgpDigParamsFree(sig); switch (sigtd.tag) { case RPMSIGTAG_GPG: @@ -343,8 +342,7 @@ static int rpmpkgVerifySigs(rpmKeyring keyring, rpmQueryFlags flags, case RPMSIGTAG_DSA: if (nosignatures) continue; - sig = parsePGPSig(&sigtd, "package", fn, &dig); - if (sig == NULL) + if (parsePGPSig(&sigtd, "package", fn, &sig)) goto exit; ctx = rpmDigestBundleDupCtx(havekey ? plbundle : hdrbundle, pgpDigParamsAlgo(sig, PGPVAL_HASHALGO)); @@ -401,7 +399,7 @@ exit: fdSetBundle(fd, NULL); /* XXX avoid double-free from fd close */ sigh = rpmFreeSignature(sigh); hi = headerFreeIterator(hi); - pgpFreeDig(dig); + pgpDigParamsFree(sig); return res; } diff --git a/lib/signature.h b/lib/signature.h index 136b70db8..18bbdc709 100644 --- a/lib/signature.h +++ b/lib/signature.h @@ -73,10 +73,10 @@ rpmRC rpmVerifySignature(rpmKeyring keyring, rpmtd sigtd, pgpDigParams sig, */ Header rpmFreeSignature(Header h); -/* Parse the parameters from the OpenPGP packets that will be needed. */ +/* Dumb wrapper around pgpPrtParams() to log some error messages on failure */ RPM_GNUC_INTERNAL -pgpDigParams parsePGPSig(rpmtd sigtd, const char *type, const char *fn, - pgpDig *digp); +int parsePGPSig(rpmtd sigtd, const char *type, const char *fn, + pgpDigParams *sig); #ifdef __cplusplus } |