Helper Tools
************

GnuPG comes with a couple of smaller tools:

Read logs from a socket
=======================

Most of the main utilities are able to write there log files to a Unix Domain socket if configured that way.  watchgnupg is a simple listener for such a socket.  It ameliorates the output with a time stamp and makes sure that long lines are not interspersed with log output from other utilities.

watchgnupg is commonly invoked as

watchgnupg --force ~/.gnupg/S.log

This starts it on the current terminal for listening on the socket ~/.gnupg/S.log.

watchgnupg understands these options:

--force
     Delete an already existing socket file.

--verbose
     Enable extra informational output.

--version
     print version of the program and exit

--help
     Display a brief help page and exit

Create .gnupg home directories.
===============================

If GnuPG is installed on a system with existing user accounts, it is sometimes required to populate the GnuPG home directory with existing files.  Especially a trustlist.txt and a keybox with some initial certificates are often desired.  This scripts help to do this by copying all files from /etc/skel/.gnupg to the home directories of the accounts given on the command line.  It takes care not to overwrite existing GnuPG home directories.

addgnupghome is invoked by root as:

addgnupghome account1 account2 ... accountn

Modify .gnupg home directories.
===============================

The gpgconf is a utility to automatically and reasonable safely query and modify configuration files in the .gnupg home directory.  It is designed not to be invoked manually by the user, but automatically by graphical user interfaces (GUI). (Please note that currently no locking is done, so concurrent access should be avoided.  There are some precautions to avoid corruption with concurrent usage, but results may be inconsistent and some changes may get lost.  The stateless design makes it difficult to provide more guarantees.)

gpgconf provides access to the configuration of one or more components of the GnuPG system.  These components correspond more or less to the programs that exist in the GnuPG framework, like GnuPG, GPGSM, DirMngr, etc.  But this is not a strict one-to-one relationship.  Not all configuration options are available through gpgconf.  gpgconf provides a generic and abstract method to access the most important configuration options that can feasibly be controlled via such a mechanism.

gpgconf can be used to gather and change the options available in each component, and can also provide their default values.  gpgconf will give detailed type information that can be used to restrict the user's input without making an attempt to commit the changes.

gpgconf provides the backend of a configuration editor.  The configuration editor would usually be a graphical user interface program, that allows to display the current options, their default values, and allows the user to make changes to the options.  These changes can then be made active with gpgconf again.  Such a program that uses gpgconf in this way will be called GUI throughout this section.

Invoking gpgconf
----------------

One of the following commands must be given:

--list-components
     List all components.  This is the default command used if none is specified.

--list-options COMPONENT
     List all options of the component COMPONENT.

--change-options COMPONENT
     Change the options of the component COMPONENT.

The following options may be used:

-v
--verbose
     Outputs additional information while running.  Specifically, this extends numerical field values by human-readable descriptions.

-r
--runtime
     Only used together with --change-options.  If one of the modified options can be changed in a running daemon process, signal the running daemon to ask it to reparse its configuration file after changing.

     This means that the changes will take effect at run-time, as far as this is possible.  Otherwise, they will take effect at the next start of the respective backend programs.

Format conventions
------------------

Some lines in the output of gpgconf contain a list of colon-separated fields.  The following conventions apply:

  * The GUI program is required to strip off trailing newline and/or carriage return characters from the output.

  * gpgconf will never leave out fields.  If a certain version provides a certain field, this field will always be present in all gpgconf versions from that time on.

  * Future versions of gpgconf might append fields to the list. New fields will always be separated from the previously last field by a colon separator.  The GUI should be prepared to parse the last field it knows about up until a colon or end of line.

  * Not all fields are defined under all conditions.  You are required to ignore the content of undefined fields.

There are several standard types for the content of a field:

verbatim
     Some fields contain strings that are not escaped in any way.  Such fields are described to be used verbatim.  These fields will never contain a colon character (for obvious reasons).  No de-escaping or other formatting is required to use the field content.  This is for easy parsing of the output, when it is known that the content can never contain any special characters.

percent-escaped
     Some fields contain strings that are described to be percent-escaped.  Such strings need to be de-escaped before their content can be presented to the user.  A percent-escaped string is de-escaped by replacing all occurences of %XY by the byte that has the hexadecimal value XY.  X and Y are from the set 0-9a-f.

localised
     Some fields contain strings that are described to be localised. Such strings are translated to the active language and formatted in the active character set.

unsigned number
     Some fields contain an unsigned number.  This number will always fit into a 32-bit unsigned integer variable.  The number may be followed by a space, followed by a human readable description of that value (if the verbose option is used).  You should ignore everything in the field that follows the number.

signed number
     Some fields contain a signed number.  This number will always fit into a 32-bit signed integer variable.  The number may be followed by a space, followed by a human readable description of that value (if the verbose option is used).  You should ignore everything in the field that follows the number.

option
     Some fields contain an option argument.  The format of an option argument depends on the type of the option and on some flags:

     no argument
          The simplest case is that the option does not take an argument at all (TYPE 0).  Then the option argument is an unsigned number that specifies how often the option occurs.  If the list flag is not set, then the only valid number is 1.  Options that do not take an argument never have the default or optional arg flag set.

     number
          If the option takes a number argument (ALT-TYPE is 2 or 3), and it can only occur once (list flag is not set), then the option argument is either empty (only allowed if the argument is optional), or it is a number.  A number is a string that begins with an optional minus character, followed by one or more digits.  The number must fit into an integer variable (unsigned or signed, depending on ALT-TYPE).

     number list
          If the option takes a number argument and it can occur more than once, then the option argument is either empty, or it is a comma-separated list of numbers as described above.

     string
          If the option takes a string argument (ALT-TYPE is 1), and it can only occur once (list flag is not set) then the option argument is either empty (only allowed if the argument is optional), or it starts with a double quote character (") followed by a percent-escaped string that is the argument value.  Note that there is only a leading double quote character, no trailing one.  The double quote character is only needed to be able to differentiate between no value and the empty string as value.

     string list
          If the option takes a number argument and it can occur more than once, then the option argument is either empty, or it is a comma-separated list of string arguments as described above.

The active language and character set are currently determined from the locale environment of the gpgconf program.

Listing components
------------------

The command --list-components will list all components that can be configured with gpgconf.  Usually, one component will correspond to one GnuPG-related program and contain the options of that programs configuration file that can be modified using gpgconf.  However, this is not necessarily the case.  A component might also be a group of selected options from several programs, or contain entirely virtual options that have a special effect rather than changing exactly one option in one configuration file.

A component is a set of configuration options that semantically belong together.  Furthermore, several changes to a component can be made in an atomic way with a single operation.  The GUI could for example provide a menu with one entry for each component, or a window with one tabulator sheet per component.

The command argument --list-components lists all available components, one per line.  The format of each line is:

NAME:DESCRIPTION

name
     This field contains a name tag of the component.  The name tag is used to specify the component in all communication with gpgconf. The name tag is to be used verbatim.  It is thus not in any escaped format.

description
     The string in this field contains a human-readable description of the component.  It can be displayed to the user of the GUI for informational purposes.  It is percent-escaped and localized.

Example:

     $ gpgconf --list-components
     gpg:GPG for OpenPGP
     gpg-agent:GPG Agent
     scdaemon:Smartcard Daemon
     gpgsm:GPG for S/MIME
     dirmngr:Directory Manager

Listing options
---------------

Every component contains one or more options.  Options may be gathered into option groups to allow the GUI to give visual hints to the user about which options are related.

The command argument --list-options COMPONENT lists all options (and the groups they belong to) in the component COMPONENT, one per line.  COMPONENT must be the string in the field NAME in the output of the --list-components command.

There is one line for each option and each group.  First come all options that are not in any group.  Then comes a line describing a group.  Then come all options that belong into each group.  Then comes the next group and so on.  There does not need to be any group (and in this case the output will stop after the last non-grouped option).

The format of each line is:

NAME:FLAGS:LEVEL:DESCRIPTION:TYPE:ALT-TYPE:ARGNAME:DEFAULT:ARGDEF:VALUE

name
     This field contains a name tag for the group or option.  The name tag is used to specify the group or option in all communication with gpgconf.  The name tag is to be used verbatim.  It is thus not in any escaped format.

flags
     The flags field contains an unsigned number.  Its value is the OR-wise combination of the following flag values:

     group (1)
          If this flag is set, this is a line describing a group and not an option.

     The following flag values are only defined for options (that is, if the group flag is not used).

     optional arg (2)
          If this flag is set, the argument is optional.  This is never set for TYPE 0 (none) options.

     list (4)
          If this flag is set, the option can be given multiple times.

     runtime (8)
          If this flag is set, the option can be changed at runtime.

     default (16)
          If this flag is set, a default value is available.

     default desc (32)
          If this flag is set, a (runtime) default is available.  This and the default flag are mutually exclusive.

     no arg desc (64)
          If this flag is set, and the optional arg flag is set, then the option has a special meaning if no argument is given.

level
     This field is defined for options and for groups.  It contains an unsigned number that specifies the expert level under which this group or option should be displayed.  The following expert levels are defined for options (they have analogous meaning for groups):

     basic (0)
          This option should always be offered to the user.

     advanced (1)
          This option may be offered to advanced users.

     expert (2)
          This option should only be offered to expert users.

     invisible (3)
          This option should normally never be displayed, not even to expert users.

     internal (4)
          This option is for internal use only.  Ignore it.

     The level of a group will always be the lowest level of all options it contains.

description
     This field is defined for options and groups.  The string in this field contains a human-readable description of the option or group.  It can be displayed to the user of the GUI for informational purposes.  It is percent-escaped and localized.

type
     This field is only defined for options.  It contains an unsigned number that specifies the type of the option's argument, if any.  The following types are defined:

     Basic types:

     none (0)
          No argument allowed.

     string (1)
          An unformatted string.

     int32 (2)
          A signed number.

     uint32 (3)
          An unsigned number.

     Complex types:

     pathname (32)
          A string that describes the pathname of a file.  The file does not necessarily need to exist.

     ldap server (33)
          A string that describes an LDAP server in the format:

          HOSTNAME:PORT:USERNAME:PASSWORD:BASE_DN

     More types will be added in the future.  Please see the ALT-TYPE field for information on how to cope with unknown types.

alt-type
     This field is identical to TYPE, except that only the types 0 to 31 are allowed.  The GUI is expected to present the user the option in the format specified by TYPE.  But if the argument type TYPE is not supported by the GUI, it can still display the option in the more generic basic type ALT-TYPE.  The GUI must support all the defined basic types to be able to display all options.  More basic types may be added in future versions.  If the GUI encounters a basic type it doesn't support, it should report an error and abort the operation.

argname
     This field is only defined for options with an argument type TYPE that is not 0.  In this case it may contain a percent-escaped and localised string that gives a short name for the argument.  The field may also be empty, though, in which case a short name is not known.

default
     This field is defined only for options.  Its format is that of an option argument (see Format conventions, for details).  If the default value is empty, then no default is known.  Otherwise, the value specifies the default value for this option.  Note that this field is also meaningful if the option itself does not take a real argument.

argdef
     This field is defined only for options for which the optional arg flag is set.  If the no arg desc flag is not set, its format is that of an option argument (see Format conventions, for details).  If the default value is empty, then no default is known.  Otherwise, the value specifies the default value for this option.  If the no arg desc flag is set, the field is either empty or contains a description of the effect of this option if no argument is given.  Note that this field is also meaningful if the option itself does not take a real argument.

value
     This field is defined only for options.  Its format is that of an option argument.  If it is empty, then the option is not explicitely set in the current configuration, and the default applies (if any).  Otherwise, it contains the current value of the option. Note that this field is also meaningful if the option itself does not take a real argument.

Changing options
----------------

The command --change-options COMPONENT will attempt to change the options of the component COMPONENT to the specified values.  COMPONENT must be the string in the field NAME in the output of the --list-components command.  You have to provide the options that shall be changed in the following format on standard input:

NAME:FLAGS:NEW-VALUE

name
     This is the name of the option to change.  NAME must be the string in the field NAME in the output of the --list-options command.

flags
     The flags field contains an unsigned number.  Its value is the OR-wise combination of the following flag values:

     default (16)
          If this flag is set, the option is deleted and the default value is used instead (if applicable).

new-value
     The new value for the option.  This field is only defined if the default flag is not set.  The format is that of an option argument.  If it is empty (or the field is omitted), the default argument is used (only allowed if the argument is optional for this option).  Otherwise, the option will be set to the specified value.

Examples:

To set the force option, which is of basic type none (0):

     $ echo 'force:0:1' | gpgconf --change-options dirmngr

To delete the force option:

     $ echo 'force:16:' | gpgconf --change-options dirmngr

The --runtime option can influence when the changes take effect.

Generate an X.509 certificate request
=====================================

This is a simple tool to interactivly generate a certificate request whicl will be printed to stdout.

gpgsm-gencert.sh is invoked as:

gpgsm-cencert.sh

Put a passphrase into the cache.
================================

The gpg-preset-passphrase is a utility to seed the internal cache of a running gpg-agent with passphrases.  It is mainly useful for unattended machines, where the usual pinentry tool may not be used and the passphrases for the to be used keys are given at machine startup.

Passphrases set with this utility don't expire unless the --forget option is used to explicitly clear them from the cache --- or gpg-agent is either restarted or reloaded (by sending a SIGHUP to it).  It is necessary to allow this passphrase presetting by starting gpg-agent with the --allow-preset-passphrase.

List of all commands and options.
---------------------------------

gpg-preset-passphrase is invoked this way:

     gpg-preset-passphrase [options] [command] KEYGRIP

KEYGRIP is a 40 character string of hexadecimal characters identifying the key for which the passphrase should be set or cleared. This keygrip is listed along with the key when running the command: gpgsm --dump-secret-keys. One of the following command options must be given:

--preset
     Preset a passphrase. This is what you usually will use. gpg-preset-passphrase will then read the passphrase from stdin.

--forget
     Flush the passphrase for the given keygrip from the cache.

The following additional options may be used:

-v
--verbose
     Output additional information while running.

-P STRING
--passphrase STRING
     Instead of reading the passphrase from stdin, use the supplied STRING as passphrase.  Note that this makes the passphrase visible for other users.

Communicate with a runnig agent.
================================

The gpg-connect-agent is a utility to communicate with a running gpg-agent.  It is useful to check out the commands gpg-agent provides using the Assuan interface.  It might also be useful for scripting simple applications.  Inputis expected at stdin and out put gets printed to stdout.

It is very similar to running gpg-agent in server mode; but here we connect to a running instance.

List of all commands and options.
---------------------------------

gpg-connect-agent is invoked this way:

     gpg-connect-agent [options]

The following options may be used:

-v
--verbose
     Output additional information while running.

-q

--quiet
     Try to be as quiet as possible.

--homedir DIR
     Set the name of the home directory to DIR. If his option is not used, the home directory defaults to ~/.gnupg.  It is only recognized when given on the command line.  It also overrides any home directory stated through the environment variable GNUPGHOME or (on W32 systems) by means on the Registry entry HKCU\SOFTWARE\GNU\GNUPG:HOMEDIR.

Call a simple symmetric encryption tool.
========================================

Sometimes simple encryption tools are already in use for a long time and there might be a desire to integrate them into the GnuPG framework.  The protocols and encryption methods might be non-standard or not even properly documented, so that a full-fledged encryption tool with an interface like gpg is not doable.  symcryptrun provides a solution: It operates by calling the external encryption/decryption module and provides a passphrase for a key using the standard pinentry based mechanism through gpg-agent.

Note, that symcryptrun is only available if GnuPG has been configured with --enable-symcryptrun at build time.

List of all commands and options.
---------------------------------

symcryptrun is invoked this way:

     symcryptrun --class CLASS --program PROGRAM --keyfile KEYFILE
        [--decrypt | --encrypt] [inputfile]

For encryption, the plain text must be provided on STDIN or as the argument INPUTFILE, and the ciphertext will be output to STDOUT. For decryption vice versa.

CLASS describes the calling conventions of the external tool. Currently it must be given as confucius.  PROGRAM is the the full filename of that external tool.

For the class confucius the option --keyfile is required; KEYFILE is the name of a file containing the secret key, which may be protected by a passphrase.  For detailed calling conventions, see the source code.

Note, that gpg-agent must be running before starting symcryptrun.

The following additional options may be used:

-v
--verbose
     Output additional information while running.

-q

--quiet
     Try to be as quiet as possible.

--homedir DIR
     Set the name of the home directory to DIR. If his option is not used, the home directory defaults to ~/.gnupg.  It is only recognized when given on the command line.  It also overrides any home directory stated through the environment variable GNUPGHOME or (on W32 systems) by means on the Registry entry HKCU\SOFTWARE\GNU\GNUPG:HOMEDIR.

--log-file FILE
     Append all logging output to FILE.  Default is to write logging informaton to STDERR.

The possible exit status codes of symcryptrun are:

0
     Success.

1
     Some error occured.

2
     No valid passphrase was provided.

3
     The operation was canceled by the user.