2000-08-28 03:27:03 +08:00
|
|
|
/** \ingroup signature
|
|
|
|
* \file lib/signature.c
|
|
|
|
*/
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1997-01-18 00:22:08 +08:00
|
|
|
|
2001-10-19 21:51:20 +08:00
|
|
|
#include "rpmio_internal.h"
|
1999-07-14 05:37:57 +08:00
|
|
|
#include <rpmlib.h>
|
2001-06-18 06:18:03 +08:00
|
|
|
#include <rpmmacro.h> /* XXX for rpmGetPath() */
|
1996-02-19 10:32:11 +08:00
|
|
|
|
2001-06-18 06:18:03 +08:00
|
|
|
#include "misc.h" /* XXX for dosetenv() and makeTempFile() */
|
2001-10-22 05:43:32 +08:00
|
|
|
#include "legacy.h" /* XXX for mdbinfile() */
|
1996-06-29 02:48:34 +08:00
|
|
|
#include "rpmlead.h"
|
1996-10-15 11:15:30 +08:00
|
|
|
#include "signature.h"
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
1996-02-19 10:32:11 +08:00
|
|
|
|
2000-10-29 01:16:25 +08:00
|
|
|
/*@access Header@*/ /* XXX compared with NULL */
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@access FD_t@*/ /* XXX compared with NULL */
|
2001-10-22 05:43:32 +08:00
|
|
|
/*@access pgpDig@*/
|
2000-10-29 01:16:25 +08:00
|
|
|
|
2001-10-21 06:31:09 +08:00
|
|
|
/*@-mustmod@*/ /* FIX: internalState not modified? */
|
1999-03-23 01:31:53 +08:00
|
|
|
int rpmLookupSignatureType(int action)
|
1996-06-20 11:10:44 +08:00
|
|
|
{
|
1999-09-11 07:48:56 +08:00
|
|
|
static int disabled = 0;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case RPMLOOKUPSIG_DISABLE:
|
|
|
|
disabled = -2;
|
|
|
|
break;
|
|
|
|
case RPMLOOKUPSIG_ENABLE:
|
|
|
|
disabled = 0;
|
1999-09-18 05:08:32 +08:00
|
|
|
/*@fallthrough@*/
|
1999-09-11 07:48:56 +08:00
|
|
|
case RPMLOOKUPSIG_QUERY:
|
|
|
|
if (disabled)
|
|
|
|
break; /* Disabled */
|
|
|
|
{ const char *name = rpmExpand("%{_signature}", NULL);
|
|
|
|
if (!(name && *name != '%'))
|
1999-03-23 01:31:53 +08:00
|
|
|
rc = 0;
|
2001-01-04 04:19:27 +08:00
|
|
|
else if (!xstrcasecmp(name, "none"))
|
1999-09-11 07:48:56 +08:00
|
|
|
rc = 0;
|
2001-01-04 04:19:27 +08:00
|
|
|
else if (!xstrcasecmp(name, "pgp"))
|
1999-09-11 07:48:56 +08:00
|
|
|
rc = RPMSIGTAG_PGP;
|
2001-01-04 04:19:27 +08:00
|
|
|
else if (!xstrcasecmp(name, "pgp5")) /* XXX legacy */
|
1999-09-11 07:48:56 +08:00
|
|
|
rc = RPMSIGTAG_PGP;
|
2001-01-04 04:19:27 +08:00
|
|
|
else if (!xstrcasecmp(name, "gpg"))
|
1999-09-11 07:48:56 +08:00
|
|
|
rc = RPMSIGTAG_GPG;
|
|
|
|
else
|
|
|
|
rc = -1; /* Invalid %_signature spec in macro file */
|
2001-04-29 09:05:43 +08:00
|
|
|
name = _free(name);
|
1999-09-11 07:48:56 +08:00
|
|
|
} break;
|
1999-03-23 01:31:53 +08:00
|
|
|
}
|
1999-03-21 05:09:47 +08:00
|
|
|
return rc;
|
1996-06-20 11:10:44 +08:00
|
|
|
}
|
2001-10-21 06:31:09 +08:00
|
|
|
/*@=mustmod@*/
|
1996-06-20 11:10:44 +08:00
|
|
|
|
1999-03-22 02:43:22 +08:00
|
|
|
/* rpmDetectPGPVersion() returns the absolute path to the "pgp" */
|
|
|
|
/* executable of the requested version, or NULL when none found. */
|
|
|
|
|
2001-02-12 06:02:29 +08:00
|
|
|
const char * rpmDetectPGPVersion(pgpVersion * pgpVer)
|
1999-03-22 02:43:22 +08:00
|
|
|
{
|
2001-10-19 21:51:20 +08:00
|
|
|
/* Actually this should support having more then one pgp version. */
|
1999-03-22 02:43:22 +08:00
|
|
|
/* At the moment only one version is possible since we only */
|
1999-03-23 01:31:53 +08:00
|
|
|
/* have one %_pgpbin and one %_pgp_path. */
|
1999-03-22 02:43:22 +08:00
|
|
|
|
1999-09-11 07:48:56 +08:00
|
|
|
static pgpVersion saved_pgp_version = PGP_UNKNOWN;
|
1999-03-22 02:43:22 +08:00
|
|
|
const char *pgpbin = rpmGetPath("%{_pgpbin}", NULL);
|
|
|
|
|
1999-09-11 07:48:56 +08:00
|
|
|
if (saved_pgp_version == PGP_UNKNOWN) {
|
1999-03-22 02:43:22 +08:00
|
|
|
char *pgpvbin;
|
2000-12-13 04:03:45 +08:00
|
|
|
struct stat st;
|
2001-10-19 21:51:20 +08:00
|
|
|
|
2000-10-29 01:16:25 +08:00
|
|
|
if (!(pgpbin && pgpbin[0] != '%')) {
|
2001-04-29 09:05:43 +08:00
|
|
|
pgpbin = _free(pgpbin);
|
1999-09-11 07:48:56 +08:00
|
|
|
saved_pgp_version = -1;
|
1999-03-22 02:43:22 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2000-10-29 01:16:25 +08:00
|
|
|
pgpvbin = (char *)alloca(strlen(pgpbin) + sizeof("v"));
|
|
|
|
(void)stpcpy(stpcpy(pgpvbin, pgpbin), "v");
|
1999-03-22 02:43:22 +08:00
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
if (stat(pgpvbin, &st) == 0)
|
1999-09-11 07:48:56 +08:00
|
|
|
saved_pgp_version = PGP_5;
|
2000-12-13 04:03:45 +08:00
|
|
|
else if (stat(pgpbin, &st) == 0)
|
1999-09-11 07:48:56 +08:00
|
|
|
saved_pgp_version = PGP_2;
|
1999-03-22 02:43:22 +08:00
|
|
|
else
|
1999-09-11 07:48:56 +08:00
|
|
|
saved_pgp_version = PGP_NOTDETECTED;
|
1999-03-22 02:43:22 +08:00
|
|
|
}
|
|
|
|
|
2001-05-04 05:00:18 +08:00
|
|
|
if (pgpVer && pgpbin)
|
1999-09-11 07:48:56 +08:00
|
|
|
*pgpVer = saved_pgp_version;
|
|
|
|
return pgpbin;
|
1999-03-22 02:43:22 +08:00
|
|
|
}
|
|
|
|
|
2001-02-13 03:02:15 +08:00
|
|
|
/**
|
|
|
|
* Check package size.
|
|
|
|
* @todo rpmio: use fdSize rather than fstat(2) to get file size.
|
|
|
|
* @param fd package file handle
|
|
|
|
* @param siglen signature header size
|
|
|
|
* @param pad signature padding
|
|
|
|
* @param datalen length of header+payload
|
|
|
|
* @return rpmRC return code
|
|
|
|
*/
|
|
|
|
static inline rpmRC checkSize(FD_t fd, int siglen, int pad, int datalen)
|
2001-10-19 21:51:20 +08:00
|
|
|
/*@globals fileSystem @*/
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@modifies fileSystem @*/
|
1999-07-14 07:33:02 +08:00
|
|
|
{
|
2000-12-13 04:03:45 +08:00
|
|
|
struct stat st;
|
2001-02-13 03:02:15 +08:00
|
|
|
rpmRC rc;
|
1999-07-14 07:33:02 +08:00
|
|
|
|
2001-02-13 03:02:15 +08:00
|
|
|
if (fstat(Fileno(fd), &st))
|
|
|
|
return RPMRC_FAIL;
|
1999-07-14 07:33:02 +08:00
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
if (!S_ISREG(st.st_mode)) {
|
|
|
|
rpmMessage(RPMMESS_DEBUG,
|
|
|
|
_("file is not regular -- skipping size check\n"));
|
2001-02-13 03:02:15 +08:00
|
|
|
return RPMRC_OK;
|
1999-07-14 07:33:02 +08:00
|
|
|
}
|
2001-02-13 03:02:15 +08:00
|
|
|
|
2001-10-16 22:58:57 +08:00
|
|
|
/*@-sizeoftype@*/
|
2001-02-13 03:02:15 +08:00
|
|
|
rc = (((sizeof(struct rpmlead) + siglen + pad + datalen) - st.st_size)
|
|
|
|
? RPMRC_BADSIZE : RPMRC_OK);
|
|
|
|
|
|
|
|
rpmMessage((rc == RPMRC_OK ? RPMMESS_DEBUG : RPMMESS_WARNING),
|
2000-12-13 04:03:45 +08:00
|
|
|
_("Expected size: %12d = lead(%d)+sigs(%d)+pad(%d)+data(%d)\n"),
|
2001-04-29 09:05:43 +08:00
|
|
|
(int)sizeof(struct rpmlead)+siglen+pad+datalen,
|
|
|
|
(int)sizeof(struct rpmlead), siglen, pad, datalen);
|
2001-10-16 22:58:57 +08:00
|
|
|
/*@=sizeoftype@*/
|
2001-02-13 03:02:15 +08:00
|
|
|
rpmMessage((rc == RPMRC_OK ? RPMMESS_DEBUG : RPMMESS_WARNING),
|
2001-04-29 09:05:43 +08:00
|
|
|
_(" Actual size: %12d\n"), (int)st.st_size);
|
2000-12-13 04:03:45 +08:00
|
|
|
|
2001-02-13 03:02:15 +08:00
|
|
|
return rc;
|
1999-07-14 07:33:02 +08:00
|
|
|
}
|
|
|
|
|
2001-02-13 03:02:15 +08:00
|
|
|
rpmRC rpmReadSignature(FD_t fd, Header * headerp, sigType sig_type)
|
1996-02-19 10:32:11 +08:00
|
|
|
{
|
2000-11-16 04:38:58 +08:00
|
|
|
byte buf[2048];
|
1996-07-08 06:26:31 +08:00
|
|
|
int sigSize, pad;
|
|
|
|
int_32 type, count;
|
1996-07-08 06:19:32 +08:00
|
|
|
int_32 *archSize;
|
2000-11-07 21:16:43 +08:00
|
|
|
Header h = NULL;
|
2001-02-13 03:02:15 +08:00
|
|
|
rpmRC rc = RPMRC_FAIL; /* assume failure */
|
1996-07-08 06:19:32 +08:00
|
|
|
|
1999-09-11 07:48:56 +08:00
|
|
|
if (headerp)
|
|
|
|
*headerp = NULL;
|
2000-12-30 05:44:37 +08:00
|
|
|
|
2001-09-21 23:07:11 +08:00
|
|
|
buf[0] = 0;
|
2001-02-13 00:33:08 +08:00
|
|
|
switch (sig_type) {
|
|
|
|
case RPMSIGTYPE_NONE:
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("No signature\n"));
|
2001-02-13 03:02:15 +08:00
|
|
|
rc = RPMRC_OK;
|
1996-02-19 10:32:11 +08:00
|
|
|
break;
|
2001-02-13 00:33:08 +08:00
|
|
|
case RPMSIGTYPE_PGP262_1024:
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("Old PGP signature\n"));
|
1996-06-20 11:10:44 +08:00
|
|
|
/* These are always 256 bytes */
|
2001-10-17 01:42:18 +08:00
|
|
|
/*@-type@*/ /* FIX: eliminate timedRead @*/
|
1999-09-11 07:48:56 +08:00
|
|
|
if (timedRead(fd, buf, 256) != 256)
|
2000-11-07 21:16:43 +08:00
|
|
|
break;
|
2001-10-17 01:42:18 +08:00
|
|
|
/*@=type@*/
|
2000-11-07 21:16:43 +08:00
|
|
|
h = headerNew();
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddEntry(h, RPMSIGTAG_PGP, RPM_BIN_TYPE, buf, 152);
|
2001-02-13 03:02:15 +08:00
|
|
|
rc = RPMRC_OK;
|
1996-02-19 10:32:11 +08:00
|
|
|
break;
|
2001-02-13 00:33:08 +08:00
|
|
|
case RPMSIGTYPE_MD5:
|
|
|
|
case RPMSIGTYPE_MD5_PGP:
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmError(RPMERR_BADSIGTYPE,
|
2001-01-16 07:09:42 +08:00
|
|
|
_("Old (internal-only) signature! How did you get that!?\n"));
|
2000-11-07 21:16:43 +08:00
|
|
|
break;
|
2001-02-13 00:33:08 +08:00
|
|
|
case RPMSIGTYPE_HEADERSIG:
|
|
|
|
case RPMSIGTYPE_DISABLE:
|
1996-07-08 06:19:32 +08:00
|
|
|
/* This is a new style signature */
|
1996-11-19 02:02:36 +08:00
|
|
|
h = headerRead(fd, HEADER_MAGIC_YES);
|
1999-09-11 07:48:56 +08:00
|
|
|
if (h == NULL)
|
2000-11-07 21:16:43 +08:00
|
|
|
break;
|
2001-02-13 03:02:15 +08:00
|
|
|
|
|
|
|
rc = RPMRC_OK;
|
1996-11-19 02:02:36 +08:00
|
|
|
sigSize = headerSizeof(h, HEADER_MAGIC_YES);
|
2000-12-03 05:53:44 +08:00
|
|
|
|
|
|
|
/* XXX Legacy headers have a HEADER_IMAGE tag added. */
|
|
|
|
if (headerIsEntry(h, RPMTAG_HEADERIMAGE))
|
|
|
|
sigSize -= (16 + 16);
|
|
|
|
|
1996-07-08 06:19:32 +08:00
|
|
|
pad = (8 - (sigSize % 8)) % 8; /* 8-byte pad */
|
2001-02-13 00:33:08 +08:00
|
|
|
if (sig_type == RPMSIGTYPE_HEADERSIG) {
|
2001-02-12 06:02:29 +08:00
|
|
|
if (! headerGetEntry(h, RPMSIGTAG_SIZE, &type,
|
|
|
|
(void **)&archSize, &count))
|
|
|
|
break;
|
2001-02-13 03:02:15 +08:00
|
|
|
rc = checkSize(fd, sigSize, pad, *archSize);
|
1996-06-20 11:10:44 +08:00
|
|
|
}
|
2001-10-17 01:42:18 +08:00
|
|
|
/*@-type@*/ /* FIX: eliminate timedRead @*/
|
2001-02-13 03:02:15 +08:00
|
|
|
if (pad && timedRead(fd, buf, pad) != pad)
|
|
|
|
rc = RPMRC_SHORTREAD;
|
2001-10-17 01:42:18 +08:00
|
|
|
/*@=type@*/
|
1996-02-19 10:32:11 +08:00
|
|
|
break;
|
2001-02-12 06:02:29 +08:00
|
|
|
default:
|
2000-11-07 21:16:43 +08:00
|
|
|
break;
|
1996-02-19 10:32:11 +08:00
|
|
|
}
|
|
|
|
|
2001-09-25 05:53:14 +08:00
|
|
|
if (headerp && rc == 0)
|
2000-11-07 21:16:43 +08:00
|
|
|
*headerp = h;
|
2001-09-25 05:53:14 +08:00
|
|
|
else
|
2001-05-23 22:25:19 +08:00
|
|
|
h = headerFree(h);
|
2000-11-07 21:16:43 +08:00
|
|
|
|
|
|
|
return rc;
|
1996-02-19 10:32:11 +08:00
|
|
|
}
|
|
|
|
|
2001-02-12 06:02:29 +08:00
|
|
|
int rpmWriteSignature(FD_t fd, Header h)
|
1996-02-20 14:02:32 +08:00
|
|
|
{
|
2000-12-03 05:53:44 +08:00
|
|
|
static byte buf[8] = "\000\000\000\000\000\000\000\000";
|
2001-02-12 06:02:29 +08:00
|
|
|
int sigSize, pad;
|
|
|
|
int rc;
|
2001-10-19 21:51:20 +08:00
|
|
|
|
2001-02-12 06:02:29 +08:00
|
|
|
rc = headerWrite(fd, h, HEADER_MAGIC_YES);
|
1999-08-24 23:18:43 +08:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2001-02-12 06:02:29 +08:00
|
|
|
sigSize = headerSizeof(h, HEADER_MAGIC_YES);
|
1996-07-08 06:19:32 +08:00
|
|
|
pad = (8 - (sigSize % 8)) % 8;
|
|
|
|
if (pad) {
|
1999-11-11 06:09:49 +08:00
|
|
|
if (Fwrite(buf, sizeof(buf[0]), pad, fd) != pad)
|
1999-08-24 23:18:43 +08:00
|
|
|
rc = 1;
|
1996-06-29 02:48:34 +08:00
|
|
|
}
|
2001-02-12 06:02:29 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("Signature: size(%d)+pad(%d)\n"), sigSize, pad);
|
1999-08-24 23:18:43 +08:00
|
|
|
return rc;
|
1996-07-08 06:19:32 +08:00
|
|
|
}
|
1996-06-29 02:48:34 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
Header rpmNewSignature(void)
|
1996-07-08 06:19:32 +08:00
|
|
|
{
|
1999-09-21 11:22:53 +08:00
|
|
|
Header h = headerNew();
|
|
|
|
return h;
|
1996-07-08 06:19:32 +08:00
|
|
|
}
|
|
|
|
|
2001-05-23 22:25:19 +08:00
|
|
|
Header rpmFreeSignature(Header h)
|
1996-07-08 06:19:32 +08:00
|
|
|
{
|
2001-05-23 22:25:19 +08:00
|
|
|
return headerFree(h);
|
1996-07-08 06:19:32 +08:00
|
|
|
}
|
|
|
|
|
2001-02-12 06:02:29 +08:00
|
|
|
static int makePGPSignature(const char * file, /*@out@*/ void ** sig,
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@out@*/ int_32 * size, /*@null@*/ const char * passPhrase)
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@globals rpmGlobalMacroContext,
|
2001-10-19 21:51:20 +08:00
|
|
|
fileSystem @*/
|
2001-10-20 03:51:18 +08:00
|
|
|
/*@modifies *sig, *size, rpmGlobalMacroContext,
|
|
|
|
fileSystem @*/
|
1996-02-19 10:32:11 +08:00
|
|
|
{
|
2001-02-12 06:02:29 +08:00
|
|
|
char * sigfile = alloca(1024);
|
1996-07-08 06:19:32 +08:00
|
|
|
int pid, status;
|
1998-11-19 05:41:05 +08:00
|
|
|
int inpipe[2];
|
2000-12-13 04:03:45 +08:00
|
|
|
struct stat st;
|
1996-02-19 10:32:11 +08:00
|
|
|
|
2001-02-12 06:02:29 +08:00
|
|
|
(void) stpcpy( stpcpy(sigfile, file), ".sig");
|
1996-02-19 10:32:11 +08:00
|
|
|
|
1999-09-18 05:08:32 +08:00
|
|
|
inpipe[0] = inpipe[1] = 0;
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) pipe(inpipe);
|
2001-10-19 21:51:20 +08:00
|
|
|
|
1996-02-19 10:32:11 +08:00
|
|
|
if (!(pid = fork())) {
|
1999-03-21 05:09:47 +08:00
|
|
|
const char *pgp_path = rpmExpand("%{_pgp_path}", NULL);
|
|
|
|
const char *name = rpmExpand("+myname=\"%{_pgp_name}\"", NULL);
|
1999-03-22 02:43:22 +08:00
|
|
|
const char *path;
|
1999-09-11 07:48:56 +08:00
|
|
|
pgpVersion pgpVer;
|
1999-03-21 05:09:47 +08:00
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) close(STDIN_FILENO);
|
|
|
|
(void) dup2(inpipe[0], 3);
|
|
|
|
(void) close(inpipe[1]);
|
1999-03-21 05:09:47 +08:00
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) dosetenv("PGPPASSFD", "3", 1);
|
1999-03-21 05:09:47 +08:00
|
|
|
if (pgp_path && *pgp_path != '%')
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) dosetenv("PGPPATH", pgp_path, 1);
|
1999-03-21 05:09:47 +08:00
|
|
|
|
1996-12-24 22:02:21 +08:00
|
|
|
/* dosetenv("PGPPASS", passPhrase, 1); */
|
1999-03-22 02:43:22 +08:00
|
|
|
|
1999-09-11 07:48:56 +08:00
|
|
|
if ((path = rpmDetectPGPVersion(&pgpVer)) != NULL) {
|
|
|
|
switch(pgpVer) {
|
|
|
|
case PGP_2:
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) execlp(path, "pgp", "+batchmode=on", "+verbose=0", "+armor=off",
|
1999-03-22 02:43:22 +08:00
|
|
|
name, "-sb", file, sigfile, NULL);
|
|
|
|
break;
|
1999-09-11 07:48:56 +08:00
|
|
|
case PGP_5:
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) execlp(path,"pgps", "+batchmode=on", "+verbose=0", "+armor=off",
|
1999-03-22 02:43:22 +08:00
|
|
|
name, "-b", file, "-o", sigfile, NULL);
|
|
|
|
break;
|
1999-09-11 07:48:56 +08:00
|
|
|
case PGP_UNKNOWN:
|
|
|
|
case PGP_NOTDETECTED:
|
|
|
|
break;
|
1999-03-22 02:43:22 +08:00
|
|
|
}
|
|
|
|
}
|
2001-05-04 05:00:18 +08:00
|
|
|
rpmError(RPMERR_EXEC, _("Couldn't exec pgp (%s)\n"),
|
|
|
|
(path ? path : NULL));
|
1996-12-12 11:35:01 +08:00
|
|
|
_exit(RPMERR_EXEC);
|
1996-02-19 10:32:11 +08:00
|
|
|
}
|
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) close(inpipe[0]);
|
2001-05-04 05:00:18 +08:00
|
|
|
if (passPhrase)
|
|
|
|
(void) write(inpipe[1], passPhrase, strlen(passPhrase));
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) write(inpipe[1], "\n", 1);
|
|
|
|
(void) close(inpipe[1]);
|
1996-02-19 10:32:11 +08:00
|
|
|
|
1998-11-17 05:40:28 +08:00
|
|
|
(void)waitpid(pid, &status, 0);
|
1996-02-19 10:32:11 +08:00
|
|
|
if (!WIFEXITED(status) || WEXITSTATUS(status)) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_SIGGEN, _("pgp failed\n"));
|
1996-02-19 10:32:11 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
if (stat(sigfile, &st)) {
|
1996-02-25 13:05:52 +08:00
|
|
|
/* PGP failed to write signature */
|
2001-05-04 05:00:18 +08:00
|
|
|
if (sigfile) (void) unlink(sigfile); /* Just in case */
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_SIGGEN, _("pgp failed to write signature\n"));
|
1996-02-25 13:05:52 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1996-06-20 11:10:44 +08:00
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
*size = st.st_size;
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("PGP sig size: %d\n"), *size);
|
1999-09-21 11:22:53 +08:00
|
|
|
*sig = xmalloc(*size);
|
2001-10-19 21:51:20 +08:00
|
|
|
|
1999-01-11 01:10:17 +08:00
|
|
|
{ FD_t fd;
|
2001-05-04 05:00:18 +08:00
|
|
|
int rc = 0;
|
1999-11-05 05:26:08 +08:00
|
|
|
fd = Fopen(sigfile, "r.fdio");
|
2001-05-04 05:00:18 +08:00
|
|
|
if (fd != NULL && !Ferror(fd)) {
|
2001-10-17 01:42:18 +08:00
|
|
|
/*@-type@*/ /* FIX: eliminate timedRead @*/
|
2001-05-04 05:00:18 +08:00
|
|
|
rc = timedRead(fd, *sig, *size);
|
2001-10-17 01:42:18 +08:00
|
|
|
/*@=type@*/
|
2001-05-04 05:00:18 +08:00
|
|
|
if (sigfile) (void) unlink(sigfile);
|
|
|
|
(void) Fclose(fd);
|
|
|
|
}
|
1999-01-11 01:10:17 +08:00
|
|
|
if (rc != *size) {
|
2001-05-01 06:32:22 +08:00
|
|
|
*sig = _free(*sig);
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_SIGGEN, _("unable to read the signature\n"));
|
1999-01-11 01:10:17 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1996-06-20 11:10:44 +08:00
|
|
|
}
|
1996-02-19 10:32:11 +08:00
|
|
|
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("Got %d bytes of PGP sig\n"), *size);
|
2001-10-19 21:51:20 +08:00
|
|
|
|
1996-02-19 10:32:11 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-01-09 08:24:02 +08:00
|
|
|
/* This is an adaptation of the makePGPSignature function to use GPG instead
|
|
|
|
* of PGP to create signatures. I think I've made all the changes necessary,
|
|
|
|
* but this could be a good place to start looking if errors in GPG signature
|
|
|
|
* creation crop up.
|
|
|
|
*/
|
2001-02-12 06:02:29 +08:00
|
|
|
static int makeGPGSignature(const char * file, /*@out@*/ void ** sig,
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@out@*/ int_32 * size, /*@null@*/ const char * passPhrase)
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@globals rpmGlobalMacroContext,
|
2001-10-19 21:51:20 +08:00
|
|
|
fileSystem @*/
|
2001-10-20 03:51:18 +08:00
|
|
|
/*@modifies *sig, *size, rpmGlobalMacroContext,
|
|
|
|
fileSystem @*/
|
1999-01-09 08:24:02 +08:00
|
|
|
{
|
2001-02-12 06:02:29 +08:00
|
|
|
char * sigfile = alloca(1024);
|
1999-01-09 08:24:02 +08:00
|
|
|
int pid, status;
|
|
|
|
int inpipe[2];
|
2001-02-12 06:02:29 +08:00
|
|
|
FILE * fpipe;
|
2000-12-13 04:03:45 +08:00
|
|
|
struct stat st;
|
1999-01-09 08:24:02 +08:00
|
|
|
|
2001-02-12 06:02:29 +08:00
|
|
|
(void) stpcpy( stpcpy(sigfile, file), ".sig");
|
1999-01-09 08:24:02 +08:00
|
|
|
|
1999-09-18 05:08:32 +08:00
|
|
|
inpipe[0] = inpipe[1] = 0;
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) pipe(inpipe);
|
2001-10-19 21:51:20 +08:00
|
|
|
|
1999-01-09 08:24:02 +08:00
|
|
|
if (!(pid = fork())) {
|
1999-03-21 05:09:47 +08:00
|
|
|
const char *gpg_path = rpmExpand("%{_gpg_path}", NULL);
|
|
|
|
const char *name = rpmExpand("%{_gpg_name}", NULL);
|
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) close(STDIN_FILENO);
|
|
|
|
(void) dup2(inpipe[0], 3);
|
|
|
|
(void) close(inpipe[1]);
|
1999-03-21 05:09:47 +08:00
|
|
|
|
|
|
|
if (gpg_path && *gpg_path != '%')
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) dosetenv("GNUPGHOME", gpg_path, 1);
|
|
|
|
(void) execlp("gpg", "gpg",
|
1999-01-09 08:24:02 +08:00
|
|
|
"--batch", "--no-verbose", "--no-armor", "--passphrase-fd", "3",
|
|
|
|
"-u", name, "-sbo", sigfile, file,
|
|
|
|
NULL);
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_EXEC, _("Couldn't exec gpg\n"));
|
1999-01-09 08:24:02 +08:00
|
|
|
_exit(RPMERR_EXEC);
|
|
|
|
}
|
|
|
|
|
|
|
|
fpipe = fdopen(inpipe[1], "w");
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) close(inpipe[0]);
|
2001-05-04 05:00:18 +08:00
|
|
|
if (fpipe) {
|
|
|
|
fprintf(fpipe, "%s\n", (passPhrase ? passPhrase : ""));
|
|
|
|
(void) fclose(fpipe);
|
|
|
|
}
|
1999-01-09 08:24:02 +08:00
|
|
|
|
|
|
|
(void)waitpid(pid, &status, 0);
|
|
|
|
if (!WIFEXITED(status) || WEXITSTATUS(status)) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_SIGGEN, _("gpg failed\n"));
|
1999-01-09 08:24:02 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
if (stat(sigfile, &st)) {
|
1999-01-09 08:24:02 +08:00
|
|
|
/* GPG failed to write signature */
|
2001-05-04 05:00:18 +08:00
|
|
|
if (sigfile) (void) unlink(sigfile); /* Just in case */
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_SIGGEN, _("gpg failed to write signature\n"));
|
1999-01-09 08:24:02 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
*size = st.st_size;
|
1999-01-09 08:24:02 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("GPG sig size: %d\n"), *size);
|
1999-09-21 11:22:53 +08:00
|
|
|
*sig = xmalloc(*size);
|
2001-10-19 21:51:20 +08:00
|
|
|
|
1999-01-09 08:24:02 +08:00
|
|
|
{ FD_t fd;
|
2001-05-04 05:00:18 +08:00
|
|
|
int rc = 0;
|
1999-11-05 05:26:08 +08:00
|
|
|
fd = Fopen(sigfile, "r.fdio");
|
2001-05-04 05:00:18 +08:00
|
|
|
if (fd != NULL && !Ferror(fd)) {
|
2001-10-17 01:42:18 +08:00
|
|
|
/*@-type@*/ /* FIX: eliminate timedRead @*/
|
2001-05-04 05:00:18 +08:00
|
|
|
rc = timedRead(fd, *sig, *size);
|
2001-10-17 01:42:18 +08:00
|
|
|
/*@=type@*/
|
2001-05-04 05:00:18 +08:00
|
|
|
if (sigfile) (void) unlink(sigfile);
|
|
|
|
(void) Fclose(fd);
|
|
|
|
}
|
1999-01-09 08:24:02 +08:00
|
|
|
if (rc != *size) {
|
2001-05-01 06:32:22 +08:00
|
|
|
*sig = _free(*sig);
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_SIGGEN, _("unable to read the signature\n"));
|
1999-01-09 08:24:02 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmMessage(RPMMESS_DEBUG, _("Got %d bytes of GPG sig\n"), *size);
|
2001-10-19 21:51:20 +08:00
|
|
|
|
1999-01-09 08:24:02 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-06-01 06:31:14 +08:00
|
|
|
int rpmAddSignature(Header h, const char * file, int_32 sigTag,
|
2001-02-12 06:02:29 +08:00
|
|
|
const char *passPhrase)
|
1996-06-29 02:48:34 +08:00
|
|
|
{
|
2000-12-13 04:03:45 +08:00
|
|
|
struct stat st;
|
1999-07-14 07:33:02 +08:00
|
|
|
int_32 size;
|
2000-11-16 04:38:58 +08:00
|
|
|
byte buf[16];
|
1999-07-14 07:33:02 +08:00
|
|
|
void *sig;
|
|
|
|
int ret = -1;
|
2001-10-19 21:51:20 +08:00
|
|
|
|
1996-07-08 11:27:05 +08:00
|
|
|
switch (sigTag) {
|
1999-09-11 07:48:56 +08:00
|
|
|
case RPMSIGTAG_SIZE:
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) stat(file, &st);
|
2000-12-13 04:03:45 +08:00
|
|
|
size = st.st_size;
|
1999-07-14 07:33:02 +08:00
|
|
|
ret = 0;
|
2001-06-01 06:31:14 +08:00
|
|
|
(void) headerAddEntry(h, RPMSIGTAG_SIZE, RPM_INT32_TYPE, &size, 1);
|
1996-07-08 06:19:32 +08:00
|
|
|
break;
|
1999-09-11 07:48:56 +08:00
|
|
|
case RPMSIGTAG_MD5:
|
1999-07-14 07:33:02 +08:00
|
|
|
ret = mdbinfile(file, buf);
|
|
|
|
if (ret == 0)
|
2001-06-01 06:31:14 +08:00
|
|
|
(void) headerAddEntry(h, sigTag, RPM_BIN_TYPE, buf, 16);
|
1996-07-08 06:19:32 +08:00
|
|
|
break;
|
1999-09-11 07:48:56 +08:00
|
|
|
case RPMSIGTAG_PGP5: /* XXX legacy */
|
|
|
|
case RPMSIGTAG_PGP:
|
1999-09-15 00:04:03 +08:00
|
|
|
rpmMessage(RPMMESS_VERBOSE, _("Generating signature using PGP.\n"));
|
1999-09-11 07:48:56 +08:00
|
|
|
ret = makePGPSignature(file, &sig, &size, passPhrase);
|
1999-07-14 07:33:02 +08:00
|
|
|
if (ret == 0)
|
2001-06-01 06:31:14 +08:00
|
|
|
(void) headerAddEntry(h, sigTag, RPM_BIN_TYPE, sig, size);
|
1996-07-08 06:19:32 +08:00
|
|
|
break;
|
1999-09-11 07:48:56 +08:00
|
|
|
case RPMSIGTAG_GPG:
|
1999-09-15 00:04:03 +08:00
|
|
|
rpmMessage(RPMMESS_VERBOSE, _("Generating signature using GPG.\n"));
|
1999-07-14 07:33:02 +08:00
|
|
|
ret = makeGPGSignature(file, &sig, &size, passPhrase);
|
|
|
|
if (ret == 0)
|
2001-06-01 06:31:14 +08:00
|
|
|
(void) headerAddEntry(h, sigTag, RPM_BIN_TYPE, sig, size);
|
1999-01-09 08:24:02 +08:00
|
|
|
break;
|
1996-07-08 11:27:05 +08:00
|
|
|
}
|
|
|
|
|
1999-07-14 07:33:02 +08:00
|
|
|
return ret;
|
1996-07-08 11:27:05 +08:00
|
|
|
}
|
|
|
|
|
2001-02-12 06:02:29 +08:00
|
|
|
static int checkPassPhrase(const char * passPhrase, const int sigTag)
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@globals rpmGlobalMacroContext,
|
2001-10-19 21:51:20 +08:00
|
|
|
fileSystem @*/
|
2001-10-20 03:51:18 +08:00
|
|
|
/*@modifies rpmGlobalMacroContext,
|
|
|
|
fileSystem @*/
|
1996-02-19 10:32:11 +08:00
|
|
|
{
|
1996-06-20 11:10:44 +08:00
|
|
|
int passPhrasePipe[2];
|
|
|
|
int pid, status;
|
|
|
|
int fd;
|
1996-02-19 10:32:11 +08:00
|
|
|
|
1999-09-18 05:08:32 +08:00
|
|
|
passPhrasePipe[0] = passPhrasePipe[1] = 0;
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) pipe(passPhrasePipe);
|
1996-06-20 11:10:44 +08:00
|
|
|
if (!(pid = fork())) {
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) close(STDIN_FILENO);
|
|
|
|
(void) close(STDOUT_FILENO);
|
|
|
|
(void) close(passPhrasePipe[1]);
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@-internalglobs@*/ /* FIX: shrug */
|
1996-11-19 02:02:36 +08:00
|
|
|
if (! rpmIsVerbose()) {
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) close(STDERR_FILENO);
|
1996-06-20 11:10:44 +08:00
|
|
|
}
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@=internalglobs@*/
|
1998-11-20 02:10:28 +08:00
|
|
|
if ((fd = open("/dev/null", O_RDONLY)) != STDIN_FILENO) {
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) dup2(fd, STDIN_FILENO);
|
|
|
|
(void) close(fd);
|
1996-06-20 11:10:44 +08:00
|
|
|
}
|
1998-11-20 02:10:28 +08:00
|
|
|
if ((fd = open("/dev/null", O_WRONLY)) != STDOUT_FILENO) {
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) dup2(fd, STDOUT_FILENO);
|
|
|
|
(void) close(fd);
|
1996-06-20 11:10:44 +08:00
|
|
|
}
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) dup2(passPhrasePipe[0], 3);
|
1999-01-09 08:24:02 +08:00
|
|
|
|
1999-03-22 03:11:29 +08:00
|
|
|
switch (sigTag) {
|
1999-03-21 05:09:47 +08:00
|
|
|
case RPMSIGTAG_GPG:
|
|
|
|
{ const char *gpg_path = rpmExpand("%{_gpg_path}", NULL);
|
|
|
|
const char *name = rpmExpand("%{_gpg_name}", NULL);
|
|
|
|
if (gpg_path && *gpg_path != '%')
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) dosetenv("GNUPGHOME", gpg_path, 1);
|
|
|
|
(void) execlp("gpg", "gpg",
|
1999-01-09 08:24:02 +08:00
|
|
|
"--batch", "--no-verbose", "--passphrase-fd", "3",
|
|
|
|
"-u", name, "-so", "-",
|
|
|
|
NULL);
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_EXEC, _("Couldn't exec gpg\n"));
|
1999-01-09 08:24:02 +08:00
|
|
|
_exit(RPMERR_EXEC);
|
1999-09-18 05:08:32 +08:00
|
|
|
} /*@notreached@*/ break;
|
1999-09-11 07:48:56 +08:00
|
|
|
case RPMSIGTAG_PGP5: /* XXX legacy */
|
1999-03-21 05:09:47 +08:00
|
|
|
case RPMSIGTAG_PGP:
|
|
|
|
{ const char *pgp_path = rpmExpand("%{_pgp_path}", NULL);
|
|
|
|
const char *name = rpmExpand("+myname=\"%{_pgp_name}\"", NULL);
|
1999-03-22 02:43:22 +08:00
|
|
|
const char *path;
|
1999-09-11 07:48:56 +08:00
|
|
|
pgpVersion pgpVer;
|
1999-03-22 02:43:22 +08:00
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) dosetenv("PGPPASSFD", "3", 1);
|
1999-03-21 05:09:47 +08:00
|
|
|
if (pgp_path && *pgp_path != '%')
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) dosetenv("PGPPATH", pgp_path, 1);
|
1999-03-22 02:43:22 +08:00
|
|
|
|
1999-09-11 07:48:56 +08:00
|
|
|
if ((path = rpmDetectPGPVersion(&pgpVer)) != NULL) {
|
|
|
|
switch(pgpVer) {
|
|
|
|
case PGP_2:
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) execlp(path, "pgp", "+batchmode=on", "+verbose=0",
|
1999-03-22 02:43:22 +08:00
|
|
|
name, "-sf", NULL);
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@innerbreak@*/ break;
|
1999-09-11 07:48:56 +08:00
|
|
|
case PGP_5: /* XXX legacy */
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) execlp(path,"pgps", "+batchmode=on", "+verbose=0",
|
1999-03-22 03:11:29 +08:00
|
|
|
name, "-f", NULL);
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@innerbreak@*/ break;
|
1999-09-11 07:48:56 +08:00
|
|
|
case PGP_UNKNOWN:
|
|
|
|
case PGP_NOTDETECTED:
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@innerbreak@*/ break;
|
1999-03-22 02:43:22 +08:00
|
|
|
}
|
|
|
|
}
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_EXEC, _("Couldn't exec pgp\n"));
|
1999-01-09 08:24:02 +08:00
|
|
|
_exit(RPMERR_EXEC);
|
1999-09-18 05:08:32 +08:00
|
|
|
} /*@notreached@*/ break;
|
1999-03-21 05:09:47 +08:00
|
|
|
default: /* This case should have been screened out long ago. */
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_SIGGEN, _("Invalid %%_signature spec in macro file\n"));
|
1999-03-21 05:09:47 +08:00
|
|
|
_exit(RPMERR_SIGGEN);
|
1999-09-18 05:08:32 +08:00
|
|
|
/*@notreached@*/ break;
|
1999-03-21 05:09:47 +08:00
|
|
|
}
|
1996-02-19 10:32:11 +08:00
|
|
|
}
|
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) close(passPhrasePipe[0]);
|
|
|
|
(void) write(passPhrasePipe[1], passPhrase, strlen(passPhrase));
|
|
|
|
(void) write(passPhrasePipe[1], "\n", 1);
|
|
|
|
(void) close(passPhrasePipe[1]);
|
1996-06-20 11:10:44 +08:00
|
|
|
|
1998-11-17 05:40:28 +08:00
|
|
|
(void)waitpid(pid, &status, 0);
|
1996-06-20 11:10:44 +08:00
|
|
|
if (!WIFEXITED(status) || WEXITSTATUS(status)) {
|
|
|
|
return 1;
|
1996-02-19 10:32:11 +08:00
|
|
|
}
|
1996-06-20 11:10:44 +08:00
|
|
|
|
|
|
|
/* passPhrase is good */
|
|
|
|
return 0;
|
1996-02-19 10:32:11 +08:00
|
|
|
}
|
1999-07-14 07:33:02 +08:00
|
|
|
|
2001-05-04 05:00:18 +08:00
|
|
|
char * rpmGetPassPhrase(const char * prompt, const int sigTag)
|
1999-07-14 07:33:02 +08:00
|
|
|
{
|
|
|
|
char *pass;
|
|
|
|
int aok;
|
|
|
|
|
|
|
|
switch (sigTag) {
|
1999-09-11 07:48:56 +08:00
|
|
|
case RPMSIGTAG_GPG:
|
1999-07-14 07:33:02 +08:00
|
|
|
{ const char *name = rpmExpand("%{_gpg_name}", NULL);
|
|
|
|
aok = (name && *name != '%');
|
2001-04-29 09:05:43 +08:00
|
|
|
name = _free(name);
|
1999-07-14 07:33:02 +08:00
|
|
|
}
|
|
|
|
if (!aok) {
|
|
|
|
rpmError(RPMERR_SIGGEN,
|
2001-01-16 07:09:42 +08:00
|
|
|
_("You must set \"%%_gpg_name\" in your macro file\n"));
|
1999-07-14 07:33:02 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
break;
|
1999-09-11 07:48:56 +08:00
|
|
|
case RPMSIGTAG_PGP5: /* XXX legacy */
|
2001-10-19 21:51:20 +08:00
|
|
|
case RPMSIGTAG_PGP:
|
1999-07-14 07:33:02 +08:00
|
|
|
{ const char *name = rpmExpand("%{_pgp_name}", NULL);
|
|
|
|
aok = (name && *name != '%');
|
2001-04-29 09:05:43 +08:00
|
|
|
name = _free(name);
|
1999-07-14 07:33:02 +08:00
|
|
|
}
|
|
|
|
if (!aok) {
|
|
|
|
rpmError(RPMERR_SIGGEN,
|
2001-01-16 07:09:42 +08:00
|
|
|
_("You must set \"%%_pgp_name\" in your macro file\n"));
|
1999-07-14 07:33:02 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
break;
|
1999-09-11 07:48:56 +08:00
|
|
|
default:
|
1999-07-14 07:33:02 +08:00
|
|
|
/* Currently the calling function (rpm.c:main) is checking this and
|
|
|
|
* doing a better job. This section should never be accessed.
|
|
|
|
*/
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_SIGGEN, _("Invalid %%_signature spec in macro file\n"));
|
1999-07-14 07:33:02 +08:00
|
|
|
return NULL;
|
1999-09-18 05:08:32 +08:00
|
|
|
/*@notreached@*/ break;
|
1999-07-14 07:33:02 +08:00
|
|
|
}
|
|
|
|
|
1999-09-18 05:08:32 +08:00
|
|
|
pass = /*@-unrecog@*/ getpass( (prompt ? prompt : "") ) /*@=unrecog@*/ ;
|
1999-07-14 07:33:02 +08:00
|
|
|
|
1999-09-18 05:08:32 +08:00
|
|
|
if (checkPassPhrase(pass, sigTag))
|
1999-07-14 07:33:02 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return pass;
|
|
|
|
}
|
|
|
|
|
2001-10-20 03:51:18 +08:00
|
|
|
static rpmVerifySignatureReturn
|
|
|
|
verifySizeSignature(/*@unused@*/ const char * fn,
|
|
|
|
const byte * sig,
|
|
|
|
/*@unused@*/ int siglen,
|
2001-10-22 05:43:32 +08:00
|
|
|
const pgpDig dig, /*@out@*/ char * result)
|
2001-10-20 03:51:18 +08:00
|
|
|
/*@modifies *result @*/
|
|
|
|
{
|
|
|
|
char * t = result;
|
|
|
|
int_32 size = *(int_32 *)sig;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
*t = '\0';
|
|
|
|
t = stpcpy(t, "Header+Payload size: ");
|
|
|
|
|
|
|
|
/*@-type@*/
|
|
|
|
if (size != dig->nbytes) {
|
|
|
|
res = RPMSIG_BAD;
|
|
|
|
sprintf(t, "BAD Expected(%d) != (%d)\n", size, dig->nbytes);
|
|
|
|
} else {
|
|
|
|
res = RPMSIG_OK;
|
|
|
|
sprintf(t, "OK (%d)\n", dig->nbytes);
|
|
|
|
}
|
|
|
|
/*@=type@*/
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static rpmVerifySignatureReturn
|
|
|
|
verifyMD5Signature(/*@unused@*/ const char * fn, const byte * sig, int siglen,
|
2001-10-22 05:43:32 +08:00
|
|
|
const pgpDig dig, /*@out@*/ char * result)
|
2001-10-20 03:51:18 +08:00
|
|
|
/*@modifies *result @*/
|
|
|
|
{
|
|
|
|
char * t = result;
|
|
|
|
byte * md5sum = NULL;
|
|
|
|
size_t md5len = 0;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
/*@-type@*/
|
|
|
|
(void) rpmDigestFinal(rpmDigestDup(dig->md5ctx),
|
|
|
|
(void **)&md5sum, &md5len, 0);
|
|
|
|
/*@=type@*/
|
|
|
|
|
|
|
|
*t = '\0';
|
|
|
|
t = stpcpy(t, "MD5 digest: ");
|
|
|
|
|
|
|
|
if (md5len != siglen || memcmp(md5sum, sig, md5len)) {
|
|
|
|
res = RPMSIG_BAD;
|
|
|
|
t = stpcpy(t, "BAD Expected(");
|
|
|
|
(void) pgpHexCvt(t, sig, siglen);
|
|
|
|
t += strlen(t);
|
|
|
|
t = stpcpy(t, ") != (");
|
|
|
|
} else {
|
|
|
|
res = RPMSIG_OK;
|
|
|
|
t = stpcpy(t, "OK (");
|
|
|
|
}
|
|
|
|
(void) pgpHexCvt(t, md5sum, md5len);
|
|
|
|
t += strlen(t);
|
|
|
|
t = stpcpy(t, ")\n");
|
|
|
|
|
|
|
|
md5sum = _free(md5sum);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static rpmVerifySignatureReturn
|
|
|
|
verifyPGPSignature(/*@unused@*/ const char * fn,
|
|
|
|
/*@unused@*/ const byte * sig,
|
|
|
|
/*@unused@*/ int siglen,
|
2001-10-22 05:43:32 +08:00
|
|
|
const pgpDig dig, /*@out@*/ char * result)
|
2001-10-20 03:51:18 +08:00
|
|
|
/*@modifies *result */
|
|
|
|
{
|
2001-10-21 04:28:56 +08:00
|
|
|
/*@unchecked@*/ static const byte * pgppk = NULL;
|
|
|
|
/*@unchecked@*/ static size_t pgppklen = 0;
|
2001-10-20 03:51:18 +08:00
|
|
|
char * t = result;
|
2001-10-21 04:28:56 +08:00
|
|
|
int res, xx;
|
2001-10-20 03:51:18 +08:00
|
|
|
|
|
|
|
*t = '\0';
|
|
|
|
t = stpcpy(t, "V3 RSA/MD5 signature: ");
|
|
|
|
|
2001-10-21 04:28:56 +08:00
|
|
|
/* XXX retrieve by keyid from signature. */
|
2001-10-21 06:31:09 +08:00
|
|
|
|
|
|
|
/*@-globs -internalglobs -mods -modfilesys@*/
|
2001-10-21 04:28:56 +08:00
|
|
|
if (pgppk == NULL) {
|
2001-10-21 06:31:09 +08:00
|
|
|
const char * pkfn = rpmExpand("%{_pgp_pubkey}", NULL);
|
|
|
|
if (pgpReadPkts(pkfn, &pgppk, &pgppklen)) {
|
|
|
|
res = RPMSIG_NOKEY;
|
|
|
|
t = stpcpy( stpcpy( stpcpy(t, "NOKEY ("), pkfn), ")\n");
|
|
|
|
pkfn = _free(pkfn);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
rpmMessage(RPMMESS_DEBUG,
|
|
|
|
"========== PGP RSA/MD5 pubkey %s\n", pkfn);
|
2001-10-21 04:28:56 +08:00
|
|
|
xx = pgpPrtPkts(pgppk, pgppklen, NULL, rpmIsDebug());
|
2001-10-21 06:31:09 +08:00
|
|
|
pkfn = _free(pkfn);
|
2001-10-21 04:28:56 +08:00
|
|
|
}
|
2001-10-21 06:31:09 +08:00
|
|
|
|
2001-10-21 04:28:56 +08:00
|
|
|
/* XXX sanity check on pubkey and signature agreement. */
|
|
|
|
|
2001-10-21 06:31:09 +08:00
|
|
|
#ifdef NOTYET
|
|
|
|
{ pgpPktSigV3 dsig = dig->signature.v3;
|
|
|
|
pgpPktKeyV3 dpk = dig->pubkey.v3;
|
|
|
|
|
|
|
|
if (dsig->pubkey_algo != dpk->pubkey_algo) {
|
|
|
|
res = RPMSIG_NOKEY;
|
|
|
|
t = stpcpy(t, "NOKEY\n");
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-10-21 04:28:56 +08:00
|
|
|
/*@-nullpass@*/
|
|
|
|
xx = pgpPrtPkts(pgppk, pgppklen, dig, 0);
|
|
|
|
/*@=nullpass@*/
|
2001-10-21 06:31:09 +08:00
|
|
|
/*@=globs =internalglobs =mods =modfilesys@*/
|
2001-10-21 04:28:56 +08:00
|
|
|
|
2001-10-20 03:51:18 +08:00
|
|
|
/*@-type@*/
|
|
|
|
if (!rsavrfy(&dig->rsa_pk, &dig->rsahm, &dig->c)) {
|
|
|
|
res = RPMSIG_BAD;
|
|
|
|
t = stpcpy(t, "BAD\n");
|
|
|
|
} else {
|
|
|
|
res = RPMSIG_OK;
|
|
|
|
t = stpcpy(t, "OK\n");
|
|
|
|
}
|
|
|
|
/*@=type@*/
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static rpmVerifySignatureReturn
|
|
|
|
verifyGPGSignature(/*@unused@*/ const char * fn,
|
|
|
|
/*@unused@*/ const byte * sig,
|
|
|
|
/*@unused@*/ int siglen,
|
2001-10-22 05:43:32 +08:00
|
|
|
const pgpDig dig, /*@out@*/ char * result)
|
2001-10-20 03:51:18 +08:00
|
|
|
/*@modifies *result @*/
|
|
|
|
{
|
2001-10-21 04:28:56 +08:00
|
|
|
/*@unchecked@*/ static const byte * gpgpk = NULL;
|
|
|
|
/*@unchecked@*/ static size_t gpgpklen = 0;
|
2001-10-20 03:51:18 +08:00
|
|
|
char * t = result;
|
2001-10-21 04:28:56 +08:00
|
|
|
int res, xx;
|
2001-10-20 03:51:18 +08:00
|
|
|
|
|
|
|
*t = '\0';
|
|
|
|
t = stpcpy(t, "V3 DSA signature: ");
|
|
|
|
|
2001-10-21 04:28:56 +08:00
|
|
|
/* XXX retrieve by keyid from signature. */
|
2001-10-21 06:31:09 +08:00
|
|
|
|
|
|
|
/*@-globs -internalglobs -mods -modfilesys@*/
|
2001-10-21 04:28:56 +08:00
|
|
|
if (gpgpk == NULL) {
|
2001-10-21 06:31:09 +08:00
|
|
|
const char * pkfn = rpmExpand("%{_gpg_pubkey}", NULL);
|
|
|
|
if (pgpReadPkts(pkfn, &gpgpk, &gpgpklen)) {
|
|
|
|
res = RPMSIG_NOKEY;
|
|
|
|
t = stpcpy( stpcpy( stpcpy(t, "NOKEY ("), pkfn), ")\n");
|
|
|
|
pkfn = _free(pkfn);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
rpmMessage(RPMMESS_DEBUG,
|
|
|
|
"========== GPG DSA pubkey %s\n", pkfn);
|
2001-10-21 04:28:56 +08:00
|
|
|
xx = pgpPrtPkts(gpgpk, gpgpklen, NULL, rpmIsDebug());
|
2001-10-21 06:31:09 +08:00
|
|
|
pkfn = _free(pkfn);
|
2001-10-21 04:28:56 +08:00
|
|
|
}
|
2001-10-21 06:31:09 +08:00
|
|
|
|
2001-10-21 04:28:56 +08:00
|
|
|
/* XXX sanity check on pubkey and signature agreement. */
|
|
|
|
|
2001-10-21 06:31:09 +08:00
|
|
|
#ifdef NOTYET
|
|
|
|
{ pgpPktSigV3 dsig = dig->signature.v3;
|
|
|
|
pgpPktKeyV4 dpk = dig->pubkey.v4;
|
|
|
|
|
|
|
|
if (dsig->pubkey_algo != dpk->pubkey_algo) {
|
|
|
|
res = RPMSIG_NOKEY;
|
|
|
|
t = stpcpy(t, "NOKEY\n");
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-10-21 04:28:56 +08:00
|
|
|
/*@-nullpass@*/
|
|
|
|
xx = pgpPrtPkts(gpgpk, gpgpklen, dig, 0);
|
|
|
|
/*@=nullpass@*/
|
2001-10-21 06:31:09 +08:00
|
|
|
/*@=globs =internalglobs =mods =modfilesys@*/
|
2001-10-21 04:28:56 +08:00
|
|
|
|
2001-10-20 03:51:18 +08:00
|
|
|
/*@-type@*/
|
|
|
|
if (!dsavrfy(&dig->p, &dig->q, &dig->g, &dig->hm, &dig->y, &dig->r, &dig->s)) {
|
|
|
|
res = RPMSIG_BAD;
|
|
|
|
t = stpcpy(t, "BAD\n");
|
|
|
|
} else {
|
|
|
|
res = RPMSIG_OK;
|
|
|
|
t = stpcpy(t, "OK\n");
|
|
|
|
}
|
|
|
|
/*@=type@*/
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-08-30 06:04:33 +08:00
|
|
|
rpmVerifySignatureReturn
|
2001-10-20 03:51:18 +08:00
|
|
|
rpmVerifySignature(const char * fn, int_32 sigTag, const void * sig,
|
2001-10-22 05:43:32 +08:00
|
|
|
int siglen, const pgpDig dig, char * result)
|
1999-07-14 07:33:02 +08:00
|
|
|
{
|
2001-10-20 03:51:18 +08:00
|
|
|
int res;
|
1999-07-14 07:33:02 +08:00
|
|
|
switch (sigTag) {
|
1999-09-11 07:48:56 +08:00
|
|
|
case RPMSIGTAG_SIZE:
|
2001-10-20 03:51:18 +08:00
|
|
|
res = verifySizeSignature(fn, sig, siglen, dig, result);
|
|
|
|
break;
|
1999-09-11 07:48:56 +08:00
|
|
|
case RPMSIGTAG_MD5:
|
2001-10-20 03:51:18 +08:00
|
|
|
res = verifyMD5Signature(fn, sig, siglen, dig, result);
|
|
|
|
break;
|
1999-09-11 07:48:56 +08:00
|
|
|
case RPMSIGTAG_PGP5: /* XXX legacy */
|
|
|
|
case RPMSIGTAG_PGP:
|
2001-10-20 03:51:18 +08:00
|
|
|
res = verifyPGPSignature(fn, sig, siglen, dig, result);
|
|
|
|
break;
|
1999-09-11 07:48:56 +08:00
|
|
|
case RPMSIGTAG_GPG:
|
2001-10-20 03:51:18 +08:00
|
|
|
res = verifyGPGSignature(fn, sig, siglen, dig, result);
|
|
|
|
break;
|
2001-09-26 04:51:34 +08:00
|
|
|
case RPMSIGTAG_LEMD5_1:
|
|
|
|
case RPMSIGTAG_LEMD5_2:
|
2001-10-20 03:51:18 +08:00
|
|
|
sprintf(result, "Broken MD5 digest: UNSUPPORTED\n");
|
|
|
|
res = RPMSIG_UNKNOWN;
|
|
|
|
break;
|
1999-09-11 07:48:56 +08:00
|
|
|
default:
|
2001-10-20 03:51:18 +08:00
|
|
|
sprintf(result, "Signature: UNKNOWN(%d)\n", sigTag);
|
|
|
|
res = RPMSIG_UNKNOWN;
|
|
|
|
break;
|
1999-07-14 07:33:02 +08:00
|
|
|
}
|
2001-10-20 03:51:18 +08:00
|
|
|
return res;
|
1999-07-14 07:33:02 +08:00
|
|
|
}
|