[svn] GnuPG - r5170 - trunk/g10
svn author wk
cvs at cvs.gnupg.org
Fri Oct 2 11:15:11 CEST 2009
Author: wk
Date: 2009-10-02 11:15:10 +0200 (Fri, 02 Oct 2009)
New Revision: 5170
Modified:
trunk/g10/parse-packet.c
Log:
Re-indented
[The diff below has been truncated]
Modified: trunk/g10/parse-packet.c
===================================================================
--- trunk/g10/parse-packet.c 2009-10-01 09:56:51 UTC (rev 5169)
+++ trunk/g10/parse-packet.c 2009-10-02 09:15:10 UTC (rev 5170)
@@ -1,6 +1,6 @@
/* parse-packet.c - read packets
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
- * 2007 Free Software Foundation, Inc.
+ * 2007, 2009 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -15,7 +15,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
@@ -39,63 +39,64 @@
static int list_mode;
static FILE *listfp;
-static int parse( IOBUF inp, PACKET *pkt, int onlykeypkts,
- off_t *retpos, int *skip, IOBUF out, int do_skip
+static int parse (IOBUF inp, PACKET * pkt, int onlykeypkts,
+ off_t * retpos, int *skip, IOBUF out, int do_skip
#ifdef DEBUG_PARSE_PACKET
- ,const char *dbg_w, const char *dbg_f, int dbg_l
+ , const char *dbg_w, const char *dbg_f, int dbg_l
#endif
- );
-static int copy_packet( IOBUF inp, IOBUF out, int pkttype,
- unsigned long pktlen, int partial );
-static void skip_packet( IOBUF inp, int pkttype,
- unsigned long pktlen, int partial );
-static void *read_rest( IOBUF inp, size_t pktlen, int partial );
-static int parse_marker( IOBUF inp, int pkttype, unsigned long pktlen );
-static int parse_symkeyenc( IOBUF inp, int pkttype, unsigned long pktlen,
- PACKET *packet );
-static int parse_pubkeyenc( IOBUF inp, int pkttype, unsigned long pktlen,
- PACKET *packet );
-static int parse_onepass_sig( IOBUF inp, int pkttype, unsigned long pktlen,
- PKT_onepass_sig *ops );
-static int parse_key( IOBUF inp, int pkttype, unsigned long pktlen,
- byte *hdr, int hdrlen, PACKET *packet );
-static int parse_user_id( IOBUF inp, int pkttype, unsigned long pktlen,
- PACKET *packet );
-static int parse_attribute( IOBUF inp, int pkttype, unsigned long pktlen,
- PACKET *packet );
-static int parse_comment( IOBUF inp, int pkttype, unsigned long pktlen,
- PACKET *packet );
-static void parse_trust( IOBUF inp, int pkttype, unsigned long pktlen,
- PACKET *packet );
-static int parse_plaintext( IOBUF inp, int pkttype, unsigned long pktlen,
- PACKET *packet, int new_ctb, int partial);
-static int parse_compressed( IOBUF inp, int pkttype, unsigned long pktlen,
- PACKET *packet, int new_ctb );
-static int parse_encrypted( IOBUF inp, int pkttype, unsigned long pktlen,
- PACKET *packet, int new_ctb, int partial);
-static int parse_mdc( IOBUF inp, int pkttype, unsigned long pktlen,
- PACKET *packet, int new_ctb);
-static int parse_gpg_control( IOBUF inp, int pkttype, unsigned long pktlen,
- PACKET *packet, int partial );
+ );
+static int copy_packet (IOBUF inp, IOBUF out, int pkttype,
+ unsigned long pktlen, int partial);
+static void skip_packet (IOBUF inp, int pkttype,
+ unsigned long pktlen, int partial);
+static void *read_rest (IOBUF inp, size_t pktlen, int partial);
+static int parse_marker (IOBUF inp, int pkttype, unsigned long pktlen);
+static int parse_symkeyenc (IOBUF inp, int pkttype, unsigned long pktlen,
+ PACKET * packet);
+static int parse_pubkeyenc (IOBUF inp, int pkttype, unsigned long pktlen,
+ PACKET * packet);
+static int parse_onepass_sig (IOBUF inp, int pkttype, unsigned long pktlen,
+ PKT_onepass_sig * ops);
+static int parse_key (IOBUF inp, int pkttype, unsigned long pktlen,
+ byte * hdr, int hdrlen, PACKET * packet);
+static int parse_user_id (IOBUF inp, int pkttype, unsigned long pktlen,
+ PACKET * packet);
+static int parse_attribute (IOBUF inp, int pkttype, unsigned long pktlen,
+ PACKET * packet);
+static int parse_comment (IOBUF inp, int pkttype, unsigned long pktlen,
+ PACKET * packet);
+static void parse_trust (IOBUF inp, int pkttype, unsigned long pktlen,
+ PACKET * packet);
+static int parse_plaintext (IOBUF inp, int pkttype, unsigned long pktlen,
+ PACKET * packet, int new_ctb, int partial);
+static int parse_compressed (IOBUF inp, int pkttype, unsigned long pktlen,
+ PACKET * packet, int new_ctb);
+static int parse_encrypted (IOBUF inp, int pkttype, unsigned long pktlen,
+ PACKET * packet, int new_ctb, int partial);
+static int parse_mdc (IOBUF inp, int pkttype, unsigned long pktlen,
+ PACKET * packet, int new_ctb);
+static int parse_gpg_control (IOBUF inp, int pkttype, unsigned long pktlen,
+ PACKET * packet, int partial);
static unsigned short
-read_16(IOBUF inp)
+read_16 (IOBUF inp)
{
- unsigned short a;
- a = iobuf_get_noeof(inp) << 8;
- a |= iobuf_get_noeof(inp);
- return a;
+ unsigned short a;
+ a = iobuf_get_noeof (inp) << 8;
+ a |= iobuf_get_noeof (inp);
+ return a;
}
+
static unsigned long
-read_32(IOBUF inp)
+read_32 (IOBUF inp)
{
- unsigned long a;
- a = iobuf_get_noeof(inp) << 24;
- a |= iobuf_get_noeof(inp) << 16;
- a |= iobuf_get_noeof(inp) << 8;
- a |= iobuf_get_noeof(inp);
- return a;
+ unsigned long a;
+ a = iobuf_get_noeof (inp) << 24;
+ a |= iobuf_get_noeof (inp) << 16;
+ a |= iobuf_get_noeof (inp) << 8;
+ a |= iobuf_get_noeof (inp);
+ return a;
}
@@ -103,12 +104,11 @@
* external format is a 16 bit unsigned value stored in network byte
* order, giving the number of bits for the following integer. The
* integer is stored with MSB first (left padded with zeroes to align
- * on a byte boundary).
- */
+ * on a byte boundary). */
static gcry_mpi_t
mpi_read (iobuf_t inp, unsigned int *ret_nread, int secure)
{
- /*FIXME: Needs to be synced with gnupg14/mpi/mpicoder.c*/
+ /*FIXME: Needs to be synced with gnupg14/mpi/mpicoder.c */
int c, c1, c2, i;
unsigned int nbits, nbytes;
@@ -116,27 +116,27 @@
gcry_mpi_t a = NULL;
byte *buf = NULL;
byte *p;
-
- if ( (c = c1 = iobuf_get (inp)) == -1 )
+
+ if ((c = c1 = iobuf_get (inp)) == -1)
goto leave;
nbits = c << 8;
- if ( (c = c2 = iobuf_get (inp)) == -1 )
+ if ((c = c2 = iobuf_get (inp)) == -1)
goto leave;
nbits |= c;
- if ( nbits > MAX_EXTERN_MPI_BITS )
+ if (nbits > MAX_EXTERN_MPI_BITS)
{
- log_error("mpi too large (%u bits)\n", nbits);
+ log_error ("mpi too large (%u bits)\n", nbits);
goto leave;
}
nread = 2;
- nbytes = (nbits+7) / 8;
+ nbytes = (nbits + 7) / 8;
buf = secure ? gcry_xmalloc_secure (nbytes + 2) : gcry_xmalloc (nbytes + 2);
p = buf;
p[0] = c1;
p[1] = c2;
- for ( i=0 ; i < nbytes; i++ )
+ for (i = 0; i < nbytes; i++)
{
- p[i+2] = iobuf_get(inp) & 0xff;
+ p[i + 2] = iobuf_get (inp) & 0xff;
nread++;
}
@@ -148,13 +148,13 @@
}
else
{
- if ( gcry_mpi_scan( &a, GCRYMPI_FMT_PGP, buf, nread, &nread ) )
- a = NULL;
+ if (gcry_mpi_scan (&a, GCRYMPI_FMT_PGP, buf, nread, &nread))
+ a = NULL;
}
leave:
- gcry_free(buf);
- if ( nread > *ret_nread )
+ gcry_free (buf);
+ if (nread > *ret_nread)
log_bug ("mpi larger than packet");
else
*ret_nread = nread;
@@ -162,963 +162,1036 @@
}
-
-
int
-set_packet_list_mode( int mode )
+set_packet_list_mode (int mode)
{
- int old = list_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 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 doing a --list-packets. If this assumption fails, it will
- be easy to add an option for the listing stream. Note that we
- initialize it only once; mainly because some code may switch
- the option value later back to 1 and we want to have all output
- to the same stream.
+ int old = list_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
+ 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
+ doing a --list-packets. If this assumption fails, it will be easy
+ to add an option for the listing stream. Note that we initialize
+ it only once; mainly because some code may switch the option
+ value later back to 1 and we want to have all output to the same
+ 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
- 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;
- return old;
+ Using stderr is not actually very clean because it bypasses the
+ logging code but it is a special thing anyay. 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;
+ return old;
}
+
static void
-unknown_pubkey_warning( int algo )
+unknown_pubkey_warning (int algo)
{
- static byte unknown_pubkey_algos[256];
+ static byte unknown_pubkey_algos[256];
- algo &= 0xff;
- if( !unknown_pubkey_algos[algo] ) {
- if( opt.verbose )
- log_info(_("can't handle public key algorithm %d\n"), algo );
- unknown_pubkey_algos[algo] = 1;
+ algo &= 0xff;
+ if (!unknown_pubkey_algos[algo])
+ {
+ if (opt.verbose)
+ log_info (_("can't handle public key algorithm %d\n"), algo);
+ unknown_pubkey_algos[algo] = 1;
}
}
-/****************
- * Parse a Packet and return it in packet
+
+/* Parse a packet and return it in packet structure.
* Returns: 0 := valid packet in pkt
* -1 := no more packets
* >0 := error
* Note: The function may return an error and a partly valid packet;
- * caller must free this packet.
- */
+ * caller must free this packet. */
#ifdef DEBUG_PARSE_PACKET
int
-dbg_parse_packet( IOBUF inp, PACKET *pkt, const char *dbg_f, int dbg_l )
+dbg_parse_packet (IOBUF inp, PACKET *pkt, const char *dbg_f, int dbg_l)
{
- int skip, rc;
+ int skip, rc;
- do {
- rc = parse( inp, pkt, 0, NULL, &skip, NULL, 0, "parse", dbg_f, dbg_l );
- } while( skip );
- return rc;
+ do
+ {
+ rc = parse (inp, pkt, 0, NULL, &skip, NULL, 0, "parse", dbg_f, dbg_l);
+ }
+ while (skip);
+ return rc;
}
-#else
+#else /*!DEBUG_PARSE_PACKET*/
int
-parse_packet( IOBUF inp, PACKET *pkt )
+parse_packet (IOBUF inp, PACKET * pkt)
{
- int skip, rc;
+ int skip, rc;
- do {
- rc = parse( inp, pkt, 0, NULL, &skip, NULL, 0 );
- } while( skip );
- return rc;
+ do
+ {
+ rc = parse (inp, pkt, 0, NULL, &skip, NULL, 0);
+ }
+ while (skip);
+ return rc;
}
-#endif
+#endif /*!DEBUG_PARSE_PACKET*/
-/****************
- * Like parse packet, but only return secret or public (sub)key packets.
+
+/*
+ * Like parse packet, but only return secret or public (sub)key
+ * packets.
*/
#ifdef DEBUG_PARSE_PACKET
int
-dbg_search_packet( IOBUF inp, PACKET *pkt, off_t *retpos, int with_uid,
- const char *dbg_f, int dbg_l )
+dbg_search_packet (IOBUF inp, PACKET * pkt, off_t * retpos, int with_uid,
+ const char *dbg_f, int dbg_l)
{
- int skip, rc;
+ int skip, rc;
- do {
- rc = parse( inp, pkt, with_uid?2:1, retpos, &skip, NULL, 0, "search", dbg_f, dbg_l );
- } while( skip );
- return rc;
+ do
+ {
+ rc =
+ parse (inp, pkt, with_uid ? 2 : 1, retpos, &skip, NULL, 0, "search",
+ dbg_f, dbg_l);
+ }
+ while (skip);
+ return rc;
}
-#else
+#else /*!DEBUG_PARSE_PACKET*/
int
-search_packet( IOBUF inp, PACKET *pkt, off_t *retpos, int with_uid )
+search_packet (IOBUF inp, PACKET * pkt, off_t * retpos, int with_uid)
{
- int skip, rc;
+ int skip, rc;
- do {
- rc = parse( inp, pkt, with_uid?2:1, retpos, &skip, NULL, 0 );
- } while( skip );
- return rc;
+ do
+ {
+ rc = parse (inp, pkt, with_uid ? 2 : 1, retpos, &skip, NULL, 0);
+ }
+ while (skip);
+ return rc;
}
-#endif
+#endif /*!DEBUG_PARSE_PACKET*/
-/****************
+
+/*
* Copy all packets from INP to OUT, thereby removing unused spaces.
*/
#ifdef DEBUG_PARSE_PACKET
int
-dbg_copy_all_packets( IOBUF inp, IOBUF out,
- const char *dbg_f, int dbg_l )
+dbg_copy_all_packets (IOBUF inp, IOBUF out, const char *dbg_f, int dbg_l)
{
- PACKET pkt;
- int skip, rc=0;
- do {
- init_packet(&pkt);
- } while( !(rc = parse( inp, &pkt, 0, NULL, &skip, out, 0, "copy", dbg_f, dbg_l )));
- return rc;
+ PACKET pkt;
+ int skip, rc = 0;
+ do
+ {
+ init_packet (&pkt);
+ }
+ while (!
+ (rc =
+ parse (inp, &pkt, 0, NULL, &skip, out, 0, "copy", dbg_f, dbg_l)));
+ return rc;
}
-#else
+#else /*!DEBUG_PARSE_PACKET*/
int
-copy_all_packets( IOBUF inp, IOBUF out )
+copy_all_packets (IOBUF inp, IOBUF out)
{
- PACKET pkt;
- int skip, rc=0;
- do {
- init_packet(&pkt);
- } while( !(rc = parse( inp, &pkt, 0, NULL, &skip, out, 0 )));
- return rc;
+ PACKET pkt;
+ int skip, rc = 0;
+ do
+ {
+ init_packet (&pkt);
+ }
+ while (!(rc = parse (inp, &pkt, 0, NULL, &skip, out, 0)));
+ return rc;
}
-#endif
+#endif /*!DEBUG_PARSE_PACKET*/
-/****************
+
+/*
* Copy some packets from INP to OUT, thereby removing unused spaces.
- * Stop at offset STOPoff (i.e. don't copy packets at this or later offsets)
+ * Stop at offset STOPoff (i.e. don't copy packets at this or later
+ * offsets)
*/
#ifdef DEBUG_PARSE_PACKET
int
-dbg_copy_some_packets( IOBUF inp, IOBUF out, off_t stopoff,
- const char *dbg_f, int dbg_l )
+dbg_copy_some_packets (IOBUF inp, IOBUF out, off_t stopoff,
+ const char *dbg_f, int dbg_l)
{
- PACKET pkt;
- int skip, rc=0;
- do {
- if( iobuf_tell(inp) >= stopoff )
- return 0;
- init_packet(&pkt);
- } while( !(rc = parse( inp, &pkt, 0, NULL, &skip, out, 0,
- "some", dbg_f, dbg_l )) );
- return rc;
+ PACKET pkt;
+ int skip, rc = 0;
+ do
+ {
+ if (iobuf_tell (inp) >= stopoff)
+ return 0;
+ init_packet (&pkt);
+ }
+ while (!(rc = parse (inp, &pkt, 0, NULL, &skip, out, 0,
+ "some", dbg_f, dbg_l)));
+ return rc;
}
-#else
+#else /*!DEBUG_PARSE_PACKET*/
int
-copy_some_packets( IOBUF inp, IOBUF out, off_t stopoff )
+copy_some_packets (IOBUF inp, IOBUF out, off_t stopoff)
{
- PACKET pkt;
- int skip, rc=0;
- do {
- if( iobuf_tell(inp) >= stopoff )
- return 0;
- init_packet(&pkt);
- } while( !(rc = parse( inp, &pkt, 0, NULL, &skip, out, 0 )) );
- return rc;
+ PACKET pkt;
+ int skip, rc = 0;
+ do
+ {
+ if (iobuf_tell (inp) >= stopoff)
+ return 0;
+ init_packet (&pkt);
+ }
+ while (!(rc = parse (inp, &pkt, 0, NULL, &skip, out, 0)));
+ return rc;
}
-#endif
+#endif /*!DEBUG_PARSE_PACKET*/
-/****************
+
+/*
* Skip over N packets
*/
#ifdef DEBUG_PARSE_PACKET
int
-dbg_skip_some_packets( IOBUF inp, unsigned n,
- const char *dbg_f, int dbg_l )
+dbg_skip_some_packets (IOBUF inp, unsigned n, const char *dbg_f, int dbg_l)
{
- int skip, rc=0;
- PACKET pkt;
+ int skip, rc = 0;
+ PACKET pkt;
- for( ;n && !rc; n--) {
- init_packet(&pkt);
- rc = parse( inp, &pkt, 0, NULL, &skip, NULL, 1, "skip", dbg_f, dbg_l );
+ for (; n && !rc; n--)
+ {
+ init_packet (&pkt);
+ rc = parse (inp, &pkt, 0, NULL, &skip, NULL, 1, "skip", dbg_f, dbg_l);
}
- return rc;
+ return rc;
}
-#else
+#else /*!DEBUG_PARSE_PACKET*/
int
-skip_some_packets( IOBUF inp, unsigned n )
+skip_some_packets (IOBUF inp, unsigned n)
{
- int skip, rc=0;
- PACKET pkt;
+ int skip, rc = 0;
+ PACKET pkt;
- for( ;n && !rc; n--) {
- init_packet(&pkt);
- rc = parse( inp, &pkt, 0, NULL, &skip, NULL, 1 );
+ for (; n && !rc; n--)
+ {
+ init_packet (&pkt);
+ rc = parse (inp, &pkt, 0, NULL, &skip, NULL, 1);
}
- return rc;
+ return rc;
}
-#endif
+#endif /*!DEBUG_PARSE_PACKET*/
-/****************
- * Parse packet. Set the variable skip points to 1 if the packet
- * should be skipped; this is the case if either ONLYKEYPKTS is set
- * and the parsed packet isn't one or the
- * packet-type is 0, indicating deleted stuff.
- * if OUT is not NULL, a special copymode is used.
+/*
+ * Parse packet. Stores 1 at SKIP 1 if the packet should be skipped;
+ * this is the case if either ONLYKEYPKTS is set and the parsed packet
+ * isn't a key packet or the packet-type is 0, indicating deleted
+ * stuff. If OUT is not NULL, a special copymode is used.
*/
static int
-parse( IOBUF inp, PACKET *pkt, int onlykeypkts, off_t *retpos,
+parse (IOBUF inp, PACKET * pkt, int onlykeypkts, off_t * retpos,
int *skip, IOBUF out, int do_skip
#ifdef DEBUG_PARSE_PACKET
- ,const char *dbg_w, const char *dbg_f, int dbg_l
+ , const char *dbg_w, const char *dbg_f, int dbg_l
#endif
- )
+ )
{
- int rc=0, c, ctb, pkttype, lenbytes;
- unsigned long pktlen;
- byte hdr[8];
- int hdrlen;
- int new_ctb = 0, partial=0;
- int with_uid = (onlykeypkts == 2);
+ int rc = 0, c, ctb, pkttype, lenbytes;
+ unsigned long pktlen;
+ byte hdr[8];
+ int hdrlen;
+ int new_ctb = 0, partial = 0;
+ int with_uid = (onlykeypkts == 2);
- *skip = 0;
- assert( !pkt->pkt.generic );
- if( retpos )
- *retpos = iobuf_tell(inp);
+ *skip = 0;
+ assert (!pkt->pkt.generic);
+ if (retpos)
+ *retpos = iobuf_tell (inp);
- if( (ctb = iobuf_get(inp)) == -1 ) {
- rc = -1;
- goto leave;
+ if ((ctb = iobuf_get (inp)) == -1)
+ {
+ rc = -1;
+ goto leave;
}
- hdrlen=0;
- hdr[hdrlen++] = ctb;
- if( !(ctb & 0x80) ) {
- log_error("%s: invalid packet (ctb=%02x)\n", iobuf_where(inp), ctb );
- rc = gpg_error (GPG_ERR_INV_PACKET);
- goto leave;
+ hdrlen = 0;
+ hdr[hdrlen++] = ctb;
+ if (!(ctb & 0x80))
+ {
+ log_error ("%s: invalid packet (ctb=%02x)\n", iobuf_where (inp), ctb);
+ rc = gpg_error (GPG_ERR_INV_PACKET);
+ goto leave;
}
- pktlen = 0;
- new_ctb = !!(ctb & 0x40);
- if( new_ctb ) {
- pkttype = ctb & 0x3f;
- if( (c = iobuf_get(inp)) == -1 ) {
- log_error("%s: 1st length byte missing\n", iobuf_where(inp) );
- rc = gpg_error (GPG_ERR_INV_PACKET);
- goto leave;
+ pktlen = 0;
+ new_ctb = !!(ctb & 0x40);
+ if (new_ctb)
+ {
+ pkttype = ctb & 0x3f;
+ if ((c = iobuf_get (inp)) == -1)
+ {
+ log_error ("%s: 1st length byte missing\n", iobuf_where (inp));
+ rc = gpg_error (GPG_ERR_INV_PACKET);
+ goto leave;
}
-/* The follwing code has been here for ages (2002-08-30) but it is
- clearly wrong: For example passing a 0 as second argument to
- iobuf_set_partial_block_mode stops the partial block mode which we
- definitely do not want. Also all values < 224 or 255 are not
- valid. Let's disable it and put PKT_COMPRESSED into the list of
- allowed packets with partial header until someone complains. */
-/* if (pkttype == PKT_COMPRESSED) { */
-/* iobuf_set_partial_block_mode(inp, c & 0xff); */
-/* pktlen = 0; /\* to indicate partial length *\/ */
-/* partial=1; */
-/* } */
-/* else */
+
+ hdr[hdrlen++] = c;
+ if (c < 192)
+ pktlen = c;
+ else if (c < 224)
{
- hdr[hdrlen++] = c;
- if( c < 192 )
- pktlen = c;
- else if( c < 224 )
- {
- pktlen = (c - 192) * 256;
- if( (c = iobuf_get(inp)) == -1 )
- {
- log_error("%s: 2nd length byte missing\n",
- iobuf_where(inp) );
- rc = gpg_error (GPG_ERR_INV_PACKET);
- goto leave;
- }
- hdr[hdrlen++] = c;
- pktlen += c + 192;
- }
- else if( c == 255 )
- {
- pktlen = (hdr[hdrlen++] = iobuf_get_noeof(inp)) << 24;
- pktlen |= (hdr[hdrlen++] = iobuf_get_noeof(inp)) << 16;
- pktlen |= (hdr[hdrlen++] = iobuf_get_noeof(inp)) << 8;
- if( (c = iobuf_get(inp)) == -1 )
- {
- log_error("%s: 4 byte length invalid\n",
- iobuf_where(inp) );
- rc = gpg_error (GPG_ERR_INV_PACKET);
- goto leave;
- }
- pktlen |= (hdr[hdrlen++] = c );
- }
- else
- {
- /* Partial body length. */
- switch (pkttype)
- {
- case PKT_PLAINTEXT:
- case PKT_ENCRYPTED:
- case PKT_ENCRYPTED_MDC:
- case PKT_COMPRESSED:
- iobuf_set_partial_block_mode(inp, c & 0xff);
- pktlen = 0;/* To indicate partial length. */
- partial=1;
- break;
+ pktlen = (c - 192) * 256;
+ if ((c = iobuf_get (inp)) == -1)
+ {
+ log_error ("%s: 2nd length byte missing\n",
+ iobuf_where (inp));
+ rc = gpg_error (GPG_ERR_INV_PACKET);
+ goto leave;
+ }
+ hdr[hdrlen++] = c;
+ pktlen += c + 192;
+ }
+ else if (c == 255)
+ {
+ pktlen = (hdr[hdrlen++] = iobuf_get_noeof (inp)) << 24;
+ pktlen |= (hdr[hdrlen++] = iobuf_get_noeof (inp)) << 16;
+ pktlen |= (hdr[hdrlen++] = iobuf_get_noeof (inp)) << 8;
+ if ((c = iobuf_get (inp)) == -1)
+ {
+ log_error ("%s: 4 byte length invalid\n", iobuf_where (inp));
+ rc = gpg_error (GPG_ERR_INV_PACKET);
+ goto leave;
+ }
+ pktlen |= (hdr[hdrlen++] = c);
+ }
+ else /* Partial body length. */
+ {
+ switch (pkttype)
+ {
+ case PKT_PLAINTEXT:
+ case PKT_ENCRYPTED:
+ case PKT_ENCRYPTED_MDC:
+ case PKT_COMPRESSED:
+ iobuf_set_partial_block_mode (inp, c & 0xff);
+ pktlen = 0; /* To indicate partial length. */
+ partial = 1;
+ break;
- default:
- log_error("%s: partial length for invalid"
- " packet type %d\n", iobuf_where(inp),pkttype);
- rc = gpg_error (GPG_ERR_INV_PACKET);
- goto leave;
- }
- }
+ default:
+ log_error ("%s: partial length for invalid"
+ " packet type %d\n", iobuf_where (inp), pkttype);
+ rc = gpg_error (GPG_ERR_INV_PACKET);
+ goto leave;
+ }
+ }
+
+ }
+ else
+ {
+ pkttype = (ctb >> 2) & 0xf;
+ lenbytes = ((ctb & 3) == 3) ? 0 : (1 << (ctb & 3));
+ if (!lenbytes)
+ {
+ pktlen = 0; /* Don't know the value. */
+ /* This isn't really partial, but we can treat it the same
+ in a "read until the end" sort of way. */
+ partial = 1;
+ if (pkttype != PKT_ENCRYPTED && pkttype != PKT_PLAINTEXT
+ && pkttype != PKT_COMPRESSED)
+ {
+ log_error ("%s: indeterminate length for invalid"
+ " packet type %d\n", iobuf_where (inp), pkttype);
+ rc = gpg_error (GPG_ERR_INV_PACKET);
+ goto leave;
+ }
}
+ else
+ {
+ for (; lenbytes; lenbytes--)
+ {
+ pktlen <<= 8;
+ pktlen |= hdr[hdrlen++] = iobuf_get_noeof (inp);
+ }
+ }
}
- else
- {
- pkttype = (ctb>>2)&0xf;
- lenbytes = ((ctb&3)==3)? 0 : (1<<(ctb & 3));
- if( !lenbytes )
- {
- pktlen = 0; /* don't know the value */
- /* This isn't really partial, but we can treat it the same
- in a "read until the end" sort of way. */
- partial=1;
- if(pkttype!=PKT_ENCRYPTED && pkttype!=PKT_PLAINTEXT
- && pkttype!=PKT_COMPRESSED)
- {
- log_error ("%s: indeterminate length for invalid"
- " packet type %d\n", iobuf_where(inp), pkttype );
- rc = gpg_error (GPG_ERR_INV_PACKET);
- goto leave;
- }
- }
- else
- {
- for( ; lenbytes; lenbytes-- )
- {
- pktlen <<= 8;
- pktlen |= hdr[hdrlen++] = iobuf_get_noeof(inp);
- }
- }
- }
- if (pktlen == (unsigned long)(-1)) {
- /* With some probability this is caused by a problem in the
- * the uncompressing layer - in some error cases it just loops
- * and spits out 0xff bytes. */
- log_error ("%s: garbled packet detected\n", iobuf_where(inp) );
- g10_exit (2);
+ if (pktlen == (unsigned long) (-1))
+ {
+ /* With some probability this is caused by a problem in the
+ * the uncompressing layer - in some error cases it just loops
+ * and spits out 0xff bytes. */
+ log_error ("%s: garbled packet detected\n", iobuf_where (inp));
+ g10_exit (2);
}
- if( out && pkttype ) {
+ if (out && pkttype)
+ {
rc = iobuf_write (out, hdr, hdrlen);
if (!rc)
- rc = copy_packet(inp, out, pkttype, pktlen, partial );
+ rc = copy_packet (inp, out, pkttype, pktlen, partial);
goto leave;
}
- if (with_uid && pkttype == PKT_USER_ID)
- ;
- else if( do_skip
- || !pkttype
- || (onlykeypkts && pkttype != PKT_PUBLIC_SUBKEY
- && pkttype != PKT_PUBLIC_KEY
- && pkttype != PKT_SECRET_SUBKEY
- && pkttype != PKT_SECRET_KEY ) ) {
- iobuf_skip_rest(inp, pktlen, partial);
- *skip = 1;
- rc = 0;
- goto leave;
+ if (with_uid && pkttype == PKT_USER_ID)
+ ;
+ else if (do_skip
+ || !pkttype
+ || (onlykeypkts && pkttype != PKT_PUBLIC_SUBKEY
+ && pkttype != PKT_PUBLIC_KEY
+ && pkttype != PKT_SECRET_SUBKEY && pkttype != PKT_SECRET_KEY))
+ {
+ iobuf_skip_rest (inp, pktlen, partial);
+ *skip = 1;
+ rc = 0;
+ goto leave;
}
- if( DBG_PACKET ) {
+ if (DBG_PACKET)
+ {
#ifdef DEBUG_PARSE_PACKET
- log_debug("parse_packet(iob=%d): type=%d length=%lu%s (%s.%s.%d)\n",
- iobuf_id(inp), pkttype, pktlen, new_ctb?" (new_ctb)":"",
- dbg_w, dbg_f, dbg_l );
+ log_debug ("parse_packet(iob=%d): type=%d length=%lu%s (%s.%s.%d)\n",
+ iobuf_id (inp), pkttype, pktlen, new_ctb ? " (new_ctb)" : "",
+ dbg_w, dbg_f, dbg_l);
#else
- log_debug("parse_packet(iob=%d): type=%d length=%lu%s\n",
- iobuf_id(inp), pkttype, pktlen, new_ctb?" (new_ctb)":"" );
+ log_debug ("parse_packet(iob=%d): type=%d length=%lu%s\n",
+ iobuf_id (inp), pkttype, pktlen,
+ new_ctb ? " (new_ctb)" : "");
#endif
}
- pkt->pkttype = pkttype;
- rc = G10ERR_UNKNOWN_PACKET; /* default error */
- switch( pkttype ) {
- case PKT_PUBLIC_KEY:
- case PKT_PUBLIC_SUBKEY:
- pkt->pkt.public_key = xmalloc_clear(sizeof *pkt->pkt.public_key );
- rc = parse_key(inp, pkttype, pktlen, hdr, hdrlen, pkt );
- break;
- case PKT_SECRET_KEY:
- case PKT_SECRET_SUBKEY:
- pkt->pkt.secret_key = xmalloc_clear(sizeof *pkt->pkt.secret_key );
- rc = parse_key(inp, pkttype, pktlen, hdr, hdrlen, pkt );
- break;
- case PKT_SYMKEY_ENC:
- rc = parse_symkeyenc( inp, pkttype, pktlen, pkt );
- break;
- case PKT_PUBKEY_ENC:
- rc = parse_pubkeyenc(inp, pkttype, pktlen, pkt );
- break;
- case PKT_SIGNATURE:
- pkt->pkt.signature = xmalloc_clear(sizeof *pkt->pkt.signature );
- rc = parse_signature(inp, pkttype, pktlen, pkt->pkt.signature );
- break;
- case PKT_ONEPASS_SIG:
- pkt->pkt.onepass_sig = xmalloc_clear(sizeof *pkt->pkt.onepass_sig );
- rc = parse_onepass_sig(inp, pkttype, pktlen, pkt->pkt.onepass_sig );
- break;
- case PKT_USER_ID:
- rc = parse_user_id(inp, pkttype, pktlen, pkt );
- break;
- case PKT_ATTRIBUTE:
- pkt->pkttype = pkttype = PKT_USER_ID; /* we store it in the userID */
- rc = parse_attribute(inp, pkttype, pktlen, pkt);
- break;
- case PKT_OLD_COMMENT:
- case PKT_COMMENT:
- rc = parse_comment(inp, pkttype, pktlen, pkt);
- break;
- case PKT_RING_TRUST:
- parse_trust(inp, pkttype, pktlen, pkt);
- rc = 0;
- break;
- case PKT_PLAINTEXT:
- rc = parse_plaintext(inp, pkttype, pktlen, pkt, new_ctb, partial );
- break;
- case PKT_COMPRESSED:
- rc = parse_compressed(inp, pkttype, pktlen, pkt, new_ctb );
- break;
- case PKT_ENCRYPTED:
- case PKT_ENCRYPTED_MDC:
- rc = parse_encrypted(inp, pkttype, pktlen, pkt, new_ctb, partial );
- break;
- case PKT_MDC:
- rc = parse_mdc(inp, pkttype, pktlen, pkt, new_ctb );
- break;
- case PKT_GPG_CONTROL:
- rc = parse_gpg_control(inp, pkttype, pktlen, pkt, partial );
- break;
+
+ pkt->pkttype = pkttype;
+ rc = G10ERR_UNKNOWN_PACKET; /* default error */
+ switch (pkttype)
+ {
+ case PKT_PUBLIC_KEY:
+ case PKT_PUBLIC_SUBKEY:
+ pkt->pkt.public_key = xmalloc_clear (sizeof *pkt->pkt.public_key);
+ rc = parse_key (inp, pkttype, pktlen, hdr, hdrlen, pkt);
+ break;
+ case PKT_SECRET_KEY:
+ case PKT_SECRET_SUBKEY:
+ pkt->pkt.secret_key = xmalloc_clear (sizeof *pkt->pkt.secret_key);
+ rc = parse_key (inp, pkttype, pktlen, hdr, hdrlen, pkt);
+ break;
+ case PKT_SYMKEY_ENC:
+ rc = parse_symkeyenc (inp, pkttype, pktlen, pkt);
+ break;
+ case PKT_PUBKEY_ENC:
+ rc = parse_pubkeyenc (inp, pkttype, pktlen, pkt);
+ break;
+ case PKT_SIGNATURE:
+ pkt->pkt.signature = xmalloc_clear (sizeof *pkt->pkt.signature);
+ rc = parse_signature (inp, pkttype, pktlen, pkt->pkt.signature);
+ break;
+ case PKT_ONEPASS_SIG:
+ pkt->pkt.onepass_sig = xmalloc_clear (sizeof *pkt->pkt.onepass_sig);
+ rc = parse_onepass_sig (inp, pkttype, pktlen, pkt->pkt.onepass_sig);
+ break;
+ case PKT_USER_ID:
+ rc = parse_user_id (inp, pkttype, pktlen, pkt);
+ break;
+ case PKT_ATTRIBUTE:
+ pkt->pkttype = pkttype = PKT_USER_ID; /* we store it in the userID */
+ rc = parse_attribute (inp, pkttype, pktlen, pkt);
+ break;
+ case PKT_OLD_COMMENT:
+ case PKT_COMMENT:
+ rc = parse_comment (inp, pkttype, pktlen, pkt);
+ break;
+ case PKT_RING_TRUST:
+ parse_trust (inp, pkttype, pktlen, pkt);
+ rc = 0;
+ break;
+ case PKT_PLAINTEXT:
+ rc = parse_plaintext (inp, pkttype, pktlen, pkt, new_ctb, partial);
+ break;
+ case PKT_COMPRESSED:
+ rc = parse_compressed (inp, pkttype, pktlen, pkt, new_ctb);
+ break;
+ case PKT_ENCRYPTED:
+ case PKT_ENCRYPTED_MDC:
+ rc = parse_encrypted (inp, pkttype, pktlen, pkt, new_ctb, partial);
+ break;
+ case PKT_MDC:
+ rc = parse_mdc (inp, pkttype, pktlen, pkt, new_ctb);
+ break;
+ case PKT_GPG_CONTROL:
+ rc = parse_gpg_control (inp, pkttype, pktlen, pkt, partial);
+ break;
case PKT_MARKER:
- rc = parse_marker(inp,pkttype,pktlen);
- break;
- default:
- skip_packet(inp, pkttype, pktlen, partial);
- break;
+ rc = parse_marker (inp, pkttype, pktlen);
+ break;
+ default:
+ skip_packet (inp, pkttype, pktlen, partial);
+ break;
}
- leave:
- if( !rc && iobuf_error(inp) )
- rc = G10ERR_INV_KEYRING;
- return rc;
+ leave:
+ if (!rc && iobuf_error (inp))
+ rc = G10ERR_INV_KEYRING;
+ return rc;
}
+
static void
-dump_hex_line( int c, int *i )
+dump_hex_line (int c, int *i)
{
- if( *i && !(*i%8) ) {
- if( *i && !(*i%24) )
- fprintf (listfp, "\n%4d:", *i );
- else
- putc (' ', listfp);
+ if (*i && !(*i % 8))
+ {
+ if (*i && !(*i % 24))
+ fprintf (listfp, "\n%4d:", *i);
+ else
+ putc (' ', listfp);
}
- if( c == -1 )
- fprintf (listfp, " EOF" );
- else
- fprintf (listfp, " %02x", c );
- ++*i;
+ if (c == -1)
+ fprintf (listfp, " EOF");
+ else
+ fprintf (listfp, " %02x", c);
+ ++*i;
}
static int
-copy_packet( IOBUF inp, IOBUF out, int pkttype,
- unsigned long pktlen, int partial )
+copy_packet (IOBUF inp, IOBUF out, int pkttype,
+ unsigned long pktlen, int partial)
{
- int rc;
- int n;
- char buf[100];
+ int rc;
+ int n;
+ char buf[100];
- if( partial ) {
- while( (n = iobuf_read( inp, buf, 100 )) != -1 )
- if( (rc=iobuf_write(out, buf, n )) )
- return rc; /* write error */
+ if (partial)
+ {
+ while ((n = iobuf_read (inp, buf, 100)) != -1)
+ if ((rc = iobuf_write (out, buf, n)))
+ return rc; /* write error */
}
- else if( !pktlen && pkttype == PKT_COMPRESSED ) {
- log_debug("copy_packet: compressed!\n");
- /* compressed packet, copy till EOF */
- while( (n = iobuf_read( inp, buf, 100 )) != -1 )
- if( (rc=iobuf_write(out, buf, n )) )
- return rc; /* write error */
+ else if (!pktlen && pkttype == PKT_COMPRESSED)
+ {
+ log_debug ("copy_packet: compressed!\n");
+ /* compressed packet, copy till EOF */
+ while ((n = iobuf_read (inp, buf, 100)) != -1)
+ if ((rc = iobuf_write (out, buf, n)))
+ return rc; /* write error */
}
- else {
- for( ; pktlen; pktlen -= n ) {
- n = pktlen > 100 ? 100 : pktlen;
- n = iobuf_read( inp, buf, n );
- if( n == -1 )
- return gpg_error (GPG_ERR_EOF);
- if( (rc=iobuf_write(out, buf, n )) )
- return rc; /* write error */
+ else
+ {
+ for (; pktlen; pktlen -= n)
+ {
+ n = pktlen > 100 ? 100 : pktlen;
+ n = iobuf_read (inp, buf, n);
+ if (n == -1)
+ return gpg_error (GPG_ERR_EOF);
+ if ((rc = iobuf_write (out, buf, n)))
+ return rc; /* write error */
}
}
- return 0;
+ return 0;
}
static void
-skip_packet( IOBUF inp, int pkttype, unsigned long pktlen, int partial )
+skip_packet (IOBUF inp, int pkttype, unsigned long pktlen, int partial)
{
- if( list_mode )
+ if (list_mode)
{
fprintf (listfp, ":unknown packet: type %2d, length %lu\n",
pkttype, pktlen);
- if( pkttype )
+ if (pkttype)
{
- int c, i=0 ;
- fputs("dump:", listfp );
- if( partial )
+ int c, i = 0;
+ fputs ("dump:", listfp);
+ if (partial)
{
- while( (c=iobuf_get(inp)) != -1 )
- dump_hex_line(c, &i);
+ while ((c = iobuf_get (inp)) != -1)
+ dump_hex_line (c, &i);
}
else
{
- for( ; pktlen; pktlen-- )
- {
- dump_hex_line( (c=iobuf_get(inp)), &i);
- if (c == -1)
- break;
- }
+ for (; pktlen; pktlen--)
+ {
+ dump_hex_line ((c = iobuf_get (inp)), &i);
+ if (c == -1)
+ break;
+ }
}
putc ('\n', listfp);
return;
}
}
- iobuf_skip_rest(inp,pktlen,partial);
+ iobuf_skip_rest (inp, pktlen, partial);
}
+
static void *
-read_rest( IOBUF inp, size_t pktlen, int partial )
+read_rest (IOBUF inp, size_t pktlen, int partial)
{
- byte *p;
- int i;
+ byte *p;
+ int i;
- if( partial ) {
- log_error("read_rest: can't store stream data\n");
- p = NULL;
+ if (partial)
+ {
+ log_error ("read_rest: can't store stream data\n");
+ p = NULL;
}
- else {
- p = xmalloc( pktlen );
- for(i=0; pktlen; pktlen--, i++ )
- p[i] = iobuf_get(inp);
+ else
+ {
+ p = xmalloc (pktlen);
+ for (i = 0; pktlen; pktlen--, i++)
+ p[i] = iobuf_get (inp);
}
- return p;
+ return p;
}
+
static int
-parse_marker( IOBUF inp, int pkttype, unsigned long pktlen )
+parse_marker (IOBUF inp, int pkttype, unsigned long pktlen)
{
- (void)pkttype;
+ (void) pkttype;
- if(pktlen!=3)
+ if (pktlen != 3)
goto fail;
- if(iobuf_get(inp)!='P')
+ if (iobuf_get (inp) != 'P')
{
pktlen--;
goto fail;
}
- if(iobuf_get(inp)!='G')
+ if (iobuf_get (inp) != 'G')
{
pktlen--;
goto fail;
}
- if(iobuf_get(inp)!='P')
+ if (iobuf_get (inp) != 'P')
{
pktlen--;
goto fail;
}
- if(list_mode)
- fputs(":marker packet: PGP\n", listfp );
+ if (list_mode)
+ fputs (":marker packet: PGP\n", listfp);
return 0;
fail:
- log_error("invalid marker packet\n");
- iobuf_skip_rest(inp,pktlen,0);
+ log_error ("invalid marker packet\n");
+ iobuf_skip_rest (inp, pktlen, 0);
return G10ERR_INVALID_PACKET;
}
+
static int
-parse_symkeyenc( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *packet )
+parse_symkeyenc (IOBUF inp, int pkttype, unsigned long pktlen,
+ PACKET * packet)
{
- PKT_symkey_enc *k;
- int rc = 0;
- int i, version, s2kmode, cipher_algo, hash_algo, seskeylen, minlen;
+ PKT_symkey_enc *k;
+ int rc = 0;
+ int i, version, s2kmode, cipher_algo, hash_algo, seskeylen, minlen;
- if( pktlen < 4 ) {
- log_error("packet(%d) too short\n", pkttype);
- rc = gpg_error (GPG_ERR_INV_PACKET);
- goto leave;
+ if (pktlen < 4)
+ {
+ log_error ("packet(%d) too short\n", pkttype);
+ rc = gpg_error (GPG_ERR_INV_PACKET);
+ goto leave;
}
- version = iobuf_get_noeof(inp); pktlen--;
- if( version != 4 ) {
- log_error("packet(%d) with unknown version %d\n", pkttype, version);
- rc = gpg_error (GPG_ERR_INV_PACKET);
- goto leave;
+ version = iobuf_get_noeof (inp);
+ pktlen--;
+ if (version != 4)
+ {
+ log_error ("packet(%d) with unknown version %d\n", pkttype, version);
+ rc = gpg_error (GPG_ERR_INV_PACKET);
+ goto leave;
}
- if( pktlen > 200 ) { /* (we encode the seskeylen in a byte) */
- log_error("packet(%d) too large\n", pkttype);
- rc = gpg_error (GPG_ERR_INV_PACKET);
- goto leave;
+ if (pktlen > 200)
+ { /* (we encode the seskeylen in a byte) */
+ log_error ("packet(%d) too large\n", pkttype);
+ rc = gpg_error (GPG_ERR_INV_PACKET);
+ goto leave;
}
- cipher_algo = iobuf_get_noeof(inp); pktlen--;
- s2kmode = iobuf_get_noeof(inp); pktlen--;
- hash_algo = iobuf_get_noeof(inp); pktlen--;
- switch( s2kmode ) {
- case 0: /* simple s2k */
- minlen = 0;
- break;
- case 1: /* salted s2k */
- minlen = 8;
- break;
- case 3: /* iterated+salted s2k */
- minlen = 9;
- break;
- default:
- log_error("unknown S2K %d\n", s2kmode );
- goto leave;
+ cipher_algo = iobuf_get_noeof (inp);
+ pktlen--;
+ s2kmode = iobuf_get_noeof (inp);
+ pktlen--;
+ hash_algo = iobuf_get_noeof (inp);
+ pktlen--;
+ switch (s2kmode)
+ {
+ case 0: /* Simple S2K. */
+ minlen = 0;
+ break;
+ case 1: /* Salted S2K. */
+ minlen = 8;
+ break;
+ case 3: /* Iterated+salted S2K. */
+ minlen = 9;
+ break;
+ default:
+ log_error ("unknown S2K mode %d\n", s2kmode);
+ goto leave;
}
- if( minlen > pktlen ) {
- log_error("packet with S2K %d too short\n", s2kmode );
- rc = gpg_error (GPG_ERR_INV_PACKET);
- goto leave;
+ if (minlen > pktlen)
+ {
+ log_error ("packet with S2K %d too short\n", s2kmode);
+ rc = gpg_error (GPG_ERR_INV_PACKET);
+ goto leave;
}
- seskeylen = pktlen - minlen;
- k = packet->pkt.symkey_enc = xmalloc_clear( sizeof *packet->pkt.symkey_enc
- + seskeylen - 1 );
- k->version = version;
- k->cipher_algo = cipher_algo;
- k->s2k.mode = s2kmode;
- k->s2k.hash_algo = hash_algo;
- if( s2kmode == 1 || s2kmode == 3 ) {
- for(i=0; i < 8 && pktlen; i++, pktlen-- )
- k->s2k.salt[i] = iobuf_get_noeof(inp);
+ seskeylen = pktlen - minlen;
+ k = packet->pkt.symkey_enc = xmalloc_clear (sizeof *packet->pkt.symkey_enc
+ + seskeylen - 1);
+ k->version = version;
+ k->cipher_algo = cipher_algo;
+ k->s2k.mode = s2kmode;
+ k->s2k.hash_algo = hash_algo;
+ if (s2kmode == 1 || s2kmode == 3)
+ {
+ for (i = 0; i < 8 && pktlen; i++, pktlen--)
+ k->s2k.salt[i] = iobuf_get_noeof (inp);
}
- if( s2kmode == 3 ) {
- k->s2k.count = iobuf_get(inp); pktlen--;
+ if (s2kmode == 3)
+ {
+ k->s2k.count = iobuf_get (inp);
+ pktlen--;
}
- k->seskeylen = seskeylen;
- if(k->seskeylen)
- {
- for(i=0; i < seskeylen && pktlen; i++, pktlen-- )
- k->seskey[i] = iobuf_get_noeof(inp);
+ k->seskeylen = seskeylen;
+ if (k->seskeylen)
+ {
+ for (i = 0; i < seskeylen && pktlen; i++, pktlen--)
+ k->seskey[i] = iobuf_get_noeof (inp);
- /* What we're watching out for here is a session key decryptor
- with no salt. The RFC says that using salt for this is a
- MUST. */
- if(s2kmode!=1 && s2kmode!=3)
- log_info(_("WARNING: potentially insecure symmetrically"
- " encrypted session key\n"));
- }
- assert( !pktlen );
+ /* What we're watching out for here is a session key decryptor
+ with no salt. The RFC says that using salt for this is a
+ MUST. */
+ if (s2kmode != 1 && s2kmode != 3)
+ log_info (_("WARNING: potentially insecure symmetrically"
+ " encrypted session key\n"));
+ }
+ assert (!pktlen);
- if( list_mode ) {
- fprintf (listfp, ":symkey enc packet: version %d, cipher %d, s2k %d, hash %d",
+ if (list_mode)
+ {
+ 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");
- if( s2kmode == 1 || s2kmode == 3 ) {
- fprintf (listfp, "\tsalt ");
- for(i=0; i < 8; i++ )
- fprintf (listfp, "%02x", k->s2k.salt[i]);
- if( s2kmode == 3 )
- fprintf (listfp, ", count %lu (%lu)",
- S2K_DECODE_COUNT((ulong)k->s2k.count),
- (ulong)k->s2k.count );
- fprintf (listfp, "\n");
+ if (seskeylen)
+ fprintf (listfp, ", seskey %d bits", (seskeylen - 1) * 8);
+ fprintf (listfp, "\n");
+ if (s2kmode == 1 || s2kmode == 3)
+ {
+ fprintf (listfp, "\tsalt ");
+ for (i = 0; i < 8; i++)
+ fprintf (listfp, "%02x", k->s2k.salt[i]);
+ if (s2kmode == 3)
+ fprintf (listfp, ", count %lu (%lu)",
+ S2K_DECODE_COUNT ((ulong) k->s2k.count),
+ (ulong) k->s2k.count);
+ fprintf (listfp, "\n");
}
}
- leave:
- iobuf_skip_rest(inp, pktlen, 0);
- return rc;
+ leave:
+ iobuf_skip_rest (inp, pktlen, 0);
+ return rc;
}
+
static int
-parse_pubkeyenc( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *packet )
+parse_pubkeyenc (IOBUF inp, int pkttype, unsigned long pktlen,
+ PACKET * packet)
{
- unsigned int n;
- int rc = 0;
- int i, ndata;
- PKT_pubkey_enc *k;
+ unsigned int n;
+ int rc = 0;
+ int i, ndata;
+ PKT_pubkey_enc *k;
- k = packet->pkt.pubkey_enc = xmalloc_clear(sizeof *packet->pkt.pubkey_enc);
- if( pktlen < 12 ) {
- log_error("packet(%d) too short\n", pkttype);
- rc = gpg_error (GPG_ERR_INV_PACKET);
- goto leave;
+ k = packet->pkt.pubkey_enc = xmalloc_clear (sizeof *packet->pkt.pubkey_enc);
+ if (pktlen < 12)
+ {
+ log_error ("packet(%d) too short\n", pkttype);
+ rc = gpg_error (GPG_ERR_INV_PACKET);
+ goto leave;
}
- k->version = iobuf_get_noeof(inp); pktlen--;
- if( k->version != 2 && k->version != 3 ) {
- log_error("packet(%d) with unknown version %d\n", pkttype, k->version);
- rc = gpg_error (GPG_ERR_INV_PACKET);
- goto leave;
+ k->version = iobuf_get_noeof (inp);
+ pktlen--;
+ if (k->version != 2 && k->version != 3)
+ {
+ log_error ("packet(%d) with unknown version %d\n", pkttype, k->version);
+ rc = gpg_error (GPG_ERR_INV_PACKET);
+ goto leave;
}
- k->keyid[0] = read_32(inp); pktlen -= 4;
- k->keyid[1] = read_32(inp); pktlen -= 4;
- k->pubkey_algo = iobuf_get_noeof(inp); 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]);
+ k->keyid[0] = read_32 (inp);
+ pktlen -= 4;
+ k->keyid[1] = read_32 (inp);
+ pktlen -= 4;
+ k->pubkey_algo = iobuf_get_noeof (inp);
+ 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]);
- ndata = pubkey_get_nenc(k->pubkey_algo);
- if( !ndata ) {
- if( list_mode )
- 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 */
+ ndata = pubkey_get_nenc (k->pubkey_algo);
More information about the Gnupg-commits
mailing list