PKCS#11 Configuration
Consistent configuration In order for multiple applications on the user's desktop to use PKCS#11 modules in a consistent manner, there must be a configuration or registry to specify which modules to load and how to use them. The PKCS#11 specification does not specify such a configuration standard. Because of the multi-library module initialization problem, use of PKCS#11 modules must be coordinated within an application. p11-kit provides that coordination. Since coordination is required, it follows that p11-kit can also implement a consistent module configuration.
Example The following sections describe the config format in detail. But first an example which shows the various features. The configuration below, loads two modules called 'my-module' and 'nss'. The user settings override some aspects of the system settings. Global configuration file: /etc/pkcs11/pkcs11.conf # This setting controls whether to load user configuration from the # ~/.pkcs11 directory. Possible values: # none: No user configuration (default) # merge: Merge the user configuration over the system configuration # only: Only user configuration, ignore system configuration user-config: merge One module configuration file per module: /etc/pkcs11/modules/my-module # This setting controls the actual module library to load. This config file # might be installed by the package that installs this module library. This # is not an absolute path name. Relative path names are loaded from the # $(libdir)/pkcs11 directory by default. module: my-pkcs11-module.so # This controls whether the module is required to successfully initialize. If 'yes', then # a failure to load or initialize this module will result in a p11-kit system failure. critical: no User configuration file: ~/.pkcs11/pkcs11.conf # This is an empty file. Files that do not exist are treated as empty. User configuration file: ~/.pkcs11/modules/my-module # Merge with the settings in the system my-module config file. In this case # a developer has overridden to load a different module for my-module instead. module: /home/user/src/custom-module/my-module.so User configuration file: ~/.pkcs11/modules/nss # Load the NSS libsoftokn.so.3 PKCS#11 library as a module. Note that we pass # some custom non-standard initialization arguments, as NSS expects. module: /usr/lib/libsoftokn3.so x-init-reserved: configdir='sql:/home/test/.pki/nssdb' certPrefix='' keyPrefix='' secmod='socmod.db' critical: yes
File format A complete configuration consists of several files. These files are text files. Since p11-kit is built to be used in all sorts of environments and at very low levels of the software stack, we cannot make use of high level configuration APIs that you may find on a modern desktop. Each setting in the config file is specified consists of a name and a value. The name is a simple string consisting of characters and dashes. The name consists of alpha numeric characters, dot, hyphen and underscore. The value is specified after the name on the same line, separated from it by a : (colon). White space between the name and value is ignored. Blank lines are ignored. White space at the beginning or end of lines is stripped. Lines that begin with a # character are ignored as comments. Comments are not recognized when they come after a value on a line. A fictitious sample configuration file might look like: name:value # Here is a comment setting.2: A long value with text. x-custom : text
Module Configuration Each configured PKCS#11 module has its own config file. These files can be placed in various locations. Most importantly each config file specifies the path of the PKCS#11 module to load. A module config file has the following fields: module: The filename of the PKCS#11 module to load. This should include an extension like .so If this value is blank, then the module will be ignored. This can be used in the user configs to override loading of a module specified in the system configuration. If this is a relative path, then the module will be loaded from the default module directory. critical: Set to yes if the module is critical and required to load. If a critical module fails to load or initialize, then the loading process for all registered modules will abort and return an error code. This argument is optional and defaults to no. enable-in: A comma and/or space separated list of names of programs that this module should only be loaded in. The module will not be loaded for other programs using p11-kit. The base name of the process executable should be used here, for example seahorse, ssh. This is not a security feature. The argument is optional. If not present, then any process will load the module. disable-in: A comma and/or space separated list of names of programs that this module should not be loaded in. The module will be loaded for any other programs using p11-kit. The base name of the process executable should be used here, for example firefox, thunderbird-bin. This is not a security feature. The argument is optional. If not present, then any process will load the module. Do not specify both enable-in and disable-in for the same module. Other fields may be present, but it is recommended that field names that are not specified in this document start with a x- prefix.
Global Configuration A global configuration is also present. This file contains settings that are not related to a single PKCS#11 module. The location(s) of the global configuration are described below. The global configuration file can contain the following fields: user-config: This will be equal to one of the following values: none, merge, only. Other fields may be present, but it is recommended that field names that are not specified in this document start with a x- prefix.
Configuration Files Each configured PKCS#11 module is has its own config file. These files are placed in a directory. In addition a global config file exists. There is a system configuration consisting of the various module config files and a file for global configuration. Optionally each user can provide additional configuration or override the system configuration. The system global configuration file is usually in /etc/pkcs11/pkcs11.conf and the user global configuration file is in ~/.pkcs11/pkcs11.conf in the user's home directory. The module config files are usually located in the /etc/pkcs11/modules directory, with one configuration file per module. In addition the ~/.pkcs11/modules directory can be used for modules installed by the user. The default system config file and module directory can be changed when building p11-kit. Always lookup these paths using pkg-config.