rpm/lib/signature.c

670 lines
17 KiB
C
Raw Normal View History

/* signature.c - RPM signature functions */
/* NOTES
*
* 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.
*/
#include "system.h"
#if HAVE_ASM_BYTEORDER_H
#include <asm/byteorder.h>
#endif
#include "rpmlib.h"
#include "md5.h"
#include "misc.h"
#include "rpmlead.h"
#include "signature.h"
typedef int (*md5func)(const char * fn, unsigned char * digest);
static int makePGPSignature(const char *file, void **sig, int_32 *size,
const char *passPhrase);
1998 8 Jan Toshio Kuratomi <badger@prtr-13.ucsc.edu> * rpm.c: An error message for --nomd5 incorrectly read "--nopgp can only be used during...."... Changed the --nopgp to --nomd5 1998 7 Jan Toshio Kuratomi <bagder@prtr-13.ucsc.edu> * lib/rpmlib.h: Add a RPMSIGTAG_GPG define for gnupg. * lib/rpmlib.h: Add RPMVAR_GPG_PATH and RPMVAR_GPG_NAME variables. * lib/rpmrc.c: (optionTable) Add gpg_path and gpg_name to the optionTable (same stats as pgp_name and pgp_path.) * lib/signature.c: (rpmLookupSignatureType) Add RPMSIGTAG_GPG as one of the recognized types. * lib/signature.c: (rpmAddSignature) Add ability to create gnupg signature. * lib/signature.c: (makeGPGSignature) Routine to create a gnupg signature (based on makePGPSignature.) * lib/signature.c: (rpmVerifySignature) Add ability to verify gnupg signatures. * lib/signature.c: (verifyGPGSignature) Routine to verify a gnupg signature (based on verifyPGPSignature.) * lib/signature.c: (rpmGetPassPhrase) When getting pass phrase for gnupg, use RPMVAR_GPG_NAME instead of RPMVAR_PGP_NAME if we are signing with GPG isntead of PGP. * lib/signature.c: (checkPassPhrase) Need to allow for GPG when we check the PassPhrase's correctness. * rpm.c: Add equivalent GPG lines everywhere we find a PGP line. * rpm.c: Add equivalent gpg stanzas wherever we find a pgp stanza. * checksig.h: define CHECKSIG_GPG (1 << 2) [Is this correct?] * checksig.c: (doCheckSig) Check for GPG signatures. [A lot could be wrong/left out here.] * rpm.c: change the call to rpmGetPassPhrase to throw in the sigType as well. * signature.h: change rpmGetPassPhrase declaration to: rpmGetPassPhrase(const char * prompt, const int sigTag); * signature.c: (rpmGetPassPhrase) change the function to accept the signature type as its second argument. CVS patchset: 2686 CVS date: 1999/01/09 00:24:02
1999-01-09 08:24:02 +08:00
static int makeGPGSignature(const char *file, void **sig, int_32 *size,
const char *passPhrase);
static int checkSize(FD_t fd, int size, int sigsize);
static int verifySizeSignature(const char *datafile, int_32 size, char *result);
static int verifyMD5Signature(const char *datafile, unsigned char *sig,
char *result, md5func fn);
static int verifyPGPSignature(const char *datafile, void *sig,
int count, char *result);
1998 8 Jan Toshio Kuratomi <badger@prtr-13.ucsc.edu> * rpm.c: An error message for --nomd5 incorrectly read "--nopgp can only be used during...."... Changed the --nopgp to --nomd5 1998 7 Jan Toshio Kuratomi <bagder@prtr-13.ucsc.edu> * lib/rpmlib.h: Add a RPMSIGTAG_GPG define for gnupg. * lib/rpmlib.h: Add RPMVAR_GPG_PATH and RPMVAR_GPG_NAME variables. * lib/rpmrc.c: (optionTable) Add gpg_path and gpg_name to the optionTable (same stats as pgp_name and pgp_path.) * lib/signature.c: (rpmLookupSignatureType) Add RPMSIGTAG_GPG as one of the recognized types. * lib/signature.c: (rpmAddSignature) Add ability to create gnupg signature. * lib/signature.c: (makeGPGSignature) Routine to create a gnupg signature (based on makePGPSignature.) * lib/signature.c: (rpmVerifySignature) Add ability to verify gnupg signatures. * lib/signature.c: (verifyGPGSignature) Routine to verify a gnupg signature (based on verifyPGPSignature.) * lib/signature.c: (rpmGetPassPhrase) When getting pass phrase for gnupg, use RPMVAR_GPG_NAME instead of RPMVAR_PGP_NAME if we are signing with GPG isntead of PGP. * lib/signature.c: (checkPassPhrase) Need to allow for GPG when we check the PassPhrase's correctness. * rpm.c: Add equivalent GPG lines everywhere we find a PGP line. * rpm.c: Add equivalent gpg stanzas wherever we find a pgp stanza. * checksig.h: define CHECKSIG_GPG (1 << 2) [Is this correct?] * checksig.c: (doCheckSig) Check for GPG signatures. [A lot could be wrong/left out here.] * rpm.c: change the call to rpmGetPassPhrase to throw in the sigType as well. * signature.h: change rpmGetPassPhrase declaration to: rpmGetPassPhrase(const char * prompt, const int sigTag); * signature.c: (rpmGetPassPhrase) change the function to accept the signature type as its second argument. CVS patchset: 2686 CVS date: 1999/01/09 00:24:02
1999-01-09 08:24:02 +08:00
static int verifyGPGSignature(const char *datafile, void *sig,
int count, char *result);
static int checkPassPhrase(const char *passPhrase, const int sigType);
int rpmLookupSignatureType(void)
{
char *name;
if (! (name = rpmGetVar(RPMVAR_SIGTYPE))) {
return 0;
}
1998 8 Jan Toshio Kuratomi <badger@prtr-13.ucsc.edu> * rpm.c: An error message for --nomd5 incorrectly read "--nopgp can only be used during...."... Changed the --nopgp to --nomd5 1998 7 Jan Toshio Kuratomi <bagder@prtr-13.ucsc.edu> * lib/rpmlib.h: Add a RPMSIGTAG_GPG define for gnupg. * lib/rpmlib.h: Add RPMVAR_GPG_PATH and RPMVAR_GPG_NAME variables. * lib/rpmrc.c: (optionTable) Add gpg_path and gpg_name to the optionTable (same stats as pgp_name and pgp_path.) * lib/signature.c: (rpmLookupSignatureType) Add RPMSIGTAG_GPG as one of the recognized types. * lib/signature.c: (rpmAddSignature) Add ability to create gnupg signature. * lib/signature.c: (makeGPGSignature) Routine to create a gnupg signature (based on makePGPSignature.) * lib/signature.c: (rpmVerifySignature) Add ability to verify gnupg signatures. * lib/signature.c: (verifyGPGSignature) Routine to verify a gnupg signature (based on verifyPGPSignature.) * lib/signature.c: (rpmGetPassPhrase) When getting pass phrase for gnupg, use RPMVAR_GPG_NAME instead of RPMVAR_PGP_NAME if we are signing with GPG isntead of PGP. * lib/signature.c: (checkPassPhrase) Need to allow for GPG when we check the PassPhrase's correctness. * rpm.c: Add equivalent GPG lines everywhere we find a PGP line. * rpm.c: Add equivalent gpg stanzas wherever we find a pgp stanza. * checksig.h: define CHECKSIG_GPG (1 << 2) [Is this correct?] * checksig.c: (doCheckSig) Check for GPG signatures. [A lot could be wrong/left out here.] * rpm.c: change the call to rpmGetPassPhrase to throw in the sigType as well. * signature.h: change rpmGetPassPhrase declaration to: rpmGetPassPhrase(const char * prompt, const int sigTag); * signature.c: (rpmGetPassPhrase) change the function to accept the signature type as its second argument. CVS patchset: 2686 CVS date: 1999/01/09 00:24:02
1999-01-09 08:24:02 +08:00
if (!strcasecmp(name, "none"))
return 0;
1998 8 Jan Toshio Kuratomi <badger@prtr-13.ucsc.edu> * rpm.c: An error message for --nomd5 incorrectly read "--nopgp can only be used during...."... Changed the --nopgp to --nomd5 1998 7 Jan Toshio Kuratomi <bagder@prtr-13.ucsc.edu> * lib/rpmlib.h: Add a RPMSIGTAG_GPG define for gnupg. * lib/rpmlib.h: Add RPMVAR_GPG_PATH and RPMVAR_GPG_NAME variables. * lib/rpmrc.c: (optionTable) Add gpg_path and gpg_name to the optionTable (same stats as pgp_name and pgp_path.) * lib/signature.c: (rpmLookupSignatureType) Add RPMSIGTAG_GPG as one of the recognized types. * lib/signature.c: (rpmAddSignature) Add ability to create gnupg signature. * lib/signature.c: (makeGPGSignature) Routine to create a gnupg signature (based on makePGPSignature.) * lib/signature.c: (rpmVerifySignature) Add ability to verify gnupg signatures. * lib/signature.c: (verifyGPGSignature) Routine to verify a gnupg signature (based on verifyPGPSignature.) * lib/signature.c: (rpmGetPassPhrase) When getting pass phrase for gnupg, use RPMVAR_GPG_NAME instead of RPMVAR_PGP_NAME if we are signing with GPG isntead of PGP. * lib/signature.c: (checkPassPhrase) Need to allow for GPG when we check the PassPhrase's correctness. * rpm.c: Add equivalent GPG lines everywhere we find a PGP line. * rpm.c: Add equivalent gpg stanzas wherever we find a pgp stanza. * checksig.h: define CHECKSIG_GPG (1 << 2) [Is this correct?] * checksig.c: (doCheckSig) Check for GPG signatures. [A lot could be wrong/left out here.] * rpm.c: change the call to rpmGetPassPhrase to throw in the sigType as well. * signature.h: change rpmGetPassPhrase declaration to: rpmGetPassPhrase(const char * prompt, const int sigTag); * signature.c: (rpmGetPassPhrase) change the function to accept the signature type as its second argument. CVS patchset: 2686 CVS date: 1999/01/09 00:24:02
1999-01-09 08:24:02 +08:00
else if (!strcasecmp(name, "pgp"))
return RPMSIGTAG_PGP;
1998 8 Jan Toshio Kuratomi <badger@prtr-13.ucsc.edu> * rpm.c: An error message for --nomd5 incorrectly read "--nopgp can only be used during...."... Changed the --nopgp to --nomd5 1998 7 Jan Toshio Kuratomi <bagder@prtr-13.ucsc.edu> * lib/rpmlib.h: Add a RPMSIGTAG_GPG define for gnupg. * lib/rpmlib.h: Add RPMVAR_GPG_PATH and RPMVAR_GPG_NAME variables. * lib/rpmrc.c: (optionTable) Add gpg_path and gpg_name to the optionTable (same stats as pgp_name and pgp_path.) * lib/signature.c: (rpmLookupSignatureType) Add RPMSIGTAG_GPG as one of the recognized types. * lib/signature.c: (rpmAddSignature) Add ability to create gnupg signature. * lib/signature.c: (makeGPGSignature) Routine to create a gnupg signature (based on makePGPSignature.) * lib/signature.c: (rpmVerifySignature) Add ability to verify gnupg signatures. * lib/signature.c: (verifyGPGSignature) Routine to verify a gnupg signature (based on verifyPGPSignature.) * lib/signature.c: (rpmGetPassPhrase) When getting pass phrase for gnupg, use RPMVAR_GPG_NAME instead of RPMVAR_PGP_NAME if we are signing with GPG isntead of PGP. * lib/signature.c: (checkPassPhrase) Need to allow for GPG when we check the PassPhrase's correctness. * rpm.c: Add equivalent GPG lines everywhere we find a PGP line. * rpm.c: Add equivalent gpg stanzas wherever we find a pgp stanza. * checksig.h: define CHECKSIG_GPG (1 << 2) [Is this correct?] * checksig.c: (doCheckSig) Check for GPG signatures. [A lot could be wrong/left out here.] * rpm.c: change the call to rpmGetPassPhrase to throw in the sigType as well. * signature.h: change rpmGetPassPhrase declaration to: rpmGetPassPhrase(const char * prompt, const int sigTag); * signature.c: (rpmGetPassPhrase) change the function to accept the signature type as its second argument. CVS patchset: 2686 CVS date: 1999/01/09 00:24:02
1999-01-09 08:24:02 +08:00
else if (!strcasecmp(name, "gpg"))
return RPMSIGTAG_GPG;
else
return -1;
}
/* rpmReadSignature() emulates the new style signatures if it finds an */
/* old-style one. It also immediately verifies the header+archive */
/* size and returns an error if it doesn't match. */
int rpmReadSignature(FD_t fd, Header *header, short sig_type)
{
unsigned char buf[2048];
int sigSize, pad;
int_32 type, count;
int_32 *archSize;
Header h;
if (header) {
*header = NULL;
}
switch (sig_type) {
case RPMSIG_NONE:
rpmMessage(RPMMESS_DEBUG, _("No signature\n"));
break;
case RPMSIG_PGP262_1024:
rpmMessage(RPMMESS_DEBUG, _("Old PGP signature\n"));
/* These are always 256 bytes */
if (timedRead(fd, buf, 256) != 256) {
return 1;
}
if (header) {
*header = headerNew();
headerAddEntry(*header, RPMSIGTAG_PGP, RPM_BIN_TYPE, buf, 152);
}
break;
case RPMSIG_MD5:
case RPMSIG_MD5_PGP:
rpmError(RPMERR_BADSIGTYPE,
_("Old (internal-only) signature! How did you get that!?"));
return 1;
break;
case RPMSIG_HEADERSIG:
rpmMessage(RPMMESS_DEBUG, _("New Header signature\n"));
/* This is a new style signature */
h = headerRead(fd, HEADER_MAGIC_YES);
if (h == NULL) {
return 1;
}
sigSize = headerSizeof(h, HEADER_MAGIC_YES);
pad = (8 - (sigSize % 8)) % 8; /* 8-byte pad */
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);
return 1;
}
if (checkSize(fd, *archSize, sigSize + pad)) {
headerFree(h);
return 1;
}
if (pad) {
if (timedRead(fd, buf, pad) != pad) {
headerFree(h);
return 1;
}
}
if (header) {
*header = h;
} else {
headerFree(h);
}
break;
default:
return 1;
}
return 0;
}
int rpmWriteSignature(FD_t fd, Header header)
{
int sigSize, pad;
unsigned char buf[8];
headerWrite(fd, header, HEADER_MAGIC_YES);
sigSize = headerSizeof(header, HEADER_MAGIC_YES);
pad = (8 - (sigSize % 8)) % 8;
if (pad) {
rpmMessage(RPMMESS_DEBUG, _("Signature size: %d\n"), sigSize);
rpmMessage(RPMMESS_DEBUG, _("Signature pad : %d\n"), pad);
memset(buf, 0, pad);
(void)fdWrite(fd, buf, pad);
}
return 0;
}
Header rpmNewSignature(void)
{
return headerNew();
}
void rpmFreeSignature(Header h)
{
headerFree(h);
}
int rpmAddSignature(Header header, const char *file, int_32 sigTag, const char *passPhrase)
{
struct stat statbuf;
int_32 size;
unsigned char buf[16];
void *sig;
switch (sigTag) {
case RPMSIGTAG_SIZE:
stat(file, &statbuf);
size = statbuf.st_size;
headerAddEntry(header, RPMSIGTAG_SIZE, RPM_INT32_TYPE, &size, 1);
break;
case RPMSIGTAG_MD5:
mdbinfile(file, buf);
headerAddEntry(header, sigTag, RPM_BIN_TYPE, buf, 16);
break;
case RPMSIGTAG_PGP:
makePGPSignature(file, &sig, &size, passPhrase);
headerAddEntry(header, sigTag, RPM_BIN_TYPE, sig, size);
break;
1998 8 Jan Toshio Kuratomi <badger@prtr-13.ucsc.edu> * rpm.c: An error message for --nomd5 incorrectly read "--nopgp can only be used during...."... Changed the --nopgp to --nomd5 1998 7 Jan Toshio Kuratomi <bagder@prtr-13.ucsc.edu> * lib/rpmlib.h: Add a RPMSIGTAG_GPG define for gnupg. * lib/rpmlib.h: Add RPMVAR_GPG_PATH and RPMVAR_GPG_NAME variables. * lib/rpmrc.c: (optionTable) Add gpg_path and gpg_name to the optionTable (same stats as pgp_name and pgp_path.) * lib/signature.c: (rpmLookupSignatureType) Add RPMSIGTAG_GPG as one of the recognized types. * lib/signature.c: (rpmAddSignature) Add ability to create gnupg signature. * lib/signature.c: (makeGPGSignature) Routine to create a gnupg signature (based on makePGPSignature.) * lib/signature.c: (rpmVerifySignature) Add ability to verify gnupg signatures. * lib/signature.c: (verifyGPGSignature) Routine to verify a gnupg signature (based on verifyPGPSignature.) * lib/signature.c: (rpmGetPassPhrase) When getting pass phrase for gnupg, use RPMVAR_GPG_NAME instead of RPMVAR_PGP_NAME if we are signing with GPG isntead of PGP. * lib/signature.c: (checkPassPhrase) Need to allow for GPG when we check the PassPhrase's correctness. * rpm.c: Add equivalent GPG lines everywhere we find a PGP line. * rpm.c: Add equivalent gpg stanzas wherever we find a pgp stanza. * checksig.h: define CHECKSIG_GPG (1 << 2) [Is this correct?] * checksig.c: (doCheckSig) Check for GPG signatures. [A lot could be wrong/left out here.] * rpm.c: change the call to rpmGetPassPhrase to throw in the sigType as well. * signature.h: change rpmGetPassPhrase declaration to: rpmGetPassPhrase(const char * prompt, const int sigTag); * signature.c: (rpmGetPassPhrase) change the function to accept the signature type as its second argument. CVS patchset: 2686 CVS date: 1999/01/09 00:24:02
1999-01-09 08:24:02 +08:00
case RPMSIGTAG_GPG:
makeGPGSignature(file, &sig, &size, passPhrase);
headerAddEntry(header, sigTag, RPM_BIN_TYPE, sig, size);
break;
}
return 0;
}
static int makePGPSignature(const char *file, void **sig, int_32 *size,
const char *passPhrase)
{
char name[1024];
char sigfile[1024];
int pid, status;
int inpipe[2];
FILE *fpipe;
struct stat statbuf;
sprintf(name, "+myname=\"%s\"", rpmGetVar(RPMVAR_PGP_NAME));
sprintf(sigfile, "%s.sig", file);
pipe(inpipe);
if (!(pid = fork())) {
close(STDIN_FILENO);
dup2(inpipe[0], 3);
close(inpipe[1]);
dosetenv("PGPPASSFD", "3", 1);
if (rpmGetVar(RPMVAR_PGP_PATH)) {
dosetenv("PGPPATH", rpmGetVar(RPMVAR_PGP_PATH), 1);
}
/* dosetenv("PGPPASS", passPhrase, 1); */
execlp("pgp", "pgp",
"+batchmode=on", "+verbose=0", "+armor=off",
name, "-sb", file, sigfile,
NULL);
rpmError(RPMERR_EXEC, _("Couldn't exec pgp"));
_exit(RPMERR_EXEC);
}
fpipe = fdopen(inpipe[1], "w");
close(inpipe[0]);
fprintf(fpipe, "%s\n", passPhrase);
fclose(fpipe);
(void)waitpid(pid, &status, 0);
if (!WIFEXITED(status) || WEXITSTATUS(status)) {
rpmError(RPMERR_SIGGEN, _("pgp failed"));
return 1;
}
if (stat(sigfile, &statbuf)) {
/* PGP failed to write signature */
unlink(sigfile); /* Just in case */
rpmError(RPMERR_SIGGEN, _("pgp failed to write signature"));
return 1;
}
*size = statbuf.st_size;
rpmMessage(RPMMESS_DEBUG, _("PGP sig size: %d\n"), *size);
*sig = malloc(*size);
{ FD_t fd;
int rc;
fd = fdOpen(sigfile, O_RDONLY, 0);
rc = timedRead(fd, *sig, *size);
unlink(sigfile);
fdClose(fd);
if (rc != *size) {
free(*sig);
rpmError(RPMERR_SIGGEN, _("unable to read the signature"));
return 1;
}
}
rpmMessage(RPMMESS_DEBUG, _("Got %d bytes of PGP sig\n"), *size);
return 0;
}
1998 8 Jan Toshio Kuratomi <badger@prtr-13.ucsc.edu> * rpm.c: An error message for --nomd5 incorrectly read "--nopgp can only be used during...."... Changed the --nopgp to --nomd5 1998 7 Jan Toshio Kuratomi <bagder@prtr-13.ucsc.edu> * lib/rpmlib.h: Add a RPMSIGTAG_GPG define for gnupg. * lib/rpmlib.h: Add RPMVAR_GPG_PATH and RPMVAR_GPG_NAME variables. * lib/rpmrc.c: (optionTable) Add gpg_path and gpg_name to the optionTable (same stats as pgp_name and pgp_path.) * lib/signature.c: (rpmLookupSignatureType) Add RPMSIGTAG_GPG as one of the recognized types. * lib/signature.c: (rpmAddSignature) Add ability to create gnupg signature. * lib/signature.c: (makeGPGSignature) Routine to create a gnupg signature (based on makePGPSignature.) * lib/signature.c: (rpmVerifySignature) Add ability to verify gnupg signatures. * lib/signature.c: (verifyGPGSignature) Routine to verify a gnupg signature (based on verifyPGPSignature.) * lib/signature.c: (rpmGetPassPhrase) When getting pass phrase for gnupg, use RPMVAR_GPG_NAME instead of RPMVAR_PGP_NAME if we are signing with GPG isntead of PGP. * lib/signature.c: (checkPassPhrase) Need to allow for GPG when we check the PassPhrase's correctness. * rpm.c: Add equivalent GPG lines everywhere we find a PGP line. * rpm.c: Add equivalent gpg stanzas wherever we find a pgp stanza. * checksig.h: define CHECKSIG_GPG (1 << 2) [Is this correct?] * checksig.c: (doCheckSig) Check for GPG signatures. [A lot could be wrong/left out here.] * rpm.c: change the call to rpmGetPassPhrase to throw in the sigType as well. * signature.h: change rpmGetPassPhrase declaration to: rpmGetPassPhrase(const char * prompt, const int sigTag); * signature.c: (rpmGetPassPhrase) change the function to accept the signature type as its second argument. CVS patchset: 2686 CVS date: 1999/01/09 00:24:02
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.
*/
static int makeGPGSignature(const char *file, void **sig, int_32 *size,
const char *passPhrase)
{
char name[1024];
char sigfile[1024];
int pid, status;
int inpipe[2];
FILE *fpipe;
struct stat statbuf;
sprintf(name, "%s", rpmGetVar(RPMVAR_GPG_NAME));
sprintf(sigfile, "%s.sig", file);
pipe(inpipe);
if (!(pid = fork())) {
close(STDIN_FILENO);
dup2(inpipe[0], 3);
close(inpipe[1]);
if (rpmGetVar(RPMVAR_GPG_PATH)) {
dosetenv("GNUPGHOME", rpmGetVar(RPMVAR_GPG_PATH), 1);
}
execlp("gpg", "gpg",
"--batch", "--no-verbose", "--no-armor", "--passphrase-fd", "3",
"-u", name, "-sbo", sigfile, file,
NULL);
rpmError(RPMERR_EXEC, _("Couldn't exec gpg"));
_exit(RPMERR_EXEC);
}
fpipe = fdopen(inpipe[1], "w");
close(inpipe[0]);
fprintf(fpipe, "%s\n", passPhrase);
fclose(fpipe);
(void)waitpid(pid, &status, 0);
if (!WIFEXITED(status) || WEXITSTATUS(status)) {
rpmError(RPMERR_SIGGEN, _("gpg failed"));
return 1;
}
if (stat(sigfile, &statbuf)) {
/* GPG failed to write signature */
unlink(sigfile); /* Just in case */
rpmError(RPMERR_SIGGEN, _("gpg failed to write signature"));
return 1;
}
*size = statbuf.st_size;
rpmMessage(RPMMESS_DEBUG, _("GPG sig size: %d\n"), *size);
*sig = malloc(*size);
{ FD_t fd;
int rc;
fd = fdOpen(sigfile, O_RDONLY, 0);
rc = timedRead(fd, *sig, *size);
unlink(sigfile);
fdClose(fd);
if (rc != *size) {
free(*sig);
rpmError(RPMERR_SIGGEN, _("unable to read the signature"));
return 1;
}
}
rpmMessage(RPMMESS_DEBUG, _("Got %d bytes of GPG sig\n"), *size);
return 0;
}
static int checkSize(FD_t fd, int size, int sigsize)
{
int headerArchiveSize;
struct stat statbuf;
fstat(fdFileno(fd), &statbuf);
if (S_ISREG(statbuf.st_mode)) {
headerArchiveSize = statbuf.st_size - sizeof(struct rpmlead) - sigsize;
rpmMessage(RPMMESS_DEBUG, _("sigsize : %d\n"), sigsize);
rpmMessage(RPMMESS_DEBUG, _("Header + Archive: %d\n"), headerArchiveSize);
rpmMessage(RPMMESS_DEBUG, _("expected size : %d\n"), size);
return size - headerArchiveSize;
} else {
rpmMessage(RPMMESS_DEBUG, _("file is not regular -- skipping size check\n"));
return 0;
}
}
int rpmVerifySignature(const char *file, int_32 sigTag, void *sig, int count,
char *result)
{
switch (sigTag) {
case RPMSIGTAG_SIZE:
if (verifySizeSignature(file, *(int_32 *)sig, result)) {
return RPMSIG_BAD;
}
break;
case RPMSIGTAG_MD5:
if (verifyMD5Signature(file, sig, result, mdbinfile)) {
return 1;
}
break;
case RPMSIGTAG_LEMD5_1:
case RPMSIGTAG_LEMD5_2:
if (verifyMD5Signature(file, sig, result, mdbinfileBroken)) {
return 1;
}
break;
case RPMSIGTAG_PGP:
return verifyPGPSignature(file, sig, count, result);
break;
1998 8 Jan Toshio Kuratomi <badger@prtr-13.ucsc.edu> * rpm.c: An error message for --nomd5 incorrectly read "--nopgp can only be used during...."... Changed the --nopgp to --nomd5 1998 7 Jan Toshio Kuratomi <bagder@prtr-13.ucsc.edu> * lib/rpmlib.h: Add a RPMSIGTAG_GPG define for gnupg. * lib/rpmlib.h: Add RPMVAR_GPG_PATH and RPMVAR_GPG_NAME variables. * lib/rpmrc.c: (optionTable) Add gpg_path and gpg_name to the optionTable (same stats as pgp_name and pgp_path.) * lib/signature.c: (rpmLookupSignatureType) Add RPMSIGTAG_GPG as one of the recognized types. * lib/signature.c: (rpmAddSignature) Add ability to create gnupg signature. * lib/signature.c: (makeGPGSignature) Routine to create a gnupg signature (based on makePGPSignature.) * lib/signature.c: (rpmVerifySignature) Add ability to verify gnupg signatures. * lib/signature.c: (verifyGPGSignature) Routine to verify a gnupg signature (based on verifyPGPSignature.) * lib/signature.c: (rpmGetPassPhrase) When getting pass phrase for gnupg, use RPMVAR_GPG_NAME instead of RPMVAR_PGP_NAME if we are signing with GPG isntead of PGP. * lib/signature.c: (checkPassPhrase) Need to allow for GPG when we check the PassPhrase's correctness. * rpm.c: Add equivalent GPG lines everywhere we find a PGP line. * rpm.c: Add equivalent gpg stanzas wherever we find a pgp stanza. * checksig.h: define CHECKSIG_GPG (1 << 2) [Is this correct?] * checksig.c: (doCheckSig) Check for GPG signatures. [A lot could be wrong/left out here.] * rpm.c: change the call to rpmGetPassPhrase to throw in the sigType as well. * signature.h: change rpmGetPassPhrase declaration to: rpmGetPassPhrase(const char * prompt, const int sigTag); * signature.c: (rpmGetPassPhrase) change the function to accept the signature type as its second argument. CVS patchset: 2686 CVS date: 1999/01/09 00:24:02
1999-01-09 08:24:02 +08:00
case RPMSIGTAG_GPG:
return verifyGPGSignature(file, sig, count, result);
break;
default:
sprintf(result, "Do not know how to verify sig type %d\n", sigTag);
return RPMSIG_UNKNOWN;
}
return RPMSIG_OK;
}
static int verifySizeSignature(const 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;
}
sprintf(result, "Header+Archive size OK: %d bytes\n", size);
return 0;
}
static int verifyMD5Signature(const char *datafile, unsigned char *sig,
char *result, md5func fn)
{
unsigned char md5sum[16];
fn(datafile, md5sum);
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(const char *datafile, void *sig,
int count, char *result)
{
int pid, status, outpipe[2];
FD_t sfd;
char *sigfile;
unsigned char buf[8192];
FILE *file;
int res = RPMSIG_OK;
/* Write out the signature */
sigfile = tempnam(rpmGetVar(RPMVAR_TMPPATH), "rpmsig");
sfd = fdOpen(sigfile, O_WRONLY|O_CREAT|O_TRUNC, 0644);
(void)fdWrite(sfd, sig, count);
fdClose(sfd);
/* Now run PGP */
pipe(outpipe);
if (!(pid = fork())) {
close(outpipe[0]);
close(STDOUT_FILENO); /* XXX unnecessary */
dup2(outpipe[1], STDOUT_FILENO);
if (rpmGetVar(RPMVAR_PGP_PATH)) {
dosetenv("PGPPATH", rpmGetVar(RPMVAR_PGP_PATH), 1);
}
execlp("pgp", "pgp",
"+batchmode=on", "+verbose=0",
sigfile, datafile,
NULL);
fprintf(stderr, _("exec failed!\n"));
rpmError(RPMERR_EXEC,
_("Could not run pgp. Use --nopgp to skip PGP checks."));
_exit(RPMERR_EXEC);
}
close(outpipe[1]);
file = fdopen(outpipe[0], "r");
result[0] = '\0';
while (fgets(buf, 1024, file)) {
if (strncmp("File '", buf, 6) &&
strncmp("Text is assu", buf, 12) &&
buf[0] != '\n') {
strcat(result, buf);
}
if (!strncmp("WARNING: Can't find the right public key", buf, 40)) {
res = RPMSIG_NOKEY;
}
}
fclose(file);
(void)waitpid(pid, &status, 0);
unlink(sigfile);
if (!res && (!WIFEXITED(status) || WEXITSTATUS(status))) {
res = RPMSIG_BAD;
}
return res;
}
1998 8 Jan Toshio Kuratomi <badger@prtr-13.ucsc.edu> * rpm.c: An error message for --nomd5 incorrectly read "--nopgp can only be used during...."... Changed the --nopgp to --nomd5 1998 7 Jan Toshio Kuratomi <bagder@prtr-13.ucsc.edu> * lib/rpmlib.h: Add a RPMSIGTAG_GPG define for gnupg. * lib/rpmlib.h: Add RPMVAR_GPG_PATH and RPMVAR_GPG_NAME variables. * lib/rpmrc.c: (optionTable) Add gpg_path and gpg_name to the optionTable (same stats as pgp_name and pgp_path.) * lib/signature.c: (rpmLookupSignatureType) Add RPMSIGTAG_GPG as one of the recognized types. * lib/signature.c: (rpmAddSignature) Add ability to create gnupg signature. * lib/signature.c: (makeGPGSignature) Routine to create a gnupg signature (based on makePGPSignature.) * lib/signature.c: (rpmVerifySignature) Add ability to verify gnupg signatures. * lib/signature.c: (verifyGPGSignature) Routine to verify a gnupg signature (based on verifyPGPSignature.) * lib/signature.c: (rpmGetPassPhrase) When getting pass phrase for gnupg, use RPMVAR_GPG_NAME instead of RPMVAR_PGP_NAME if we are signing with GPG isntead of PGP. * lib/signature.c: (checkPassPhrase) Need to allow for GPG when we check the PassPhrase's correctness. * rpm.c: Add equivalent GPG lines everywhere we find a PGP line. * rpm.c: Add equivalent gpg stanzas wherever we find a pgp stanza. * checksig.h: define CHECKSIG_GPG (1 << 2) [Is this correct?] * checksig.c: (doCheckSig) Check for GPG signatures. [A lot could be wrong/left out here.] * rpm.c: change the call to rpmGetPassPhrase to throw in the sigType as well. * signature.h: change rpmGetPassPhrase declaration to: rpmGetPassPhrase(const char * prompt, const int sigTag); * signature.c: (rpmGetPassPhrase) change the function to accept the signature type as its second argument. CVS patchset: 2686 CVS date: 1999/01/09 00:24:02
1999-01-09 08:24:02 +08:00
static int verifyGPGSignature(const char *datafile, void *sig,
int count, char *result)
{
int pid, status, outpipe[2];
FD_t sfd;
1998 8 Jan Toshio Kuratomi <badger@prtr-13.ucsc.edu> * rpm.c: An error message for --nomd5 incorrectly read "--nopgp can only be used during...."... Changed the --nopgp to --nomd5 1998 7 Jan Toshio Kuratomi <bagder@prtr-13.ucsc.edu> * lib/rpmlib.h: Add a RPMSIGTAG_GPG define for gnupg. * lib/rpmlib.h: Add RPMVAR_GPG_PATH and RPMVAR_GPG_NAME variables. * lib/rpmrc.c: (optionTable) Add gpg_path and gpg_name to the optionTable (same stats as pgp_name and pgp_path.) * lib/signature.c: (rpmLookupSignatureType) Add RPMSIGTAG_GPG as one of the recognized types. * lib/signature.c: (rpmAddSignature) Add ability to create gnupg signature. * lib/signature.c: (makeGPGSignature) Routine to create a gnupg signature (based on makePGPSignature.) * lib/signature.c: (rpmVerifySignature) Add ability to verify gnupg signatures. * lib/signature.c: (verifyGPGSignature) Routine to verify a gnupg signature (based on verifyPGPSignature.) * lib/signature.c: (rpmGetPassPhrase) When getting pass phrase for gnupg, use RPMVAR_GPG_NAME instead of RPMVAR_PGP_NAME if we are signing with GPG isntead of PGP. * lib/signature.c: (checkPassPhrase) Need to allow for GPG when we check the PassPhrase's correctness. * rpm.c: Add equivalent GPG lines everywhere we find a PGP line. * rpm.c: Add equivalent gpg stanzas wherever we find a pgp stanza. * checksig.h: define CHECKSIG_GPG (1 << 2) [Is this correct?] * checksig.c: (doCheckSig) Check for GPG signatures. [A lot could be wrong/left out here.] * rpm.c: change the call to rpmGetPassPhrase to throw in the sigType as well. * signature.h: change rpmGetPassPhrase declaration to: rpmGetPassPhrase(const char * prompt, const int sigTag); * signature.c: (rpmGetPassPhrase) change the function to accept the signature type as its second argument. CVS patchset: 2686 CVS date: 1999/01/09 00:24:02
1999-01-09 08:24:02 +08:00
char *sigfile;
unsigned char buf[8192];
FILE *file;
int res = RPMSIG_OK;
/* Write out the signature */
sigfile = tempnam(rpmGetVar(RPMVAR_TMPPATH), "rpmsig");
sfd = fdOpen(sigfile, O_WRONLY|O_CREAT|O_TRUNC, 0644);
(void)fdWrite(sfd, sig, count);
fdClose(sfd);
1998 8 Jan Toshio Kuratomi <badger@prtr-13.ucsc.edu> * rpm.c: An error message for --nomd5 incorrectly read "--nopgp can only be used during...."... Changed the --nopgp to --nomd5 1998 7 Jan Toshio Kuratomi <bagder@prtr-13.ucsc.edu> * lib/rpmlib.h: Add a RPMSIGTAG_GPG define for gnupg. * lib/rpmlib.h: Add RPMVAR_GPG_PATH and RPMVAR_GPG_NAME variables. * lib/rpmrc.c: (optionTable) Add gpg_path and gpg_name to the optionTable (same stats as pgp_name and pgp_path.) * lib/signature.c: (rpmLookupSignatureType) Add RPMSIGTAG_GPG as one of the recognized types. * lib/signature.c: (rpmAddSignature) Add ability to create gnupg signature. * lib/signature.c: (makeGPGSignature) Routine to create a gnupg signature (based on makePGPSignature.) * lib/signature.c: (rpmVerifySignature) Add ability to verify gnupg signatures. * lib/signature.c: (verifyGPGSignature) Routine to verify a gnupg signature (based on verifyPGPSignature.) * lib/signature.c: (rpmGetPassPhrase) When getting pass phrase for gnupg, use RPMVAR_GPG_NAME instead of RPMVAR_PGP_NAME if we are signing with GPG isntead of PGP. * lib/signature.c: (checkPassPhrase) Need to allow for GPG when we check the PassPhrase's correctness. * rpm.c: Add equivalent GPG lines everywhere we find a PGP line. * rpm.c: Add equivalent gpg stanzas wherever we find a pgp stanza. * checksig.h: define CHECKSIG_GPG (1 << 2) [Is this correct?] * checksig.c: (doCheckSig) Check for GPG signatures. [A lot could be wrong/left out here.] * rpm.c: change the call to rpmGetPassPhrase to throw in the sigType as well. * signature.h: change rpmGetPassPhrase declaration to: rpmGetPassPhrase(const char * prompt, const int sigTag); * signature.c: (rpmGetPassPhrase) change the function to accept the signature type as its second argument. CVS patchset: 2686 CVS date: 1999/01/09 00:24:02
1999-01-09 08:24:02 +08:00
/* Now run GPG */
pipe(outpipe);
if (!(pid = fork())) {
close(outpipe[0]);
/* gpg version 0.9 sends its output to stderr. */
close(STDERR_FILENO); /* XXX unnecessary */
dup2(outpipe[1], STDERR_FILENO);
1998 8 Jan Toshio Kuratomi <badger@prtr-13.ucsc.edu> * rpm.c: An error message for --nomd5 incorrectly read "--nopgp can only be used during...."... Changed the --nopgp to --nomd5 1998 7 Jan Toshio Kuratomi <bagder@prtr-13.ucsc.edu> * lib/rpmlib.h: Add a RPMSIGTAG_GPG define for gnupg. * lib/rpmlib.h: Add RPMVAR_GPG_PATH and RPMVAR_GPG_NAME variables. * lib/rpmrc.c: (optionTable) Add gpg_path and gpg_name to the optionTable (same stats as pgp_name and pgp_path.) * lib/signature.c: (rpmLookupSignatureType) Add RPMSIGTAG_GPG as one of the recognized types. * lib/signature.c: (rpmAddSignature) Add ability to create gnupg signature. * lib/signature.c: (makeGPGSignature) Routine to create a gnupg signature (based on makePGPSignature.) * lib/signature.c: (rpmVerifySignature) Add ability to verify gnupg signatures. * lib/signature.c: (verifyGPGSignature) Routine to verify a gnupg signature (based on verifyPGPSignature.) * lib/signature.c: (rpmGetPassPhrase) When getting pass phrase for gnupg, use RPMVAR_GPG_NAME instead of RPMVAR_PGP_NAME if we are signing with GPG isntead of PGP. * lib/signature.c: (checkPassPhrase) Need to allow for GPG when we check the PassPhrase's correctness. * rpm.c: Add equivalent GPG lines everywhere we find a PGP line. * rpm.c: Add equivalent gpg stanzas wherever we find a pgp stanza. * checksig.h: define CHECKSIG_GPG (1 << 2) [Is this correct?] * checksig.c: (doCheckSig) Check for GPG signatures. [A lot could be wrong/left out here.] * rpm.c: change the call to rpmGetPassPhrase to throw in the sigType as well. * signature.h: change rpmGetPassPhrase declaration to: rpmGetPassPhrase(const char * prompt, const int sigTag); * signature.c: (rpmGetPassPhrase) change the function to accept the signature type as its second argument. CVS patchset: 2686 CVS date: 1999/01/09 00:24:02
1999-01-09 08:24:02 +08:00
if (rpmGetVar(RPMVAR_GPG_PATH)) {
dosetenv("GNUPGHOME", rpmGetVar(RPMVAR_GPG_PATH), 1);
}
execlp("gpg", "gpg",
"--batch", "--no-verbose",
"--verify", sigfile, datafile,
NULL);
fprintf(stderr, _("exec failed!\n"));
rpmError(RPMERR_EXEC,
_("Could not run gpg. Use --nogpg to skip GPG checks."));
_exit(RPMERR_EXEC);
}
close(outpipe[1]);
file = fdopen(outpipe[0], "r");
result[0] = '\0';
while (fgets(buf, 1024, file)) {
strcat(result, buf);
if (!strncmp("gpg: Can't check signature: Public key not found", buf, 48)) {
res = RPMSIG_NOKEY;
}
1998 8 Jan Toshio Kuratomi <badger@prtr-13.ucsc.edu> * rpm.c: An error message for --nomd5 incorrectly read "--nopgp can only be used during...."... Changed the --nopgp to --nomd5 1998 7 Jan Toshio Kuratomi <bagder@prtr-13.ucsc.edu> * lib/rpmlib.h: Add a RPMSIGTAG_GPG define for gnupg. * lib/rpmlib.h: Add RPMVAR_GPG_PATH and RPMVAR_GPG_NAME variables. * lib/rpmrc.c: (optionTable) Add gpg_path and gpg_name to the optionTable (same stats as pgp_name and pgp_path.) * lib/signature.c: (rpmLookupSignatureType) Add RPMSIGTAG_GPG as one of the recognized types. * lib/signature.c: (rpmAddSignature) Add ability to create gnupg signature. * lib/signature.c: (makeGPGSignature) Routine to create a gnupg signature (based on makePGPSignature.) * lib/signature.c: (rpmVerifySignature) Add ability to verify gnupg signatures. * lib/signature.c: (verifyGPGSignature) Routine to verify a gnupg signature (based on verifyPGPSignature.) * lib/signature.c: (rpmGetPassPhrase) When getting pass phrase for gnupg, use RPMVAR_GPG_NAME instead of RPMVAR_PGP_NAME if we are signing with GPG isntead of PGP. * lib/signature.c: (checkPassPhrase) Need to allow for GPG when we check the PassPhrase's correctness. * rpm.c: Add equivalent GPG lines everywhere we find a PGP line. * rpm.c: Add equivalent gpg stanzas wherever we find a pgp stanza. * checksig.h: define CHECKSIG_GPG (1 << 2) [Is this correct?] * checksig.c: (doCheckSig) Check for GPG signatures. [A lot could be wrong/left out here.] * rpm.c: change the call to rpmGetPassPhrase to throw in the sigType as well. * signature.h: change rpmGetPassPhrase declaration to: rpmGetPassPhrase(const char * prompt, const int sigTag); * signature.c: (rpmGetPassPhrase) change the function to accept the signature type as its second argument. CVS patchset: 2686 CVS date: 1999/01/09 00:24:02
1999-01-09 08:24:02 +08:00
}
fclose(file);
(void)waitpid(pid, &status, 0);
unlink(sigfile);
if (!res && (!WIFEXITED(status) || WEXITSTATUS(status))) {
res = RPMSIG_BAD;
}
return res;
}
char *rpmGetPassPhrase(const char *prompt, const int sigTag)
{
char *pass;
1998 8 Jan Toshio Kuratomi <badger@prtr-13.ucsc.edu> * rpm.c: An error message for --nomd5 incorrectly read "--nopgp can only be used during...."... Changed the --nopgp to --nomd5 1998 7 Jan Toshio Kuratomi <bagder@prtr-13.ucsc.edu> * lib/rpmlib.h: Add a RPMSIGTAG_GPG define for gnupg. * lib/rpmlib.h: Add RPMVAR_GPG_PATH and RPMVAR_GPG_NAME variables. * lib/rpmrc.c: (optionTable) Add gpg_path and gpg_name to the optionTable (same stats as pgp_name and pgp_path.) * lib/signature.c: (rpmLookupSignatureType) Add RPMSIGTAG_GPG as one of the recognized types. * lib/signature.c: (rpmAddSignature) Add ability to create gnupg signature. * lib/signature.c: (makeGPGSignature) Routine to create a gnupg signature (based on makePGPSignature.) * lib/signature.c: (rpmVerifySignature) Add ability to verify gnupg signatures. * lib/signature.c: (verifyGPGSignature) Routine to verify a gnupg signature (based on verifyPGPSignature.) * lib/signature.c: (rpmGetPassPhrase) When getting pass phrase for gnupg, use RPMVAR_GPG_NAME instead of RPMVAR_PGP_NAME if we are signing with GPG isntead of PGP. * lib/signature.c: (checkPassPhrase) Need to allow for GPG when we check the PassPhrase's correctness. * rpm.c: Add equivalent GPG lines everywhere we find a PGP line. * rpm.c: Add equivalent gpg stanzas wherever we find a pgp stanza. * checksig.h: define CHECKSIG_GPG (1 << 2) [Is this correct?] * checksig.c: (doCheckSig) Check for GPG signatures. [A lot could be wrong/left out here.] * rpm.c: change the call to rpmGetPassPhrase to throw in the sigType as well. * signature.h: change rpmGetPassPhrase declaration to: rpmGetPassPhrase(const char * prompt, const int sigTag); * signature.c: (rpmGetPassPhrase) change the function to accept the signature type as its second argument. CVS patchset: 2686 CVS date: 1999/01/09 00:24:02
1999-01-09 08:24:02 +08:00
switch (sigTag) {
case RPMSIGTAG_GPG:
if (! rpmGetVar(RPMVAR_GPG_NAME)) {
rpmError(RPMERR_SIGGEN,
_("You must set \"gpg_name:\" in your rpmrc file"));
return NULL;
}
break;
case RPMSIGTAG_PGP:
if (! rpmGetVar(RPMVAR_PGP_NAME)) {
rpmError(RPMERR_SIGGEN,
_("You must set \"pgp_name:\" in your rpmrc file"));
return NULL;
}
break;
default:
/* Currently the calling function (rpm.c:main) is checking this and
* doing a better job. This section should never be accessed.
*/
rpmError(RPMERR_SIGGEN,
_("Invalid signature spec in rc file"));
return NULL;
}
if (prompt) {
pass = getpass(prompt);
} else {
pass = getpass("");
}
1998 8 Jan Toshio Kuratomi <badger@prtr-13.ucsc.edu> * rpm.c: An error message for --nomd5 incorrectly read "--nopgp can only be used during...."... Changed the --nopgp to --nomd5 1998 7 Jan Toshio Kuratomi <bagder@prtr-13.ucsc.edu> * lib/rpmlib.h: Add a RPMSIGTAG_GPG define for gnupg. * lib/rpmlib.h: Add RPMVAR_GPG_PATH and RPMVAR_GPG_NAME variables. * lib/rpmrc.c: (optionTable) Add gpg_path and gpg_name to the optionTable (same stats as pgp_name and pgp_path.) * lib/signature.c: (rpmLookupSignatureType) Add RPMSIGTAG_GPG as one of the recognized types. * lib/signature.c: (rpmAddSignature) Add ability to create gnupg signature. * lib/signature.c: (makeGPGSignature) Routine to create a gnupg signature (based on makePGPSignature.) * lib/signature.c: (rpmVerifySignature) Add ability to verify gnupg signatures. * lib/signature.c: (verifyGPGSignature) Routine to verify a gnupg signature (based on verifyPGPSignature.) * lib/signature.c: (rpmGetPassPhrase) When getting pass phrase for gnupg, use RPMVAR_GPG_NAME instead of RPMVAR_PGP_NAME if we are signing with GPG isntead of PGP. * lib/signature.c: (checkPassPhrase) Need to allow for GPG when we check the PassPhrase's correctness. * rpm.c: Add equivalent GPG lines everywhere we find a PGP line. * rpm.c: Add equivalent gpg stanzas wherever we find a pgp stanza. * checksig.h: define CHECKSIG_GPG (1 << 2) [Is this correct?] * checksig.c: (doCheckSig) Check for GPG signatures. [A lot could be wrong/left out here.] * rpm.c: change the call to rpmGetPassPhrase to throw in the sigType as well. * signature.h: change rpmGetPassPhrase declaration to: rpmGetPassPhrase(const char * prompt, const int sigTag); * signature.c: (rpmGetPassPhrase) change the function to accept the signature type as its second argument. CVS patchset: 2686 CVS date: 1999/01/09 00:24:02
1999-01-09 08:24:02 +08:00
if (checkPassPhrase(pass, sigTag)) {
return NULL;
}
return pass;
}
1998 8 Jan Toshio Kuratomi <badger@prtr-13.ucsc.edu> * rpm.c: An error message for --nomd5 incorrectly read "--nopgp can only be used during...."... Changed the --nopgp to --nomd5 1998 7 Jan Toshio Kuratomi <bagder@prtr-13.ucsc.edu> * lib/rpmlib.h: Add a RPMSIGTAG_GPG define for gnupg. * lib/rpmlib.h: Add RPMVAR_GPG_PATH and RPMVAR_GPG_NAME variables. * lib/rpmrc.c: (optionTable) Add gpg_path and gpg_name to the optionTable (same stats as pgp_name and pgp_path.) * lib/signature.c: (rpmLookupSignatureType) Add RPMSIGTAG_GPG as one of the recognized types. * lib/signature.c: (rpmAddSignature) Add ability to create gnupg signature. * lib/signature.c: (makeGPGSignature) Routine to create a gnupg signature (based on makePGPSignature.) * lib/signature.c: (rpmVerifySignature) Add ability to verify gnupg signatures. * lib/signature.c: (verifyGPGSignature) Routine to verify a gnupg signature (based on verifyPGPSignature.) * lib/signature.c: (rpmGetPassPhrase) When getting pass phrase for gnupg, use RPMVAR_GPG_NAME instead of RPMVAR_PGP_NAME if we are signing with GPG isntead of PGP. * lib/signature.c: (checkPassPhrase) Need to allow for GPG when we check the PassPhrase's correctness. * rpm.c: Add equivalent GPG lines everywhere we find a PGP line. * rpm.c: Add equivalent gpg stanzas wherever we find a pgp stanza. * checksig.h: define CHECKSIG_GPG (1 << 2) [Is this correct?] * checksig.c: (doCheckSig) Check for GPG signatures. [A lot could be wrong/left out here.] * rpm.c: change the call to rpmGetPassPhrase to throw in the sigType as well. * signature.h: change rpmGetPassPhrase declaration to: rpmGetPassPhrase(const char * prompt, const int sigTag); * signature.c: (rpmGetPassPhrase) change the function to accept the signature type as its second argument. CVS patchset: 2686 CVS date: 1999/01/09 00:24:02
1999-01-09 08:24:02 +08:00
static int checkPassPhrase(const char *passPhrase, const int sigType)
{
char name[1024];
int passPhrasePipe[2];
FILE *fpipe;
int pid, status;
int fd;
pipe(passPhrasePipe);
if (!(pid = fork())) {
close(STDIN_FILENO);
close(STDOUT_FILENO);
if (! rpmIsVerbose()) {
close(STDERR_FILENO);
}
if ((fd = open("/dev/null", O_RDONLY)) != STDIN_FILENO) {
dup2(fd, STDIN_FILENO);
}
if ((fd = open("/dev/null", O_WRONLY)) != STDOUT_FILENO) {
dup2(fd, STDOUT_FILENO);
}
dup2(passPhrasePipe[0], 3);
1998 8 Jan Toshio Kuratomi <badger@prtr-13.ucsc.edu> * rpm.c: An error message for --nomd5 incorrectly read "--nopgp can only be used during...."... Changed the --nopgp to --nomd5 1998 7 Jan Toshio Kuratomi <bagder@prtr-13.ucsc.edu> * lib/rpmlib.h: Add a RPMSIGTAG_GPG define for gnupg. * lib/rpmlib.h: Add RPMVAR_GPG_PATH and RPMVAR_GPG_NAME variables. * lib/rpmrc.c: (optionTable) Add gpg_path and gpg_name to the optionTable (same stats as pgp_name and pgp_path.) * lib/signature.c: (rpmLookupSignatureType) Add RPMSIGTAG_GPG as one of the recognized types. * lib/signature.c: (rpmAddSignature) Add ability to create gnupg signature. * lib/signature.c: (makeGPGSignature) Routine to create a gnupg signature (based on makePGPSignature.) * lib/signature.c: (rpmVerifySignature) Add ability to verify gnupg signatures. * lib/signature.c: (verifyGPGSignature) Routine to verify a gnupg signature (based on verifyPGPSignature.) * lib/signature.c: (rpmGetPassPhrase) When getting pass phrase for gnupg, use RPMVAR_GPG_NAME instead of RPMVAR_PGP_NAME if we are signing with GPG isntead of PGP. * lib/signature.c: (checkPassPhrase) Need to allow for GPG when we check the PassPhrase's correctness. * rpm.c: Add equivalent GPG lines everywhere we find a PGP line. * rpm.c: Add equivalent gpg stanzas wherever we find a pgp stanza. * checksig.h: define CHECKSIG_GPG (1 << 2) [Is this correct?] * checksig.c: (doCheckSig) Check for GPG signatures. [A lot could be wrong/left out here.] * rpm.c: change the call to rpmGetPassPhrase to throw in the sigType as well. * signature.h: change rpmGetPassPhrase declaration to: rpmGetPassPhrase(const char * prompt, const int sigTag); * signature.c: (rpmGetPassPhrase) change the function to accept the signature type as its second argument. CVS patchset: 2686 CVS date: 1999/01/09 00:24:02
1999-01-09 08:24:02 +08:00
switch (sigType) {
case RPMSIGTAG_GPG:
sprintf(name, "%s", rpmGetVar(RPMVAR_GPG_NAME));
if (rpmGetVar(RPMVAR_GPG_PATH)) {
dosetenv("GNUPGHOME", rpmGetVar(RPMVAR_GPG_PATH), 1);
}
execlp("gpg", "gpg",
"--batch", "--no-verbose", "--passphrase-fd", "3",
"-u", name, "-so", "-",
NULL);
rpmError(RPMERR_EXEC, _("Couldn't exec gpg"));
_exit(RPMERR_EXEC);
break;
case RPMSIGTAG_PGP:
sprintf(name, "+myname=\"%s\"", rpmGetVar(RPMVAR_PGP_NAME));
dosetenv("PGPPASSFD", "3", 1);
if (rpmGetVar(RPMVAR_PGP_PATH)) {
dosetenv("PGPPATH", rpmGetVar(RPMVAR_PGP_PATH), 1);
}
execlp("pgp", "pgp",
"+batchmode=on", "+verbose=0",
name, "-sf",
NULL);
rpmError(RPMERR_EXEC, _("Couldn't exec pgp"));
_exit(RPMERR_EXEC);
break;
default:
/* This case should have been screened out long ago. */
rpmError(RPMERR_SIGGEN,
_("Invalid signature spec in rc file"));
_exit(RPMERR_SIGGEN);
}
}
fpipe = fdopen(passPhrasePipe[1], "w");
close(passPhrasePipe[0]);
fprintf(fpipe, "%s\n", passPhrase);
fclose(fpipe);
(void)waitpid(pid, &status, 0);
if (!WIFEXITED(status) || WEXITSTATUS(status)) {
return 1;
}
/* passPhrase is good */
return 0;
}