ntp-keygen - Generate Public and Private Keys Files

giffrom Alice's Adventures in Wonderland, Lewis Carroll

Alice holds the key.

Last update: 20:57 UTC Saturday, December 22, 2007


Related Links

Table of Contents


Introduction

Note: In order to support the MV identity scheme and provide for a trusted-agent function, the -p, and -q options have been changed in minor ways from previous versions. See the command line options for details.

This program generates cryptographic data files used by the NTPv4 authentication schemes. It generates MD5 key files used in symmetric key cryptography and, if the OpenSSL software library has been installed, generates files used in Autokey public key cryptography. All files are in printable ASCII format and can be embedded as attachments in mail to other sites and certificate authorities.

File names begin with the prefix ntpkey_ and end with the postfix _name.filestamp, where name is the host or group name and filestamp is the NTP decimal seconds when the file was generated. This both guarantees uniqueness and simplifies maintenance procedures.

The host name for the host, sign and certificate files is specified by the -s option and must agree with the host option of the crypto configuration command. If this option is not specified, the string returned by the Unix gethostname() function is used. The group name for the identity files and certificate subject and issuer fields is specified by the -i option and must agree with the ident option of the crypto configuration command. If this option is not specified, the host name is used.

Files containing private data are encrypted with DES-CBC and the password specified by the -p option and must agree with the pw option of the crypto configuration command. If the -p option is not specified, the string returned by the Unix gethostname() function is used. However, private data files can be encrypted with the password specified by the -q option and redirected via the standard output stream to a file or another program. In a similar way the public data files can be redirected using the -e option.

All files are installed by default in the keys directory /usr/local/etc, which is normally in a shared filesystem in NFS-mounted networks. The actual location of the keys directory can be changed by the keysdir configuration command.

Host and Sign Key Files

With the -H option the ntp-keygen program generates a new private host key file ntpkey_RSAkey_hostname.filestamp and link ntpkey_host_hostname. With the -S option the program generates a new private sign key file ntpkey_keynamesign_hostname.filestamp and soft link ntpkey_sign_hostname, where keyname is the name of the digest/signature scheme specified by the -S option, either RSA or DSA. If this option is not specified, the host key is used as the sign key.

Certificate Files

The ntp-keygen program automatically generates a new self-signed X.509v3 public certificate ntpkey_digestcert_hostname.filestamp, and soft link ntpkey_cert_hostname, where digest is the name of the digest/signature scheme. All digest/signature schemes in the OpenSSL library are available; however, the scheme specified in the certificate must be compatible with the sign key.

With the -P option the program generates a private certificate including an X509v3 Extended Key Usage extension field with value private. Certificates generated without this option do not contain this field and are by default public.

With the -T option the program generates a trusted certificate including an X509v3 Extended Key Usage extension field with value trustRoot. Certificates generated without this option do not contain this field and are by default nontrusted.

Identity Scheme Files

There are several optional identity schemes available with Autokey, including TC, PC, IFF, GQ and MV described on the Autokey Identity Schemes page. The IFF, GQ and MV schemes are based on a challenge-response exchange where the challenger uses public client parameters and the responder uses private server keys. For the IFF and GQ schemes the ntp-keygen program generates the server file ntpkey_SCHEMEkey_groupname.filestamp and soft link ntpkey_schemekey_groupname, where scheme is iff or gq with the -I or -G options, respectively. In these schemes the client file is not stored locally and must be redirected using the -e option.

In the MV scheme the keys are generated by a trusted agent (TA) which for security purposes is neither a server nor a client. With the -V option the program generates the TA keys file ntpkey_MVta_hostname.filestamp and soft link ntpkey_mvta_hostname. In this scheme the server and client files are not stored locally and must be redirected using the -q and -e options, respectively.

Symmetric Keys Files

With the -M option the ntp-keygen program generates a symmetric keys file ntpkey_MD5key_hostname.filestamp and soft link ntpkey_md5key_hostname. The file contains a list of 16 printable, semi-random MD5 keys compatible with previous NTP versions. It is in plaini text format, so additional keys can be added by hand. Since it is not encrypted, it should be visible only to root and distributed by secure means to other hosts. While this file is not used with the Autokey Version 2 protocol, it is needed to authenticate some remote configuration commands used by the ntpq and ntpdc utilities.

While the key identifiers for MD5 keys must be in the range 1-65,535, inclusive, the ntp-keygen program uses only the identifiers from 1 to 16. The key identifier for each association is specified as the key option with the server or peer configuration command.

Running the Program

The safest way to run the ntp-keygen program is logged in directly as root. The recommended procedure is change to the keys directory, usually /ust/local/etc, then run the program. When run without options for the first time, or if all ntpkey files have been removed, the program generates an RSA host keys file and matching RSA-MD5 certificate file, which is all that is necessary in many cases. Additional information and examples are on the Authentication Options page.

If run again, the program uses the same host, sign and identity files, but generates a new certificate file and link using the fields of the original certificate, but updating the issue and expire dates.

If the -M option is specified, all other options are ignored. The -I, -G and -V options work only with the -T option; a warning message is displayed otherwise. The -q and -e options work only if an identity scheme has been previously specified and in either case a new certificate is not generated. The recommended procedure is to specify all except these options in one invocation of the program and one of these options in a subsequent invocation.

Command Line Options

-c [ RSA-MD2 | RSA-MD5 | RSA-SHA | RSA-SHA1 | RSA-MDC2 | RSA-RIPEMD160 | DSA-SHA | DSA-SHA1 ]
Specify the certificate digest/signature scheme. Note that RSA schemes must be used with a RSA sign key and DSA schemes must be used with a DSA sign key. If not specified, the scheme is RSA-MD5.
-d
Enable debugging. This option displays cryptographic data produced in eye-friendly billboards.
-e
Redirect the public client parameters to the standard output stream.
-G
Generate a new private server keys file for the GQ identity scheme.
-H
Generate a new private RSA host keys file.
-I
Generate a new private server keys file for the IFF identity scheme.
-i name
Specify the group name for the identity file and certificate subject and issuer fields. If not specified, the host name is used as the group name.
-m mod
Set the modulus for cryptographic keys to mod in the range 256-2048. If not specified, the modulus is 512. Caution: some schemes may not work with values other than 512 and some with larger values may produce unacceptably large network packets and may require unacceptably long times to compute.
-M
Generate a new public keys file containing 16 MD5 semi-random keys.
-P
Generate a new private certificate file. If not specified, the program generates a public certificate file.
-p password
Specify the read and write password for locally generated files to password. If not specified the host name is used as the password.
-q password
Redirect the server keys file to the standard output stream encrypted using password.
-S [ RSA | DSA ]
Generate a new sign keys file of the designated type. If not specified, the host key is used as the sign key.
-s name
Specify the host name for the host, sign and certificate files. If not specified, the host name is the string returned by the Unix gethostname() function.
-T
Generate a new trusted certificate file. By default, the program generates a nontrusted certificate file.
-V nkeys
Generate a new private trusted-agent file for the Mu-Varadharajan (MV) identity scheme containing nkeys activation keys.

File Formats

All file formats begin with two lines. The first contains the file name, including the host/group name and filestamp, while the second contains the datestamp in conventional Unix date format. Empty lines and lines beginning with # are ignored. For all except the symmetric keys file, the cryptographic values are encoded first using ASN.1 encoding rules and then in PEM-encoded printable ASCII format preceded and followed by MIME content identifier lines.

Private/public key files and certificates are compatible with other OpenSSL applications and very likely other libraries as well. Certificates or certificate requests derived from them should be compatible with extant industry practice, although some users might find the interpretation of X509v3 extension fields somewhat liberal. However, the identity files, although encoded as the other files, are probably not compatible with anything other than Autokey.

The format of the symmetric keys file is different than the other files for backward compatibility with the NTPv3 format and can be further customized using an ordinary text editor. The lines following the header contain 16 MD5 keys, one key per line. Since DES-CBC is deprecated in NTPv4, the only key format of interest is MD5 alphanumeric strings. Keys are entered one per line in the format

keyno MD5 key

where keyno is an integer in the range 1-65,535 and key is the key itself, which is a string containing 16 characters or less. Each character is chosen from the 93 printable ASCII characters in the range 0x21 through 0x7f excluding space and the '#' character.

Note that the keys used by the ntpq and ntpdc programs are checked against passwords requested by the program and entered by hand, so it is generally appropriate to specify these keys in human readable ASCII format.

Bugs

It can take quite a while to generate some cryptographic values, from one to several minutes with modern architectures such as UltraSPARC and up to tens of minutes to an hour with older architectures such as SPARC IPC.