1
1
/* parse-packet.c - read packets
2
* Copyright (C) 1998, 1999, 2000, 2001, 2002,
3
* 2003 Free Software Foundation, Inc.
2
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3
* 2007 Free Software Foundation, Inc.
5
5
* This file is part of GnuPG.
7
7
* GnuPG is free software; you can redistribute it and/or modify
8
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
9
* the Free Software Foundation; either version 3 of the License, or
10
10
* (at your option) any later version.
12
12
* GnuPG is distributed in the hope that it will be useful,
25
24
#include <string.h>
26
25
#include <assert.h>
28
28
#include "packet.h"
32
31
#include "cipher.h"
34
32
#include "filter.h"
35
33
#include "photoid.h"
36
34
#include "options.h"
40
static int mpi_print_mode = 0;
41
static int list_mode = 0;
38
static int mpi_print_mode;
43
static int parse( iobuf_t inp, PACKET *pkt, int onlykeypkts,
44
off_t *retpos, int *skip, iobuf_t out, int do_skip
42
static int parse( IOBUF inp, PACKET *pkt, int onlykeypkts,
43
off_t *retpos, int *skip, IOBUF out, int do_skip
45
44
#ifdef DEBUG_PARSE_PACKET
46
45
,const char *dbg_w, const char *dbg_f, int dbg_l
49
static int copy_packet( iobuf_t inp, iobuf_t out, int pkttype,
50
unsigned long pktlen );
51
static void skip_packet( iobuf_t inp, int pkttype, unsigned long pktlen );
52
static void skip_rest( iobuf_t inp, unsigned long pktlen );
53
static void *read_rest( iobuf_t inp, size_t pktlen );
54
static int parse_symkeyenc( iobuf_t inp, int pkttype, unsigned long pktlen,
56
static int parse_pubkeyenc( iobuf_t inp, int pkttype, unsigned long pktlen,
58
static int parse_signature( iobuf_t inp, int pkttype, unsigned long pktlen,
60
static int parse_onepass_sig( iobuf_t inp, int pkttype, unsigned long pktlen,
48
static int copy_packet( IOBUF inp, IOBUF out, int pkttype,
49
unsigned long pktlen, int partial );
50
static void skip_packet( IOBUF inp, int pkttype,
51
unsigned long pktlen, int partial );
52
static void *read_rest( IOBUF inp, size_t pktlen, int partial );
53
static int parse_marker( IOBUF inp, int pkttype, unsigned long pktlen );
54
static int parse_symkeyenc( IOBUF inp, int pkttype, unsigned long pktlen,
56
static int parse_pubkeyenc( IOBUF inp, int pkttype, unsigned long pktlen,
58
static int parse_onepass_sig( IOBUF inp, int pkttype, unsigned long pktlen,
61
59
PKT_onepass_sig *ops );
62
static int parse_key( iobuf_t inp, int pkttype, unsigned long pktlen,
60
static int parse_key( IOBUF inp, int pkttype, unsigned long pktlen,
63
61
byte *hdr, int hdrlen, PACKET *packet );
64
static int parse_user_id( iobuf_t inp, int pkttype, unsigned long pktlen,
66
static int parse_attribute( iobuf_t inp, int pkttype, unsigned long pktlen,
68
static int parse_comment( iobuf_t inp, int pkttype, unsigned long pktlen,
70
static void parse_trust( iobuf_t inp, int pkttype, unsigned long pktlen,
72
static int parse_plaintext( iobuf_t inp, int pkttype, unsigned long pktlen,
73
PACKET *packet, int new_ctb);
74
static int parse_compressed( iobuf_t inp, int pkttype, unsigned long pktlen,
62
static int parse_user_id( IOBUF inp, int pkttype, unsigned long pktlen,
64
static int parse_attribute( IOBUF inp, int pkttype, unsigned long pktlen,
66
static int parse_comment( IOBUF inp, int pkttype, unsigned long pktlen,
68
static void parse_trust( IOBUF inp, int pkttype, unsigned long pktlen,
70
static int parse_plaintext( IOBUF inp, int pkttype, unsigned long pktlen,
71
PACKET *packet, int new_ctb, int partial);
72
static int parse_compressed( IOBUF inp, int pkttype, unsigned long pktlen,
75
73
PACKET *packet, int new_ctb );
76
static int parse_encrypted( iobuf_t inp, int pkttype, unsigned long pktlen,
77
PACKET *packet, int new_ctb);
78
static int parse_mdc( iobuf_t inp, int pkttype, unsigned long pktlen,
79
PACKET *packet, int new_ctb);
80
static int parse_gpg_control( iobuf_t inp, int pkttype, unsigned long pktlen,
74
static int parse_encrypted( IOBUF inp, int pkttype, unsigned long pktlen,
75
PACKET *packet, int new_ctb, int partial);
76
static int parse_mdc( IOBUF inp, int pkttype, unsigned long pktlen,
77
PACKET *packet, int new_ctb);
78
static int parse_gpg_control( IOBUF inp, int pkttype, unsigned long pktlen,
79
PACKET *packet, int partial );
83
81
static unsigned short
87
85
a = iobuf_get_noeof(inp) << 8;
102
/* Read an external representation of an mpi and return the MPI. The
103
* external format is a 16 bit unsigned value stored in network byte
104
* order, giving the number of bits for the following integer. The
105
* integer is stored with MSB first (left padded with zeroes to align
106
* on a byte boundary).
109
mpi_read (iobuf_t inp, unsigned int *ret_nread, int secure)
111
/*FIXME: Needs to be synced with gnupg14/mpi/mpicoder.c*/
114
unsigned int nbits, nbytes;
120
if ( (c = c1 = iobuf_get (inp)) == -1 )
123
if ( (c = c2 = iobuf_get (inp)) == -1 )
126
if ( nbits > MAX_EXTERN_MPI_BITS )
128
log_error("mpi too large (%u bits)\n", nbits);
132
nbytes = (nbits+7) / 8;
133
buf = secure ? gcry_xmalloc_secure (nbytes + 2) : gcry_xmalloc (nbytes + 2);
137
for ( i=0 ; i < nbytes; i++ )
139
p[i+2] = iobuf_get(inp) & 0xff;
142
if ( gcry_mpi_scan( &a, GCRYMPI_FMT_PGP, buf, nread, &nread ) )
147
if ( nread > *ret_nread )
148
log_bug ("mpi larger than packet");
105
158
set_packet_list_mode( int mode )
107
160
int old = list_mode;
108
161
list_mode = mode;
109
/* FIXME(gcrypt) mpi_print_mode = DBG_MPI; */
162
/* FIXME(gcrypt) mpi_print_mode = DBG_MPI; */
163
/* We use stdout print only if invoked by the --list-packets
164
command but switch to stderr in all otehr cases. This breaks
165
the previous behaviour but that seems to be more of a bug than
166
intentional. I don't believe that any application makes use of
167
this long standing annoying way of printing to stdout except
168
when doing a --list-packets. If this assumption fails, it will
169
be easy to add an option for the listing stream. Note that we
170
initialize it only once; mainly because some code may switch
171
the option value later back to 1 and we want to have all output
174
Using stderr is not actually very clean because it bypasses the
175
logging code but it is a special thing anyay. I am not sure
176
whether using log_stream() would be better. Perhaps we should
177
enable the list mdoe only with a special option. */
179
listfp = opt.list_packets == 2 ? stdout : stderr;
322
392
pkttype = ctb & 0x3f;
323
393
if( (c = iobuf_get(inp)) == -1 ) {
324
394
log_error("%s: 1st length byte missing\n", iobuf_where(inp) );
325
rc = GPG_ERR_INV_PACKET;
395
rc = gpg_error (GPG_ERR_INV_PACKET);
328
398
if (pkttype == PKT_COMPRESSED) {
329
399
iobuf_set_partial_block_mode(inp, c & 0xff);
330
400
pktlen = 0;/* to indicate partial length */
333
404
hdr[hdrlen++] = c;
337
pktlen = (c - 192) * 256;
338
if( (c = iobuf_get(inp)) == -1 ) {
339
log_error("%s: 2nd length byte missing\n",
341
rc = GPG_ERR_INV_PACKET;
347
else if( c == 255 ) {
348
pktlen = (hdr[hdrlen++] = iobuf_get_noeof(inp)) << 24;
349
pktlen |= (hdr[hdrlen++] = iobuf_get_noeof(inp)) << 16;
350
pktlen |= (hdr[hdrlen++] = iobuf_get_noeof(inp)) << 8;
351
if( (c = iobuf_get(inp)) == -1 ) {
352
log_error("%s: 4 byte length invalid\n",
354
rc = GPG_ERR_INV_PACKET;
357
pktlen |= (hdr[hdrlen++] = c );
359
else { /* partial body length */
360
iobuf_set_partial_block_mode(inp, c & 0xff);
361
pktlen = 0;/* to indicate partial length */
409
pktlen = (c - 192) * 256;
410
if( (c = iobuf_get(inp)) == -1 )
412
log_error("%s: 2nd length byte missing\n",
414
rc = gpg_error (GPG_ERR_INV_PACKET);
422
pktlen = (hdr[hdrlen++] = iobuf_get_noeof(inp)) << 24;
423
pktlen |= (hdr[hdrlen++] = iobuf_get_noeof(inp)) << 16;
424
pktlen |= (hdr[hdrlen++] = iobuf_get_noeof(inp)) << 8;
425
if( (c = iobuf_get(inp)) == -1 )
427
log_error("%s: 4 byte length invalid\n",
429
rc = gpg_error (GPG_ERR_INV_PACKET);
432
pktlen |= (hdr[hdrlen++] = c );
436
/* Partial body length. Note that we handled
437
PKT_COMPRESSED earlier. */
438
if(pkttype==PKT_PLAINTEXT || pkttype==PKT_ENCRYPTED
439
|| pkttype==PKT_ENCRYPTED_MDC)
441
iobuf_set_partial_block_mode(inp, c & 0xff);
442
pktlen = 0;/* to indicate partial length */
447
log_error("%s: partial length for invalid"
448
" packet type %d\n",iobuf_where(inp),pkttype);
449
rc = gpg_error (GPG_ERR_INV_PACKET);
366
457
pkttype = (ctb>>2)&0xf;
367
458
lenbytes = ((ctb&3)==3)? 0 : (1<<(ctb & 3));
369
461
pktlen = 0; /* don't know the value */
373
/* These partial length encodings are from an very
374
early GnuPG release and deprecated. However we
375
still support them read-wise. Note, that we should
376
not allow them for any key related packets, because
377
this might render a keyring unusable if an errenous
378
packet indicated this mode but not complying to it
380
iobuf_set_block_mode(inp, 1);
384
break; /* the orginal pgp 2 way. */
387
log_error ("%s: old style partial length "
388
"for invalid packet type\n", iobuf_where(inp) );
462
/* This isn't really partial, but we can treat it the same
463
in a "read until the end" sort of way. */
465
if(pkttype!=PKT_ENCRYPTED && pkttype!=PKT_PLAINTEXT
466
&& pkttype!=PKT_COMPRESSED)
468
log_error ("%s: indeterminate length for invalid"
469
" packet type %d\n", iobuf_where(inp), pkttype );
389
470
rc = gpg_error (GPG_ERR_INV_PACKET);
394
for( ; lenbytes; lenbytes-- ) {
476
for( ; lenbytes; lenbytes-- )
396
479
pktlen |= hdr[hdrlen++] = iobuf_get_noeof(inp);
401
484
if (pktlen == 0xffffffff) {
402
485
/* with a some probability this is caused by a problem in the
482
565
case PKT_PLAINTEXT:
483
rc = parse_plaintext(inp, pkttype, pktlen, pkt, new_ctb );
566
rc = parse_plaintext(inp, pkttype, pktlen, pkt, new_ctb, partial );
485
568
case PKT_COMPRESSED:
486
569
rc = parse_compressed(inp, pkttype, pktlen, pkt, new_ctb );
488
571
case PKT_ENCRYPTED:
489
572
case PKT_ENCRYPTED_MDC:
490
rc = parse_encrypted(inp, pkttype, pktlen, pkt, new_ctb );
573
rc = parse_encrypted(inp, pkttype, pktlen, pkt, new_ctb, partial );
493
576
rc = parse_mdc(inp, pkttype, pktlen, pkt, new_ctb );
495
578
case PKT_GPG_CONTROL:
496
rc = parse_gpg_control(inp, pkttype, pktlen, pkt );
579
rc = parse_gpg_control(inp, pkttype, pktlen, pkt, partial );
582
rc = parse_marker(inp,pkttype,pktlen);
499
skip_packet(inp, pkttype, pktlen);
585
skip_packet(inp, pkttype, pktlen, partial);
504
590
if( !rc && iobuf_error(inp) )
505
rc = GPG_ERR_INV_KEYRING;
591
rc = G10ERR_INV_KEYRING;
512
598
if( *i && !(*i%8) ) {
513
599
if( *i && !(*i%24) )
514
printf("\n%4d:", *i );
600
fprintf (listfp, "\n%4d:", *i );
605
fprintf (listfp, " EOF" );
607
fprintf (listfp, " %02x", c );
527
copy_packet( iobuf_t inp, iobuf_t out, int pkttype, unsigned long pktlen )
613
copy_packet( IOBUF inp, IOBUF out, int pkttype,
614
unsigned long pktlen, int partial )
532
if( iobuf_in_block_mode(inp) ) {
533
621
while( (n = iobuf_read( inp, buf, 100 )) != -1 )
534
if( (rc = iobuf_write(out, buf, n )) )
622
if( (rc=iobuf_write(out, buf, n )) )
535
623
return rc; /* write error */
537
625
else if( !pktlen && pkttype == PKT_COMPRESSED ) {
538
626
log_debug("copy_packet: compressed!\n");
539
627
/* compressed packet, copy till EOF */
540
628
while( (n = iobuf_read( inp, buf, 100 )) != -1 )
541
if( (rc = iobuf_write(out, buf, n )) )
629
if( (rc=iobuf_write(out, buf, n )) )
542
630
return rc; /* write error */
559
skip_packet( iobuf_t inp, int pkttype, unsigned long pktlen )
647
skip_packet( IOBUF inp, int pkttype, unsigned long pktlen, int partial )
562
if( pkttype == PKT_MARKER )
563
fputs(":marker packet:\n", stdout );
565
printf(":unknown packet: type %2d, length %lu\n", pkttype, pktlen);
568
if( pkttype != PKT_MARKER )
569
fputs("dump:", stdout );
570
if( iobuf_in_block_mode(inp) ) {
571
while( (c=iobuf_get(inp)) != -1 )
572
dump_hex_line(c, &i);
575
for( ; pktlen; pktlen-- )
576
dump_hex_line(iobuf_get(inp), &i);
651
fprintf (listfp, ":unknown packet: type %2d, length %lu\n",
656
fputs("dump:", listfp );
659
while( (c=iobuf_get(inp)) != -1 )
660
dump_hex_line(c, &i);
664
for( ; pktlen; pktlen-- )
665
dump_hex_line(iobuf_get(inp), &i);
582
skip_rest(inp,pktlen);
586
skip_rest( iobuf_t inp, unsigned long pktlen )
588
if( iobuf_in_block_mode(inp) ) {
589
while( iobuf_get(inp) != -1 )
593
for( ; pktlen; pktlen-- )
594
if( iobuf_get(inp) == -1 )
671
iobuf_skip_rest(inp,pktlen,partial);
601
read_rest( iobuf_t inp, size_t pktlen )
675
read_rest( IOBUF inp, size_t pktlen, int partial )
606
if( iobuf_in_block_mode(inp) ) {
607
681
log_error("read_rest: can't store stream data\n");
611
p = xmalloc ( pktlen );
685
p = xmalloc( pktlen );
612
686
for(i=0; pktlen; pktlen--, i++ )
613
687
p[i] = iobuf_get(inp);
621
parse_symkeyenc( iobuf_t inp, int pkttype, unsigned long pktlen, PACKET *packet )
693
parse_marker( IOBUF inp, int pkttype, unsigned long pktlen )
698
if(iobuf_get(inp)!='P')
704
if(iobuf_get(inp)!='G')
710
if(iobuf_get(inp)!='P')
717
fputs(":marker packet: PGP\n", listfp );
722
log_error("invalid marker packet\n");
723
iobuf_skip_rest(inp,pktlen,0);
724
return G10ERR_INVALID_PACKET;
728
parse_symkeyenc( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *packet )
623
730
PKT_symkey_enc *k;
677
784
k->s2k.count = iobuf_get(inp); pktlen--;
679
786
k->seskeylen = seskeylen;
680
for(i=0; i < seskeylen && pktlen; i++, pktlen-- )
681
k->seskey[i] = iobuf_get_noeof(inp);
789
for(i=0; i < seskeylen && pktlen; i++, pktlen-- )
790
k->seskey[i] = iobuf_get_noeof(inp);
792
/* What we're watching out for here is a session key decryptor
793
with no salt. The RFC says that using salt for this is a
795
if(s2kmode!=1 && s2kmode!=3)
796
log_info(_("WARNING: potentially insecure symmetrically"
797
" encrypted session key\n"));
682
799
assert( !pktlen );
684
801
if( list_mode ) {
685
printf(":symkey enc packet: version %d, cipher %d, s2k %d, hash %d\n",
686
version, cipher_algo, s2kmode, hash_algo);
802
fprintf (listfp, ":symkey enc packet: version %d, cipher %d, s2k %d, hash %d",
803
version, cipher_algo, s2kmode, hash_algo);
805
fprintf (listfp, ", seskey %d bits",(seskeylen-1)*8);
806
fprintf (listfp, "\n");
687
807
if( s2kmode == 1 || s2kmode == 3 ) {
808
fprintf (listfp, "\tsalt ");
689
809
for(i=0; i < 8; i++ )
690
printf("%02x", k->s2k.salt[i]);
810
fprintf (listfp, "%02x", k->s2k.salt[i]);
691
811
if( s2kmode == 3 )
692
printf(", count %lu\n", (ulong)k->s2k.count );
812
fprintf (listfp, ", count %lu (%lu)",
813
S2K_DECODE_COUNT((ulong)k->s2k.count),
814
(ulong)k->s2k.count );
815
fprintf (listfp, "\n");
698
skip_rest(inp, pktlen);
820
iobuf_skip_rest(inp, pktlen, 0);
703
parse_pubkeyenc( iobuf_t inp, int pkttype, unsigned long pktlen, PACKET *packet )
825
parse_pubkeyenc( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *packet )
708
830
PKT_pubkey_enc *k;
710
k = packet->pkt.pubkey_enc = xcalloc (1,sizeof *packet->pkt.pubkey_enc);
832
k = packet->pkt.pubkey_enc = xmalloc_clear(sizeof *packet->pkt.pubkey_enc);
711
833
if( pktlen < 12 ) {
712
834
log_error("packet(%d) too short\n", pkttype);
713
rc = GPG_ERR_INV_PACKET;
835
rc = gpg_error (GPG_ERR_INV_PACKET);
716
838
k->version = iobuf_get_noeof(inp); pktlen--;
717
839
if( k->version != 2 && k->version != 3 ) {
718
840
log_error("packet(%d) with unknown version %d\n", pkttype, k->version);
719
rc = GPG_ERR_INV_PACKET;
841
rc = gpg_error (GPG_ERR_INV_PACKET);
722
844
k->keyid[0] = read_32(inp); pktlen -= 4;
765
887
* detect the ARRs - we print our old message here when it is a faked
766
888
* ARR and add an additional notice */
767
889
if ( type == SIGSUBPKT_ARR && !hashed ) {
768
printf("\tsubpkt %d len %u (additional recipient request)\n"
769
"WARNING: PGP versions > 5.0 and < 6.5.8 will automagically "
770
"encrypt to this key and thereby reveal the plaintext to "
771
"the owner of this ARR key. Detailed info follows:\n",
772
type, (unsigned)length );
891
"\tsubpkt %d len %u (additional recipient request)\n"
892
"WARNING: PGP versions > 5.0 and < 6.5.8 will automagically "
893
"encrypt to this key and thereby reveal the plaintext to "
894
"the owner of this ARR key. Detailed info follows:\n",
895
type, (unsigned)length );
778
printf("\t%s%ssubpkt %d len %u (", /*)*/
901
fprintf (listfp, "\t%s%ssubpkt %d len %u (", /*)*/
779
902
critical ? "critical ":"",
780
903
hashed ? "hashed ":"", type, (unsigned)length );
781
904
if( length > buflen ) {
782
printf("too short: buffer is only %u)\n", (unsigned)buflen );
905
fprintf (listfp, "too short: buffer is only %u)\n", (unsigned)buflen );
786
909
case SIGSUBPKT_SIG_CREATED:
787
910
if( length >= 4 )
788
printf("sig created %s", strtimestamp( buffer_to_u32(buffer) ) );
911
fprintf (listfp, "sig created %s", strtimestamp( buffer_to_u32(buffer) ) );
790
913
case SIGSUBPKT_SIG_EXPIRE:
791
914
if( length >= 4 )
792
printf("sig expires after %s",
793
strtimevalue( buffer_to_u32(buffer) ) );
916
if(buffer_to_u32(buffer))
917
fprintf (listfp, "sig expires after %s",
918
strtimevalue( buffer_to_u32(buffer) ) );
920
fprintf (listfp, "sig does not expire");
795
923
case SIGSUBPKT_EXPORTABLE:
797
printf("%sexportable", *buffer? "":"not ");
925
fprintf (listfp, "%sexportable", *buffer? "":"not ");
799
927
case SIGSUBPKT_TRUST:
801
929
p="[invalid trust subpacket]";
803
printf("trust signature of depth %d, value %d",buffer[0],buffer[1]);
931
fprintf (listfp, "trust signature of depth %d, value %d",buffer[0],buffer[1]);
805
933
case SIGSUBPKT_REGEXP:
807
935
p="[invalid regexp subpacket]";
809
printf("regular expression: \"%s\"",buffer);
937
fprintf (listfp, "regular expression: \"%s\"",buffer);
811
939
case SIGSUBPKT_REVOCABLE:
813
printf("%srevocable", *buffer? "":"not ");
941
fprintf (listfp, "%srevocable", *buffer? "":"not ");
815
943
case SIGSUBPKT_KEY_EXPIRE:
816
944
if( length >= 4 )
817
printf("key expires after %s",
818
strtimevalue( buffer_to_u32(buffer) ) );
946
if(buffer_to_u32(buffer))
947
fprintf (listfp, "key expires after %s",
948
strtimevalue( buffer_to_u32(buffer) ) );
950
fprintf (listfp, "key does not expire");
820
953
case SIGSUBPKT_PREF_SYM:
821
fputs("pref-sym-algos:", stdout );
954
fputs("pref-sym-algos:", listfp );
822
955
for( i=0; i < length; i++ )
823
printf(" %d", buffer[i] );
956
fprintf (listfp, " %d", buffer[i] );
825
958
case SIGSUBPKT_REV_KEY:
826
fputs("revocation key: ", stdout );
959
fputs("revocation key: ", listfp );
827
960
if( length < 22 )
828
961
p = "[too short]";
830
printf("c=%02x a=%d f=", buffer[0], buffer[1] );
963
fprintf (listfp, "c=%02x a=%d f=", buffer[0], buffer[1] );
831
964
for( i=2; i < length; i++ )
832
printf("%02X", buffer[i] );
965
fprintf (listfp, "%02X", buffer[i] );
835
968
case SIGSUBPKT_ISSUER:
836
969
if( length >= 8 )
837
printf("issuer key ID %08lX%08lX",
970
fprintf (listfp, "issuer key ID %08lX%08lX",
838
971
(ulong)buffer_to_u32(buffer),
839
972
(ulong)buffer_to_u32(buffer+4) );
841
974
case SIGSUBPKT_NOTATION:
843
fputs("notation: ", stdout );
976
fputs("notation: ", listfp );
845
978
p = "[too short]";
867
1000
case SIGSUBPKT_PREF_HASH:
868
fputs("pref-hash-algos:", stdout );
1001
fputs("pref-hash-algos:", listfp );
869
1002
for( i=0; i < length; i++ )
870
printf(" %d", buffer[i] );
1003
fprintf (listfp, " %d", buffer[i] );
872
1005
case SIGSUBPKT_PREF_COMPR:
873
fputs("pref-zip-algos:", stdout );
1006
fputs("pref-zip-algos:", listfp );
874
1007
for( i=0; i < length; i++ )
875
printf(" %d", buffer[i] );
1008
fprintf (listfp, " %d", buffer[i] );
877
1010
case SIGSUBPKT_KS_FLAGS:
878
fputs("key server preferences:",stdout);
1011
fputs("key server preferences:",listfp);
879
1012
for(i=0;i<length;i++)
880
printf(" %02X", buffer[i]);
1013
fprintf (listfp, " %02X", buffer[i]);
882
1015
case SIGSUBPKT_PREF_KS:
883
fputs("preferred key server: ", stdout );
884
print_string( stdout, buffer, length, ')' );
1016
fputs("preferred key server: ", listfp );
1017
print_string( listfp, buffer, length, ')' );
886
1019
case SIGSUBPKT_PRIMARY_UID:
887
1020
p = "primary user ID";
889
1022
case SIGSUBPKT_POLICY:
890
fputs("policy: ", stdout );
891
print_string( stdout, buffer, length, ')' );
1023
fputs("policy: ", listfp );
1024
print_string( listfp, buffer, length, ')' );
893
1026
case SIGSUBPKT_KEY_FLAGS:
894
fputs ( "key flags:", stdout );
1027
fputs ( "key flags:", listfp );
895
1028
for( i=0; i < length; i++ )
896
printf(" %02X", buffer[i] );
1029
fprintf (listfp, " %02X", buffer[i] );
898
1031
case SIGSUBPKT_SIGNERS_UID:
899
1032
p = "signer's user ID";
901
1034
case SIGSUBPKT_REVOC_REASON:
903
printf("revocation reason 0x%02x (", *buffer );
904
print_string( stdout, buffer+1, length-1, ')' );
1036
fprintf (listfp, "revocation reason 0x%02x (", *buffer );
1037
print_string( listfp, buffer+1, length-1, ')' );
908
1041
case SIGSUBPKT_ARR:
909
fputs("Big Brother's key (ignored): ", stdout );
1042
fputs("Big Brother's key (ignored): ", listfp );
910
1043
if( length < 22 )
911
1044
p = "[too short]";
913
printf("c=%02x a=%d f=", buffer[0], buffer[1] );
1046
fprintf (listfp, "c=%02x a=%d f=", buffer[0], buffer[1] );
914
1047
for( i=2; i < length; i++ )
915
printf("%02X", buffer[i] );
1048
fprintf (listfp, "%02X", buffer[i] );
918
1051
case SIGSUBPKT_FEATURES:
919
fputs ( "features:", stdout );
1052
fputs ( "features:", listfp );
920
1053
for( i=0; i < length; i++ )
921
printf(" %02x", buffer[i] );
1054
fprintf (listfp, " %02x", buffer[i] );
1056
case SIGSUBPKT_SIGNATURE:
1057
fputs("signature: ",listfp);
1061
fprintf (listfp, "v%d, class 0x%02X, algo %d, digest algo %d",
1063
buffer[0]==3?buffer[2]:buffer[1],
1064
buffer[0]==3?buffer[15]:buffer[2],
1065
buffer[0]==3?buffer[16]:buffer[3]);
924
1068
if(type>=100 && type<=110)
931
printf("%s)\n", p? p: "");
1075
fprintf (listfp, "%s)\n", p? p: "");
934
1078
/****************
935
* Returns: >= 0 offset into buffer
937
* -2 unsupported type
938
* -3 subpacket too short
1079
* Returns: >= 0 use this offset into buffer
1080
* -1 explicitly reject returning this type
1081
* -2 subpacket too short
941
1084
parse_one_sig_subpkt( const byte *buffer, size_t n, int type )
944
case SIGSUBPKT_REV_KEY:
948
case SIGSUBPKT_SIG_CREATED:
949
case SIGSUBPKT_SIG_EXPIRE:
950
case SIGSUBPKT_KEY_EXPIRE:
954
case SIGSUBPKT_KEY_FLAGS:
955
case SIGSUBPKT_KS_FLAGS:
956
case SIGSUBPKT_PREF_SYM:
957
case SIGSUBPKT_PREF_HASH:
958
case SIGSUBPKT_PREF_COMPR:
959
case SIGSUBPKT_POLICY:
960
case SIGSUBPKT_PREF_KS:
961
case SIGSUBPKT_FEATURES:
962
case SIGSUBPKT_REGEXP:
964
case SIGSUBPKT_EXPORTABLE:
965
case SIGSUBPKT_REVOCABLE:
969
case SIGSUBPKT_ISSUER: /* issuer key ID */
973
case SIGSUBPKT_NOTATION:
974
if( n < 8 ) /* minimum length needed */
977
case SIGSUBPKT_REVOC_REASON:
981
case SIGSUBPKT_PRIMARY_UID:
985
case SIGSUBPKT_TRUST:
1088
case SIGSUBPKT_REV_KEY:
1092
case SIGSUBPKT_SIG_CREATED:
1093
case SIGSUBPKT_SIG_EXPIRE:
1094
case SIGSUBPKT_KEY_EXPIRE:
1098
case SIGSUBPKT_KEY_FLAGS:
1099
case SIGSUBPKT_KS_FLAGS:
1100
case SIGSUBPKT_PREF_SYM:
1101
case SIGSUBPKT_PREF_HASH:
1102
case SIGSUBPKT_PREF_COMPR:
1103
case SIGSUBPKT_POLICY:
1104
case SIGSUBPKT_PREF_KS:
1105
case SIGSUBPKT_FEATURES:
1106
case SIGSUBPKT_REGEXP:
1108
case SIGSUBPKT_SIGNATURE:
1109
case SIGSUBPKT_EXPORTABLE:
1110
case SIGSUBPKT_REVOCABLE:
1111
case SIGSUBPKT_REVOC_REASON:
1115
case SIGSUBPKT_ISSUER: /* issuer key ID */
1119
case SIGSUBPKT_NOTATION:
1120
/* minimum length needed, and the subpacket must be well-formed
1121
where the name length and value length all fit inside the
1123
if(n<8 || 8+((buffer[4]<<8)|buffer[5])+((buffer[6]<<8)|buffer[7]) != n)
1126
case SIGSUBPKT_PRIMARY_UID:
1130
case SIGSUBPKT_TRUST:
1139
/* Not many critical notations we understand yet... */
1141
can_handle_critical_notation(const byte *name,size_t len)
1143
if(len==32 && memcmp(name,"preferred-email-encoding@pgp.com",32)==0)
1145
if(len==21 && memcmp(name,"pka-address@gnupg.org",21)==0)
996
1152
can_handle_critical( const byte *buffer, size_t n, int type )
999
case SIGSUBPKT_NOTATION:
1000
if( n >= 8 && (*buffer & 0x80) )
1001
return 1; /* human readable is handled */
1004
case SIGSUBPKT_SIG_CREATED:
1005
case SIGSUBPKT_SIG_EXPIRE:
1006
case SIGSUBPKT_KEY_EXPIRE:
1007
case SIGSUBPKT_EXPORTABLE:
1008
case SIGSUBPKT_REVOCABLE:
1009
case SIGSUBPKT_REV_KEY:
1010
case SIGSUBPKT_ISSUER:/* issuer key ID */
1011
case SIGSUBPKT_PREF_SYM:
1012
case SIGSUBPKT_PREF_HASH:
1013
case SIGSUBPKT_PREF_COMPR:
1014
case SIGSUBPKT_KEY_FLAGS:
1015
case SIGSUBPKT_PRIMARY_UID:
1016
case SIGSUBPKT_FEATURES:
1017
case SIGSUBPKT_TRUST:
1018
case SIGSUBPKT_REGEXP:
1019
/* Is it enough to show the policy or keyserver? */
1020
case SIGSUBPKT_POLICY:
1021
case SIGSUBPKT_PREF_KS:
1156
case SIGSUBPKT_NOTATION:
1158
return can_handle_critical_notation(buffer+8,(buffer[4]<<8)|buffer[5]);
1161
case SIGSUBPKT_SIGNATURE:
1162
case SIGSUBPKT_SIG_CREATED:
1163
case SIGSUBPKT_SIG_EXPIRE:
1164
case SIGSUBPKT_KEY_EXPIRE:
1165
case SIGSUBPKT_EXPORTABLE:
1166
case SIGSUBPKT_REVOCABLE:
1167
case SIGSUBPKT_REV_KEY:
1168
case SIGSUBPKT_ISSUER:/* issuer key ID */
1169
case SIGSUBPKT_PREF_SYM:
1170
case SIGSUBPKT_PREF_HASH:
1171
case SIGSUBPKT_PREF_COMPR:
1172
case SIGSUBPKT_KEY_FLAGS:
1173
case SIGSUBPKT_PRIMARY_UID:
1174
case SIGSUBPKT_FEATURES:
1175
case SIGSUBPKT_TRUST:
1176
case SIGSUBPKT_REGEXP:
1177
/* Is it enough to show the policy or keyserver? */
1178
case SIGSUBPKT_POLICY:
1179
case SIGSUBPKT_PREF_KS:
1260
1418
if( pktlen < 5 ) { /* sanity check */
1261
1419
log_error("packet(%d) too short\n", pkttype);
1262
rc = GPG_ERR_INV_PACKET;
1420
rc = G10ERR_INVALID_PACKET;
1266
1424
sig->digest_start[0] = iobuf_get_noeof(inp); pktlen--;
1267
1425
sig->digest_start[1] = iobuf_get_noeof(inp); pktlen--;
1269
if( is_v4 && sig->pubkey_algo ) { /*extract required information */
1427
if( is_v4 && sig->pubkey_algo )
1428
{ /*extract required information */
1273
1432
/* set sig->flags.unknown_critical if there is a
1274
1433
* critical bit set for packets which we do not understand */
1275
1434
if( !parse_sig_subpkt (sig->hashed, SIGSUBPKT_TEST_CRITICAL, NULL)
1276
|| !parse_sig_subpkt (sig->unhashed, SIGSUBPKT_TEST_CRITICAL,
1279
sig->flags.unknown_critical = 1;
1435
|| !parse_sig_subpkt (sig->unhashed, SIGSUBPKT_TEST_CRITICAL,
1437
sig->flags.unknown_critical = 1;
1282
1439
p = parse_sig_subpkt (sig->hashed, SIGSUBPKT_SIG_CREATED, NULL );
1284
1441
sig->timestamp = buffer_to_u32(p);
1285
else if(!(sig->pubkey_algo>=100 && sig->pubkey_algo<=110))
1286
log_error("signature packet without timestamp\n");
1442
else if(!(sig->pubkey_algo>=100 && sig->pubkey_algo<=110)
1444
log_info ("signature packet without timestamp\n");
1288
1446
p = parse_sig_subpkt2( sig, SIGSUBPKT_ISSUER, NULL );
1291
sig->keyid[0] = buffer_to_u32(p);
1292
sig->keyid[1] = buffer_to_u32(p+4);
1294
else if(!(sig->pubkey_algo>=100 && sig->pubkey_algo<=110))
1295
log_error("signature packet without keyid\n");
1449
sig->keyid[0] = buffer_to_u32(p);
1450
sig->keyid[1] = buffer_to_u32(p+4);
1452
else if(!(sig->pubkey_algo>=100 && sig->pubkey_algo<=110)
1454
log_info ("signature packet without keyid\n");
1297
1456
p=parse_sig_subpkt(sig->hashed,SIGSUBPKT_SIG_EXPIRE,NULL);
1457
if(p && buffer_to_u32(p))
1299
1458
sig->expiredate=sig->timestamp+buffer_to_u32(p);
1300
1459
if(sig->expiredate && sig->expiredate<=make_timestamp())
1301
sig->flags.expired=1;
1460
sig->flags.expired=1;
1303
1462
p=parse_sig_subpkt(sig->hashed,SIGSUBPKT_POLICY,NULL);
1365
1524
ndata = pubkey_get_nsig(sig->pubkey_algo);
1367
1526
if( list_mode )
1368
printf("\tunknown algorithm %d\n", sig->pubkey_algo );
1527
fprintf (listfp, "\tunknown algorithm %d\n", sig->pubkey_algo );
1369
1528
unknown_pubkey_warning( sig->pubkey_algo );
1370
/* we store the plain material in data[0], so that we are able
1529
/* We store the plain material in data[0], so that we are able
1371
1530
* to write it back with build_packet() */
1372
sig->data[0] = gcry_mpi_set_opaque(NULL, read_rest(inp, pktlen),
1531
if (pktlen > (5 * MAX_EXTERN_MPI_BITS/8))
1533
/* However we include a limit to avoid too trivial DoS
1534
attacks by having gpg allocate too much memory. */
1535
log_error ("signature packet: too much data\n");
1536
rc = G10ERR_INVALID_PACKET;
1540
sig->data[0]= gcry_mpi_set_opaque (NULL, read_rest(inp, pktlen, 0),
1377
1546
for( i=0; i < ndata; i++ ) {
1419
1588
ops->keyid[1] = read_32(inp); pktlen -= 4;
1420
1589
ops->last = iobuf_get_noeof(inp); pktlen--;
1421
1590
if( list_mode )
1422
printf(":onepass_sig packet: keyid %08lX%08lX\n"
1423
"\tversion %d, sigclass %02x, digest %d, pubkey %d, last=%d\n",
1592
":onepass_sig packet: keyid %08lX%08lX\n"
1593
"\tversion %d, sigclass 0x%02x, digest %d, pubkey %d, "
1424
1595
(ulong)ops->keyid[0], (ulong)ops->keyid[1],
1425
1596
version, ops->sig_class,
1426
1597
ops->digest_algo, ops->pubkey_algo, ops->last );
1430
skip_rest(inp, pktlen);
1601
iobuf_skip_rest(inp, pktlen, 0);
1435
1606
static gcry_mpi_t
1436
read_protected_v3_mpi (iobuf_t inp, unsigned long *length)
1607
read_protected_v3_mpi (IOBUF inp, unsigned long *length)
1439
1610
unsigned int nbits, nbytes;
1657
1828
switch( sk->protect.s2k.mode ) {
1658
case 0: if( list_mode ) printf( "\tsimple S2K" );
1660
case 1: if( list_mode ) printf( "\tsalted S2K" );
1662
case 3: if( list_mode ) printf( "\titer+salt S2K" );
1664
case 1001: if( list_mode ) printf( "\tgnu-dummy S2K" );
1666
case 1002: if (list_mode) printf("\tgnu-divert-to-card S2K");
1829
case 0: if( list_mode ) fprintf (listfp, "\tsimple S2K" );
1831
case 1: if( list_mode ) fprintf (listfp, "\tsalted S2K" );
1833
case 3: if( list_mode ) fprintf (listfp, "\titer+salt S2K" );
1835
case 1001: if( list_mode ) fprintf (listfp,
1836
"\tgnu-dummy S2K" );
1838
case 1002: if (list_mode) fprintf (listfp,
1839
"\tgnu-divert-to-card S2K");
1669
1842
if( list_mode )
1670
printf( "\tunknown %sS2K %d\n",
1843
fprintf (listfp, "\tunknown %sS2K %d\n",
1671
1844
sk->protect.s2k.mode < 1000? "":"GNU ",
1672
1845
sk->protect.s2k.mode );
1673
rc = GPG_ERR_INV_PACKET;
1846
rc = G10ERR_INVALID_PACKET;
1677
1850
if( list_mode ) {
1678
printf(", algo: %d,%s hash: %d",
1851
fprintf (listfp, ", algo: %d,%s hash: %d",
1679
1852
sk->protect.algo,
1680
1853
sk->protect.sha1chk?" SHA1 protection,"
1681
1854
:" simple checksum,",
1682
1855
sk->protect.s2k.hash_algo );
1683
1856
if( sk->protect.s2k.mode == 1
1684
1857
|| sk->protect.s2k.mode == 3 ) {
1858
fprintf (listfp, ", salt: ");
1686
1859
for(i=0; i < 8; i++ )
1687
printf("%02x", sk->protect.s2k.salt[i]);
1860
fprintf (listfp, "%02x", sk->protect.s2k.salt[i]);
1862
putc ('\n', listfp);
1692
1865
if( sk->protect.s2k.mode == 3 ) {
1693
1866
if( pktlen < 1 ) {
1694
rc = GPG_ERR_INV_PACKET;
1867
rc = G10ERR_INVALID_PACKET;
1697
1870
sk->protect.s2k.count = iobuf_get(inp);
1699
1872
if( list_mode )
1700
printf("\tprotect count: %lu\n",
1873
fprintf (listfp, "\tprotect count: %lu\n",
1701
1874
(ulong)sk->protect.s2k.count);
1703
1876
else if( sk->protect.s2k.mode == 1002 ) {
1704
1877
/* Read the serial number. */
1705
1878
if (pktlen < 1) {
1706
rc = GPG_ERR_INV_PACKET;
1879
rc = G10ERR_INVALID_PACKET;
1709
1882
snlen = iobuf_get (inp);
1711
1884
if (pktlen < snlen || snlen == -1) {
1712
rc = GPG_ERR_INV_PACKET;
1885
rc = G10ERR_INVALID_PACKET;
1769
1941
* If the user is so careless, not to protect his secret key,
1770
1942
* we can assume, that he operates an open system :=(.
1771
1943
* So we put the key into secure memory when we unprotect it. */
1772
if( sk->protect.s2k.mode == 1001
1944
if( sk->protect.s2k.mode == 1001
1773
1945
|| sk->protect.s2k.mode == 1002 ) {
1774
1946
/* better set some dummy stuff here */
1775
sk->skey[npkey] = gcry_mpi_set_opaque(NULL, xstrdup ("dummydata"),
1947
sk->skey[npkey] = gcry_mpi_set_opaque(NULL,
1948
xstrdup("dummydata"), 10*8);
1779
1951
else if( is_v4 && sk->is_protected ) {
1780
1952
/* ugly; the length is encrypted too, so we read all
1781
1953
* stuff up to the end of the packet into the first
1782
1954
* skey element */
1783
sk->skey[npkey] = gcry_mpi_set_opaque(NULL, read_rest(inp, pktlen),
1955
sk->skey[npkey] = gcry_mpi_set_opaque (NULL,
1956
read_rest(inp, pktlen, 0),
1786
1959
if( list_mode ) {
1787
printf("\tencrypted stuff follows\n");
1960
fprintf (listfp, "\tencrypted stuff follows\n");
1790
1963
else { /* v3 method: the mpi length is not encrypted */
1792
1965
if ( sk->is_protected ) {
1793
1966
sk->skey[i] = read_protected_v3_mpi (inp, &pktlen);
1794
1967
if( list_mode )
1795
printf( "\tskey[%d]: [encrypted]\n", i);
1968
fprintf (listfp, "\tskey[%d]: [encrypted]\n", i);
1799
1972
sk->skey[i] = mpi_read(inp, &n, 0 );
1801
1974
if( list_mode ) {
1802
printf( "\tskey[%d]: ", i);
1803
mpi_print(stdout, sk->skey[i], mpi_print_mode );
1975
fprintf (listfp, "\tskey[%d]: ", i);
1976
mpi_print(listfp, sk->skey[i], mpi_print_mode );
1977
putc ('\n', listfp);
1808
1981
if (!sk->skey[i])
1809
rc = GPG_ERR_INV_PACKET;
1982
rc = G10ERR_INVALID_PACKET;
1814
1987
sk->csum = read_16(inp); pktlen -= 2;
1815
1988
if( list_mode ) {
1816
printf("\tchecksum: %04hx\n", sk->csum);
1989
fprintf (listfp, "\tchecksum: %04hx\n", sk->csum);
1906
log_error("buffer shorter than attribute subpacket\n");
2081
log_info("buffer shorter than attribute subpacket\n");
1907
2082
uid->attribs=attribs;
1908
2083
uid->numattribs=count;
1912
static void setup_user_id(PACKET *packet)
1914
packet->pkt.user_id->ref = 1;
1915
packet->pkt.user_id->attribs = NULL;
1916
packet->pkt.user_id->attrib_data = NULL;
1917
packet->pkt.user_id->attrib_len = 0;
1918
packet->pkt.user_id->is_primary = 0;
1919
packet->pkt.user_id->is_revoked = 0;
1920
packet->pkt.user_id->is_expired = 0;
1921
packet->pkt.user_id->expiredate = 0;
1922
packet->pkt.user_id->created = 0;
1923
packet->pkt.user_id->help_key_usage = 0;
1924
packet->pkt.user_id->help_key_expire = 0;
1925
packet->pkt.user_id->prefs = NULL;
1926
packet->pkt.user_id->namehash = NULL;
1930
parse_user_id( iobuf_t inp, int pkttype, unsigned long pktlen, PACKET *packet )
2089
parse_user_id( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *packet )
2028
2185
make_attribute_uidname(packet->pkt.user_id, EXTRA_UID_NAME_SPACE);
2030
2187
if( list_mode ) {
2031
printf(":attribute packet: %s\n", packet->pkt.user_id->name );
2188
fprintf (listfp, ":attribute packet: %s\n", packet->pkt.user_id->name );
2038
parse_comment( iobuf_t inp, int pkttype, unsigned long pktlen, PACKET *packet )
2195
parse_comment( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *packet )
2042
packet->pkt.comment = xmalloc (sizeof *packet->pkt.comment + pktlen - 1);
2199
/* Cap comment packet at a reasonable value to avoid an integer
2200
overflow in the malloc below. Comment packets are actually not
2201
anymore define my OpenPGP and we even stopped to use our
2202
private comment packet. */
2205
log_error ("packet(%d) too large\n", pkttype);
2206
iobuf_skip_rest (inp, pktlen, 0);
2207
return G10ERR_INVALID_PACKET;
2209
packet->pkt.comment = xmalloc(sizeof *packet->pkt.comment + pktlen - 1);
2043
2210
packet->pkt.comment->len = pktlen;
2044
2211
p = packet->pkt.comment->data;
2045
2212
for( ; pktlen; pktlen--, p++ )
2082
2249
pkt->pkt.ring_trust->sigcache = c;
2084
2251
if( list_mode )
2085
printf(":trust packet: flag=%02x sigcache=%02x\n",
2252
fprintf (listfp, ":trust packet: flag=%02x sigcache=%02x\n",
2086
2253
pkt->pkt.ring_trust->trustval,
2087
2254
pkt->pkt.ring_trust->sigcache);
2091
2258
if( list_mode )
2092
printf(":trust packet: empty\n");
2259
fprintf (listfp, ":trust packet: empty\n");
2094
skip_rest (inp, pktlen);
2261
iobuf_skip_rest (inp, pktlen, 0);
2099
parse_plaintext( iobuf_t inp, int pkttype, unsigned long pktlen,
2100
PACKET *pkt, int new_ctb )
2266
parse_plaintext( IOBUF inp, int pkttype, unsigned long pktlen,
2267
PACKET *pkt, int new_ctb, int partial )
2103
int mode, namelen, partial=0;
2104
2271
PKT_plaintext *pt;
2108
if( pktlen && pktlen < 6 ) {
2275
if( !partial && pktlen < 6 ) {
2109
2276
log_error("packet(%d) too short (%lu)\n", pkttype, (ulong)pktlen);
2110
rc = GPG_ERR_INV_PACKET;
2277
rc = gpg_error (GPG_ERR_INV_PACKET);
2113
/* A packet length of zero indicates partial body length. A zero
2114
data length isn't a zero length packet due to the header (mode,
2115
name, etc), so this is accurate. */
2118
2280
mode = iobuf_get_noeof(inp); if( pktlen ) pktlen--;
2119
2281
namelen = iobuf_get_noeof(inp); if( pktlen ) pktlen--;
2120
pt = pkt->pkt.plaintext = xmalloc (sizeof *pkt->pkt.plaintext + namelen -1);
2282
/* Note that namelen will never exceed 255 bytes. */
2283
pt = pkt->pkt.plaintext = xmalloc(sizeof *pkt->pkt.plaintext + namelen -1);
2121
2284
pt->new_ctb = new_ctb;
2122
2285
pt->mode = mode;
2123
2286
pt->namelen = namelen;
2141
2304
if( list_mode ) {
2142
printf(":literal data packet:\n"
2143
"\tmode %c, created %lu, name=\"",
2144
mode >= ' ' && mode <'z'? mode : '?',
2305
fprintf (listfp, ":literal data packet:\n"
2306
"\tmode %c (%X), created %lu, name=\"",
2307
mode >= ' ' && mode <'z'? mode : '?', mode,
2145
2308
(ulong)pt->timestamp );
2146
2309
for(p=pt->name,i=0; i < namelen; p++, i++ ) {
2147
2310
if( *p >= ' ' && *p <= 'z' )
2150
printf("\\x%02x", *p );
2313
fprintf (listfp, "\\x%02x", *p );
2152
printf("\",\n\traw data: %lu bytes\n", (ulong)pt->len );
2315
fprintf (listfp, "\",\n\traw data: ");
2317
fprintf (listfp, "unknown length\n");
2319
fprintf (listfp, "%lu bytes\n", (ulong)pt->len );
2167
2334
* (this should be the last object in a file or
2168
2335
* the compress algorithm should know the length)
2170
zd = pkt->pkt.compressed = xmalloc (sizeof *pkt->pkt.compressed );
2337
zd = pkt->pkt.compressed = xmalloc(sizeof *pkt->pkt.compressed );
2171
2338
zd->algorithm = iobuf_get_noeof(inp);
2172
2339
zd->len = 0; /* not used */
2173
2340
zd->new_ctb = new_ctb;
2175
2342
if( list_mode )
2176
printf(":compressed packet: algo=%d\n", zd->algorithm);
2343
fprintf (listfp, ":compressed packet: algo=%d\n", zd->algorithm);
2182
parse_encrypted( iobuf_t inp, int pkttype, unsigned long pktlen,
2183
PACKET *pkt, int new_ctb )
2349
parse_encrypted( IOBUF inp, int pkttype, unsigned long pktlen,
2350
PACKET *pkt, int new_ctb, int partial )
2186
2353
PKT_encrypted *ed;
2187
2354
unsigned long orig_pktlen = pktlen;
2189
ed = pkt->pkt.encrypted = xmalloc (sizeof *pkt->pkt.encrypted );
2356
ed = pkt->pkt.encrypted = xmalloc(sizeof *pkt->pkt.encrypted );
2190
2357
ed->len = pktlen;
2191
2358
/* we don't know the extralen which is (cipher_blocksize+2)
2192
2359
because the algorithm ist not specified in this packet.
2208
2376
log_error("encrypted_mdc packet with unknown version %d\n",
2210
2378
/*skip_rest(inp, pktlen); should we really do this? */
2211
rc = GPG_ERR_INV_PACKET;
2379
rc = gpg_error (GPG_ERR_INV_PACKET);
2214
2382
ed->mdc_method = DIGEST_ALGO_SHA1;
2216
2384
if( orig_pktlen && pktlen < 10 ) { /* actually this is blocksize+2 */
2217
2385
log_error("packet(%d) too short\n", pkttype);
2218
rc = GPG_ERR_INV_PACKET;
2219
skip_rest(inp, pktlen);
2386
rc = G10ERR_INVALID_PACKET;
2387
iobuf_skip_rest(inp, pktlen, partial);
2222
2390
if( list_mode ) {
2223
2391
if( orig_pktlen )
2224
printf(":encrypted data packet:\n\tlength: %lu\n", orig_pktlen);
2392
fprintf (listfp, ":encrypted data packet:\n\tlength: %lu\n",
2226
printf(":encrypted data packet:\n\tlength: unknown\n");
2395
fprintf (listfp, ":encrypted data packet:\n\tlength: unknown\n");
2227
2396
if( ed->mdc_method )
2228
printf("\tmdc_method: %d\n", ed->mdc_method );
2397
fprintf (listfp, "\tmdc_method: %d\n", ed->mdc_method );
2407
/* Note, that this code is not anymore used in real life because now
2408
the MDC checking is done right after the encryption in
2240
parse_mdc( iobuf_t inp, int pkttype, unsigned long pktlen,
2411
parse_mdc( IOBUF inp, int pkttype, unsigned long pktlen,
2241
2412
PACKET *pkt, int new_ctb )
2247
mdc = pkt->pkt.mdc= xmalloc (sizeof *pkt->pkt.mdc );
2418
mdc = pkt->pkt.mdc = xmalloc(sizeof *pkt->pkt.mdc );
2248
2419
if( list_mode )
2249
printf(":mdc packet: length=%lu\n", pktlen);
2420
fprintf (listfp, ":mdc packet: length=%lu\n", pktlen);
2250
2421
if( !new_ctb || pktlen != 20 ) {
2251
2422
log_error("mdc_packet with invalid encoding\n");
2252
rc = GPG_ERR_INV_PACKET;
2423
rc = gpg_error (GPG_ERR_INV_PACKET);