373e16c9b10555ae8c0683c468b73e2386a04c4e
[platform/upstream/rpm.git] / rpmio / thkp.c
1 #include "system.h"
2
3 #include "rpmio_internal.h"
4 #include "rpmmacro.h"
5 #include "rpmmessages.h"
6 #include <popt.h>
7
8 #include "debug.h"
9
10 static int _debug = 0;
11 static int _printing = 0;
12
13 #if 0
14 #define HKPPATH         "hkp://pgp.mit.edu:11371/pks/lookup?op=get&search=0xF5C75256"
15 #else
16 #if 0
17 #define HKPPATH         "hkp://pgp.mit.edu"
18 #else
19 #define HKPPATH         "hkp://sks.keyserver.penguin.de"
20 #endif
21 #endif
22 static char * hkppath = HKPPATH;
23
24 static unsigned int keyids[] = {
25 #if 0
26         0xc2b079fc, 0xf5c75256,
27         0x94cd5742, 0xe418e3aa,
28         0xb44269d0, 0x4f2a6fd2,
29         0xda84cbd4, 0x30c9ecf8,
30         0x29d5ba24, 0x8df56d05,
31         0xa520e8f1, 0xcba29bf9,
32         0x219180cd, 0xdb42a60e,
33         0xfd372689, 0x897da07a,
34         0xe1385d4e, 0x1cddbca9,
35         0xb873641b, 0x2039b291,
36 #endif
37         0x58e727c4, 0xc621be0f,
38         0
39 };
40
41 static int readKeys(const char * uri)
42 {
43     unsigned int * kip;
44     const byte * pkt;
45     size_t pktlen;
46     byte keyid[8];
47     char fn[BUFSIZ];
48     pgpDig dig;
49     int rc;
50     int ec = 0;
51
52     rpmInitCrypto();
53     dig = pgpNewDig();
54     for (kip = keyids; *kip; kip += 2) {
55         pgpArmor pa;
56
57         sprintf(fn, "%s/pks/lookup?op=get&search=0x%08x%08x", uri, kip[0], kip[1]);
58 fprintf(stderr, "======================= %s\n", fn);
59         pkt = NULL;
60         pktlen = 0;
61         pa = pgpReadPkts(fn, &pkt, &pktlen);
62         if (pa == PGPARMOR_ERROR || pa == PGPARMOR_NONE
63          || pkt == NULL || pktlen <= 0)
64         {
65             ec++;
66             continue;
67         }
68
69         rc = pgpPrtPkts(pkt, pktlen, dig, _printing);
70         if (rc)
71             ec++;
72 #if 0
73 fprintf(stderr, "%s\n", pgpHexStr(pkt, pktlen));
74 #endif
75         if (!pgpPubkeyFingerprint(pkt, pktlen, keyid))
76 fprintf(stderr, "KEYID: %08x %08x\n", pgpGrab(keyid, 4), pgpGrab(keyid+4, 4));
77
78
79         pgpCleanDig(dig);
80
81         free((void *)pkt);
82         pkt = NULL;
83     }
84     dig = pgpFreeDig(dig);
85
86     return ec;
87 }
88
89 static struct poptOption optionsTable[] = {
90  { "print", 'p', POPT_ARG_VAL,  &_printing, 1,          NULL, NULL },
91  { "noprint", 'n', POPT_ARG_VAL, &_printing, 0,         NULL, NULL },
92  { "debug", 'd', POPT_ARG_VAL,  &_debug, -1,            NULL, NULL },
93  { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
94         N_("debug rpmio I/O"), NULL},
95  { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
96         N_("debug URL cache handling"), NULL},
97  { "verbose", 'v', 0, 0, 'v',                           NULL, NULL },
98   POPT_AUTOHELP
99   POPT_TABLEEND
100 };
101
102 int
103 main(int argc, char *argv[])
104 {
105     poptContext optCon = poptGetContext(argv[0], argc, (const char **) argv, optionsTable, 0);
106     int rc;
107
108     while ((rc = poptGetNextOpt(optCon)) > 0) {
109         switch (rc) {
110         case 'v':
111             rpmIncreaseVerbosity();
112             break;
113         default:
114             break;
115         }
116     }
117
118     if (_debug) {
119         rpmIncreaseVerbosity();
120         rpmIncreaseVerbosity();
121     }
122
123     readKeys(hkppath);
124
125     return 0;
126 }