Name

modutil — Manage PKCS #11 module information within the security module database.

Synopsis

modutil [options] [[arguments]]

STATUS

This documentation is still work in progress. Please contribute to the initial review in Mozilla NSS bug 836477

Description

The Security Module Database Tool, modutil, is a command-line utility for managing PKCS #11 module information both within secmod.db files and within hardware tokens. modutil can add and delete PKCS #11 modules, change passwords on security databases, set defaults, list module contents, enable or disable slots, enable or disable FIPS 140-2 compliance, and assign default providers for cryptographic operations. This tool can also create certificate, key, and module security database files.

The tasks associated with security module database management are part of a process that typically also involves managing key databases and certificate databases.

Options

Running modutil always requires one (and only one) option to specify the type of module operation. Each option may take arguments, anywhere from none to multiple arguments.

Options

-add modulename

Add the named PKCS #11 module to the database. Use this option with the -libfile, -ciphers, and -mechanisms arguments.

-changepw tokenname

Change the password on the named token. If the token has not been initialized, this option initializes the password. Use this option with the -pwfile and -newpwfile arguments. A password is equivalent to a personal identification number (PIN).

-chkfips

Verify whether the module is in the given FIPS mode. true means to verify that the module is in FIPS mode, while false means to verify that the module is not in FIPS mode.

-create

Create new certificate, key, and module databases. Use the -dbdir directory argument to specify a directory. If any of these databases already exist in a specified directory, modutil returns an error message.

-default modulename

Specify the security mechanisms for which the named module will be a default provider. The security mechanisms are specified with the -mechanisms argument.

-delete modulename

Delete the named module. The default NSS PKCS #11 module cannot be deleted.

-disable modulename

Disable all slots on the named module. Use the -slot argument to disable a specific slot.

The internal NSS PKCS #11 module cannot be disabled.

-enable modulename

Enable all slots on the named module. Use the -slot argument to enable a specific slot.

-fips [true | false]

Enable (true) or disable (false) FIPS 140-2 compliance for the default NSS module.

-force

Disable modutil's interactive prompts so it can be run from a script. Use this option only after manually testing each planned operation to check for warnings and to ensure that bypassing the prompts will cause no security lapses or loss of database integrity.

-list [modulename]

Display basic information about the contents of the secmod.db file. Specifying a modulename displays detailed information about a particular module and its slots and tokens.

-rawadd

Add the module spec string to the secmod.db database.

-rawlist

Display the module specs for a specified module or for all loadable modules.

-undefault modulename

Specify the security mechanisms for which the named module will not be a default provider. The security mechanisms are specified with the -mechanisms argument.

Arguments

MODULE

Give the security module to access.

MODULESPEC

Give the security module spec to load into the security database.

-ciphers cipher-enable-list

Enable specific ciphers in a module that is being added to the database. The cipher-enable-list is a colon-delimited list of cipher names. Enclose this list in quotation marks if it contains spaces.

-dbdir directory

Specify the database directory in which to access or create security module database files.

modutil supports two types of databases: the legacy security databases (cert8.db, key3.db, and secmod.db) and SQLite databases (cert9.db, key4.db, and pkcs11.txt). If the prefix dbm: is not used, then the tool assumes that the given databases are in SQLite format.

--dbprefix prefix

Specify the prefix used on the database files, such as my_ for my_cert9.db. This option is provided as a special case. Changing the names of the certificate and key databases is not recommended.

-libfile library-file

Specify a path to a library file containing the implementation of the PKCS #11 interface module that is being added to the database.

-mechanisms mechanism-list

Specify the security mechanisms for which a particular module will be flagged as a default provider. The mechanism-list is a colon-delimited list of mechanism names. Enclose this list in quotation marks if it contains spaces.

The module becomes a default provider for the listed mechanisms when those mechanisms are enabled. If more than one module claims to be a particular mechanism's default provider, that mechanism's default provider is undefined.

modutil supports several mechanisms: RSA, DSA, RC2, RC4, RC5, AES, DES, DH, SHA1, SHA256, SHA512, SSL, TLS, MD5, MD2, RANDOM (for random number generation), and FRIENDLY (meaning certificates are publicly readable).

-newpwfile new-password-file

Specify a text file containing a token's new or replacement password so that a password can be entered automatically with the -changepw option.

-nocertdb

Do not open the certificate or key databases. This has several effects:

  • With the -create command, only a module security file is created; certificate and key databases are not created.

  • With the -changepw command, the password on the NSS internal module cannot be set or changed, since this password is stored in the key database.

-pwfile old-password-file

Specify a text file containing a token's existing password so that a password can be entered automatically when the -changepw option is used to change passwords.

-secmod secmodname

Give the name of the security module database (like secmod.db) to load.

-slot slotname

Specify a particular slot to be enabled or disabled with the -enable or -disable options.

-string CONFIG_STRING

Pass a configuration string for the module being added to the database.

Usage and Examples

Creating Database Files

Before any operations can be performed, there must be a set of security databases available. modutil can be used to create these files. The only required argument is the database that where the databases will be located.

modutil -create -dbdir directory

Adding a Cryptographic Module

Adding a PKCS #11 module means submitting a supporting library file, enabling its ciphers, and setting default provider status for various security mechanisms. This can be done by supplying all of the information through modutil directly. For the most basic case, simply upload the library:

modutil -add modulename -libfile library-file [-ciphers cipher-enable-list] [-mechanisms mechanism-list] 

For example:

modutil -dbdir /home/my/sharednssdb -add "Example PKCS #11 Module" -libfile "/tmp/crypto.so" -mechanisms RSA:DSA:RC2:RANDOM 

Using database directory ... 
Module "Example PKCS #11 Module" added to database.

Adding Module Spec

Each module has information stored in the security database about its configuration and parameters. These can be added or edited using the -rawadd command. For the current settings or to see the format of the module spec in the database, use the -rawlist option.

modutil -rawadd modulespec

Deleting a Module

A specific PKCS #11 module can be deleted from the secmod.db database:

modutil -delete modulename -dbdir directory 

Displaying Module Information

The secmod.db database contains information about the PKCS #11 modules that are available to an application or server to use. The list of all modules, information about specific modules, and database configuration specs for modules can all be viewed.

To simply get a list of modules in the database, use the -list command.

modutil -list [modulename] -dbdir directory 

Listing the modules shows the module name, their status, and other associated security databases for certificates and keys. For example:

modutil -list -dbdir /home/my/sharednssdb 

Listing of PKCS #11 Modules
-----------------------------------------------------------
  1. NSS Internal PKCS #11 Module
         slots: 2 slots attached
        status: loaded

         slot: NSS Internal Cryptographic Services                            
        token: NSS Generic Crypto Services
	  uri: pkcs11:token=NSS%20Generic%20Crypto%20Services;manufacturer=Mozilla%20Foundation;serial=0000000000000000;model=NSS%203

         slot: NSS User Private Key and Certificate Services                  
        token: NSS Certificate DB
	  uri: pkcs11:token=NSS%20Certificate%20DB;manufacturer=Mozilla%20Foundation;serial=0000000000000000;model=NSS%203
-----------------------------------------------------------

Passing a specific module name with the -list returns details information about the module itself, like supported cipher mechanisms, version numbers, serial numbers, and other information about the module and the token it is loaded on. For example:

 modutil -list "NSS Internal PKCS #11 Module" -dbdir /home/my/sharednssdb

-----------------------------------------------------------
Name: NSS Internal PKCS #11 Module
Library file: **Internal ONLY module**
Manufacturer: Mozilla Foundation              
Description: NSS Internal Crypto Services    
PKCS #11 Version 2.20
Library Version: 3.11
Cipher Enable Flags: None
Default Mechanism Flags: RSA:RC2:RC4:DES:DH:SHA1:MD5:MD2:SSL:TLS:AES

  Slot: NSS Internal Cryptographic Services                            
  Slot Mechanism Flags: RSA:RC2:RC4:DES:DH:SHA1:MD5:MD2:SSL:TLS:AES
  Manufacturer: Mozilla Foundation              
  Type: Software
  Version Number: 3.11
  Firmware Version: 0.0
  Status: Enabled
  Token Name: NSS Generic Crypto Services     
  Token Manufacturer: Mozilla Foundation              
  Token Model: NSS 3           
  Token Serial Number: 0000000000000000
  Token Version: 4.0
  Token Firmware Version: 0.0
  Access: Write Protected
  Login Type: Public (no login required)
  User Pin: NOT Initialized

  Slot: NSS User Private Key and Certificate Services                  
  Slot Mechanism Flags: None
  Manufacturer: Mozilla Foundation              
  Type: Software
  Version Number: 3.11
  Firmware Version: 0.0
  Status: Enabled
  Token Name: NSS Certificate DB              
  Token Manufacturer: Mozilla Foundation              
  Token Model: NSS 3           
  Token Serial Number: 0000000000000000
  Token Version: 8.3
  Token Firmware Version: 0.0
  Access: NOT Write Protected
  Login Type: Login required
  User Pin: Initialized

A related command, -rawlist returns information about the database configuration for the modules. (This information can be edited by loading new specs using the -rawadd command.)

 modutil -rawlist -dbdir /home/my/sharednssdb
 name="NSS Internal PKCS #11 Module" parameters="configdir=. certPrefix= keyPrefix= secmod=secmod.db flags=readOnly " NSS="trustOrder=75 cipherOrder=100 slotParams={0x00000001=[slotFlags=RSA,RC4,RC2,DES,DH,SHA1,MD5,MD2,SSL,TLS,AES,RANDOM askpw=any timeout=30 ] }  Flags=internal,critical"

Setting a Default Provider for Security Mechanisms

Multiple security modules may provide support for the same security mechanisms. It is possible to set a specific security module as the default provider for a specific security mechanism (or, conversely, to prohibit a provider from supplying those mechanisms).

modutil -default modulename -mechanisms mechanism-list 

To set a module as the default provider for mechanisms, use the -default command with a colon-separated list of mechanisms. The available mechanisms depend on the module; NSS supplies almost all common mechanisms. For example:

modutil -default "NSS Internal PKCS #11 Module" -dbdir -mechanisms RSA:DSA:RC2 

Using database directory c:\databases...

Successfully changed defaults.

Clearing the default provider has the same format:

modutil -undefault "NSS Internal PKCS #11 Module" -dbdir -mechanisms MD2:MD5

Enabling and Disabling Modules and Slots

Modules, and specific slots on modules, can be selectively enabled or disabled using modutil. Both commands have the same format:

modutil -enable|-disable modulename [-slot slotname] 

For example:

modutil -enable "NSS Internal PKCS #11 Module" -slot "NSS Internal Cryptographic Services                            " -dbdir .

Slot "NSS Internal Cryptographic Services                            " enabled.

Be sure that the appropriate amount of trailing whitespace is after the slot name. Some slot names have a significant amount of whitespace that must be included, or the operation will fail.

Enabling and Verifying FIPS Compliance

The NSS modules can have FIPS 140-2 compliance enabled or disabled using modutil with the -fips option. For example:

modutil -fips true -dbdir /home/my/sharednssdb/

FIPS mode enabled.

To verify that status of FIPS mode, run the -chkfips command with either a true or false flag (it doesn't matter which). The tool returns the current FIPS setting.

modutil -chkfips false -dbdir /home/my/sharednssdb/

FIPS mode enabled.

Changing the Password on a Token

Initializing or changing a token's password:

modutil -changepw tokenname [-pwfile old-password-file] [-newpwfile new-password-file] 
modutil -dbdir /home/my/sharednssdb -changepw "NSS Certificate DB" 

Enter old password: 
Incorrect password, try again... 
Enter old password: 
Enter new password: 
Re-enter new password: 
Token "Communicator Certificate DB" password changed successfully.

NSS Database Types

NSS originally used BerkeleyDB databases to store security information. The last versions of these legacy databases are:

  • cert8.db for certificates

  • key3.db for keys

  • secmod.db for PKCS #11 module information

BerkeleyDB has performance limitations, though, which prevent it from being easily used by multiple applications simultaneously. NSS has some flexibility that allows applications to use their own, independent database engine while keeping a shared database and working around the access issues. Still, NSS requires more flexibility to provide a truly shared security database.

In 2009, NSS introduced a new set of databases that are SQLite databases rather than BerkleyDB. These new databases provide more accessibility and performance:

  • cert9.db for certificates

  • key4.db for keys

  • pkcs11.txt, which is listing of all of the PKCS #11 modules contained in a new subdirectory in the security databases directory

Because the SQLite databases are designed to be shared, these are the shared database type. The shared database type is preferred; the legacy format is included for backward compatibility.

By default, the tools (certutil, pk12util, modutil) assume that the given security databases use the SQLite type. Using the legacy databases must be manually specified by using the dbm: prefix with the given security directory. For example:

modutil -create -dbdir dbm:/home/my/sharednssdb

To set the legacy database type as the default type for the tools, set the NSS_DEFAULT_DB_TYPE environment variable to dbm:

export NSS_DEFAULT_DB_TYPE="dbm"

This line can be added to the ~/.bashrc file to make the change permanent for the user.

  • https://wiki.mozilla.org/NSS_Shared_DB_Howto

For an engineering draft on the changes in the shared NSS databases, see the NSS project wiki:

  • https://wiki.mozilla.org/NSS_Shared_DB

See Also

certutil (1)

pk12util (1)

The NSS wiki has information on the new database design and how to configure applications to use it.

  • https://wiki.mozilla.org/NSS_Shared_DB_Howto

  • https://wiki.mozilla.org/NSS_Shared_DB

Additional Resources

For information about NSS and other tools related to NSS (like JSS), check out the NSS project wiki at http://www.mozilla.org/projects/security/pki/nss/. The NSS site relates directly to NSS code changes and releases.

Mailing lists: https://lists.mozilla.org/listinfo/dev-tech-crypto

IRC: Freenode at #dogtag-pki

Authors

The NSS tools were written and maintained by developers with Netscape, Red Hat, Sun, Oracle, Mozilla, and Google.

Authors: Elio Maldonado <emaldona@redhat.com>, Deon Lackey <dlackey@redhat.com>.

LICENSE

Licensed under the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.