#include "postgres.h"
#include "px.h"
#include "mbuf.h"
#include "pgp.h"
Go to the source code of this file.
Functions | |
static int | read_pubkey_keyid (PullFilter *pkt, uint8 *keyid_buf) |
static int | read_pubenc_keyid (PullFilter *pkt, uint8 *keyid_buf) |
static int | print_key (uint8 *keyid, char *dst) |
int | pgp_get_keyid (MBuf *pgp_data, char *dst) |
Variables | |
static const char | hextbl [] = "0123456789ABCDEF" |
static const uint8 | any_key [] |
int pgp_get_keyid | ( | MBuf * | pgp_data, | |
char * | dst | |||
) |
Definition at line 112 of file pgp-info.c.
References any_key, memcmp(), NULL, pgp_create_pkt_reader(), pgp_parse_pkt_hdr(), PGP_PKT_MARKER, PGP_PKT_PRIV_61, PGP_PKT_PUBENCRYPTED_SESSKEY, PGP_PKT_PUBLIC_KEY, PGP_PKT_PUBLIC_SUBKEY, PGP_PKT_SECRET_KEY, PGP_PKT_SECRET_SUBKEY, PGP_PKT_SIGNATURE, PGP_PKT_SYMENCRYPTED_DATA, PGP_PKT_SYMENCRYPTED_DATA_MDC, PGP_PKT_SYMENCRYPTED_SESSKEY, PGP_PKT_TRUST, PGP_PKT_USER_ATTR, PGP_PKT_USER_ID, pgp_skip_packet(), print_key(), pullf_create_mbuf_reader(), pullf_free(), read_pubenc_keyid(), and read_pubkey_keyid().
Referenced by pgp_key_id_w().
{ int res; PullFilter *src; PullFilter *pkt = NULL; int len; uint8 tag; int got_pub_key = 0, got_symenc_key = 0, got_pubenc_key = 0; int got_data = 0; uint8 keyid_buf[8]; int got_main_key = 0; res = pullf_create_mbuf_reader(&src, pgp_data); if (res < 0) return res; while (1) { res = pgp_parse_pkt_hdr(src, &tag, &len, 0); if (res <= 0) break; res = pgp_create_pkt_reader(&pkt, src, len, res, NULL); if (res < 0) break; switch (tag) { case PGP_PKT_SECRET_KEY: case PGP_PKT_PUBLIC_KEY: /* main key is for signing, so ignore it */ if (!got_main_key) { got_main_key = 1; res = pgp_skip_packet(pkt); } else res = PXE_PGP_MULTIPLE_KEYS; break; case PGP_PKT_SECRET_SUBKEY: case PGP_PKT_PUBLIC_SUBKEY: res = read_pubkey_keyid(pkt, keyid_buf); if (res < 0) break; if (res > 0) got_pub_key++; break; case PGP_PKT_PUBENCRYPTED_SESSKEY: got_pubenc_key++; res = read_pubenc_keyid(pkt, keyid_buf); break; case PGP_PKT_SYMENCRYPTED_DATA: case PGP_PKT_SYMENCRYPTED_DATA_MDC: /* don't skip it, just stop */ got_data = 1; break; case PGP_PKT_SYMENCRYPTED_SESSKEY: got_symenc_key++; /* fallthru */ case PGP_PKT_SIGNATURE: case PGP_PKT_MARKER: case PGP_PKT_TRUST: case PGP_PKT_USER_ID: case PGP_PKT_USER_ATTR: case PGP_PKT_PRIV_61: res = pgp_skip_packet(pkt); break; default: res = PXE_PGP_CORRUPT_DATA; } if (pkt) pullf_free(pkt); pkt = NULL; if (res < 0 || got_data) break; } pullf_free(src); if (pkt) pullf_free(pkt); if (res < 0) return res; /* now check sanity */ if (got_pub_key && got_pubenc_key) res = PXE_PGP_CORRUPT_DATA; if (got_pub_key > 1) res = PXE_PGP_MULTIPLE_KEYS; if (got_pubenc_key > 1) res = PXE_PGP_MULTIPLE_KEYS; /* * if still ok, look what we got */ if (res >= 0) { if (got_pubenc_key || got_pub_key) { if (memcmp(keyid_buf, any_key, 8) == 0) { memcpy(dst, "ANYKEY", 7); res = 6; } else res = print_key(keyid_buf, dst); } else if (got_symenc_key) { memcpy(dst, "SYMKEY", 7); res = 6; } else res = PXE_PGP_NO_USABLE_KEY; } return res; }
static int print_key | ( | uint8 * | keyid, | |
char * | dst | |||
) | [static] |
Definition at line 90 of file pgp-info.c.
Referenced by pgp_get_keyid().
static int read_pubenc_keyid | ( | PullFilter * | pkt, | |
uint8 * | keyid_buf | |||
) | [static] |
Definition at line 71 of file pgp-info.c.
References GETBYTE, pgp_skip_packet(), and pullf_read_fixed().
Referenced by pgp_get_keyid().
{ uint8 ver; int res; GETBYTE(pkt, ver); if (ver != 3) return -1; res = pullf_read_fixed(pkt, 8, keyid_buf); if (res < 0) return res; return pgp_skip_packet(pkt); }
static int read_pubkey_keyid | ( | PullFilter * | pkt, | |
uint8 * | keyid_buf | |||
) | [static] |
Definition at line 38 of file pgp-info.c.
References _pgp_read_public_key(), PGP_PubKey::algo, PGP_PubKey::key_id, pgp_key_free(), PGP_PUB_ELG_ENCRYPT, PGP_PUB_RSA_ENCRYPT, PGP_PUB_RSA_ENCRYPT_SIGN, and pgp_skip_packet().
Referenced by pgp_get_keyid().
{ int res; PGP_PubKey *pk = NULL; res = _pgp_read_public_key(pkt, &pk); if (res < 0) goto err; /* skip secret key part, if it exists */ res = pgp_skip_packet(pkt); if (res < 0) goto err; /* is it encryption key */ switch (pk->algo) { case PGP_PUB_ELG_ENCRYPT: case PGP_PUB_RSA_ENCRYPT: case PGP_PUB_RSA_ENCRYPT_SIGN: memcpy(keyid_buf, pk->key_id, 8); res = 1; break; default: res = 0; } err: pgp_key_free(pk); return res; }
{0, 0, 0, 0, 0, 0, 0, 0}
Definition at line 105 of file pgp-info.c.
Referenced by pgp_get_keyid().
const char hextbl[] = "0123456789ABCDEF" [static] |
Definition at line 87 of file pgp-info.c.
Referenced by appendByteaLiteral(), and print_key().