] An operation on a smartcard definitely failed. Currently there is no indication of the actual error code, but application should be prepared to later accept more arguments. Defined values for are: - 0 :: unspecified error (identically to a missing CODE) - 1 :: canceled - 2 :: bad PIN *** SC_OP_SUCCESS A smart card operaion succeeded. This status is only printed for certain operation and is mostly useful to check whether a PIN change really worked. ** Miscellaneous status codes *** NODATA No data has been found. Codes for WHAT are: - 1 :: No armored data. - 2 :: Expected a packet but did not found one. - 3 :: Invalid packet found, this may indicate a non OpenPGP message. - 4 :: Signature expected but not found You may see more than one of these status lines. *** UNEXPECTED Unexpected data has been encountered. Codes for WHAT are: - 0 :: Not further specified - 1 :: Corrupted message structure *** TRUNCATED The output was truncated to MAXNO items. This status code is issued for certain external requests. *** ERROR [] This is a generic error status message, it might be followed by error location specific data. and should not contain spaces. The error code is a either a string commencing with a letter or such a string prefixed with a numerical error code and an underscore; e.g.: "151011327_EOF". *** WARNING [] This is a generic warning status message, it might be followed by error location specific data. and may not contain spaces. The may be used to indicate a class of warnings. The error code is a either a string commencing with a letter or such a string prefixed with a numerical error code and an underscore; e.g.: "151011327_EOF". *** NOTE [] This is a generic info status message the same syntax as for WARNING messages is used. *** SUCCESS [] Positive confirmation that an operation succeeded. It is used similar to ISO-C's EXIT_SUCCESS. is optional but if given should not contain spaces. Used only with a few commands. *** FAILURE This is the counterpart to SUCCESS and used to indicate a program failure. It is used similar to ISO-C's EXIT_FAILURE but allows conveying more information, in particular a gpg-error error code. That numerical error code may optionally have a suffix made of an underscore and a string with an error symbol like "151011327_EOF". A dash may be used instead of . *** BADARMOR The ASCII armor is corrupted. No arguments yet. *** DELETE_PROBLEM Deleting a key failed. Reason codes are: - 1 :: No such key - 2 :: Must delete secret key first - 3 :: Ambigious specification - 4 :: Key is stored on a smartcard. *** PROGRESS [] Used by the primegen and public key functions to indicate progress. is the character displayed with no --status-fd enabled, with the linefeed replaced by an 'X'. is the current amount done and is amount to be done; a of 0 indicates that the total amount is not known. Both are non-negative integers. The condition : TOTAL && CUR == TOTAL may be used to detect the end of an operation. Well known values for are: - pk_dsa :: DSA key generation - pk_elg :: Elgamal key generation - primegen :: Prime generation - need_entropy :: Waiting for new entropy in the RNG - tick :: Generic tick without any special meaning - useful for letting clients know that the server is still working. - starting_agent :: A gpg-agent was started because it is not running as a daemon. - learncard :: Send by the agent and gpgsm while learing the data of a smartcard. - card_busy :: A smartcard is still working When refers to a file path, it may be truncated. is sometimes used to describe the units for and . For example "B", "KiB", or "MiB". *** BACKUP_KEY_CREATED A backup of a key identified by has been writte to the file ; is percent-escaped. *** MOUNTPOINT is a percent-plus escaped filename describing the mountpoint for the current operation (e.g. used by "g13 --mount"). This may either be the specified mountpoint or one randomly chosen by g13. *** PINENTRY_LAUNCHED [:] This status line is emitted by gpg to notify a client that a Pinentry has been launched. is the PID of the Pinentry. It may be used to display a hint to the user but can't be used to synchronize with Pinentry. Note that there is also an Assuan inquiry line with the same name used internally or, if enabled, send to the client instead of this status line. Such an inquiry may be used to sync with Pinentry ** Obsolete status codes *** SIGEXPIRED Removed on 2011-02-04. This is deprecated in favor of KEYEXPIRED. *** RSA_OR_IDEA Obsolete. This status message used to be emitted for requests to use the IDEA or RSA algorithms. It has been dropped from GnuPG 2.1 after the respective patents expired. *** SHM_INFO, SHM_GET, SHM_GET_BOOL, SHM_GET_HIDDEN These were used for the ancient shared memory based co-processing. *** BEGIN_STREAM, END_STREAM Used to issued by the experimental pipemode. * Format of the --attribute-fd output When --attribute-fd is set, during key listings (--list-keys, --list-secret-keys) GnuPG dumps each attribute packet to the file descriptor specified. --attribute-fd is intended for use with --status-fd as part of the required information is carried on the ATTRIBUTE status tag (see above). The contents of the attribute data is specified by RFC 4880. For convenience, here is the Photo ID format, as it is currently the only attribute defined: - Byte 0-1 :: The length of the image header. Due to a historical accident (i.e. oops!) back in the NAI PGP days, this is a little-endian number. Currently 16 (0x10 0x00). - Byte 2 :: The image header version. Currently 0x01. - Byte 3 :: Encoding format. 0x01 == JPEG. - Byte 4-15 :: Reserved, and currently unused. All other data after this header is raw image (JPEG) data. * Layout of the TrustDB The TrustDB is built from fixed length records, where the first byte describes the record type. All numeric values are stored in network byte order. The length of each record is 40 bytes. The first record of the DB is always of type 1 and this is the only record of this type. The record types: directory(2), key(3), uid(4), pref(5), sigrec(6), and shadow directory(8) are not anymore used by version 2 of the TrustDB. ** Record type 0 Unused record or deleted, can be reused for any purpose. Such records should in general not exist because deleted records are of type 254 and kept in a linked list. ** Version info (RECTYPE_VER, 1) Version information for this TrustDB. This is always the first record of the DB and the only one of this type. - 1 u8 :: Record type (value: 1). - 3 byte :: Magic value ("gpg") - 1 u8 :: TrustDB version (value: 2). - 1 u8 :: =marginals=. How many marginal trusted keys are required. - 1 u8 :: =completes=. How many completely trusted keys are required. - 1 u8 :: =max_cert_depth=. How deep is the WoT evaluated. Along with =marginals= and =completes=, this value is used to check whether the cached validity value from a [FIXME dir] record can be used. - 1 u8 :: =trust_model= - 1 u8 :: =min_cert_level= - 2 byte :: Not used - 1 u32 :: =created=. Timestamp of trustdb creation. - 1 u32 :: =nextcheck=. Timestamp of last modification which may affect the validity of keys in the trustdb. This value is checked against the validity timestamp in the dir records. - 1 u32 :: =reserved=. Not used. - 1 u32 :: =reserved2=. Not used. - 1 u32 :: =firstfree=. Number of the record with the head record of the RECTYPE_FREE linked list. - 1 u32 :: =reserved3=. Not used. - 1 u32 :: =trusthashtbl=. Record number of the trusthashtable. ** Hash table (RECTYPE_HTBL, 10) Due to the fact that we use fingerprints to lookup keys, we can implement quick access by some simple hash methods, and avoid the overhead of gdbm. A property of fingerprints is that they can be used directly as hash values. What we use is a dynamic multilevel architecture, which combines hash tables, record lists, and linked lists. This record is a hash table of 256 entries with the property that all these records are stored consecutively to make one big table. The hash value is simple the 1st, 2nd, ... byte of the fingerprint (depending on the indirection level). - 1 u8 :: Record type (value: 10). - 1 u8 :: Reserved - n u32 :: =recnum=. A table with the hash table items fitting into this record. =n= depends on the record length: $n=(reclen-2)/4$ which yields 9 for oure current record length of 40 bytes. The total number of hash table records to form the table is: $m=(256+n-1)/n$. This is 29 for our record length of 40. To look up a key we use the first byte of the fingerprint to get the recnum from this hash table and then look up the addressed record: - If that record is another hash table, we use 2nd byte to index that hash table and so on; - if that record is a hash list, we walk all entries until we find a matching one; or - if that record is a key record, we compare the fingerprint to decide whether it is the requested key; ** Hash list (RECTYPE_HLST, 11) See hash table above on how it is used. It may also be used for other purposes. - 1 u8 :: Record type (value: 11). - 1 u8 :: Reserved. - 1 u32 :: =next=. Record number of the next hash list record or 0 if none. - n u32 :: =rnum=. Array with record numbers to values. With $n=(reclen-5)/5$ and our record length of 40, n is 7. ** Trust record (RECTYPE_TRUST, 12) - 1 u8 :: Record type (value: 12). - 1 u8 :: Reserved. - 20 byte :: =fingerprint=. - 1 u8 :: =ownertrust=. - 1 u8 :: =depth=. - 1 u8 :: =min_ownertrust=. - 1 byte :: Not used. - 1 u32 :: =validlist=. - 10 byte :: Not used. ** Validity record (RECTYPE_VALID, 13) - 1 u8 :: Record type (value: 13). - 1 u8 :: Reserved. - 20 byte :: =namehash=. - 1 u8 :: =validity= - 1 u32 :: =next=. - 1 u8 :: =full_count=. - 1 u8 :: =marginal_count=. - 11 byte :: Not used. ** Free record (RECTYPE_FREE, 254) All these records form a linked list of unused records in the TrustDB. - 1 u8 :: Record type (value: 254) - 1 u8 :: Reserved. - 1 u32 :: =next=. Record number of the next rcord of this type. The record number to the head of this linked list is stored in the version info record. * Database scheme for the TOFU info #+begin_src sql -- -- The VERSION table holds the version of our TOFU data structures. -- CREATE TABLE version ( version integer -- As of now this is always 1 ); -- -- The BINDINGS table associates mail addresses with keys. -- CREATE TABLE bindings ( oid integer primary key autoincrement, fingerprint text, -- The key's fingerprint in hex email text, -- The normalized mail address destilled from user_id user_id text, -- The unmodified user id time integer, -- The time this binding was first observed. policy boolean check (policy in (1, 2, 3, 4, 5)), -- The trust policy with the values: -- 1 := Auto -- 2 := Good -- 3 := Unknown -- 4 := Bad -- 5 := Ask conflict string, -- NULL or a hex formatted fingerprint. unique (fingerprint, email) ); CREATE INDEX bindings_fingerprint_email on bindings (fingerprint, email); CREATE INDEX bindings_email on bindings (email); -- -- The SIGNATURES table records all data signatures we verified -- CREATE TABLE signatures ( binding integer not null, -- Link to bindings table, -- references bindings.oid. sig_digest text, -- The digest of the signed message. origin text, -- String describing who initially fed -- the signature to gpg (e.g. "email:claws"). sig_time integer, -- Timestamp from the signature. time integer, -- Time this record was created. primary key (binding, sig_digest, origin) ); #+end_src * GNU extensions to the S2K algorithm 1 octet - S2K Usage: either 254 or 255. 1 octet - S2K Cipher Algo: 0 1 octet - S2K Specifier: 101 3 octets - "GNU" 1 octet - GNU S2K Extension Number. If such a GNU extension is used neither an IV nor any kind of checksum is used. The defined GNU S2K Extension Numbers are: - 1 :: Do not store the secret part at all. No specific data follows. - 2 :: A stub to access smartcards. This data follows: - One octet with the length of the following serial number. - The serial number. Regardless of what the length octet indicates no more than 16 octets are stored. Note that gpg stores the GNU S2K Extension Number internally as an S2K Specifier with an offset of 1000. * Format of the OpenPGP TRUST packet According to RFC4880 (5.10), the trust packet (aka ring trust) is only used within keyrings and contains data that records the user's specifications of which key holds trusted introducers. The RFC also states that the format of this packet is implementation defined and SHOULD NOT be emitted to output streams or should be ignored on import. GnuPG uses this packet in several additional ways: - 1 octet :: Trust-Value (only used by Subtype SIG) - 1 octet :: Signature-Cache (only used by Subtype SIG; value must be less than 128) - 3 octets :: Fixed value: "gpg" - 1 octet :: Subtype - 0 :: Signature cache (SIG) - 1 :: Key source on the primary key (KEY) - 2 :: Key source on a user id (UID) - 1 octet :: Key Source; i.e. the origin of the key: - 0 :: Unknown source. - 1 :: Public keyserver. - 2 :: Preferred keyserver. - 3 :: OpenPGP DANE. - 4 :: Web Key Directory. - 5 :: Import from a trusted URL. - 6 :: Import from a trusted file. - 7 :: Self generated. - 4 octets :: Time of last update. This is a a four-octet scalar with the seconds since Epoch. - 1 octet :: Scalar with the length of the following field. - N octets :: String with the URL of the source. This may be a zero-length string. If the packets contains only two octets a Subtype of 0 is assumed; this is the only format recognized by GnuPG versions < 2.1.18. Trust-Value and Signature-Cache must be zero for all subtypes other than SIG. * Keyserver helper message format *This information is obsolete* (Keyserver helpers have been replaced by dirmngr) The keyserver may be contacted by a Unix Domain socket or via TCP. The format of a request is: #+begin_example command-tag "Content-length:" digits CRLF #+end_example Where command-tag is #+begin_example NOOP GET PUT DELETE #+end_example The format of a response is: #+begin_example "GNUPG/1.0" status-code status-text "Content-length:" digits CRLF #+end_example followed by bytes of data Status codes are: - 1xx :: Informational - Request received, continuing process - 2xx :: Success - The action was successfully received, understood, and accepted - 4xx :: Client Error - The request contains bad syntax or cannot be fulfilled - 5xx :: Server Error - The server failed to fulfill an apparently valid request * Object identifiers OIDs below the GnuPG arc: #+begin_example 1.3.6.1.4.1.11591.2 GnuPG 1.3.6.1.4.1.11591.2.1 notation 1.3.6.1.4.1.11591.2.1.1 pkaAddress 1.3.6.1.4.1.11591.2.2 X.509 extensions 1.3.6.1.4.1.11591.2.2.1 standaloneCertificate 1.3.6.1.4.1.11591.2.2.2 wellKnownPrivateKey 1.3.6.1.4.1.11591.2.12242973 invalid encoded OID #+end_example * Debug flags This tables gives the flag values for the --debug option along with the alternative names used by the components. | | gpg | gpgsm | agent | scd | dirmngr | g13 | wks | |-------+---------+---------+---------+---------+---------+---------+---------| | 1 | packet | x509 | | | x509 | mount | mime | | 2 | mpi | mpi | mpi | mpi | | | parser | | 4 | crypto | crypto | crypto | crypto | crypto | crypto | crypto | | 8 | filter | | | | | | | | 16 | iobuf | | | | dns | | | | 32 | memory | memory | memory | memory | memory | memory | memory | | 64 | cache | cache | cache | cache | cache | | | | 128 | memstat | memstat | memstat | memstat | memstat | memstat | memstat | | 256 | trust | | | | | | | | 512 | hashing | hashing | hashing | hashing | hashing | | | | 1024 | ipc | ipc | ipc | ipc | ipc | ipc | ipc | | 2048 | | | | cardio | network | | | | 4096 | clock | | | reader | | | | | 8192 | lookup | | | | lookup | | | | 16384 | extprog | | | | | | extprog | Description of some debug flags: - cardio :: Used by scdaemon to trace the APDUs exchange with the card. - clock :: Show execution times of certain functions. - crypto :: Trace crypto operations. - hashing :: Create files with the hashed data. - ipc :: Trace the Assuan commands. - mpi :: Show the values of the MPIs. - reader :: Used by scdaemon to trace card reader related code. For example: Open and close reader. * Miscellaneous notes ** v3 fingerprints For packet version 3 we calculate the keyids this way: - RSA :: Low 64 bits of n - ELGAMAL :: Build a v3 pubkey packet (with CTB 0x99) and calculate a RMD160 hash value from it. This is used as the fingerprint and the low 64 bits are the keyid. ** Simplified revocation certificates Revocation certificates consist only of the signature packet; "--import" knows how to handle this. The rationale behind it is to keep them small. ** Documentation on HKP (the http keyserver protocol): A minimalistic HTTP server on port 11371 recognizes a GET for /pks/lookup. The standard http URL encoded query parameters are this (always key=value): - op=index (like pgp -kv), op=vindex (like pgp -kvv) and op=get (like pgp -kxa) - search=. This is a list of words that must occur in the key. The words are delimited with space, points, @ and so on. The delimiters are not searched for and the order of the words doesn't matter (but see next option). - exact=on. This switch tells the hkp server to only report exact matching keys back. In this case the order and the "delimiters" are important. - fingerprint=on. Also reports the fingerprints when used with 'index' or 'vindex' The keyserver also recognizes http-POSTs to /pks/add. Use this to upload keys. A better way to do this would be a request like: /pks/lookup/?op= This can be implemented using Hurd's translator mechanism. However, I think the whole keyserver stuff has to be re-thought; I have some ideas and probably create a white paper. ** Algorithm names for the "keygen.algo" prompt When using a --command-fd controlled key generation or "addkey" there is way to know the number to enter on the "keygen.algo" prompt. The displayed numbers are for human reception and may change with releases. To provide a stable way to enter a desired algorithm choice the prompt also accepts predefined names for the algorithms, which will not change. | Name | No | Description | |---------+----+---------------------------------| | rsa+rsa | 1 | RSA and RSA (default) | | dsa+elg | 2 | DSA and Elgamal | | dsa | 3 | DSA (sign only) | | rsa/s | 4 | RSA (sign only) | | elg | 5 | Elgamal (encrypt only) | | rsa/e | 6 | RSA (encrypt only) | | dsa/* | 7 | DSA (set your own capabilities) | | rsa/* | 8 | RSA (set your own capabilities) | | ecc+ecc | 9 | ECC and ECC | | ecc/s | 10 | ECC (sign only) | | ecc/* | 11 | ECC (set your own capabilities) | | ecc/e | 12 | ECC (encrypt only) | | keygrip | 13 | Existing key | | cardkey | 14 | Existing key from card | If one of the "foo/*" names are used a "keygen.flags" prompt needs to be answered as well. Instead of toggling the predefined flags, it is also possible to set them direct: Use a "=" character directly followed by a combination of "a" (for authentication), "s" (for signing), or "c" (for certification).
are: - 0 :: unspecified error (identically to a missing CODE) - 1 :: canceled - 2 :: bad PIN *** SC_OP_SUCCESS A smart card operaion succeeded. This status is only printed for certain operation and is mostly useful to check whether a PIN change really worked. ** Miscellaneous status codes *** NODATA No data has been found. Codes for WHAT are: - 1 :: No armored data. - 2 :: Expected a packet but did not found one. - 3 :: Invalid packet found, this may indicate a non OpenPGP message. - 4 :: Signature expected but not found You may see more than one of these status lines. *** UNEXPECTED Unexpected data has been encountered. Codes for WHAT are: - 0 :: Not further specified - 1 :: Corrupted message structure *** TRUNCATED The output was truncated to MAXNO items. This status code is issued for certain external requests. *** ERROR [] This is a generic error status message, it might be followed by error location specific data. and should not contain spaces. The error code is a either a string commencing with a letter or such a string prefixed with a numerical error code and an underscore; e.g.: "151011327_EOF". *** WARNING [] This is a generic warning status message, it might be followed by error location specific data. and may not contain spaces. The may be used to indicate a class of warnings. The error code is a either a string commencing with a letter or such a string prefixed with a numerical error code and an underscore; e.g.: "151011327_EOF". *** NOTE [] This is a generic info status message the same syntax as for WARNING messages is used. *** SUCCESS [] Positive confirmation that an operation succeeded. It is used similar to ISO-C's EXIT_SUCCESS. is optional but if given should not contain spaces. Used only with a few commands. *** FAILURE This is the counterpart to SUCCESS and used to indicate a program failure. It is used similar to ISO-C's EXIT_FAILURE but allows conveying more information, in particular a gpg-error error code. That numerical error code may optionally have a suffix made of an underscore and a string with an error symbol like "151011327_EOF". A dash may be used instead of . *** BADARMOR The ASCII armor is corrupted. No arguments yet. *** DELETE_PROBLEM Deleting a key failed. Reason codes are: - 1 :: No such key - 2 :: Must delete secret key first - 3 :: Ambigious specification - 4 :: Key is stored on a smartcard. *** PROGRESS [] Used by the primegen and public key functions to indicate progress. is the character displayed with no --status-fd enabled, with the linefeed replaced by an 'X'. is the current amount done and is amount to be done; a of 0 indicates that the total amount is not known. Both are non-negative integers. The condition : TOTAL && CUR == TOTAL may be used to detect the end of an operation. Well known values for are: - pk_dsa :: DSA key generation - pk_elg :: Elgamal key generation - primegen :: Prime generation - need_entropy :: Waiting for new entropy in the RNG - tick :: Generic tick without any special meaning - useful for letting clients know that the server is still working. - starting_agent :: A gpg-agent was started because it is not running as a daemon. - learncard :: Send by the agent and gpgsm while learing the data of a smartcard. - card_busy :: A smartcard is still working When refers to a file path, it may be truncated. is sometimes used to describe the units for and . For example "B", "KiB", or "MiB". *** BACKUP_KEY_CREATED A backup of a key identified by has been writte to the file ; is percent-escaped. *** MOUNTPOINT is a percent-plus escaped filename describing the mountpoint for the current operation (e.g. used by "g13 --mount"). This may either be the specified mountpoint or one randomly chosen by g13. *** PINENTRY_LAUNCHED [:] This status line is emitted by gpg to notify a client that a Pinentry has been launched. is the PID of the Pinentry. It may be used to display a hint to the user but can't be used to synchronize with Pinentry. Note that there is also an Assuan inquiry line with the same name used internally or, if enabled, send to the client instead of this status line. Such an inquiry may be used to sync with Pinentry ** Obsolete status codes *** SIGEXPIRED Removed on 2011-02-04. This is deprecated in favor of KEYEXPIRED. *** RSA_OR_IDEA Obsolete. This status message used to be emitted for requests to use the IDEA or RSA algorithms. It has been dropped from GnuPG 2.1 after the respective patents expired. *** SHM_INFO, SHM_GET, SHM_GET_BOOL, SHM_GET_HIDDEN These were used for the ancient shared memory based co-processing. *** BEGIN_STREAM, END_STREAM Used to issued by the experimental pipemode. * Format of the --attribute-fd output When --attribute-fd is set, during key listings (--list-keys, --list-secret-keys) GnuPG dumps each attribute packet to the file descriptor specified. --attribute-fd is intended for use with --status-fd as part of the required information is carried on the ATTRIBUTE status tag (see above). The contents of the attribute data is specified by RFC 4880. For convenience, here is the Photo ID format, as it is currently the only attribute defined: - Byte 0-1 :: The length of the image header. Due to a historical accident (i.e. oops!) back in the NAI PGP days, this is a little-endian number. Currently 16 (0x10 0x00). - Byte 2 :: The image header version. Currently 0x01. - Byte 3 :: Encoding format. 0x01 == JPEG. - Byte 4-15 :: Reserved, and currently unused. All other data after this header is raw image (JPEG) data. * Layout of the TrustDB The TrustDB is built from fixed length records, where the first byte describes the record type. All numeric values are stored in network byte order. The length of each record is 40 bytes. The first record of the DB is always of type 1 and this is the only record of this type. The record types: directory(2), key(3), uid(4), pref(5), sigrec(6), and shadow directory(8) are not anymore used by version 2 of the TrustDB. ** Record type 0 Unused record or deleted, can be reused for any purpose. Such records should in general not exist because deleted records are of type 254 and kept in a linked list. ** Version info (RECTYPE_VER, 1) Version information for this TrustDB. This is always the first record of the DB and the only one of this type. - 1 u8 :: Record type (value: 1). - 3 byte :: Magic value ("gpg") - 1 u8 :: TrustDB version (value: 2). - 1 u8 :: =marginals=. How many marginal trusted keys are required. - 1 u8 :: =completes=. How many completely trusted keys are required. - 1 u8 :: =max_cert_depth=. How deep is the WoT evaluated. Along with =marginals= and =completes=, this value is used to check whether the cached validity value from a [FIXME dir] record can be used. - 1 u8 :: =trust_model= - 1 u8 :: =min_cert_level= - 2 byte :: Not used - 1 u32 :: =created=. Timestamp of trustdb creation. - 1 u32 :: =nextcheck=. Timestamp of last modification which may affect the validity of keys in the trustdb. This value is checked against the validity timestamp in the dir records. - 1 u32 :: =reserved=. Not used. - 1 u32 :: =reserved2=. Not used. - 1 u32 :: =firstfree=. Number of the record with the head record of the RECTYPE_FREE linked list. - 1 u32 :: =reserved3=. Not used. - 1 u32 :: =trusthashtbl=. Record number of the trusthashtable. ** Hash table (RECTYPE_HTBL, 10) Due to the fact that we use fingerprints to lookup keys, we can implement quick access by some simple hash methods, and avoid the overhead of gdbm. A property of fingerprints is that they can be used directly as hash values. What we use is a dynamic multilevel architecture, which combines hash tables, record lists, and linked lists. This record is a hash table of 256 entries with the property that all these records are stored consecutively to make one big table. The hash value is simple the 1st, 2nd, ... byte of the fingerprint (depending on the indirection level). - 1 u8 :: Record type (value: 10). - 1 u8 :: Reserved - n u32 :: =recnum=. A table with the hash table items fitting into this record. =n= depends on the record length: $n=(reclen-2)/4$ which yields 9 for oure current record length of 40 bytes. The total number of hash table records to form the table is: $m=(256+n-1)/n$. This is 29 for our record length of 40. To look up a key we use the first byte of the fingerprint to get the recnum from this hash table and then look up the addressed record: - If that record is another hash table, we use 2nd byte to index that hash table and so on; - if that record is a hash list, we walk all entries until we find a matching one; or - if that record is a key record, we compare the fingerprint to decide whether it is the requested key; ** Hash list (RECTYPE_HLST, 11) See hash table above on how it is used. It may also be used for other purposes. - 1 u8 :: Record type (value: 11). - 1 u8 :: Reserved. - 1 u32 :: =next=. Record number of the next hash list record or 0 if none. - n u32 :: =rnum=. Array with record numbers to values. With $n=(reclen-5)/5$ and our record length of 40, n is 7. ** Trust record (RECTYPE_TRUST, 12) - 1 u8 :: Record type (value: 12). - 1 u8 :: Reserved. - 20 byte :: =fingerprint=. - 1 u8 :: =ownertrust=. - 1 u8 :: =depth=. - 1 u8 :: =min_ownertrust=. - 1 byte :: Not used. - 1 u32 :: =validlist=. - 10 byte :: Not used. ** Validity record (RECTYPE_VALID, 13) - 1 u8 :: Record type (value: 13). - 1 u8 :: Reserved. - 20 byte :: =namehash=. - 1 u8 :: =validity= - 1 u32 :: =next=. - 1 u8 :: =full_count=. - 1 u8 :: =marginal_count=. - 11 byte :: Not used. ** Free record (RECTYPE_FREE, 254) All these records form a linked list of unused records in the TrustDB. - 1 u8 :: Record type (value: 254) - 1 u8 :: Reserved. - 1 u32 :: =next=. Record number of the next rcord of this type. The record number to the head of this linked list is stored in the version info record. * Database scheme for the TOFU info #+begin_src sql -- -- The VERSION table holds the version of our TOFU data structures. -- CREATE TABLE version ( version integer -- As of now this is always 1 ); -- -- The BINDINGS table associates mail addresses with keys. -- CREATE TABLE bindings ( oid integer primary key autoincrement, fingerprint text, -- The key's fingerprint in hex email text, -- The normalized mail address destilled from user_id user_id text, -- The unmodified user id time integer, -- The time this binding was first observed. policy boolean check (policy in (1, 2, 3, 4, 5)), -- The trust policy with the values: -- 1 := Auto -- 2 := Good -- 3 := Unknown -- 4 := Bad -- 5 := Ask conflict string, -- NULL or a hex formatted fingerprint. unique (fingerprint, email) ); CREATE INDEX bindings_fingerprint_email on bindings (fingerprint, email); CREATE INDEX bindings_email on bindings (email); -- -- The SIGNATURES table records all data signatures we verified -- CREATE TABLE signatures ( binding integer not null, -- Link to bindings table, -- references bindings.oid. sig_digest text, -- The digest of the signed message. origin text, -- String describing who initially fed -- the signature to gpg (e.g. "email:claws"). sig_time integer, -- Timestamp from the signature. time integer, -- Time this record was created. primary key (binding, sig_digest, origin) ); #+end_src * GNU extensions to the S2K algorithm 1 octet - S2K Usage: either 254 or 255. 1 octet - S2K Cipher Algo: 0 1 octet - S2K Specifier: 101 3 octets - "GNU" 1 octet - GNU S2K Extension Number. If such a GNU extension is used neither an IV nor any kind of checksum is used. The defined GNU S2K Extension Numbers are: - 1 :: Do not store the secret part at all. No specific data follows. - 2 :: A stub to access smartcards. This data follows: - One octet with the length of the following serial number. - The serial number. Regardless of what the length octet indicates no more than 16 octets are stored. Note that gpg stores the GNU S2K Extension Number internally as an S2K Specifier with an offset of 1000. * Format of the OpenPGP TRUST packet According to RFC4880 (5.10), the trust packet (aka ring trust) is only used within keyrings and contains data that records the user's specifications of which key holds trusted introducers. The RFC also states that the format of this packet is implementation defined and SHOULD NOT be emitted to output streams or should be ignored on import. GnuPG uses this packet in several additional ways: - 1 octet :: Trust-Value (only used by Subtype SIG) - 1 octet :: Signature-Cache (only used by Subtype SIG; value must be less than 128) - 3 octets :: Fixed value: "gpg" - 1 octet :: Subtype - 0 :: Signature cache (SIG) - 1 :: Key source on the primary key (KEY) - 2 :: Key source on a user id (UID) - 1 octet :: Key Source; i.e. the origin of the key: - 0 :: Unknown source. - 1 :: Public keyserver. - 2 :: Preferred keyserver. - 3 :: OpenPGP DANE. - 4 :: Web Key Directory. - 5 :: Import from a trusted URL. - 6 :: Import from a trusted file. - 7 :: Self generated. - 4 octets :: Time of last update. This is a a four-octet scalar with the seconds since Epoch. - 1 octet :: Scalar with the length of the following field. - N octets :: String with the URL of the source. This may be a zero-length string. If the packets contains only two octets a Subtype of 0 is assumed; this is the only format recognized by GnuPG versions < 2.1.18. Trust-Value and Signature-Cache must be zero for all subtypes other than SIG. * Keyserver helper message format *This information is obsolete* (Keyserver helpers have been replaced by dirmngr) The keyserver may be contacted by a Unix Domain socket or via TCP. The format of a request is: #+begin_example command-tag "Content-length:" digits CRLF #+end_example Where command-tag is #+begin_example NOOP GET PUT DELETE #+end_example The format of a response is: #+begin_example "GNUPG/1.0" status-code status-text "Content-length:" digits CRLF #+end_example followed by bytes of data Status codes are: - 1xx :: Informational - Request received, continuing process - 2xx :: Success - The action was successfully received, understood, and accepted - 4xx :: Client Error - The request contains bad syntax or cannot be fulfilled - 5xx :: Server Error - The server failed to fulfill an apparently valid request * Object identifiers OIDs below the GnuPG arc: #+begin_example 1.3.6.1.4.1.11591.2 GnuPG 1.3.6.1.4.1.11591.2.1 notation 1.3.6.1.4.1.11591.2.1.1 pkaAddress 1.3.6.1.4.1.11591.2.2 X.509 extensions 1.3.6.1.4.1.11591.2.2.1 standaloneCertificate 1.3.6.1.4.1.11591.2.2.2 wellKnownPrivateKey 1.3.6.1.4.1.11591.2.12242973 invalid encoded OID #+end_example * Debug flags This tables gives the flag values for the --debug option along with the alternative names used by the components. | | gpg | gpgsm | agent | scd | dirmngr | g13 | wks | |-------+---------+---------+---------+---------+---------+---------+---------| | 1 | packet | x509 | | | x509 | mount | mime | | 2 | mpi | mpi | mpi | mpi | | | parser | | 4 | crypto | crypto | crypto | crypto | crypto | crypto | crypto | | 8 | filter | | | | | | | | 16 | iobuf | | | | dns | | | | 32 | memory | memory | memory | memory | memory | memory | memory | | 64 | cache | cache | cache | cache | cache | | | | 128 | memstat | memstat | memstat | memstat | memstat | memstat | memstat | | 256 | trust | | | | | | | | 512 | hashing | hashing | hashing | hashing | hashing | | | | 1024 | ipc | ipc | ipc | ipc | ipc | ipc | ipc | | 2048 | | | | cardio | network | | | | 4096 | clock | | | reader | | | | | 8192 | lookup | | | | lookup | | | | 16384 | extprog | | | | | | extprog | Description of some debug flags: - cardio :: Used by scdaemon to trace the APDUs exchange with the card. - clock :: Show execution times of certain functions. - crypto :: Trace crypto operations. - hashing :: Create files with the hashed data. - ipc :: Trace the Assuan commands. - mpi :: Show the values of the MPIs. - reader :: Used by scdaemon to trace card reader related code. For example: Open and close reader. * Miscellaneous notes ** v3 fingerprints For packet version 3 we calculate the keyids this way: - RSA :: Low 64 bits of n - ELGAMAL :: Build a v3 pubkey packet (with CTB 0x99) and calculate a RMD160 hash value from it. This is used as the fingerprint and the low 64 bits are the keyid. ** Simplified revocation certificates Revocation certificates consist only of the signature packet; "--import" knows how to handle this. The rationale behind it is to keep them small. ** Documentation on HKP (the http keyserver protocol): A minimalistic HTTP server on port 11371 recognizes a GET for /pks/lookup. The standard http URL encoded query parameters are this (always key=value): - op=index (like pgp -kv), op=vindex (like pgp -kvv) and op=get (like pgp -kxa) - search=. This is a list of words that must occur in the key. The words are delimited with space, points, @ and so on. The delimiters are not searched for and the order of the words doesn't matter (but see next option). - exact=on. This switch tells the hkp server to only report exact matching keys back. In this case the order and the "delimiters" are important. - fingerprint=on. Also reports the fingerprints when used with 'index' or 'vindex' The keyserver also recognizes http-POSTs to /pks/add. Use this to upload keys. A better way to do this would be a request like: /pks/lookup/?op= This can be implemented using Hurd's translator mechanism. However, I think the whole keyserver stuff has to be re-thought; I have some ideas and probably create a white paper. ** Algorithm names for the "keygen.algo" prompt When using a --command-fd controlled key generation or "addkey" there is way to know the number to enter on the "keygen.algo" prompt. The displayed numbers are for human reception and may change with releases. To provide a stable way to enter a desired algorithm choice the prompt also accepts predefined names for the algorithms, which will not change. | Name | No | Description | |---------+----+---------------------------------| | rsa+rsa | 1 | RSA and RSA (default) | | dsa+elg | 2 | DSA and Elgamal | | dsa | 3 | DSA (sign only) | | rsa/s | 4 | RSA (sign only) | | elg | 5 | Elgamal (encrypt only) | | rsa/e | 6 | RSA (encrypt only) | | dsa/* | 7 | DSA (set your own capabilities) | | rsa/* | 8 | RSA (set your own capabilities) | | ecc+ecc | 9 | ECC and ECC | | ecc/s | 10 | ECC (sign only) | | ecc/* | 11 | ECC (set your own capabilities) | | ecc/e | 12 | ECC (encrypt only) | | keygrip | 13 | Existing key | | cardkey | 14 | Existing key from card | If one of the "foo/*" names are used a "keygen.flags" prompt needs to be answered as well. Instead of toggling the predefined flags, it is also possible to set them direct: Use a "=" character directly followed by a combination of "a" (for authentication), "s" (for signing), or "c" (for certification).