aboutsummaryrefslogtreecommitdiffstats
path: root/g10/parse-packet.c
diff options
context:
space:
mode:
Diffstat (limited to 'g10/parse-packet.c')
-rw-r--r--g10/parse-packet.c385
1 files changed, 192 insertions, 193 deletions
diff --git a/g10/parse-packet.c b/g10/parse-packet.c
index e2a5ea39d..2065c22ef 100644
--- a/g10/parse-packet.c
+++ b/g10/parse-packet.c
@@ -1,6 +1,6 @@
/* parse-packet.c - read packets
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
- * 2007, 2009 Free Software Foundation, Inc.
+ * 2007, 2009, 2010 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -37,7 +37,7 @@
static int mpi_print_mode;
static int list_mode;
-static FILE *listfp;
+static estream_t listfp;
static int parse (IOBUF inp, PACKET * pkt, int onlykeypkts,
off_t * retpos, int *skip, IOBUF out, int do_skip
@@ -169,7 +169,7 @@ set_packet_list_mode (int mode)
list_mode = mode;
/* FIXME(gcrypt) mpi_print_mode = DBG_MPI; */
/* We use stdout print only if invoked by the --list-packets command
- but switch to stderr in all otehr cases. This breaks the
+ but switch to stderr in all other cases. This breaks the
previous behaviour but that seems to be more of a bug than
intentional. I don't believe that any application makes use of
this long standing annoying way of printing to stdout except when
@@ -180,11 +180,11 @@ set_packet_list_mode (int mode)
stream.
Using stderr is not actually very clean because it bypasses the
- logging code but it is a special thing anyay. I am not sure
+ logging code but it is a special thing anyway. I am not sure
whether using log_stream() would be better. Perhaps we should
enable the list mdoe only with a special option. */
if (!listfp)
- listfp = opt.list_packets == 2 ? stdout : stderr;
+ listfp = opt.list_packets == 2 ? es_stdout : es_stderr;
return old;
}
@@ -639,14 +639,14 @@ dump_hex_line (int c, int *i)
if (*i && !(*i % 8))
{
if (*i && !(*i % 24))
- fprintf (listfp, "\n%4d:", *i);
+ es_fprintf (listfp, "\n%4d:", *i);
else
- putc (' ', listfp);
+ es_putc (' ', listfp);
}
if (c == -1)
- fprintf (listfp, " EOF");
+ es_fprintf (listfp, " EOF");
else
- fprintf (listfp, " %02x", c);
+ es_fprintf (listfp, " %02x", c);
++*i;
}
@@ -694,12 +694,12 @@ skip_packet (IOBUF inp, int pkttype, unsigned long pktlen, int partial)
{
if (list_mode)
{
- fprintf (listfp, ":unknown packet: type %2d, length %lu\n",
- pkttype, pktlen);
+ es_fprintf (listfp, ":unknown packet: type %2d, length %lu\n",
+ pkttype, pktlen);
if (pkttype)
{
int c, i = 0;
- fputs ("dump:", listfp);
+ es_fputs ("dump:", listfp);
if (partial)
{
while ((c = iobuf_get (inp)) != -1)
@@ -714,7 +714,7 @@ skip_packet (IOBUF inp, int pkttype, unsigned long pktlen, int partial)
break;
}
}
- putc ('\n', listfp);
+ es_putc ('\n', listfp);
return;
}
}
@@ -770,7 +770,7 @@ parse_marker (IOBUF inp, int pkttype, unsigned long pktlen)
}
if (list_mode)
- fputs (":marker packet: PGP\n", listfp);
+ es_fputs (":marker packet: PGP\n", listfp);
return 0;
@@ -870,22 +870,21 @@ parse_symkeyenc (IOBUF inp, int pkttype, unsigned long pktlen,
if (list_mode)
{
- fprintf (listfp,
- ":symkey enc packet: version %d, cipher %d, s2k %d, hash %d",
- version, cipher_algo, s2kmode, hash_algo);
+ es_fprintf (listfp,
+ ":symkey enc packet: version %d, cipher %d, s2k %d, hash %d",
+ version, cipher_algo, s2kmode, hash_algo);
if (seskeylen)
- fprintf (listfp, ", seskey %d bits", (seskeylen - 1) * 8);
- fprintf (listfp, "\n");
+ es_fprintf (listfp, ", seskey %d bits", (seskeylen - 1) * 8);
+ es_fprintf (listfp, "\n");
if (s2kmode == 1 || s2kmode == 3)
{
- fprintf (listfp, "\tsalt ");
- for (i = 0; i < 8; i++)
- fprintf (listfp, "%02x", k->s2k.salt[i]);
+ es_fprintf (listfp, "\tsalt ");
+ es_write_hexstring (listfp, k->s2k.salt, 8, 0, NULL);
if (s2kmode == 3)
- fprintf (listfp, ", count %lu (%lu)",
- S2K_DECODE_COUNT ((ulong) k->s2k.count),
- (ulong) k->s2k.count);
- fprintf (listfp, "\n");
+ es_fprintf (listfp, ", count %lu (%lu)",
+ S2K_DECODE_COUNT ((ulong) k->s2k.count),
+ (ulong) k->s2k.count);
+ es_fprintf (listfp, "\n");
}
}
@@ -927,16 +926,16 @@ parse_pubkeyenc (IOBUF inp, int pkttype, unsigned long pktlen,
pktlen--;
k->throw_keyid = 0; /* Only used as flag for build_packet. */
if (list_mode)
- fprintf (listfp,
- ":pubkey enc packet: version %d, algo %d, keyid %08lX%08lX\n",
- k->version, k->pubkey_algo, (ulong) k->keyid[0],
- (ulong) k->keyid[1]);
+ es_fprintf (listfp,
+ ":pubkey enc packet: version %d, algo %d, keyid %08lX%08lX\n",
+ k->version, k->pubkey_algo, (ulong) k->keyid[0],
+ (ulong) k->keyid[1]);
ndata = pubkey_get_nenc (k->pubkey_algo);
if (!ndata)
{
if (list_mode)
- fprintf (listfp, "\tunsupported algorithm %d\n", k->pubkey_algo);
+ es_fprintf (listfp, "\tunsupported algorithm %d\n", k->pubkey_algo);
unknown_pubkey_warning (k->pubkey_algo);
k->data[0] = NULL; /* No need to store the encrypted data. */
}
@@ -949,9 +948,9 @@ parse_pubkeyenc (IOBUF inp, int pkttype, unsigned long pktlen,
pktlen -= n;
if (list_mode)
{
- fprintf (listfp, "\tdata: ");
+ es_fprintf (listfp, "\tdata: ");
mpi_print (listfp, k->data[i], mpi_print_mode);
- putc ('\n', listfp);
+ es_putc ('\n', listfp);
}
if (!k->data[i])
rc = gpg_error (GPG_ERR_INV_PACKET);
@@ -976,98 +975,98 @@ dump_sig_subpkt (int hashed, int type, int critical,
* and add an additional notice. */
if (type == SIGSUBPKT_ARR && !hashed)
{
- fprintf (listfp,
- "\tsubpkt %d len %u (additional recipient request)\n"
- "WARNING: PGP versions > 5.0 and < 6.5.8 will automagically "
- "encrypt to this key and thereby reveal the plaintext to "
- "the owner of this ARR key. Detailed info follows:\n",
- type, (unsigned) length);
+ es_fprintf (listfp,
+ "\tsubpkt %d len %u (additional recipient request)\n"
+ "WARNING: PGP versions > 5.0 and < 6.5.8 will automagically "
+ "encrypt to this key and thereby reveal the plaintext to "
+ "the owner of this ARR key. Detailed info follows:\n",
+ type, (unsigned) length);
}
buffer++;
length--;
- fprintf (listfp, "\t%s%ssubpkt %d len %u (", /*) */
- critical ? "critical " : "",
- hashed ? "hashed " : "", type, (unsigned) length);
+ es_fprintf (listfp, "\t%s%ssubpkt %d len %u (", /*) */
+ critical ? "critical " : "",
+ hashed ? "hashed " : "", type, (unsigned) length);
if (length > buflen)
{
- fprintf (listfp, "too short: buffer is only %u)\n", (unsigned) buflen);
+ es_fprintf (listfp, "too short: buffer is only %u)\n", (unsigned) buflen);
return;
}
switch (type)
{
case SIGSUBPKT_SIG_CREATED:
if (length >= 4)
- fprintf (listfp, "sig created %s",
- strtimestamp (buffer_to_u32 (buffer)));
+ es_fprintf (listfp, "sig created %s",
+ strtimestamp (buffer_to_u32 (buffer)));
break;
case SIGSUBPKT_SIG_EXPIRE:
if (length >= 4)
{
if (buffer_to_u32 (buffer))
- fprintf (listfp, "sig expires after %s",
- strtimevalue (buffer_to_u32 (buffer)));
+ es_fprintf (listfp, "sig expires after %s",
+ strtimevalue (buffer_to_u32 (buffer)));
else
- fprintf (listfp, "sig does not expire");
+ es_fprintf (listfp, "sig does not expire");
}
break;
case SIGSUBPKT_EXPORTABLE:
if (length)
- fprintf (listfp, "%sexportable", *buffer ? "" : "not ");
+ es_fprintf (listfp, "%sexportable", *buffer ? "" : "not ");
break;
case SIGSUBPKT_TRUST:
if (length != 2)
p = "[invalid trust subpacket]";
else
- fprintf (listfp, "trust signature of depth %d, value %d", buffer[0],
- buffer[1]);
+ es_fprintf (listfp, "trust signature of depth %d, value %d", buffer[0],
+ buffer[1]);
break;
case SIGSUBPKT_REGEXP:
if (!length)
p = "[invalid regexp subpacket]";
else
- fprintf (listfp, "regular expression: \"%s\"", buffer);
+ es_fprintf (listfp, "regular expression: \"%s\"", buffer);
break;
case SIGSUBPKT_REVOCABLE:
if (length)
- fprintf (listfp, "%srevocable", *buffer ? "" : "not ");
+ es_fprintf (listfp, "%srevocable", *buffer ? "" : "not ");
break;
case SIGSUBPKT_KEY_EXPIRE:
if (length >= 4)
{
if (buffer_to_u32 (buffer))
- fprintf (listfp, "key expires after %s",
- strtimevalue (buffer_to_u32 (buffer)));
+ es_fprintf (listfp, "key expires after %s",
+ strtimevalue (buffer_to_u32 (buffer)));
else
- fprintf (listfp, "key does not expire");
+ es_fprintf (listfp, "key does not expire");
}
break;
case SIGSUBPKT_PREF_SYM:
- fputs ("pref-sym-algos:", listfp);
+ es_fputs ("pref-sym-algos:", listfp);
for (i = 0; i < length; i++)
- fprintf (listfp, " %d", buffer[i]);
+ es_fprintf (listfp, " %d", buffer[i]);
break;
case SIGSUBPKT_REV_KEY:
- fputs ("revocation key: ", listfp);
+ es_fputs ("revocation key: ", listfp);
if (length < 22)
p = "[too short]";
else
{
- fprintf (listfp, "c=%02x a=%d f=", buffer[0], buffer[1]);
+ es_fprintf (listfp, "c=%02x a=%d f=", buffer[0], buffer[1]);
for (i = 2; i < length; i++)
- fprintf (listfp, "%02X", buffer[i]);
+ es_fprintf (listfp, "%02X", buffer[i]);
}
break;
case SIGSUBPKT_ISSUER:
if (length >= 8)
- fprintf (listfp, "issuer key ID %08lX%08lX",
- (ulong) buffer_to_u32 (buffer),
- (ulong) buffer_to_u32 (buffer + 4));
+ es_fprintf (listfp, "issuer key ID %08lX%08lX",
+ (ulong) buffer_to_u32 (buffer),
+ (ulong) buffer_to_u32 (buffer + 4));
break;
case SIGSUBPKT_NOTATION:
{
- fputs ("notation: ", listfp);
+ es_fputs ("notation: ", listfp);
if (length < 8)
p = "[too short]";
else
@@ -1082,11 +1081,11 @@ dump_sig_subpkt (int hashed, int type, int critical,
p = "[error]";
else
{
- print_string (listfp, s, n1, ')');
- putc ('=', listfp);
+ es_write_sanitized (listfp, s, n1, ")", NULL);
+ es_putc ('=', listfp);
if (*buffer & 0x80)
- print_string (listfp, s + n1, n2, ')');
+ es_write_sanitized (listfp, s + n1, n2, ")", NULL);
else
p = "[not human readable]";
}
@@ -1094,35 +1093,35 @@ dump_sig_subpkt (int hashed, int type, int critical,
}
break;
case SIGSUBPKT_PREF_HASH:
- fputs ("pref-hash-algos:", listfp);
+ es_fputs ("pref-hash-algos:", listfp);
for (i = 0; i < length; i++)
- fprintf (listfp, " %d", buffer[i]);
+ es_fprintf (listfp, " %d", buffer[i]);
break;
case SIGSUBPKT_PREF_COMPR:
- fputs ("pref-zip-algos:", listfp);
+ es_fputs ("pref-zip-algos:", listfp);
for (i = 0; i < length; i++)
- fprintf (listfp, " %d", buffer[i]);
+ es_fprintf (listfp, " %d", buffer[i]);
break;
case SIGSUBPKT_KS_FLAGS:
- fputs ("key server preferences:", listfp);
+ es_fputs ("key server preferences:", listfp);
for (i = 0; i < length; i++)
- fprintf (listfp, " %02X", buffer[i]);
+ es_fprintf (listfp, " %02X", buffer[i]);
break;
case SIGSUBPKT_PREF_KS:
- fputs ("preferred key server: ", listfp);
- print_string (listfp, buffer, length, ')');
+ es_fputs ("preferred key server: ", listfp);
+ es_write_sanitized (listfp, buffer, length, ")", NULL);
break;
case SIGSUBPKT_PRIMARY_UID:
p = "primary user ID";
break;
case SIGSUBPKT_POLICY:
- fputs ("policy: ", listfp);
- print_string (listfp, buffer, length, ')');
+ es_fputs ("policy: ", listfp);
+ es_write_sanitized (listfp, buffer, length, ")", NULL);
break;
case SIGSUBPKT_KEY_FLAGS:
- fputs ("key flags:", listfp);
+ es_fputs ("key flags:", listfp);
for (i = 0; i < length; i++)
- fprintf (listfp, " %02X", buffer[i]);
+ es_fprintf (listfp, " %02X", buffer[i]);
break;
case SIGSUBPKT_SIGNERS_UID:
p = "signer's user ID";
@@ -1130,37 +1129,37 @@ dump_sig_subpkt (int hashed, int type, int critical,
case SIGSUBPKT_REVOC_REASON:
if (length)
{
- fprintf (listfp, "revocation reason 0x%02x (", *buffer);
- print_string (listfp, buffer + 1, length - 1, ')');
+ es_fprintf (listfp, "revocation reason 0x%02x (", *buffer);
+ es_write_sanitized (listfp, buffer + 1, length - 1, ")", NULL);
p = ")";
}
break;
case SIGSUBPKT_ARR:
- fputs ("Big Brother's key (ignored): ", listfp);
+ es_fputs ("Big Brother's key (ignored): ", listfp);
if (length < 22)
p = "[too short]";
else
{
- fprintf (listfp, "c=%02x a=%d f=", buffer[0], buffer[1]);
- for (i = 2; i < length; i++)
- fprintf (listfp, "%02X", buffer[i]);
+ es_fprintf (listfp, "c=%02x a=%d f=", buffer[0], buffer[1]);
+ if (length > 2)
+ es_write_hexstring (listfp, buffer+2, length-2, 0, NULL);
}
break;
case SIGSUBPKT_FEATURES:
- fputs ("features:", listfp);
+ es_fputs ("features:", listfp);
for (i = 0; i < length; i++)
- fprintf (listfp, " %02x", buffer[i]);
+ es_fprintf (listfp, " %02x", buffer[i]);
break;
case SIGSUBPKT_SIGNATURE:
- fputs ("signature: ", listfp);
+ es_fputs ("signature: ", listfp);
if (length < 17)
p = "[too short]";
else
- fprintf (listfp, "v%d, class 0x%02X, algo %d, digest algo %d",
- buffer[0],
- buffer[0] == 3 ? buffer[2] : buffer[1],
- buffer[0] == 3 ? buffer[15] : buffer[2],
- buffer[0] == 3 ? buffer[16] : buffer[3]);
+ es_fprintf (listfp, "v%d, class 0x%02X, algo %d, digest algo %d",
+ buffer[0],
+ buffer[0] == 3 ? buffer[2] : buffer[1],
+ buffer[0] == 3 ? buffer[15] : buffer[2],
+ buffer[0] == 3 ? buffer[16] : buffer[3]);
break;
default:
if (type >= 100 && type <= 110)
@@ -1170,7 +1169,7 @@ dump_sig_subpkt (int hashed, int type, int critical,
break;
}
- fprintf (listfp, "%s)\n", p ? p : "");
+ es_fprintf (listfp, "%s)\n", p ? p : "");
}
@@ -1654,13 +1653,13 @@ parse_signature (IOBUF inp, int pkttype, unsigned long pktlen,
if (list_mode)
{
- fprintf (listfp, ":signature packet: algo %d, keyid %08lX%08lX\n"
- "\tversion %d, created %lu, md5len %d, sigclass 0x%02x\n"
- "\tdigest algo %d, begin of digest %02x %02x\n",
- sig->pubkey_algo,
- (ulong) sig->keyid[0], (ulong) sig->keyid[1],
- sig->version, (ulong) sig->timestamp, md5_len, sig->sig_class,
- sig->digest_algo, sig->digest_start[0], sig->digest_start[1]);
+ es_fprintf (listfp, ":signature packet: algo %d, keyid %08lX%08lX\n"
+ "\tversion %d, created %lu, md5len %d, sigclass 0x%02x\n"
+ "\tdigest algo %d, begin of digest %02x %02x\n",
+ sig->pubkey_algo,
+ (ulong) sig->keyid[0], (ulong) sig->keyid[1],
+ sig->version, (ulong) sig->timestamp, md5_len, sig->sig_class,
+ sig->digest_algo, sig->digest_start[0], sig->digest_start[1]);
if (is_v4)
{
parse_sig_subpkt (sig->hashed, SIGSUBPKT_LIST_HASHED, NULL);
@@ -1672,7 +1671,7 @@ parse_signature (IOBUF inp, int pkttype, unsigned long pktlen,
if (!ndata)
{
if (list_mode)
- fprintf (listfp, "\tunknown algorithm %d\n", sig->pubkey_algo);
+ es_fprintf (listfp, "\tunknown algorithm %d\n", sig->pubkey_algo);
unknown_pubkey_warning (sig->pubkey_algo);
/* We store the plain material in data[0], so that we are able
@@ -1701,9 +1700,9 @@ parse_signature (IOBUF inp, int pkttype, unsigned long pktlen,
pktlen -= n;
if (list_mode)
{
- fprintf (listfp, "\tdata: ");
+ es_fprintf (listfp, "\tdata: ");
mpi_print (listfp, sig->data[i], mpi_print_mode);
- putc ('\n', listfp);
+ es_putc ('\n', listfp);
}
if (!sig->data[i])
rc = G10ERR_INVALID_PACKET;
@@ -1750,13 +1749,13 @@ parse_onepass_sig (IOBUF inp, int pkttype, unsigned long pktlen,
ops->last = iobuf_get_noeof (inp);
pktlen--;
if (list_mode)
- fprintf (listfp,
- ":onepass_sig packet: keyid %08lX%08lX\n"
- "\tversion %d, sigclass 0x%02x, digest %d, pubkey %d, "
- "last=%d\n",
- (ulong) ops->keyid[0], (ulong) ops->keyid[1],
- version, ops->sig_class,
- ops->digest_algo, ops->pubkey_algo, ops->last);
+ es_fprintf (listfp,
+ ":onepass_sig packet: keyid %08lX%08lX\n"
+ "\tversion %d, sigclass 0x%02x, digest %d, pubkey %d, "
+ "last=%d\n",
+ (ulong) ops->keyid[0], (ulong) ops->keyid[1],
+ version, ops->sig_class,
+ ops->digest_algo, ops->pubkey_algo, ops->last);
leave:
@@ -1834,17 +1833,17 @@ parse_key (IOBUF inp, int pkttype, unsigned long pktlen,
* luckily all those comments are started by a hash. */
if (list_mode)
{
- fprintf (listfp, ":rfc1991 comment packet: \"");
+ es_fprintf (listfp, ":rfc1991 comment packet: \"");
for (; pktlen; pktlen--)
{
int c;
c = iobuf_get_noeof (inp);
if (c >= ' ' && c <= 'z')
- putc (c, listfp);
+ es_putc (c, listfp);
else
- fprintf (listfp, "\\x%02x", c);
+ es_fprintf (listfp, "\\x%02x", c);
}
- fprintf (listfp, "\"\n");
+ es_fprintf (listfp, "\"\n");
}
iobuf_skip_rest (inp, pktlen, 0);
return 0;
@@ -1887,13 +1886,13 @@ parse_key (IOBUF inp, int pkttype, unsigned long pktlen,
algorithm = iobuf_get_noeof (inp);
pktlen--;
if (list_mode)
- fprintf (listfp, ":%s key packet:\n"
- "\tversion %d, algo %d, created %lu, expires %lu\n",
- pkttype == PKT_PUBLIC_KEY ? "public" :
- pkttype == PKT_SECRET_KEY ? "secret" :
- pkttype == PKT_PUBLIC_SUBKEY ? "public sub" :
- pkttype == PKT_SECRET_SUBKEY ? "secret sub" : "??",
- version, algorithm, timestamp, expiredate);
+ es_fprintf (listfp, ":%s key packet:\n"
+ "\tversion %d, algo %d, created %lu, expires %lu\n",
+ pkttype == PKT_PUBLIC_KEY ? "public" :
+ pkttype == PKT_SECRET_KEY ? "secret" :
+ pkttype == PKT_PUBLIC_SUBKEY ? "public sub" :
+ pkttype == PKT_SECRET_SUBKEY ? "secret sub" : "??",
+ version, algorithm, timestamp, expiredate);
if (pkttype == PKT_SECRET_KEY || pkttype == PKT_SECRET_SUBKEY)
{
@@ -1932,7 +1931,7 @@ parse_key (IOBUF inp, int pkttype, unsigned long pktlen,
if (!npkey)
{
if (list_mode)
- fprintf (listfp, "\tunknown algorithm %d\n", algorithm);
+ es_fprintf (listfp, "\tunknown algorithm %d\n", algorithm);
unknown_pubkey_warning (algorithm);
}
@@ -1958,9 +1957,9 @@ parse_key (IOBUF inp, int pkttype, unsigned long pktlen,
pktlen -= n;
if (list_mode)
{
- fprintf (listfp, "\tskey[%d]: ", i);
+ es_fprintf (listfp, "\tskey[%d]: ", i);
mpi_print (listfp, sk->skey[i], mpi_print_mode);
- putc ('\n', listfp);
+ es_putc ('\n', listfp);
}
if (!sk->skey[i])
rc = G10ERR_INVALID_PACKET;
@@ -1999,8 +1998,8 @@ parse_key (IOBUF inp, int pkttype, unsigned long pktlen,
if (i < 4 || memcmp (temp, "GNU", 3))
{
if (list_mode)
- fprintf (listfp, "\tunknown S2K %d\n",
- sk->protect.s2k.mode);
+ es_fprintf (listfp, "\tunknown S2K %d\n",
+ sk->protect.s2k.mode);
rc = G10ERR_INVALID_PACKET;
goto leave;
}
@@ -2023,46 +2022,46 @@ parse_key (IOBUF inp, int pkttype, unsigned long pktlen,
{
case 0:
if (list_mode)
- fprintf (listfp, "\tsimple S2K");
+ es_fprintf (listfp, "\tsimple S2K");
break;
case 1:
if (list_mode)
- fprintf (listfp, "\tsalted S2K");
+ es_fprintf (listfp, "\tsalted S2K");
break;
case 3:
if (list_mode)
- fprintf (listfp, "\titer+salt S2K");
+ es_fprintf (listfp, "\titer+salt S2K");
break;
case 1001:
if (list_mode)
- fprintf (listfp, "\tgnu-dummy S2K");
+ es_fprintf (listfp, "\tgnu-dummy S2K");
break;
case 1002:
if (list_mode)
- fprintf (listfp, "\tgnu-divert-to-card S2K");
+ es_fprintf (listfp, "\tgnu-divert-to-card S2K");
break;
default:
if (list_mode)
- fprintf (listfp, "\tunknown %sS2K %d\n",
- sk->protect.s2k.mode < 1000 ? "" : "GNU ",
- sk->protect.s2k.mode);
+ es_fprintf (listfp, "\tunknown %sS2K %d\n",
+ sk->protect.s2k.mode < 1000 ? "" : "GNU ",
+ sk->protect.s2k.mode);
rc = G10ERR_INVALID_PACKET;
goto leave;
}
if (list_mode)
{
- fprintf (listfp, ", algo: %d,%s hash: %d",
- sk->protect.algo,
- sk->protect.sha1chk ? " SHA1 protection,"
- : " simple checksum,", sk->protect.s2k.hash_algo);
+ es_fprintf (listfp, ", algo: %d,%s hash: %d",
+ sk->protect.algo,
+ sk->protect.sha1chk ? " SHA1 protection,"
+ : " simple checksum,", sk->protect.s2k.hash_algo);
if (sk->protect.s2k.mode == 1 || sk->protect.s2k.mode == 3)
{
- fprintf (listfp, ", salt: ");
- for (i = 0; i < 8; i++)
- fprintf (listfp, "%02x", sk->protect.s2k.salt[i]);
+ es_fprintf (listfp, ", salt: ");
+ es_write_hexstring (listfp, sk->protect.s2k.salt, 8,
+ 0, NULL);
}
- putc ('\n', listfp);
+ es_putc ('\n', listfp);
}
if (sk->protect.s2k.mode == 3)
@@ -2075,8 +2074,8 @@ parse_key (IOBUF inp, int pkttype, unsigned long pktlen,
sk->protect.s2k.count = iobuf_get (inp);
pktlen--;
if (list_mode)
- fprintf (listfp, "\tprotect count: %lu\n",
- (ulong) sk->protect.s2k.count);
+ es_fprintf (listfp, "\tprotect count: %lu\n",
+ (ulong) sk->protect.s2k.count);
}
else if (sk->protect.s2k.mode == 1002)
{
@@ -2103,8 +2102,8 @@ parse_key (IOBUF inp, int pkttype, unsigned long pktlen,
sk->protect.s2k.mode = 0;
sk->protect.s2k.hash_algo = DIGEST_ALGO_MD5;
if (list_mode)
- fprintf (listfp, "\tprotect algo: %d (hash algo: %d)\n",
- sk->protect.algo, sk->protect.s2k.hash_algo);
+ es_fprintf (listfp, "\tprotect algo: %d (hash algo: %d)\n",
+ sk->protect.algo, sk->protect.s2k.hash_algo);
}
/* It is really ugly that we don't know the size
@@ -2131,12 +2130,12 @@ parse_key (IOBUF inp, int pkttype, unsigned long pktlen,
temp[i] = iobuf_get_noeof (inp);
if (list_mode)
{
- fprintf (listfp,
+ es_fprintf (listfp,
sk->protect.s2k.mode == 1002 ? "\tserial-number: "
: "\tprotect IV: ");
for (i = 0; i < sk->protect.ivlen; i++)
- fprintf (listfp, " %02x", temp[i]);
- putc ('\n', listfp);
+ es_fprintf (listfp, " %02x", temp[i]);
+ es_putc ('\n', listfp);
}
memcpy (sk->protect.iv, temp, sk->protect.ivlen);
}
@@ -2166,7 +2165,7 @@ parse_key (IOBUF inp, int pkttype, unsigned long pktlen,
pktlen = 0;
if (list_mode)
{
- fprintf (listfp, "\tencrypted stuff follows\n");
+ es_fprintf (listfp, "\tencrypted stuff follows\n");
}
}
else /* The v3 method: The mpi length is not encrypted. */
@@ -2177,7 +2176,7 @@ parse_key (IOBUF inp, int pkttype, unsigned long pktlen,
{
sk->skey[i] = read_protected_v3_mpi (inp, &pktlen);
if (list_mode)
- fprintf (listfp, "\tskey[%d]: [encrypted]\n", i);
+ es_fprintf (listfp, "\tskey[%d]: [encrypted]\n", i);
}
else
{
@@ -2186,9 +2185,9 @@ parse_key (IOBUF inp, int pkttype, unsigned long pktlen,
pktlen -= n;
if (list_mode)
{
- fprintf (listfp, "\tskey[%d]: ", i);
+ es_fprintf (listfp, "\tskey[%d]: ", i);
mpi_print (listfp, sk->skey[i], mpi_print_mode);
- putc ('\n', listfp);
+ es_putc ('\n', listfp);
}
}
@@ -2202,7 +2201,7 @@ parse_key (IOBUF inp, int pkttype, unsigned long pktlen,
pktlen -= 2;
if (list_mode)
{
- fprintf (listfp, "\tchecksum: %04hx\n", sk->csum);
+ es_fprintf (listfp, "\tchecksum: %04hx\n", sk->csum);
}
}
@@ -2229,9 +2228,9 @@ parse_key (IOBUF inp, int pkttype, unsigned long pktlen,
pktlen -= n;
if (list_mode)
{
- fprintf (listfp, "\tpkey[%d]: ", i);
+ es_fprintf (listfp, "\tpkey[%d]: ", i);
mpi_print (listfp, pk->pkey[i], mpi_print_mode);
- putc ('\n', listfp);
+ es_putc ('\n', listfp);
}
if (!pk->pkey[i])
rc = G10ERR_INVALID_PACKET;
@@ -2243,8 +2242,8 @@ parse_key (IOBUF inp, int pkttype, unsigned long pktlen,
}
if (list_mode)
- fprintf (listfp, "\tkeyid: %08lX%08lX\n",
- (ulong) keyid[0], (ulong) keyid[1]);
+ es_fprintf (listfp, "\tkeyid: %08lX%08lX\n",
+ (ulong) keyid[0], (ulong) keyid[1]);
leave:
iobuf_skip_rest (inp, pktlen, 0);
@@ -2352,16 +2351,16 @@ parse_user_id (IOBUF inp, int pkttype, unsigned long pktlen, PACKET * packet)
if (list_mode)
{
int n = packet->pkt.user_id->len;
- fprintf (listfp, ":user ID packet: \"");
- /* fixme: Hey why don't we replace this with print_string?? */
+ es_fprintf (listfp, ":user ID packet: \"");
+ /* fixme: Hey why don't we replace this with es_write_sanitized?? */
for (p = packet->pkt.user_id->name; n; p++, n--)
{
if (*p >= ' ' && *p <= 'z')
- putc (*p, listfp);
+ es_putc (*p, listfp);
else
- fprintf (listfp, "\\x%02x", *p);
+ es_fprintf (listfp, "\\x%02x", *p);
}
- fprintf (listfp, "\"\n");
+ es_fprintf (listfp, "\"\n");
}
return 0;
}
@@ -2429,7 +2428,7 @@ parse_attribute (IOBUF inp, int pkttype, unsigned long pktlen,
if (list_mode)
{
- fprintf (listfp, ":attribute packet: %s\n", packet->pkt.user_id->name);
+ es_fprintf (listfp, ":attribute packet: %s\n", packet->pkt.user_id->name);
}
return 0;
}
@@ -2459,16 +2458,16 @@ parse_comment (IOBUF inp, int pkttype, unsigned long pktlen, PACKET * packet)
if (list_mode)
{
int n = packet->pkt.comment->len;
- fprintf (listfp, ":%scomment packet: \"", pkttype == PKT_OLD_COMMENT ?
- "OpenPGP draft " : "");
+ es_fprintf (listfp, ":%scomment packet: \"", pkttype == PKT_OLD_COMMENT ?
+ "OpenPGP draft " : "");
for (p = packet->pkt.comment->data; n; p++, n--)
{
if (*p >= ' ' && *p <= 'z')
- putc (*p, listfp);
+ es_putc (*p, listfp);
else
- fprintf (listfp, "\\x%02x", *p);
+ es_fprintf (listfp, "\\x%02x", *p);
}
- fprintf (listfp, "\"\n");
+ es_fprintf (listfp, "\"\n");
}
return 0;
}
@@ -2498,14 +2497,14 @@ parse_trust (IOBUF inp, int pkttype, unsigned long pktlen, PACKET * pkt)
pkt->pkt.ring_trust->sigcache = c;
}
if (list_mode)
- fprintf (listfp, ":trust packet: flag=%02x sigcache=%02x\n",
- pkt->pkt.ring_trust->trustval,
- pkt->pkt.ring_trust->sigcache);
+ es_fprintf (listfp, ":trust packet: flag=%02x sigcache=%02x\n",
+ pkt->pkt.ring_trust->trustval,
+ pkt->pkt.ring_trust->sigcache);
}
else
{
if (list_mode)
- fprintf (listfp, ":trust packet: empty\n");
+ es_fprintf (listfp, ":trust packet: empty\n");
}
iobuf_skip_rest (inp, pktlen, 0);
}
@@ -2562,22 +2561,22 @@ parse_plaintext (IOBUF inp, int pkttype, unsigned long pktlen,
if (list_mode)
{
- fprintf (listfp, ":literal data packet:\n"
- "\tmode %c (%X), created %lu, name=\"",
- mode >= ' ' && mode < 'z' ? mode : '?', mode,
- (ulong) pt->timestamp);
+ es_fprintf (listfp, ":literal data packet:\n"
+ "\tmode %c (%X), created %lu, name=\"",
+ mode >= ' ' && mode < 'z' ? mode : '?', mode,
+ (ulong) pt->timestamp);
for (p = pt->name, i = 0; i < namelen; p++, i++)
{
if (*p >= ' ' && *p <= 'z')
- putc (*p, listfp);
+ es_putc (*p, listfp);
else
- fprintf (listfp, "\\x%02x", *p);
+ es_fprintf (listfp, "\\x%02x", *p);
}
- fprintf (listfp, "\",\n\traw data: ");
+ es_fprintf (listfp, "\",\n\traw data: ");
if (partial)
- fprintf (listfp, "unknown length\n");
+ es_fprintf (listfp, "unknown length\n");
else
- fprintf (listfp, "%lu bytes\n", (ulong) pt->len);
+ es_fprintf (listfp, "%lu bytes\n", (ulong) pt->len);
}
leave:
@@ -2603,7 +2602,7 @@ parse_compressed (IOBUF inp, int pkttype, unsigned long pktlen,
zd->new_ctb = new_ctb;
zd->buf = inp;
if (list_mode)
- fprintf (listfp, ":compressed packet: algo=%d\n", zd->algorithm);
+ es_fprintf (listfp, ":compressed packet: algo=%d\n", zd->algorithm);
return 0;
}
@@ -2663,12 +2662,12 @@ parse_encrypted (IOBUF inp, int pkttype, unsigned long pktlen,
if (list_mode)
{
if (orig_pktlen)
- fprintf (listfp, ":encrypted data packet:\n\tlength: %lu\n",
- orig_pktlen);
+ es_fprintf (listfp, ":encrypted data packet:\n\tlength: %lu\n",
+ orig_pktlen);
else
- fprintf (listfp, ":encrypted data packet:\n\tlength: unknown\n");
+ es_fprintf (listfp, ":encrypted data packet:\n\tlength: unknown\n");
if (ed->mdc_method)
- fprintf (listfp, "\tmdc_method: %d\n", ed->mdc_method);
+ es_fprintf (listfp, "\tmdc_method: %d\n", ed->mdc_method);
}
ed->buf = inp;
@@ -2693,7 +2692,7 @@ parse_mdc (IOBUF inp, int pkttype, unsigned long pktlen,
mdc = pkt->pkt.mdc = xmalloc (sizeof *pkt->pkt.mdc);
if (list_mode)
- fprintf (listfp, ":mdc packet: length=%lu\n", pktlen);
+ es_fprintf (listfp, ":mdc packet: length=%lu\n", pktlen);
if (!new_ctb || pktlen != 20)
{
log_error ("mdc_packet with invalid encoding\n");
@@ -2732,7 +2731,7 @@ parse_gpg_control (IOBUF inp, int pkttype, unsigned long pktlen,
(void) pkttype;
if (list_mode)
- fprintf (listfp, ":packet 63: length %lu ", pktlen);
+ es_fprintf (listfp, ":packet 63: length %lu ", pktlen);
sesmark = get_session_marker (&sesmarklen);
if (pktlen < sesmarklen + 1) /* 1 is for the control bytes */
@@ -2765,7 +2764,7 @@ parse_gpg_control (IOBUF inp, int pkttype, unsigned long pktlen,
int c;
i = 0;
- fprintf (listfp, "- private (rest length %lu)\n", pktlen);
+ es_fprintf (listfp, "- private (rest length %lu)\n", pktlen);
if (partial)
{
while ((c = iobuf_get (inp)) != -1)
@@ -2780,7 +2779,7 @@ parse_gpg_control (IOBUF inp, int pkttype, unsigned long pktlen,
break;
}
}
- putc ('\n', listfp);
+ es_putc ('\n', listfp);
}
iobuf_skip_rest (inp, pktlen, 0);
return gpg_error (GPG_ERR_INV_PACKET);