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 /** \file
51*ebfedea0SLionel Sambuc *
52*ebfedea0SLionel Sambuc * Creates printable text strings from packet contents
53*ebfedea0SLionel Sambuc *
54*ebfedea0SLionel Sambuc */
55*ebfedea0SLionel Sambuc #include "config.h"
56*ebfedea0SLionel Sambuc
57*ebfedea0SLionel Sambuc #ifdef HAVE_SYS_CDEFS_H
58*ebfedea0SLionel Sambuc #include <sys/cdefs.h>
59*ebfedea0SLionel Sambuc #endif
60*ebfedea0SLionel Sambuc
61*ebfedea0SLionel Sambuc #if defined(__NetBSD__)
62*ebfedea0SLionel Sambuc __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
63*ebfedea0SLionel Sambuc __RCSID("$NetBSD: packet-show.c,v 1.21 2011/08/14 11:19:51 christos Exp $");
64*ebfedea0SLionel Sambuc #endif
65*ebfedea0SLionel Sambuc
66*ebfedea0SLionel Sambuc #include <stdlib.h>
67*ebfedea0SLionel Sambuc #include <string.h>
68*ebfedea0SLionel Sambuc
69*ebfedea0SLionel Sambuc #include "packet-show.h"
70*ebfedea0SLionel Sambuc
71*ebfedea0SLionel Sambuc #include "netpgpsdk.h"
72*ebfedea0SLionel Sambuc #include "netpgpdefs.h"
73*ebfedea0SLionel Sambuc
74*ebfedea0SLionel Sambuc
75*ebfedea0SLionel Sambuc /*
76*ebfedea0SLionel Sambuc * Arrays of value->text maps
77*ebfedea0SLionel Sambuc */
78*ebfedea0SLionel Sambuc
79*ebfedea0SLionel Sambuc static pgp_map_t packet_tag_map[] =
80*ebfedea0SLionel Sambuc {
81*ebfedea0SLionel Sambuc {PGP_PTAG_CT_RESERVED, "Reserved"},
82*ebfedea0SLionel Sambuc {PGP_PTAG_CT_PK_SESSION_KEY, "Public-Key Encrypted Session Key"},
83*ebfedea0SLionel Sambuc {PGP_PTAG_CT_SIGNATURE, "Signature"},
84*ebfedea0SLionel Sambuc {PGP_PTAG_CT_SK_SESSION_KEY, "Symmetric-Key Encrypted Session Key"},
85*ebfedea0SLionel Sambuc {PGP_PTAG_CT_1_PASS_SIG, "One-Pass Signature"},
86*ebfedea0SLionel Sambuc {PGP_PTAG_CT_SECRET_KEY, "Secret Key"},
87*ebfedea0SLionel Sambuc {PGP_PTAG_CT_PUBLIC_KEY, "Public Key"},
88*ebfedea0SLionel Sambuc {PGP_PTAG_CT_SECRET_SUBKEY, "Secret Subkey"},
89*ebfedea0SLionel Sambuc {PGP_PTAG_CT_COMPRESSED, "Compressed Data"},
90*ebfedea0SLionel Sambuc {PGP_PTAG_CT_SE_DATA, "Symmetrically Encrypted Data"},
91*ebfedea0SLionel Sambuc {PGP_PTAG_CT_MARKER, "Marker"},
92*ebfedea0SLionel Sambuc {PGP_PTAG_CT_LITDATA, "Literal Data"},
93*ebfedea0SLionel Sambuc {PGP_PTAG_CT_TRUST, "Trust"},
94*ebfedea0SLionel Sambuc {PGP_PTAG_CT_USER_ID, "User ID"},
95*ebfedea0SLionel Sambuc {PGP_PTAG_CT_PUBLIC_SUBKEY, "Public Subkey"},
96*ebfedea0SLionel Sambuc {PGP_PTAG_CT_RESERVED2, "reserved2"},
97*ebfedea0SLionel Sambuc {PGP_PTAG_CT_RESERVED3, "reserved3"},
98*ebfedea0SLionel Sambuc {PGP_PTAG_CT_USER_ATTR, "User Attribute"},
99*ebfedea0SLionel Sambuc {PGP_PTAG_CT_SE_IP_DATA,
100*ebfedea0SLionel Sambuc "Symmetric Encrypted and Integrity Protected Data"},
101*ebfedea0SLionel Sambuc {PGP_PTAG_CT_MDC, "Modification Detection Code"},
102*ebfedea0SLionel Sambuc {PGP_PARSER_PTAG, "PGP_PARSER_PTAG"},
103*ebfedea0SLionel Sambuc {PGP_PTAG_RAW_SS, "PGP_PTAG_RAW_SS"},
104*ebfedea0SLionel Sambuc {PGP_PTAG_SS_ALL, "PGP_PTAG_SS_ALL"},
105*ebfedea0SLionel Sambuc {PGP_PARSER_PACKET_END, "PGP_PARSER_PACKET_END"},
106*ebfedea0SLionel Sambuc {PGP_PTAG_SIG_SUBPKT_BASE, "PGP_PTAG_SIG_SUBPKT_BASE"},
107*ebfedea0SLionel Sambuc {PGP_PTAG_SS_CREATION_TIME, "SS: Signature Creation Time"},
108*ebfedea0SLionel Sambuc {PGP_PTAG_SS_EXPIRATION_TIME, "SS: Signature Expiration Time"},
109*ebfedea0SLionel Sambuc {PGP_PTAG_SS_EXPORT_CERT, "SS: Exportable Certification"},
110*ebfedea0SLionel Sambuc {PGP_PTAG_SS_TRUST, "SS: Trust Signature"},
111*ebfedea0SLionel Sambuc {PGP_PTAG_SS_REGEXP, "SS: Regular Expression"},
112*ebfedea0SLionel Sambuc {PGP_PTAG_SS_REVOCABLE, "SS: Revocable"},
113*ebfedea0SLionel Sambuc {PGP_PTAG_SS_KEY_EXPIRY, "SS: Key Expiration Time"},
114*ebfedea0SLionel Sambuc {PGP_PTAG_SS_RESERVED, "SS: Reserved"},
115*ebfedea0SLionel Sambuc {PGP_PTAG_SS_PREFERRED_SKA, "SS: Preferred Secret Key Algorithm"},
116*ebfedea0SLionel Sambuc {PGP_PTAG_SS_REVOCATION_KEY, "SS: Revocation Key"},
117*ebfedea0SLionel Sambuc {PGP_PTAG_SS_ISSUER_KEY_ID, "SS: Issuer Key Id"},
118*ebfedea0SLionel Sambuc {PGP_PTAG_SS_NOTATION_DATA, "SS: Notation Data"},
119*ebfedea0SLionel Sambuc {PGP_PTAG_SS_PREFERRED_HASH, "SS: Preferred Hash Algorithm"},
120*ebfedea0SLionel Sambuc {PGP_PTAG_SS_PREF_COMPRESS, "SS: Preferred Compression Algorithm"},
121*ebfedea0SLionel Sambuc {PGP_PTAG_SS_KEYSERV_PREFS, "SS: Key Server Preferences"},
122*ebfedea0SLionel Sambuc {PGP_PTAG_SS_PREF_KEYSERV, "SS: Preferred Key Server"},
123*ebfedea0SLionel Sambuc {PGP_PTAG_SS_PRIMARY_USER_ID, "SS: Primary User ID"},
124*ebfedea0SLionel Sambuc {PGP_PTAG_SS_POLICY_URI, "SS: Policy URI"},
125*ebfedea0SLionel Sambuc {PGP_PTAG_SS_KEY_FLAGS, "SS: Key Flags"},
126*ebfedea0SLionel Sambuc {PGP_PTAG_SS_SIGNERS_USER_ID, "SS: Signer's User ID"},
127*ebfedea0SLionel Sambuc {PGP_PTAG_SS_REVOCATION_REASON, "SS: Reason for Revocation"},
128*ebfedea0SLionel Sambuc {PGP_PTAG_SS_FEATURES, "SS: Features"},
129*ebfedea0SLionel Sambuc {PGP_PTAG_SS_SIGNATURE_TARGET, "SS: Signature Target"},
130*ebfedea0SLionel Sambuc {PGP_PTAG_SS_EMBEDDED_SIGNATURE, "SS: Embedded Signature"},
131*ebfedea0SLionel Sambuc
132*ebfedea0SLionel Sambuc {PGP_PTAG_CT_LITDATA_HEADER, "CT: Literal Data Header"},
133*ebfedea0SLionel Sambuc {PGP_PTAG_CT_LITDATA_BODY, "CT: Literal Data Body"},
134*ebfedea0SLionel Sambuc {PGP_PTAG_CT_SIGNATURE_HEADER, "CT: Signature Header"},
135*ebfedea0SLionel Sambuc {PGP_PTAG_CT_SIGNATURE_FOOTER, "CT: Signature Footer"},
136*ebfedea0SLionel Sambuc {PGP_PTAG_CT_ARMOUR_HEADER, "CT: Armour Header"},
137*ebfedea0SLionel Sambuc {PGP_PTAG_CT_ARMOUR_TRAILER, "CT: Armour Trailer"},
138*ebfedea0SLionel Sambuc {PGP_PTAG_CT_SIGNED_CLEARTEXT_HEADER, "CT: Signed Cleartext Header"},
139*ebfedea0SLionel Sambuc {PGP_PTAG_CT_SIGNED_CLEARTEXT_BODY, "CT: Signed Cleartext Body"},
140*ebfedea0SLionel Sambuc {PGP_PTAG_CT_SIGNED_CLEARTEXT_TRAILER, "CT: Signed Cleartext Trailer"},
141*ebfedea0SLionel Sambuc {PGP_PTAG_CT_UNARMOURED_TEXT, "CT: Unarmoured Text"},
142*ebfedea0SLionel Sambuc {PGP_PTAG_CT_ENCRYPTED_SECRET_KEY, "CT: Encrypted Secret Key"},
143*ebfedea0SLionel Sambuc {PGP_PTAG_CT_SE_DATA_HEADER, "CT: Sym Encrypted Data Header"},
144*ebfedea0SLionel Sambuc {PGP_PTAG_CT_SE_DATA_BODY, "CT: Sym Encrypted Data Body"},
145*ebfedea0SLionel Sambuc {PGP_PTAG_CT_SE_IP_DATA_HEADER, "CT: Sym Encrypted IP Data Header"},
146*ebfedea0SLionel Sambuc {PGP_PTAG_CT_SE_IP_DATA_BODY, "CT: Sym Encrypted IP Data Body"},
147*ebfedea0SLionel Sambuc {PGP_PTAG_CT_ENCRYPTED_PK_SESSION_KEY, "CT: Encrypted PK Session Key"},
148*ebfedea0SLionel Sambuc {PGP_GET_PASSPHRASE, "CMD: Get Secret Key Passphrase"},
149*ebfedea0SLionel Sambuc {PGP_GET_SECKEY, "CMD: Get Secret Key"},
150*ebfedea0SLionel Sambuc {PGP_PARSER_ERROR, "PGP_PARSER_ERROR"},
151*ebfedea0SLionel Sambuc {PGP_PARSER_ERRCODE, "PGP_PARSER_ERRCODE"},
152*ebfedea0SLionel Sambuc
153*ebfedea0SLionel Sambuc {0x00, NULL}, /* this is the end-of-array marker */
154*ebfedea0SLionel Sambuc };
155*ebfedea0SLionel Sambuc
156*ebfedea0SLionel Sambuc static pgp_map_t ss_type_map[] =
157*ebfedea0SLionel Sambuc {
158*ebfedea0SLionel Sambuc {PGP_PTAG_SS_CREATION_TIME, "Signature Creation Time"},
159*ebfedea0SLionel Sambuc {PGP_PTAG_SS_EXPIRATION_TIME, "Signature Expiration Time"},
160*ebfedea0SLionel Sambuc {PGP_PTAG_SS_TRUST, "Trust Signature"},
161*ebfedea0SLionel Sambuc {PGP_PTAG_SS_REGEXP, "Regular Expression"},
162*ebfedea0SLionel Sambuc {PGP_PTAG_SS_REVOCABLE, "Revocable"},
163*ebfedea0SLionel Sambuc {PGP_PTAG_SS_KEY_EXPIRY, "Key Expiration Time"},
164*ebfedea0SLionel Sambuc {PGP_PTAG_SS_PREFERRED_SKA, "Preferred Symmetric Algorithms"},
165*ebfedea0SLionel Sambuc {PGP_PTAG_SS_REVOCATION_KEY, "Revocation Key"},
166*ebfedea0SLionel Sambuc {PGP_PTAG_SS_ISSUER_KEY_ID, "Issuer key ID"},
167*ebfedea0SLionel Sambuc {PGP_PTAG_SS_NOTATION_DATA, "Notation Data"},
168*ebfedea0SLionel Sambuc {PGP_PTAG_SS_PREFERRED_HASH, "Preferred Hash Algorithms"},
169*ebfedea0SLionel Sambuc {PGP_PTAG_SS_PREF_COMPRESS, "Preferred Compression Algorithms"},
170*ebfedea0SLionel Sambuc {PGP_PTAG_SS_KEYSERV_PREFS, "Key Server Preferences"},
171*ebfedea0SLionel Sambuc {PGP_PTAG_SS_PREF_KEYSERV, "Preferred Key Server"},
172*ebfedea0SLionel Sambuc {PGP_PTAG_SS_PRIMARY_USER_ID, "Primary User ID"},
173*ebfedea0SLionel Sambuc {PGP_PTAG_SS_POLICY_URI, "Policy URI"},
174*ebfedea0SLionel Sambuc {PGP_PTAG_SS_KEY_FLAGS, "Key Flags"},
175*ebfedea0SLionel Sambuc {PGP_PTAG_SS_REVOCATION_REASON, "Reason for Revocation"},
176*ebfedea0SLionel Sambuc {PGP_PTAG_SS_FEATURES, "Features"},
177*ebfedea0SLionel Sambuc {0x00, NULL}, /* this is the end-of-array marker */
178*ebfedea0SLionel Sambuc };
179*ebfedea0SLionel Sambuc
180*ebfedea0SLionel Sambuc
181*ebfedea0SLionel Sambuc static pgp_map_t ss_rr_code_map[] =
182*ebfedea0SLionel Sambuc {
183*ebfedea0SLionel Sambuc {0x00, "No reason specified"},
184*ebfedea0SLionel Sambuc {0x01, "Key is superseded"},
185*ebfedea0SLionel Sambuc {0x02, "Key material has been compromised"},
186*ebfedea0SLionel Sambuc {0x03, "Key is retired and no longer used"},
187*ebfedea0SLionel Sambuc {0x20, "User ID information is no longer valid"},
188*ebfedea0SLionel Sambuc {0x00, NULL}, /* this is the end-of-array marker */
189*ebfedea0SLionel Sambuc };
190*ebfedea0SLionel Sambuc
191*ebfedea0SLionel Sambuc static pgp_map_t sig_type_map[] =
192*ebfedea0SLionel Sambuc {
193*ebfedea0SLionel Sambuc {PGP_SIG_BINARY, "Signature of a binary document"},
194*ebfedea0SLionel Sambuc {PGP_SIG_TEXT, "Signature of a canonical text document"},
195*ebfedea0SLionel Sambuc {PGP_SIG_STANDALONE, "Standalone signature"},
196*ebfedea0SLionel Sambuc {PGP_CERT_GENERIC, "Generic certification of a User ID and Public Key packet"},
197*ebfedea0SLionel Sambuc {PGP_CERT_PERSONA, "Personal certification of a User ID and Public Key packet"},
198*ebfedea0SLionel Sambuc {PGP_CERT_CASUAL, "Casual certification of a User ID and Public Key packet"},
199*ebfedea0SLionel Sambuc {PGP_CERT_POSITIVE, "Positive certification of a User ID and Public Key packet"},
200*ebfedea0SLionel Sambuc {PGP_SIG_SUBKEY, "Subkey Binding Signature"},
201*ebfedea0SLionel Sambuc {PGP_SIG_PRIMARY, "Primary Key Binding Signature"},
202*ebfedea0SLionel Sambuc {PGP_SIG_DIRECT, "Signature directly on a key"},
203*ebfedea0SLionel Sambuc {PGP_SIG_REV_KEY, "Key revocation signature"},
204*ebfedea0SLionel Sambuc {PGP_SIG_REV_SUBKEY, "Subkey revocation signature"},
205*ebfedea0SLionel Sambuc {PGP_SIG_REV_CERT, "Certification revocation signature"},
206*ebfedea0SLionel Sambuc {PGP_SIG_TIMESTAMP, "Timestamp signature"},
207*ebfedea0SLionel Sambuc {PGP_SIG_3RD_PARTY, "Third-Party Confirmation signature"},
208*ebfedea0SLionel Sambuc {0x00, NULL}, /* this is the end-of-array marker */
209*ebfedea0SLionel Sambuc };
210*ebfedea0SLionel Sambuc
211*ebfedea0SLionel Sambuc static pgp_map_t pubkey_alg_map[] =
212*ebfedea0SLionel Sambuc {
213*ebfedea0SLionel Sambuc {PGP_PKA_RSA, "RSA (Encrypt or Sign)"},
214*ebfedea0SLionel Sambuc {PGP_PKA_RSA_ENCRYPT_ONLY, "RSA Encrypt-Only"},
215*ebfedea0SLionel Sambuc {PGP_PKA_RSA_SIGN_ONLY, "RSA Sign-Only"},
216*ebfedea0SLionel Sambuc {PGP_PKA_ELGAMAL, "Elgamal (Encrypt-Only)"},
217*ebfedea0SLionel Sambuc {PGP_PKA_DSA, "DSA"},
218*ebfedea0SLionel Sambuc {PGP_PKA_RESERVED_ELLIPTIC_CURVE, "Reserved for Elliptic Curve"},
219*ebfedea0SLionel Sambuc {PGP_PKA_RESERVED_ECDSA, "Reserved for ECDSA"},
220*ebfedea0SLionel Sambuc {PGP_PKA_ELGAMAL_ENCRYPT_OR_SIGN, "Reserved (formerly Elgamal Encrypt or Sign"},
221*ebfedea0SLionel Sambuc {PGP_PKA_RESERVED_DH, "Reserved for Diffie-Hellman (X9.42)"},
222*ebfedea0SLionel Sambuc {PGP_PKA_PRIVATE00, "Private/Experimental"},
223*ebfedea0SLionel Sambuc {PGP_PKA_PRIVATE01, "Private/Experimental"},
224*ebfedea0SLionel Sambuc {PGP_PKA_PRIVATE02, "Private/Experimental"},
225*ebfedea0SLionel Sambuc {PGP_PKA_PRIVATE03, "Private/Experimental"},
226*ebfedea0SLionel Sambuc {PGP_PKA_PRIVATE04, "Private/Experimental"},
227*ebfedea0SLionel Sambuc {PGP_PKA_PRIVATE05, "Private/Experimental"},
228*ebfedea0SLionel Sambuc {PGP_PKA_PRIVATE06, "Private/Experimental"},
229*ebfedea0SLionel Sambuc {PGP_PKA_PRIVATE07, "Private/Experimental"},
230*ebfedea0SLionel Sambuc {PGP_PKA_PRIVATE08, "Private/Experimental"},
231*ebfedea0SLionel Sambuc {PGP_PKA_PRIVATE09, "Private/Experimental"},
232*ebfedea0SLionel Sambuc {PGP_PKA_PRIVATE10, "Private/Experimental"},
233*ebfedea0SLionel Sambuc {0x00, NULL}, /* this is the end-of-array marker */
234*ebfedea0SLionel Sambuc };
235*ebfedea0SLionel Sambuc
236*ebfedea0SLionel Sambuc static pgp_map_t symm_alg_map[] =
237*ebfedea0SLionel Sambuc {
238*ebfedea0SLionel Sambuc {PGP_SA_PLAINTEXT, "Plaintext or unencrypted data"},
239*ebfedea0SLionel Sambuc {PGP_SA_IDEA, "IDEA"},
240*ebfedea0SLionel Sambuc {PGP_SA_TRIPLEDES, "TripleDES"},
241*ebfedea0SLionel Sambuc {PGP_SA_CAST5, "CAST5"},
242*ebfedea0SLionel Sambuc {PGP_SA_BLOWFISH, "Blowfish"},
243*ebfedea0SLionel Sambuc {PGP_SA_AES_128, "AES (128-bit key)"},
244*ebfedea0SLionel Sambuc {PGP_SA_AES_192, "AES (192-bit key)"},
245*ebfedea0SLionel Sambuc {PGP_SA_AES_256, "AES (256-bit key)"},
246*ebfedea0SLionel Sambuc {PGP_SA_TWOFISH, "Twofish(256-bit key)"},
247*ebfedea0SLionel Sambuc {PGP_SA_CAMELLIA_128, "Camellia (128-bit key)"},
248*ebfedea0SLionel Sambuc {PGP_SA_CAMELLIA_192, "Camellia (192-bit key)"},
249*ebfedea0SLionel Sambuc {PGP_SA_CAMELLIA_256, "Camellia (256-bit key)"},
250*ebfedea0SLionel Sambuc {0x00, NULL}, /* this is the end-of-array marker */
251*ebfedea0SLionel Sambuc };
252*ebfedea0SLionel Sambuc
253*ebfedea0SLionel Sambuc static pgp_map_t hash_alg_map[] =
254*ebfedea0SLionel Sambuc {
255*ebfedea0SLionel Sambuc {PGP_HASH_MD5, "MD5"},
256*ebfedea0SLionel Sambuc {PGP_HASH_SHA1, "SHA1"},
257*ebfedea0SLionel Sambuc {PGP_HASH_RIPEMD, "RIPEMD160"},
258*ebfedea0SLionel Sambuc {PGP_HASH_SHA256, "SHA256"},
259*ebfedea0SLionel Sambuc {PGP_HASH_SHA384, "SHA384"},
260*ebfedea0SLionel Sambuc {PGP_HASH_SHA512, "SHA512"},
261*ebfedea0SLionel Sambuc {PGP_HASH_SHA224, "SHA224"},
262*ebfedea0SLionel Sambuc {0x00, NULL}, /* this is the end-of-array marker */
263*ebfedea0SLionel Sambuc };
264*ebfedea0SLionel Sambuc
265*ebfedea0SLionel Sambuc static pgp_map_t compression_alg_map[] =
266*ebfedea0SLionel Sambuc {
267*ebfedea0SLionel Sambuc {PGP_C_NONE, "Uncompressed"},
268*ebfedea0SLionel Sambuc {PGP_C_ZIP, "ZIP(RFC1951)"},
269*ebfedea0SLionel Sambuc {PGP_C_ZLIB, "ZLIB(RFC1950)"},
270*ebfedea0SLionel Sambuc {PGP_C_BZIP2, "Bzip2(BZ2)"},
271*ebfedea0SLionel Sambuc {0x00, NULL}, /* this is the end-of-array marker */
272*ebfedea0SLionel Sambuc };
273*ebfedea0SLionel Sambuc
274*ebfedea0SLionel Sambuc static pgp_bit_map_t ss_notation_map_byte0[] =
275*ebfedea0SLionel Sambuc {
276*ebfedea0SLionel Sambuc {0x80, "Human-readable"},
277*ebfedea0SLionel Sambuc {0x00, NULL},
278*ebfedea0SLionel Sambuc };
279*ebfedea0SLionel Sambuc
280*ebfedea0SLionel Sambuc static pgp_bit_map_t *ss_notation_map[] =
281*ebfedea0SLionel Sambuc {
282*ebfedea0SLionel Sambuc ss_notation_map_byte0,
283*ebfedea0SLionel Sambuc };
284*ebfedea0SLionel Sambuc
285*ebfedea0SLionel Sambuc static pgp_bit_map_t ss_feature_map_byte0[] =
286*ebfedea0SLionel Sambuc {
287*ebfedea0SLionel Sambuc {0x01, "Modification Detection"},
288*ebfedea0SLionel Sambuc {0x00, NULL},
289*ebfedea0SLionel Sambuc };
290*ebfedea0SLionel Sambuc
291*ebfedea0SLionel Sambuc static pgp_bit_map_t *ss_feature_map[] =
292*ebfedea0SLionel Sambuc {
293*ebfedea0SLionel Sambuc ss_feature_map_byte0,
294*ebfedea0SLionel Sambuc };
295*ebfedea0SLionel Sambuc
296*ebfedea0SLionel Sambuc static pgp_bit_map_t ss_key_flags_map[] =
297*ebfedea0SLionel Sambuc {
298*ebfedea0SLionel Sambuc {0x01, "May be used to certify other keys"},
299*ebfedea0SLionel Sambuc {0x02, "May be used to sign data"},
300*ebfedea0SLionel Sambuc {0x04, "May be used to encrypt communications"},
301*ebfedea0SLionel Sambuc {0x08, "May be used to encrypt storage"},
302*ebfedea0SLionel Sambuc {0x10, "Private component may have been split by a secret-sharing mechanism"},
303*ebfedea0SLionel Sambuc {0x80, "Private component may be in possession of more than one person"},
304*ebfedea0SLionel Sambuc {0x00, NULL},
305*ebfedea0SLionel Sambuc };
306*ebfedea0SLionel Sambuc
307*ebfedea0SLionel Sambuc static pgp_bit_map_t ss_key_server_prefs_map[] =
308*ebfedea0SLionel Sambuc {
309*ebfedea0SLionel Sambuc {0x80, "Key holder requests that this key only be modified or updated by the key holder or an administrator of the key server"},
310*ebfedea0SLionel Sambuc {0x00, NULL},
311*ebfedea0SLionel Sambuc };
312*ebfedea0SLionel Sambuc
313*ebfedea0SLionel Sambuc /*
314*ebfedea0SLionel Sambuc * Private functions
315*ebfedea0SLionel Sambuc */
316*ebfedea0SLionel Sambuc
317*ebfedea0SLionel Sambuc static void
list_init(pgp_list_t * list)318*ebfedea0SLionel Sambuc list_init(pgp_list_t *list)
319*ebfedea0SLionel Sambuc {
320*ebfedea0SLionel Sambuc list->size = 0;
321*ebfedea0SLionel Sambuc list->used = 0;
322*ebfedea0SLionel Sambuc list->strings = NULL;
323*ebfedea0SLionel Sambuc }
324*ebfedea0SLionel Sambuc
325*ebfedea0SLionel Sambuc static void
list_free_strings(pgp_list_t * list)326*ebfedea0SLionel Sambuc list_free_strings(pgp_list_t *list)
327*ebfedea0SLionel Sambuc {
328*ebfedea0SLionel Sambuc unsigned i;
329*ebfedea0SLionel Sambuc
330*ebfedea0SLionel Sambuc for (i = 0; i < list->used; i++) {
331*ebfedea0SLionel Sambuc free(list->strings[i]);
332*ebfedea0SLionel Sambuc list->strings[i] = NULL;
333*ebfedea0SLionel Sambuc }
334*ebfedea0SLionel Sambuc }
335*ebfedea0SLionel Sambuc
336*ebfedea0SLionel Sambuc static void
list_free(pgp_list_t * list)337*ebfedea0SLionel Sambuc list_free(pgp_list_t *list)
338*ebfedea0SLionel Sambuc {
339*ebfedea0SLionel Sambuc if (list->strings)
340*ebfedea0SLionel Sambuc free(list->strings);
341*ebfedea0SLionel Sambuc list_init(list);
342*ebfedea0SLionel Sambuc }
343*ebfedea0SLionel Sambuc
344*ebfedea0SLionel Sambuc static unsigned
list_resize(pgp_list_t * list)345*ebfedea0SLionel Sambuc list_resize(pgp_list_t *list)
346*ebfedea0SLionel Sambuc {
347*ebfedea0SLionel Sambuc /*
348*ebfedea0SLionel Sambuc * We only resize in one direction - upwards. Algorithm used : double
349*ebfedea0SLionel Sambuc * the current size then add 1
350*ebfedea0SLionel Sambuc */
351*ebfedea0SLionel Sambuc char **newstrings;
352*ebfedea0SLionel Sambuc int newsize;
353*ebfedea0SLionel Sambuc
354*ebfedea0SLionel Sambuc newsize = (list->size * 2) + 1;
355*ebfedea0SLionel Sambuc newstrings = realloc(list->strings, newsize * sizeof(char *));
356*ebfedea0SLionel Sambuc if (newstrings) {
357*ebfedea0SLionel Sambuc list->strings = newstrings;
358*ebfedea0SLionel Sambuc list->size = newsize;
359*ebfedea0SLionel Sambuc return 1;
360*ebfedea0SLionel Sambuc }
361*ebfedea0SLionel Sambuc (void) fprintf(stderr, "list_resize - bad alloc\n");
362*ebfedea0SLionel Sambuc return 0;
363*ebfedea0SLionel Sambuc }
364*ebfedea0SLionel Sambuc
365*ebfedea0SLionel Sambuc static unsigned
add_str(pgp_list_t * list,const char * str)366*ebfedea0SLionel Sambuc add_str(pgp_list_t *list, const char *str)
367*ebfedea0SLionel Sambuc {
368*ebfedea0SLionel Sambuc if (list->size == list->used && !list_resize(list)) {
369*ebfedea0SLionel Sambuc return 0;
370*ebfedea0SLionel Sambuc }
371*ebfedea0SLionel Sambuc list->strings[list->used++] = __UNCONST(str);
372*ebfedea0SLionel Sambuc return 1;
373*ebfedea0SLionel Sambuc }
374*ebfedea0SLionel Sambuc
375*ebfedea0SLionel Sambuc /* find a bitfield in a map - serial search */
376*ebfedea0SLionel Sambuc static const char *
find_bitfield(pgp_bit_map_t * map,uint8_t octet)377*ebfedea0SLionel Sambuc find_bitfield(pgp_bit_map_t *map, uint8_t octet)
378*ebfedea0SLionel Sambuc {
379*ebfedea0SLionel Sambuc pgp_bit_map_t *row;
380*ebfedea0SLionel Sambuc
381*ebfedea0SLionel Sambuc for (row = map; row->string != NULL && row->mask != octet ; row++) {
382*ebfedea0SLionel Sambuc }
383*ebfedea0SLionel Sambuc return (row->string) ? row->string : "Unknown";
384*ebfedea0SLionel Sambuc }
385*ebfedea0SLionel Sambuc
386*ebfedea0SLionel Sambuc /* ! generic function to initialise pgp_text_t structure */
387*ebfedea0SLionel Sambuc void
pgp_text_init(pgp_text_t * text)388*ebfedea0SLionel Sambuc pgp_text_init(pgp_text_t *text)
389*ebfedea0SLionel Sambuc {
390*ebfedea0SLionel Sambuc list_init(&text->known);
391*ebfedea0SLionel Sambuc list_init(&text->unknown);
392*ebfedea0SLionel Sambuc }
393*ebfedea0SLionel Sambuc
394*ebfedea0SLionel Sambuc /**
395*ebfedea0SLionel Sambuc * \ingroup Core_Print
396*ebfedea0SLionel Sambuc *
397*ebfedea0SLionel Sambuc * pgp_text_free() frees the memory used by an pgp_text_t structure
398*ebfedea0SLionel Sambuc *
399*ebfedea0SLionel Sambuc * \param text Pointer to a previously allocated structure. This structure and its contents will be freed.
400*ebfedea0SLionel Sambuc */
401*ebfedea0SLionel Sambuc void
pgp_text_free(pgp_text_t * text)402*ebfedea0SLionel Sambuc pgp_text_free(pgp_text_t *text)
403*ebfedea0SLionel Sambuc {
404*ebfedea0SLionel Sambuc /* Strings in "known" array will be constants, so don't free them */
405*ebfedea0SLionel Sambuc list_free(&text->known);
406*ebfedea0SLionel Sambuc
407*ebfedea0SLionel Sambuc /*
408*ebfedea0SLionel Sambuc * Strings in "unknown" array will be dynamically allocated, so do
409*ebfedea0SLionel Sambuc * free them
410*ebfedea0SLionel Sambuc */
411*ebfedea0SLionel Sambuc list_free_strings(&text->unknown);
412*ebfedea0SLionel Sambuc list_free(&text->unknown);
413*ebfedea0SLionel Sambuc
414*ebfedea0SLionel Sambuc free(text);
415*ebfedea0SLionel Sambuc }
416*ebfedea0SLionel Sambuc
417*ebfedea0SLionel Sambuc /* XXX: should this (and many others) be unsigned? */
418*ebfedea0SLionel Sambuc /* ! generic function which adds text derived from single octet map to text */
419*ebfedea0SLionel Sambuc static unsigned
add_str_from_octet_map(pgp_text_t * map,char * str,uint8_t octet)420*ebfedea0SLionel Sambuc add_str_from_octet_map(pgp_text_t *map, char *str, uint8_t octet)
421*ebfedea0SLionel Sambuc {
422*ebfedea0SLionel Sambuc if (str && !add_str(&map->known, str)) {
423*ebfedea0SLionel Sambuc /*
424*ebfedea0SLionel Sambuc * value recognised, but there was a problem adding it to the
425*ebfedea0SLionel Sambuc * list
426*ebfedea0SLionel Sambuc */
427*ebfedea0SLionel Sambuc /* XXX - should print out error msg here, Ben? - rachel */
428*ebfedea0SLionel Sambuc return 0;
429*ebfedea0SLionel Sambuc } else if (!str) {
430*ebfedea0SLionel Sambuc /*
431*ebfedea0SLionel Sambuc * value not recognised and there was a problem adding it to
432*ebfedea0SLionel Sambuc * the unknown list
433*ebfedea0SLionel Sambuc */
434*ebfedea0SLionel Sambuc unsigned len = 2 + 2 + 1; /* 2 for "0x", 2 for
435*ebfedea0SLionel Sambuc * single octet in hex
436*ebfedea0SLionel Sambuc * format, 1 for NUL */
437*ebfedea0SLionel Sambuc if ((str = calloc(1, len)) == NULL) {
438*ebfedea0SLionel Sambuc (void) fprintf(stderr, "add_str_from_octet_map: bad alloc\n");
439*ebfedea0SLionel Sambuc return 0;
440*ebfedea0SLionel Sambuc }
441*ebfedea0SLionel Sambuc (void) snprintf(str, len, "0x%x", octet);
442*ebfedea0SLionel Sambuc if (!add_str(&map->unknown, str)) {
443*ebfedea0SLionel Sambuc return 0;
444*ebfedea0SLionel Sambuc }
445*ebfedea0SLionel Sambuc free(str);
446*ebfedea0SLionel Sambuc }
447*ebfedea0SLionel Sambuc return 1;
448*ebfedea0SLionel Sambuc }
449*ebfedea0SLionel Sambuc
450*ebfedea0SLionel Sambuc /* ! generic function which adds text derived from single bit map to text */
451*ebfedea0SLionel Sambuc static unsigned
add_bitmap_entry(pgp_text_t * map,const char * str,uint8_t bit)452*ebfedea0SLionel Sambuc add_bitmap_entry(pgp_text_t *map, const char *str, uint8_t bit)
453*ebfedea0SLionel Sambuc {
454*ebfedea0SLionel Sambuc
455*ebfedea0SLionel Sambuc if (str && !add_str(&map->known, str)) {
456*ebfedea0SLionel Sambuc /*
457*ebfedea0SLionel Sambuc * value recognised, but there was a problem adding it to the
458*ebfedea0SLionel Sambuc * list
459*ebfedea0SLionel Sambuc */
460*ebfedea0SLionel Sambuc /* XXX - should print out error msg here, Ben? - rachel */
461*ebfedea0SLionel Sambuc return 0;
462*ebfedea0SLionel Sambuc } else if (!str) {
463*ebfedea0SLionel Sambuc /*
464*ebfedea0SLionel Sambuc * value not recognised and there was a problem adding it to
465*ebfedea0SLionel Sambuc * the unknown list
466*ebfedea0SLionel Sambuc * 2 chars of the string are the format definition, this will
467*ebfedea0SLionel Sambuc * be replaced in the output by 2 chars of hex, so the length
468*ebfedea0SLionel Sambuc * will be correct
469*ebfedea0SLionel Sambuc */
470*ebfedea0SLionel Sambuc char *newstr;
471*ebfedea0SLionel Sambuc if (asprintf(&newstr, "Unknown bit(0x%x)", bit) == -1) {
472*ebfedea0SLionel Sambuc (void) fprintf(stderr, "add_bitmap_entry: bad alloc\n");
473*ebfedea0SLionel Sambuc return 0;
474*ebfedea0SLionel Sambuc }
475*ebfedea0SLionel Sambuc if (!add_str(&map->unknown, newstr)) {
476*ebfedea0SLionel Sambuc return 0;
477*ebfedea0SLionel Sambuc }
478*ebfedea0SLionel Sambuc free(newstr);
479*ebfedea0SLionel Sambuc }
480*ebfedea0SLionel Sambuc return 1;
481*ebfedea0SLionel Sambuc }
482*ebfedea0SLionel Sambuc
483*ebfedea0SLionel Sambuc /**
484*ebfedea0SLionel Sambuc * Produce a structure containing human-readable textstrings
485*ebfedea0SLionel Sambuc * representing the recognised and unrecognised contents
486*ebfedea0SLionel Sambuc * of this byte array. text_fn() will be called on each octet in turn.
487*ebfedea0SLionel Sambuc * Each octet will generate one string representing the whole byte.
488*ebfedea0SLionel Sambuc *
489*ebfedea0SLionel Sambuc */
490*ebfedea0SLionel Sambuc
491*ebfedea0SLionel Sambuc static pgp_text_t *
text_from_bytemapped_octets(const pgp_data_t * data,const char * (* text_fn)(uint8_t octet))492*ebfedea0SLionel Sambuc text_from_bytemapped_octets(const pgp_data_t *data,
493*ebfedea0SLionel Sambuc const char *(*text_fn)(uint8_t octet))
494*ebfedea0SLionel Sambuc {
495*ebfedea0SLionel Sambuc pgp_text_t *text;
496*ebfedea0SLionel Sambuc const char *str;
497*ebfedea0SLionel Sambuc unsigned i;
498*ebfedea0SLionel Sambuc
499*ebfedea0SLionel Sambuc /*
500*ebfedea0SLionel Sambuc * ! allocate and initialise pgp_text_t structure to store derived
501*ebfedea0SLionel Sambuc * strings
502*ebfedea0SLionel Sambuc */
503*ebfedea0SLionel Sambuc if ((text = calloc(1, sizeof(*text))) == NULL) {
504*ebfedea0SLionel Sambuc return NULL;
505*ebfedea0SLionel Sambuc }
506*ebfedea0SLionel Sambuc
507*ebfedea0SLionel Sambuc pgp_text_init(text);
508*ebfedea0SLionel Sambuc
509*ebfedea0SLionel Sambuc /* ! for each octet in field ... */
510*ebfedea0SLionel Sambuc for (i = 0; i < data->len; i++) {
511*ebfedea0SLionel Sambuc /* ! derive string from octet */
512*ebfedea0SLionel Sambuc str = (*text_fn) (data->contents[i]);
513*ebfedea0SLionel Sambuc
514*ebfedea0SLionel Sambuc /* ! and add to text */
515*ebfedea0SLionel Sambuc if (!add_str_from_octet_map(text, netpgp_strdup(str),
516*ebfedea0SLionel Sambuc data->contents[i])) {
517*ebfedea0SLionel Sambuc pgp_text_free(text);
518*ebfedea0SLionel Sambuc return NULL;
519*ebfedea0SLionel Sambuc }
520*ebfedea0SLionel Sambuc }
521*ebfedea0SLionel Sambuc /*
522*ebfedea0SLionel Sambuc * ! All values have been added to either the known or the unknown
523*ebfedea0SLionel Sambuc * list
524*ebfedea0SLionel Sambuc */
525*ebfedea0SLionel Sambuc return text;
526*ebfedea0SLionel Sambuc }
527*ebfedea0SLionel Sambuc
528*ebfedea0SLionel Sambuc /**
529*ebfedea0SLionel Sambuc * Produce a structure containing human-readable textstrings
530*ebfedea0SLionel Sambuc * representing the recognised and unrecognised contents
531*ebfedea0SLionel Sambuc * of this byte array, derived from each bit of each octet.
532*ebfedea0SLionel Sambuc *
533*ebfedea0SLionel Sambuc */
534*ebfedea0SLionel Sambuc static pgp_text_t *
showall_octets_bits(pgp_data_t * data,pgp_bit_map_t ** map,size_t nmap)535*ebfedea0SLionel Sambuc showall_octets_bits(pgp_data_t *data, pgp_bit_map_t **map, size_t nmap)
536*ebfedea0SLionel Sambuc {
537*ebfedea0SLionel Sambuc pgp_text_t *text;
538*ebfedea0SLionel Sambuc const char *str;
539*ebfedea0SLionel Sambuc unsigned i;
540*ebfedea0SLionel Sambuc uint8_t mask, bit;
541*ebfedea0SLionel Sambuc int j = 0;
542*ebfedea0SLionel Sambuc
543*ebfedea0SLionel Sambuc /*
544*ebfedea0SLionel Sambuc * ! allocate and initialise pgp_text_t structure to store derived
545*ebfedea0SLionel Sambuc * strings
546*ebfedea0SLionel Sambuc */
547*ebfedea0SLionel Sambuc if ((text = calloc(1, sizeof(pgp_text_t))) == NULL) {
548*ebfedea0SLionel Sambuc return NULL;
549*ebfedea0SLionel Sambuc }
550*ebfedea0SLionel Sambuc
551*ebfedea0SLionel Sambuc pgp_text_init(text);
552*ebfedea0SLionel Sambuc
553*ebfedea0SLionel Sambuc /* ! for each octet in field ... */
554*ebfedea0SLionel Sambuc for (i = 0; i < data->len; i++) {
555*ebfedea0SLionel Sambuc /* ! for each bit in octet ... */
556*ebfedea0SLionel Sambuc mask = 0x80;
557*ebfedea0SLionel Sambuc for (j = 0; j < 8; j++, mask = (unsigned)mask >> 1) {
558*ebfedea0SLionel Sambuc bit = data->contents[i] & mask;
559*ebfedea0SLionel Sambuc if (bit) {
560*ebfedea0SLionel Sambuc str = (i >= nmap) ? "Unknown" :
561*ebfedea0SLionel Sambuc find_bitfield(map[i], bit);
562*ebfedea0SLionel Sambuc if (!add_bitmap_entry(text, str, bit)) {
563*ebfedea0SLionel Sambuc pgp_text_free(text);
564*ebfedea0SLionel Sambuc return NULL;
565*ebfedea0SLionel Sambuc }
566*ebfedea0SLionel Sambuc }
567*ebfedea0SLionel Sambuc }
568*ebfedea0SLionel Sambuc }
569*ebfedea0SLionel Sambuc return text;
570*ebfedea0SLionel Sambuc }
571*ebfedea0SLionel Sambuc
572*ebfedea0SLionel Sambuc /*
573*ebfedea0SLionel Sambuc * Public Functions
574*ebfedea0SLionel Sambuc */
575*ebfedea0SLionel Sambuc
576*ebfedea0SLionel Sambuc /**
577*ebfedea0SLionel Sambuc * \ingroup Core_Print
578*ebfedea0SLionel Sambuc * returns description of the Packet Tag
579*ebfedea0SLionel Sambuc * \param packet_tag
580*ebfedea0SLionel Sambuc * \return string or "Unknown"
581*ebfedea0SLionel Sambuc */
582*ebfedea0SLionel Sambuc const char *
pgp_show_packet_tag(pgp_content_enum packet_tag)583*ebfedea0SLionel Sambuc pgp_show_packet_tag(pgp_content_enum packet_tag)
584*ebfedea0SLionel Sambuc {
585*ebfedea0SLionel Sambuc const char *ret;
586*ebfedea0SLionel Sambuc
587*ebfedea0SLionel Sambuc ret = pgp_str_from_map(packet_tag, packet_tag_map);
588*ebfedea0SLionel Sambuc if (!ret) {
589*ebfedea0SLionel Sambuc ret = "Unknown Tag";
590*ebfedea0SLionel Sambuc }
591*ebfedea0SLionel Sambuc return ret;
592*ebfedea0SLionel Sambuc }
593*ebfedea0SLionel Sambuc
594*ebfedea0SLionel Sambuc /**
595*ebfedea0SLionel Sambuc * \ingroup Core_Print
596*ebfedea0SLionel Sambuc *
597*ebfedea0SLionel Sambuc * returns description of the Signature Sub-Packet type
598*ebfedea0SLionel Sambuc * \param ss_type Signature Sub-Packet type
599*ebfedea0SLionel Sambuc * \return string or "Unknown"
600*ebfedea0SLionel Sambuc */
601*ebfedea0SLionel Sambuc const char *
pgp_show_ss_type(pgp_content_enum ss_type)602*ebfedea0SLionel Sambuc pgp_show_ss_type(pgp_content_enum ss_type)
603*ebfedea0SLionel Sambuc {
604*ebfedea0SLionel Sambuc return pgp_str_from_map(ss_type, ss_type_map);
605*ebfedea0SLionel Sambuc }
606*ebfedea0SLionel Sambuc
607*ebfedea0SLionel Sambuc /**
608*ebfedea0SLionel Sambuc * \ingroup Core_Print
609*ebfedea0SLionel Sambuc *
610*ebfedea0SLionel Sambuc * returns description of the Revocation Reason code
611*ebfedea0SLionel Sambuc * \param ss_rr_code Revocation Reason code
612*ebfedea0SLionel Sambuc * \return string or "Unknown"
613*ebfedea0SLionel Sambuc */
614*ebfedea0SLionel Sambuc const char *
pgp_show_ss_rr_code(pgp_ss_rr_code_t ss_rr_code)615*ebfedea0SLionel Sambuc pgp_show_ss_rr_code(pgp_ss_rr_code_t ss_rr_code)
616*ebfedea0SLionel Sambuc {
617*ebfedea0SLionel Sambuc return pgp_str_from_map(ss_rr_code, ss_rr_code_map);
618*ebfedea0SLionel Sambuc }
619*ebfedea0SLionel Sambuc
620*ebfedea0SLionel Sambuc /**
621*ebfedea0SLionel Sambuc * \ingroup Core_Print
622*ebfedea0SLionel Sambuc *
623*ebfedea0SLionel Sambuc * returns description of the given Signature type
624*ebfedea0SLionel Sambuc * \param sig_type Signature type
625*ebfedea0SLionel Sambuc * \return string or "Unknown"
626*ebfedea0SLionel Sambuc */
627*ebfedea0SLionel Sambuc const char *
pgp_show_sig_type(pgp_sig_type_t sig_type)628*ebfedea0SLionel Sambuc pgp_show_sig_type(pgp_sig_type_t sig_type)
629*ebfedea0SLionel Sambuc {
630*ebfedea0SLionel Sambuc return pgp_str_from_map(sig_type, sig_type_map);
631*ebfedea0SLionel Sambuc }
632*ebfedea0SLionel Sambuc
633*ebfedea0SLionel Sambuc /**
634*ebfedea0SLionel Sambuc * \ingroup Core_Print
635*ebfedea0SLionel Sambuc *
636*ebfedea0SLionel Sambuc * returns description of the given Public Key Algorithm
637*ebfedea0SLionel Sambuc * \param pka Public Key Algorithm type
638*ebfedea0SLionel Sambuc * \return string or "Unknown"
639*ebfedea0SLionel Sambuc */
640*ebfedea0SLionel Sambuc const char *
pgp_show_pka(pgp_pubkey_alg_t pka)641*ebfedea0SLionel Sambuc pgp_show_pka(pgp_pubkey_alg_t pka)
642*ebfedea0SLionel Sambuc {
643*ebfedea0SLionel Sambuc return pgp_str_from_map(pka, pubkey_alg_map);
644*ebfedea0SLionel Sambuc }
645*ebfedea0SLionel Sambuc
646*ebfedea0SLionel Sambuc /**
647*ebfedea0SLionel Sambuc * \ingroup Core_Print
648*ebfedea0SLionel Sambuc * returns description of the Preferred Compression
649*ebfedea0SLionel Sambuc * \param octet Preferred Compression
650*ebfedea0SLionel Sambuc * \return string or "Unknown"
651*ebfedea0SLionel Sambuc */
652*ebfedea0SLionel Sambuc const char *
pgp_show_ss_zpref(uint8_t octet)653*ebfedea0SLionel Sambuc pgp_show_ss_zpref(uint8_t octet)
654*ebfedea0SLionel Sambuc {
655*ebfedea0SLionel Sambuc return pgp_str_from_map(octet, compression_alg_map);
656*ebfedea0SLionel Sambuc }
657*ebfedea0SLionel Sambuc
658*ebfedea0SLionel Sambuc /**
659*ebfedea0SLionel Sambuc * \ingroup Core_Print
660*ebfedea0SLionel Sambuc *
661*ebfedea0SLionel Sambuc * returns set of descriptions of the given Preferred Compression Algorithms
662*ebfedea0SLionel Sambuc * \param ss_zpref Array of Preferred Compression Algorithms
663*ebfedea0SLionel Sambuc * \return NULL if cannot allocate memory or other error
664*ebfedea0SLionel Sambuc * \return pointer to structure, if no error
665*ebfedea0SLionel Sambuc */
666*ebfedea0SLionel Sambuc pgp_text_t *
pgp_showall_ss_zpref(const pgp_data_t * ss_zpref)667*ebfedea0SLionel Sambuc pgp_showall_ss_zpref(const pgp_data_t *ss_zpref)
668*ebfedea0SLionel Sambuc {
669*ebfedea0SLionel Sambuc return text_from_bytemapped_octets(ss_zpref,
670*ebfedea0SLionel Sambuc &pgp_show_ss_zpref);
671*ebfedea0SLionel Sambuc }
672*ebfedea0SLionel Sambuc
673*ebfedea0SLionel Sambuc
674*ebfedea0SLionel Sambuc /**
675*ebfedea0SLionel Sambuc * \ingroup Core_Print
676*ebfedea0SLionel Sambuc *
677*ebfedea0SLionel Sambuc * returns description of the Hash Algorithm type
678*ebfedea0SLionel Sambuc * \param hash Hash Algorithm type
679*ebfedea0SLionel Sambuc * \return string or "Unknown"
680*ebfedea0SLionel Sambuc */
681*ebfedea0SLionel Sambuc const char *
pgp_show_hash_alg(uint8_t hash)682*ebfedea0SLionel Sambuc pgp_show_hash_alg(uint8_t hash)
683*ebfedea0SLionel Sambuc {
684*ebfedea0SLionel Sambuc return pgp_str_from_map(hash, hash_alg_map);
685*ebfedea0SLionel Sambuc }
686*ebfedea0SLionel Sambuc
687*ebfedea0SLionel Sambuc /**
688*ebfedea0SLionel Sambuc * \ingroup Core_Print
689*ebfedea0SLionel Sambuc *
690*ebfedea0SLionel Sambuc * returns set of descriptions of the given Preferred Hash Algorithms
691*ebfedea0SLionel Sambuc * \param ss_hashpref Array of Preferred Hash Algorithms
692*ebfedea0SLionel Sambuc * \return NULL if cannot allocate memory or other error
693*ebfedea0SLionel Sambuc * \return pointer to structure, if no error
694*ebfedea0SLionel Sambuc */
695*ebfedea0SLionel Sambuc pgp_text_t *
pgp_showall_ss_hashpref(const pgp_data_t * ss_hashpref)696*ebfedea0SLionel Sambuc pgp_showall_ss_hashpref(const pgp_data_t *ss_hashpref)
697*ebfedea0SLionel Sambuc {
698*ebfedea0SLionel Sambuc return text_from_bytemapped_octets(ss_hashpref,
699*ebfedea0SLionel Sambuc &pgp_show_hash_alg);
700*ebfedea0SLionel Sambuc }
701*ebfedea0SLionel Sambuc
702*ebfedea0SLionel Sambuc const char *
pgp_show_symm_alg(uint8_t hash)703*ebfedea0SLionel Sambuc pgp_show_symm_alg(uint8_t hash)
704*ebfedea0SLionel Sambuc {
705*ebfedea0SLionel Sambuc return pgp_str_from_map(hash, symm_alg_map);
706*ebfedea0SLionel Sambuc }
707*ebfedea0SLionel Sambuc
708*ebfedea0SLionel Sambuc /**
709*ebfedea0SLionel Sambuc * \ingroup Core_Print
710*ebfedea0SLionel Sambuc * returns description of the given Preferred Symmetric Key Algorithm
711*ebfedea0SLionel Sambuc * \param octet
712*ebfedea0SLionel Sambuc * \return string or "Unknown"
713*ebfedea0SLionel Sambuc */
714*ebfedea0SLionel Sambuc const char *
pgp_show_ss_skapref(uint8_t octet)715*ebfedea0SLionel Sambuc pgp_show_ss_skapref(uint8_t octet)
716*ebfedea0SLionel Sambuc {
717*ebfedea0SLionel Sambuc return pgp_str_from_map(octet, symm_alg_map);
718*ebfedea0SLionel Sambuc }
719*ebfedea0SLionel Sambuc
720*ebfedea0SLionel Sambuc /**
721*ebfedea0SLionel Sambuc * \ingroup Core_Print
722*ebfedea0SLionel Sambuc *
723*ebfedea0SLionel Sambuc * returns set of descriptions of the given Preferred Symmetric Key Algorithms
724*ebfedea0SLionel Sambuc * \param ss_skapref Array of Preferred Symmetric Key Algorithms
725*ebfedea0SLionel Sambuc * \return NULL if cannot allocate memory or other error
726*ebfedea0SLionel Sambuc * \return pointer to structure, if no error
727*ebfedea0SLionel Sambuc */
728*ebfedea0SLionel Sambuc pgp_text_t *
pgp_showall_ss_skapref(const pgp_data_t * ss_skapref)729*ebfedea0SLionel Sambuc pgp_showall_ss_skapref(const pgp_data_t *ss_skapref)
730*ebfedea0SLionel Sambuc {
731*ebfedea0SLionel Sambuc return text_from_bytemapped_octets(ss_skapref,
732*ebfedea0SLionel Sambuc &pgp_show_ss_skapref);
733*ebfedea0SLionel Sambuc }
734*ebfedea0SLionel Sambuc
735*ebfedea0SLionel Sambuc /**
736*ebfedea0SLionel Sambuc * \ingroup Core_Print
737*ebfedea0SLionel Sambuc * returns description of one SS Feature
738*ebfedea0SLionel Sambuc * \param octet
739*ebfedea0SLionel Sambuc * \return string or "Unknown"
740*ebfedea0SLionel Sambuc */
741*ebfedea0SLionel Sambuc static const char *
show_ss_feature(uint8_t octet,unsigned offset)742*ebfedea0SLionel Sambuc show_ss_feature(uint8_t octet, unsigned offset)
743*ebfedea0SLionel Sambuc {
744*ebfedea0SLionel Sambuc if (offset >= PGP_ARRAY_SIZE(ss_feature_map)) {
745*ebfedea0SLionel Sambuc return "Unknown";
746*ebfedea0SLionel Sambuc }
747*ebfedea0SLionel Sambuc return find_bitfield(ss_feature_map[offset], octet);
748*ebfedea0SLionel Sambuc }
749*ebfedea0SLionel Sambuc
750*ebfedea0SLionel Sambuc /**
751*ebfedea0SLionel Sambuc * \ingroup Core_Print
752*ebfedea0SLionel Sambuc *
753*ebfedea0SLionel Sambuc * returns set of descriptions of the given SS Features
754*ebfedea0SLionel Sambuc * \param ss_features Signature Sub-Packet Features
755*ebfedea0SLionel Sambuc * \return NULL if cannot allocate memory or other error
756*ebfedea0SLionel Sambuc * \return pointer to structure, if no error
757*ebfedea0SLionel Sambuc */
758*ebfedea0SLionel Sambuc /* XXX: shouldn't this use show_all_octets_bits? */
759*ebfedea0SLionel Sambuc pgp_text_t *
pgp_showall_ss_features(pgp_data_t ss_features)760*ebfedea0SLionel Sambuc pgp_showall_ss_features(pgp_data_t ss_features)
761*ebfedea0SLionel Sambuc {
762*ebfedea0SLionel Sambuc pgp_text_t *text;
763*ebfedea0SLionel Sambuc const char *str;
764*ebfedea0SLionel Sambuc unsigned i;
765*ebfedea0SLionel Sambuc uint8_t mask, bit;
766*ebfedea0SLionel Sambuc int j;
767*ebfedea0SLionel Sambuc
768*ebfedea0SLionel Sambuc if ((text = calloc(1, sizeof(*text))) == NULL) {
769*ebfedea0SLionel Sambuc return NULL;
770*ebfedea0SLionel Sambuc }
771*ebfedea0SLionel Sambuc
772*ebfedea0SLionel Sambuc pgp_text_init(text);
773*ebfedea0SLionel Sambuc
774*ebfedea0SLionel Sambuc for (i = 0; i < ss_features.len; i++) {
775*ebfedea0SLionel Sambuc mask = 0x80;
776*ebfedea0SLionel Sambuc for (j = 0; j < 8; j++, mask = (unsigned)mask >> 1) {
777*ebfedea0SLionel Sambuc bit = ss_features.contents[i] & mask;
778*ebfedea0SLionel Sambuc if (bit) {
779*ebfedea0SLionel Sambuc str = show_ss_feature(bit, i);
780*ebfedea0SLionel Sambuc if (!add_bitmap_entry(text, str, bit)) {
781*ebfedea0SLionel Sambuc pgp_text_free(text);
782*ebfedea0SLionel Sambuc return NULL;
783*ebfedea0SLionel Sambuc }
784*ebfedea0SLionel Sambuc }
785*ebfedea0SLionel Sambuc }
786*ebfedea0SLionel Sambuc }
787*ebfedea0SLionel Sambuc return text;
788*ebfedea0SLionel Sambuc }
789*ebfedea0SLionel Sambuc
790*ebfedea0SLionel Sambuc /**
791*ebfedea0SLionel Sambuc * \ingroup Core_Print
792*ebfedea0SLionel Sambuc * returns description of SS Key Flag
793*ebfedea0SLionel Sambuc * \param octet
794*ebfedea0SLionel Sambuc * \param map
795*ebfedea0SLionel Sambuc * \return
796*ebfedea0SLionel Sambuc */
797*ebfedea0SLionel Sambuc const char *
pgp_show_ss_key_flag(uint8_t octet,pgp_bit_map_t * map)798*ebfedea0SLionel Sambuc pgp_show_ss_key_flag(uint8_t octet, pgp_bit_map_t *map)
799*ebfedea0SLionel Sambuc {
800*ebfedea0SLionel Sambuc return find_bitfield(map, octet);
801*ebfedea0SLionel Sambuc }
802*ebfedea0SLionel Sambuc
803*ebfedea0SLionel Sambuc /**
804*ebfedea0SLionel Sambuc * \ingroup Core_Print
805*ebfedea0SLionel Sambuc *
806*ebfedea0SLionel Sambuc * returns set of descriptions of the given Preferred Key Flags
807*ebfedea0SLionel Sambuc * \param ss_key_flags Array of Key Flags
808*ebfedea0SLionel Sambuc * \return NULL if cannot allocate memory or other error
809*ebfedea0SLionel Sambuc * \return pointer to structure, if no error
810*ebfedea0SLionel Sambuc */
811*ebfedea0SLionel Sambuc pgp_text_t *
pgp_showall_ss_key_flags(const pgp_data_t * ss_key_flags)812*ebfedea0SLionel Sambuc pgp_showall_ss_key_flags(const pgp_data_t *ss_key_flags)
813*ebfedea0SLionel Sambuc {
814*ebfedea0SLionel Sambuc pgp_text_t *text;
815*ebfedea0SLionel Sambuc const char *str;
816*ebfedea0SLionel Sambuc uint8_t mask, bit;
817*ebfedea0SLionel Sambuc int i;
818*ebfedea0SLionel Sambuc
819*ebfedea0SLionel Sambuc if ((text = calloc(1, sizeof(*text))) == NULL) {
820*ebfedea0SLionel Sambuc return NULL;
821*ebfedea0SLionel Sambuc }
822*ebfedea0SLionel Sambuc
823*ebfedea0SLionel Sambuc pgp_text_init(text);
824*ebfedea0SLionel Sambuc
825*ebfedea0SLionel Sambuc /* xxx - TBD: extend to handle multiple octets of bits - rachel */
826*ebfedea0SLionel Sambuc for (i = 0, mask = 0x80; i < 8; i++, mask = (unsigned)mask >> 1) {
827*ebfedea0SLionel Sambuc bit = ss_key_flags->contents[0] & mask;
828*ebfedea0SLionel Sambuc if (bit) {
829*ebfedea0SLionel Sambuc str = pgp_show_ss_key_flag(bit, ss_key_flags_map);
830*ebfedea0SLionel Sambuc if (!add_bitmap_entry(text, netpgp_strdup(str), bit)) {
831*ebfedea0SLionel Sambuc pgp_text_free(text);
832*ebfedea0SLionel Sambuc return NULL;
833*ebfedea0SLionel Sambuc }
834*ebfedea0SLionel Sambuc }
835*ebfedea0SLionel Sambuc }
836*ebfedea0SLionel Sambuc /*
837*ebfedea0SLionel Sambuc * xxx - must add error text if more than one octet. Only one
838*ebfedea0SLionel Sambuc * currently specified -- rachel
839*ebfedea0SLionel Sambuc */
840*ebfedea0SLionel Sambuc return text;
841*ebfedea0SLionel Sambuc }
842*ebfedea0SLionel Sambuc
843*ebfedea0SLionel Sambuc /**
844*ebfedea0SLionel Sambuc * \ingroup Core_Print
845*ebfedea0SLionel Sambuc *
846*ebfedea0SLionel Sambuc * returns description of one given Key Server Preference
847*ebfedea0SLionel Sambuc *
848*ebfedea0SLionel Sambuc * \param prefs Byte containing bitfield of preferences
849*ebfedea0SLionel Sambuc * \param map
850*ebfedea0SLionel Sambuc * \return string or "Unknown"
851*ebfedea0SLionel Sambuc */
852*ebfedea0SLionel Sambuc const char *
pgp_show_keyserv_pref(uint8_t prefs,pgp_bit_map_t * map)853*ebfedea0SLionel Sambuc pgp_show_keyserv_pref(uint8_t prefs, pgp_bit_map_t *map)
854*ebfedea0SLionel Sambuc {
855*ebfedea0SLionel Sambuc return find_bitfield(map, prefs);
856*ebfedea0SLionel Sambuc }
857*ebfedea0SLionel Sambuc
858*ebfedea0SLionel Sambuc /**
859*ebfedea0SLionel Sambuc * \ingroup Core_Print
860*ebfedea0SLionel Sambuc * returns set of descriptions of given Key Server Preferences
861*ebfedea0SLionel Sambuc * \param ss_key_server_prefs
862*ebfedea0SLionel Sambuc * \return NULL if cannot allocate memory or other error
863*ebfedea0SLionel Sambuc * \return pointer to structure, if no error
864*ebfedea0SLionel Sambuc *
865*ebfedea0SLionel Sambuc */
866*ebfedea0SLionel Sambuc pgp_text_t *
pgp_show_keyserv_prefs(const pgp_data_t * prefs)867*ebfedea0SLionel Sambuc pgp_show_keyserv_prefs(const pgp_data_t *prefs)
868*ebfedea0SLionel Sambuc {
869*ebfedea0SLionel Sambuc pgp_text_t *text;
870*ebfedea0SLionel Sambuc const char *str;
871*ebfedea0SLionel Sambuc uint8_t mask, bit;
872*ebfedea0SLionel Sambuc int i = 0;
873*ebfedea0SLionel Sambuc
874*ebfedea0SLionel Sambuc if ((text = calloc(1, sizeof(*text))) == NULL) {
875*ebfedea0SLionel Sambuc return NULL;
876*ebfedea0SLionel Sambuc }
877*ebfedea0SLionel Sambuc
878*ebfedea0SLionel Sambuc pgp_text_init(text);
879*ebfedea0SLionel Sambuc
880*ebfedea0SLionel Sambuc /* xxx - TBD: extend to handle multiple octets of bits - rachel */
881*ebfedea0SLionel Sambuc
882*ebfedea0SLionel Sambuc for (i = 0, mask = 0x80; i < 8; i++, mask = (unsigned)mask >> 1) {
883*ebfedea0SLionel Sambuc bit = prefs->contents[0] & mask;
884*ebfedea0SLionel Sambuc if (bit) {
885*ebfedea0SLionel Sambuc str = pgp_show_keyserv_pref(bit,
886*ebfedea0SLionel Sambuc ss_key_server_prefs_map);
887*ebfedea0SLionel Sambuc if (!add_bitmap_entry(text, netpgp_strdup(str), bit)) {
888*ebfedea0SLionel Sambuc pgp_text_free(text);
889*ebfedea0SLionel Sambuc return NULL;
890*ebfedea0SLionel Sambuc }
891*ebfedea0SLionel Sambuc }
892*ebfedea0SLionel Sambuc }
893*ebfedea0SLionel Sambuc /*
894*ebfedea0SLionel Sambuc * xxx - must add error text if more than one octet. Only one
895*ebfedea0SLionel Sambuc * currently specified -- rachel
896*ebfedea0SLionel Sambuc */
897*ebfedea0SLionel Sambuc return text;
898*ebfedea0SLionel Sambuc }
899*ebfedea0SLionel Sambuc
900*ebfedea0SLionel Sambuc /**
901*ebfedea0SLionel Sambuc * \ingroup Core_Print
902*ebfedea0SLionel Sambuc *
903*ebfedea0SLionel Sambuc * returns set of descriptions of the given SS Notation Data Flags
904*ebfedea0SLionel Sambuc * \param ss_notation Signature Sub-Packet Notation Data
905*ebfedea0SLionel Sambuc * \return NULL if cannot allocate memory or other error
906*ebfedea0SLionel Sambuc * \return pointer to structure, if no error
907*ebfedea0SLionel Sambuc */
908*ebfedea0SLionel Sambuc pgp_text_t *
pgp_showall_notation(pgp_ss_notation_t ss_notation)909*ebfedea0SLionel Sambuc pgp_showall_notation(pgp_ss_notation_t ss_notation)
910*ebfedea0SLionel Sambuc {
911*ebfedea0SLionel Sambuc return showall_octets_bits(&ss_notation.flags,
912*ebfedea0SLionel Sambuc ss_notation_map,
913*ebfedea0SLionel Sambuc PGP_ARRAY_SIZE(ss_notation_map));
914*ebfedea0SLionel Sambuc }
915