2 #------------------------------------------------------------------------------
3 # $File: pgp,v 1.11 2014/11/11 21:32:38 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 0 beshort 0x9900 PGP key public ring
8 !:mime application/x-pgp-keyring
9 0 beshort 0x9501 PGP key security ring
10 !:mime application/x-pgp-keyring
11 0 beshort 0x9500 PGP key security ring
12 !:mime application/x-pgp-keyring
13 0 beshort 0xa600 PGP encrypted data
14 #!:mime application/pgp-encrypted
15 #0 string -----BEGIN\040PGP text/PGP armored data
16 !:mime text/PGP # encoding: armored data
17 #>15 string PUBLIC\040KEY\040BLOCK- public key block
18 #>15 string MESSAGE- message
19 #>15 string SIGNED\040MESSAGE- signed message
20 #>15 string PGP\040SIGNATURE- signature
22 2 string ---BEGIN\ PGP\ PUBLIC\ KEY\ BLOCK- PGP public key block
23 !:mime application/pgp-keys
26 0 string -----BEGIN\040PGP\40MESSAGE- PGP message
27 !:mime application/pgp
30 0 string -----BEGIN\040PGP\40SIGNATURE- PGP signature
31 !:mime application/pgp-signature
35 # Decode the type of the packet based on it's base64 encoding.
36 # Idea from Mark Martinec
37 # The specification is in RFC 4880, section 4.2 and 4.3:
38 # http://tools.ietf.org/html/rfc4880#section-4.2
41 >0 byte 0x67 Reserved (old)
42 >0 byte 0x68 Public-Key Encrypted Session Key (old)
43 >0 byte 0x69 Signature (old)
44 >0 byte 0x6a Symmetric-Key Encrypted Session Key (old)
45 >0 byte 0x6b One-Pass Signature (old)
46 >0 byte 0x6c Secret-Key (old)
47 >0 byte 0x6d Public-Key (old)
48 >0 byte 0x6e Secret-Subkey (old)
49 >0 byte 0x6f Compressed Data (old)
50 >0 byte 0x70 Symmetrically Encrypted Data (old)
51 >0 byte 0x71 Marker (old)
52 >0 byte 0x72 Literal Data (old)
53 >0 byte 0x73 Trust (old)
54 >0 byte 0x74 User ID (old)
55 >0 byte 0x75 Public-Subkey (old)
56 >0 byte 0x76 Unused (old)
58 >>1 byte&0xc0 0x00 Reserved
59 >>1 byte&0xc0 0x40 Public-Key Encrypted Session Key
60 >>1 byte&0xc0 0x80 Signature
61 >>1 byte&0xc0 0xc0 Symmetric-Key Encrypted Session Key
63 >>1 byte&0xc0 0x00 One-Pass Signature
64 >>1 byte&0xc0 0x40 Secret-Key
65 >>1 byte&0xc0 0x80 Public-Key
66 >>1 byte&0xc0 0xc0 Secret-Subkey
68 >>1 byte&0xc0 0x00 Compressed Data
69 >>1 byte&0xc0 0x40 Symmetrically Encrypted Data
70 >>1 byte&0xc0 0x80 Marker
71 >>1 byte&0xc0 0xc0 Literal Data
73 >>1 byte&0xc0 0x00 Trust
74 >>1 byte&0xc0 0x40 User ID
75 >>1 byte&0xc0 0x80 Public-Subkey
76 >>1 byte&0xc0 0xc0 Unused [z%x]
78 >>1 byte&0xc0 0x00 Unused [0%x]
79 >>1 byte&0xc0 0x40 User Attribute
80 >>1 byte&0xc0 0x80 Sym. Encrypted and Integrity Protected Data
81 >>1 byte&0xc0 0xc0 Modification Detection Code
83 # magic signatures to detect PGP crypto material (from stef)
84 # detects and extracts metadata from:
85 # - symmetric encrypted packet header
86 # - RSA (e=65537) secret (sub-)keys
88 # 1024b RSA encrypted data
90 0 string \x84\x8c\x03 PGP RSA encrypted session key -
93 >11 byte 0x01 RSA (Encrypt or Sign) 1024b
94 >11 byte 0x02 RSA Encrypt-Only 1024b
105 # 2048b RSA encrypted data
107 0 string \x85\x01\x0c\x03 PGP RSA encrypted session key -
108 >4 lelong x keyid: %X
110 >12 byte 0x01 RSA (Encrypt or Sign) 2048b
111 >12 byte 0x02 RSA Encrypt-Only 2048b
122 # 3072b RSA encrypted data
124 0 string \x85\x01\x8c\x03 PGP RSA encrypted session key -
125 >4 lelong x keyid: %X
127 >12 byte 0x01 RSA (Encrypt or Sign) 3072b
128 >12 byte 0x02 RSA Encrypt-Only 3072b
139 # 3072b RSA encrypted data
141 0 string \x85\x02\x0c\x03 PGP RSA encrypted session key -
142 >4 lelong x keyid: %X
144 >12 byte 0x01 RSA (Encrypt or Sign) 4096b
145 >12 byte 0x02 RSA Encrypt-Only 4096b
156 # 4096b RSA encrypted data
158 0 string \x85\x04\x0c\x03 PGP RSA encrypted session key -
159 >4 lelong x keyid: %X
161 >12 byte 0x01 RSA (Encrypt or Sign) 8129b
162 >12 byte 0x02 RSA Encrypt-Only 8129b
176 >0 byte 0x00 Plaintext or unencrypted data
178 >0 byte 0x02 TripleDES
179 >0 byte 0x03 CAST5 (128 bit key)
180 >0 byte 0x04 Blowfish (128 bit key, 16 rounds)
181 >0 byte 0x07 AES with 128-bit key
182 >0 byte 0x08 AES with 192-bit key
183 >0 byte 0x09 AES with 256-bit key
184 >0 byte 0x0a Twofish with 256-bit key
191 >0 byte 0x03 RIPE-MD/160
197 # pgp symmetric encrypted data
199 0 byte 0x8c PGP symmetric key encrypted data -
204 >4 byte 0x01 salted -
208 >4 byte 0x03 salted & iterated -
213 # encrypted keymaterial needs s2k & can be checksummed/hashed
217 >1 byte 0x00 Simple S2K
218 >1 byte 0x01 Salted S2K
219 >1 byte 0x03 Salted&Iterated S2K
222 # all PGP keys start with this prolog
223 # containing version, creation date, and purpose
227 >1 beldate x created on %s -
228 >5 byte 0x01 RSA (Encrypt or Sign)
229 >5 byte 0x02 RSA Encrypt-Only
231 # end of secret keys known signature
232 # contains e=65537 and the prolog to
233 # the encrypted parameters
236 >0 string \x00\x11\x01\x00\x01 e=65537
238 >5 byte 0xff checksummed
243 # PGP secret keys contain also the public parts
244 # these vary by bitsize of the key
274 # \x00|\x1f[\xfe\xff]).{1024})'
282 # depending on the size of the pkt
283 # we branch into the proper key size
284 # signatures defined as x{keysize}
287 >0 string \x01\xd8 1024b
289 >0 string \x01\xeb 1024b
291 >0 string \x01\xfb 1024b
293 >0 string \x01\xfd 1024b
295 >0 string \x01\xf3 1024b
297 >0 string \x01\xee 1024b
299 >0 string \x01\xfe 1024b
301 >0 string \x01\xf4 1024b
303 >0 string \x02\x0d 1024b
305 >0 string \x02\x03 1024b
307 >0 string \x02\x05 1024b
309 >0 string \x02\x15 1024b
311 >0 string \x02\x00 1024b
313 >0 string \x02\x10 1024b
315 >0 string \x02\x04 1024b
317 >0 string \x02\x06 1024b
319 >0 string \x02\x16 1024b
321 >0 string \x03\x98 2048b
323 >0 string \x03\xab 2048b
325 >0 string \x03\xbb 2048b
327 >0 string \x03\xbd 2048b
329 >0 string \x03\xcd 2048b
331 >0 string \x03\xb3 2048b
333 >0 string \x03\xc3 2048b
335 >0 string \x03\xc5 2048b
337 >0 string \x03\xd5 2048b
339 >0 string \x03\xae 2048b
341 >0 string \x03\xbe 2048b
343 >0 string \x03\xc0 2048b
345 >0 string \x03\xd0 2048b
347 >0 string \x03\xb4 2048b
349 >0 string \x03\xc4 2048b
351 >0 string \x03\xc6 2048b
353 >0 string \x03\xd6 2048b
355 >0 string \x05X 3072b
357 >0 string \x05k 3072b
359 >0 string \x05{ 3072b
361 >0 string \x05} 3072b
363 >0 string \x05\x8d 3072b
365 >0 string \x05s 3072b
367 >0 string \x05\x83 3072b
369 >0 string \x05\x85 3072b
371 >0 string \x05\x95 3072b
373 >0 string \x05n 3072b
375 >0 string \x05\x7e 3072b
377 >0 string \x05\x80 3072b
379 >0 string \x05\x90 3072b
381 >0 string \x05t 3072b
383 >0 string \x05\x84 3072b
385 >0 string \x05\x86 3072b
387 >0 string \x05\x96 3072b
389 >0 string \x07[ 4096b
391 >0 string \x07\x18 4096b
393 >0 string \x07+ 4096b
395 >0 string \x07; 4096b
397 >0 string \x07= 4096b
399 >0 string \x07M 4096b
401 >0 string \x073 4096b
403 >0 string \x07C 4096b
405 >0 string \x07E 4096b
407 >0 string \x07U 4096b
409 >0 string \x07. 4096b
411 >0 string \x07> 4096b
413 >0 string \x07@ 4096b
415 >0 string \x07P 4096b
417 >0 string \x074 4096b
419 >0 string \x07D 4096b
421 >0 string \x07F 4096b
423 >0 string \x07V 4096b
425 >0 string \x0e[ 8192b
427 >0 string \x0e\x18 8192b
429 >0 string \x0e+ 8192b
431 >0 string \x0e; 8192b
433 >0 string \x0e= 8192b
435 >0 string \x0eM 8192b
437 >0 string \x0e3 8192b
439 >0 string \x0eC 8192b
441 >0 string \x0eE 8192b
443 >0 string \x0eU 8192b
445 >0 string \x0e. 8192b
447 >0 string \x0e> 8192b
449 >0 string \x0e@ 8192b
451 >0 string \x0eP 8192b
453 >0 string \x0e4 8192b
455 >0 string \x0eD 8192b
457 >0 string \x0eF 8192b
459 >0 string \x0eV 8192b
462 # PGP RSA (e=65537) secret (sub-)key header
464 0 byte 0x95 PGP Secret Key -
466 0 byte 0x97 PGP Secret Sub-key -
468 0 byte 0x9d PGP Secret Sub-key -