# rpmdb/signature.c File Reference

`#include "system.h"`
`#include <rpmio.h>`
`#include <rpmurl.h>`
`#include <rpmcb.h>`
`#include <rpmpgp.h>`
`#include <rpmtag.h>`
`#include <rpmmacro.h>`
`#include "rpmdb.h"`
`#include "legacy.h"`
`#include <pkgio.h>`
`#include "signature.h"`
`#include "debug.h"`

Include dependency graph for signature.c:

Go to the source code of this file.

## Defines

#define | _RPMPGP_INTERNAL

## Functions

int | rpmTempFile (const char *prefix, const char **fnptr, void *fdptr)
| Return file handle for a temporaray file.
static int | makeGPGSignature (const char *file, uint32_t *sigTagp, uint8_t **pktp, uint32_t *pktlenp, const char *passPhrase)
| Generate GPG signature(s) for a header+payload file.
static int | makeHDRSignature (Header sigh, const char *file, uint32_t sigTag, const char *passPhrase)
| Generate header only signature(s) from a header+payload file.
int | rpmAddSignature (Header sigh, const char *file, uint32_t sigTag, const char *passPhrase)
| Generate signature(s) from a header+payload file, save in signature header.
int | rpmCheckPassPhrase (const char *passPhrase)
| Check for valid pass phrase by invoking a helper.
static const char * | rpmSigString (rpmRC res)
static rpmRC | verifySizeSignature (const pgpDig dig, char *t)
static rpmRC | verifyMD5Signature (const pgpDig dig, char *t, DIGEST_CTX md5ctx)
static rpmRC | verifySHA1Signature (const pgpDig dig, char *t, DIGEST_CTX sha1ctx)
| Verify header immutable region SHA1 digest.
static rpmRC | verifyRSASignature (pgpDig dig, char *t, DIGEST_CTX md5ctx)
| Verify RSA signature.
static rpmRC | verifyDSASignature (pgpDig dig, char *t, DIGEST_CTX sha1ctx)
| Verify DSA signature.
rpmRC | rpmVerifySignature (void *_dig, char *result)
| Verify a signature from a package.

## Define Documentation

#define _RPMPGP_INTERNAL

Definition at line 13 of file signature.c.

## Function Documentation

static int makeGPGSignature | ( | const char * | file,
|  | uint32_t * | sigTagp,
|  | uint8_t ** | pktp,
|  | uint32_t * | pktlenp,
|  | const char * | passPhrase |
| ) |  |  | `[static]`

Generate GPG signature(s) for a header+payload file.

Parameters:

  | file | header+payload file name

Return values:

  | *sigTagp | signature tag
  | *pktp | signature packet(s)
  | *pktlenp | signature packet(s) length

Parameters:

  | passPhrase | private key pass phrase

Returns:
  0 on success, 1 on failure

Definition at line 145 of file signature.c.

References _, _free(), addMacro(), alloca(), D_, delMacro(), errno, EXIT_FAILURE, Fclose(), Ferror(), Fopen(), Fread(), pgpDigFree(), pgpDigNew(), pgpGetSignature(), pgpPrtPkts(), PGPPUBKEYALGO_DSA, PGPPUBKEYALGO_RSA, rpmExpand(), rpmlog(), RPMLOG_DEBUG, RPMLOG_ERR, RPMSIGTAG_DSA, RPMSIGTAG_MD5, RPMSIGTAG_RSA, RPMSIGTAG_SHA1, RPMSIGTAG_SIZE, setenv(), Stat(), stpcpy(), Unlink(), unsetenv(), and xmalloc().

Referenced by makeHDRSignature().

static int makeHDRSignature | ( | Header | sigh,
|  | const char * | file,
|  | uint32_t | sigTag,
|  | const char * | passPhrase |
| ) |  |  | `[static]`

Generate header only signature(s) from a header+payload file.

Parameters:

  | sigh | signature header
  | file | header+payload file name
  | sigTag | type of signature(s) to add
  | passPhrase | private key pass phrase

Returns:
  0 on success, -1 on failure

Definition at line 306 of file signature.c.

References _free(), alloca(), _HE_s::c, Fclose(), Ferror(), Fopen(), headerFree(), headerGet(), headerGetMagic(), headerIsEntry(), headerPut(), makeGPGSignature(), _HE_s::p, PGPHASHALGO_SHA1, rpmDataType_u::ptr, RPM_BIN_TYPE, RPM_STRING_TYPE, RPMDIGEST_NONE, rpmDigestFinal(), rpmDigestInit(), rpmDigestUpdate(), rpmlog(), RPMLOG_ERR, rpmpkgRead(), rpmpkgWrite(), RPMRC_OK, RPMSIGTAG_DSA, RPMSIGTAG_GPG, RPMSIGTAG_MD5, RPMSIGTAG_PGP, RPMSIGTAG_PGP5, RPMSIGTAG_SHA1, RPMSIGTAG_SIZE, RPMTAG_HEADERIMMUTABLE, rpmTempFile(), rpmDataType_u::str, _HE_s::t, _HE_s::tag, and Unlink().

Referenced by rpmAddSignature().

int rpmCheckPassPhrase | ( | const char * | passPhrase | ) |

Check for valid pass phrase by invoking a helper.

Parameters:

  | passPhrase | pass phrase

Returns:
  0 on valid, 1 on invalid

Definition at line 490 of file signature.c.

References _, _free(), errno, rpmExpand(), rpmIsVerbose, rpmlog(), RPMLOG_ERR, setenv(), and unsetenv().

Referenced by main().

static const char* rpmSigString | ( | rpmRC | res | ) | `[static]`

Definition at line 575 of file signature.c.

References RPMRC_FAIL, RPMRC_NOKEY, RPMRC_NOTFOUND, RPMRC_NOTTRUSTED, and RPMRC_OK.

Referenced by verifyDSASignature(), verifyMD5Signature(), verifyRSASignature(), verifySHA1Signature(), and verifySizeSignature().

int rpmTempFile | ( | const char * | prefix,
|  | const char ** | fnptr,
|  | void * | fdptr |
| ) |  |  |

Return file handle for a temporaray file.

A unique temporaray file path will be generated using rpmGenPath(prefix, "%{_tmppath}/", "rpm-tmp.XXXXX") where "XXXXXX" is filled in using rand(3). The file is opened, and the link count and (dev,ino) location are verified after opening. The file name and the open file handle are returned.

Parameters:

  | prefix | leading part of temp file path

Return values:

  | *fnptr | temp file name (or NULL)
  | *fdptr | temp file handle

Returns:
  0 on success

Definition at line 30 of file signature.c.

References _, _free(), errno, Fclose(), Ferror(), Fileno(), Fopen(), rpmGenPath(), rpmioMkpath(), rpmlog(), RPMLOG_ERR, S_ISLNK, URL_IS_DASH, URL_IS_FTP, URL_IS_HKP, URL_IS_HTTP, URL_IS_HTTPS, URL_IS_PATH, URL_IS_UNKNOWN, and urlPath().

Referenced by makeHDRSignature(), manageFile(), runScript(), and writeRPM().

static rpmRC verifyDSASignature | ( | pgpDig | dig,
|  | char * | t,
|  | DIGEST_CTX | sha1ctx |
| ) |  |  | `[static]`

Verify DSA signature.

Parameters:

  | dig | container

Return values:

  | t | verbose success/failure text

Parameters:

  | sha1ctx |

Returns:
  RPMRC_OK on success

Definition at line 861 of file signature.c.

References _, rpmop_s::count, pgpFindPubkey(), pgpGetSig(), pgpGetSiglen(), pgpGetSignature(), pgpGetSigtag(), PGPHASHALGO_SHA1, pgpHexCvt(), pgpImplSetDSA(), pgpImplVerifyDSA(), PGPPUBKEYALGO_DSA, pgpStatsAccumulator(), rpmDigestDup(), rpmDigestUpdate(), RPMRC_FAIL, RPMRC_NOKEY, RPMRC_OK, rpmSigString(), RPMSIGTAG_DSA, rpmswEnter(), rpmswExit(), and stpcpy().

Referenced by rpmVerifySignature().

static rpmRC verifyMD5Signature | ( | const pgpDig | dig,
|  | char * | t,
|  | DIGEST_CTX | md5ctx |
| ) |  |  | `[static]`

Definition at line 624 of file signature.c.

References _, _free(), rpmop_s::count, pgpGetSig(), pgpGetSiglen(), pgpHexCvt(), pgpStatsAccumulator(), rpmDigestDup(), rpmDigestFinal(), RPMRC_FAIL, RPMRC_NOKEY, RPMRC_OK, rpmSigString(), rpmswEnter(), rpmswExit(), and stpcpy().

Referenced by rpmVerifySignature().

static rpmRC verifyRSASignature | ( | pgpDig | dig,
|  | char * | t,
|  | DIGEST_CTX | md5ctx |
| ) |  |  | `[static]`

Verify RSA signature.

Parameters:

  | dig | container

Return values:

  | t | verbose success/failure text

Parameters:

  | md5ctx |

Returns:
  RPMRC_OK on success

Definition at line 735 of file signature.c.

References _, rpmop_s::count, pgpFindPubkey(), pgpGetSig(), pgpGetSiglen(), pgpGetSignature(), pgpGetSigtag(), PGPHASHALGO_HAVAL_5_160, PGPHASHALGO_MD2, PGPHASHALGO_MD5, PGPHASHALGO_RIPEMD160, PGPHASHALGO_SHA1, PGPHASHALGO_SHA256, PGPHASHALGO_SHA384, PGPHASHALGO_SHA512, PGPHASHALGO_TIGER192, pgpHexCvt(), pgpImplSetRSA(), pgpImplVerifyRSA(), PGPPUBKEYALGO_RSA, pgpStatsAccumulator(), rpmDigestDup(), rpmDigestUpdate(), RPMRC_FAIL, RPMRC_NOKEY, RPMRC_OK, rpmSigString(), RPMSIGTAG_RSA, rpmswEnter(), rpmswExit(), and stpcpy().

Referenced by rpmVerifySignature().

static rpmRC verifySHA1Signature | ( | const pgpDig | dig,
|  | char * | t,
|  | DIGEST_CTX | sha1ctx |
| ) |  |  | `[static]`

Verify header immutable region SHA1 digest.

Parameters:

  | dig | container

Return values:

  | t | verbose success/failure text

Parameters:

  | sha1ctx |

Returns:
  RPMRC_OK on success

Definition at line 680 of file signature.c.

References _, _free(), pgpGetSig(), pgpGetSiglen(), pgpStatsAccumulator(), rpmDigestDup(), rpmDigestFinal(), RPMRC_FAIL, RPMRC_NOKEY, RPMRC_OK, rpmSigString(), rpmswEnter(), rpmswExit(), and stpcpy().

Referenced by rpmVerifySignature().

static rpmRC verifySizeSignature | ( | const pgpDig | dig,
|  | char * | t |
| ) |  |  | `[static]`

Definition at line 591 of file signature.c.

References _, pgpGetSig(), RPMRC_FAIL, RPMRC_NOKEY, RPMRC_OK, rpmSigString(), and stpcpy().

Referenced by rpmVerifySignature().