From: Harlan Stenn Date: Wed, 29 Apr 2009 05:40:19 +0000 (-0400) Subject: Updates from Dave Mills X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8f8172dadb38e6dedd33e33bbe2bec2ad3855b8f;p=thirdparty%2Fntp.git Updates from Dave Mills bk: 49f7e843wOms1czKBaWSKuFCD73HnQ --- diff --git a/ChangeLog b/ChangeLog index f29d8999fb..0d67036885 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +* Updates from Dave Mills: +* ntp-keygen.c: Updates. +* Fix the error return and syslog function ID in refclock_{param,ppsapi}. +* Make sure syspoll is within the peer's minpoll/maxpoll bounds. +* ntp_crypto.c: Use sign_siglen, not len. sign key filename cleanup. +* Bump NTP_MAXEXTEN from 1024 to 2048, update values for some field lengths. (4.2.5p167) 2009/04/26 Released by Harlan Stenn * Crypto cleanup from Dave Mills. (4.2.5p166) 2009/04/25 Released by Harlan Stenn diff --git a/html/keygen.html b/html/keygen.html index ddf584ed40..d41a71b1f2 100644 --- a/html/keygen.html +++ b/html/keygen.html @@ -2,140 +2,229 @@ - - - - ntp-keygen - generate public and private keys - + + + +ntp-keygen - generate public and private keys + - -

ntp-keygen - generate public and private keys

- giffrom Alice's Adventures in Wonderland, Lewis Carroll -

Alice holds the key.

-

Last update: July 5, 2008

-
-

Related Links

- -

Table of Contents

- -
-

Synopsis

-

ntp-keygen [ -cdeMPT ] [ -c [RSA-MD2 | RSA-MD5 | RSA-SHA | RSA-SHA1 | RSA-MDC2 | RSA-RIPEMD160 | DSA-SHA | DSA-SHA1 ] ] [ -H } [ -i issuername ] [ -p passwd2 ] [ -q passwd1 ] [ -S [ RSA | DSA ] ] [ -s subjectame ] [ -V nkeys ]

-

Description

-

This program generates cryptographic data files used by the NTPv4 authentication and identity schemes. It generates MD5 keys used in symmetric key cryptography and, if the OpenSSL software library has been installed, it generates host keys, certificates and identity keys used in the Autokey public key cryptography. The symmetric keys file is generated in a format compatable with NTPv3 and also used with NTPv4. All other files are in PEM-encoded printable ASCII format so they can be embedded as MIME attachments in mail to other sites and certificate authorities.

-

When used to generate symmetric keys, the program produces a file containing 16 random keys. If this is the only need, run ntp-keygen with the -M option and disregard the remainder of this page. The file can be edited later with purpose-chosen passwords. Each line of the file contains three fields, first an integer between 1 and 65534, inclusive, representing the key identifier used in the server and peer configuration command. Next is the single character M to designate the key as MD5. Finally is the key itself from 1 to 31 characters chosen from the printable ASCII set with the exclusion of space and #. As is custom, # and the remaining chacters on the line are ignored.

-

Generated files are compatible with other OpenSSL applications and other Public Key Infrastructure (PKI) resources. Certificates generated by this program should be compatible with extant industry practice, although some users might find the interpretation of X509v3 extension fields somewhat liberal. However, the identity keys are probably not compatible with anything other than Autokey.

-

Most files used by this program are encrypted using a private password. The -p option specifies the password for local files and the -q option the password for files to be sent to remote sites. If no local password is specified, the string returned by the Unix gethostname() function is used. If no remote password is specified, the local password is used.

-

The ntpd command crypto pw specifies the read password for previously encrypted files. This must match the local password used by this program. If not specified, the host name is used. Thus, if files are generated by this program without password, they can be read back by ntpd without password, but only on the same host.

-

All files and links are installed by default in the keys directory /usr/local/etc, which is normally in a shared filesystem in NFS-mounted networks. The location of the keys directory can be changed by the keysdir configuration command. Normally, encrypted files for each host are generated by that host and used only by that host, although exceptions exist as noted later on this page.

-

This program directs commentary and error messages to the standard error stream stderr and remote files to the standard output stream stdout where they can be piped to other aplications or redirected to a file. The names used for generated files and links all begin with the string ntpkey and include the file type, generating host and filestamp, as described in the Cryptographic Data Files section below

-

Running the Program

-

To test and gain experience with Autokey concepts, log in as root and change - to the keys directory, usually /usr/local/etc. When run for the first - time, or if all files with names beginning ntpkey have been removed, - use the ntp-keygen command without arguments to generate a default - RSA host key and matching RSA-MD5 certificate with expiration date - one year hence. If run again, the program uses the existing keys - and parameters and generates a new certificate with new expiration - date one year hence; however, the certificate is not generated - if the -e or -q options - are present..

-

Run the command on as many hosts as necessary. Designate one of them as the trusted host (TH) using ntp-keygen with the -T option and configure it to synchronize from reliable Internet servers. Then configure the other hosts to synchronize to the TH directly or indirectly. A certificate trail is created when Autokey asks the immediately ascendant host towards the root to sign its certificate, which is then provided to the immediately descendant host on request. All group hosts should have acyclic certificate trails ending on the TH.

-

The host key is used to encrypt the cookie when required and so must be - RSA type. By default, the host key is also the sign key used to encrypt - signatures. A different sign key can be assigned using the -S option - and this can be either RSA or DSA type. By default, the signature - message digest type is MD5, but any combination of sign key type - and sign digest type supported by the OpenSSL library can be specified - using the -c option. - At the moment, legacy considerations require the NTP packet header - digest type to be MD5.

-

Trusted Hosts and Secure Groups

-

As described on the Authentication Options page, an NTP secure group consists of one or more low-stratum THs as the root from which all other group hosts derive synchronization directly or indirectly. For authentication purposes all hosts in a group must have the same group name specified by the -i option and matching the crypto ident command option. The group name is used in the subject and issuer fields of trusted certificates and when constructing the file names for identity keys. All hosts must have different host names specified by the -s option and matching the crypto host command option. Host names are used in the subject and issuer fields of nontrusted certificates and when constructing the file names for host and sign keys and certificats. Host and group names are used only for authentication purposes and have nothing to do with DNS names.

-

Identity Schemes

-

As described on the Authentication Options page, there are five identity schemes, three of which - IFF, GQ and MV - require identity keys specific to each scheme. There are two files for each scheme, an encrypted keys file and a nonencrypted parameters file. In general, servers use the keys file and clients use the parameters file. In general, servers expecting to support a client population ned the keys file while others need only the parameters file. Both files are generated by the TA on behalf of all servers and clients in the group.

-

The parameters files are public; they can be stored in a public place and sent in the clear. The keys files are encrypted with the local password. To retrieve the keys file, a host sends a mail request to the TA including its local password. The TA encrypts the keys file with this password and returns it as an attachment. The attachment is then copied intact to the keys directory with name given in the first line of the file, but all in lower case and with the filestamp deleted..

-

For example, the TA can generate IFF keys and trusted certificate - using the command

-

ntp-keygen -p local_passwd -T -I

-

Once these media have been generated, the TA can then generate the public - parameters using the command

- ntp-keygen -p local_passwd -e >parameters_file

-

where the -e option redirects the unencrypted parameters to - the standard output stream for a mail application or stored locally - for later distribution. In a similar fashion the -q option redirects - the encrypted server keys to the standard output stream.

-

-

Command Line Options

-
-
-c [ RSA-MD2 | RSA-MD5 | RSA-SHA | RSA-SHA1 | RSA-MDC2 | RSA-RIPEMD160 | DSA-SHA | DSA-SHA1 ] -
Select certificate and message digest/signature encryption scheme. Note that RSA schemes must be used with a RSA sign key and DSA schemes must be used with a DSA sign key. The default without this option is RSA-MD5. -
-d -
Enable debugging. This option displays the cryptographic data produced for eye-friendly billboards.
-e -
Extract the IFF or GQ public parameters from the IFFkey or GQkey keys - file previously specified. Send the unencrypted data to the - standard output stream stdout. - While the IFF parameters do not reveal the - private group key,  the - GQ parameters should be used with caution, as - they include the group key. Use the -q option with password - instead. - Note: a new certificate is not generated when this option is present. - - This allows multiple commands with this option but without disturbing - existing media. -
-G -
Generate GQ key file GQkey and link gqkey for the Guillou-Quisquater (GQ) identity scheme. -
-H -
Generate a new public/private host keys RSAkey, and link host. -
-I -
Generate a new encrypted IFF key file IFFkey and link iffkey for the Schnorr (IFF) identity scheme.
-i group -
Set the group name to group for generated identity files. This is useful only if the TA is not a group member and is generally considered not a good practice.
-M -
Generate a new MD5 key file.
-P -
Generate a new private certificate used by the PC identity scheme. By default, the program generates public certificates. Note: the PC identity scheme is not recommended for new installations.
-p passwd -
Set the password for reading and writing encrypted files to passwd. - By default, the password is the host name.
-q passwd -
Extract the encrypted IFF or GQ server keys from the IFFkey - or GQkey key file previously generated. The data are - sent to the standard output stream stdout. Set the password for - writing the data, which is also the password to read the data - file in another host. By default, the password is the host name. - Note: a new certificate is not generated when this option is present. - This allows multiple commands with this option but without disturbing - existing media. -
-S [ RSA | DSA ] -
Generate a new sign key of the designated type. By default, the sign key is the host key.
-s name -
Set the host name to name. This is used in the host and sign key file names, as well as the subject and issuer names in the certificate. It must match the host name specified in the CRYPTO configuration command.
-T -
Generate a trusted certificate. By default, the program generates nontrusted certificates.
-V nkeys -
Generate server parameters MV and nkeys client keys for the Mu-Varadharajan (MV) identity scheme. Note: support for this option should be considered a work in progress.
-

Random Seed File

-

All cryptographically sound key generation schemes must have means to randomize the entropy seed used to initialize the internal pseudo-random number generator used by the OpenSSL library routines. If a site supports ssh, it is very likely that means to do this are already available. The entropy seed used by the OpenSSL library is contained in a file, usually called .rnd, which must be available when starting the ntp-keygen program or ntpd daemon.

-

The OpenSSL library looks for the file using the path specified by the RANDFILE environment variable in the user home directory, whether root or some other user. If the RANDFILE environment variable is not present, the library looks for the .rnd file in the user home directory. Since both the ntp-keygen program and ntpd daemon must run as root, the logical place to put this file is in /.rnd or /root/.rnd. If the file is not available or cannot be written, the program exits with a message to the system log.

-

Cryptographic Data Files

-

File and link names are in the form ntpkey_key_name.fstamp, where key is the key or parameter type, name is the host or group name and fstamp is the filestamp (NTP seconds) when the file was created). By convention, key fields in generated file names include both upper and lower case alphanumeric characters, while key fields in generated link names include only lower case characters. The filestamp is not used in generated link names.

-

The key type is a string defining the cryptographic function. Key types include public/private keys host and sign, certificate cert and several challenge/response key types. By convention, files used for challenges have a par subtype, as in the IFF challenge IFFpar, while files for responses have a key subtype, as in the GQ response GQkey.

-

All files begin with two nonencrypted lines. The first line contains the file name in the format ntpkey_key_host.fstamp. The second line contains the datestamp in conventional Unix date format. Lines beginning with # are ignored.

-

The remainder of the file contains cryptographic data encoded first using ASN.1 rules, then encrypted using the DES-CBC algorithm and given password and finally written in PEM-encoded printable ASCII text preceded and followed by MIME content identifier lines.

-

The format of the symmetric keys file is somewhat different than the other files in the interest of backward compatibility. Since DES-CBC is deprecated in NTPv4, the only key format of interest is MD5 alphanumeric strings. Following the header the keys are entered one per line in the format

-

keyno type key

-

where keyno is a positive integer in the range 1-65,535, type is the string MD5 defining the key format and key is the key itself, which is a printable ASCII string 16 characters or less in length. Each character is chosen from the 93 printable 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 programs and entered by hand, so it is generally appropriate to specify these keys in human readable ASCII format.

-

The ntp-keygen program generates a MD5 symmetric keys file ntpkey_MD5key_hostname.filestamp. Since the file contains private shared keys, it should be visible only to root and distributed by secure means to other subnet hosts. The NTP daemon loads the file ntp.keys, so ntp-keygen installs a soft link from this name to the generated file. Subsequently, similar soft links must be installed by manual or automated means on the other subnet 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.

-

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.

-
- - + +

ntp-keygen - generate public and private keys

+ +

giffrom Alice's Adventures in Wonderland, Lewis Carroll

+ +

Alice holds the key.

+ +

Last update: + 26-Apr-2009 15:46 +

+
+ +

Related Links

+ + +

Table of Contents

+ + + +
+ +

Synopsis

+ +

ntp-keygen [ -deGHIMPT ] [ -c [RSA-MD2 | RSA-MD5 | RSA-SHA + | RSA-SHA1 | RSA-MDC2 | RSA-RIPEMD160 | DSA-SHA | DSA-SHA1 ] ] [ + -i group ] + [ -m modulus ] [ -p passwd2 ] [ -q passwd1 ] [ -S + [ RSA | DSA ] ] [ -s host ] [ -V nkeys ]

+ +

Description

+ +

This program generates cryptographic data files used by the NTPv4 authentication + and identity schemes. It generates MD5 keys used in symmetric key cryptography + and, if the OpenSSL software library has been installed, it generates host keys, + certificates and identity keys used in the Autokey public key cryptography. + The symmetric keys file is generated in a format comparable with NTPv3 and also + used with NTPv4. All other files are in PEM-encoded printable ASCII format so + they can be embedded as MIME attachments in mail to other sites and certificate + authorities.

+ +

When used to generate symmetric keys, the program produces a file containing + 16 random keys. If this is the only need, run ntp-keygen with the -M option + and disregard the remainder of this page. The file can be edited later with + purpose-chosen passwords. Each line of the file contains three fields, first + an integer between 1 and 65534, inclusive, representing the key identifier used + in the server and peer configuration command. Next is the + single character M to designate the key as MD5. Finally is the key + itself from 1 to 31 characters chosen from the printable ASCII set with the + exclusion of space and #. As is custom, # and the remaining characters on the + line are ignored.

+ +

Generated files are compatible with other OpenSSL applications and other Public Key Infrastructure (PKI) resources. Certificates generated by this program should be compatible with extant industry practice, although some users might find the interpretation of X509v3 extension fields somewhat liberal. However, the identity keys are probably not compatible with anything other than Autokey.

+ +

Most files used by this program are encrypted using a private password. The -p option specifies the password for local files and the -q option the password for files to be sent to remote sites. If no local password is specified, the host name returned by the Unix gethostname() function is used. If no remote password is specified, the local password is used.

+ +

The pw option of the crypto configuration command specifies the read password for previously encrypted files. This must match the local password used by this program. If not specified, the host name is used. Thus, if files are generated by this program without password, they can be read back by ntpd without password, but only on the same host.

+ +

All files and links are installed by default in the keys directory /usr/local/etc, which is normally in a shared filesystem in NFS-mounted networks and cannot be changed by clients. The location of the keys directory can be changed by the keysdir configuration command in such cases. Normally, encrypted files for each host are generated by that host and used only by that host, although exceptions exist as noted later on this page.

+ +

This program directs commentary and error messages to the standard error stream stderr and + remote files to the standard output stream stdout where they can be + piped to other applications or redirected to a file. The names used for generated + files and links all begin with the string ntpkey and include the file + type, generating host and filestamp, as described in the Cryptographic + Data Files section below

+ +

Running the Program

+ +

To test and gain experience with Autokey concepts, log in as root and change to the keys directory, usually /usr/local/etc. When run for the first time, or if all files with names beginning ntpkey have been removed, use the ntp-keygen command without arguments to generate a default RSA host key and matching RSA-MD5 certificate with expiration date one year hence. If run again, the program uses the existing keys and parameters and generates a new certificate with new expiration date one year hence; however, the certificate is not generated if the -e or -q options are present.

+ +

Run the command on as many hosts as necessary. Designate one of them as the + trusted host (TH) using ntp-keygen with the -T option and + configure it to synchronize from reliable Internet servers. Then configure the + other hosts to synchronize to the TH directly or indirectly. A certificate trail + is created when Autokey asks the immediately ascendant host towards the root + to sign its certificate, which is then provided to the immediately descendant + host on request. All group hosts should have acyclic certificate trails ending + on the TH.

+ +

The host key is used to encrypt the cookie when required and so must be RSA type. By default, the host key is also the sign key used to encrypt signatures. A different sign key can be assigned using the -S option and this can be either RSA or DSA type. By default, the signature message digest type is MD5, but any combination of sign key type and sign digest type supported by the OpenSSL library can be specified using the -c option. At the moment, legacy considerations require the NTP packet header digest type to be MD5.

+ +

Trusted Hosts and Secure Groups

+ +

As described on the Authentication Options page, + an NTP secure group consists of one or more low-stratum The as the root + from which all other group hosts derive synchronization directly or indirectly. + For authentication purposes all hosts in a group must have the same group name + specified by the -i option and matching the ident option of + the crypto configuration command. The group name is used in the subject + and issuer fields of trusted certificates and when constructing the file names + for identity keys. All hosts must have different host names specified by the -s option + and matching the host option of the crypto configuration command. + Host names are used in the subject and issuer fields of nontrusted certificates + and when constructing the file names for host and sign keys and certificates. + Host and group names are used only for authentication purposes and have nothing + to do with NS names.

+ +

Identity Schemes

+ +

As described on the Authentication Options page, there are five identity schemes, three of which - IFF, GQ and MV - require identity keys specific to each scheme. There are two types of files for each scheme, an encrypted keys file and a nonencrypted parameters file, which usually contains a subset of the keys file. In general, NTP secondary servers operating as certificate signing authorities (CSA) use the keys file and clients use the parameters file. Both files are generated by the TA operating as a certificate authority (CA) on behalf of all servers and clients in the group.

+ +

The parameters files are public; they can be stored in a public place and sent in the clear. The keys files are encrypted with the local password. To retrieve the keys file, a host sends a mail request to the TA including its local password. The TA encrypts the keys file with this password and returns it as an attachment. The attachment is then copied intact to the keys directory with name given in the first line of the file, but all in lower case and with the filestamp deleted..

+ +

For example, the TA can generate IFF keys and trusted certificate using the command

+ +

ntp-keygen -p local_passwd -T -I

+ +

Once these media have been generated, the TA can then generate the public parameters using the command

+ +

ntp-keygen -p local_passwd -e >parameters_file

+ +

where the -e option redirects the unencrypted parameters to the standard output stream for a mail application or stored locally for later distribution. In a similar fashion the -q option redirects the encrypted server keys to the standard output stream.

+ +

Command Line Options

+ +
+ +
-c [ RSA-MD2 | RSA-MD5 | RSA-SHA | RSA-SHA1 | RSA-MDC2 | RSA-RIPEMD160 | DSA-SHA | DSA-SHA1 ]
+
Select certificate and message digest/signature encryption scheme. Note that RSA schemes must be used with a RSA sign key and DSA schemes must be used with a DSA sign key. The default without this option is RSA-MD5.
+ +
-d
+
Enable debugging. This option displays the cryptographic data produced for eye-friendly billboards.
+ +
-e
+
Extract the IFF or GQ public parameters from the IFFkey or GQkey keys file previously specified. Send the unencrypted data to the standard output stream stdout. While the IFF parameters do not reveal the private group key,  the GQ parameters should be used with caution, as they include the group key. Use the -q option with password instead. Note: a new certificate is not generated when this option is present. This allows multiple commands with this option but without disturbing existing media.
+ +
-G
+
Generate GQ key file GQkey and link gqkey for the Guillou-Quisquater + (GQ) identity scheme.
+ +
-H
+
Generate a new public/private host keys RSAkey, and link host.
+ +
-i group
+
Set the group name to group. This is used in the identity file names. It must match the group name specified in the ident option of the crypto configuration command.
+ +
-I
+
Generate a new encrypted IFF key file IFFkey and link iffkey for the Schnorr (IFF) identity scheme.
+ +
-m modulus
+
Set the modulus for generating files to modulus bits. The modulus defaults to 512, but can be set from this value to 2048.
+ +
-M
+
Generate a new MD5 key file.
+ +
-P
+
Generate a new private certificate used by the PC identity scheme. By default, the program generates public certificates. Note: the PC identity scheme is not recommended for new installations.
+ +
-p passwd
+
Set the password for reading and writing encrypted files to passwd. By default, the password is the host name.
+ +
-q passwd
+
Extract the encrypted IFF or GQ server keys from the IFFkey or GQkey key file previously generated. The data are sent to the standard output stream stdout. Set the password for writing the data, which is also the password to read the data file in another host. By default, the password is the host name. Note: a new certificate is not generated when this option is present. This allows multiple commands with this option but without disturbing existing media.
+ +
-S [ RSA | DSA ]
+
Generate a new sign key of the designated type. By default, the sign key is the host key.
+ +
-s host
+
Set the host name to host. This is used in the host and sign key file names. It must match the host name specified in the host option of the crypto configuration command.
+ +
-T
+
Generate a trusted certificate. By default, the program generates nontrusted certificates.
+ +
-V nkeys
+
Generate server parameters MV and nkeys client keys for the Mu-Varadharajan (MV) identity scheme. Note: support for this option should be considered a work in progress.
+ +
+ +

Random Seed File

+ +

All cryptographically sound key generation schemes must have means to randomize the entropy seed used to initialize the internal pseudo-random number generator used by the OpenSSL library routines. If a site supports ssh, it is very likely that means to do this are already available. The entropy seed used by the OpenSSL library is contained in a file, usually called .rnd, which must be available when starting the ntp-keygen program or ntpd daemon.

+ +

The OpenSSL library looks for the file using the path specified by the RANDFILE environment variable in the user home directory, whether root or some other user. If the RANDFILE environment variable is not present, the library looks for the .rnd file in the user home directory. Since both the ntp-keygen program and ntpd daemon must run as root, the logical place to put this file is in /.rnd or /root/.rnd. If the file is not available or cannot be written, the program exits with a message to the system log.

+ +

Cryptographic Data Files

+ +

File and link names are in the form ntpkey_key_name.fstamp, where key is the key or parameter type, name is the host or group name and fstamp is the filestamp (NTP seconds) when the file was created). By convention, key fields in generated file names include both upper and lower case alphanumeric characters, while key fields in generated link names include only lower case characters. The filestamp is not used in generated link names.

+ +

The key type is a string defining the cryptographic function. Key types include public/private keys host and sign, certificate cert and several challenge/response key types. By convention, files used for challenges have a par subtype, as in the IFF challenge IFFpar, while files for responses have a key subtype, as in the GQ response GQkey.

+ +

All files begin with two nonencrypted lines. The first line contains the file + name in the format ntpkey_key_host.fstamp. The + second line contains the datestamp in conventional Unix date format. + Lines beginning with # are ignored.

+ +

The remainder of the file contains cryptographic data encoded first using ASN.1 rules, then encrypted using the DES-CBC algorithm and given password and finally written in PEM-encoded printable ASCII text preceded and followed by MIME content identifier lines.

+ +

The format of the symmetric keys file is somewhat different than the other files in the interest of backward compatibility. Since DES-CBC is deprecated in NTPv4, the only key format of interest is MD5 alphanumeric strings. Following the header the keys are entered one per line in the format

+ +

keyno type key

+ +

where keyno is a positive integer in the range 1-65,535, type is the string MD5 defining the key format and key is the key itself, which is a printable ASCII string 16 characters or less in length. Each character is chosen from the 93 printable 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 programs and entered by hand, so it is generally appropriate to specify these keys in human readable ASCII format.

+ +

The ntp-keygen program generates a MD5 symmetric keys file ntpkey_MD5key_hostname.filestamp. Since the file contains private shared keys, it should be visible only to root and distributed by secure means to other subnet hosts. The NTP daemon loads the file ntp.keys, so ntp-keygen installs a soft link from this name to the generated file. Subsequently, similar soft links must be installed by manual or automated means on the other subnet 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.

+ +

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.

+ +
+ + + + \ No newline at end of file diff --git a/include/ntp.h b/include/ntp.h index e74f5cfd91..b188c123ec 100644 --- a/include/ntp.h +++ b/include/ntp.h @@ -133,7 +133,7 @@ typedef char s_char; #define MAXHOP 2 /* anti-clockhop threshold */ #define MAX_TTL 8 /* max ttl mapping vector size */ #define BEACON 7200 /* manycast beacon interval */ -#define NTP_MAXEXTEN 1024 /* max extension field size */ +#define NTP_MAXEXTEN 2048 /* max extension field size */ /* * Miscellaneous stuff @@ -634,11 +634,11 @@ struct pkt { /* * The length of the packet less MAC must be a multiple of 64 - * with an RSA modulus and Diffie-Hellman prime of 64 octets + * with an RSA modulus and Diffie-Hellman prime of 256 octets * and maximum host name of 128 octets, the maximum autokey * command is 152 octets and maximum autokey response is 460 * octets. A packet can contain no more than one command and one - * response, so the maximum total extension field length is 672 + * response, so the maximum total extension field length is 864 * octets. But, to handle humungus certificates, the bank must * be broke. */ diff --git a/include/ntp_crypto.h b/include/ntp_crypto.h index f8900b83df..5abb331466 100644 --- a/include/ntp_crypto.h +++ b/include/ntp_crypto.h @@ -100,7 +100,7 @@ * Miscellaneous crypto stuff */ #define NTP_MAXSESSION 100 /* maximum session key list entries */ -#define NTP_MAXEXTEN 1024 /* maximum extension field size */ +#define NTP_MAXEXTEN 2048 /* maximum extension field size */ #define NTP_AUTOMAX 12 /* default key list timeout (log2 s) */ #define KEY_REVOKE 17 /* default key revoke timeout (log2 s) */ #define NTP_REFRESH 19 /* default restart timeout (log2 s) */ diff --git a/ntpd/ntp_crypto.c b/ntpd/ntp_crypto.c index 38dcb02024..f6af463fe5 100644 --- a/ntpd/ntp_crypto.c +++ b/ntpd/ntp_crypto.c @@ -355,7 +355,7 @@ make_keylist( EVP_SignUpdate(&ctx, (u_char *)vp, 12); EVP_SignUpdate(&ctx, vp->ptr, sizeof(struct autokey)); if (EVP_SignFinal(&ctx, vp->sig, &len, sign_pkey)) { - vp->siglen = htonl(len); + vp->siglen = htonl(sign_siglen); peer->flags |= FLAG_ASSOC; } } @@ -1420,8 +1420,8 @@ crypto_verify( /* * Check for valid value header opcode, association ID and - & extension field length. The request and response opcodes must - & match and the response ID must match the association ID. The + * extension field length. The request and response opcodes must + * match and the response ID must match the association ID. The * autokey values response is the exception, as it can be sent * unsolicited. */ @@ -1588,7 +1588,7 @@ crypto_encrypt( EVP_SignUpdate(&ctx, (u_char *)&vp->tstamp, 12); EVP_SignUpdate(&ctx, vp->ptr, len); if (EVP_SignFinal(&ctx, vp->sig, &len, sign_pkey)) - vp->siglen = htonl(len); + vp->siglen = htonl(sign_siglen); return (XEVNT_OK); } @@ -1810,7 +1810,7 @@ crypto_update(void) EVP_SignUpdate(&ctx, (u_char *)&pubkey, 12); EVP_SignUpdate(&ctx, pubkey.ptr, ntohl(pubkey.vallen)); if (EVP_SignFinal(&ctx, pubkey.sig, &len, sign_pkey)) - pubkey.siglen = htonl(len); + pubkey.siglen = htonl(sign_siglen); } /* @@ -1829,7 +1829,7 @@ crypto_update(void) EVP_SignUpdate(&ctx, cp->cert.ptr, ntohl(cp->cert.vallen)); if (EVP_SignFinal(&ctx, cp->cert.sig, &len, sign_pkey)) - cp->cert.siglen = htonl(len); + cp->cert.siglen = htonl(sign_siglen); } /* @@ -1852,7 +1852,7 @@ crypto_update(void) EVP_SignUpdate(&ctx, (u_char *)&tai_leap, 12); EVP_SignUpdate(&ctx, tai_leap.ptr, len); if (EVP_SignFinal(&ctx, tai_leap.sig, &len, sign_pkey)) - tai_leap.siglen = htonl(len); + tai_leap.siglen = htonl(sign_siglen); if (leap_sec > 0) crypto_flags |= CRYPTO_FLAG_TAI; snprintf(statstr, NTP_MAXSTRLEN, "signature update ts %u", @@ -2070,7 +2070,7 @@ crypto_alice( EVP_SignUpdate(&ctx, (u_char *)&vp->tstamp, 12); EVP_SignUpdate(&ctx, vp->ptr, len); if (EVP_SignFinal(&ctx, vp->sig, &len, sign_pkey)) - vp->siglen = htonl(len); + vp->siglen = htonl(sign_siglen); return (XEVNT_OK); } @@ -2167,7 +2167,7 @@ crypto_bob( EVP_SignUpdate(&ctx, (u_char *)&vp->tstamp, 12); EVP_SignUpdate(&ctx, vp->ptr, len); if (EVP_SignFinal(&ctx, vp->sig, &len, sign_pkey)) - vp->siglen = htonl(len); + vp->siglen = htonl(sign_siglen); return (XEVNT_OK); } @@ -2372,7 +2372,7 @@ crypto_alice2( EVP_SignUpdate(&ctx, (u_char *)&vp->tstamp, 12); EVP_SignUpdate(&ctx, vp->ptr, len); if (EVP_SignFinal(&ctx, vp->sig, &len, sign_pkey)) - vp->siglen = htonl(len); + vp->siglen = htonl(sign_siglen); return (XEVNT_OK); } @@ -2469,7 +2469,7 @@ crypto_bob2( EVP_SignUpdate(&ctx, (u_char *)&vp->tstamp, 12); EVP_SignUpdate(&ctx, vp->ptr, len); if (EVP_SignFinal(&ctx, vp->sig, &len, sign_pkey)) - vp->siglen = htonl(len); + vp->siglen = htonl(sign_siglen); return (XEVNT_OK); } @@ -2698,7 +2698,7 @@ crypto_alice3( EVP_SignUpdate(&ctx, (u_char *)&vp->tstamp, 12); EVP_SignUpdate(&ctx, vp->ptr, len); if (EVP_SignFinal(&ctx, vp->sig, &len, sign_pkey)) - vp->siglen = htonl(len); + vp->siglen = htonl(sign_siglen); return (XEVNT_OK); } @@ -2798,7 +2798,7 @@ crypto_bob3( EVP_SignUpdate(&ctx, (u_char *)&vp->tstamp, 12); EVP_SignUpdate(&ctx, vp->ptr, len); if (EVP_SignFinal(&ctx, vp->sig, &len, sign_pkey)) - vp->siglen = htonl(len); + vp->siglen = htonl(sign_siglen); return (XEVNT_OK); } @@ -3032,7 +3032,7 @@ cert_sign( EVP_SignUpdate(&ctx, (u_char *)vp, 12); EVP_SignUpdate(&ctx, vp->ptr, len); if (EVP_SignFinal(&ctx, vp->sig, &len, sign_pkey)) - vp->siglen = htonl(len); + vp->siglen = htonl(sign_siglen); } #ifdef DEBUG if (debug > 1) @@ -3775,14 +3775,9 @@ crypto_setup(void) * Load optional sign key from file "ntpkey_sign_". If * available, it becomes the sign key. */ - if (sign_file != NULL) { - snprintf(filename, MAXFILENAME, "ntpkey_sign_%s", - sign_file); - pinfo = crypto_key(filename, passwd, NULL); - if (pinfo != NULL) - sign_pkey = pinfo->pkey; - } - sign_siglen = EVP_PKEY_size(sign_pkey); + snprintf(filename, MAXFILENAME, "ntpkey_sign_%s", sys_hostname); + pinfo = crypto_key(filename, passwd, NULL); if (pinfo != NULL) + sign_pkey = pinfo->pkey; /* * Load required certificate from file "ntpkey_cert_". @@ -3797,6 +3792,7 @@ crypto_setup(void) } cert_host = cinfo; sign_digest = cinfo->digest; + sign_siglen = EVP_PKEY_size(sign_pkey); if (cinfo->flags & CERT_PRIV) crypto_flags |= CRYPTO_FLAG_PRIV; @@ -3864,7 +3860,7 @@ crypto_setup(void) */ crypto_flags |= CRYPTO_FLAG_ENAB | (cinfo->nid << 16); snprintf(statstr, NTP_MAXSTRLEN, - "setup 0x%x host %s %s\n", crypto_flags, sys_hostname, + "setup 0x%x host %s %s", crypto_flags, sys_hostname, OBJ_nid2ln(cinfo->nid)); record_crypto_stats(NULL, statstr); #ifdef DEBUG diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index 398743af89..f092e43841 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -1633,10 +1633,16 @@ clock_update( #endif /* HAVE_LIBSCF_H */ /* - * Update the remaining system state variables. + * Update the system state variables. We do this very carefully, + * as the poll interval might need to be clamped differently. */ sys_peer = peer; sys_epoch = peer->epoch; + if (sys_poll < peer->minpoll) + sys_poll = peer->minpoll; + if (sys_poll > peer->maxpoll) + sys_poll = peer->maxpoll; + poll_update(peer, sys_poll); sys_stratum = min(peer->stratum + 1, STRATUM_UNSPEC); if (peer->stratum == STRATUM_REFCLOCK || peer->stratum == STRATUM_UNSPEC) @@ -1663,6 +1669,11 @@ clock_update( "clock_update: at %lu sample %lu associd %d\n", current_time, peer->epoch, peer->associd); #endif + + /* + * Comes now the moment of truth. Crank the clock discipline and + * see what comes out. + */ switch (local_clock(peer, peer->epoch, sys_offset)) { /* @@ -2685,13 +2696,18 @@ clock_select(void) sys_peer = NULL; return; } + + /* + * Do not use old data, as this may mess up the clock discipline + * stability. + */ if (typesystem->epoch <= sys_epoch) return; /* * We have found the alpha male. Wind the clock. */ - if (osys_peer != typesystem) + if (osys_peer != typesystem) report_event(PEVNT_NEWPEER, typesystem, NULL); typesystem->flags |= FLAG_SYSPEER; clock_update(typesystem); diff --git a/ntpd/ntp_refclock.c b/ntpd/ntp_refclock.c index c048133616..58e948f182 100644 --- a/ntpd/ntp_refclock.c +++ b/ntpd/ntp_refclock.c @@ -1218,8 +1218,8 @@ refclock_ppsapi( if (ap->handle == NULL) { if (time_pps_create(fddev, &ap->handle) < 0) { msyslog(LOG_ERR, - "refclock_atom: time_pps_create failed: %m"); - return (errno); + "refclock_ppsapi: time_pps_create: %m"); + return (0); } } return (1); @@ -1253,8 +1253,8 @@ refclock_params( ap->pps_params.mode = PPS_TSFMT_TSPEC | PPS_CAPTUREASSERT; if (time_pps_setparams(ap->handle, &ap->pps_params) < 0) { msyslog(LOG_ERR, - "refclock_ppsapi: time_pps_setparams failed: %m"); - return (errno); + "refclock_params: time_pps_setparams: %m"); + return (0); } /* @@ -1266,8 +1266,8 @@ refclock_params( PPS_TSFMT_TSPEC) < 0) { if (errno != EOPNOTSUPP) { msyslog(LOG_ERR, - "refclock_ppsapi: time_pps_kcbind failed: %m"); - return (errno); + "refclock_params: time_pps_kcbind: %m"); + return (0); } } pps_enable = 1; @@ -1314,7 +1314,7 @@ refclock_pps( if (time_pps_fetch(ap->handle, PPS_TSFMT_TSPEC, &pps_info, &timeout) < 0) { refclock_report(peer, CEVNT_FAULT); - return (errno); + return (0); } timeout = ap->ts; if (ap->pps_params.mode & PPS_CAPTUREASSERT) diff --git a/util/ntp-keygen.c b/util/ntp-keygen.c index 787cf4d7c2..f6d439082a 100644 --- a/util/ntp-keygen.c +++ b/util/ntp-keygen.c @@ -18,15 +18,17 @@ * MD5 (128-bit) keys used to compute message digests in symmetric * key cryptography * - * ntpkey_RSAkey_. + * ntpkey_RSAhost_. * ntpkey_host_ * RSA private/public host key pair used for public key signatures - * and data encryption * - * ntpkey_DSAkey_. + * ntpkey_RSAsign_. * ntpkey_sign_ - * DSA private/public sign key pair used for public key signatures, - * but not data encryption + * RSA private/public sign key pair used for public key signatures + * + * ntpkey_DSAsign_. + * ntpkey_sign_ + * DSA Private/public sign key pair used for public key signatures * * Available digest/signature schemes * @@ -121,6 +123,7 @@ extern int ntp_getopt (int, char **, const char *); #define MAXHOSTNAME 256 /* max host name length */ #ifdef OPENSSL #define PLEN 512 /* default prime modulus size (bits) */ +#define ILEN 256 /* default identity modulus size (bits) */ #define MVMAX 100 /* max MV parameters */ /* @@ -161,6 +164,7 @@ char *progname; int debug = 0; /* debug, not de bug */ #ifdef OPENSSL u_int modulus = PLEN; /* prime modulus size (bits) */ +u_int modulus2 = ILEN; /* identity modulus size (bits) */ #endif int nkeys; /* MV keys */ time_t epoch; /* Unix epoch (seconds) since 1970 */ @@ -865,7 +869,10 @@ gen_rsa( * Write the RSA parameters and keys as a RSA private key * encoded in PEM. */ - str = fheader("RSAkey", id, hostname); + if (strcmp(id, "sign") == 0) + str = fheader("RSAsign", id, hostname); + else + str = fheader("RSAhost", id, hostname); pkey = EVP_PKEY_new(); EVP_PKEY_assign_RSA(pkey, rsa); PEM_write_PrivateKey(str, pkey, EVP_des_cbc(), NULL, 0, NULL, @@ -889,14 +896,18 @@ gen_dsa( DSA *dsa; /* DSA parameters */ u_char seed[20]; /* seed for parameters */ FILE *str; + int bits; /* * Generate DSA parameters. */ + bits = modulus; + if (bits > 1024) + bits = 1024; fprintf(stderr, - "Generating DSA parameters (%d bits)...\n", modulus); + "Generating DSA parameters (%d bits)...\n", bits); RAND_bytes(seed, sizeof(seed)); - dsa = DSA_generate_parameters(modulus, seed, sizeof(seed), NULL, + dsa = DSA_generate_parameters(bits, seed, sizeof(seed), NULL, NULL, cb, "DSA"); fprintf(stderr, "\n"); if (dsa == NULL) { @@ -920,7 +931,7 @@ gen_dsa( * Write the DSA parameters and keys as a DSA private key * encoded in PEM. */ - str = fheader("DSAkey", id, hostname); + str = fheader("DSAsign", id, hostname); pkey = EVP_PKEY_new(); EVP_PKEY_assign_DSA(pkey, dsa); PEM_write_PrivateKey(str, pkey, EVP_des_cbc(), NULL, 0, NULL, @@ -999,9 +1010,9 @@ gen_iffkey( * Generate DSA parameters for use as IFF parameters. */ fprintf(stderr, "Generating IFF keys (%d bits)...\n", - modulus); + modulus2); RAND_bytes(seed, sizeof(seed)); - dsa = DSA_generate_parameters(modulus, seed, sizeof(seed), NULL, + dsa = DSA_generate_parameters(modulus2, seed, sizeof(seed), NULL, NULL, cb, "IFF"); fprintf(stderr, "\n"); if (dsa == NULL) { @@ -1177,8 +1188,8 @@ gen_gqkey( */ fprintf(stderr, "Generating GQ parameters (%d bits)...\n", - modulus); - rsa = RSA_generate_key(modulus, 3, cb, "GQ"); + modulus2); + rsa = RSA_generate_key(modulus2, 3, cb, "GQ"); fprintf(stderr, "\n"); if (rsa == NULL) { fprintf(stderr, "RSA generate keys fails\n%s\n", @@ -1410,7 +1421,7 @@ gen_mvkey( n = nkeys; fprintf(stderr, "Generating MV parameters for %d keys (%d bits)...\n", n, - modulus / n); + modulus2 / n); ctx = BN_CTX_new(); u = BN_new(); v = BN_new(); w = BN_new(); b = BN_new(); b1 = BN_new(); dsa = DSA_new(); @@ -1420,7 +1431,7 @@ gen_mvkey( for (j = 1; j <= n; j++) { s1[j] = BN_new(); while (1) { - BN_generate_prime(s1[j], modulus / n, 0, NULL, + BN_generate_prime(s1[j], modulus2 / n, 0, NULL, NULL, NULL, NULL); for (i = 1; i < j; i++) { if (BN_cmp(s1[i], s1[j]) == 0) @@ -1460,7 +1471,7 @@ gen_mvkey( temp++; j = temp % n + 1; while (1) { - BN_generate_prime(u, modulus / n, 0, 0, NULL, + BN_generate_prime(u, modulus2 / n, 0, 0, NULL, NULL, NULL); for (i = 1; i <= n; i++) { if (BN_cmp(u, s1[i]) == 0)