rpm  4.5
Data Structures | Macros | Functions | Variables
rpmpgp.c File Reference

Routines to handle RFC-2440 detached signatures. More...

#include "system.h"
#include "rpmio_internal.h"
#include "debug.h"
Include dependency graph for rpmpgp.c:

Go to the source code of this file.

Data Structures

struct  pgpPkt_s
 

Macros

#define TOKEQ(_s, _tok)   (!strncmp((_s), (_tok), sizeof(_tok)-1))
 

Functions

static void pgpPrtNL (void)
 
static void pgpPrtInt (const char *pre, int i)
 
static void pgpPrtStr (const char *pre, const char *s)
 
static void pgpPrtHex (const char *pre, const byte *p, unsigned int plen)
 
void pgpPrtVal (const char *pre, pgpValTbl vs, byte val)
 Print an OpenPGP value.
 
static const char * pgpMpiHex (const byte *p)
 
static int pgpHexSet (const char *pre, int lbits, mpnumber *mpn, const byte *p, const byte *pend)
 
int pgpPrtSubType (const byte *h, unsigned int hlen, pgpSigType sigtype)
 Print/parse an OpenPGP subtype packet.
 
static int pgpPrtSigParams (const pgpPkt pp, byte pubkey_algo, byte sigtype, const byte *p)
 
int pgpPrtSig (const pgpPkt pp)
 Print/parse an OpenPGP signature packet.
 
static const bytepgpPrtPubkeyParams (const pgpPkt pp, byte pubkey_algo, const byte *p)
 
static const bytepgpPrtSeckeyParams (const pgpPkt pp, byte pubkey_algo, const byte *p)
 
int pgpPrtKey (const pgpPkt pp)
 Print/parse an OpenPGP key packet.
 
int pgpPrtUserID (const pgpPkt pp)
 Print/parse an OpenPGP userid packet.
 
int pgpPrtComment (const pgpPkt pp)
 Print/parse an OpenPGP comment packet.
 
int pgpPktLen (const byte *pkt, unsigned int pleft, pgpPkt pp)
 Return lenth of a OpenPGP packet.
 
int pgpPubkeyFingerprint (const byte *pkt, unsigned int pktlen, byte *keyid)
 Calculate OpenPGP public key fingerprint.
 
int pgpExtractPubkeyFingerprint (const char *b64pkt, byte *keyid)
 Extract OpenPGP public key fingerprint from base64 encoded packet.
 
int pgpPrtPkt (const byte *pkt, unsigned int pleft)
 Print/parse next OpenPGP packet.
 
pgpDig pgpNewDig (void)
 Create a container for parsed OpenPGP packates.
 
void pgpCleanDig (pgpDig dig)
 Release (malloc'd) data from container.
 
pgpDig pgpFreeDig (pgpDig dig)
 Destroy a container for parsed OpenPGP packates.
 
static int pgpGrabPkts (const byte *pkts, unsigned int pktlen, byte ***pppkts, int *pnpkts)
 
int pgpPrtPkts (const byte *pkts, unsigned int pktlen, pgpDig dig, int printing)
 Print/parse a OpenPGP packet(s).
 
pgpArmor pgpReadPkts (const char *fn, const byte **pkt, size_t *pktlen)
 Parse armored OpenPGP packets from a file.
 
char * pgpArmorWrap (int atype, const unsigned char *s, size_t ns)
 Wrap a OpenPGP packets in ascii armor for transport.
 

Variables

static int _debug = 0
 
static int _print = 0
 
static pgpDig _dig = NULL
 
static pgpDigParams _digp = NULL
 
struct pgpValTbl_s pgpSigTypeTbl []
 
struct pgpValTbl_s pgpPubkeyTbl []
 
struct pgpValTbl_s pgpSymkeyTbl []
 Symmetric key (string, value) pairs.
 
struct pgpValTbl_s pgpCompressionTbl []
 Compression (string, value) pairs.
 
struct pgpValTbl_s pgpHashTbl []
 Hash (string, value) pairs.
 
struct pgpValTbl_s pgpKeyServerPrefsTbl []
 
struct pgpValTbl_s pgpSubTypeTbl []
 Subtype (string, value) pairs.
 
struct pgpValTbl_s pgpTagTbl []
 
struct pgpValTbl_s pgpArmorTbl []
 Armor (string, value) pairs.
 
struct pgpValTbl_s pgpArmorKeyTbl []
 Armor key (string, value) pairs.
 
static const char * pgpSigRSA []
 
static const char * pgpSigDSA []
 
static const char * pgpPublicRSA []
 
static const char * pgpPublicDSA []
 
static const char * pgpPublicELGAMAL []
 

Detailed Description

Routines to handle RFC-2440 detached signatures.

Definition in file rpmpgp.c.

Macro Definition Documentation

#define TOKEQ (   _s,
  _tok 
)    (!strncmp((_s), (_tok), sizeof(_tok)-1))

Referenced by pgpReadPkts().

Function Documentation

char* pgpArmorWrap ( int  atype,
const unsigned char *  s,
size_t  ns 
)

Wrap a OpenPGP packets in ascii armor for transport.

Parameters
atypetype of armor
sbinary pkt data
nsbinary pkt data length
Returns
formatted string

Definition at line 1444 of file rpmpgp.c.

References _free(), pgpValStr(), stpcpy(), pgpValTbl_s::val, VERSION, and xmalloc().

Referenced by armorFormat(), and processMetadataFile().

void pgpCleanDig ( pgpDig  dig)
int pgpExtractPubkeyFingerprint ( const char *  b64pkt,
byte keyid 
)

Extract OpenPGP public key fingerprint from base64 encoded packet.

Todo:
V3 non-RSA public keys not implemented.
Parameters
b64pktbase64 encoded openpgp packet
Return values
keyid[8]public key fingerprint
Returns
8 (no. of bytes) on success, < 0 on error

Definition at line 1033 of file rpmpgp.c.

References _free(), and pgpPubkeyFingerprint().

Referenced by rpmdbAdd(), and rpmdbRemove().

pgpDig pgpFreeDig ( pgpDig  dig)
static int pgpGrabPkts ( const byte pkts,
unsigned int  pktlen,
byte ***  pppkts,
int *  pnpkts 
)
static

Definition at line 1205 of file rpmpgp.c.

References _free(), alloca(), pgpPktLen(), pgpPkt_s::pktlen, and xcalloc().

Referenced by pgpPrtPkts().

static int pgpHexSet ( const char *  pre,
int  lbits,
mpnumber *  mpn,
const byte p,
const byte pend 
)
static
Returns
0 on success

Definition at line 329 of file rpmpgp.c.

References _debug, _free(), _print, pgpMpiBits(), pgpMpiHex(), and xmalloc().

Referenced by pgpPrtSigParams().

static const char* pgpMpiHex ( const byte p)
static

Definition at line 316 of file rpmpgp.c.

References pgpHexCvt(), and pgpMpiLen().

Referenced by pgpHexSet(), pgpPrtPubkeyParams(), and pgpPrtSigParams().

pgpDig pgpNewDig ( void  )

Create a container for parsed OpenPGP packates.

Returns
container

Definition at line 1108 of file rpmpgp.c.

References xcalloc().

Referenced by getSignid(), makeGPGSignature(), makePGPSignature(), pgpsigFormat(), rpmcliImportPubkey(), and rpmtsDig().

int pgpPktLen ( const byte pkt,
unsigned int  pleft,
pgpPkt  pp 
)

Return lenth of a OpenPGP packet.

Parameters
pktOpenPGP packet (i.e. PGPTAG_PUBLIC_KEY)
pleftOpenPGP packet length (no. of bytes)
Return values
pppacket tag/ptr/len
Returns
packet length, <0 on error.

Definition at line 946 of file rpmpgp.c.

References pgpPkt_s::h, pgpPkt_s::hlen, pgpGrab(), pgpLen(), pgpPkt_s::pktlen, pgpPkt_s::tag, and pgpValTbl_s::val.

Referenced by pgpGrabPkts(), pgpPrtPkt(), pgpPrtPkts(), and pgpPubkeyFingerprint().

int pgpPrtComment ( const pgpPkt  pp)

Print/parse an OpenPGP comment packet.

Parameters
pppacket tag/ptr/len
Returns
0 on success

Definition at line 917 of file rpmpgp.c.

References _print, pgpPkt_s::h, pgpPkt_s::hlen, pgpPrtHex(), pgpPrtNL(), pgpPrtVal(), and pgpPkt_s::tag.

Referenced by pgpPrtPkt().

static void pgpPrtHex ( const char *  pre,
const byte p,
unsigned int  plen 
)
static

Definition at line 293 of file rpmpgp.c.

References _print, and pgpHexStr().

Referenced by pgpPrtComment(), pgpPrtPkt(), pgpPrtSeckeyParams(), pgpPrtSig(), and pgpPrtSubType().

static void pgpPrtInt ( const char *  pre,
int  i 
)
static

Definition at line 273 of file rpmpgp.c.

References _print.

Referenced by pgpPrtSeckeyParams().

int pgpPrtKey ( const pgpPkt  pp)
static void pgpPrtNL ( void  )
static
int pgpPrtPkt ( const byte pkt,
unsigned int  pleft 
)
int pgpPrtPkts ( const byte pkts,
unsigned int  pktlen,
pgpDig  dig,
int  printing 
)

Print/parse a OpenPGP packet(s).

Parameters
pktsOpenPGP packet(s)
pktlenOpenPGP packet(s) length (no. of bytes)
Return values
digparsed output of signature/pubkey packet parameters
Parameters
printingshould packets be printed?
Returns
-1 on error, 0 on success

Definition at line 1249 of file rpmpgp.c.

References _free(), _print, alloca(), pgpDig_s::npkts, pgpGrabPkts(), pgpPktLen(), pgpPrtPkt(), PGPTAG_SIGNATURE, pgpPkt_s::pktlen, pgpDig_s::ppkts, pgpDig_s::pubkey, pgpDig_s::signature, pgpDigParams_s::tag, and pgpValTbl_s::val.

Referenced by getSignid(), headerCheck(), makeGPGSignature(), makePGPSignature(), pgpsigFormat(), rpmcliImportPubkey(), rpmReadPackageFile(), rpmts_PgpPrtPkts(), rpmtsFindPubkey(), and rpmVerifySignatures().

static const byte* pgpPrtPubkeyParams ( const pgpPkt  pp,
byte  pubkey_algo,
const byte p 
)
static
static const byte* pgpPrtSeckeyParams ( const pgpPkt  pp,
byte  pubkey_algo,
const byte p 
)
static
int pgpPrtSig ( const pgpPkt  pp)
static int pgpPrtSigParams ( const pgpPkt  pp,
byte  pubkey_algo,
byte  sigtype,
const byte p 
)
static
static void pgpPrtStr ( const char *  pre,
const char *  s 
)
static

Definition at line 283 of file rpmpgp.c.

References _print.

Referenced by pgpPrtPubkeyParams(), pgpPrtSeckeyParams(), and pgpPrtSigParams().

int pgpPrtSubType ( const byte h,
unsigned int  hlen,
pgpSigType  sigtype 
)
int pgpPrtUserID ( const pgpPkt  pp)

Print/parse an OpenPGP userid packet.

Parameters
pppacket tag/ptr/len
Returns
0 on success

Definition at line 899 of file rpmpgp.c.

References _free(), _print, pgpPkt_s::h, pgpPkt_s::hlen, pgpPrtNL(), pgpPrtVal(), pgpPkt_s::tag, pgpDigParams_s::userid, and xmalloc().

Referenced by pgpPrtPkt().

void pgpPrtVal ( const char *  pre,
pgpValTbl  vs,
byte  val 
)

Print an OpenPGP value.

Parameters
preoutput prefix
vstable of (string,value) pairs
valbyte value to print

Definition at line 303 of file rpmpgp.c.

References _print, and pgpValStr().

Referenced by pgpPrtComment(), pgpPrtKey(), pgpPrtPkt(), pgpPrtSeckeyParams(), pgpPrtSig(), pgpPrtSubType(), and pgpPrtUserID().

int pgpPubkeyFingerprint ( const byte pkt,
unsigned int  pktlen,
byte keyid 
)

Calculate OpenPGP public key fingerprint.

Todo:
V3 non-RSA public keys not implemented.
Parameters
pktOpenPGP packet (i.e. PGPTAG_PUBLIC_KEY)
pktlenOpenPGP packet length (no. of bytes)
Return values
keyidpublick key fingerprint
Returns
0 on sucess, else -1

Definition at line 976 of file rpmpgp.c.

References _free(), alloca(), pgpPkt_s::h, PGPHASHALGO_SHA1, pgpMpiLen(), pgpPktLen(), PGPPUBKEYALGO_DSA, PGPPUBKEYALGO_RSA, PGPTAG_PUBLIC_KEY, pgpPktKeyV3_s::pubkey_algo, pgpPktKeyV4_s::pubkey_algo, RPMDIGEST_NONE, rpmDigestFinal(), rpmDigestInit(), rpmDigestUpdate(), and pgpPkt_s::tag.

Referenced by pgpExtractPubkeyFingerprint(), and pgpPrtPkt().

pgpArmor pgpReadPkts ( const char *  fn,
const byte **  pkt,
size_t *  pktlen 
)

Parse armored OpenPGP packets from a file.

Parameters
fnfile name
Return values
pktdearmored OpenPGP packet(s)
pktlendearmored OpenPGP packet(s) length in bytes
Returns
type of armor found

Definition at line 1292 of file rpmpgp.c.

References _free(), PGPARMOR_ERR_BODY_DECODE, PGPARMOR_ERR_CRC_CHECK, PGPARMOR_ERR_CRC_DECODE, PGPARMOR_ERR_NO_BEGIN_PGP, PGPARMOR_ERR_NO_END_PGP, PGPARMOR_ERR_UNKNOWN_ARMOR_TYPE, PGPARMOR_NONE, PGPARMOR_PUBKEY, pgpCRC(), pgpGrab(), pgpIsPkt(), pgpValTok(), rpmioSlurp(), and TOKEQ.

Referenced by processMetadataFile(), rpmcliImportPubkeys(), and rpmtsFindPubkey().

Variable Documentation

int _debug = 0
static

Definition at line 16 of file rpmpgp.c.

Referenced by pgpHexSet(), pgpPrtPubkeyParams(), pgpPrtSig(), and pgpPrtSigParams().

pgpDig _dig = NULL
static

Definition at line 22 of file rpmpgp.c.

pgpDigParams _digp = NULL
static

Definition at line 25 of file rpmpgp.c.

int _print = 0
static
struct pgpValTbl_s pgpArmorKeyTbl[]
Initial value:
= {
{ PGPARMORKEY_VERSION, "Version: " },
{ PGPARMORKEY_COMMENT, "Comment: " },
{ PGPARMORKEY_MESSAGEID, "MessageID: " },
{ PGPARMORKEY_HASH, "Hash: " },
{ PGPARMORKEY_CHARSET, "Charset: " },
{ -1, "Unknown armor key" }
}

Armor key (string, value) pairs.

Definition at line 256 of file rpmpgp.c.

struct pgpValTbl_s pgpArmorTbl[]
Initial value:
= {
{ PGPARMOR_MESSAGE, "MESSAGE" },
{ PGPARMOR_PUBKEY, "PUBLIC KEY BLOCK" },
{ PGPARMOR_SIGNATURE, "SIGNATURE" },
{ PGPARMOR_SIGNED_MESSAGE, "SIGNED MESSAGE" },
{ PGPARMOR_FILE, "ARMORED FILE" },
{ PGPARMOR_PRIVKEY, "PRIVATE KEY BLOCK" },
{ PGPARMOR_SECKEY, "SECRET KEY BLOCK" },
{ -1, "Unknown armor block" }
}

Armor (string, value) pairs.

Definition at line 245 of file rpmpgp.c.

struct pgpValTbl_s pgpCompressionTbl[]
Initial value:
= {
{ PGPCOMPRESSALGO_NONE, "Uncompressed" },
{ PGPCOMPRESSALGO_ZIP, "ZIP" },
{ PGPCOMPRESSALGO_ZLIB, "ZLIB" },
{ PGPCOMPRESSALGO_BZIP2, "BZIP2" },
{ -1, "Unknown compression algorithm" },
}

Compression (string, value) pairs.

Definition at line 151 of file rpmpgp.c.

struct pgpValTbl_s pgpHashTbl[]
Initial value:
= {
{ PGPHASHALGO_MD5, "MD5" },
{ PGPHASHALGO_SHA1, "SHA1" },
{ PGPHASHALGO_RIPEMD160, "RIPEMD160" },
{ PGPHASHALGO_MD2, "MD2" },
{ PGPHASHALGO_TIGER192, "TIGER192" },
{ PGPHASHALGO_HAVAL_5_160, "HAVAL-5-160" },
{ PGPHASHALGO_SHA256, "SHA256" },
{ PGPHASHALGO_SHA384, "SHA384" },
{ PGPHASHALGO_SHA512, "SHA512" },
{ -1, "Unknown hash algorithm" },
}

Hash (string, value) pairs.

Definition at line 159 of file rpmpgp.c.

struct pgpValTbl_s pgpKeyServerPrefsTbl[]
Initial value:
= {
{ 0x80, "No-modify" },
{ -1, "Unknown key server preference" },
}

Definition at line 174 of file rpmpgp.c.

struct pgpValTbl_s pgpPubkeyTbl[]
Initial value:
= {
{ PGPPUBKEYALGO_RSA, "RSA" },
{ PGPPUBKEYALGO_RSA_ENCRYPT,"RSA(Encrypt-Only)" },
{ PGPPUBKEYALGO_RSA_SIGN, "RSA(Sign-Only)" },
{ PGPPUBKEYALGO_ELGAMAL_ENCRYPT,"Elgamal(Encrypt-Only)" },
{ PGPPUBKEYALGO_DSA, "DSA" },
{ PGPPUBKEYALGO_EC, "Elliptic Curve" },
{ PGPPUBKEYALGO_ECDSA, "ECDSA" },
{ PGPPUBKEYALGO_ELGAMAL, "Elgamal" },
{ PGPPUBKEYALGO_DH, "Diffie-Hellman (X9.42)" },
{ -1, "Unknown public key algorithm" },
}

Definition at line 122 of file rpmpgp.c.

const char* pgpPublicDSA[]
static
Initial value:
= {
" p =",
" q =",
" g =",
" y =",
NULL,
}

Definition at line 660 of file rpmpgp.c.

Referenced by pgpPrtPubkeyParams().

const char* pgpPublicELGAMAL[]
static
Initial value:
= {
" p =",
" g =",
" y =",
NULL,
}

Definition at line 677 of file rpmpgp.c.

Referenced by pgpPrtPubkeyParams().

const char* pgpPublicRSA[]
static
Initial value:
= {
" n =",
" e =",
NULL,
}

Definition at line 642 of file rpmpgp.c.

Referenced by pgpPrtPubkeyParams().

const char* pgpSigDSA[]
static
Initial value:
= {
" r =",
" s =",
NULL,
}

Definition at line 469 of file rpmpgp.c.

Referenced by pgpPrtSigParams().

const char* pgpSigRSA[]
static
Initial value:
= {
" m**d =",
NULL,
}

Definition at line 463 of file rpmpgp.c.

Referenced by pgpPrtSigParams().

struct pgpValTbl_s pgpSigTypeTbl[]
Initial value:
= {
{ PGPSIGTYPE_BINARY, "Binary document signature" },
{ PGPSIGTYPE_TEXT, "Text document signature" },
{ PGPSIGTYPE_STANDALONE, "Standalone signature" },
{ PGPSIGTYPE_GENERIC_CERT, "Generic certification of a User ID and Public Key" },
{ PGPSIGTYPE_PERSONA_CERT, "Personal certification of a User ID and Public Key" },
{ PGPSIGTYPE_CASUAL_CERT, "Casual certification of a User ID and Public Key" },
{ PGPSIGTYPE_POSITIVE_CERT, "Positive certification of a User ID and Public Key" },
{ PGPSIGTYPE_SUBKEY_BINDING,"Subkey Binding Signature" },
{ PGPSIGTYPE_SIGNED_KEY, "Signature directly on a key" },
{ PGPSIGTYPE_KEY_REVOKE, "Key revocation signature" },
{ PGPSIGTYPE_SUBKEY_REVOKE, "Subkey revocation signature" },
{ PGPSIGTYPE_CERT_REVOKE, "Certification revocation signature" },
{ PGPSIGTYPE_TIMESTAMP, "Timestamp signature" },
{ -1, "Unknown signature type" },
}

Definition at line 105 of file rpmpgp.c.

struct pgpValTbl_s pgpSubTypeTbl[]

Subtype (string, value) pairs.

Definition at line 180 of file rpmpgp.c.

struct pgpValTbl_s pgpSymkeyTbl[]
Initial value:
= {
{ PGPSYMKEYALGO_PLAINTEXT, "Plaintext" },
{ PGPSYMKEYALGO_IDEA, "IDEA" },
{ PGPSYMKEYALGO_CAST5, "CAST5" },
{ PGPSYMKEYALGO_BLOWFISH, "BLOWFISH" },
{ PGPSYMKEYALGO_SAFER, "SAFER" },
{ PGPSYMKEYALGO_DES_SK, "DES/SK" },
{ PGPSYMKEYALGO_AES_128, "AES(128-bit key)" },
{ PGPSYMKEYALGO_AES_192, "AES(192-bit key)" },
{ PGPSYMKEYALGO_AES_256, "AES(256-bit key)" },
{ PGPSYMKEYALGO_TWOFISH, "TWOFISH(256-bit key)" },
{ PGPSYMKEYALGO_NOENCRYPT, "no encryption" },
{ -1, "Unknown symmetric key algorithm" },
}

Symmetric key (string, value) pairs.

Definition at line 135 of file rpmpgp.c.

struct pgpValTbl_s pgpTagTbl[]
Initial value:
= {
{ PGPTAG_PUBLIC_SESSION_KEY,"Public-Key Encrypted Session Key" },
{ PGPTAG_SIGNATURE, "Signature" },
{ PGPTAG_SYMMETRIC_SESSION_KEY,"Symmetric-Key Encrypted Session Key" },
{ PGPTAG_ONEPASS_SIGNATURE, "One-Pass Signature" },
{ PGPTAG_SECRET_KEY, "Secret Key" },
{ PGPTAG_PUBLIC_KEY, "Public Key" },
{ PGPTAG_SECRET_SUBKEY, "Secret Subkey" },
{ PGPTAG_COMPRESSED_DATA, "Compressed Data" },
{ PGPTAG_SYMMETRIC_DATA, "Symmetrically Encrypted Data" },
{ PGPTAG_MARKER, "Marker" },
{ PGPTAG_LITERAL_DATA, "Literal Data" },
{ PGPTAG_TRUST, "Trust" },
{ PGPTAG_USER_ID, "User ID" },
{ PGPTAG_PUBLIC_SUBKEY, "Public Subkey" },
{ PGPTAG_COMMENT_OLD, "Comment (from OpenPGP draft)" },
{ PGPTAG_PHOTOID, "PGP's photo ID" },
{ PGPTAG_ENCRYPTED_MDC, "Integrity protected encrypted data" },
{ PGPTAG_MDC, "Manipulaion detection code packet" },
{ PGPTAG_PRIVATE_60, "Private #60" },
{ PGPTAG_COMMENT, "Comment" },
{ PGPTAG_PRIVATE_62, "Private #62" },
{ PGPTAG_CONTROL, "Control (GPG)" },
{ -1, "Unknown packet tag" },
}

Definition at line 219 of file rpmpgp.c.