3 * \file lib/signature.c
8 #include "rpmio_internal.h"
10 #include <rpmmacro.h> /* XXX for rpmGetPath() */
12 #include "misc.h" /* XXX for dosetenv() and makeTempFile() */
14 #include "signature.h"
17 /*@access Header@*/ /* XXX compared with NULL */
18 /*@access FD_t@*/ /* XXX compared with NULL */
20 int rpmLookupSignatureType(int action)
22 static int disabled = 0;
26 case RPMLOOKUPSIG_DISABLE:
29 case RPMLOOKUPSIG_ENABLE:
32 case RPMLOOKUPSIG_QUERY:
35 { const char *name = rpmExpand("%{_signature}", NULL);
36 if (!(name && *name != '%'))
38 else if (!xstrcasecmp(name, "none"))
40 else if (!xstrcasecmp(name, "pgp"))
42 else if (!xstrcasecmp(name, "pgp5")) /* XXX legacy */
44 else if (!xstrcasecmp(name, "gpg"))
47 rc = -1; /* Invalid %_signature spec in macro file */
54 /* rpmDetectPGPVersion() returns the absolute path to the "pgp" */
55 /* executable of the requested version, or NULL when none found. */
57 const char * rpmDetectPGPVersion(pgpVersion * pgpVer)
59 /* Actually this should support having more then one pgp version. */
60 /* At the moment only one version is possible since we only */
61 /* have one %_pgpbin and one %_pgp_path. */
63 static pgpVersion saved_pgp_version = PGP_UNKNOWN;
64 const char *pgpbin = rpmGetPath("%{_pgpbin}", NULL);
66 if (saved_pgp_version == PGP_UNKNOWN) {
70 if (!(pgpbin && pgpbin[0] != '%')) {
71 pgpbin = _free(pgpbin);
72 saved_pgp_version = -1;
75 pgpvbin = (char *)alloca(strlen(pgpbin) + sizeof("v"));
76 (void)stpcpy(stpcpy(pgpvbin, pgpbin), "v");
78 if (stat(pgpvbin, &st) == 0)
79 saved_pgp_version = PGP_5;
80 else if (stat(pgpbin, &st) == 0)
81 saved_pgp_version = PGP_2;
83 saved_pgp_version = PGP_NOTDETECTED;
87 *pgpVer = saved_pgp_version;
93 * @todo rpmio: use fdSize rather than fstat(2) to get file size.
94 * @param fd package file handle
95 * @param siglen signature header size
96 * @param pad signature padding
97 * @param datalen length of header+payload
98 * @return rpmRC return code
100 static inline rpmRC checkSize(FD_t fd, int siglen, int pad, int datalen)
101 /*@globals fileSystem @*/
102 /*@modifies fileSystem @*/
107 if (fstat(Fileno(fd), &st))
110 if (!S_ISREG(st.st_mode)) {
111 rpmMessage(RPMMESS_DEBUG,
112 _("file is not regular -- skipping size check\n"));
117 rc = (((sizeof(struct rpmlead) + siglen + pad + datalen) - st.st_size)
118 ? RPMRC_BADSIZE : RPMRC_OK);
120 rpmMessage((rc == RPMRC_OK ? RPMMESS_DEBUG : RPMMESS_WARNING),
121 _("Expected size: %12d = lead(%d)+sigs(%d)+pad(%d)+data(%d)\n"),
122 (int)sizeof(struct rpmlead)+siglen+pad+datalen,
123 (int)sizeof(struct rpmlead), siglen, pad, datalen);
125 rpmMessage((rc == RPMRC_OK ? RPMMESS_DEBUG : RPMMESS_WARNING),
126 _(" Actual size: %12d\n"), (int)st.st_size);
131 rpmRC rpmReadSignature(FD_t fd, Header * headerp, sigType sig_type)
138 rpmRC rc = RPMRC_FAIL; /* assume failure */
145 case RPMSIGTYPE_NONE:
146 rpmMessage(RPMMESS_DEBUG, _("No signature\n"));
149 case RPMSIGTYPE_PGP262_1024:
150 rpmMessage(RPMMESS_DEBUG, _("Old PGP signature\n"));
151 /* These are always 256 bytes */
152 /*@-type@*/ /* FIX: eliminate timedRead @*/
153 if (timedRead(fd, buf, 256) != 256)
157 (void) headerAddEntry(h, RPMSIGTAG_PGP, RPM_BIN_TYPE, buf, 152);
161 case RPMSIGTYPE_MD5_PGP:
162 rpmError(RPMERR_BADSIGTYPE,
163 _("Old (internal-only) signature! How did you get that!?\n"));
165 case RPMSIGTYPE_HEADERSIG:
166 case RPMSIGTYPE_DISABLE:
167 /* This is a new style signature */
168 h = headerRead(fd, HEADER_MAGIC_YES);
173 sigSize = headerSizeof(h, HEADER_MAGIC_YES);
175 /* XXX Legacy headers have a HEADER_IMAGE tag added. */
176 if (headerIsEntry(h, RPMTAG_HEADERIMAGE))
177 sigSize -= (16 + 16);
179 pad = (8 - (sigSize % 8)) % 8; /* 8-byte pad */
180 if (sig_type == RPMSIGTYPE_HEADERSIG) {
181 if (! headerGetEntry(h, RPMSIGTAG_SIZE, &type,
182 (void **)&archSize, &count))
184 rc = checkSize(fd, sigSize, pad, *archSize);
186 /*@-type@*/ /* FIX: eliminate timedRead @*/
187 if (pad && timedRead(fd, buf, pad) != pad)
188 rc = RPMRC_SHORTREAD;
195 if (headerp && rc == 0)
203 int rpmWriteSignature(FD_t fd, Header h)
205 static byte buf[8] = "\000\000\000\000\000\000\000\000";
209 rc = headerWrite(fd, h, HEADER_MAGIC_YES);
213 sigSize = headerSizeof(h, HEADER_MAGIC_YES);
214 pad = (8 - (sigSize % 8)) % 8;
216 if (Fwrite(buf, sizeof(buf[0]), pad, fd) != pad)
219 rpmMessage(RPMMESS_DEBUG, _("Signature: size(%d)+pad(%d)\n"), sigSize, pad);
223 Header rpmNewSignature(void)
225 Header h = headerNew();
229 Header rpmFreeSignature(Header h)
231 return headerFree(h);
234 static int makePGPSignature(const char * file, /*@out@*/ void ** sig,
235 /*@out@*/ int_32 * size, /*@null@*/ const char * passPhrase)
236 /*@globals rpmGlobalMacroContext,
238 /*@modifies *sig, *size, fileSystem @*/
240 char * sigfile = alloca(1024);
245 (void) stpcpy( stpcpy(sigfile, file), ".sig");
247 inpipe[0] = inpipe[1] = 0;
250 if (!(pid = fork())) {
251 const char *pgp_path = rpmExpand("%{_pgp_path}", NULL);
252 const char *name = rpmExpand("+myname=\"%{_pgp_name}\"", NULL);
256 (void) close(STDIN_FILENO);
257 (void) dup2(inpipe[0], 3);
258 (void) close(inpipe[1]);
260 (void) dosetenv("PGPPASSFD", "3", 1);
261 if (pgp_path && *pgp_path != '%')
262 (void) dosetenv("PGPPATH", pgp_path, 1);
264 /* dosetenv("PGPPASS", passPhrase, 1); */
266 if ((path = rpmDetectPGPVersion(&pgpVer)) != NULL) {
269 (void) execlp(path, "pgp", "+batchmode=on", "+verbose=0", "+armor=off",
270 name, "-sb", file, sigfile, NULL);
273 (void) execlp(path,"pgps", "+batchmode=on", "+verbose=0", "+armor=off",
274 name, "-b", file, "-o", sigfile, NULL);
277 case PGP_NOTDETECTED:
281 rpmError(RPMERR_EXEC, _("Couldn't exec pgp (%s)\n"),
282 (path ? path : NULL));
286 (void) close(inpipe[0]);
288 (void) write(inpipe[1], passPhrase, strlen(passPhrase));
289 (void) write(inpipe[1], "\n", 1);
290 (void) close(inpipe[1]);
292 (void)waitpid(pid, &status, 0);
293 if (!WIFEXITED(status) || WEXITSTATUS(status)) {
294 rpmError(RPMERR_SIGGEN, _("pgp failed\n"));
298 if (stat(sigfile, &st)) {
299 /* PGP failed to write signature */
300 if (sigfile) (void) unlink(sigfile); /* Just in case */
301 rpmError(RPMERR_SIGGEN, _("pgp failed to write signature\n"));
306 rpmMessage(RPMMESS_DEBUG, _("PGP sig size: %d\n"), *size);
307 *sig = xmalloc(*size);
311 fd = Fopen(sigfile, "r.fdio");
312 if (fd != NULL && !Ferror(fd)) {
313 /*@-type@*/ /* FIX: eliminate timedRead @*/
314 rc = timedRead(fd, *sig, *size);
316 if (sigfile) (void) unlink(sigfile);
321 rpmError(RPMERR_SIGGEN, _("unable to read the signature\n"));
326 rpmMessage(RPMMESS_DEBUG, _("Got %d bytes of PGP sig\n"), *size);
331 /* This is an adaptation of the makePGPSignature function to use GPG instead
332 * of PGP to create signatures. I think I've made all the changes necessary,
333 * but this could be a good place to start looking if errors in GPG signature
336 static int makeGPGSignature(const char * file, /*@out@*/ void ** sig,
337 /*@out@*/ int_32 * size, /*@null@*/ const char * passPhrase)
338 /*@globals rpmGlobalMacroContext,
340 /*@modifies *sig, *size, fileSystem @*/
342 char * sigfile = alloca(1024);
348 (void) stpcpy( stpcpy(sigfile, file), ".sig");
350 inpipe[0] = inpipe[1] = 0;
353 if (!(pid = fork())) {
354 const char *gpg_path = rpmExpand("%{_gpg_path}", NULL);
355 const char *name = rpmExpand("%{_gpg_name}", NULL);
357 (void) close(STDIN_FILENO);
358 (void) dup2(inpipe[0], 3);
359 (void) close(inpipe[1]);
361 if (gpg_path && *gpg_path != '%')
362 (void) dosetenv("GNUPGHOME", gpg_path, 1);
363 (void) execlp("gpg", "gpg",
364 "--batch", "--no-verbose", "--no-armor", "--passphrase-fd", "3",
365 "-u", name, "-sbo", sigfile, file,
367 rpmError(RPMERR_EXEC, _("Couldn't exec gpg\n"));
371 fpipe = fdopen(inpipe[1], "w");
372 (void) close(inpipe[0]);
374 fprintf(fpipe, "%s\n", (passPhrase ? passPhrase : ""));
375 (void) fclose(fpipe);
378 (void)waitpid(pid, &status, 0);
379 if (!WIFEXITED(status) || WEXITSTATUS(status)) {
380 rpmError(RPMERR_SIGGEN, _("gpg failed\n"));
384 if (stat(sigfile, &st)) {
385 /* GPG failed to write signature */
386 if (sigfile) (void) unlink(sigfile); /* Just in case */
387 rpmError(RPMERR_SIGGEN, _("gpg failed to write signature\n"));
392 rpmMessage(RPMMESS_DEBUG, _("GPG sig size: %d\n"), *size);
393 *sig = xmalloc(*size);
397 fd = Fopen(sigfile, "r.fdio");
398 if (fd != NULL && !Ferror(fd)) {
399 /*@-type@*/ /* FIX: eliminate timedRead @*/
400 rc = timedRead(fd, *sig, *size);
402 if (sigfile) (void) unlink(sigfile);
407 rpmError(RPMERR_SIGGEN, _("unable to read the signature\n"));
412 rpmMessage(RPMMESS_DEBUG, _("Got %d bytes of GPG sig\n"), *size);
417 int rpmAddSignature(Header h, const char * file, int_32 sigTag,
418 const char *passPhrase)
428 (void) stat(file, &st);
431 (void) headerAddEntry(h, RPMSIGTAG_SIZE, RPM_INT32_TYPE, &size, 1);
434 ret = mdbinfile(file, buf);
436 (void) headerAddEntry(h, sigTag, RPM_BIN_TYPE, buf, 16);
438 case RPMSIGTAG_PGP5: /* XXX legacy */
440 rpmMessage(RPMMESS_VERBOSE, _("Generating signature using PGP.\n"));
441 ret = makePGPSignature(file, &sig, &size, passPhrase);
443 (void) headerAddEntry(h, sigTag, RPM_BIN_TYPE, sig, size);
446 rpmMessage(RPMMESS_VERBOSE, _("Generating signature using GPG.\n"));
447 ret = makeGPGSignature(file, &sig, &size, passPhrase);
449 (void) headerAddEntry(h, sigTag, RPM_BIN_TYPE, sig, size);
457 static rpmVerifySignatureReturn
458 verifySizeSignature(const char * datafile, int_32 size, /*@out@*/ char * result)
459 /*@globals fileSystem @*/
460 /*@modifies *result, fileSystem @*/
464 (void) stat(datafile, &st);
465 if (size != st.st_size) {
466 sprintf(result, "Header+Archive size mismatch.\n"
467 "Expected %d, saw %d.\n",
468 size, (int)st.st_size);
472 sprintf(result, "Header+Archive size OK: %d bytes\n", size);
478 static rpmVerifySignatureReturn
479 verifyMD5Signature(const char * datafile, const byte * sig, int siglen,
480 const rpmDigest dig, /*@out@*/ char * result, md5func fn)
481 /*@globals fileSystem @*/
482 /*@modifies *result, fileSystem @*/
485 byte * md5sum = NULL;
487 int res = RPMSIG_BAD;
492 DIGEST_CTX ctx = rpmDigestDup(dig->md5ctx);
493 (void) rpmDigestFinal(ctx, (void **)&md5sum, &md5len, 0);
498 md5sum = xcalloc(1, md5len);
499 xx = fn(datafile, md5sum);
503 if (md5len != siglen || memcmp(md5sum, sig, md5len)) {
505 t = stpcpy(t, " Expected: ");
506 (void) pgpHexCvt(t, sig, siglen);
508 t = stpcpy(t, " Actual: ");
511 t = stpcpy(t, "MD5 sum OK: ");
513 (void) pgpHexCvt(t, md5sum, md5len);
515 md5sum = _free(md5sum);
521 static rpmVerifySignatureReturn
522 verifyPGPSignature(/*@unused@*/ const char * datafile,
523 /*@unused@*/ const byte * sig,
524 /*@unused@*/ int siglen,
525 const rpmDigest dig, /*@out@*/ char * result)
526 /*@modifies *result */
533 if (rsavrfy(&dig->rsa_pk, &dig->rsahm, &dig->c)) {
534 res = resbc = RPMSIG_OK;
536 res = resbc = RPMSIG_BAD;
541 { int pid, status, outpipe[2];
542 /*@only@*/ /*@null@*/ const char * sigfile = NULL;
548 /* What version do we have? */
549 if ((path = rpmDetectPGPVersion(&pgpVer)) == NULL) {
551 rpmError(RPMERR_EXEC,
552 _("Could not run pgp. Use --nopgp to skip PGP checks.\n"));
557 * Sad but true: pgp-5.0 returns exit value of 0 on bad signature.
558 * Instead we have to use the text output to detect a bad signature.
563 /* Write out the signature */
565 { const char *tmppath = rpmGetPath("%{_tmppath}", NULL);
566 sigfile = tempnam(tmppath, "rpmsig");
567 tmppath = _free(tmppath);
569 sfd = Fopen(sigfile, "w.fdio");
570 if (sfd != NULL && !Ferror(sfd)) {
571 (void) Fwrite(sig, sizeof(char), siglen, sfd);
576 if (!makeTempFile(NULL, &sigfile, &sfd)) {
577 (void) Fwrite(sig, sizeof(*sig), siglen, sfd);
587 outpipe[0] = outpipe[1] = 0;
588 (void) pipe(outpipe);
590 if (!(pid = fork())) {
591 const char *pgp_path = rpmExpand("%{_pgp_path}", NULL);
593 (void) close(outpipe[0]);
594 (void) close(STDOUT_FILENO); /* XXX unnecessary */
595 (void) dup2(outpipe[1], STDOUT_FILENO);
597 if (pgp_path && *pgp_path != '%')
598 (void) dosetenv("PGPPATH", pgp_path, 1);
602 /* Some output (in particular "This signature applies to */
603 /* another message") is _always_ written to stderr; we */
604 /* want to catch that output, so dup stdout to stderr: */
605 { int save_stderr = dup(2);
607 (void) execlp(path, "pgpv", "+batchmode=on", "+verbose=0",
608 /* Write "Good signature..." to stdout: */
609 "+OutputInformationFD=1",
610 /* Write "WARNING: ... is not trusted to... to stdout: */
611 "+OutputWarningFD=1",
612 sigfile, "-o", datafile, NULL);
613 /* Restore stderr so we can print the error message below. */
614 (void) dup2(save_stderr, 2);
615 (void) close(save_stderr);
618 (void) execlp(path, "pgp", "+batchmode=on", "+verbose=0",
619 sigfile, datafile, NULL);
622 case PGP_NOTDETECTED:
626 rpmError(RPMERR_EXEC,
627 _("Could not run pgp. Use --nopgp to skip PGP checks.\n"));
631 (void) close(outpipe[1]);
632 file = fdopen(outpipe[0], "r");
635 while (fgets(buf, 1024, file)) {
636 if (strncmp("File '", buf, 6) &&
637 strncmp("Text is assu", buf, 12) &&
638 strncmp("This signature applies to another message", buf, 41) &&
642 if (!strncmp("WARNING: Can't find the right public key", buf, 40))
644 else if (!strncmp("Signature by unknown keyid:", buf, 27))
646 else if (!strncmp("WARNING: The signing key is not trusted", buf, 39))
647 res = RPMSIG_NOTTRUSTED;
648 else if (!strncmp("Good signature", buf, 14))
654 (void) waitpid(pid, &status, 0);
655 if (sigfile) (void) unlink(sigfile);
656 sigfile = _free(sigfile);
657 if (!res && (!WIFEXITED(status) || WEXITSTATUS(status))) {
663 fprintf(stderr, "=============================== RSA verify %s: rc %d\n",
665 (void) pgpPrtPkts(sig, siglen, dig, 1);
666 printf("\t n = "); (void) fflush(stdout);
667 mp32println(dig->rsa_pk.n.size, dig->rsa_pk.n.modl);
668 printf("\t e = "); (void) fflush(stdout);
669 mp32println(dig->rsa_pk.e.size, dig->rsa_pk.e.data);
670 printf("\t c = "); (void) fflush(stdout);
671 mp32println(dig->c.size, dig->c.data);
672 printf("\t m = "); (void)fflush(stdout);
673 mp32println(dig->rsahm.size, dig->rsahm.data);
680 static rpmVerifySignatureReturn
681 verifyGPGSignature(/*@unused@*/ const char * datafile,
682 /*@unused@*/ const byte * sig,
683 /*@unused@*/ int siglen,
684 const rpmDigest dig, /*@out@*/ char * result)
685 /*@modifies *result @*/
692 if (dsavrfy(&dig->p, &dig->q, &dig->g, &dig->hm, &dig->y, &dig->r, &dig->s))
693 res = resbc = RPMSIG_OK;
695 res = resbc = RPMSIG_BAD;
700 int pid, status, outpipe[2];
701 /*@only@*/ /*@null@*/ const char * sigfile = NULL;
709 /* Write out the signature */
711 { const char *tmppath = rpmGetPath("%{_tmppath}", NULL);
712 sigfile = tempnam(tmppath, "rpmsig");
713 tmppath = _free(tmppath);
715 sfd = Fopen(sigfile, "w.fdio");
716 if (sfd != NULL && !Ferror(sfd)) {
717 (void) Fwrite(sig, sizeof(char), siglen, sfd);
722 if (!makeTempFile(NULL, &sigfile, &sfd)) {
723 (void) Fwrite(sig, sizeof(*sig), siglen, sfd);
733 outpipe[0] = outpipe[1] = 0;
734 (void) pipe(outpipe);
736 if (!(pid = fork())) {
737 const char *gpg_path = rpmExpand("%{_gpg_path}", NULL);
739 (void) close(outpipe[0]);
740 /* gpg version 0.9 sends its output to stderr. */
741 (void) dup2(outpipe[1], STDERR_FILENO);
743 if (gpg_path && *gpg_path != '%')
744 (void) dosetenv("GNUPGHOME", gpg_path, 1);
746 (void) execlp("gpg", "gpg",
747 "--batch", "--no-verbose",
748 "--verify", sigfile, datafile,
750 rpmError(RPMERR_EXEC,
751 _("Could not run gpg. Use --nogpg to skip GPG checks.\n"));
755 (void) close(outpipe[1]);
756 file = fdopen(outpipe[0], "r");
759 while (fgets(buf, 1024, file)) {
761 if (!xstrncasecmp("gpg: Can't check signature: Public key not found", buf, 48)) {
768 (void) waitpid(pid, &status, 0);
769 if (sigfile) (void) unlink(sigfile);
770 sigfile = _free(sigfile);
771 if (!res && (!WIFEXITED(status) || WEXITSTATUS(status))) {
778 fprintf(stderr, "=============================== DSA verify %s: rc %d\n",
780 (void) pgpPrtPkts(sig, siglen, dig, 1);
781 printf("\t p = "); (void) fflush(stdout);
782 mp32println(dig->p.size, dig->p.modl);
783 printf("\t q = "); (void) fflush(stdout);
784 mp32println(dig->q.size, dig->q.modl);
785 printf("\t g = "); (void) fflush(stdout);
786 mp32println(dig->g.size, dig->g.data);
787 printf("\t y = "); (void) fflush(stdout);
788 mp32println(dig->y.size, dig->y.data);
789 printf("\t r = "); (void) fflush(stdout);
790 mp32println(dig->r.size, dig->r.data);
791 printf("\t s = "); (void) fflush(stdout);
792 mp32println(dig->s.size, dig->s.data);
793 printf("\thm = "); (void) fflush(stdout);
794 mp32println(dig->hm.size, dig->hm.data);
801 static int checkPassPhrase(const char * passPhrase, const int sigTag)
802 /*@globals rpmGlobalMacroContext,
804 /*@modifies fileSystem @*/
806 int passPhrasePipe[2];
810 passPhrasePipe[0] = passPhrasePipe[1] = 0;
811 (void) pipe(passPhrasePipe);
812 if (!(pid = fork())) {
813 (void) close(STDIN_FILENO);
814 (void) close(STDOUT_FILENO);
815 (void) close(passPhrasePipe[1]);
816 /*@-internalglobs@*/ /* FIX: shrug */
817 if (! rpmIsVerbose()) {
818 (void) close(STDERR_FILENO);
821 if ((fd = open("/dev/null", O_RDONLY)) != STDIN_FILENO) {
822 (void) dup2(fd, STDIN_FILENO);
825 if ((fd = open("/dev/null", O_WRONLY)) != STDOUT_FILENO) {
826 (void) dup2(fd, STDOUT_FILENO);
829 (void) dup2(passPhrasePipe[0], 3);
833 { const char *gpg_path = rpmExpand("%{_gpg_path}", NULL);
834 const char *name = rpmExpand("%{_gpg_name}", NULL);
835 if (gpg_path && *gpg_path != '%')
836 (void) dosetenv("GNUPGHOME", gpg_path, 1);
837 (void) execlp("gpg", "gpg",
838 "--batch", "--no-verbose", "--passphrase-fd", "3",
839 "-u", name, "-so", "-",
841 rpmError(RPMERR_EXEC, _("Couldn't exec gpg\n"));
843 } /*@notreached@*/ break;
844 case RPMSIGTAG_PGP5: /* XXX legacy */
846 { const char *pgp_path = rpmExpand("%{_pgp_path}", NULL);
847 const char *name = rpmExpand("+myname=\"%{_pgp_name}\"", NULL);
851 (void) dosetenv("PGPPASSFD", "3", 1);
852 if (pgp_path && *pgp_path != '%')
853 (void) dosetenv("PGPPATH", pgp_path, 1);
855 if ((path = rpmDetectPGPVersion(&pgpVer)) != NULL) {
858 (void) execlp(path, "pgp", "+batchmode=on", "+verbose=0",
860 /*@innerbreak@*/ break;
861 case PGP_5: /* XXX legacy */
862 (void) execlp(path,"pgps", "+batchmode=on", "+verbose=0",
864 /*@innerbreak@*/ break;
866 case PGP_NOTDETECTED:
867 /*@innerbreak@*/ break;
870 rpmError(RPMERR_EXEC, _("Couldn't exec pgp\n"));
872 } /*@notreached@*/ break;
873 default: /* This case should have been screened out long ago. */
874 rpmError(RPMERR_SIGGEN, _("Invalid %%_signature spec in macro file\n"));
875 _exit(RPMERR_SIGGEN);
876 /*@notreached@*/ break;
880 (void) close(passPhrasePipe[0]);
881 (void) write(passPhrasePipe[1], passPhrase, strlen(passPhrase));
882 (void) write(passPhrasePipe[1], "\n", 1);
883 (void) close(passPhrasePipe[1]);
885 (void)waitpid(pid, &status, 0);
886 if (!WIFEXITED(status) || WEXITSTATUS(status)) {
890 /* passPhrase is good */
894 char * rpmGetPassPhrase(const char * prompt, const int sigTag)
901 { const char *name = rpmExpand("%{_gpg_name}", NULL);
902 aok = (name && *name != '%');
906 rpmError(RPMERR_SIGGEN,
907 _("You must set \"%%_gpg_name\" in your macro file\n"));
911 case RPMSIGTAG_PGP5: /* XXX legacy */
913 { const char *name = rpmExpand("%{_pgp_name}", NULL);
914 aok = (name && *name != '%');
918 rpmError(RPMERR_SIGGEN,
919 _("You must set \"%%_pgp_name\" in your macro file\n"));
924 /* Currently the calling function (rpm.c:main) is checking this and
925 * doing a better job. This section should never be accessed.
927 rpmError(RPMERR_SIGGEN, _("Invalid %%_signature spec in macro file\n"));
929 /*@notreached@*/ break;
932 pass = /*@-unrecog@*/ getpass( (prompt ? prompt : "") ) /*@=unrecog@*/ ;
934 if (checkPassPhrase(pass, sigTag))
940 rpmVerifySignatureReturn
941 rpmVerifySignature(const char * file, int_32 sigTag, const void * sig,
942 int siglen, const rpmDigest dig, char * result)
946 return verifySizeSignature(file, *(int_32 *)sig, result);
947 /*@notreached@*/ break;
949 return verifyMD5Signature(file, sig, siglen, dig, result, mdbinfile);
950 /*@notreached@*/ break;
951 case RPMSIGTAG_PGP5: /* XXX legacy */
953 return verifyPGPSignature(file, sig, siglen, dig, result);
954 /*@notreached@*/ break;
956 return verifyGPGSignature(file, sig, siglen, dig, result);
957 /*@notreached@*/ break;
958 case RPMSIGTAG_LEMD5_1:
959 case RPMSIGTAG_LEMD5_2:
961 sprintf(result, "Do not know how to verify sig type %d\n", sigTag);
962 return RPMSIG_UNKNOWN;