summaryrefslogtreecommitdiffstats
path: root/src/file_gpg.c
blob: b1aadf0119652a3a565630f029fb899c500ce95c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
/*

    File: file_gpg.c

    Copyright (C) 2008-2012 Christophe GRENIER <grenier@cgsecurity.org>
  
    This software is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
  
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    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, write the Free Software Foundation, Inc., 51
    Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <stdio.h>
#include "types.h"
#include "common.h"
#include "filegen.h"
#ifdef DEBUG_GPG
#include "log.h"
#endif

static void register_header_check_gpg(file_stat_t *file_stat);
static int header_check_gpg(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new);

const file_hint_t file_hint_gpg= {
  .extension="gpg",
  .description="OpenPGP/GPG (Partial support)",
  .max_filesize=PHOTOREC_MAX_FILE_SIZE,
  .recover=1,
  .enable_by_default=1,
  .register_header_check=&register_header_check_gpg
};

/* See rfc4880 OpenPGP Message Format */

/* Public-Key Encrypted Session Key Packets */
#define OPENPGP_TAG_PUBKEY_ENC_SESSION_KEY	1
/* Signature Packet */
#define OPENPGP_TAG_SIGNATURE			2
/* Symmetric-Key Encrypted Session Key Packets */
#define OPENPGP_TAG_SYMKEY_ENC_SESSION_KEY	3
/* One-Pass Signature Packets (Tag 4) */
#define OPENPGP_TAG_ONE_PASS_SIG		4
/* Secret-Key Packet (Tag 5) */
#define OPENPGP_TAG_SEC_KEY			5
/* Public-Key Packet (Tag 6)*/
#define OPENPGP_TAG_PUB_KEY			6
/* Secret-Subkey Packet (Tag 7)	*/
#define OPENPGP_TAG_SEC_SUBKEY			7
/* Compressed Data Packet (Tag 8) */
/* Symmetrically Encrypted Data Packet */
#define OPENPGP_TAG_SYM_ENC_DATA		9
/* Marker Packet (Tag 10) */
#define OPENPGP_TAG_MARKER			10
/* Literal Data Packet (Tag 11)
 * Trust Packet (Tag 12) */
#define OPENPGP_TAG_TRUST			12
 /* User ID Packet */
#define OPENPGP_TAG_USER_ID			13
 /* Public-Subkey Packet (Tag 14) */
#define OPENPGP_TAG_PUB_SUBKEY			14
/* User Attribute Packet (Tag 17)
 */
/* Sym. Encrypted Integrity Protected Data Packet */
#define OPENPGP_TAG_SYM_ENC_INTEGRITY		18
 /* Modification Detection Code Packet (Tag 19) */

static const unsigned char pgp_header[5]= {0xa8, 0x03, 'P', 'G', 'P'};

static void register_header_check_gpg(file_stat_t *file_stat)
{
  static const unsigned char gpg_header_pkey_enc[1]= {0x85};
  static const unsigned char gpg_header_symkey_enc[1]= {0x8c};
  static const unsigned char gpg_header_seckey[1]= {0x95};
#if 1
  static const unsigned char gpg_header_pkey[1]= {0x99};
#endif
  register_header_check(0, gpg_header_seckey, sizeof(gpg_header_seckey), &header_check_gpg, file_stat);
  register_header_check(0, gpg_header_symkey_enc, sizeof(gpg_header_symkey_enc), &header_check_gpg, file_stat);
  register_header_check(0, gpg_header_pkey_enc, sizeof(gpg_header_pkey_enc), &header_check_gpg, file_stat);
  register_header_check(0, pgp_header, sizeof(pgp_header), &header_check_gpg, file_stat);
#if 1
  register_header_check(0, gpg_header_pkey, sizeof(gpg_header_pkey), &header_check_gpg, file_stat);
#endif
}

static unsigned int openpgp_packet_tag(const unsigned char *buf)
{
  /* Bit 7 -- Always one */
  if((buf[0]&0x80)==0)
    return 0;	/* Invalid */
  return ((buf[0]&0x40)==0?((buf[0]>>2)&0x0f):(buf[0]&0x3f));
}

static unsigned int old_format_packet_length(const unsigned char *buf, unsigned int *length_type, int *indeterminate_length)
{
  /* Old format */
  switch(buf[0]&0x3)
  {
    case 0:
      *length_type=2;
      return buf[1];
    case 1:
      *length_type=3;
      return (buf[1] << 8) | buf[2];
    case 2:
      *length_type=5;
      return (buf[1] << 24) |(buf[2] << 16) |  (buf[3] << 8) | buf[4];
    default:
      *length_type=1;
      *indeterminate_length=1;
      return 0;
  }
}

static unsigned int new_format_packet_length(const unsigned char *buf, unsigned int *length_type, int *partial_body_length)
{
  *partial_body_length=0;
  /* One-Octet Body Length */
  if(buf[0]<=191)
  {
    *length_type=1;
    return buf[0];
  }
  /* Two-Octet Body Length */
  if(buf[0]<=223)
  {
    *length_type=2;
    return ((buf[0] - 192) << 8) + buf[1] + 192;
  }
  /* Five-Octet Body Length */
  if(buf[0]==255)
  {
    *length_type=5;
    return (buf[1] << 24) | (buf[2] << 16) | (buf[3] << 8)  | buf[4];
  }
  /* Partial Body Lengths */
  *length_type=1;
  *partial_body_length=1;
  return 1 << (buf[0]& 0x1F);
}

static int is_valid_mpi(const uint16_t *size)
{
  if(be16(*size) <= 16384)
    return (be16(*size)+7)/8;
  return -1;
}

static  int is_valid_pubkey_algo(const int algo)
{
  /*  1          - RSA (Encrypt or Sign)
   *  2          - RSA Encrypt-Only
   *  3          - RSA Sign-Only
   *  16         - Elgamal (Encrypt-Only), see [ELGAMAL]
   *  17         - DSA (Digital Signature Standard)
   *  18         - Reserved for Elliptic Curve
   *  19         - Reserved for ECDSA
   *  20         - Elgamal (Encrypt or Sign)
   *  21         - Reserved for Diffie-Hellman (X9.42, as defined for IETF-S/MIME)
   *  100 to 110 - Private/Experimental algorithm
   */
  switch(algo)
  {
    case 1:
    case 2:
    case 3:
    case 16:
    case 17:
    case 20:
      return 1;
    default:
      return 0;
  }
}

static int is_valid_sym_algo(const int algo)
{
  /*
       0          - Plaintext or unencrypted data
       1          - IDEA [IDEA]
       2          - TripleDES (DES-EDE, [SCHNEIER] [HAC] -
                    168 bit key derived from 192)
       3          - CAST5 (128 bit key, as per [RFC2144])
       4          - Blowfish (128 bit key, 16 rounds) [BLOWFISH]
       5          - Reserved
       6          - Reserved
       7          - AES with 128-bit key [AES]
       8          - AES with 192-bit key
       9          - AES with 256-bit key
       10         - Twofish with 256-bit key [TWOFISH]
       100 to 110 - Private/Experimental algorithm
       */
  switch(algo)
  {
    case 1:
    case 2:
    case 3:
    case 4:
    case 7:
    case 8:
    case 9:
    case 10:
      return 1;
    default:
      return 0;
  }
}

static int is_valid_S2K(const unsigned int algo)
{
  /*  ID          S2K Type
   *  --          --------
   *  0           Simple S2K
   *  1           Salted S2K
   *  2           Reserved value
   *  3           Iterated and Salted S2K
   *  100 to 110  Private/Experimental S2K
   */
  return (algo==0 || algo==1 || algo==3);
}

static void file_check_gpg(file_recovery_t *file_recovery)
{
  unsigned int tag=0;
  unsigned int nbr=0;
  int partial_body_length=0;
  int stop=0;
  off_t offset=0;
  unsigned char buffer[32];
  const uint64_t org_file_size=file_recovery->file_size;
  file_recovery->file_size=0;
  while(stop==0)
  {
    unsigned int i=0;
    unsigned int length_type=0;
    unsigned int length;
    const int old_partial_body_length=partial_body_length;
    if(my_fseek(file_recovery->handle, offset, SEEK_SET) < 0 ||
	fread(&buffer, sizeof(buffer), 1, file_recovery->handle) != 1)
      return;

    if(partial_body_length==0)
    {
      if((buffer[i]&0x80)==0)
	break;	/* Invalid */
      tag=openpgp_packet_tag(&buffer[i]);
      if((buffer[i]&0x40)==0)
      {
	length=old_format_packet_length(&buffer[i], &length_type, &stop);
      }
      else
      {
	length=new_format_packet_length(&buffer[i+1], &length_type, &partial_body_length);
	length_type++;
      }
    }
    else
    {
      length=new_format_packet_length(&buffer[i], &length_type, &partial_body_length);
    }
#ifdef DEBUG_GPG
    log_info("GPG 0x%04x: %02u tag=%2u, size=%u + %u)\n",
	i, nbr, tag, length_type, length);
#endif
#if 0
    if(tag==0 || tag==15 || (tag>19 && tag!=61))	/* Reserved or unused */
      return;
#endif
    if(length_type==0)
      break;	/* Don't know how to find the size */
    i+=length_type;
    offset+=length_type;
    if(old_partial_body_length==0)
    {
      if(tag==OPENPGP_TAG_PUBKEY_ENC_SESSION_KEY)
      {
	const uint16_t *mpi=(const uint16_t *)&buffer[i+1+8+1];
	const int len=is_valid_mpi(mpi);
	/* uint8_t  version	must be 3
	 * uint64_t pub_key_id
	 * uint8_t  pub_key_algo
	 *          encrypted_session_key	*/
	if(buffer[i]==3 && is_valid_pubkey_algo(buffer[i+1+8]) &&
	    len>0)
	{
#ifdef DEBUG_GPG
	  log_info("GPG :pubkey enc packet: version %u, algo %u, keyid %02X%02X%02X%02X%02X%02X%02X%02X\n",
	      buffer[i], buffer[i+1+8],
	      buffer[i+1], buffer[i+2], buffer[i+3], buffer[i+4],
	      buffer[i+5], buffer[i+6], buffer[i+7], buffer[i+8]);
	  log_info(" data: [ %u bits]\n", be16(*mpi));
#endif
	  if((unsigned)(1+8+1+2+len) > length)
	    return ;
	  if(buffer[i+1+8]==16 || buffer[i+1+8]==20)
	  {
	    int len2;
	    unsigned char tmp[2];
	    if(my_fseek(file_recovery->handle, offset+1+8+1+2+len, SEEK_SET) < 0 ||
		fread(&tmp, sizeof(tmp), 1, file_recovery->handle) != 1)
	      return;
	    mpi=(const uint16_t *)&tmp[0];
	    len2=is_valid_mpi(mpi);
#ifdef DEBUG_GPG
	    log_info(" data: [ %u bits]\n", be16(*mpi));
#endif
	    if(len2 <= 0)
	      return ;
	    if((unsigned)(1+8+1+2+len+2+len2) > length)
	      return ;
	  }
	}
	else
	  return;
      }
      else if(tag==OPENPGP_TAG_SIGNATURE)
      {
	/* v3 - length=5 */
	if(buffer[i]==3 && buffer[i+1]==5 && is_valid_pubkey_algo(buffer[i+1+1+5+8]))
	{
#ifdef DEBUG_GPG
	  log_info(":signature packet: algo %u\n", buffer[i+1+1+5+8]);
	  log_info(":signature packet: sig_class 0x%02x\n", buffer[i+1+1]);
#endif
	}
	/* v4 */
	else if(buffer[i]==4 && is_valid_pubkey_algo(buffer[i+2]))
	{
#ifdef DEBUG_GPG
	  log_info(":signature packet: algo %u\n", buffer[i+2]);
#endif
	}
	else
	  return;
      }
      else if(tag==OPENPGP_TAG_SYMKEY_ENC_SESSION_KEY)
      {
	/* v4 */
	if(buffer[i]==4 && is_valid_sym_algo(buffer[i+1]) && is_valid_S2K(buffer[i+2]))
	{
	}
	else
	  return;
      }
      else if(tag==OPENPGP_TAG_ONE_PASS_SIG)
      {
	if(buffer[i]==3 && is_valid_sym_algo(buffer[i+1]))
	{
	}
	else
	  return;
      }
      else if(tag==OPENPGP_TAG_SYM_ENC_DATA)
      {
      }
      else if(tag==OPENPGP_TAG_MARKER)
      {
	/* Must be at the beginning of the packet */
	if(nbr!=0)
	  return;
      }
      else if(tag==OPENPGP_TAG_SYM_ENC_INTEGRITY)
      {
#ifdef DEBUG_GPG
	log_info("GPG :encrypted data packet:\n");
#endif
	/* Version must be 1 */
	if(buffer[i]!=1)
	  return;
      }
      else if(tag==OPENPGP_TAG_PUB_KEY ||
	  tag==OPENPGP_TAG_PUB_SUBKEY ||
	  tag==OPENPGP_TAG_SEC_KEY||
	  tag==OPENPGP_TAG_SEC_SUBKEY)
      {
	if((buffer[i]==2 || buffer[i]==3) && is_valid_pubkey_algo(buffer[i+1+4+2]))
	{ /* version 2 or 3 */
	}
	else if(buffer[i]==4 && is_valid_pubkey_algo(buffer[i+1+4]))
	{ /* version 4 */
	}
	else
	  return;
      }
    }
    if(partial_body_length==0)
      nbr++;
    offset+=length;
  }
  if(nbr<2)
    return;
  file_recovery->file_size=(stop==0?org_file_size:(uint64_t)offset);
}

static int header_check_gpg(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
  unsigned int packet_tag[16];
  unsigned int nbr=0;
  unsigned int i=0;
  int partial_body_length=0;
  int stop=0;
  memset(packet_tag, 0, sizeof(packet_tag));
  while(nbr<16 && i < buffer_size - 20 && stop==0)
  {
    unsigned int length_type=0;
    unsigned int tag;
    unsigned int length;
    const int old_partial_body_length=partial_body_length;
    if(partial_body_length==0)
    {
      if((buffer[i]&0x80)==0)
	break;	/* Invalid */
      packet_tag[nbr]=openpgp_packet_tag(&buffer[i]);
      if((buffer[i]&0x40)==0)
      {
	length=old_format_packet_length(&buffer[i], &length_type, &stop);
      }
      else
      {
	length=new_format_packet_length(&buffer[i+1], &length_type, &partial_body_length);
	length_type++;
      }
    }
    else
    {
      length=new_format_packet_length(&buffer[i], &length_type, &partial_body_length);
    }
    tag=packet_tag[nbr];
#ifdef DEBUG_GPG
    log_info("GPG 0x%04x: %02u tag=%2u, size=%u + %u)\n",
	i, nbr, tag, length_type, length);
#endif
#if 0
    if(tag==0 || tag==15 || (tag>19 && tag!=61))	/* Reserved or unused */
      return 0;
#endif
    if(length_type==0)
      break;	/* Don't know how to find the size */
    i+=length_type;
    if(old_partial_body_length==0)
    {
      if(tag==OPENPGP_TAG_PUBKEY_ENC_SESSION_KEY)
      {
	const uint16_t *mpi=(const uint16_t *)&buffer[i+1+8+1];
	const int len=is_valid_mpi(mpi);
	/* uint8_t  version	must be 3
	 * uint64_t pub_key_id
	 * uint8_t  pub_key_algo
	 *          encrypted_session_key	*/
	if(buffer[i]==3 && is_valid_pubkey_algo(buffer[i+1+8]) &&
	    len>0)
	{
#ifdef DEBUG_GPG
	  log_info("GPG :pubkey enc packet: version %u, algo %u, keyid %02X%02X%02X%02X%02X%02X%02X%02X\n",
	      buffer[i], buffer[i+1+8],
	      buffer[i+1], buffer[i+2], buffer[i+3], buffer[i+4],
	      buffer[i+5], buffer[i+6], buffer[i+7], buffer[i+8]);
	  log_info(" data: [ %u bits]\n", be16(*mpi));
#endif
	  if((unsigned)(1+8+1+2+len) > length)
	    return 0;
	  if((buffer[i+1+8]==16 || buffer[i+1+8]==20) &&
	      i+1+8+1+2+len+2<buffer_size)
	  {
	    int len2;
	    mpi=(const uint16_t *)&buffer[i+1+8+1+2+len];
	    len2=is_valid_mpi(mpi);
#ifdef DEBUG_GPG
	    log_info(" data: [ %u bits]\n", be16(*mpi));
#endif
	    if(len2 <= 0)
	      return 0;
	    if((unsigned)(1+8+1+2+len+2+len2) > length)
	      return 0;
	  }
	}
	else
	  return 0;
      }
      else if(tag==OPENPGP_TAG_SIGNATURE)
      {
	/* v3 - length=5 */
	if(buffer[i]==3 && buffer[i+1]==5 && is_valid_pubkey_algo(buffer[i+1+1+5+8]))
	{
#ifdef DEBUG_GPG
	  log_info(":signature packet: algo %u\n", buffer[i+1+1+5+8]);
	  log_info(":signature packet: sig_class 0x%02x\n", buffer[i+1+1]);
#endif
	}
	/* v4 */
	else if(buffer[i]==4 && is_valid_pubkey_algo(buffer[i+2]))
	{
#ifdef DEBUG_GPG
	  log_info(":signature packet: algo %u\n", buffer[i+2]);
#endif
	}
	else
	  return 0;
      }
      else if(tag==OPENPGP_TAG_SYMKEY_ENC_SESSION_KEY)
      {
	/* v4 */
	if(buffer[i]==4 && is_valid_sym_algo(buffer[i+1]) && is_valid_S2K(buffer[i+2]))
	{
	}
	else
	  return 0;
      }
      else if(tag==OPENPGP_TAG_ONE_PASS_SIG)
      {
	if(buffer[i]==3 && is_valid_sym_algo(buffer[i+1]))
	{
	}
	else
	  return 0;
      }
      else if(tag==OPENPGP_TAG_SYM_ENC_DATA)
      {
	unsigned int j;
	int ok=0;
	/* The symmetric cipher used may be specified in a Public-Key or
	 * Symmetric-Key Encrypted Session Key packet that precedes the
	 * Symmetrically Encrypted Data packet.
	 * PhotoRec assumes it must */
	for(j=0; j<nbr; j++)
	{
	  if(packet_tag[j]==OPENPGP_TAG_PUBKEY_ENC_SESSION_KEY ||
	      packet_tag[j]==OPENPGP_TAG_SYMKEY_ENC_SESSION_KEY)
	    ok=1;
	}
	if(ok==0)
	  return 0;
      }
      else if(tag==OPENPGP_TAG_MARKER)
      {
	/* Must be at the beginning of the packet */
	if(nbr!=0)
	  return 0;
      }
      else if(tag==OPENPGP_TAG_SYM_ENC_INTEGRITY)
      {
	unsigned int j;
	int ok=0;
#ifdef DEBUG_GPG
	log_info("GPG :encrypted data packet:\n");
#endif
	/* Version must be 1 */
	if(buffer[i]!=1)
	  return 0;
	/* The symmetric cipher used MUST be specified in a Public-Key or
	 * Symmetric-Key Encrypted Session Key packet that precedes the
	 * Symmetrically Encrypted Data packet. */
	for(j=0; j<nbr; j++)
	{
	  if(packet_tag[j]==OPENPGP_TAG_PUBKEY_ENC_SESSION_KEY ||
	      packet_tag[j]==OPENPGP_TAG_SYMKEY_ENC_SESSION_KEY)
	    ok=1;
	}
	if(ok==0)
	  return 0;
      }
      else if(tag==OPENPGP_TAG_PUB_KEY ||
	  tag==OPENPGP_TAG_PUB_SUBKEY ||
	  tag==OPENPGP_TAG_SEC_KEY||
	  tag==OPENPGP_TAG_SEC_SUBKEY)
      {
	if((buffer[i]==2 || buffer[i]==3) && is_valid_pubkey_algo(buffer[i+1+4+2]))
	{ /* version 2 or 3 */
	}
	else if(buffer[i]==4 && is_valid_pubkey_algo(buffer[i+1+4]))
	{ /* version 4 */
	}
	else
	  return 0;
      }
    }
    if(partial_body_length==0)
      nbr++;
    i+=length;
  }
  if(nbr<2)
    return 0;
  if(memcmp(buffer, pgp_header, sizeof(pgp_header))==0)
  {
    reset_file_recovery(file_recovery_new);
    file_recovery_new->file_check=&file_check_gpg;
    file_recovery_new->extension="pgp";
    return 1;
  }
  if( /* encrypted_data.gpg */
      ((packet_tag[0]==OPENPGP_TAG_PUBKEY_ENC_SESSION_KEY ||
	packet_tag[0]==OPENPGP_TAG_SYMKEY_ENC_SESSION_KEY) &&
       (packet_tag[1]==OPENPGP_TAG_SYM_ENC_DATA ||
	packet_tag[1]==OPENPGP_TAG_SYM_ENC_INTEGRITY)) ||
       /* pubring.gpg */
      (packet_tag[0]==OPENPGP_TAG_PUB_KEY &&
       packet_tag[1]==OPENPGP_TAG_USER_ID &&
       packet_tag[2]==OPENPGP_TAG_SIGNATURE &&
       packet_tag[3]==OPENPGP_TAG_TRUST) ||
      (packet_tag[0]==OPENPGP_TAG_PUB_KEY &&
       packet_tag[1]==OPENPGP_TAG_USER_ID &&
       packet_tag[2]==OPENPGP_TAG_SIGNATURE &&
       packet_tag[3]==OPENPGP_TAG_PUB_SUBKEY) ||
       /* secring.gpg */
      (packet_tag[0]==OPENPGP_TAG_SEC_KEY &&
       packet_tag[1]==OPENPGP_TAG_USER_ID &&
       packet_tag[2]==OPENPGP_TAG_SIGNATURE &&
       packet_tag[3]==OPENPGP_TAG_TRUST) ||
      (packet_tag[0]==OPENPGP_TAG_SEC_KEY &&
       packet_tag[1]==61 &&
       packet_tag[2]==61 &&
       packet_tag[3]==61)
    )
  {
    reset_file_recovery(file_recovery_new);
    file_recovery_new->file_check=&file_check_gpg;
    file_recovery_new->extension=file_hint_gpg.extension;
    return 1;
  }
#ifdef DEBUG_GPG
  log_info("tag don't match: nbr=%u - ", nbr);
  for(i=0; i<nbr; i++)
    log_info(" %u", packet_tag[i]);
  log_info("\n");
#endif
  return 0;
}