ArchWiki / Network Security Services
ArchWiki / Network Security Services
ja:Network Security Services ru:Network Security Services zh-hans:Network Security Services Network Security Services (NSS) is a set of libraries designed to support cross-platform development of security-enabled client and server applications.
Applications built with NSS can support SSL v2 and v3, TLS, PKCS #5, PKCS #7, PKCS #11, PKCS #12, S/MIME, X.509 v3 certificates, and other security standards.
NSS is required by many packages, including, for example, Chromium and Firefox.
Installation
Usage
NSS is implemented in terms of operations on a dynamically configured list of PKCS #11 modules. Each module provides access to tokens, which can execute cryptographic operations and store cryptographic objects. The configured list of modules is usually stored in an arbitrary directory, provided by a user at initialization of NSS, in the file pkcs11.txt. The list always contains a built-in module "NSS Internal PKCS #11 Module" with tokens "NSS Generic Crypto Services" and "NSS Certificate DB". The first token provides cryptographic mechanisms such as RSA, SHA256, TLS etc. The second token stores certificates and private keys in the same user-provided directory in the files cert9.db and key4.db. The files pkcs11.txt, cert9.db and key4.db are also called "NSS databases". Paths to NSS databases for some applications are listed in the table below. You should provide some path for each operation. Examples below will use ~/.pki/nssdb/.
Since Firefox 147, previously at
~/.mozilla/firefox/profile/.
For managing PKCS #11 modules NSS provides the modutil(1) utility, for managing certificates and private keys — the certutil(1) utility.
NSS can automatically add /usr/lib/libnssckbi.so to the list of PKCS #11 modules depending on initialization flags.
List certificate DB
To get list of all certificates:
$ certutil -d ~/.pki/nssdb/ -LTo get details about certificate:
$ certutil -d ~/.pki/nssdb/ -L -n certificate_nicknameGenerate an RSA private key
$ certutil -d ~/.pki/nssdb/ -G -g keysize -n nicknameGenerate a certificate signing request
$ certutil -d ~/.pki/nssdb/ -R -k key-id -s subject -o fileGenerate a self-signed certificate
$ certutil -d ~/.pki/nssdb/ -S -s subject -n nickname -x -t C,C,C -o fileGenerate a self-signed certificate with the assistance of OpenSSL
Using OpenSSL allows you to have an interactive prompt that's easier to format than using the certutil subject format. Instructions below were adapted from https://serverfault.com/questions/831394/how-can-i-create-a-pkcs12-file-using-openssl-self-signed-certs and https://askubuntu.com/questions/1225262/how-do-i-generate-a-certificate-to-sign-pdf-electronically.
Create a key pair and a certificate (-noenc disables encryption of a private key with a password):
$ openssl req -x509 -newkey rsa:4096 -keyout myKey.pem -out cert.pem -days 365 -noencCreate a pkcs12 file:
$ openssl pkcs12 -export -out keyStore.p12 -inkey myKey.pem -in cert.pemCreate NSS databases if they do not exist yet:
$ certutil -d ~/.pki/nssdb -N --empty-passwordImport your key to the database:
$ pk12util -d ~/.pki/nssdb -i keyStore.p12Import certificate
To add a certificate specify the -A option:
$ certutil -d ~/.pki/nssdb/ -A -t "TRUSTARGS" -n certificate_nickname -i /path/to/cert/filenameThe TRUSTARGS are three strings of zero or more alphabetic characters, separated by commas, for example: "TCu,Cu,Tuw". They define how the certificate should be trusted for SSL, email, and object signing, and are explained in the certutil(1) manual or Meena's blog post on trust flags.
To add a personal certificate and private key for SSL client authentication use the command:
$ pk12util -d ~/.pki/nssdb/ -i /path/to/PKCS12/cert/filename.p12This will import a personal certificate and private key stored in a PKCS #12 file. The TRUSTARGS of the personal certificate will be set to "u,u,u".
Edit certificate
Call certutil with -M option to edit the certificate. For example, to edit the TRUSTARGS:
$ certutil -d ~/.pki/nssdb/ -M -t "TRUSTARGS" -n certificate_nicknameDelete certificate
Use -D option to remove the certificate:
$ certutil -d ~/.pki/nssdb/ -D -n certificate_nicknameAdding a trusted CA certificate
A system-wide trust store /usr/lib/pkcs11/p11-kit-trust.so is usually automatically added to the list of PKCS #11 modules. See Transport Layer Security#Trust management for system-wide configuration. For application-specific configuration use such a command to add a CA certificate:
certutil -d ~/.pki/nssdb/ -A -i /path/to/certificate -n certificate_nickname -t C,,