1996-02-19 10:32:11 +08:00
|
|
|
/* signature.c - RPM signature functions */
|
|
|
|
|
|
|
|
/* NOTES
|
|
|
|
*
|
1996-06-20 11:10:44 +08:00
|
|
|
* Things have been cleaned up wrt PGP. We can now handle
|
|
|
|
* signatures of any length (which means you can use any
|
|
|
|
* size key you like). We also honor PGPPATH finally.
|
1996-02-19 10:32:11 +08:00
|
|
|
*/
|
|
|
|
|
1997-01-18 00:22:08 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#if HAVE_ASM_BYTEORDER_H
|
1996-09-26 03:16:34 +08:00
|
|
|
#include <asm/byteorder.h>
|
|
|
|
#endif
|
|
|
|
|
1996-02-19 10:32:11 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/wait.h>
|
1996-02-25 13:05:52 +08:00
|
|
|
#include <sys/stat.h>
|
1996-02-19 10:32:11 +08:00
|
|
|
#include <fcntl.h>
|
1997-01-17 01:22:20 +08:00
|
|
|
#include <string.h>
|
1996-02-19 10:32:11 +08:00
|
|
|
|
1996-06-20 11:10:44 +08:00
|
|
|
#include "md5.h"
|
1997-01-18 00:22:08 +08:00
|
|
|
#include "misc.h"
|
1996-02-19 10:32:11 +08:00
|
|
|
#include "rpmlib.h"
|
1996-06-29 02:48:34 +08:00
|
|
|
#include "rpmlead.h"
|
1996-10-15 11:15:30 +08:00
|
|
|
#include "signature.h"
|
|
|
|
#include "tread.h"
|
1996-11-19 02:02:36 +08:00
|
|
|
#include "messages.h"
|
1996-02-19 10:32:11 +08:00
|
|
|
|
1996-09-01 02:36:53 +08:00
|
|
|
typedef int (*md5func)(char * fn, unsigned char * digest);
|
|
|
|
|
1996-07-08 06:19:32 +08:00
|
|
|
static int makePGPSignature(char *file, void **sig, int_32 *size,
|
|
|
|
char *passPhrase);
|
1996-06-29 02:48:34 +08:00
|
|
|
static int checkSize(int fd, int size, int sigsize);
|
1996-07-08 11:27:05 +08:00
|
|
|
static int verifySizeSignature(char *datafile, int_32 size, char *result);
|
|
|
|
static int verifyMD5Signature(char *datafile, unsigned char *sig,
|
1996-09-01 02:36:53 +08:00
|
|
|
char *result, md5func fn);
|
1996-07-08 11:27:05 +08:00
|
|
|
static int verifyPGPSignature(char *datafile, void *sig,
|
|
|
|
int count, char *result);
|
1996-02-22 09:35:00 +08:00
|
|
|
static int checkPassPhrase(char *passPhrase);
|
1996-02-19 10:32:11 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
int rpmLookupSignatureType(void)
|
1996-06-20 11:10:44 +08:00
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
if (! (name = rpmGetVar(RPMVAR_SIGTYPE))) {
|
1996-07-08 06:19:32 +08:00
|
|
|
return 0;
|
1996-06-20 11:10:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcasecmp(name, "none")) {
|
1996-07-08 06:19:32 +08:00
|
|
|
return 0;
|
1996-06-20 11:10:44 +08:00
|
|
|
} else if (!strcasecmp(name, "pgp")) {
|
1996-11-19 02:02:36 +08:00
|
|
|
return RPMSIGTAG_PGP;
|
1996-06-20 11:10:44 +08:00
|
|
|
} else {
|
1996-07-08 06:19:32 +08:00
|
|
|
return -1;
|
1996-06-20 11:10:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
/* rpmReadSignature() emulates the new style signatures if it finds an */
|
1996-07-08 06:19:32 +08:00
|
|
|
/* old-style one. It also immediately verifies the header+archive */
|
|
|
|
/* size and returns an error if it doesn't match. */
|
1996-06-20 11:10:44 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
int rpmReadSignature(int fd, Header *header, short sig_type)
|
1996-02-19 10:32:11 +08:00
|
|
|
{
|
1996-06-20 11:10:44 +08:00
|
|
|
unsigned char 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;
|
|
|
|
Header h;
|
|
|
|
|
|
|
|
if (header) {
|
|
|
|
*header = NULL;
|
|
|
|
}
|
1996-02-19 10:32:11 +08:00
|
|
|
|
|
|
|
switch (sig_type) {
|
1996-07-08 06:19:32 +08:00
|
|
|
case RPMSIG_NONE:
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "No signature\n");
|
1996-02-19 10:32:11 +08:00
|
|
|
break;
|
1996-07-08 06:19:32 +08:00
|
|
|
case RPMSIG_PGP262_1024:
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "Old PGP signature\n");
|
1996-06-20 11:10:44 +08:00
|
|
|
/* These are always 256 bytes */
|
1996-10-15 11:15:30 +08:00
|
|
|
if (timedRead(fd, buf, 256) != 256) {
|
1996-07-08 06:19:32 +08:00
|
|
|
return 1;
|
1996-02-22 06:20:37 +08:00
|
|
|
}
|
1996-07-08 06:19:32 +08:00
|
|
|
if (header) {
|
1996-11-19 02:02:36 +08:00
|
|
|
*header = headerNew();
|
|
|
|
headerAddEntry(*header, RPMSIGTAG_PGP, RPM_BIN_TYPE, buf, 152);
|
1996-02-19 10:32:11 +08:00
|
|
|
}
|
|
|
|
break;
|
1996-07-08 06:19:32 +08:00
|
|
|
case RPMSIG_MD5:
|
|
|
|
case RPMSIG_MD5_PGP:
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmError(RPMERR_BADSIGTYPE,
|
1996-07-08 06:26:31 +08:00
|
|
|
"Old (internal-only) signature! How did you get that!?");
|
|
|
|
return 1;
|
1996-06-20 11:10:44 +08:00
|
|
|
break;
|
1996-07-08 06:19:32 +08:00
|
|
|
case RPMSIG_HEADERSIG:
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "New Header signature\n");
|
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);
|
1996-07-08 06:19:32 +08:00
|
|
|
if (! h) {
|
|
|
|
return 1;
|
1996-02-25 13:05:52 +08:00
|
|
|
}
|
1996-11-19 02:02:36 +08:00
|
|
|
sigSize = headerSizeof(h, HEADER_MAGIC_YES);
|
1996-07-08 06:19:32 +08:00
|
|
|
pad = (8 - (sigSize % 8)) % 8; /* 8-byte pad */
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "Signature size: %d\n", sigSize);
|
|
|
|
rpmMessage(RPMMESS_DEBUG, "Signature pad : %d\n", pad);
|
|
|
|
if (! headerGetEntry(h, RPMSIGTAG_SIZE, &type, (void **)&archSize, &count)) {
|
|
|
|
headerFree(h);
|
1996-07-08 06:19:32 +08:00
|
|
|
return 1;
|
1996-06-20 11:10:44 +08:00
|
|
|
}
|
1996-07-08 06:19:32 +08:00
|
|
|
if (checkSize(fd, *archSize, sigSize + pad)) {
|
1996-11-19 02:02:36 +08:00
|
|
|
headerFree(h);
|
1996-07-08 06:19:32 +08:00
|
|
|
return 1;
|
1996-06-20 11:10:44 +08:00
|
|
|
}
|
1996-07-08 06:19:32 +08:00
|
|
|
if (pad) {
|
1996-10-15 11:15:30 +08:00
|
|
|
if (timedRead(fd, buf, pad) != pad) {
|
1996-11-19 02:02:36 +08:00
|
|
|
headerFree(h);
|
1996-07-08 06:19:32 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1996-06-20 11:10:44 +08:00
|
|
|
}
|
1996-07-08 06:19:32 +08:00
|
|
|
if (header) {
|
|
|
|
*header = h;
|
|
|
|
} else {
|
1996-11-19 02:02:36 +08:00
|
|
|
headerFree(h);
|
1996-06-20 11:10:44 +08:00
|
|
|
}
|
1996-02-19 10:32:11 +08:00
|
|
|
break;
|
1996-07-08 06:19:32 +08:00
|
|
|
default:
|
|
|
|
return 1;
|
1996-02-19 10:32:11 +08:00
|
|
|
}
|
|
|
|
|
1996-02-22 09:59:29 +08:00
|
|
|
return 0;
|
1996-02-19 10:32:11 +08:00
|
|
|
}
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
int rpmWriteSignature(int fd, Header header)
|
1996-02-20 14:02:32 +08:00
|
|
|
{
|
1996-07-08 06:19:32 +08:00
|
|
|
int sigSize, pad;
|
|
|
|
unsigned char buf[8];
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
headerWrite(fd, header, HEADER_MAGIC_YES);
|
|
|
|
sigSize = headerSizeof(header, HEADER_MAGIC_YES);
|
1996-07-08 06:19:32 +08:00
|
|
|
pad = (8 - (sigSize % 8)) % 8;
|
|
|
|
if (pad) {
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "Signature size: %d\n", sigSize);
|
|
|
|
rpmMessage(RPMMESS_DEBUG, "Signature pad : %d\n", pad);
|
1996-07-08 06:19:32 +08:00
|
|
|
memset(buf, 0, pad);
|
|
|
|
write(fd, buf, pad);
|
1996-06-29 02:48:34 +08:00
|
|
|
}
|
1996-07-08 06:19:32 +08:00
|
|
|
return 0;
|
|
|
|
}
|
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
|
|
|
{
|
1996-11-19 02:02:36 +08:00
|
|
|
return headerNew();
|
1996-07-08 06:19:32 +08:00
|
|
|
}
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
void rpmFreeSignature(Header h)
|
1996-07-08 06:19:32 +08:00
|
|
|
{
|
1996-11-19 02:02:36 +08:00
|
|
|
headerFree(h);
|
1996-07-08 06:19:32 +08:00
|
|
|
}
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
int rpmAddSignature(Header header, char *file, int_32 sigTag, char *passPhrase)
|
1996-07-08 06:19:32 +08:00
|
|
|
{
|
|
|
|
struct stat statbuf;
|
|
|
|
int_32 size;
|
|
|
|
unsigned char buf[16];
|
|
|
|
void *sig;
|
1996-06-20 11:10:44 +08:00
|
|
|
|
1996-07-08 06:19:32 +08:00
|
|
|
switch (sigTag) {
|
1996-11-19 02:02:36 +08:00
|
|
|
case RPMSIGTAG_SIZE:
|
1996-07-08 06:19:32 +08:00
|
|
|
stat(file, &statbuf);
|
|
|
|
size = statbuf.st_size;
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(header, RPMSIGTAG_SIZE, RPM_INT32_TYPE, &size, 1);
|
1996-07-08 06:19:32 +08:00
|
|
|
break;
|
1996-11-19 02:02:36 +08:00
|
|
|
case RPMSIGTAG_MD5:
|
1996-07-08 06:19:32 +08:00
|
|
|
mdbinfile(file, buf);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(header, sigTag, RPM_BIN_TYPE, buf, 16);
|
1996-07-08 06:19:32 +08:00
|
|
|
break;
|
1996-11-19 02:02:36 +08:00
|
|
|
case RPMSIGTAG_PGP:
|
1996-07-08 06:19:32 +08:00
|
|
|
makePGPSignature(file, &sig, &size, passPhrase);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(header, sigTag, RPM_BIN_TYPE, sig, size);
|
1996-07-08 06:19:32 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1996-02-22 09:35:00 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-07-08 06:19:32 +08:00
|
|
|
static int makePGPSignature(char *file, void **sig, int_32 *size,
|
|
|
|
char *passPhrase)
|
1996-02-19 10:32:11 +08:00
|
|
|
{
|
|
|
|
char name[1024];
|
|
|
|
char sigfile[1024];
|
1996-07-08 06:19:32 +08:00
|
|
|
int pid, status;
|
1996-02-19 10:32:11 +08:00
|
|
|
int fd, inpipe[2];
|
|
|
|
FILE *fpipe;
|
1996-02-25 13:05:52 +08:00
|
|
|
struct stat statbuf;
|
1996-02-19 10:32:11 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
sprintf(name, "+myname=\"%s\"", rpmGetVar(RPMVAR_PGP_NAME));
|
1996-02-19 10:32:11 +08:00
|
|
|
|
|
|
|
sprintf(sigfile, "%s.sig", file);
|
|
|
|
|
|
|
|
pipe(inpipe);
|
|
|
|
|
|
|
|
if (!(pid = fork())) {
|
|
|
|
close(0);
|
|
|
|
dup2(inpipe[0], 3);
|
|
|
|
close(inpipe[1]);
|
1996-12-24 22:02:21 +08:00
|
|
|
dosetenv("PGPPASSFD", "3", 1);
|
1996-11-19 02:02:36 +08:00
|
|
|
if (rpmGetVar(RPMVAR_PGP_PATH)) {
|
1996-12-24 22:02:21 +08:00
|
|
|
dosetenv("PGPPATH", rpmGetVar(RPMVAR_PGP_PATH), 1);
|
1996-06-19 22:29:48 +08:00
|
|
|
}
|
1996-12-24 22:02:21 +08:00
|
|
|
/* dosetenv("PGPPASS", passPhrase, 1); */
|
1996-02-19 10:32:11 +08:00
|
|
|
execlp("pgp", "pgp",
|
1996-04-29 22:26:01 +08:00
|
|
|
"+batchmode=on", "+verbose=0", "+armor=off",
|
1996-06-19 22:29:48 +08:00
|
|
|
name, "-sb", file, sigfile,
|
1996-02-19 10:32:11 +08:00
|
|
|
NULL);
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmError(RPMERR_EXEC, "Couldn't exec pgp");
|
1996-12-12 11:35:01 +08:00
|
|
|
_exit(RPMERR_EXEC);
|
1996-02-19 10:32:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fpipe = fdopen(inpipe[1], "w");
|
|
|
|
close(inpipe[0]);
|
|
|
|
fprintf(fpipe, "%s\n", passPhrase);
|
|
|
|
fclose(fpipe);
|
|
|
|
|
|
|
|
waitpid(pid, &status, 0);
|
|
|
|
if (!WIFEXITED(status) || WEXITSTATUS(status)) {
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmError(RPMERR_SIGGEN, "pgp failed");
|
1996-02-19 10:32:11 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1996-02-25 13:05:52 +08:00
|
|
|
if (stat(sigfile, &statbuf)) {
|
|
|
|
/* PGP failed to write signature */
|
|
|
|
unlink(sigfile); /* Just in case */
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmError(RPMERR_SIGGEN, "pgp failed to write signature");
|
1996-02-25 13:05:52 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1996-06-20 11:10:44 +08:00
|
|
|
|
1996-07-08 06:19:32 +08:00
|
|
|
*size = statbuf.st_size;
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "PGP sig size: %d\n", *size);
|
1996-07-08 06:19:32 +08:00
|
|
|
*sig = malloc(*size);
|
1996-02-25 13:05:52 +08:00
|
|
|
|
1996-02-19 10:32:11 +08:00
|
|
|
fd = open(sigfile, O_RDONLY);
|
1996-10-15 11:15:30 +08:00
|
|
|
if (timedRead(fd, *sig, *size) != *size) {
|
1996-06-20 11:10:44 +08:00
|
|
|
unlink(sigfile);
|
|
|
|
close(fd);
|
1996-07-08 06:19:32 +08:00
|
|
|
free(*sig);
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmError(RPMERR_SIGGEN, "unable to read the signature");
|
1996-06-20 11:10:44 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1996-02-19 10:32:11 +08:00
|
|
|
close(fd);
|
|
|
|
unlink(sigfile);
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "Got %d bytes of PGP sig\n", *size);
|
1996-02-19 10:32:11 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-06-29 02:48:34 +08:00
|
|
|
static int checkSize(int fd, int size, int sigsize)
|
|
|
|
{
|
|
|
|
int headerArchiveSize;
|
|
|
|
struct stat statbuf;
|
|
|
|
|
|
|
|
fstat(fd, &statbuf);
|
|
|
|
|
1996-10-15 11:15:30 +08:00
|
|
|
if (S_ISREG(statbuf.st_mode)) {
|
|
|
|
headerArchiveSize = statbuf.st_size - sizeof(struct rpmlead) - sigsize;
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "sigsize : %d\n", sigsize);
|
|
|
|
rpmMessage(RPMMESS_DEBUG, "Header + Archive: %d\n", headerArchiveSize);
|
|
|
|
rpmMessage(RPMMESS_DEBUG, "expected size : %d\n", size);
|
1996-06-29 02:48:34 +08:00
|
|
|
|
1996-10-15 11:15:30 +08:00
|
|
|
return size - headerArchiveSize;
|
|
|
|
} else {
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "file is not regular -- skipping size check\n");
|
1996-10-15 11:15:30 +08:00
|
|
|
return 0;
|
|
|
|
}
|
1996-06-29 02:48:34 +08:00
|
|
|
}
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
int rpmVerifySignature(char *file, int_32 sigTag, void *sig, int count,
|
1996-07-08 11:27:05 +08:00
|
|
|
char *result)
|
1996-07-08 06:19:32 +08:00
|
|
|
{
|
1996-07-08 11:27:05 +08:00
|
|
|
switch (sigTag) {
|
1996-11-19 02:02:36 +08:00
|
|
|
case RPMSIGTAG_SIZE:
|
1996-07-08 11:27:05 +08:00
|
|
|
if (verifySizeSignature(file, *(int_32 *)sig, result)) {
|
|
|
|
return RPMSIG_BAD;
|
1996-07-08 06:19:32 +08:00
|
|
|
}
|
|
|
|
break;
|
1996-11-19 02:02:36 +08:00
|
|
|
case RPMSIGTAG_MD5:
|
1996-09-01 02:36:53 +08:00
|
|
|
if (verifyMD5Signature(file, sig, result, mdbinfile)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
1996-11-19 02:02:36 +08:00
|
|
|
case RPMSIGTAG_LITTLEENDIANMD5:
|
1996-09-01 02:36:53 +08:00
|
|
|
if (verifyMD5Signature(file, sig, result, mdbinfileBroken)) {
|
1996-07-08 11:27:05 +08:00
|
|
|
return 1;
|
1996-07-08 06:19:32 +08:00
|
|
|
}
|
|
|
|
break;
|
1996-11-19 02:02:36 +08:00
|
|
|
case RPMSIGTAG_PGP:
|
1996-07-13 03:27:34 +08:00
|
|
|
return verifyPGPSignature(file, sig, count, result);
|
1996-07-08 06:19:32 +08:00
|
|
|
break;
|
|
|
|
default:
|
1996-07-08 11:27:05 +08:00
|
|
|
sprintf(result, "Do not know how to verify sig type %d\n", sigTag);
|
|
|
|
return RPMSIG_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RPMSIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int verifySizeSignature(char *datafile, int_32 size, char *result)
|
|
|
|
{
|
|
|
|
struct stat statbuf;
|
|
|
|
|
|
|
|
stat(datafile, &statbuf);
|
|
|
|
if (size != statbuf.st_size) {
|
|
|
|
sprintf(result, "Header+Archive size mismatch.\n"
|
|
|
|
"Expected %d, saw %d.\n",
|
|
|
|
size, (int)statbuf.st_size);
|
|
|
|
return 1;
|
1996-07-08 06:19:32 +08:00
|
|
|
}
|
|
|
|
|
1996-07-08 11:27:05 +08:00
|
|
|
sprintf(result, "Header+Archive size OK: %d bytes\n", size);
|
|
|
|
return 0;
|
1996-07-08 06:19:32 +08:00
|
|
|
}
|
|
|
|
|
1996-09-01 02:36:53 +08:00
|
|
|
static int verifyMD5Signature(char *datafile, unsigned char *sig,
|
|
|
|
char *result, md5func fn)
|
1996-02-19 10:32:11 +08:00
|
|
|
{
|
1996-07-08 11:27:05 +08:00
|
|
|
unsigned char md5sum[16];
|
|
|
|
|
1996-09-01 02:36:53 +08:00
|
|
|
fn(datafile, md5sum);
|
1996-07-08 11:27:05 +08:00
|
|
|
if (memcmp(md5sum, sig, 16)) {
|
|
|
|
sprintf(result, "MD5 sum mismatch\n"
|
|
|
|
"Expected: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
|
|
|
|
"%02x%02x%02x%02x%02x\n"
|
|
|
|
"Saw : %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
|
|
|
|
"%02x%02x%02x%02x%02x\n",
|
|
|
|
sig[0], sig[1], sig[2], sig[3],
|
|
|
|
sig[4], sig[5], sig[6], sig[7],
|
|
|
|
sig[8], sig[9], sig[10], sig[11],
|
|
|
|
sig[12], sig[13], sig[14], sig[15],
|
|
|
|
md5sum[0], md5sum[1], md5sum[2], md5sum[3],
|
|
|
|
md5sum[4], md5sum[5], md5sum[6], md5sum[7],
|
|
|
|
md5sum[8], md5sum[9], md5sum[10], md5sum[11],
|
|
|
|
md5sum[12], md5sum[13], md5sum[14], md5sum[15]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(result, "MD5 sum OK: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
|
|
|
|
"%02x%02x%02x%02x%02x\n",
|
|
|
|
md5sum[0], md5sum[1], md5sum[2], md5sum[3],
|
|
|
|
md5sum[4], md5sum[5], md5sum[6], md5sum[7],
|
|
|
|
md5sum[8], md5sum[9], md5sum[10], md5sum[11],
|
|
|
|
md5sum[12], md5sum[13], md5sum[14], md5sum[15]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int verifyPGPSignature(char *datafile, void *sig,
|
|
|
|
int count, char *result)
|
|
|
|
{
|
|
|
|
int pid, status, outpipe[2], sfd;
|
|
|
|
char *sigfile;
|
1996-02-19 10:32:11 +08:00
|
|
|
unsigned char buf[8192];
|
|
|
|
FILE *file;
|
1996-07-13 03:27:34 +08:00
|
|
|
int res = RPMSIG_OK;
|
1996-02-19 10:32:11 +08:00
|
|
|
|
1996-07-08 11:27:05 +08:00
|
|
|
/* Write out the signature */
|
1996-11-19 02:02:36 +08:00
|
|
|
sigfile = tempnam(rpmGetVar(RPMVAR_TMPPATH), "rpmsig");
|
1996-07-08 11:27:05 +08:00
|
|
|
sfd = open(sigfile, O_WRONLY|O_CREAT|O_TRUNC, 0644);
|
|
|
|
write(sfd, sig, count);
|
|
|
|
close(sfd);
|
|
|
|
|
1996-02-19 10:32:11 +08:00
|
|
|
/* Now run PGP */
|
|
|
|
pipe(outpipe);
|
|
|
|
|
|
|
|
if (!(pid = fork())) {
|
|
|
|
close(1);
|
|
|
|
close(outpipe[0]);
|
|
|
|
dup2(outpipe[1], 1);
|
1996-11-19 02:02:36 +08:00
|
|
|
if (rpmGetVar(RPMVAR_PGP_PATH)) {
|
1996-12-24 22:02:21 +08:00
|
|
|
dosetenv("PGPPATH", rpmGetVar(RPMVAR_PGP_PATH), 1);
|
1996-06-19 22:29:48 +08:00
|
|
|
}
|
1996-02-19 10:32:11 +08:00
|
|
|
execlp("pgp", "pgp",
|
|
|
|
"+batchmode=on", "+verbose=0",
|
|
|
|
sigfile, datafile,
|
|
|
|
NULL);
|
|
|
|
printf("exec failed!\n");
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmError(RPMERR_EXEC, "Could not run pgp. Use --nopgp to skip PGP checks.");
|
1996-12-12 11:35:01 +08:00
|
|
|
_exit(RPMERR_EXEC);
|
1996-02-19 10:32:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
close(outpipe[1]);
|
|
|
|
file = fdopen(outpipe[0], "r");
|
|
|
|
result[0] = '\0';
|
|
|
|
while (fgets(buf, 1024, file)) {
|
1996-07-08 11:27:05 +08:00
|
|
|
if (strncmp("File '", buf, 6) &&
|
|
|
|
strncmp("Text is assu", buf, 12) &&
|
|
|
|
buf[0] != '\n') {
|
1996-02-19 10:32:11 +08:00
|
|
|
strcat(result, buf);
|
|
|
|
}
|
1996-07-13 03:27:34 +08:00
|
|
|
if (!strncmp("WARNING: Can't find the right public key", buf, 40)) {
|
|
|
|
res = RPMSIG_NOKEY;
|
|
|
|
}
|
1996-02-19 10:32:11 +08:00
|
|
|
}
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
waitpid(pid, &status, 0);
|
1996-07-12 07:42:46 +08:00
|
|
|
unlink(sigfile);
|
1996-07-13 03:27:34 +08:00
|
|
|
if (!res && (!WIFEXITED(status) || WEXITSTATUS(status))) {
|
|
|
|
res = RPMSIG_BAD;
|
1996-02-19 10:32:11 +08:00
|
|
|
}
|
|
|
|
|
1996-07-13 03:27:34 +08:00
|
|
|
return res;
|
1996-02-19 10:32:11 +08:00
|
|
|
}
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
char *rpmGetPassPhrase(char *prompt)
|
1996-02-19 10:32:11 +08:00
|
|
|
{
|
1996-06-20 11:10:44 +08:00
|
|
|
char *pass;
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
if (! rpmGetVar(RPMVAR_PGP_NAME)) {
|
|
|
|
rpmError(RPMERR_SIGGEN,
|
1996-06-20 11:10:44 +08:00
|
|
|
"You must set \"pgp_name:\" in your rpmrc file");
|
|
|
|
return NULL;
|
1996-02-19 10:32:11 +08:00
|
|
|
}
|
|
|
|
|
1996-06-20 11:10:44 +08:00
|
|
|
if (prompt) {
|
|
|
|
pass = getpass(prompt);
|
|
|
|
} else {
|
|
|
|
pass = getpass("");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (checkPassPhrase(pass)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pass;
|
1996-02-19 10:32:11 +08:00
|
|
|
}
|
|
|
|
|
1996-06-20 11:10:44 +08:00
|
|
|
static int checkPassPhrase(char *passPhrase)
|
1996-02-19 10:32:11 +08:00
|
|
|
{
|
1996-06-20 11:10:44 +08:00
|
|
|
char name[1024];
|
|
|
|
int passPhrasePipe[2];
|
|
|
|
FILE *fpipe;
|
|
|
|
int pid, status;
|
|
|
|
int fd;
|
1996-02-19 10:32:11 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
sprintf(name, "+myname=\"%s\"", rpmGetVar(RPMVAR_PGP_NAME));
|
1996-06-20 11:10:44 +08:00
|
|
|
|
|
|
|
pipe(passPhrasePipe);
|
|
|
|
if (!(pid = fork())) {
|
|
|
|
close(0);
|
|
|
|
close(1);
|
1996-11-19 02:02:36 +08:00
|
|
|
if (! rpmIsVerbose()) {
|
1996-06-20 11:10:44 +08:00
|
|
|
close(2);
|
|
|
|
}
|
|
|
|
if ((fd = open("/dev/null", O_RDONLY)) != 0) {
|
|
|
|
dup2(fd, 0);
|
|
|
|
}
|
|
|
|
if ((fd = open("/dev/null", O_WRONLY)) != 1) {
|
|
|
|
dup2(fd, 1);
|
|
|
|
}
|
|
|
|
dup2(passPhrasePipe[0], 3);
|
1996-12-24 22:02:21 +08:00
|
|
|
dosetenv("PGPPASSFD", "3", 1);
|
1996-11-19 02:02:36 +08:00
|
|
|
if (rpmGetVar(RPMVAR_PGP_PATH)) {
|
1996-12-24 22:02:21 +08:00
|
|
|
dosetenv("PGPPATH", rpmGetVar(RPMVAR_PGP_PATH), 1);
|
1996-06-20 11:10:44 +08:00
|
|
|
}
|
|
|
|
execlp("pgp", "pgp",
|
|
|
|
"+batchmode=on", "+verbose=0",
|
|
|
|
name, "-sf",
|
|
|
|
NULL);
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmError(RPMERR_EXEC, "Couldn't exec pgp");
|
1996-12-12 11:35:01 +08:00
|
|
|
_exit(RPMERR_EXEC);
|
1996-02-19 10:32:11 +08:00
|
|
|
}
|
|
|
|
|
1996-06-20 11:10:44 +08:00
|
|
|
fpipe = fdopen(passPhrasePipe[1], "w");
|
|
|
|
close(passPhrasePipe[0]);
|
|
|
|
fprintf(fpipe, "%s\n", passPhrase);
|
|
|
|
fclose(fpipe);
|
|
|
|
|
|
|
|
waitpid(pid, &status, 0);
|
|
|
|
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
|
|
|
}
|