signature.c   signature.c 
skipping to change at line 155 skipping to change at line 155
* @return 0 on success, 1 on failure * @return 0 on success, 1 on failure
*/ */
static int makeGPGSignature(const char * file, rpmSigTag * sigTagp, static int makeGPGSignature(const char * file, rpmSigTag * sigTagp,
/*@out@*/ rpmuint8_t ** pktp, /*@out@*/ rpmuint32_t * pktlen p, /*@out@*/ rpmuint8_t ** pktp, /*@out@*/ rpmuint32_t * pktlen p,
/*@null@*/ const char * passPhrase) /*@null@*/ const char * passPhrase)
/*@globals rpmGlobalMacroContext, h_errno, /*@globals rpmGlobalMacroContext, h_errno,
fileSystem, internalState @*/ fileSystem, internalState @*/
/*@modifies *pktp, *pktlenp, *sigTagp, rpmGlobalMacroContext, /*@modifies *pktp, *pktlenp, *sigTagp, rpmGlobalMacroContext,
fileSystem, internalState @*/ fileSystem, internalState @*/
{ {
char * sigfile = alloca(strlen(file)+sizeof(".sig")); char * sigfile = (char *) alloca(strlen(file)+sizeof(".sig"));
pid_t pid; pid_t pid;
int status; int status;
int inpipe[2]; int inpipe[2];
FILE * fpipe; FILE * fpipe;
struct stat st; struct stat st;
const char * cmd; const char * cmd;
char *const *av; char *const *av;
pgpDig dig = NULL; pgpDig dig = NULL;
pgpDigParams sigp = NULL; pgpDigParams sigp = NULL;
const char * pw = NULL; const char * pw = NULL;
skipping to change at line 238 skipping to change at line 238
if (Stat(sigfile, &st)) { if (Stat(sigfile, &st)) {
/* GPG failed to write signature */ /* GPG failed to write signature */
if (sigfile) (void) Unlink(sigfile); /* Just in case */ if (sigfile) (void) Unlink(sigfile); /* Just in case */
rpmlog(RPMLOG_ERR, _("gpg failed to write signature\n")); rpmlog(RPMLOG_ERR, _("gpg failed to write signature\n"));
return 1; return 1;
} }
*pktlenp = (rpmuint32_t)st.st_size; *pktlenp = (rpmuint32_t)st.st_size;
rpmlog(RPMLOG_DEBUG, D_("GPG sig size: %u\n"), (unsigned)*pktlenp); rpmlog(RPMLOG_DEBUG, D_("GPG sig size: %u\n"), (unsigned)*pktlenp);
*pktp = xmalloc(*pktlenp); *pktp = (rpmuint8_t *) xmalloc(*pktlenp);
{ FD_t fd; { FD_t fd;
rc = 0; rc = 0;
fd = Fopen(sigfile, "r.ufdio"); fd = Fopen(sigfile, "r.ufdio");
if (fd != NULL && !Ferror(fd)) { if (fd != NULL && !Ferror(fd)) {
rc = (int) Fread(*pktp, sizeof((*pktp)[0]), *pktlenp, fd); rc = (int) Fread(*pktp, sizeof((*pktp)[0]), *pktlenp, fd);
if (sigfile) (void) Unlink(sigfile); if (sigfile) (void) Unlink(sigfile);
(void) Fclose(fd); (void) Fclose(fd);
} }
if ((rpmuint32_t)rc != *pktlenp) { if ((rpmuint32_t)rc != *pktlenp) {
*pktp = _free(*pktp); *pktp = _free(*pktp);
rpmlog(RPMLOG_ERR, _("unable to read the signature\n")); rpmlog(RPMLOG_ERR, _("unable to read the signature\n"));
return 1; return 1;
} }
} }
rpmlog(RPMLOG_DEBUG, D_("Got %u bytes of GPG sig\n"), (unsigned)*pktlen p); rpmlog(RPMLOG_DEBUG, D_("Got %u bytes of GPG sig\n"), (unsigned)*pktlen p);
/* Parse the signature, change signature tag as appropriate. */ /* Parse the signature, change signature tag as appropriate. */
dig = pgpDigNew(RPMVSF_DEFAULT, 0); dig = pgpDigNew(RPMVSF_DEFAULT, (pgpPubkeyAlgo)0);
(void) pgpPrtPkts(*pktp, *pktlenp, dig, 0); (void) pgpPrtPkts(*pktp, *pktlenp, dig, 0);
sigp = pgpGetSignature(dig); sigp = pgpGetSignature(dig);
/* Identify the type of signature being returned. */ /* Identify the type of signature being returned. */
switch (*sigTagp) { switch (*sigTagp) {
default: default:
assert(0); /* XXX never happens. */ assert(0); /* XXX never happens. */
/*@notreached@*/ break; /*@notreached@*/ break;
case RPMSIGTAG_SIZE: case RPMSIGTAG_SIZE:
skipping to change at line 303 skipping to change at line 303
* @param sigTag type of signature(s) to add * @param sigTag type of signature(s) to add
* @param passPhrase private key pass phrase * @param passPhrase private key pass phrase
* @return 0 on success, -1 on failure * @return 0 on success, -1 on failure
*/ */
/*@-mustmod@*/ /* sigh is modified */ /*@-mustmod@*/ /* sigh is modified */
static int makeHDRSignature(Header sigh, const char * file, rpmSigTag sigTa g, static int makeHDRSignature(Header sigh, const char * file, rpmSigTag sigTa g,
/*@null@*/ const char * passPhrase) /*@null@*/ const char * passPhrase)
/*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/ /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
/*@modifies sigh, sigTag, rpmGlobalMacroContext, fileSystem, interna lState @*/ /*@modifies sigh, sigTag, rpmGlobalMacroContext, fileSystem, interna lState @*/
{ {
HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); HE_t he = (HE_t) memset(alloca(sizeof(*he)), 0, sizeof(*he));
Header h = NULL; Header h = NULL;
FD_t fd = NULL; FD_t fd = NULL;
rpmuint8_t * pkt; rpmuint8_t * pkt;
rpmuint32_t pktlen; rpmuint32_t pktlen;
const char * fn = NULL; const char * fn = NULL;
const char * msg; const char * msg;
rpmRC rc; rpmRC rc;
int ret = -1; /* assume failure. */ int ret = -1; /* assume failure. */
int xx; int xx;
skipping to change at line 435 skipping to change at line 435
(void)headerFree(h); (void)headerFree(h);
h = NULL; h = NULL;
if (fd != NULL) (void) Fclose(fd); if (fd != NULL) (void) Fclose(fd);
return ret; return ret;
} }
/*@=mustmod@*/ /*@=mustmod@*/
int rpmAddSignature(Header sigh, const char * file, rpmSigTag sigTag, int rpmAddSignature(Header sigh, const char * file, rpmSigTag sigTag,
const char * passPhrase) const char * passPhrase)
{ {
HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); HE_t he = (HE_t) memset(alloca(sizeof(*he)), 0, sizeof(*he));
struct stat st; struct stat st;
rpmuint8_t * pkt; rpmuint8_t * pkt;
rpmuint32_t pktlen; rpmuint32_t pktlen;
int ret = -1; /* assume failure. */ int ret = -1; /* assume failure. */
int xx; int xx;
switch (sigTag) { switch (sigTag) {
default: default:
assert(0); /* XXX never happens. */ assert(0); /* XXX never happens. */
/*@notreached@*/ break; /*@notreached@*/ break;
skipping to change at line 463 skipping to change at line 463
he->c = 1; he->c = 1;
/*@-compmempass@*/ /*@-compmempass@*/
xx = headerPut(sigh, he, 0); xx = headerPut(sigh, he, 0);
/*@=compmempass@*/ /*@=compmempass@*/
if (!xx) if (!xx)
break; break;
ret = 0; ret = 0;
break; break;
case RPMSIGTAG_MD5: case RPMSIGTAG_MD5:
pktlen = 128/8; pktlen = 128/8;
pkt = memset(alloca(pktlen), 0, pktlen); pkt = (rpmuint8_t *) memset(alloca(pktlen), 0, pktlen);
if (dodigest(PGPHASHALGO_MD5, file, (unsigned char *)pkt, 0, NULL)) if (dodigest(PGPHASHALGO_MD5, file, (unsigned char *)pkt, 0, NULL))
break; break;
he->tag = (rpmTag) sigTag; he->tag = (rpmTag) sigTag;
he->t = RPM_BIN_TYPE; he->t = RPM_BIN_TYPE;
he->p.ptr = pkt; he->p.ptr = pkt;
he->c = pktlen; he->c = pktlen;
xx = headerPut(sigh, he, 0); xx = headerPut(sigh, he, 0);
if (!xx) if (!xx)
break; break;
ret = 0; ret = 0;
skipping to change at line 638 skipping to change at line 638
/* Identify the hash. */ /* Identify the hash. */
t = stpcpy(t, rpmDigestName(md5ctx)); t = stpcpy(t, rpmDigestName(md5ctx));
t = stpcpy(t, _(" digest: ")); t = stpcpy(t, _(" digest: "));
if (sig == NULL) { /* XXX can't happen, DYING */ if (sig == NULL) { /* XXX can't happen, DYING */
res = RPMRC_NOKEY; res = RPMRC_NOKEY;
t = stpcpy(t, rpmSigString(res)); t = stpcpy(t, rpmSigString(res));
goto exit; goto exit;
} }
{ rpmop op = pgpStatsAccumulator(dig, 10); /* RPMTS_OP_DIGEST * / { rpmop op = (rpmop)pgpStatsAccumulator(dig, 10); /* RPMTS_OP_DIGEST * /
(void) rpmswEnter(op, 0); (void) rpmswEnter(op, 0);
(void) rpmDigestFinal(rpmDigestDup(md5ctx), &md5sum, &md5len, 0); (void) rpmDigestFinal(rpmDigestDup(md5ctx), &md5sum, &md5len, 0);
(void) rpmswExit(op, 0); (void) rpmswExit(op, 0);
if (op != NULL) op->count--; /* XXX one too many */ if (op != NULL) op->count--; /* XXX one too many */
} }
if (md5len != siglen || memcmp(md5sum, sig, md5len)) { if (md5len != siglen || memcmp(md5sum, sig, md5len)) {
res = RPMRC_FAIL; res = RPMRC_FAIL;
t = stpcpy(t, rpmSigString(res)); t = stpcpy(t, rpmSigString(res));
t = stpcpy(t, " Expected("); t = stpcpy(t, " Expected(");
(void) pgpHexCvt(t, sig, siglen); (void) pgpHexCvt(t, (rpmuint8_t *)sig, siglen);
t += strlen(t); t += strlen(t);
t = stpcpy(t, ") != ("); t = stpcpy(t, ") != (");
} else { } else {
res = RPMRC_OK; res = RPMRC_OK;
t = stpcpy(t, rpmSigString(res)); t = stpcpy(t, rpmSigString(res));
t = stpcpy(t, " ("); t = stpcpy(t, " (");
} }
(void) pgpHexCvt(t, md5sum, md5len); (void) pgpHexCvt(t, md5sum, md5len);
t += strlen(t); t += strlen(t);
t = stpcpy(t, ")"); t = stpcpy(t, ")");
skipping to change at line 702 skipping to change at line 702
/* Identify the hash. */ /* Identify the hash. */
t = stpcpy(t, rpmDigestName(shactx)); t = stpcpy(t, rpmDigestName(shactx));
t = stpcpy(t, _(" digest: ")); t = stpcpy(t, _(" digest: "));
if (sig == NULL) { /* XXX can't happen, DYING */ if (sig == NULL) { /* XXX can't happen, DYING */
res = RPMRC_NOKEY; res = RPMRC_NOKEY;
t = stpcpy(t, rpmSigString(res)); t = stpcpy(t, rpmSigString(res));
goto exit; goto exit;
} }
{ rpmop op = pgpStatsAccumulator(dig, 10); /* RPMTS_OP_DIGEST * / { rpmop op = (rpmop)pgpStatsAccumulator(dig, 10); /* RPMTS_OP_DIGEST * /
(void) rpmswEnter(op, 0); (void) rpmswEnter(op, 0);
(void) rpmDigestFinal(rpmDigestDup(shactx), &SHA1, NULL, 1); (void) rpmDigestFinal(rpmDigestDup(shactx), &SHA1, NULL, 1);
(void) rpmswExit(op, 0); (void) rpmswExit(op, 0);
} }
if (SHA1 == NULL || strlen(SHA1) != strlen(sig) || strcmp(SHA1, sig)) { if (SHA1 == NULL
|| strlen(SHA1) != strlen((char *)sig)
|| strcmp(SHA1, (char *)sig))
{
res = RPMRC_FAIL; res = RPMRC_FAIL;
t = stpcpy(t, rpmSigString(res)); t = stpcpy(t, rpmSigString(res));
t = stpcpy(t, " Expected("); t = stpcpy(t, " Expected(");
t = stpcpy(t, sig); t = stpcpy(t, (char *)sig);
t = stpcpy(t, ") != ("); t = stpcpy(t, ") != (");
} else { } else {
res = RPMRC_OK; res = RPMRC_OK;
t = stpcpy(t, rpmSigString(res)); t = stpcpy(t, rpmSigString(res));
t = stpcpy(t, " ("); t = stpcpy(t, " (");
} }
if (SHA1) if (SHA1)
t = stpcpy(t, SHA1); t = stpcpy(t, SHA1);
t = stpcpy(t, ")"); t = stpcpy(t, ")");
skipping to change at line 780 skipping to change at line 783
/* Identify the RSA/hash. */ /* Identify the RSA/hash. */
{ const char * hashname = rpmDigestName(rsactx); { const char * hashname = rpmDigestName(rsactx);
t = stpcpy(t, " RSA"); t = stpcpy(t, " RSA");
if (strcmp(hashname, "UNKNOWN")) { if (strcmp(hashname, "UNKNOWN")) {
*t++ = '/'; *t++ = '/';
t = stpcpy(t, hashname); t = stpcpy(t, hashname);
} }
} }
t = stpcpy(t, _(" signature: ")); t = stpcpy(t, _(" signature: "));
{ rpmop op = pgpStatsAccumulator(dig, 10); /* RPMTS_OP_DIGEST * / { rpmop op = (rpmop)pgpStatsAccumulator(dig, 10); /* RPMTS_OP_DIGEST * /
DIGEST_CTX ctx = rpmDigestDup(rsactx); DIGEST_CTX ctx = rpmDigestDup(rsactx);
(void) rpmswEnter(op, 0); (void) rpmswEnter(op, 0);
if (sigp->hash != NULL) if (sigp->hash != NULL)
xx = rpmDigestUpdate(ctx, sigp->hash, sigp->hashlen); xx = rpmDigestUpdate(ctx, sigp->hash, sigp->hashlen);
if (sigp->version == (rpmuint8_t) 4) { if (sigp->version == (rpmuint8_t) 4) {
rpmuint8_t trailer[6]; rpmuint8_t trailer[6];
trailer[0] = sigp->version; trailer[0] = sigp->version;
trailer[1] = (rpmuint8_t)0xff; trailer[1] = (rpmuint8_t)0xff;
skipping to change at line 807 skipping to change at line 810
(void) rpmswExit(op, sigp->hashlen); (void) rpmswExit(op, sigp->hashlen);
if (op != NULL) op->count--; /* XXX one too many */ if (op != NULL) op->count--; /* XXX one too many */
if ((xx = pgpImplSetRSA(ctx, dig, sigp)) != 0) { if ((xx = pgpImplSetRSA(ctx, dig, sigp)) != 0) {
res = RPMRC_FAIL; res = RPMRC_FAIL;
goto exit; goto exit;
} }
} }
/* Retrieve the matching public key. */ /* Retrieve the matching public key. */
res = pgpFindPubkey(dig); res = (rpmRC) pgpFindPubkey(dig);
if (res != RPMRC_OK) if (res != RPMRC_OK)
goto exit; goto exit;
/* Verify the RSA signature. */ /* Verify the RSA signature. */
{ rpmop op = pgpStatsAccumulator(dig, 11); /* RPMTS_OP_SIGNATUR E */ { rpmop op = (rpmop)pgpStatsAccumulator(dig, 11); /* RPMTS_OP_SIGNATUR E */
(void) rpmswEnter(op, 0); (void) rpmswEnter(op, 0);
xx = pgpImplVerify(dig); xx = pgpImplVerify(dig);
(void) rpmswExit(op, 0); (void) rpmswExit(op, 0);
res = (xx ? RPMRC_OK : RPMRC_FAIL); res = (xx ? RPMRC_OK : RPMRC_FAIL);
} }
exit: exit:
/* Identify the pubkey fingerprint. */ /* Identify the pubkey fingerprint. */
t = stpcpy(t, rpmSigString(res)); t = stpcpy(t, rpmSigString(res));
if (sigp != NULL) { if (sigp != NULL) {
skipping to change at line 882 skipping to change at line 885
/* Identify the DSA/hash. */ /* Identify the DSA/hash. */
{ const char * hashname = rpmDigestName(dsactx); { const char * hashname = rpmDigestName(dsactx);
t = stpcpy(t, " DSA"); t = stpcpy(t, " DSA");
if (strcmp(hashname, "UNKNOWN") && strcmp(hashname, "SHA1")) { if (strcmp(hashname, "UNKNOWN") && strcmp(hashname, "SHA1")) {
*t++ = '/'; *t++ = '/';
t = stpcpy(t, hashname); t = stpcpy(t, hashname);
} }
} }
t = stpcpy(t, _(" signature: ")); t = stpcpy(t, _(" signature: "));
{ rpmop op = pgpStatsAccumulator(dig, 10); /* RPMTS_OP_DIGEST * / { rpmop op = (rpmop)pgpStatsAccumulator(dig, 10); /* RPMTS_OP_DIGEST * /
DIGEST_CTX ctx = rpmDigestDup(dsactx); DIGEST_CTX ctx = rpmDigestDup(dsactx);
(void) rpmswEnter(op, 0); (void) rpmswEnter(op, 0);
if (sigp->hash != NULL) if (sigp->hash != NULL)
xx = rpmDigestUpdate(ctx, sigp->hash, sigp->hashlen); xx = rpmDigestUpdate(ctx, sigp->hash, sigp->hashlen);
if (sigp->version == (rpmuint8_t) 4) { if (sigp->version == (rpmuint8_t) 4) {
rpmuint8_t trailer[6]; rpmuint8_t trailer[6];
trailer[0] = sigp->version; trailer[0] = sigp->version;
trailer[1] = (rpmuint8_t)0xff; trailer[1] = (rpmuint8_t)0xff;
skipping to change at line 909 skipping to change at line 912
(void) rpmswExit(op, sigp->hashlen); (void) rpmswExit(op, sigp->hashlen);
if (op != NULL) op->count--; /* XXX one too many */ if (op != NULL) op->count--; /* XXX one too many */
if (pgpImplSetDSA(ctx, dig, sigp)) { if (pgpImplSetDSA(ctx, dig, sigp)) {
res = RPMRC_FAIL; res = RPMRC_FAIL;
goto exit; goto exit;
} }
} }
/* Retrieve the matching public key. */ /* Retrieve the matching public key. */
res = pgpFindPubkey(dig); res = (rpmRC) pgpFindPubkey(dig);
if (res != RPMRC_OK) if (res != RPMRC_OK)
goto exit; goto exit;
/* Verify the DSA signature. */ /* Verify the DSA signature. */
{ rpmop op = pgpStatsAccumulator(dig, 11); /* RPMTS_OP_SIGNATUR E */ { rpmop op = (rpmop)pgpStatsAccumulator(dig, 11); /* RPMTS_OP_SIGNATUR E */
(void) rpmswEnter(op, 0); (void) rpmswEnter(op, 0);
xx = pgpImplVerify(dig); xx = pgpImplVerify(dig);
res = (xx ? RPMRC_OK : RPMRC_FAIL); res = (xx ? RPMRC_OK : RPMRC_FAIL);
(void) rpmswExit(op, 0); (void) rpmswExit(op, 0);
} }
exit: exit:
/* Identify the pubkey fingerprint. */ /* Identify the pubkey fingerprint. */
t = stpcpy(t, rpmSigString(res)); t = stpcpy(t, rpmSigString(res));
if (sigp != NULL) { if (sigp != NULL) {
skipping to change at line 939 skipping to change at line 942
if (_rpmhkp_debug) if (_rpmhkp_debug)
fprintf(stderr, "<-- %s(%p,%p,%p) res %d %s\n", __FUNCTION__, dig, t, dsact x, res, t); fprintf(stderr, "<-- %s(%p,%p,%p) res %d %s\n", __FUNCTION__, dig, t, dsact x, res, t);
return res; return res;
} }
rpmRC rpmRC
rpmVerifySignature(void * _dig, char * result) rpmVerifySignature(void * _dig, char * result)
{ {
pgpDig dig = _dig; pgpDig dig = (pgpDig) _dig;
const void * sig = pgpGetSig(dig); const void * sig = pgpGetSig(dig);
rpmuint32_t siglen = pgpGetSiglen(dig); rpmuint32_t siglen = pgpGetSiglen(dig);
rpmSigTag sigtag = pgpGetSigtag(dig); rpmSigTag sigtag = (rpmSigTag) pgpGetSigtag(dig);
rpmRC res; rpmRC res;
if (_rpmhkp_debug) if (_rpmhkp_debug)
fprintf(stderr, "--> %s(%p,%p) sig %p[%u]\n", __FUNCTION__, _dig, result, s ig, siglen); fprintf(stderr, "--> %s(%p,%p) sig %p[%u]\n", __FUNCTION__, _dig, result, s ig, siglen);
if (dig == NULL || sig == NULL || siglen == 0) { if (dig == NULL || sig == NULL || siglen == 0) {
sprintf(result, _("Verify signature: BAD PARAMETERS\n")); sprintf(result, _("Verify signature: BAD PARAMETERS\n"));
res = RPMRC_NOTFOUND; res = RPMRC_NOTFOUND;
goto exit; goto exit;
} }
 End of changes. 19 change blocks. 
19 lines changed or deleted 22 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/