2 #------------------------------------------------------------------------------
3 # $File: pgp,v 1.15 2018/02/24 16:11:23 christos Exp $
4 # pgp: file(1) magic for Pretty Good Privacy
5 # see http://lists.gnupg.org/pipermail/gnupg-devel/1999-September/016052.html
7 # Update: Joerg Jenderek
8 # Note: verified by `gpg -v --debug 0x02 --list-packets < PUBRING263_10.PGP`
9 #0 byte 0x99 MAYBE PGP 0x99
11 # 99h~10;0110;01~2=old packet type;tag 6=Public-Key Packet;1=two-octet length
12 # A two-octet body header encodes packet lengths of 192~00C0h - 8383~20BFh
13 #>1 ubeshort x \b, body length 0x%.4x
14 # skip Basic.Image Beauty.320 Pic.Icons by looking for low version number
16 #>3 ubyte <5 VERSION OK
18 # next packet type often b4h~(tag 13)~User ID Packet, b0h~(tag 12)~Trust packet
19 #>>(1.S+3) ubyte x \b, next packet type 0x%x
20 # skip 9900-v4.bin 9902-v4.bin by looking for valid second packet type (bit 7=1)
21 #>>(1.S+3) ubyte >0x7F TYPE OK,
23 # old versions 2,3 implies Pretty Good Privacy
24 >>>3 ubyte <4 PGP key public ring (v%u)
25 !:mime application/pgp-keys
27 >>>>4 beldate x created %s
28 # days that this key is valid. If this number is zero, then it does not expire
29 >>>>8 ubeshort >0 \b, %u days valid
30 >>>>8 ubeshort =0 \b, not expire
31 # display key algorithm 1~RSA (Encrypt or Sign)
33 # Multiprecision Integers (MPI) size
34 >>>>11 ubeshort x %u bits
36 >>>>13 ubequad x MPI=0x%16.16llx...
37 # new version implies Pretty Good Privacy (PGP) >= 5.0 or Gnu Privacy Guard (GPG)
38 >>>3 ubyte >3 PGP/GPG key public ring (v%u)
39 !:mime application/pgp-keys
41 >>>>4 beldate x created %s
42 # display key algorithm 17~DSA
44 # Multiprecision Integers (MPI) size
45 >>>>9 ubeshort x %u bits
46 >>>>11 ubequad x MPI=0x%16.16llx...
48 0 beshort 0x9501 PGP key security ring
49 !:mime application/x-pgp-keyring
50 0 beshort 0x9500 PGP key security ring
51 !:mime application/x-pgp-keyring
52 0 beshort 0xa600 PGP encrypted data
53 #!:mime application/pgp-encrypted
54 #0 string -----BEGIN\040PGP text/PGP armored data
55 !:mime text/PGP # encoding: armored data
56 #>15 string PUBLIC\040KEY\040BLOCK- public key block
57 #>15 string MESSAGE- message
58 #>15 string SIGNED\040MESSAGE- signed message
59 #>15 string PGP\040SIGNATURE- signature
61 2 string ---BEGIN\040PGP\040PUBLIC\040KEY\040BLOCK- PGP public key block
62 !:mime application/pgp-keys
65 0 string -----BEGIN\040PGP\040MESSAGE- PGP message
66 !:mime application/pgp
69 0 string -----BEGIN\040PGP\040SIGNATURE- PGP signature
70 !:mime application/pgp-signature
74 # Decode the type of the packet based on it's base64 encoding.
75 # Idea from Mark Martinec
76 # The specification is in RFC 4880, section 4.2 and 4.3:
77 # http://tools.ietf.org/html/rfc4880#section-4.2
80 >0 byte 0x67 Reserved (old)
81 >0 byte 0x68 Public-Key Encrypted Session Key (old)
82 >0 byte 0x69 Signature (old)
83 >0 byte 0x6a Symmetric-Key Encrypted Session Key (old)
84 >0 byte 0x6b One-Pass Signature (old)
85 >0 byte 0x6c Secret-Key (old)
86 >0 byte 0x6d Public-Key (old)
87 >0 byte 0x6e Secret-Subkey (old)
88 >0 byte 0x6f Compressed Data (old)
89 >0 byte 0x70 Symmetrically Encrypted Data (old)
90 >0 byte 0x71 Marker (old)
91 >0 byte 0x72 Literal Data (old)
92 >0 byte 0x73 Trust (old)
93 >0 byte 0x74 User ID (old)
94 >0 byte 0x75 Public-Subkey (old)
95 >0 byte 0x76 Unused (old)
97 >>1 byte&0xc0 0x00 Reserved
98 >>1 byte&0xc0 0x40 Public-Key Encrypted Session Key
99 >>1 byte&0xc0 0x80 Signature
100 >>1 byte&0xc0 0xc0 Symmetric-Key Encrypted Session Key
102 >>1 byte&0xc0 0x00 One-Pass Signature
103 >>1 byte&0xc0 0x40 Secret-Key
104 >>1 byte&0xc0 0x80 Public-Key
105 >>1 byte&0xc0 0xc0 Secret-Subkey
107 >>1 byte&0xc0 0x00 Compressed Data
108 >>1 byte&0xc0 0x40 Symmetrically Encrypted Data
109 >>1 byte&0xc0 0x80 Marker
110 >>1 byte&0xc0 0xc0 Literal Data
112 >>1 byte&0xc0 0x00 Trust
113 >>1 byte&0xc0 0x40 User ID
114 >>1 byte&0xc0 0x80 Public-Subkey
115 >>1 byte&0xc0 0xc0 Unused [z%x]
117 >>1 byte&0xc0 0x00 Unused [0%x]
118 >>1 byte&0xc0 0x40 User Attribute
119 >>1 byte&0xc0 0x80 Sym. Encrypted and Integrity Protected Data
120 >>1 byte&0xc0 0xc0 Modification Detection Code
122 # magic signatures to detect PGP crypto material (from stef)
123 # detects and extracts metadata from:
124 # - symmetric encrypted packet header
125 # - RSA (e=65537) secret (sub-)keys
127 # 1024b RSA encrypted data
129 0 string \x84\x8c\x03 PGP RSA encrypted session key -
130 >3 lelong x keyid: %X
132 >11 byte 0x01 RSA (Encrypt or Sign) 1024b
133 >11 byte 0x02 RSA Encrypt-Only 1024b
144 # 2048b RSA encrypted data
146 0 string \x85\x01\x0c\x03 PGP RSA encrypted session key -
147 >4 lelong x keyid: %X
149 >12 byte 0x01 RSA (Encrypt or Sign) 2048b
150 >12 byte 0x02 RSA Encrypt-Only 2048b
161 # 3072b RSA encrypted data
163 0 string \x85\x01\x8c\x03 PGP RSA encrypted session key -
164 >4 lelong x keyid: %X
166 >12 byte 0x01 RSA (Encrypt or Sign) 3072b
167 >12 byte 0x02 RSA Encrypt-Only 3072b
178 # 3072b RSA encrypted data
180 0 string \x85\x02\x0c\x03 PGP RSA encrypted session key -
181 >4 lelong x keyid: %X
183 >12 byte 0x01 RSA (Encrypt or Sign) 4096b
184 >12 byte 0x02 RSA Encrypt-Only 4096b
195 # 4096b RSA encrypted data
197 0 string \x85\x04\x0c\x03 PGP RSA encrypted session key -
198 >4 lelong x keyid: %X
200 >12 byte 0x01 RSA (Encrypt or Sign) 8129b
201 >12 byte 0x02 RSA Encrypt-Only 8129b
215 >0 byte 0x00 Plaintext or unencrypted data
217 >0 byte 0x02 TripleDES
218 >0 byte 0x03 CAST5 (128 bit key)
219 >0 byte 0x04 Blowfish (128 bit key, 16 rounds)
220 >0 byte 0x07 AES with 128-bit key
221 >0 byte 0x08 AES with 192-bit key
222 >0 byte 0x09 AES with 256-bit key
223 >0 byte 0x0a Twofish with 256-bit key
230 >0 byte 0x03 RIPE-MD/160
236 # display public key algorithms as human readable text
238 >0 byte 0x01 RSA (Encrypt or Sign)
239 # keep old look of version 5.28 without parentheses
240 >0 byte 0x02 RSA Encrypt-Only
241 >0 byte 0x03 RSA (Sign-Only)
242 >0 byte 16 ElGamal (Encrypt-Only)
244 >0 byte 18 Elliptic Curve
246 >0 byte 20 ElGamal (Encrypt or Sign)
247 >0 byte 21 Diffie-Hellman
249 >>0 ubyte <22 unknown (pub %d)
250 # this should never happen
251 >>0 ubyte >21 invalid (%d)
253 # pgp symmetric encrypted data
255 0 byte 0x8c PGP symmetric key encrypted data -
260 >4 byte 0x01 salted -
264 >4 byte 0x03 salted & iterated -
269 # encrypted keymaterial needs s2k & can be checksummed/hashed
273 >1 byte 0x00 Simple S2K
274 >1 byte 0x01 Salted S2K
275 >1 byte 0x03 Salted&Iterated S2K
278 # all PGP keys start with this prolog
279 # containing version, creation date, and purpose
283 >1 beldate x created on %s -
284 >5 byte 0x01 RSA (Encrypt or Sign)
285 >5 byte 0x02 RSA Encrypt-Only
287 # end of secret keys known signature
288 # contains e=65537 and the prolog to
289 # the encrypted parameters
292 >0 string \x00\x11\x01\x00\x01 e=65537
294 >5 byte 0xff checksummed
299 # PGP secret keys contain also the public parts
300 # these vary by bitsize of the key
330 # \x00|\x1f[\xfe\xff]).{1024})'
338 # depending on the size of the pkt
339 # we branch into the proper key size
340 # signatures defined as x{keysize}
343 >0 string \x01\xd8 1024b
345 >0 string \x01\xeb 1024b
347 >0 string \x01\xfb 1024b
349 >0 string \x01\xfd 1024b
351 >0 string \x01\xf3 1024b
353 >0 string \x01\xee 1024b
355 >0 string \x01\xfe 1024b
357 >0 string \x01\xf4 1024b
359 >0 string \x02\x0d 1024b
361 >0 string \x02\x03 1024b
363 >0 string \x02\x05 1024b
365 >0 string \x02\x15 1024b
367 >0 string \x02\x00 1024b
369 >0 string \x02\x10 1024b
371 >0 string \x02\x04 1024b
373 >0 string \x02\x06 1024b
375 >0 string \x02\x16 1024b
377 >0 string \x03\x98 2048b
379 >0 string \x03\xab 2048b
381 >0 string \x03\xbb 2048b
383 >0 string \x03\xbd 2048b
385 >0 string \x03\xcd 2048b
387 >0 string \x03\xb3 2048b
389 >0 string \x03\xc3 2048b
391 >0 string \x03\xc5 2048b
393 >0 string \x03\xd5 2048b
395 >0 string \x03\xae 2048b
397 >0 string \x03\xbe 2048b
399 >0 string \x03\xc0 2048b
401 >0 string \x03\xd0 2048b
403 >0 string \x03\xb4 2048b
405 >0 string \x03\xc4 2048b
407 >0 string \x03\xc6 2048b
409 >0 string \x03\xd6 2048b
411 >0 string \x05X 3072b
413 >0 string \x05k 3072b
415 >0 string \x05{ 3072b
417 >0 string \x05} 3072b
419 >0 string \x05\x8d 3072b
421 >0 string \x05s 3072b
423 >0 string \x05\x83 3072b
425 >0 string \x05\x85 3072b
427 >0 string \x05\x95 3072b
429 >0 string \x05n 3072b
431 >0 string \x05\x7e 3072b
433 >0 string \x05\x80 3072b
435 >0 string \x05\x90 3072b
437 >0 string \x05t 3072b
439 >0 string \x05\x84 3072b
441 >0 string \x05\x86 3072b
443 >0 string \x05\x96 3072b
445 >0 string \x07[ 4096b
447 >0 string \x07\x18 4096b
449 >0 string \x07+ 4096b
451 >0 string \x07; 4096b
453 >0 string \x07= 4096b
455 >0 string \x07M 4096b
457 >0 string \x073 4096b
459 >0 string \x07C 4096b
461 >0 string \x07E 4096b
463 >0 string \x07U 4096b
465 >0 string \x07. 4096b
467 >0 string \x07> 4096b
469 >0 string \x07@ 4096b
471 >0 string \x07P 4096b
473 >0 string \x074 4096b
475 >0 string \x07D 4096b
477 >0 string \x07F 4096b
479 >0 string \x07V 4096b
481 >0 string \x0e[ 8192b
483 >0 string \x0e\x18 8192b
485 >0 string \x0e+ 8192b
487 >0 string \x0e; 8192b
489 >0 string \x0e= 8192b
491 >0 string \x0eM 8192b
493 >0 string \x0e3 8192b
495 >0 string \x0eC 8192b
497 >0 string \x0eE 8192b
499 >0 string \x0eU 8192b
501 >0 string \x0e. 8192b
503 >0 string \x0e> 8192b
505 >0 string \x0e@ 8192b
507 >0 string \x0eP 8192b
509 >0 string \x0e4 8192b
511 >0 string \x0eD 8192b
513 >0 string \x0eF 8192b
515 >0 string \x0eV 8192b
518 # PGP RSA (e=65537) secret (sub-)key header
520 0 byte 0x95 PGP Secret Key -
522 0 byte 0x97 PGP Secret Sub-key -
525 # Update: Joerg Jenderek
526 # secret subkey packet (tag 7) with same structure as secret key packet (tag 5)
527 # skip Fetus.Sys16 CALIBUS.MAIN OrbFix.Sys16.Ex by looking for positive len
529 #>1 ubeshort x \b, body length 0x%x
530 # next packet type often 88h,89h~(tag 2)~Signature Packet
531 #>>(1.S+3) ubyte x \b, next packet type 0x%x
532 # skip Dragon.SHR DEMO.INIT by looking for positive version
534 # skip BUISSON.13 GUITAR1 by looking for low version number
535 >>>3 ubyte <5 PGP Secret Sub-key
536 # sub-key are normally part of secret key. So it does not occur as standalone file
538 # version 2,3~old 4~new . Comment following line for version 5.28 look
541 # old versions 2 or 3 but no real example found
543 # 2 byte for key bits in version 5.28 look
544 >>>>>11 ubeshort x %db
545 >>>>>4 beldate x created on %s -
546 # old versions use 2 additional bytes after time stamp
547 #>>>>>8 ubeshort x 0x%x
548 # display key algorithm 1~RSA Encrypt|Sign - 21~Diffie-Hellman
550 >>>>>(11.S/8) ubequad x
551 # look after first key
555 >>>>>9 ubeshort x %db
556 >>>>>4 beldate x created on %s -
557 # display key algorithm
559 >>>>>(9.S/8) ubequad x
560 # look after first key for something like s2k