10 #define _RPMPGP_INTERNAL
32 const char * tpmacro =
"%{?_tmppath}%{!?_tmppath:/var/tmp/}";
33 const char * tempfn =
NULL;
34 const char * tfn =
NULL;
35 static int _initialized = 0;
40 if (!prefix) prefix =
"";
46 if (
rpmioMkpath(tempfn, 0755, (uid_t) -1, (gid_t) -1))
53 ran = rand() % 100000;
60 sprintf(tfnbuf,
"rpm-tmp.%u", ran++);
61 tempfn =
_free(tempfn);
64 strcpy(tfnbuf,
"rpm-tmp.XXXXXX");
65 tempfn =
_free(tempfn);
66 tempfn =
rpmGenPath(prefix, tpmacro, mktemp(tfnbuf));
70 if (*tfn ==
'\0')
goto errxit;
85 fd =
Fopen(tempfn,
"w+x.fdio");
97 {
struct stat sb, sb2;
98 if (!stat(tfn, &sb) &&
S_ISLNK(sb.st_mode)) {
103 if (sb.st_nlink != 1) {
108 if (fstat(
Fileno(fd), &sb2) == 0) {
109 if (sb2.st_ino != sb.st_ino || sb2.st_dev != sb.st_dev) {
122 tempfn =
_free(tempfn);
129 tempfn =
_free(tempfn);
156 char * sigfile = (
char *)
alloca(strlen(file)+
sizeof(
".sig"));
166 const char * pw =
NULL;
174 inpipe[0] = inpipe[1] = 0;
175 if (pipe(inpipe) < 0) {
180 if (!(pid = fork())) {
183 (
void) dup2(inpipe[0], 3);
184 (
void) close(inpipe[1]);
186 if (gpg_path && *gpg_path !=
'\0')
191 rc = poptParseArgvString(cmd,
NULL, (
const char ***)&av);
193 rc = execve(av[0], av+1,
environ);
210 fpipe = fdopen(inpipe[1],
"w");
211 (
void) close(inpipe[0]);
213 fprintf(fpipe,
"%s\n", (pw ? pw :
""));
214 (
void) fclose(fpipe);
223 (
void) waitpid(pid, &status, 0);
225 if (!WIFEXITED(status) || WEXITSTATUS(status)) {
230 if (
Stat(sigfile, &st)) {
244 fd =
Fopen(sigfile,
"r.ufdio");
246 rc = (
int)
Fread(*pktp,
sizeof((*pktp)[0]), *pktlenp,
fd);
251 *pktp =
_free(*pktp);
328 fd =
Fopen(file,
"r.fdio");
331 {
const char item[] =
"Header";
344 unsigned char * hmagic =
NULL;
357 if (hmagic && nmagic > 0)
379 fd =
Fopen(file,
"r.fdio");
382 {
const char item[] =
"Header";
396 {
const char item[] =
"Header";
448 if (
Stat(file, &st) != 0)
498 if (!(passPhrase && passPhrase[0]))
504 if (!(pid = fork())) {
509 xx = close(STDIN_FILENO);
510 xx = close(STDOUT_FILENO);
513 xx = close(STDERR_FILENO);
514 if ((fdno = open(
"/dev/null", O_RDONLY)) != STDIN_FILENO) {
515 xx = dup2(fdno, STDIN_FILENO);
518 if ((fdno = open(
"/dev/null", O_WRONLY)) != STDOUT_FILENO) {
519 xx = dup2(fdno, STDOUT_FILENO);
527 if (gpg_path && *gpg_path !=
'\0')
531 rc = poptParseArgvString(cmd,
NULL, (
const char ***)&av);
533 rc = execve(av[0], av+1,
environ);
548 xx = (
int) write(p[1], pw, strlen(pw));
549 xx = (
int) write(p[1],
"\n", 1);
558 (
void) waitpid(pid, &status, 0);
561 return ((!WIFEXITED(status) || WEXITSTATUS(status)) ? 1 : 0);
588 t =
stpcpy(t,
_(
"Header+Payload size: "));
590 if (sig ==
NULL || dig ==
NULL || dig->nbytes == 0) {
596 memcpy(&size, sig,
sizeof(size));
601 sprintf(t,
" Expected(%u) != (%u)\n", (
unsigned)size, (
unsigned)dig->nbytes);
605 sprintf(t,
" (%u)", (
unsigned)dig->nbytes);
646 if (md5len != siglen || memcmp(md5sum, sig, md5len)) {
649 t =
stpcpy(t,
" Expected(");
710 || strlen(SHA1) != strlen((
char *)sig)
711 ||
strcmp(SHA1, (
char *)sig))
715 t =
stpcpy(t,
" Expected(");
716 t =
stpcpy(t, (
char *)sig);
753 fprintf(stderr,
"--> %s(%p,%p,%p) sig %p sigp %p\n", __FUNCTION__, dig, t, rsactx, sig, sigp);
764 if (dig->hdrctx == rsactx)
769 switch (sigp->version) {
770 case 3: *t++ =
'3';
break;
771 case 4: *t++ =
'4';
break;
782 t =
stpcpy(t,
_(
" signature: "));
788 if (sigp->hash != NULL)
793 trailer[0] = sigp->version;
795 trailer[2] = (sigp->hashlen >> 24);
796 trailer[3] = (sigp->hashlen >> 16);
797 trailer[4] = (sigp->hashlen >> 8);
798 trailer[5] = (sigp->hashlen );
802 if (op != NULL) op->
count--;
827 t =
stpcpy(t,
", key ID ");
855 fprintf(stderr,
"--> %s(%p,%p,%p) sig %p sigp %p\n", __FUNCTION__, dig, t, dsactx, sig, sigp);
866 if (dig != NULL && dig->hdrsha1ctx == dsactx)
871 switch (sigp->version) {
872 case 3: *t++ =
'3';
break;
873 case 4: *t++ =
'4';
break;
884 t =
stpcpy(t,
_(
" signature: "));
890 if (sigp->hash != NULL)
895 trailer[0] = sigp->version;
897 trailer[2] = (sigp->hashlen >> 24);
898 trailer[3] = (sigp->hashlen >> 16);
899 trailer[4] = (sigp->hashlen >> 8);
900 trailer[5] = (sigp->hashlen );
904 if (op != NULL) op->
count--;
929 t =
stpcpy(t,
", key ID ");
935 fprintf(stderr,
"<-- %s(%p,%p,%p) res %d %s\n", __FUNCTION__, dig, t, dsactx, res, t);
950 fprintf(stderr,
"--> %s(%p,%p) sig %p[%u]\n", __FUNCTION__, _dig, result, sig, siglen);
952 if (dig == NULL || sig == NULL || siglen == 0) {
953 sprintf(result,
_(
"Verify signature: BAD PARAMETERS\n"));
960 res = verifySize(dig, result);
963 res = verifyMD5(dig, result, dig->md5ctx);
966 res = verifySHA1(dig, result, dig->hdrsha1ctx);
969 res = verifyRSA(dig, result, dig->hdrctx);
972 res = verifyDSA(dig, result, dig->hdrsha1ctx);
975 sprintf(result,
_(
"Signature: UNKNOWN (%u)\n"), (
unsigned)sigtag);
982 fprintf(stderr,
"<-- %s(%p,%p) res %d %s\n", __FUNCTION__, _dig, result, res, result);
void pgpHexCvt(t, md5sum, md5len)
static int makeGPGSignature(const char *file, rpmSigTag *sigTagp, rpmuint8_t **pktp, rpmuint32_t *pktlenp, const char *passPhrase)
Generate GPG signature(s) for a header+payload file.
enum pgpPubkeyAlgo_e pgpPubkeyAlgo
9.1.
rpmlog(RPMLOG_ERR,"%s\n", buf)
OpenPGP constants and structures from RFC-2440.
rpmRC rpmpkgWrite(const char *fn, FD_t fd, void *ptr, const char **msg)
Write item onto file descriptor.
int rpmCheckPassPhrase(const char *passPhrase)
Check for valid pass phrase by invoking a helper.
FD_t Fopen(const char *path, const char *_fmode)
fopen(3) clone.
int rpmioMkpath(const char *path, mode_t mode, uid_t uid, gid_t gid)
Insure that directories in path exist, creating as needed.
int setenv(const char *name, const char *value, int replace)
int Stat(const char *path, struct stat *st)
stat(2) clone.
int pgpFindPubkey(pgpDig dig)
Call find pubkey vector.
void addMacro(MacroContext mc, const char *n, const char *o, const char *b, int level)
Add macro to context.
int dodigest(int dalgo, const char *fn, unsigned char *digest, unsigned dflags, size_t *fsizep)
Return digest and size of a file.
static int pgpImplSetDSA(DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
unsigned char rpmuint8_t
Private int typedefs to avoid C99 portability issues.
sprintf(t," (%u)",(unsigned) dig->nbytes)
pgpDig pgpDigNew(pgpVSFlags vsflags, pgpPubkeyAlgo pubkey_algo)
Create a container for parsed OpenPGP packates.
enum rpmRC_e rpmRC
RPM return codes.
memset(_r, 0, sizeof(*_r))
assert(key->size==sizeof(hdrNum))
int rpmAddSignature(Header sigh, const char *file, rpmSigTag sigTag, const char *passPhrase)
Generate signature(s) from a header+payload file, save in signature header.
fprintf(stderr,"--> %s(%p,%p,%p) sig %p sigp %p\n", __FUNCTION__, dig, t, rsactx, sig, sigp)
static int makeHDRSignature(Header sigh, const char *file, rpmSigTag sigTag, const char *passPhrase)
Generate header only signature(s) from a header+payload file.
int rpmTempFile(const char *prefix, const char **fnptr, void *fdptr)
Return file handle for a temporaray file.
void * pgpStatsAccumulator(pgpDig dig, int opx)
Return pgpDig container accumulator structure.
const char * rpmDigestName(DIGEST_CTX ctx)
Return digest name.
DIGEST_CTX rpmDigestDup(DIGEST_CTX octx)
Duplicate a digest context.
int rpmDigestUpdate(DIGEST_CTX ctx, const void *data, size_t len)
Update context with next plain text buffer.
pgpDigParams pgpGetSignature(pgpDig dig)
Return OpenPGP signature parameters.
pgpHashAlgo rpmDigestAlgo(DIGEST_CTX ctx)
Return digest algorithm identifier.
int pgpPrtPkts(const rpmuint8_t *pkts, size_t pktlen, pgpDig dig, int printing)
Print/parse a OpenPGP packet(s).
The FD_t File Handle data structure.
pgpDig pgpDigFree(pgpDig dig)
Destroy a container for parsed OpenPGP packates.
const char * rpmGenPath(const char *urlroot, const char *urlmdir, const char *urlfile)
Merge 3 args into path, any or all of which may be a url.
Generate and verify rpm package signatures.
DIGEST_CTX rpmDigestInit(pgpHashAlgo hashalgo, rpmDigestFlags flags)
Initialize digest.
char * rpmExpand(const char *arg,...)
Return (malloc'ed) concatenated macro expansion(s).
size_t Fread(void *buf, size_t size, size_t nmemb, FD_t fd)
fread(3) clone.
void unsetenv(const char *name)
static const char * rpmSigString(rpmRC res)
int Fclose(FD_t fd)
fclose(3) clone.
Cumulative statistics for an operation.
rpmuint32_t pgpGetSigtag(pgpDig dig)
Get signature tag.
static int pgpImplSetRSA(DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
int Ferror(FD_t fd)
ferror(3) clone.
return strcmp(ame->name, bme->name)
urltype urlPath(const char *url, const char **pathp)
Return path component of URL.
static const char * prefix[]
Tables for prefixing and suffixing patterns, according to the -w, -x, and -F options.
Methods to handle package elements.
char * stpcpy(char *dest, const char *src)
const void * pgpGetSig(pgpDig dig)
Get signature tag data, i.e.
static int pgpImplVerify(pgpDig dig)
struct pgpDigParams_s * pgpDigParams
int Fileno(FD_t fd)
fileno(3) clone.
static void
Print copy of spec file, filling in Group/Description/Summary from specspo.
rpmuint32_t pgpGetSiglen(pgpDig dig)
Get signature tag data length, i.e.
static PyObject *unsigned char * pkt
int
Save source and expand field into target.
void rpmDigestFinal(rpmDigestDup(md5ctx),&md5sum,&md5len, 0)
rpmRC rpmpkgRead(const char *fn, FD_t fd, void *ptr, const char **msg)
Read item from file descriptor.
Access RPM indices using Berkeley DB interface(s).
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
const char * rpmkuPassPhrase(const char *passPhrase)
Return pass phrase from keyutils keyring.
rpmRC rpmVerifySignature(void *_dig, char *result)
Verify a signature from a package.
int Unlink(const char *path)
unlink(2) clone.