2 Format of "---with-colons" listings
3 ===================================
5 sec::1024:17:6C7EE1B8621CC013:1998-07-07:0:::Werner Koch <werner.koch@guug.de>:
6 ssb::1536:20:5CE086B5B5A18FF4:1998-07-07:0:::
8 1. Field: Type of record
10 sub = subkey (secondary key)
12 ssb = secret subkey (secondary key)
13 uid = user id (only field 10 is used).
14 fpr = fingerprint: (fingerprint is in field 10)
16 2. Field: A letter describing the calculated trust, see doc/FAQ
17 This is a single letter, but be prepared that additional
18 information may follow in some future versions.
19 (not used for secret keys)
20 3. Field: length of key in bits.
21 4. Field: Algorithm: 1 = RSA
22 16 = ElGamal (encrypt only)
23 17 = DSA (sometimes called DH, sign only)
24 20 = ElGamal (sign and encrypt)
26 6. Field: Creation Date (in UTC)
27 7. Field: Key expiration date or empty if none.
28 8. Field: Local ID: record number of the dir record in the trustdb
29 this value is only valid as long as the trustdb is not
30 deleted. May be later used to lookup the key: You will be
31 able to use "#<local-id> as the user id. This is needed
32 because keyids may not be unique - a program may use this
33 number to access keys later.
34 9. Field: Ownertrust (primary public keys only)
35 This is a single letter, but be prepared that additional
36 information may follow in some future versions.
37 10. Field: User-ID. The value is quoted like a C string to avoid
38 control characters (the colon is quoted "\x3a").
40 More fields may be added later.
43 Format of the "--status-fd" output
44 ==================================
45 Every line is prefixed with "[GNUPG:] ", followed by a keyword with
46 the type of the status line and a some arguments depending on the
47 type (maybe none); an application should always be prepared to see
48 more arguments in future versions.
51 GOODSIG <long keyid> <username>
52 The signature with the keyid is good.
54 BADSIG <long keyid> <username>
55 The signature with the keyid has not been verified okay.
57 ERRSIG <long keyid> <algorithm_number>
58 It was not possible to check the signature. This may be
59 caused by a missing public key or an unsupported algorithm.
61 VALIDSIG <fingerprint in hex>
62 The signature with the keyid is good. This is the same
63 as GOODSIG but has the fingerprint as the argument. Both
64 status lines ere emitted for a good signature.
66 SIG_ID <radix64_string> <sig_creation_date>
67 This is emitted only for signatures which
68 have been verified okay. The string is a signature id
69 and may be used in applications to detect replay attacks
70 of signed messages. Note that only DLP algorithms give
71 unique ids - others may yield duplicated ones when they
72 have been created in the same second.
75 The message is encrypted to this keyid.
78 No data has been found. Codes for what are:
86 For good signatures one of these status lines are emitted
87 to indicate how trustworthy the signature is. No arguments yet.
90 The signature key has expired. No arguments yet.
93 The used key has been revoked by his owner. No arguments yet.
96 The ASCII armor is corrupted. No arguments yet.
99 The RSA or IDEA algorithms has been used in the data. A
100 program might want to fallback to another program to handle
101 the data if GnuPG failed.
108 NEED_PASSPHRASE <long keyid>
109 Issued whenever a passphrase is needed.
111 NEED_PASSPHRASE_SYM <cipher_algo> <s2k_mode> <s2k_hash>
112 Issued whenever a passphrase for symmetric encryption is needed.
116 BAD_PASSPHRASE <long keyid>
117 The supplied passphrase was wrong
120 The supplied passphrase was good and the secret key material
121 is therefore usuable.
124 The symmetric decryption failed - one reason could be a wrong
125 passphrase for a symmetrical encrypted message.
128 The decryption process succeeded. This means, that either the
129 correct secret key has been used or the correct passphrase
130 for a conventional encrypted message was given. The program
131 itself may return an errorcode becuase it may not be possible to
132 verify a signature for some reasons.
134 NO_PUBKEY <long keyid>
135 NO_SECKEY <long keyid>
136 The key is not available
141 Key generation shows progress by printing different characters to
143 "." Last 10 Miller-Rabin tests failed
144 "+" Miller-Rabin test succeeded
145 "!" Reloading the pool with fresh prime numbers
146 "^" Checking a new value for the generator
147 "<" Size of one factor decreased
148 ">" Size of one factor increased
150 The prime number for ElGamal is generated this way:
152 1) Make a prime number q of 160, 200, 240 bits (depending on the keysize)
153 2) Select the length of the other prime factors to be at least the size
154 of q and calculate the number of prime factors needed
155 3) Make a pool of prime numbers, each of the length determined in step 2
156 4) Get a new permutation out of the pool or continue with step 3
157 if we have tested all permutations.
158 5) Calculate a candidate prime p = 2 * q * p[1] * ... * p[n] + 1
159 6) Check that this prime has the correct length (this may change q if
160 it seems not to be possible to make a prime of the desired length)
161 7) Check whether this is a prime using trial divisions and the
163 8) Continue with step 4 if we did not find a prime in step 7.
164 9) Find a generator for that prime.
166 This algorithm is based on Lim and Lee's suggestion from the
167 Crypto '97 proceedings p. 260.
171 Layout of the TrustDB
172 =====================
173 The TrustDB is built from fixed length records, where the first byte
174 describes the record type. All numeric values are stored in network
175 byte order. The length of each record is 40 bytes. The first record of
176 the DB is always of type 2 and this is the only record of this type.
180 Unused record, can be reused for any purpose.
184 Version information for this TrustDB. This is always the first
185 record of the DB and the only one with type 1.
187 3 bytes 'gpg' magic value
188 1 byte Version of the TrustDB (2)
189 1 byte marginals needed
190 1 byte completes needed
191 1 byte max_cert_depth
192 The three items are used to check whether the cached
193 validity value from the dir record can be used.
195 1 u32 timestamp of trustdb creation
196 1 u32 timestamp of last modification which may affect the validity
197 of keys in the trustdb. This value is checked against the
198 validity timestamp in the dir records.
199 1 u32 timestamp of last validation
200 (Used to keep track of the time, when this TrustDB was checked
202 1 u32 record number of keyhashtable
203 1 u32 first free record
204 1 u32 record number of shadow directory hash table
205 It does not make sense to combine this table with the key table
206 because the keyid is not in every case a part of the fingerprint.
207 4 bytes reserved for version extension record
210 Record type 2: (directory record)
212 Informations about a public key certificate.
213 These are static values which are never changed without user interaction.
217 1 u32 LID . (This is simply the record number of this record.)
218 1 u32 List of key-records (the first one is the primary key)
219 1 u32 List of uid-records
223 1 byte maximum validity of all the user ids
224 4 byte time of last validity check.
228 Record type 3: (key record)
230 Informations about a primary public key.
231 (This is mainly used to lookup a trust record)
236 1 u32 next - next key record
239 1 byte pubkey algorithm
240 1 byte length of the fingerprint (in bytes)
241 20 bytes fingerprint of the public key
242 (This is the value we use to identify a key)
244 Record type 4: (uid record)
246 Informations about a userid
247 We do not store the userid but the hash value of the userid because that
252 1 u32 LID points to the directory record.
253 1 u32 next next userid
254 1 u32 pointer to preference record
255 1 u32 siglist list of valid signatures
257 1 byte validity of the key calculated over this user id
258 20 bytes ripemd160 hash of the username.
261 Record type 5: (pref record)
263 Informations about preferences
267 1 u32 LID; points to the directory record (and not to the uid record!).
268 (or 0 for standard preference record)
270 30 byte preference data
272 Record type 6 (sigrec)
274 Used to keep track of key signatures. Self-signatures are not
275 stored. If a public key is not in the DB, the signature points to
276 a shadow dir record, which in turn has a list of records which
277 might be interested in this key (and the signature record here
282 1 u32 LID points back to the dir record
283 1 u32 next next sigrec of this uid or 0 to indicate the
286 1 u32 Local_id of signators dir or shadow dir record
287 1 byte Flag: Bit 0 = checked: Bit 1 is valid (we have a real
288 directory record for this)
289 1 = valid is set (but my be revoked)
293 Record type 8: (shadow directory record)
295 This record is used to reserved a LID for a public key. We
296 need this to create the sig records of other keys, even if we
297 do not yet have the public key of the signature.
298 This record (the record number to be more precise) will be reused
299 as the dir record when we import the real public key.
303 1 u32 LID (This is simply the record number of this record.)
305 1 byte pubkey algorithm
307 1 u32 hintlist A list of records which have references to
308 this key. This is used for fast access to
309 signature records which are not yet checked.
310 Note, that this is only a hint and the actual records
311 may not anymore hold signature records for that key
312 but that the code cares about this.
317 Record Type 10 (hash table)
319 Due to the fact that we use fingerprints to lookup keys, we can
320 implement quick access by some simple hash methods, and avoid
321 the overhead of gdbm. A property of fingerprints is that they can be
322 used directly as hash values. (They can be considered as strong
324 What we use is a dynamic multilevel architecture, which combines
325 hashtables, record lists, and linked lists.
327 This record is a hashtable of 256 entries; a special property
328 is that all these records are stored consecutively to make one
329 big table. The hash value is simple the 1st, 2nd, ... byte of
330 the fingerprint (depending on the indirection level).
332 When used to hash shadow directory records, a different table is used
333 and indexed by the keyid.
337 n u32 recnum; n depends on the record length:
338 n = (reclen-2)/4 which yields 9 for the current record length
341 the total number of such record which makes up the table is:
343 which is 29 for a record length of 40.
345 To look up a key we use the first byte of the fingerprint to get
346 the recnum from this hashtable and look up the addressed record:
347 - If this record is another hashtable, we use 2nd byte
348 to index this hash table and so on.
349 - if this record is a hashlist, we walk all entries
350 until we found one a matching one.
351 - if this record is a key record, we compare the
352 fingerprint and to decide whether it is the requested key;
355 Record type 11 (hash list)
357 see hash table for an explanation.
358 This is also used for other purposes.
362 1 u32 next next hash list record
363 n times n = (reclen-5)/5
366 For the current record length of 40, n is 7
370 Record type 254 (free record)
372 All these records form a linked list of unused records.
382 GNUPG uses PGP 2 packet headers and also understands OpenPGP packet header.
383 There is one enhancement used with the old style packet headers:
385 CTB bits 10, the "packet-length length bits", have values listed in
388 00 - 1-byte packet-length field
389 01 - 2-byte packet-length field
390 10 - 4-byte packet-length field
391 11 - no packet length supplied, unknown packet length
393 As indicated in this table, depending on the packet-length length
394 bits, the remaining 1, 2, 4, or 0 bytes of the packet structure field
395 are a "packet-length field". The packet-length field is a whole
396 number field. The value of the packet-length field is defined to be
397 the value of the whole number field.
399 A value of 11 is currently used in one place: on compressed data.
400 That is, a compressed data block currently looks like <A3 01 . . .>,
401 where <A3>, binary 10 1000 11, is an indefinite-length packet. The
402 proper interpretation is "until the end of the enclosing structure",
403 although it should never appear outermost (where the enclosing
404 structure is a file).
406 + This will be changed with another version, where the new meaning of
407 + the value 11 (see below) will also take place.
409 + A value of 11 for other packets enables a special length encoding,
410 + which is used in case, where the length of the following packet can
411 + not be determined prior to writing the packet; especially this will
412 + be used if large amounts of data are processed in filter mode.
414 + It works like this: After the CTB (with a length field of 11) a
415 + marker field is used, which gives the length of the following datablock.
416 + This is a simple 2 byte field (MSB first) containing the amount of data
417 + following this field, not including this length field. After this datablock
418 + another length field follows, which gives the size of the next datablock.
419 + A value of 0 indicates the end of the packet. The maximum size of a
420 + data block is limited to 65534, thereby reserving a value of 0xffff for
421 + future extensions. These length markers must be inserted into the data
422 + stream just before writing the data out.
424 + This 2 byte filed is large enough, because the application must buffer
425 + this amount of data to prepend the length marker before writing it out.
426 + Data block sizes larger than about 32k doesn't make any sense. Note
427 + that this may also be used for compressed data streams, but we must use
428 + another packet version to tell the application that it can not assume,
429 + that this is the last packet.
432 Usage of gdbm files for keyrings
433 ================================
434 The key to store the keyblock is it's fingerprint, other records
435 are used for secondary keys. fingerprints are always 20 bytes
436 where 16 bit fingerprints are appended with zero.
437 The first byte of the key gives some information on the type of the
439 1 = key is a 20 bit fingerprint (16 bytes fpr are padded with zeroes)
441 2 = key is the complete 8 byte keyid
442 data is a list of 20 byte fingerprints
443 3 = key is the short 4 byte keyid
444 data is a list of 20 byte fingerprints
445 4 = key is the email address
446 data is a list of 20 byte fingerprints
448 Data is prepended with a type byte:
450 2 = list of 20 byte padded fingerprints
451 3 = list of list fingerprints (but how to we key them?)
458 * For packet version 3 we calculate the keyids this way:
459 RSA := low 64 bits of n
460 ELGAMAL := build a v3 pubkey packet (with CTB 0x99) and calculate
461 a rmd160 hash value from it. This is used as the
462 fingerprint and the low 64 bits are the keyid.
464 * Revocation certificates consist only of the signature packet;
465 "import" knows how to handle this. The rationale behind it is
474 Keyserver Message Format
475 =========================
477 The keyserver may be contacted by a Unix Domain socket or via TCP.
479 The format of a request is:
483 "Content-length:" digits
495 The format of a response is:
498 "GNUPG/1.0" status-code status-text
499 "Content-length:" digits
502 followed by <digits> bytes of data
507 o 1xx: Informational - Request received, continuing process
509 o 2xx: Success - The action was successfully received, understood,
512 o 4xx: Client Error - The request contains bad syntax or cannot be
515 o 5xx: Server Error - The server failed to fulfill an apparently
520 Ich werde jetzt doch das HKP Protokoll implementieren:
522 Naja, die Doku ist so gut wie nichtexistent, da gebe ich Dir recht.
525 (Minimal-)HTTP-Server auf Port 11371, versteht ein GET auf /pks/lookup,
526 wobei die Query-Parameter (Key-Value-Paare mit = zwischen Key und
527 Value; die Paare sind hinter ? und durch & getrennt). Gültige
530 - - op (Operation) mit den Möglichkeiten index (gleich wie -kv bei
531 PGP), vindex (-kvv) und get (-kxa)
532 - - search: Liste der Worte, die im Key vorkommen müssen. Worte sind
533 mit Worttrennzeichen wie Space, Punkt, @, ... getrennt, Worttrennzeichen
534 werden nicht betrachtet, die Reihenfolge der Worte ist egal.
535 - - exact: (on=aktiv, alles andere inaktiv) Nur die Schlüssel
536 zurückgeben, die auch den "search"-String beinhalten (d.h.
537 Wortreihenfolge und Sonderzeichen sind wichtig)
538 - - fingerprint (Bei [v]index auch den Fingerprint ausgeben), "on"
539 für aktiv, alles andere inaktiv
541 Neu (wird von GNUPG benutzt):
542 /pks/lookup/<gnupg_formatierte_user_id>?op=<operation>
544 Zusätzlich versteht der Keyserver auch ein POST auf /pks/add, womit
545 man Keys hochladen kann.