1*ebfedea0SLionel Sambuc /*-
2*ebfedea0SLionel Sambuc * Copyright (c) 2009 The NetBSD Foundation, Inc.
3*ebfedea0SLionel Sambuc * All rights reserved.
4*ebfedea0SLionel Sambuc *
5*ebfedea0SLionel Sambuc * This code is derived from software contributed to The NetBSD Foundation
6*ebfedea0SLionel Sambuc * by Alistair Crooks (agc@NetBSD.org)
7*ebfedea0SLionel Sambuc *
8*ebfedea0SLionel Sambuc * Redistribution and use in source and binary forms, with or without
9*ebfedea0SLionel Sambuc * modification, are permitted provided that the following conditions
10*ebfedea0SLionel Sambuc * are met:
11*ebfedea0SLionel Sambuc * 1. Redistributions of source code must retain the above copyright
12*ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer.
13*ebfedea0SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
14*ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer in the
15*ebfedea0SLionel Sambuc * documentation and/or other materials provided with the distribution.
16*ebfedea0SLionel Sambuc *
17*ebfedea0SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18*ebfedea0SLionel Sambuc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19*ebfedea0SLionel Sambuc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20*ebfedea0SLionel Sambuc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21*ebfedea0SLionel Sambuc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22*ebfedea0SLionel Sambuc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23*ebfedea0SLionel Sambuc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*ebfedea0SLionel Sambuc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25*ebfedea0SLionel Sambuc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26*ebfedea0SLionel Sambuc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27*ebfedea0SLionel Sambuc * POSSIBILITY OF SUCH DAMAGE.
28*ebfedea0SLionel Sambuc */
29*ebfedea0SLionel Sambuc /*
30*ebfedea0SLionel Sambuc * Copyright (c) 2005-2008 Nominet UK (www.nic.uk)
31*ebfedea0SLionel Sambuc * All rights reserved.
32*ebfedea0SLionel Sambuc * Contributors: Ben Laurie, Rachel Willmer. The Contributors have asserted
33*ebfedea0SLionel Sambuc * their moral rights under the UK Copyright Design and Patents Act 1988 to
34*ebfedea0SLionel Sambuc * be recorded as the authors of this copyright work.
35*ebfedea0SLionel Sambuc *
36*ebfedea0SLionel Sambuc * Licensed under the Apache License, Version 2.0 (the "License"); you may not
37*ebfedea0SLionel Sambuc * use this file except in compliance with the License.
38*ebfedea0SLionel Sambuc *
39*ebfedea0SLionel Sambuc * You may obtain a copy of the License at
40*ebfedea0SLionel Sambuc * http://www.apache.org/licenses/LICENSE-2.0
41*ebfedea0SLionel Sambuc *
42*ebfedea0SLionel Sambuc * Unless required by applicable law or agreed to in writing, software
43*ebfedea0SLionel Sambuc * distributed under the License is distributed on an "AS IS" BASIS,
44*ebfedea0SLionel Sambuc * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45*ebfedea0SLionel Sambuc *
46*ebfedea0SLionel Sambuc * See the License for the specific language governing permissions and
47*ebfedea0SLionel Sambuc * limitations under the License.
48*ebfedea0SLionel Sambuc */
49*ebfedea0SLionel Sambuc
50*ebfedea0SLionel Sambuc /*
51*ebfedea0SLionel Sambuc * ! \file \brief Standard API print functions
52*ebfedea0SLionel Sambuc */
53*ebfedea0SLionel Sambuc #include "config.h"
54*ebfedea0SLionel Sambuc
55*ebfedea0SLionel Sambuc #ifdef HAVE_SYS_CDEFS_H
56*ebfedea0SLionel Sambuc #include <sys/cdefs.h>
57*ebfedea0SLionel Sambuc #endif
58*ebfedea0SLionel Sambuc
59*ebfedea0SLionel Sambuc #if defined(__NetBSD__)
60*ebfedea0SLionel Sambuc __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
61*ebfedea0SLionel Sambuc __RCSID("$NetBSD: packet-print.c,v 1.42 2012/02/22 06:29:40 agc Exp $");
62*ebfedea0SLionel Sambuc #endif
63*ebfedea0SLionel Sambuc
64*ebfedea0SLionel Sambuc #include <string.h>
65*ebfedea0SLionel Sambuc #include <stdio.h>
66*ebfedea0SLionel Sambuc
67*ebfedea0SLionel Sambuc #ifdef HAVE_UNISTD_H
68*ebfedea0SLionel Sambuc #include <unistd.h>
69*ebfedea0SLionel Sambuc #endif
70*ebfedea0SLionel Sambuc
71*ebfedea0SLionel Sambuc #include "crypto.h"
72*ebfedea0SLionel Sambuc #include "keyring.h"
73*ebfedea0SLionel Sambuc #include "packet-show.h"
74*ebfedea0SLionel Sambuc #include "signature.h"
75*ebfedea0SLionel Sambuc #include "readerwriter.h"
76*ebfedea0SLionel Sambuc #include "netpgpdefs.h"
77*ebfedea0SLionel Sambuc #include "netpgpsdk.h"
78*ebfedea0SLionel Sambuc #include "packet.h"
79*ebfedea0SLionel Sambuc #include "netpgpdigest.h"
80*ebfedea0SLionel Sambuc #include "mj.h"
81*ebfedea0SLionel Sambuc
82*ebfedea0SLionel Sambuc /* static functions */
83*ebfedea0SLionel Sambuc
84*ebfedea0SLionel Sambuc static void
print_indent(int indent)85*ebfedea0SLionel Sambuc print_indent(int indent)
86*ebfedea0SLionel Sambuc {
87*ebfedea0SLionel Sambuc int i;
88*ebfedea0SLionel Sambuc
89*ebfedea0SLionel Sambuc for (i = 0; i < indent; i++) {
90*ebfedea0SLionel Sambuc printf(" ");
91*ebfedea0SLionel Sambuc }
92*ebfedea0SLionel Sambuc }
93*ebfedea0SLionel Sambuc
94*ebfedea0SLionel Sambuc static void
print_name(int indent,const char * name)95*ebfedea0SLionel Sambuc print_name(int indent, const char *name)
96*ebfedea0SLionel Sambuc {
97*ebfedea0SLionel Sambuc print_indent(indent);
98*ebfedea0SLionel Sambuc if (name) {
99*ebfedea0SLionel Sambuc printf("%s: ", name);
100*ebfedea0SLionel Sambuc }
101*ebfedea0SLionel Sambuc }
102*ebfedea0SLionel Sambuc
103*ebfedea0SLionel Sambuc static void
print_hexdump(int indent,const char * name,const uint8_t * data,unsigned len)104*ebfedea0SLionel Sambuc print_hexdump(int indent, const char *name, const uint8_t *data, unsigned len)
105*ebfedea0SLionel Sambuc {
106*ebfedea0SLionel Sambuc print_name(indent, name);
107*ebfedea0SLionel Sambuc hexdump(stdout, NULL, data, len);
108*ebfedea0SLionel Sambuc }
109*ebfedea0SLionel Sambuc
110*ebfedea0SLionel Sambuc static void
hexdump_data(int indent,const char * name,const uint8_t * data,unsigned len)111*ebfedea0SLionel Sambuc hexdump_data(int indent, const char *name, const uint8_t *data, unsigned len)
112*ebfedea0SLionel Sambuc {
113*ebfedea0SLionel Sambuc print_name(indent, name);
114*ebfedea0SLionel Sambuc hexdump(stdout, NULL, data, len);
115*ebfedea0SLionel Sambuc }
116*ebfedea0SLionel Sambuc
117*ebfedea0SLionel Sambuc static void
print_uint(int indent,const char * name,unsigned val)118*ebfedea0SLionel Sambuc print_uint(int indent, const char *name, unsigned val)
119*ebfedea0SLionel Sambuc {
120*ebfedea0SLionel Sambuc print_name(indent, name);
121*ebfedea0SLionel Sambuc printf("%u\n", val);
122*ebfedea0SLionel Sambuc }
123*ebfedea0SLionel Sambuc
124*ebfedea0SLionel Sambuc static void
showtime(const char * name,time_t t)125*ebfedea0SLionel Sambuc showtime(const char *name, time_t t)
126*ebfedea0SLionel Sambuc {
127*ebfedea0SLionel Sambuc printf("%s=%" PRItime "d (%.24s)", name, (long long) t, ctime(&t));
128*ebfedea0SLionel Sambuc }
129*ebfedea0SLionel Sambuc
130*ebfedea0SLionel Sambuc static void
print_time(int indent,const char * name,time_t t)131*ebfedea0SLionel Sambuc print_time(int indent, const char *name, time_t t)
132*ebfedea0SLionel Sambuc {
133*ebfedea0SLionel Sambuc print_indent(indent);
134*ebfedea0SLionel Sambuc printf("%s: ", name);
135*ebfedea0SLionel Sambuc showtime("time", t);
136*ebfedea0SLionel Sambuc printf("\n");
137*ebfedea0SLionel Sambuc }
138*ebfedea0SLionel Sambuc
139*ebfedea0SLionel Sambuc static void
print_string_and_value(int indent,const char * name,const char * str,uint8_t value)140*ebfedea0SLionel Sambuc print_string_and_value(int indent, const char *name, const char *str, uint8_t value)
141*ebfedea0SLionel Sambuc {
142*ebfedea0SLionel Sambuc print_name(indent, name);
143*ebfedea0SLionel Sambuc printf("%s (0x%x)\n", str, value);
144*ebfedea0SLionel Sambuc }
145*ebfedea0SLionel Sambuc
146*ebfedea0SLionel Sambuc static void
print_tagname(int indent,const char * str)147*ebfedea0SLionel Sambuc print_tagname(int indent, const char *str)
148*ebfedea0SLionel Sambuc {
149*ebfedea0SLionel Sambuc print_indent(indent);
150*ebfedea0SLionel Sambuc printf("%s packet\n", str);
151*ebfedea0SLionel Sambuc }
152*ebfedea0SLionel Sambuc
153*ebfedea0SLionel Sambuc static void
print_data(int indent,const char * name,const pgp_data_t * data)154*ebfedea0SLionel Sambuc print_data(int indent, const char *name, const pgp_data_t *data)
155*ebfedea0SLionel Sambuc {
156*ebfedea0SLionel Sambuc print_hexdump(indent, name, data->contents, (unsigned)data->len);
157*ebfedea0SLionel Sambuc }
158*ebfedea0SLionel Sambuc
159*ebfedea0SLionel Sambuc static void
print_bn(int indent,const char * name,const BIGNUM * bn)160*ebfedea0SLionel Sambuc print_bn(int indent, const char *name, const BIGNUM *bn)
161*ebfedea0SLionel Sambuc {
162*ebfedea0SLionel Sambuc print_indent(indent);
163*ebfedea0SLionel Sambuc printf("%s=", name);
164*ebfedea0SLionel Sambuc if (bn) {
165*ebfedea0SLionel Sambuc BN_print_fp(stdout, bn);
166*ebfedea0SLionel Sambuc putchar('\n');
167*ebfedea0SLionel Sambuc } else {
168*ebfedea0SLionel Sambuc puts("(unset)");
169*ebfedea0SLionel Sambuc }
170*ebfedea0SLionel Sambuc }
171*ebfedea0SLionel Sambuc
172*ebfedea0SLionel Sambuc static void
print_packet_hex(const pgp_subpacket_t * pkt)173*ebfedea0SLionel Sambuc print_packet_hex(const pgp_subpacket_t *pkt)
174*ebfedea0SLionel Sambuc {
175*ebfedea0SLionel Sambuc hexdump(stdout, "packet contents:", pkt->raw, pkt->length);
176*ebfedea0SLionel Sambuc }
177*ebfedea0SLionel Sambuc
178*ebfedea0SLionel Sambuc static void
print_escaped(const uint8_t * data,size_t length)179*ebfedea0SLionel Sambuc print_escaped(const uint8_t *data, size_t length)
180*ebfedea0SLionel Sambuc {
181*ebfedea0SLionel Sambuc while (length-- > 0) {
182*ebfedea0SLionel Sambuc if ((*data >= 0x20 && *data < 0x7f && *data != '%') ||
183*ebfedea0SLionel Sambuc *data == '\n') {
184*ebfedea0SLionel Sambuc putchar(*data);
185*ebfedea0SLionel Sambuc } else {
186*ebfedea0SLionel Sambuc printf("%%%02x", *data);
187*ebfedea0SLionel Sambuc }
188*ebfedea0SLionel Sambuc ++data;
189*ebfedea0SLionel Sambuc }
190*ebfedea0SLionel Sambuc }
191*ebfedea0SLionel Sambuc
192*ebfedea0SLionel Sambuc static void
print_string(int indent,const char * name,const char * str)193*ebfedea0SLionel Sambuc print_string(int indent, const char *name, const char *str)
194*ebfedea0SLionel Sambuc {
195*ebfedea0SLionel Sambuc print_name(indent, name);
196*ebfedea0SLionel Sambuc print_escaped((const uint8_t *) str, strlen(str));
197*ebfedea0SLionel Sambuc putchar('\n');
198*ebfedea0SLionel Sambuc }
199*ebfedea0SLionel Sambuc
200*ebfedea0SLionel Sambuc static void
print_utf8_string(int indent,const char * name,const uint8_t * str)201*ebfedea0SLionel Sambuc print_utf8_string(int indent, const char *name, const uint8_t *str)
202*ebfedea0SLionel Sambuc {
203*ebfedea0SLionel Sambuc /* \todo Do this better for non-English character sets */
204*ebfedea0SLionel Sambuc print_string(indent, name, (const char *) str);
205*ebfedea0SLionel Sambuc }
206*ebfedea0SLionel Sambuc
207*ebfedea0SLionel Sambuc static void
print_duration(int indent,const char * name,time_t t)208*ebfedea0SLionel Sambuc print_duration(int indent, const char *name, time_t t)
209*ebfedea0SLionel Sambuc {
210*ebfedea0SLionel Sambuc int mins, hours, days, years;
211*ebfedea0SLionel Sambuc
212*ebfedea0SLionel Sambuc print_indent(indent);
213*ebfedea0SLionel Sambuc printf("%s: ", name);
214*ebfedea0SLionel Sambuc printf("duration %" PRItime "d seconds", (long long) t);
215*ebfedea0SLionel Sambuc
216*ebfedea0SLionel Sambuc mins = (int)(t / 60);
217*ebfedea0SLionel Sambuc hours = mins / 60;
218*ebfedea0SLionel Sambuc days = hours / 24;
219*ebfedea0SLionel Sambuc years = days / 365;
220*ebfedea0SLionel Sambuc
221*ebfedea0SLionel Sambuc printf(" (approx. ");
222*ebfedea0SLionel Sambuc if (years) {
223*ebfedea0SLionel Sambuc printf("%d %s", years, years == 1 ? "year" : "years");
224*ebfedea0SLionel Sambuc } else if (days) {
225*ebfedea0SLionel Sambuc printf("%d %s", days, days == 1 ? "day" : "days");
226*ebfedea0SLionel Sambuc } else if (hours) {
227*ebfedea0SLionel Sambuc printf("%d %s", hours, hours == 1 ? "hour" : "hours");
228*ebfedea0SLionel Sambuc }
229*ebfedea0SLionel Sambuc printf(")\n");
230*ebfedea0SLionel Sambuc }
231*ebfedea0SLionel Sambuc
232*ebfedea0SLionel Sambuc static void
print_boolean(int indent,const char * name,uint8_t boolval)233*ebfedea0SLionel Sambuc print_boolean(int indent, const char *name, uint8_t boolval)
234*ebfedea0SLionel Sambuc {
235*ebfedea0SLionel Sambuc print_name(indent, name);
236*ebfedea0SLionel Sambuc printf("%s\n", (boolval) ? "Yes" : "No");
237*ebfedea0SLionel Sambuc }
238*ebfedea0SLionel Sambuc
239*ebfedea0SLionel Sambuc static void
print_text_breakdown(int indent,pgp_text_t * text)240*ebfedea0SLionel Sambuc print_text_breakdown(int indent, pgp_text_t *text)
241*ebfedea0SLionel Sambuc {
242*ebfedea0SLionel Sambuc const char *prefix = ".. ";
243*ebfedea0SLionel Sambuc unsigned i;
244*ebfedea0SLionel Sambuc
245*ebfedea0SLionel Sambuc /* these were recognised */
246*ebfedea0SLionel Sambuc for (i = 0; i < text->known.used; i++) {
247*ebfedea0SLionel Sambuc print_indent(indent);
248*ebfedea0SLionel Sambuc printf("%s", prefix);
249*ebfedea0SLionel Sambuc printf("%s\n", text->known.strings[i]);
250*ebfedea0SLionel Sambuc }
251*ebfedea0SLionel Sambuc /*
252*ebfedea0SLionel Sambuc * these were not recognised. the strings will contain the hex value
253*ebfedea0SLionel Sambuc * of the unrecognised value in string format - see
254*ebfedea0SLionel Sambuc * process_octet_str()
255*ebfedea0SLionel Sambuc */
256*ebfedea0SLionel Sambuc if (text->unknown.used) {
257*ebfedea0SLionel Sambuc printf("\n");
258*ebfedea0SLionel Sambuc print_indent(indent);
259*ebfedea0SLionel Sambuc printf("Not Recognised: ");
260*ebfedea0SLionel Sambuc }
261*ebfedea0SLionel Sambuc for (i = 0; i < text->unknown.used; i++) {
262*ebfedea0SLionel Sambuc print_indent(indent);
263*ebfedea0SLionel Sambuc printf("%s", prefix);
264*ebfedea0SLionel Sambuc printf("%s\n", text->unknown.strings[i]);
265*ebfedea0SLionel Sambuc }
266*ebfedea0SLionel Sambuc }
267*ebfedea0SLionel Sambuc
268*ebfedea0SLionel Sambuc static void
print_headers(const pgp_headers_t * h)269*ebfedea0SLionel Sambuc print_headers(const pgp_headers_t *h)
270*ebfedea0SLionel Sambuc {
271*ebfedea0SLionel Sambuc unsigned i;
272*ebfedea0SLionel Sambuc
273*ebfedea0SLionel Sambuc for (i = 0; i < h->headerc; ++i) {
274*ebfedea0SLionel Sambuc printf("%s=%s\n", h->headers[i].key, h->headers[i].value);
275*ebfedea0SLionel Sambuc }
276*ebfedea0SLionel Sambuc }
277*ebfedea0SLionel Sambuc
278*ebfedea0SLionel Sambuc static void
print_block(int indent,const char * name,const uint8_t * str,size_t length)279*ebfedea0SLionel Sambuc print_block(int indent, const char *name, const uint8_t *str, size_t length)
280*ebfedea0SLionel Sambuc {
281*ebfedea0SLionel Sambuc int o = (int)length;
282*ebfedea0SLionel Sambuc
283*ebfedea0SLionel Sambuc print_indent(indent);
284*ebfedea0SLionel Sambuc printf(">>>>> %s >>>>>\n", name);
285*ebfedea0SLionel Sambuc
286*ebfedea0SLionel Sambuc print_indent(indent);
287*ebfedea0SLionel Sambuc for (; length > 0; --length) {
288*ebfedea0SLionel Sambuc if (*str >= 0x20 && *str < 0x7f && *str != '%') {
289*ebfedea0SLionel Sambuc putchar(*str);
290*ebfedea0SLionel Sambuc } else if (*str == '\n') {
291*ebfedea0SLionel Sambuc putchar(*str);
292*ebfedea0SLionel Sambuc print_indent(indent);
293*ebfedea0SLionel Sambuc } else {
294*ebfedea0SLionel Sambuc printf("%%%02x", *str);
295*ebfedea0SLionel Sambuc }
296*ebfedea0SLionel Sambuc ++str;
297*ebfedea0SLionel Sambuc }
298*ebfedea0SLionel Sambuc if (o && str[-1] != '\n') {
299*ebfedea0SLionel Sambuc putchar('\n');
300*ebfedea0SLionel Sambuc print_indent(indent);
301*ebfedea0SLionel Sambuc fputs("[no newline]", stdout);
302*ebfedea0SLionel Sambuc } else {
303*ebfedea0SLionel Sambuc print_indent(indent);
304*ebfedea0SLionel Sambuc }
305*ebfedea0SLionel Sambuc printf("<<<<< %s <<<<<\n", name);
306*ebfedea0SLionel Sambuc }
307*ebfedea0SLionel Sambuc
308*ebfedea0SLionel Sambuc /* return the number of bits in the public key */
309*ebfedea0SLionel Sambuc static int
numkeybits(const pgp_pubkey_t * pubkey)310*ebfedea0SLionel Sambuc numkeybits(const pgp_pubkey_t *pubkey)
311*ebfedea0SLionel Sambuc {
312*ebfedea0SLionel Sambuc switch(pubkey->alg) {
313*ebfedea0SLionel Sambuc case PGP_PKA_RSA:
314*ebfedea0SLionel Sambuc case PGP_PKA_RSA_ENCRYPT_ONLY:
315*ebfedea0SLionel Sambuc case PGP_PKA_RSA_SIGN_ONLY:
316*ebfedea0SLionel Sambuc return BN_num_bytes(pubkey->key.rsa.n) * 8;
317*ebfedea0SLionel Sambuc case PGP_PKA_DSA:
318*ebfedea0SLionel Sambuc switch(BN_num_bytes(pubkey->key.dsa.q)) {
319*ebfedea0SLionel Sambuc case 20:
320*ebfedea0SLionel Sambuc return 1024;
321*ebfedea0SLionel Sambuc case 28:
322*ebfedea0SLionel Sambuc return 2048;
323*ebfedea0SLionel Sambuc case 32:
324*ebfedea0SLionel Sambuc return 3072;
325*ebfedea0SLionel Sambuc default:
326*ebfedea0SLionel Sambuc return 0;
327*ebfedea0SLionel Sambuc }
328*ebfedea0SLionel Sambuc case PGP_PKA_ELGAMAL:
329*ebfedea0SLionel Sambuc return BN_num_bytes(pubkey->key.elgamal.y) * 8;
330*ebfedea0SLionel Sambuc default:
331*ebfedea0SLionel Sambuc return -1;
332*ebfedea0SLionel Sambuc }
333*ebfedea0SLionel Sambuc }
334*ebfedea0SLionel Sambuc
335*ebfedea0SLionel Sambuc /* return the hexdump as a string */
336*ebfedea0SLionel Sambuc static char *
strhexdump(char * dest,const uint8_t * src,size_t length,const char * sep)337*ebfedea0SLionel Sambuc strhexdump(char *dest, const uint8_t *src, size_t length, const char *sep)
338*ebfedea0SLionel Sambuc {
339*ebfedea0SLionel Sambuc unsigned i;
340*ebfedea0SLionel Sambuc int n;
341*ebfedea0SLionel Sambuc
342*ebfedea0SLionel Sambuc for (n = 0, i = 0 ; i < length ; i += 2) {
343*ebfedea0SLionel Sambuc n += snprintf(&dest[n], 3, "%02x", *src++);
344*ebfedea0SLionel Sambuc n += snprintf(&dest[n], 10, "%02x%s", *src++, sep);
345*ebfedea0SLionel Sambuc }
346*ebfedea0SLionel Sambuc return dest;
347*ebfedea0SLionel Sambuc }
348*ebfedea0SLionel Sambuc
349*ebfedea0SLionel Sambuc /* return the time as a string */
350*ebfedea0SLionel Sambuc static char *
ptimestr(char * dest,size_t size,time_t t)351*ebfedea0SLionel Sambuc ptimestr(char *dest, size_t size, time_t t)
352*ebfedea0SLionel Sambuc {
353*ebfedea0SLionel Sambuc struct tm *tm;
354*ebfedea0SLionel Sambuc
355*ebfedea0SLionel Sambuc tm = gmtime(&t);
356*ebfedea0SLionel Sambuc (void) snprintf(dest, size, "%04d-%02d-%02d",
357*ebfedea0SLionel Sambuc tm->tm_year + 1900,
358*ebfedea0SLionel Sambuc tm->tm_mon + 1,
359*ebfedea0SLionel Sambuc tm->tm_mday);
360*ebfedea0SLionel Sambuc return dest;
361*ebfedea0SLionel Sambuc }
362*ebfedea0SLionel Sambuc
363*ebfedea0SLionel Sambuc /* print the sub key binding signature info */
364*ebfedea0SLionel Sambuc static int
psubkeybinding(char * buf,size_t size,const pgp_key_t * key,const char * expired)365*ebfedea0SLionel Sambuc psubkeybinding(char *buf, size_t size, const pgp_key_t *key, const char *expired)
366*ebfedea0SLionel Sambuc {
367*ebfedea0SLionel Sambuc char keyid[512];
368*ebfedea0SLionel Sambuc char t[32];
369*ebfedea0SLionel Sambuc
370*ebfedea0SLionel Sambuc return snprintf(buf, size, "encryption %d/%s %s %s %s\n",
371*ebfedea0SLionel Sambuc numkeybits(&key->enckey),
372*ebfedea0SLionel Sambuc pgp_show_pka(key->enckey.alg),
373*ebfedea0SLionel Sambuc strhexdump(keyid, key->encid, PGP_KEY_ID_SIZE, ""),
374*ebfedea0SLionel Sambuc ptimestr(t, sizeof(t), key->enckey.birthtime),
375*ebfedea0SLionel Sambuc expired);
376*ebfedea0SLionel Sambuc }
377*ebfedea0SLionel Sambuc
378*ebfedea0SLionel Sambuc static int
isrevoked(const pgp_key_t * key,unsigned uid)379*ebfedea0SLionel Sambuc isrevoked(const pgp_key_t *key, unsigned uid)
380*ebfedea0SLionel Sambuc {
381*ebfedea0SLionel Sambuc unsigned r;
382*ebfedea0SLionel Sambuc
383*ebfedea0SLionel Sambuc for (r = 0 ; r < key->revokec ; r++) {
384*ebfedea0SLionel Sambuc if (key->revokes[r].uid == uid) {
385*ebfedea0SLionel Sambuc return r;
386*ebfedea0SLionel Sambuc }
387*ebfedea0SLionel Sambuc }
388*ebfedea0SLionel Sambuc return -1;
389*ebfedea0SLionel Sambuc }
390*ebfedea0SLionel Sambuc
391*ebfedea0SLionel Sambuc #ifndef KB
392*ebfedea0SLionel Sambuc #define KB(x) ((x) * 1024)
393*ebfedea0SLionel Sambuc #endif
394*ebfedea0SLionel Sambuc
395*ebfedea0SLionel Sambuc /* print into a string (malloc'ed) the pubkeydata */
396*ebfedea0SLionel Sambuc int
pgp_sprint_keydata(pgp_io_t * io,const pgp_keyring_t * keyring,const pgp_key_t * key,char ** buf,const char * header,const pgp_pubkey_t * pubkey,const int psigs)397*ebfedea0SLionel Sambuc pgp_sprint_keydata(pgp_io_t *io, const pgp_keyring_t *keyring,
398*ebfedea0SLionel Sambuc const pgp_key_t *key, char **buf, const char *header,
399*ebfedea0SLionel Sambuc const pgp_pubkey_t *pubkey, const int psigs)
400*ebfedea0SLionel Sambuc {
401*ebfedea0SLionel Sambuc const pgp_key_t *trustkey;
402*ebfedea0SLionel Sambuc unsigned from;
403*ebfedea0SLionel Sambuc unsigned i;
404*ebfedea0SLionel Sambuc unsigned j;
405*ebfedea0SLionel Sambuc time_t now;
406*ebfedea0SLionel Sambuc char uidbuf[KB(128)];
407*ebfedea0SLionel Sambuc char keyid[PGP_KEY_ID_SIZE * 3];
408*ebfedea0SLionel Sambuc char fp[(PGP_FINGERPRINT_SIZE * 3) + 1];
409*ebfedea0SLionel Sambuc char expired[128];
410*ebfedea0SLionel Sambuc char t[32];
411*ebfedea0SLionel Sambuc int cc;
412*ebfedea0SLionel Sambuc int n;
413*ebfedea0SLionel Sambuc int r;
414*ebfedea0SLionel Sambuc
415*ebfedea0SLionel Sambuc if (key == NULL || key->revoked) {
416*ebfedea0SLionel Sambuc return -1;
417*ebfedea0SLionel Sambuc }
418*ebfedea0SLionel Sambuc now = time(NULL);
419*ebfedea0SLionel Sambuc if (pubkey->duration > 0) {
420*ebfedea0SLionel Sambuc cc = snprintf(expired, sizeof(expired),
421*ebfedea0SLionel Sambuc (pubkey->birthtime + pubkey->duration < now) ?
422*ebfedea0SLionel Sambuc "[EXPIRED " : "[EXPIRES ");
423*ebfedea0SLionel Sambuc ptimestr(&expired[cc], sizeof(expired) - cc,
424*ebfedea0SLionel Sambuc pubkey->birthtime + pubkey->duration);
425*ebfedea0SLionel Sambuc cc += 10;
426*ebfedea0SLionel Sambuc cc += snprintf(&expired[cc], sizeof(expired) - cc, "]");
427*ebfedea0SLionel Sambuc } else {
428*ebfedea0SLionel Sambuc expired[0] = 0x0;
429*ebfedea0SLionel Sambuc }
430*ebfedea0SLionel Sambuc for (i = 0, n = 0; i < key->uidc; i++) {
431*ebfedea0SLionel Sambuc if ((r = isrevoked(key, i)) >= 0 &&
432*ebfedea0SLionel Sambuc key->revokes[r].code == PGP_REVOCATION_COMPROMISED) {
433*ebfedea0SLionel Sambuc continue;
434*ebfedea0SLionel Sambuc }
435*ebfedea0SLionel Sambuc n += snprintf(&uidbuf[n], sizeof(uidbuf) - n, "uid%s%s%s\n",
436*ebfedea0SLionel Sambuc (psigs) ? " " : " ",
437*ebfedea0SLionel Sambuc key->uids[i],
438*ebfedea0SLionel Sambuc (isrevoked(key, i) >= 0) ? " [REVOKED]" : "");
439*ebfedea0SLionel Sambuc for (j = 0 ; j < key->subsigc ; j++) {
440*ebfedea0SLionel Sambuc if (psigs) {
441*ebfedea0SLionel Sambuc if (key->subsigs[j].uid != i) {
442*ebfedea0SLionel Sambuc continue;
443*ebfedea0SLionel Sambuc }
444*ebfedea0SLionel Sambuc } else {
445*ebfedea0SLionel Sambuc if (!(key->subsigs[j].sig.info.version == 4 &&
446*ebfedea0SLionel Sambuc key->subsigs[j].sig.info.type == PGP_SIG_SUBKEY &&
447*ebfedea0SLionel Sambuc i == key->uidc - 1)) {
448*ebfedea0SLionel Sambuc continue;
449*ebfedea0SLionel Sambuc }
450*ebfedea0SLionel Sambuc }
451*ebfedea0SLionel Sambuc from = 0;
452*ebfedea0SLionel Sambuc trustkey = pgp_getkeybyid(io, keyring, key->subsigs[j].sig.info.signer_id, &from, NULL);
453*ebfedea0SLionel Sambuc if (key->subsigs[j].sig.info.version == 4 &&
454*ebfedea0SLionel Sambuc key->subsigs[j].sig.info.type == PGP_SIG_SUBKEY) {
455*ebfedea0SLionel Sambuc psubkeybinding(&uidbuf[n], sizeof(uidbuf) - n, key, expired);
456*ebfedea0SLionel Sambuc } else {
457*ebfedea0SLionel Sambuc n += snprintf(&uidbuf[n], sizeof(uidbuf) - n,
458*ebfedea0SLionel Sambuc "sig %s %s %s\n",
459*ebfedea0SLionel Sambuc strhexdump(keyid, key->subsigs[j].sig.info.signer_id, PGP_KEY_ID_SIZE, ""),
460*ebfedea0SLionel Sambuc ptimestr(t, sizeof(t), key->subsigs[j].sig.info.birthtime),
461*ebfedea0SLionel Sambuc (trustkey) ? (char *)trustkey->uids[trustkey->uid0] : "[unknown]");
462*ebfedea0SLionel Sambuc }
463*ebfedea0SLionel Sambuc }
464*ebfedea0SLionel Sambuc }
465*ebfedea0SLionel Sambuc return pgp_asprintf(buf, "%s %d/%s %s %s %s\nKey fingerprint: %s\n%s",
466*ebfedea0SLionel Sambuc header,
467*ebfedea0SLionel Sambuc numkeybits(pubkey),
468*ebfedea0SLionel Sambuc pgp_show_pka(pubkey->alg),
469*ebfedea0SLionel Sambuc strhexdump(keyid, key->sigid, PGP_KEY_ID_SIZE, ""),
470*ebfedea0SLionel Sambuc ptimestr(t, sizeof(t), pubkey->birthtime),
471*ebfedea0SLionel Sambuc expired,
472*ebfedea0SLionel Sambuc strhexdump(fp, key->sigfingerprint.fingerprint, key->sigfingerprint.length, " "),
473*ebfedea0SLionel Sambuc uidbuf);
474*ebfedea0SLionel Sambuc }
475*ebfedea0SLionel Sambuc
476*ebfedea0SLionel Sambuc /* return the key info as a JSON encoded string */
477*ebfedea0SLionel Sambuc int
pgp_sprint_mj(pgp_io_t * io,const pgp_keyring_t * keyring,const pgp_key_t * key,mj_t * keyjson,const char * header,const pgp_pubkey_t * pubkey,const int psigs)478*ebfedea0SLionel Sambuc pgp_sprint_mj(pgp_io_t *io, const pgp_keyring_t *keyring,
479*ebfedea0SLionel Sambuc const pgp_key_t *key, mj_t *keyjson, const char *header,
480*ebfedea0SLionel Sambuc const pgp_pubkey_t *pubkey, const int psigs)
481*ebfedea0SLionel Sambuc {
482*ebfedea0SLionel Sambuc const pgp_key_t *trustkey;
483*ebfedea0SLionel Sambuc unsigned from;
484*ebfedea0SLionel Sambuc unsigned i;
485*ebfedea0SLionel Sambuc unsigned j;
486*ebfedea0SLionel Sambuc mj_t sub_obj;
487*ebfedea0SLionel Sambuc char keyid[PGP_KEY_ID_SIZE * 3];
488*ebfedea0SLionel Sambuc char fp[(PGP_FINGERPRINT_SIZE * 3) + 1];
489*ebfedea0SLionel Sambuc int r;
490*ebfedea0SLionel Sambuc
491*ebfedea0SLionel Sambuc if (key == NULL || key->revoked) {
492*ebfedea0SLionel Sambuc return -1;
493*ebfedea0SLionel Sambuc }
494*ebfedea0SLionel Sambuc (void) memset(keyjson, 0x0, sizeof(*keyjson));
495*ebfedea0SLionel Sambuc mj_create(keyjson, "object");
496*ebfedea0SLionel Sambuc mj_append_field(keyjson, "header", "string", header, -1);
497*ebfedea0SLionel Sambuc mj_append_field(keyjson, "key bits", "integer", (int64_t) numkeybits(pubkey));
498*ebfedea0SLionel Sambuc mj_append_field(keyjson, "pka", "string", pgp_show_pka(pubkey->alg), -1);
499*ebfedea0SLionel Sambuc mj_append_field(keyjson, "key id", "string", strhexdump(keyid, key->sigid, PGP_KEY_ID_SIZE, ""), -1);
500*ebfedea0SLionel Sambuc mj_append_field(keyjson, "fingerprint", "string",
501*ebfedea0SLionel Sambuc strhexdump(fp, key->sigfingerprint.fingerprint, key->sigfingerprint.length, " "), -1);
502*ebfedea0SLionel Sambuc mj_append_field(keyjson, "birthtime", "integer", pubkey->birthtime);
503*ebfedea0SLionel Sambuc mj_append_field(keyjson, "duration", "integer", pubkey->duration);
504*ebfedea0SLionel Sambuc for (i = 0; i < key->uidc; i++) {
505*ebfedea0SLionel Sambuc if ((r = isrevoked(key, i)) >= 0 &&
506*ebfedea0SLionel Sambuc key->revokes[r].code == PGP_REVOCATION_COMPROMISED) {
507*ebfedea0SLionel Sambuc continue;
508*ebfedea0SLionel Sambuc }
509*ebfedea0SLionel Sambuc (void) memset(&sub_obj, 0x0, sizeof(sub_obj));
510*ebfedea0SLionel Sambuc mj_create(&sub_obj, "array");
511*ebfedea0SLionel Sambuc mj_append(&sub_obj, "string", key->uids[i], -1);
512*ebfedea0SLionel Sambuc mj_append(&sub_obj, "string", (r >= 0) ? "[REVOKED]" : "", -1);
513*ebfedea0SLionel Sambuc mj_append_field(keyjson, "uid", "array", &sub_obj);
514*ebfedea0SLionel Sambuc mj_delete(&sub_obj);
515*ebfedea0SLionel Sambuc for (j = 0 ; j < key->subsigc ; j++) {
516*ebfedea0SLionel Sambuc if (psigs) {
517*ebfedea0SLionel Sambuc if (key->subsigs[j].uid != i) {
518*ebfedea0SLionel Sambuc continue;
519*ebfedea0SLionel Sambuc }
520*ebfedea0SLionel Sambuc } else {
521*ebfedea0SLionel Sambuc if (!(key->subsigs[j].sig.info.version == 4 &&
522*ebfedea0SLionel Sambuc key->subsigs[j].sig.info.type == PGP_SIG_SUBKEY &&
523*ebfedea0SLionel Sambuc i == key->uidc - 1)) {
524*ebfedea0SLionel Sambuc continue;
525*ebfedea0SLionel Sambuc }
526*ebfedea0SLionel Sambuc }
527*ebfedea0SLionel Sambuc (void) memset(&sub_obj, 0x0, sizeof(sub_obj));
528*ebfedea0SLionel Sambuc mj_create(&sub_obj, "array");
529*ebfedea0SLionel Sambuc if (key->subsigs[j].sig.info.version == 4 &&
530*ebfedea0SLionel Sambuc key->subsigs[j].sig.info.type == PGP_SIG_SUBKEY) {
531*ebfedea0SLionel Sambuc mj_append(&sub_obj, "integer", (int64_t)numkeybits(&key->enckey));
532*ebfedea0SLionel Sambuc mj_append(&sub_obj, "string",
533*ebfedea0SLionel Sambuc (const char *)pgp_show_pka(key->enckey.alg), -1);
534*ebfedea0SLionel Sambuc mj_append(&sub_obj, "string",
535*ebfedea0SLionel Sambuc strhexdump(keyid, key->encid, PGP_KEY_ID_SIZE, ""), -1);
536*ebfedea0SLionel Sambuc mj_append(&sub_obj, "integer", (int64_t)key->enckey.birthtime);
537*ebfedea0SLionel Sambuc mj_append_field(keyjson, "encryption", "array", &sub_obj);
538*ebfedea0SLionel Sambuc mj_delete(&sub_obj);
539*ebfedea0SLionel Sambuc } else {
540*ebfedea0SLionel Sambuc mj_append(&sub_obj, "string",
541*ebfedea0SLionel Sambuc strhexdump(keyid, key->subsigs[j].sig.info.signer_id, PGP_KEY_ID_SIZE, ""), -1);
542*ebfedea0SLionel Sambuc mj_append(&sub_obj, "integer",
543*ebfedea0SLionel Sambuc (int64_t)(key->subsigs[j].sig.info.birthtime));
544*ebfedea0SLionel Sambuc from = 0;
545*ebfedea0SLionel Sambuc trustkey = pgp_getkeybyid(io, keyring, key->subsigs[j].sig.info.signer_id, &from, NULL);
546*ebfedea0SLionel Sambuc mj_append(&sub_obj, "string",
547*ebfedea0SLionel Sambuc (trustkey) ? (char *)trustkey->uids[trustkey->uid0] : "[unknown]", -1);
548*ebfedea0SLionel Sambuc mj_append_field(keyjson, "sig", "array", &sub_obj);
549*ebfedea0SLionel Sambuc mj_delete(&sub_obj);
550*ebfedea0SLionel Sambuc }
551*ebfedea0SLionel Sambuc }
552*ebfedea0SLionel Sambuc }
553*ebfedea0SLionel Sambuc if (pgp_get_debug_level(__FILE__)) {
554*ebfedea0SLionel Sambuc char *buf;
555*ebfedea0SLionel Sambuc
556*ebfedea0SLionel Sambuc mj_asprint(&buf, keyjson, 1);
557*ebfedea0SLionel Sambuc (void) fprintf(stderr, "pgp_sprint_mj: '%s'\n", buf);
558*ebfedea0SLionel Sambuc free(buf);
559*ebfedea0SLionel Sambuc }
560*ebfedea0SLionel Sambuc return 1;
561*ebfedea0SLionel Sambuc }
562*ebfedea0SLionel Sambuc
563*ebfedea0SLionel Sambuc int
pgp_hkp_sprint_keydata(pgp_io_t * io,const pgp_keyring_t * keyring,const pgp_key_t * key,char ** buf,const pgp_pubkey_t * pubkey,const int psigs)564*ebfedea0SLionel Sambuc pgp_hkp_sprint_keydata(pgp_io_t *io, const pgp_keyring_t *keyring,
565*ebfedea0SLionel Sambuc const pgp_key_t *key, char **buf,
566*ebfedea0SLionel Sambuc const pgp_pubkey_t *pubkey, const int psigs)
567*ebfedea0SLionel Sambuc {
568*ebfedea0SLionel Sambuc const pgp_key_t *trustkey;
569*ebfedea0SLionel Sambuc unsigned from;
570*ebfedea0SLionel Sambuc unsigned i;
571*ebfedea0SLionel Sambuc unsigned j;
572*ebfedea0SLionel Sambuc char keyid[PGP_KEY_ID_SIZE * 3];
573*ebfedea0SLionel Sambuc char uidbuf[KB(128)];
574*ebfedea0SLionel Sambuc char fp[(PGP_FINGERPRINT_SIZE * 3) + 1];
575*ebfedea0SLionel Sambuc int n;
576*ebfedea0SLionel Sambuc
577*ebfedea0SLionel Sambuc if (key->revoked) {
578*ebfedea0SLionel Sambuc return -1;
579*ebfedea0SLionel Sambuc }
580*ebfedea0SLionel Sambuc for (i = 0, n = 0; i < key->uidc; i++) {
581*ebfedea0SLionel Sambuc n += snprintf(&uidbuf[n], sizeof(uidbuf) - n,
582*ebfedea0SLionel Sambuc "uid:%lld:%lld:%s\n",
583*ebfedea0SLionel Sambuc (long long)pubkey->birthtime,
584*ebfedea0SLionel Sambuc (long long)pubkey->duration,
585*ebfedea0SLionel Sambuc key->uids[i]);
586*ebfedea0SLionel Sambuc for (j = 0 ; j < key->subsigc ; j++) {
587*ebfedea0SLionel Sambuc if (psigs) {
588*ebfedea0SLionel Sambuc if (key->subsigs[j].uid != i) {
589*ebfedea0SLionel Sambuc continue;
590*ebfedea0SLionel Sambuc }
591*ebfedea0SLionel Sambuc } else {
592*ebfedea0SLionel Sambuc if (!(key->subsigs[j].sig.info.version == 4 &&
593*ebfedea0SLionel Sambuc key->subsigs[j].sig.info.type == PGP_SIG_SUBKEY &&
594*ebfedea0SLionel Sambuc i == key->uidc - 1)) {
595*ebfedea0SLionel Sambuc continue;
596*ebfedea0SLionel Sambuc }
597*ebfedea0SLionel Sambuc }
598*ebfedea0SLionel Sambuc from = 0;
599*ebfedea0SLionel Sambuc trustkey = pgp_getkeybyid(io, keyring, key->subsigs[j].sig.info.signer_id, &from, NULL);
600*ebfedea0SLionel Sambuc if (key->subsigs[j].sig.info.version == 4 &&
601*ebfedea0SLionel Sambuc key->subsigs[j].sig.info.type == PGP_SIG_SUBKEY) {
602*ebfedea0SLionel Sambuc n += snprintf(&uidbuf[n], sizeof(uidbuf) - n, "sub:%d:%d:%s:%lld:%lld\n",
603*ebfedea0SLionel Sambuc numkeybits(pubkey),
604*ebfedea0SLionel Sambuc key->subsigs[j].sig.info.key_alg,
605*ebfedea0SLionel Sambuc strhexdump(keyid, key->subsigs[j].sig.info.signer_id, PGP_KEY_ID_SIZE, ""),
606*ebfedea0SLionel Sambuc (long long)(key->subsigs[j].sig.info.birthtime),
607*ebfedea0SLionel Sambuc (long long)pubkey->duration);
608*ebfedea0SLionel Sambuc } else {
609*ebfedea0SLionel Sambuc n += snprintf(&uidbuf[n], sizeof(uidbuf) - n,
610*ebfedea0SLionel Sambuc "sig:%s:%lld:%s\n",
611*ebfedea0SLionel Sambuc strhexdump(keyid, key->subsigs[j].sig.info.signer_id, PGP_KEY_ID_SIZE, ""),
612*ebfedea0SLionel Sambuc (long long)key->subsigs[j].sig.info.birthtime,
613*ebfedea0SLionel Sambuc (trustkey) ? (char *)trustkey->uids[trustkey->uid0] : "");
614*ebfedea0SLionel Sambuc }
615*ebfedea0SLionel Sambuc }
616*ebfedea0SLionel Sambuc }
617*ebfedea0SLionel Sambuc return pgp_asprintf(buf, "pub:%s:%d:%d:%lld:%lld\n%s",
618*ebfedea0SLionel Sambuc strhexdump(fp, key->sigfingerprint.fingerprint, PGP_FINGERPRINT_SIZE, ""),
619*ebfedea0SLionel Sambuc pubkey->alg,
620*ebfedea0SLionel Sambuc numkeybits(pubkey),
621*ebfedea0SLionel Sambuc (long long)pubkey->birthtime,
622*ebfedea0SLionel Sambuc (long long)pubkey->duration,
623*ebfedea0SLionel Sambuc uidbuf);
624*ebfedea0SLionel Sambuc }
625*ebfedea0SLionel Sambuc
626*ebfedea0SLionel Sambuc /* print the key data for a pub or sec key */
627*ebfedea0SLionel Sambuc void
pgp_print_keydata(pgp_io_t * io,const pgp_keyring_t * keyring,const pgp_key_t * key,const char * header,const pgp_pubkey_t * pubkey,const int psigs)628*ebfedea0SLionel Sambuc pgp_print_keydata(pgp_io_t *io, const pgp_keyring_t *keyring,
629*ebfedea0SLionel Sambuc const pgp_key_t *key, const char *header,
630*ebfedea0SLionel Sambuc const pgp_pubkey_t *pubkey, const int psigs)
631*ebfedea0SLionel Sambuc {
632*ebfedea0SLionel Sambuc char *cp;
633*ebfedea0SLionel Sambuc
634*ebfedea0SLionel Sambuc if (pgp_sprint_keydata(io, keyring, key, &cp, header, pubkey, psigs) >= 0) {
635*ebfedea0SLionel Sambuc (void) fprintf(io->res, "%s", cp);
636*ebfedea0SLionel Sambuc free(cp);
637*ebfedea0SLionel Sambuc }
638*ebfedea0SLionel Sambuc }
639*ebfedea0SLionel Sambuc
640*ebfedea0SLionel Sambuc /**
641*ebfedea0SLionel Sambuc \ingroup Core_Print
642*ebfedea0SLionel Sambuc \param pubkey
643*ebfedea0SLionel Sambuc */
644*ebfedea0SLionel Sambuc void
pgp_print_pubkey(const pgp_pubkey_t * pubkey)645*ebfedea0SLionel Sambuc pgp_print_pubkey(const pgp_pubkey_t *pubkey)
646*ebfedea0SLionel Sambuc {
647*ebfedea0SLionel Sambuc printf("------- PUBLIC KEY ------\n");
648*ebfedea0SLionel Sambuc print_uint(0, "Version", (unsigned)pubkey->version);
649*ebfedea0SLionel Sambuc print_time(0, "Creation Time", pubkey->birthtime);
650*ebfedea0SLionel Sambuc if (pubkey->version == PGP_V3) {
651*ebfedea0SLionel Sambuc print_uint(0, "Days Valid", pubkey->days_valid);
652*ebfedea0SLionel Sambuc }
653*ebfedea0SLionel Sambuc print_string_and_value(0, "Algorithm", pgp_show_pka(pubkey->alg),
654*ebfedea0SLionel Sambuc pubkey->alg);
655*ebfedea0SLionel Sambuc switch (pubkey->alg) {
656*ebfedea0SLionel Sambuc case PGP_PKA_DSA:
657*ebfedea0SLionel Sambuc print_bn(0, "p", pubkey->key.dsa.p);
658*ebfedea0SLionel Sambuc print_bn(0, "q", pubkey->key.dsa.q);
659*ebfedea0SLionel Sambuc print_bn(0, "g", pubkey->key.dsa.g);
660*ebfedea0SLionel Sambuc print_bn(0, "y", pubkey->key.dsa.y);
661*ebfedea0SLionel Sambuc break;
662*ebfedea0SLionel Sambuc
663*ebfedea0SLionel Sambuc case PGP_PKA_RSA:
664*ebfedea0SLionel Sambuc case PGP_PKA_RSA_ENCRYPT_ONLY:
665*ebfedea0SLionel Sambuc case PGP_PKA_RSA_SIGN_ONLY:
666*ebfedea0SLionel Sambuc print_bn(0, "n", pubkey->key.rsa.n);
667*ebfedea0SLionel Sambuc print_bn(0, "e", pubkey->key.rsa.e);
668*ebfedea0SLionel Sambuc break;
669*ebfedea0SLionel Sambuc
670*ebfedea0SLionel Sambuc case PGP_PKA_ELGAMAL:
671*ebfedea0SLionel Sambuc case PGP_PKA_ELGAMAL_ENCRYPT_OR_SIGN:
672*ebfedea0SLionel Sambuc print_bn(0, "p", pubkey->key.elgamal.p);
673*ebfedea0SLionel Sambuc print_bn(0, "g", pubkey->key.elgamal.g);
674*ebfedea0SLionel Sambuc print_bn(0, "y", pubkey->key.elgamal.y);
675*ebfedea0SLionel Sambuc break;
676*ebfedea0SLionel Sambuc
677*ebfedea0SLionel Sambuc default:
678*ebfedea0SLionel Sambuc (void) fprintf(stderr,
679*ebfedea0SLionel Sambuc "pgp_print_pubkey: Unusual algorithm\n");
680*ebfedea0SLionel Sambuc }
681*ebfedea0SLionel Sambuc
682*ebfedea0SLionel Sambuc printf("------- end of PUBLIC KEY ------\n");
683*ebfedea0SLionel Sambuc }
684*ebfedea0SLionel Sambuc
685*ebfedea0SLionel Sambuc int
pgp_sprint_pubkey(const pgp_key_t * key,char * out,size_t outsize)686*ebfedea0SLionel Sambuc pgp_sprint_pubkey(const pgp_key_t *key, char *out, size_t outsize)
687*ebfedea0SLionel Sambuc {
688*ebfedea0SLionel Sambuc char fp[(PGP_FINGERPRINT_SIZE * 3) + 1];
689*ebfedea0SLionel Sambuc int cc;
690*ebfedea0SLionel Sambuc
691*ebfedea0SLionel Sambuc cc = snprintf(out, outsize, "key=%s\nname=%s\ncreation=%lld\nexpiry=%lld\nversion=%d\nalg=%d\n",
692*ebfedea0SLionel Sambuc strhexdump(fp, key->sigfingerprint.fingerprint, PGP_FINGERPRINT_SIZE, ""),
693*ebfedea0SLionel Sambuc key->uids[key->uid0],
694*ebfedea0SLionel Sambuc (long long)key->key.pubkey.birthtime,
695*ebfedea0SLionel Sambuc (long long)key->key.pubkey.days_valid,
696*ebfedea0SLionel Sambuc key->key.pubkey.version,
697*ebfedea0SLionel Sambuc key->key.pubkey.alg);
698*ebfedea0SLionel Sambuc switch (key->key.pubkey.alg) {
699*ebfedea0SLionel Sambuc case PGP_PKA_DSA:
700*ebfedea0SLionel Sambuc cc += snprintf(&out[cc], outsize - cc,
701*ebfedea0SLionel Sambuc "p=%s\nq=%s\ng=%s\ny=%s\n",
702*ebfedea0SLionel Sambuc BN_bn2hex(key->key.pubkey.key.dsa.p),
703*ebfedea0SLionel Sambuc BN_bn2hex(key->key.pubkey.key.dsa.q),
704*ebfedea0SLionel Sambuc BN_bn2hex(key->key.pubkey.key.dsa.g),
705*ebfedea0SLionel Sambuc BN_bn2hex(key->key.pubkey.key.dsa.y));
706*ebfedea0SLionel Sambuc break;
707*ebfedea0SLionel Sambuc case PGP_PKA_RSA:
708*ebfedea0SLionel Sambuc case PGP_PKA_RSA_ENCRYPT_ONLY:
709*ebfedea0SLionel Sambuc case PGP_PKA_RSA_SIGN_ONLY:
710*ebfedea0SLionel Sambuc cc += snprintf(&out[cc], outsize - cc,
711*ebfedea0SLionel Sambuc "n=%s\ne=%s\n",
712*ebfedea0SLionel Sambuc BN_bn2hex(key->key.pubkey.key.rsa.n),
713*ebfedea0SLionel Sambuc BN_bn2hex(key->key.pubkey.key.rsa.e));
714*ebfedea0SLionel Sambuc break;
715*ebfedea0SLionel Sambuc case PGP_PKA_ELGAMAL:
716*ebfedea0SLionel Sambuc case PGP_PKA_ELGAMAL_ENCRYPT_OR_SIGN:
717*ebfedea0SLionel Sambuc cc += snprintf(&out[cc], outsize - cc,
718*ebfedea0SLionel Sambuc "p=%s\ng=%s\ny=%s\n",
719*ebfedea0SLionel Sambuc BN_bn2hex(key->key.pubkey.key.elgamal.p),
720*ebfedea0SLionel Sambuc BN_bn2hex(key->key.pubkey.key.elgamal.g),
721*ebfedea0SLionel Sambuc BN_bn2hex(key->key.pubkey.key.elgamal.y));
722*ebfedea0SLionel Sambuc break;
723*ebfedea0SLionel Sambuc default:
724*ebfedea0SLionel Sambuc (void) fprintf(stderr,
725*ebfedea0SLionel Sambuc "pgp_print_pubkey: Unusual algorithm\n");
726*ebfedea0SLionel Sambuc }
727*ebfedea0SLionel Sambuc return cc;
728*ebfedea0SLionel Sambuc }
729*ebfedea0SLionel Sambuc
730*ebfedea0SLionel Sambuc /**
731*ebfedea0SLionel Sambuc \ingroup Core_Print
732*ebfedea0SLionel Sambuc \param type
733*ebfedea0SLionel Sambuc \param seckey
734*ebfedea0SLionel Sambuc */
735*ebfedea0SLionel Sambuc static void
print_seckey_verbose(const pgp_content_enum type,const pgp_seckey_t * seckey)736*ebfedea0SLionel Sambuc print_seckey_verbose(const pgp_content_enum type,
737*ebfedea0SLionel Sambuc const pgp_seckey_t *seckey)
738*ebfedea0SLionel Sambuc {
739*ebfedea0SLionel Sambuc printf("------- SECRET KEY or ENCRYPTED SECRET KEY ------\n");
740*ebfedea0SLionel Sambuc print_tagname(0, (type == PGP_PTAG_CT_SECRET_KEY) ?
741*ebfedea0SLionel Sambuc "SECRET_KEY" :
742*ebfedea0SLionel Sambuc "ENCRYPTED_SECRET_KEY");
743*ebfedea0SLionel Sambuc /* pgp_print_pubkey(key); */
744*ebfedea0SLionel Sambuc printf("S2K Usage: %d\n", seckey->s2k_usage);
745*ebfedea0SLionel Sambuc if (seckey->s2k_usage != PGP_S2KU_NONE) {
746*ebfedea0SLionel Sambuc printf("S2K Specifier: %d\n", seckey->s2k_specifier);
747*ebfedea0SLionel Sambuc printf("Symmetric algorithm: %d (%s)\n", seckey->alg,
748*ebfedea0SLionel Sambuc pgp_show_symm_alg(seckey->alg));
749*ebfedea0SLionel Sambuc printf("Hash algorithm: %d (%s)\n", seckey->hash_alg,
750*ebfedea0SLionel Sambuc pgp_show_hash_alg((uint8_t)seckey->hash_alg));
751*ebfedea0SLionel Sambuc if (seckey->s2k_specifier != PGP_S2KS_SIMPLE) {
752*ebfedea0SLionel Sambuc print_hexdump(0, "Salt", seckey->salt,
753*ebfedea0SLionel Sambuc (unsigned)sizeof(seckey->salt));
754*ebfedea0SLionel Sambuc }
755*ebfedea0SLionel Sambuc if (seckey->s2k_specifier == PGP_S2KS_ITERATED_AND_SALTED) {
756*ebfedea0SLionel Sambuc printf("Octet count: %u\n", seckey->octetc);
757*ebfedea0SLionel Sambuc }
758*ebfedea0SLionel Sambuc print_hexdump(0, "IV", seckey->iv, pgp_block_size(seckey->alg));
759*ebfedea0SLionel Sambuc }
760*ebfedea0SLionel Sambuc /* no more set if encrypted */
761*ebfedea0SLionel Sambuc if (type == PGP_PTAG_CT_ENCRYPTED_SECRET_KEY) {
762*ebfedea0SLionel Sambuc return;
763*ebfedea0SLionel Sambuc }
764*ebfedea0SLionel Sambuc switch (seckey->pubkey.alg) {
765*ebfedea0SLionel Sambuc case PGP_PKA_RSA:
766*ebfedea0SLionel Sambuc print_bn(0, "d", seckey->key.rsa.d);
767*ebfedea0SLionel Sambuc print_bn(0, "p", seckey->key.rsa.p);
768*ebfedea0SLionel Sambuc print_bn(0, "q", seckey->key.rsa.q);
769*ebfedea0SLionel Sambuc print_bn(0, "u", seckey->key.rsa.u);
770*ebfedea0SLionel Sambuc break;
771*ebfedea0SLionel Sambuc
772*ebfedea0SLionel Sambuc case PGP_PKA_DSA:
773*ebfedea0SLionel Sambuc print_bn(0, "x", seckey->key.dsa.x);
774*ebfedea0SLionel Sambuc break;
775*ebfedea0SLionel Sambuc
776*ebfedea0SLionel Sambuc default:
777*ebfedea0SLionel Sambuc (void) fprintf(stderr,
778*ebfedea0SLionel Sambuc "print_seckey_verbose: unusual algorithm\n");
779*ebfedea0SLionel Sambuc }
780*ebfedea0SLionel Sambuc if (seckey->s2k_usage == PGP_S2KU_ENCRYPTED_AND_HASHED) {
781*ebfedea0SLionel Sambuc print_hexdump(0, "Checkhash", seckey->checkhash,
782*ebfedea0SLionel Sambuc PGP_CHECKHASH_SIZE);
783*ebfedea0SLionel Sambuc } else {
784*ebfedea0SLionel Sambuc printf("Checksum: %04x\n", seckey->checksum);
785*ebfedea0SLionel Sambuc }
786*ebfedea0SLionel Sambuc printf("------- end of SECRET KEY or ENCRYPTED SECRET KEY ------\n");
787*ebfedea0SLionel Sambuc }
788*ebfedea0SLionel Sambuc
789*ebfedea0SLionel Sambuc
790*ebfedea0SLionel Sambuc /**
791*ebfedea0SLionel Sambuc \ingroup Core_Print
792*ebfedea0SLionel Sambuc \param tag
793*ebfedea0SLionel Sambuc \param key
794*ebfedea0SLionel Sambuc */
795*ebfedea0SLionel Sambuc static void
print_pk_sesskey(pgp_content_enum tag,const pgp_pk_sesskey_t * key)796*ebfedea0SLionel Sambuc print_pk_sesskey(pgp_content_enum tag,
797*ebfedea0SLionel Sambuc const pgp_pk_sesskey_t * key)
798*ebfedea0SLionel Sambuc {
799*ebfedea0SLionel Sambuc print_tagname(0, (tag == PGP_PTAG_CT_PK_SESSION_KEY) ?
800*ebfedea0SLionel Sambuc "PUBLIC KEY SESSION KEY" :
801*ebfedea0SLionel Sambuc "ENCRYPTED PUBLIC KEY SESSION KEY");
802*ebfedea0SLionel Sambuc printf("Version: %d\n", key->version);
803*ebfedea0SLionel Sambuc print_hexdump(0, "Key ID", key->key_id, (unsigned)sizeof(key->key_id));
804*ebfedea0SLionel Sambuc printf("Algorithm: %d (%s)\n", key->alg,
805*ebfedea0SLionel Sambuc pgp_show_pka(key->alg));
806*ebfedea0SLionel Sambuc switch (key->alg) {
807*ebfedea0SLionel Sambuc case PGP_PKA_RSA:
808*ebfedea0SLionel Sambuc print_bn(0, "encrypted_m", key->params.rsa.encrypted_m);
809*ebfedea0SLionel Sambuc break;
810*ebfedea0SLionel Sambuc
811*ebfedea0SLionel Sambuc case PGP_PKA_ELGAMAL:
812*ebfedea0SLionel Sambuc print_bn(0, "g_to_k", key->params.elgamal.g_to_k);
813*ebfedea0SLionel Sambuc print_bn(0, "encrypted_m", key->params.elgamal.encrypted_m);
814*ebfedea0SLionel Sambuc break;
815*ebfedea0SLionel Sambuc
816*ebfedea0SLionel Sambuc default:
817*ebfedea0SLionel Sambuc (void) fprintf(stderr,
818*ebfedea0SLionel Sambuc "print_pk_sesskey: unusual algorithm\n");
819*ebfedea0SLionel Sambuc }
820*ebfedea0SLionel Sambuc if (tag == PGP_PTAG_CT_PK_SESSION_KEY) {
821*ebfedea0SLionel Sambuc printf("Symmetric algorithm: %d (%s)\n", key->symm_alg,
822*ebfedea0SLionel Sambuc pgp_show_symm_alg(key->symm_alg));
823*ebfedea0SLionel Sambuc print_hexdump(0, "Key", key->key, pgp_key_size(key->symm_alg));
824*ebfedea0SLionel Sambuc printf("Checksum: %04x\n", key->checksum);
825*ebfedea0SLionel Sambuc }
826*ebfedea0SLionel Sambuc }
827*ebfedea0SLionel Sambuc
828*ebfedea0SLionel Sambuc static void
start_subpacket(int * indent,int type)829*ebfedea0SLionel Sambuc start_subpacket(int *indent, int type)
830*ebfedea0SLionel Sambuc {
831*ebfedea0SLionel Sambuc *indent += 1;
832*ebfedea0SLionel Sambuc print_indent(*indent);
833*ebfedea0SLionel Sambuc printf("-- %s (type 0x%02x)\n",
834*ebfedea0SLionel Sambuc pgp_show_ss_type((pgp_content_enum)type),
835*ebfedea0SLionel Sambuc type - PGP_PTAG_SIG_SUBPKT_BASE);
836*ebfedea0SLionel Sambuc }
837*ebfedea0SLionel Sambuc
838*ebfedea0SLionel Sambuc static void
end_subpacket(int * indent)839*ebfedea0SLionel Sambuc end_subpacket(int *indent)
840*ebfedea0SLionel Sambuc {
841*ebfedea0SLionel Sambuc *indent -= 1;
842*ebfedea0SLionel Sambuc }
843*ebfedea0SLionel Sambuc
844*ebfedea0SLionel Sambuc /**
845*ebfedea0SLionel Sambuc \ingroup Core_Print
846*ebfedea0SLionel Sambuc \param contents
847*ebfedea0SLionel Sambuc */
848*ebfedea0SLionel Sambuc int
pgp_print_packet(pgp_printstate_t * print,const pgp_packet_t * pkt)849*ebfedea0SLionel Sambuc pgp_print_packet(pgp_printstate_t *print, const pgp_packet_t *pkt)
850*ebfedea0SLionel Sambuc {
851*ebfedea0SLionel Sambuc const pgp_contents_t *content = &pkt->u;
852*ebfedea0SLionel Sambuc pgp_text_t *text;
853*ebfedea0SLionel Sambuc const char *str;
854*ebfedea0SLionel Sambuc
855*ebfedea0SLionel Sambuc if (print->unarmoured && pkt->tag != PGP_PTAG_CT_UNARMOURED_TEXT) {
856*ebfedea0SLionel Sambuc print->unarmoured = 0;
857*ebfedea0SLionel Sambuc puts("UNARMOURED TEXT ends");
858*ebfedea0SLionel Sambuc }
859*ebfedea0SLionel Sambuc if (pkt->tag == PGP_PARSER_PTAG) {
860*ebfedea0SLionel Sambuc printf("=> PGP_PARSER_PTAG: %s\n",
861*ebfedea0SLionel Sambuc pgp_show_packet_tag((pgp_content_enum)content->ptag.type));
862*ebfedea0SLionel Sambuc } else {
863*ebfedea0SLionel Sambuc printf("=> %s\n", pgp_show_packet_tag(pkt->tag));
864*ebfedea0SLionel Sambuc }
865*ebfedea0SLionel Sambuc
866*ebfedea0SLionel Sambuc switch (pkt->tag) {
867*ebfedea0SLionel Sambuc case PGP_PARSER_ERROR:
868*ebfedea0SLionel Sambuc printf("parse error: %s\n", content->error);
869*ebfedea0SLionel Sambuc break;
870*ebfedea0SLionel Sambuc
871*ebfedea0SLionel Sambuc case PGP_PARSER_ERRCODE:
872*ebfedea0SLionel Sambuc printf("parse error: %s\n",
873*ebfedea0SLionel Sambuc pgp_errcode(content->errcode.errcode));
874*ebfedea0SLionel Sambuc break;
875*ebfedea0SLionel Sambuc
876*ebfedea0SLionel Sambuc case PGP_PARSER_PACKET_END:
877*ebfedea0SLionel Sambuc print_packet_hex(&content->packet);
878*ebfedea0SLionel Sambuc break;
879*ebfedea0SLionel Sambuc
880*ebfedea0SLionel Sambuc case PGP_PARSER_PTAG:
881*ebfedea0SLionel Sambuc if (content->ptag.type == PGP_PTAG_CT_PUBLIC_KEY) {
882*ebfedea0SLionel Sambuc print->indent = 0;
883*ebfedea0SLionel Sambuc printf("\n*** NEXT KEY ***\n");
884*ebfedea0SLionel Sambuc }
885*ebfedea0SLionel Sambuc printf("\n");
886*ebfedea0SLionel Sambuc print_indent(print->indent);
887*ebfedea0SLionel Sambuc printf("==== ptag new_format=%u type=%u length_type=%d"
888*ebfedea0SLionel Sambuc " length=0x%x (%u) position=0x%x (%u)\n",
889*ebfedea0SLionel Sambuc content->ptag.new_format,
890*ebfedea0SLionel Sambuc content->ptag.type, content->ptag.length_type,
891*ebfedea0SLionel Sambuc content->ptag.length, content->ptag.length,
892*ebfedea0SLionel Sambuc content->ptag.position, content->ptag.position);
893*ebfedea0SLionel Sambuc print_tagname(print->indent, pgp_show_packet_tag((pgp_content_enum)content->ptag.type));
894*ebfedea0SLionel Sambuc break;
895*ebfedea0SLionel Sambuc
896*ebfedea0SLionel Sambuc case PGP_PTAG_CT_SE_DATA_HEADER:
897*ebfedea0SLionel Sambuc print_tagname(print->indent, "SYMMETRIC ENCRYPTED DATA");
898*ebfedea0SLionel Sambuc break;
899*ebfedea0SLionel Sambuc
900*ebfedea0SLionel Sambuc case PGP_PTAG_CT_SE_IP_DATA_HEADER:
901*ebfedea0SLionel Sambuc print_tagname(print->indent,
902*ebfedea0SLionel Sambuc "SYMMETRIC ENCRYPTED INTEGRITY PROTECTED DATA HEADER");
903*ebfedea0SLionel Sambuc printf("Version: %d\n", content->se_ip_data_header);
904*ebfedea0SLionel Sambuc break;
905*ebfedea0SLionel Sambuc
906*ebfedea0SLionel Sambuc case PGP_PTAG_CT_SE_IP_DATA_BODY:
907*ebfedea0SLionel Sambuc print_tagname(print->indent,
908*ebfedea0SLionel Sambuc "SYMMETRIC ENCRYPTED INTEGRITY PROTECTED DATA BODY");
909*ebfedea0SLionel Sambuc hexdump(stdout, "data", content->se_data_body.data,
910*ebfedea0SLionel Sambuc content->se_data_body.length);
911*ebfedea0SLionel Sambuc break;
912*ebfedea0SLionel Sambuc
913*ebfedea0SLionel Sambuc case PGP_PTAG_CT_PUBLIC_KEY:
914*ebfedea0SLionel Sambuc case PGP_PTAG_CT_PUBLIC_SUBKEY:
915*ebfedea0SLionel Sambuc print_tagname(print->indent, (pkt->tag == PGP_PTAG_CT_PUBLIC_KEY) ?
916*ebfedea0SLionel Sambuc "PUBLIC KEY" :
917*ebfedea0SLionel Sambuc "PUBLIC SUBKEY");
918*ebfedea0SLionel Sambuc pgp_print_pubkey(&content->pubkey);
919*ebfedea0SLionel Sambuc break;
920*ebfedea0SLionel Sambuc
921*ebfedea0SLionel Sambuc case PGP_PTAG_CT_TRUST:
922*ebfedea0SLionel Sambuc print_tagname(print->indent, "TRUST");
923*ebfedea0SLionel Sambuc print_data(print->indent, "Trust", &content->trust);
924*ebfedea0SLionel Sambuc break;
925*ebfedea0SLionel Sambuc
926*ebfedea0SLionel Sambuc case PGP_PTAG_CT_USER_ID:
927*ebfedea0SLionel Sambuc print_tagname(print->indent, "USER ID");
928*ebfedea0SLionel Sambuc print_utf8_string(print->indent, "userid", content->userid);
929*ebfedea0SLionel Sambuc break;
930*ebfedea0SLionel Sambuc
931*ebfedea0SLionel Sambuc case PGP_PTAG_CT_SIGNATURE:
932*ebfedea0SLionel Sambuc print_tagname(print->indent, "SIGNATURE");
933*ebfedea0SLionel Sambuc print_indent(print->indent);
934*ebfedea0SLionel Sambuc print_uint(print->indent, "Signature Version",
935*ebfedea0SLionel Sambuc (unsigned)content->sig.info.version);
936*ebfedea0SLionel Sambuc if (content->sig.info.birthtime_set) {
937*ebfedea0SLionel Sambuc print_time(print->indent, "Signature Creation Time",
938*ebfedea0SLionel Sambuc content->sig.info.birthtime);
939*ebfedea0SLionel Sambuc }
940*ebfedea0SLionel Sambuc if (content->sig.info.duration_set) {
941*ebfedea0SLionel Sambuc print_uint(print->indent, "Signature Duration",
942*ebfedea0SLionel Sambuc (unsigned)content->sig.info.duration);
943*ebfedea0SLionel Sambuc }
944*ebfedea0SLionel Sambuc
945*ebfedea0SLionel Sambuc print_string_and_value(print->indent, "Signature Type",
946*ebfedea0SLionel Sambuc pgp_show_sig_type(content->sig.info.type),
947*ebfedea0SLionel Sambuc content->sig.info.type);
948*ebfedea0SLionel Sambuc
949*ebfedea0SLionel Sambuc if (content->sig.info.signer_id_set) {
950*ebfedea0SLionel Sambuc hexdump_data(print->indent, "Signer ID",
951*ebfedea0SLionel Sambuc content->sig.info.signer_id,
952*ebfedea0SLionel Sambuc (unsigned)sizeof(content->sig.info.signer_id));
953*ebfedea0SLionel Sambuc }
954*ebfedea0SLionel Sambuc
955*ebfedea0SLionel Sambuc print_string_and_value(print->indent, "Public Key Algorithm",
956*ebfedea0SLionel Sambuc pgp_show_pka(content->sig.info.key_alg),
957*ebfedea0SLionel Sambuc content->sig.info.key_alg);
958*ebfedea0SLionel Sambuc print_string_and_value(print->indent, "Hash Algorithm",
959*ebfedea0SLionel Sambuc pgp_show_hash_alg((uint8_t)
960*ebfedea0SLionel Sambuc content->sig.info.hash_alg),
961*ebfedea0SLionel Sambuc (uint8_t)content->sig.info.hash_alg);
962*ebfedea0SLionel Sambuc print_uint(print->indent, "Hashed data len",
963*ebfedea0SLionel Sambuc (unsigned)content->sig.info.v4_hashlen);
964*ebfedea0SLionel Sambuc print_indent(print->indent);
965*ebfedea0SLionel Sambuc hexdump_data(print->indent, "hash2", &content->sig.hash2[0], 2);
966*ebfedea0SLionel Sambuc switch (content->sig.info.key_alg) {
967*ebfedea0SLionel Sambuc case PGP_PKA_RSA:
968*ebfedea0SLionel Sambuc case PGP_PKA_RSA_SIGN_ONLY:
969*ebfedea0SLionel Sambuc print_bn(print->indent, "sig", content->sig.info.sig.rsa.sig);
970*ebfedea0SLionel Sambuc break;
971*ebfedea0SLionel Sambuc
972*ebfedea0SLionel Sambuc case PGP_PKA_DSA:
973*ebfedea0SLionel Sambuc print_bn(print->indent, "r", content->sig.info.sig.dsa.r);
974*ebfedea0SLionel Sambuc print_bn(print->indent, "s", content->sig.info.sig.dsa.s);
975*ebfedea0SLionel Sambuc break;
976*ebfedea0SLionel Sambuc
977*ebfedea0SLionel Sambuc case PGP_PKA_ELGAMAL_ENCRYPT_OR_SIGN:
978*ebfedea0SLionel Sambuc print_bn(print->indent, "r", content->sig.info.sig.elgamal.r);
979*ebfedea0SLionel Sambuc print_bn(print->indent, "s", content->sig.info.sig.elgamal.s);
980*ebfedea0SLionel Sambuc break;
981*ebfedea0SLionel Sambuc
982*ebfedea0SLionel Sambuc default:
983*ebfedea0SLionel Sambuc (void) fprintf(stderr,
984*ebfedea0SLionel Sambuc "pgp_print_packet: Unusual algorithm\n");
985*ebfedea0SLionel Sambuc return 0;
986*ebfedea0SLionel Sambuc }
987*ebfedea0SLionel Sambuc
988*ebfedea0SLionel Sambuc if (content->sig.hash)
989*ebfedea0SLionel Sambuc printf("data hash is set\n");
990*ebfedea0SLionel Sambuc
991*ebfedea0SLionel Sambuc break;
992*ebfedea0SLionel Sambuc
993*ebfedea0SLionel Sambuc case PGP_PTAG_CT_COMPRESSED:
994*ebfedea0SLionel Sambuc print_tagname(print->indent, "COMPRESSED");
995*ebfedea0SLionel Sambuc print_uint(print->indent, "Compressed Data Type",
996*ebfedea0SLionel Sambuc (unsigned)content->compressed);
997*ebfedea0SLionel Sambuc break;
998*ebfedea0SLionel Sambuc
999*ebfedea0SLionel Sambuc case PGP_PTAG_CT_1_PASS_SIG:
1000*ebfedea0SLionel Sambuc print_tagname(print->indent, "ONE PASS SIGNATURE");
1001*ebfedea0SLionel Sambuc
1002*ebfedea0SLionel Sambuc print_uint(print->indent, "Version", (unsigned)content->one_pass_sig.version);
1003*ebfedea0SLionel Sambuc print_string_and_value(print->indent, "Signature Type",
1004*ebfedea0SLionel Sambuc pgp_show_sig_type(content->one_pass_sig.sig_type),
1005*ebfedea0SLionel Sambuc content->one_pass_sig.sig_type);
1006*ebfedea0SLionel Sambuc print_string_and_value(print->indent, "Hash Algorithm",
1007*ebfedea0SLionel Sambuc pgp_show_hash_alg((uint8_t)content->one_pass_sig.hash_alg),
1008*ebfedea0SLionel Sambuc (uint8_t)content->one_pass_sig.hash_alg);
1009*ebfedea0SLionel Sambuc print_string_and_value(print->indent, "Public Key Algorithm",
1010*ebfedea0SLionel Sambuc pgp_show_pka(content->one_pass_sig.key_alg),
1011*ebfedea0SLionel Sambuc content->one_pass_sig.key_alg);
1012*ebfedea0SLionel Sambuc hexdump_data(print->indent, "Signer ID",
1013*ebfedea0SLionel Sambuc content->one_pass_sig.keyid,
1014*ebfedea0SLionel Sambuc (unsigned)sizeof(content->one_pass_sig.keyid));
1015*ebfedea0SLionel Sambuc print_uint(print->indent, "Nested", content->one_pass_sig.nested);
1016*ebfedea0SLionel Sambuc break;
1017*ebfedea0SLionel Sambuc
1018*ebfedea0SLionel Sambuc case PGP_PTAG_CT_USER_ATTR:
1019*ebfedea0SLionel Sambuc print_tagname(print->indent, "USER ATTRIBUTE");
1020*ebfedea0SLionel Sambuc print_hexdump(print->indent, "User Attribute",
1021*ebfedea0SLionel Sambuc content->userattr.contents,
1022*ebfedea0SLionel Sambuc (unsigned)content->userattr.len);
1023*ebfedea0SLionel Sambuc break;
1024*ebfedea0SLionel Sambuc
1025*ebfedea0SLionel Sambuc case PGP_PTAG_RAW_SS:
1026*ebfedea0SLionel Sambuc if (pkt->critical) {
1027*ebfedea0SLionel Sambuc (void) fprintf(stderr, "contents are critical\n");
1028*ebfedea0SLionel Sambuc return 0;
1029*ebfedea0SLionel Sambuc }
1030*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1031*ebfedea0SLionel Sambuc print_uint(print->indent, "Raw Signature Subpacket: tag",
1032*ebfedea0SLionel Sambuc (unsigned)(content->ss_raw.tag -
1033*ebfedea0SLionel Sambuc (unsigned)PGP_PTAG_SIG_SUBPKT_BASE));
1034*ebfedea0SLionel Sambuc print_hexdump(print->indent, "Raw Data",
1035*ebfedea0SLionel Sambuc content->ss_raw.raw,
1036*ebfedea0SLionel Sambuc (unsigned)content->ss_raw.length);
1037*ebfedea0SLionel Sambuc break;
1038*ebfedea0SLionel Sambuc
1039*ebfedea0SLionel Sambuc case PGP_PTAG_SS_CREATION_TIME:
1040*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1041*ebfedea0SLionel Sambuc print_time(print->indent, "Signature Creation Time", content->ss_time);
1042*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1043*ebfedea0SLionel Sambuc break;
1044*ebfedea0SLionel Sambuc
1045*ebfedea0SLionel Sambuc case PGP_PTAG_SS_EXPIRATION_TIME:
1046*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1047*ebfedea0SLionel Sambuc print_duration(print->indent, "Signature Expiration Time",
1048*ebfedea0SLionel Sambuc content->ss_time);
1049*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1050*ebfedea0SLionel Sambuc break;
1051*ebfedea0SLionel Sambuc
1052*ebfedea0SLionel Sambuc case PGP_PTAG_SS_KEY_EXPIRY:
1053*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1054*ebfedea0SLionel Sambuc print_duration(print->indent, "Key Expiration Time", content->ss_time);
1055*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1056*ebfedea0SLionel Sambuc break;
1057*ebfedea0SLionel Sambuc
1058*ebfedea0SLionel Sambuc case PGP_PTAG_SS_TRUST:
1059*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1060*ebfedea0SLionel Sambuc print_string(print->indent, "Trust Signature", "");
1061*ebfedea0SLionel Sambuc print_uint(print->indent, "Level", (unsigned)content->ss_trust.level);
1062*ebfedea0SLionel Sambuc print_uint(print->indent, "Amount", (unsigned)content->ss_trust.amount);
1063*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1064*ebfedea0SLionel Sambuc break;
1065*ebfedea0SLionel Sambuc
1066*ebfedea0SLionel Sambuc case PGP_PTAG_SS_REVOCABLE:
1067*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1068*ebfedea0SLionel Sambuc print_boolean(print->indent, "Revocable", content->ss_revocable);
1069*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1070*ebfedea0SLionel Sambuc break;
1071*ebfedea0SLionel Sambuc
1072*ebfedea0SLionel Sambuc case PGP_PTAG_SS_REVOCATION_KEY:
1073*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1074*ebfedea0SLionel Sambuc /* not yet tested */
1075*ebfedea0SLionel Sambuc printf(" revocation key: class=0x%x",
1076*ebfedea0SLionel Sambuc content->ss_revocation_key.class);
1077*ebfedea0SLionel Sambuc if (content->ss_revocation_key.class & 0x40) {
1078*ebfedea0SLionel Sambuc printf(" (sensitive)");
1079*ebfedea0SLionel Sambuc }
1080*ebfedea0SLionel Sambuc printf(", algid=0x%x", content->ss_revocation_key.algid);
1081*ebfedea0SLionel Sambuc hexdump(stdout, "fingerprint", content->ss_revocation_key.fingerprint,
1082*ebfedea0SLionel Sambuc PGP_FINGERPRINT_SIZE);
1083*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1084*ebfedea0SLionel Sambuc break;
1085*ebfedea0SLionel Sambuc
1086*ebfedea0SLionel Sambuc case PGP_PTAG_SS_ISSUER_KEY_ID:
1087*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1088*ebfedea0SLionel Sambuc print_hexdump(print->indent, "Issuer Key Id",
1089*ebfedea0SLionel Sambuc content->ss_issuer, (unsigned)sizeof(content->ss_issuer));
1090*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1091*ebfedea0SLionel Sambuc break;
1092*ebfedea0SLionel Sambuc
1093*ebfedea0SLionel Sambuc case PGP_PTAG_SS_PREFERRED_SKA:
1094*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1095*ebfedea0SLionel Sambuc print_data(print->indent, "Preferred Symmetric Algorithms",
1096*ebfedea0SLionel Sambuc &content->ss_skapref);
1097*ebfedea0SLionel Sambuc text = pgp_showall_ss_skapref(&content->ss_skapref);
1098*ebfedea0SLionel Sambuc print_text_breakdown(print->indent, text);
1099*ebfedea0SLionel Sambuc pgp_text_free(text);
1100*ebfedea0SLionel Sambuc
1101*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1102*ebfedea0SLionel Sambuc break;
1103*ebfedea0SLionel Sambuc
1104*ebfedea0SLionel Sambuc case PGP_PTAG_SS_PRIMARY_USER_ID:
1105*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1106*ebfedea0SLionel Sambuc print_boolean(print->indent, "Primary User ID",
1107*ebfedea0SLionel Sambuc content->ss_primary_userid);
1108*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1109*ebfedea0SLionel Sambuc break;
1110*ebfedea0SLionel Sambuc
1111*ebfedea0SLionel Sambuc case PGP_PTAG_SS_PREFERRED_HASH:
1112*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1113*ebfedea0SLionel Sambuc print_data(print->indent, "Preferred Hash Algorithms",
1114*ebfedea0SLionel Sambuc &content->ss_hashpref);
1115*ebfedea0SLionel Sambuc text = pgp_showall_ss_hashpref(&content->ss_hashpref);
1116*ebfedea0SLionel Sambuc print_text_breakdown(print->indent, text);
1117*ebfedea0SLionel Sambuc pgp_text_free(text);
1118*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1119*ebfedea0SLionel Sambuc break;
1120*ebfedea0SLionel Sambuc
1121*ebfedea0SLionel Sambuc case PGP_PTAG_SS_PREF_COMPRESS:
1122*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1123*ebfedea0SLionel Sambuc print_data(print->indent, "Preferred Compression Algorithms",
1124*ebfedea0SLionel Sambuc &content->ss_zpref);
1125*ebfedea0SLionel Sambuc text = pgp_showall_ss_zpref(&content->ss_zpref);
1126*ebfedea0SLionel Sambuc print_text_breakdown(print->indent, text);
1127*ebfedea0SLionel Sambuc pgp_text_free(text);
1128*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1129*ebfedea0SLionel Sambuc break;
1130*ebfedea0SLionel Sambuc
1131*ebfedea0SLionel Sambuc case PGP_PTAG_SS_KEY_FLAGS:
1132*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1133*ebfedea0SLionel Sambuc print_data(print->indent, "Key Flags", &content->ss_key_flags);
1134*ebfedea0SLionel Sambuc
1135*ebfedea0SLionel Sambuc text = pgp_showall_ss_key_flags(&content->ss_key_flags);
1136*ebfedea0SLionel Sambuc print_text_breakdown(print->indent, text);
1137*ebfedea0SLionel Sambuc pgp_text_free(text);
1138*ebfedea0SLionel Sambuc
1139*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1140*ebfedea0SLionel Sambuc break;
1141*ebfedea0SLionel Sambuc
1142*ebfedea0SLionel Sambuc case PGP_PTAG_SS_KEYSERV_PREFS:
1143*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1144*ebfedea0SLionel Sambuc print_data(print->indent, "Key Server Preferences",
1145*ebfedea0SLionel Sambuc &content->ss_key_server_prefs);
1146*ebfedea0SLionel Sambuc text = pgp_show_keyserv_prefs(&content->ss_key_server_prefs);
1147*ebfedea0SLionel Sambuc print_text_breakdown(print->indent, text);
1148*ebfedea0SLionel Sambuc pgp_text_free(text);
1149*ebfedea0SLionel Sambuc
1150*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1151*ebfedea0SLionel Sambuc break;
1152*ebfedea0SLionel Sambuc
1153*ebfedea0SLionel Sambuc case PGP_PTAG_SS_FEATURES:
1154*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1155*ebfedea0SLionel Sambuc print_data(print->indent, "Features", &content->ss_features);
1156*ebfedea0SLionel Sambuc text = pgp_showall_ss_features(content->ss_features);
1157*ebfedea0SLionel Sambuc print_text_breakdown(print->indent, text);
1158*ebfedea0SLionel Sambuc pgp_text_free(text);
1159*ebfedea0SLionel Sambuc
1160*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1161*ebfedea0SLionel Sambuc break;
1162*ebfedea0SLionel Sambuc
1163*ebfedea0SLionel Sambuc case PGP_PTAG_SS_NOTATION_DATA:
1164*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1165*ebfedea0SLionel Sambuc print_indent(print->indent);
1166*ebfedea0SLionel Sambuc printf("Notation Data:\n");
1167*ebfedea0SLionel Sambuc
1168*ebfedea0SLionel Sambuc print->indent++;
1169*ebfedea0SLionel Sambuc print_data(print->indent, "Flags", &content->ss_notation.flags);
1170*ebfedea0SLionel Sambuc text = pgp_showall_notation(content->ss_notation);
1171*ebfedea0SLionel Sambuc print_text_breakdown(print->indent, text);
1172*ebfedea0SLionel Sambuc pgp_text_free(text);
1173*ebfedea0SLionel Sambuc
1174*ebfedea0SLionel Sambuc print_data(print->indent, "Name", &content->ss_notation.name);
1175*ebfedea0SLionel Sambuc
1176*ebfedea0SLionel Sambuc print_data(print->indent, "Value", &content->ss_notation.value);
1177*ebfedea0SLionel Sambuc
1178*ebfedea0SLionel Sambuc print->indent--;
1179*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1180*ebfedea0SLionel Sambuc break;
1181*ebfedea0SLionel Sambuc
1182*ebfedea0SLionel Sambuc case PGP_PTAG_SS_REGEXP:
1183*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1184*ebfedea0SLionel Sambuc print_hexdump(print->indent, "Regular Expression",
1185*ebfedea0SLionel Sambuc (uint8_t *) content->ss_regexp,
1186*ebfedea0SLionel Sambuc (unsigned)strlen(content->ss_regexp));
1187*ebfedea0SLionel Sambuc print_string(print->indent, NULL, content->ss_regexp);
1188*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1189*ebfedea0SLionel Sambuc break;
1190*ebfedea0SLionel Sambuc
1191*ebfedea0SLionel Sambuc case PGP_PTAG_SS_POLICY_URI:
1192*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1193*ebfedea0SLionel Sambuc print_string(print->indent, "Policy URL", content->ss_policy);
1194*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1195*ebfedea0SLionel Sambuc break;
1196*ebfedea0SLionel Sambuc
1197*ebfedea0SLionel Sambuc case PGP_PTAG_SS_SIGNERS_USER_ID:
1198*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1199*ebfedea0SLionel Sambuc print_utf8_string(print->indent, "Signer's User ID", content->ss_signer);
1200*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1201*ebfedea0SLionel Sambuc break;
1202*ebfedea0SLionel Sambuc
1203*ebfedea0SLionel Sambuc case PGP_PTAG_SS_PREF_KEYSERV:
1204*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1205*ebfedea0SLionel Sambuc print_string(print->indent, "Preferred Key Server", content->ss_keyserv);
1206*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1207*ebfedea0SLionel Sambuc break;
1208*ebfedea0SLionel Sambuc
1209*ebfedea0SLionel Sambuc case PGP_PTAG_SS_EMBEDDED_SIGNATURE:
1210*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1211*ebfedea0SLionel Sambuc end_subpacket(&print->indent);/* \todo print out contents? */
1212*ebfedea0SLionel Sambuc break;
1213*ebfedea0SLionel Sambuc
1214*ebfedea0SLionel Sambuc case PGP_PTAG_SS_USERDEFINED00:
1215*ebfedea0SLionel Sambuc case PGP_PTAG_SS_USERDEFINED01:
1216*ebfedea0SLionel Sambuc case PGP_PTAG_SS_USERDEFINED02:
1217*ebfedea0SLionel Sambuc case PGP_PTAG_SS_USERDEFINED03:
1218*ebfedea0SLionel Sambuc case PGP_PTAG_SS_USERDEFINED04:
1219*ebfedea0SLionel Sambuc case PGP_PTAG_SS_USERDEFINED05:
1220*ebfedea0SLionel Sambuc case PGP_PTAG_SS_USERDEFINED06:
1221*ebfedea0SLionel Sambuc case PGP_PTAG_SS_USERDEFINED07:
1222*ebfedea0SLionel Sambuc case PGP_PTAG_SS_USERDEFINED08:
1223*ebfedea0SLionel Sambuc case PGP_PTAG_SS_USERDEFINED09:
1224*ebfedea0SLionel Sambuc case PGP_PTAG_SS_USERDEFINED10:
1225*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1226*ebfedea0SLionel Sambuc print_hexdump(print->indent, "Internal or user-defined",
1227*ebfedea0SLionel Sambuc content->ss_userdef.contents,
1228*ebfedea0SLionel Sambuc (unsigned)content->ss_userdef.len);
1229*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1230*ebfedea0SLionel Sambuc break;
1231*ebfedea0SLionel Sambuc
1232*ebfedea0SLionel Sambuc case PGP_PTAG_SS_RESERVED:
1233*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1234*ebfedea0SLionel Sambuc print_hexdump(print->indent, "Reserved",
1235*ebfedea0SLionel Sambuc content->ss_userdef.contents,
1236*ebfedea0SLionel Sambuc (unsigned)content->ss_userdef.len);
1237*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1238*ebfedea0SLionel Sambuc break;
1239*ebfedea0SLionel Sambuc
1240*ebfedea0SLionel Sambuc case PGP_PTAG_SS_REVOCATION_REASON:
1241*ebfedea0SLionel Sambuc start_subpacket(&print->indent, pkt->tag);
1242*ebfedea0SLionel Sambuc print_hexdump(print->indent, "Revocation Reason",
1243*ebfedea0SLionel Sambuc &content->ss_revocation.code,
1244*ebfedea0SLionel Sambuc 1);
1245*ebfedea0SLionel Sambuc str = pgp_show_ss_rr_code(content->ss_revocation.code);
1246*ebfedea0SLionel Sambuc print_string(print->indent, NULL, str);
1247*ebfedea0SLionel Sambuc end_subpacket(&print->indent);
1248*ebfedea0SLionel Sambuc break;
1249*ebfedea0SLionel Sambuc
1250*ebfedea0SLionel Sambuc case PGP_PTAG_CT_LITDATA_HEADER:
1251*ebfedea0SLionel Sambuc print_tagname(print->indent, "LITERAL DATA HEADER");
1252*ebfedea0SLionel Sambuc printf(" literal data header format=%c filename='%s'\n",
1253*ebfedea0SLionel Sambuc content->litdata_header.format,
1254*ebfedea0SLionel Sambuc content->litdata_header.filename);
1255*ebfedea0SLionel Sambuc showtime(" modification time",
1256*ebfedea0SLionel Sambuc content->litdata_header.mtime);
1257*ebfedea0SLionel Sambuc printf("\n");
1258*ebfedea0SLionel Sambuc break;
1259*ebfedea0SLionel Sambuc
1260*ebfedea0SLionel Sambuc case PGP_PTAG_CT_LITDATA_BODY:
1261*ebfedea0SLionel Sambuc print_tagname(print->indent, "LITERAL DATA BODY");
1262*ebfedea0SLionel Sambuc printf(" literal data body length=%u\n",
1263*ebfedea0SLionel Sambuc content->litdata_body.length);
1264*ebfedea0SLionel Sambuc printf(" data=");
1265*ebfedea0SLionel Sambuc print_escaped(content->litdata_body.data,
1266*ebfedea0SLionel Sambuc content->litdata_body.length);
1267*ebfedea0SLionel Sambuc printf("\n");
1268*ebfedea0SLionel Sambuc break;
1269*ebfedea0SLionel Sambuc
1270*ebfedea0SLionel Sambuc case PGP_PTAG_CT_SIGNATURE_HEADER:
1271*ebfedea0SLionel Sambuc print_tagname(print->indent, "SIGNATURE");
1272*ebfedea0SLionel Sambuc print_indent(print->indent);
1273*ebfedea0SLionel Sambuc print_uint(print->indent, "Signature Version",
1274*ebfedea0SLionel Sambuc (unsigned)content->sig.info.version);
1275*ebfedea0SLionel Sambuc if (content->sig.info.birthtime_set) {
1276*ebfedea0SLionel Sambuc print_time(print->indent, "Signature Creation Time",
1277*ebfedea0SLionel Sambuc content->sig.info.birthtime);
1278*ebfedea0SLionel Sambuc }
1279*ebfedea0SLionel Sambuc if (content->sig.info.duration_set) {
1280*ebfedea0SLionel Sambuc print_uint(print->indent, "Signature Duration",
1281*ebfedea0SLionel Sambuc (unsigned)content->sig.info.duration);
1282*ebfedea0SLionel Sambuc }
1283*ebfedea0SLionel Sambuc print_string_and_value(print->indent, "Signature Type",
1284*ebfedea0SLionel Sambuc pgp_show_sig_type(content->sig.info.type),
1285*ebfedea0SLionel Sambuc content->sig.info.type);
1286*ebfedea0SLionel Sambuc if (content->sig.info.signer_id_set) {
1287*ebfedea0SLionel Sambuc hexdump_data(print->indent, "Signer ID",
1288*ebfedea0SLionel Sambuc content->sig.info.signer_id,
1289*ebfedea0SLionel Sambuc (unsigned)sizeof(content->sig.info.signer_id));
1290*ebfedea0SLionel Sambuc }
1291*ebfedea0SLionel Sambuc print_string_and_value(print->indent, "Public Key Algorithm",
1292*ebfedea0SLionel Sambuc pgp_show_pka(content->sig.info.key_alg),
1293*ebfedea0SLionel Sambuc content->sig.info.key_alg);
1294*ebfedea0SLionel Sambuc print_string_and_value(print->indent, "Hash Algorithm",
1295*ebfedea0SLionel Sambuc pgp_show_hash_alg((uint8_t)content->sig.info.hash_alg),
1296*ebfedea0SLionel Sambuc (uint8_t)content->sig.info.hash_alg);
1297*ebfedea0SLionel Sambuc print_uint(print->indent, "Hashed data len",
1298*ebfedea0SLionel Sambuc (unsigned)content->sig.info.v4_hashlen);
1299*ebfedea0SLionel Sambuc
1300*ebfedea0SLionel Sambuc break;
1301*ebfedea0SLionel Sambuc
1302*ebfedea0SLionel Sambuc case PGP_PTAG_CT_SIGNATURE_FOOTER:
1303*ebfedea0SLionel Sambuc print_indent(print->indent);
1304*ebfedea0SLionel Sambuc hexdump_data(print->indent, "hash2", &content->sig.hash2[0], 2);
1305*ebfedea0SLionel Sambuc
1306*ebfedea0SLionel Sambuc switch (content->sig.info.key_alg) {
1307*ebfedea0SLionel Sambuc case PGP_PKA_RSA:
1308*ebfedea0SLionel Sambuc print_bn(print->indent, "sig", content->sig.info.sig.rsa.sig);
1309*ebfedea0SLionel Sambuc break;
1310*ebfedea0SLionel Sambuc
1311*ebfedea0SLionel Sambuc case PGP_PKA_DSA:
1312*ebfedea0SLionel Sambuc print_bn(print->indent, "r", content->sig.info.sig.dsa.r);
1313*ebfedea0SLionel Sambuc print_bn(print->indent, "s", content->sig.info.sig.dsa.s);
1314*ebfedea0SLionel Sambuc break;
1315*ebfedea0SLionel Sambuc
1316*ebfedea0SLionel Sambuc case PGP_PKA_ELGAMAL_ENCRYPT_OR_SIGN:
1317*ebfedea0SLionel Sambuc print_bn(print->indent, "r", content->sig.info.sig.elgamal.r);
1318*ebfedea0SLionel Sambuc print_bn(print->indent, "s", content->sig.info.sig.elgamal.s);
1319*ebfedea0SLionel Sambuc break;
1320*ebfedea0SLionel Sambuc
1321*ebfedea0SLionel Sambuc case PGP_PKA_PRIVATE00:
1322*ebfedea0SLionel Sambuc case PGP_PKA_PRIVATE01:
1323*ebfedea0SLionel Sambuc case PGP_PKA_PRIVATE02:
1324*ebfedea0SLionel Sambuc case PGP_PKA_PRIVATE03:
1325*ebfedea0SLionel Sambuc case PGP_PKA_PRIVATE04:
1326*ebfedea0SLionel Sambuc case PGP_PKA_PRIVATE05:
1327*ebfedea0SLionel Sambuc case PGP_PKA_PRIVATE06:
1328*ebfedea0SLionel Sambuc case PGP_PKA_PRIVATE07:
1329*ebfedea0SLionel Sambuc case PGP_PKA_PRIVATE08:
1330*ebfedea0SLionel Sambuc case PGP_PKA_PRIVATE09:
1331*ebfedea0SLionel Sambuc case PGP_PKA_PRIVATE10:
1332*ebfedea0SLionel Sambuc print_data(print->indent, "Private/Experimental",
1333*ebfedea0SLionel Sambuc &content->sig.info.sig.unknown);
1334*ebfedea0SLionel Sambuc break;
1335*ebfedea0SLionel Sambuc
1336*ebfedea0SLionel Sambuc default:
1337*ebfedea0SLionel Sambuc (void) fprintf(stderr,
1338*ebfedea0SLionel Sambuc "pgp_print_packet: Unusual key algorithm\n");
1339*ebfedea0SLionel Sambuc return 0;
1340*ebfedea0SLionel Sambuc }
1341*ebfedea0SLionel Sambuc break;
1342*ebfedea0SLionel Sambuc
1343*ebfedea0SLionel Sambuc case PGP_GET_PASSPHRASE:
1344*ebfedea0SLionel Sambuc print_tagname(print->indent, "PGP_GET_PASSPHRASE");
1345*ebfedea0SLionel Sambuc break;
1346*ebfedea0SLionel Sambuc
1347*ebfedea0SLionel Sambuc case PGP_PTAG_CT_SECRET_KEY:
1348*ebfedea0SLionel Sambuc print_tagname(print->indent, "PGP_PTAG_CT_SECRET_KEY");
1349*ebfedea0SLionel Sambuc print_seckey_verbose(pkt->tag, &content->seckey);
1350*ebfedea0SLionel Sambuc break;
1351*ebfedea0SLionel Sambuc
1352*ebfedea0SLionel Sambuc case PGP_PTAG_CT_ENCRYPTED_SECRET_KEY:
1353*ebfedea0SLionel Sambuc print_tagname(print->indent, "PGP_PTAG_CT_ENCRYPTED_SECRET_KEY");
1354*ebfedea0SLionel Sambuc print_seckey_verbose(pkt->tag, &content->seckey);
1355*ebfedea0SLionel Sambuc break;
1356*ebfedea0SLionel Sambuc
1357*ebfedea0SLionel Sambuc case PGP_PTAG_CT_ARMOUR_HEADER:
1358*ebfedea0SLionel Sambuc print_tagname(print->indent, "ARMOUR HEADER");
1359*ebfedea0SLionel Sambuc print_string(print->indent, "type", content->armour_header.type);
1360*ebfedea0SLionel Sambuc break;
1361*ebfedea0SLionel Sambuc
1362*ebfedea0SLionel Sambuc case PGP_PTAG_CT_SIGNED_CLEARTEXT_HEADER:
1363*ebfedea0SLionel Sambuc print_tagname(print->indent, "SIGNED CLEARTEXT HEADER");
1364*ebfedea0SLionel Sambuc print_headers(&content->cleartext_head);
1365*ebfedea0SLionel Sambuc break;
1366*ebfedea0SLionel Sambuc
1367*ebfedea0SLionel Sambuc case PGP_PTAG_CT_SIGNED_CLEARTEXT_BODY:
1368*ebfedea0SLionel Sambuc print_tagname(print->indent, "SIGNED CLEARTEXT BODY");
1369*ebfedea0SLionel Sambuc print_block(print->indent, "signed cleartext", content->cleartext_body.data,
1370*ebfedea0SLionel Sambuc content->cleartext_body.length);
1371*ebfedea0SLionel Sambuc break;
1372*ebfedea0SLionel Sambuc
1373*ebfedea0SLionel Sambuc case PGP_PTAG_CT_SIGNED_CLEARTEXT_TRAILER:
1374*ebfedea0SLionel Sambuc print_tagname(print->indent, "SIGNED CLEARTEXT TRAILER");
1375*ebfedea0SLionel Sambuc printf("hash algorithm: %d\n",
1376*ebfedea0SLionel Sambuc content->cleartext_trailer->alg);
1377*ebfedea0SLionel Sambuc printf("\n");
1378*ebfedea0SLionel Sambuc break;
1379*ebfedea0SLionel Sambuc
1380*ebfedea0SLionel Sambuc case PGP_PTAG_CT_UNARMOURED_TEXT:
1381*ebfedea0SLionel Sambuc if (!print->unarmoured) {
1382*ebfedea0SLionel Sambuc print_tagname(print->indent, "UNARMOURED TEXT");
1383*ebfedea0SLionel Sambuc print->unarmoured = 1;
1384*ebfedea0SLionel Sambuc }
1385*ebfedea0SLionel Sambuc putchar('[');
1386*ebfedea0SLionel Sambuc print_escaped(content->unarmoured_text.data,
1387*ebfedea0SLionel Sambuc content->unarmoured_text.length);
1388*ebfedea0SLionel Sambuc putchar(']');
1389*ebfedea0SLionel Sambuc break;
1390*ebfedea0SLionel Sambuc
1391*ebfedea0SLionel Sambuc case PGP_PTAG_CT_ARMOUR_TRAILER:
1392*ebfedea0SLionel Sambuc print_tagname(print->indent, "ARMOUR TRAILER");
1393*ebfedea0SLionel Sambuc print_string(print->indent, "type", content->armour_header.type);
1394*ebfedea0SLionel Sambuc break;
1395*ebfedea0SLionel Sambuc
1396*ebfedea0SLionel Sambuc case PGP_PTAG_CT_PK_SESSION_KEY:
1397*ebfedea0SLionel Sambuc case PGP_PTAG_CT_ENCRYPTED_PK_SESSION_KEY:
1398*ebfedea0SLionel Sambuc print_pk_sesskey(pkt->tag, &content->pk_sesskey);
1399*ebfedea0SLionel Sambuc break;
1400*ebfedea0SLionel Sambuc
1401*ebfedea0SLionel Sambuc case PGP_GET_SECKEY:
1402*ebfedea0SLionel Sambuc print_pk_sesskey(PGP_PTAG_CT_ENCRYPTED_PK_SESSION_KEY,
1403*ebfedea0SLionel Sambuc content->get_seckey.pk_sesskey);
1404*ebfedea0SLionel Sambuc break;
1405*ebfedea0SLionel Sambuc
1406*ebfedea0SLionel Sambuc default:
1407*ebfedea0SLionel Sambuc print_tagname(print->indent, "UNKNOWN PACKET TYPE");
1408*ebfedea0SLionel Sambuc fprintf(stderr, "pgp_print_packet: unknown tag=%d (0x%x)\n",
1409*ebfedea0SLionel Sambuc pkt->tag, pkt->tag);
1410*ebfedea0SLionel Sambuc return 0;
1411*ebfedea0SLionel Sambuc }
1412*ebfedea0SLionel Sambuc return 1;
1413*ebfedea0SLionel Sambuc }
1414*ebfedea0SLionel Sambuc
1415*ebfedea0SLionel Sambuc static pgp_cb_ret_t
cb_list_packets(const pgp_packet_t * pkt,pgp_cbdata_t * cbinfo)1416*ebfedea0SLionel Sambuc cb_list_packets(const pgp_packet_t *pkt, pgp_cbdata_t *cbinfo)
1417*ebfedea0SLionel Sambuc {
1418*ebfedea0SLionel Sambuc pgp_print_packet(&cbinfo->printstate, pkt);
1419*ebfedea0SLionel Sambuc return PGP_RELEASE_MEMORY;
1420*ebfedea0SLionel Sambuc }
1421*ebfedea0SLionel Sambuc
1422*ebfedea0SLionel Sambuc /**
1423*ebfedea0SLionel Sambuc \ingroup Core_Print
1424*ebfedea0SLionel Sambuc \param filename
1425*ebfedea0SLionel Sambuc \param armour
1426*ebfedea0SLionel Sambuc \param keyring
1427*ebfedea0SLionel Sambuc \param cb_get_passphrase
1428*ebfedea0SLionel Sambuc */
1429*ebfedea0SLionel Sambuc int
pgp_list_packets(pgp_io_t * io,char * filename,unsigned armour,pgp_keyring_t * secring,pgp_keyring_t * pubring,void * passfp,pgp_cbfunc_t * cb_get_passphrase)1430*ebfedea0SLionel Sambuc pgp_list_packets(pgp_io_t *io,
1431*ebfedea0SLionel Sambuc char *filename,
1432*ebfedea0SLionel Sambuc unsigned armour,
1433*ebfedea0SLionel Sambuc pgp_keyring_t *secring,
1434*ebfedea0SLionel Sambuc pgp_keyring_t *pubring,
1435*ebfedea0SLionel Sambuc void *passfp,
1436*ebfedea0SLionel Sambuc pgp_cbfunc_t *cb_get_passphrase)
1437*ebfedea0SLionel Sambuc {
1438*ebfedea0SLionel Sambuc pgp_stream_t *stream = NULL;
1439*ebfedea0SLionel Sambuc const unsigned accumulate = 1;
1440*ebfedea0SLionel Sambuc const int printerrors = 1;
1441*ebfedea0SLionel Sambuc int fd;
1442*ebfedea0SLionel Sambuc
1443*ebfedea0SLionel Sambuc fd = pgp_setup_file_read(io, &stream, filename, NULL, cb_list_packets,
1444*ebfedea0SLionel Sambuc accumulate);
1445*ebfedea0SLionel Sambuc pgp_parse_options(stream, PGP_PTAG_SS_ALL, PGP_PARSE_PARSED);
1446*ebfedea0SLionel Sambuc stream->cryptinfo.secring = secring;
1447*ebfedea0SLionel Sambuc stream->cryptinfo.pubring = pubring;
1448*ebfedea0SLionel Sambuc stream->cbinfo.passfp = passfp;
1449*ebfedea0SLionel Sambuc stream->cryptinfo.getpassphrase = cb_get_passphrase;
1450*ebfedea0SLionel Sambuc if (armour) {
1451*ebfedea0SLionel Sambuc pgp_reader_push_dearmour(stream);
1452*ebfedea0SLionel Sambuc }
1453*ebfedea0SLionel Sambuc pgp_parse(stream, printerrors);
1454*ebfedea0SLionel Sambuc pgp_teardown_file_read(stream, fd);
1455*ebfedea0SLionel Sambuc return 1;
1456*ebfedea0SLionel Sambuc }
1457