1.Dd August 14 2018 2.Dt NTP_KEYGEN 8 User Commands 3.Os 4.\" EDIT THIS FILE WITH CAUTION (ntp-keygen-opts.mdoc) 5.\" 6.\" $FreeBSD$ 7.\" 8.\" It has been AutoGen-ed August 14, 2018 at 08:30:38 AM by AutoGen 5.18.5 9.\" From the definitions ntp-keygen-opts.def 10.\" and the template file agmdoc-cmd.tpl 11.Sh NAME 12.Nm ntp-keygen 13.Nd Create a NTP host key 14.Sh SYNOPSIS 15.Nm 16.\" Mixture of short (flag) options and long options 17.Op Fl flags 18.Op Fl flag Op Ar value 19.Op Fl \-option\-name Ns Oo Oo Ns "=| " Oc Ns Ar value Oc 20.Pp 21All arguments must be options. 22.Pp 23.Sh DESCRIPTION 24This program generates cryptographic data files used by the NTPv4 25authentication and identification schemes. 26It can generate message digest keys used in symmetric key cryptography and, 27if the OpenSSL software library has been installed, it can generate host keys, 28signing keys, certificates, and identity keys and parameters used in Autokey 29public key cryptography. 30These files are used for cookie encryption, 31digital signature, and challenge/response identification algorithms 32compatible with the Internet standard security infrastructure. 33.Pp 34The message digest symmetric keys file is generated in a format 35compatible with NTPv3. 36All other files are in PEM\-encoded printable ASCII format, 37so they can be embedded as MIME attachments in email to other sites 38and certificate authorities. 39By default, files are not encrypted. 40.Pp 41When used to generate message digest symmetric keys, the program 42produces a file containing ten pseudo\-random printable ASCII strings 43suitable for the MD5 message digest algorithm included in the 44distribution. 45If the OpenSSL library is installed, it produces an additional ten 46hex\-encoded random bit strings suitable for SHA1, AES\-128\-CMAC, and 47other message digest algorithms. 48The message digest symmetric keys file must be distributed and stored 49using secure means beyond the scope of NTP itself. 50Besides the keys used for ordinary NTP associations, additional keys 51can be defined as passwords for the 52.Xr ntpq 8 53and 54.Xr ntpdc 8 55utility programs. 56.Pp 57The remaining generated files are compatible with other OpenSSL 58applications and other Public Key Infrastructure (PKI) resources. 59Certificates generated by this program are compatible with extant 60industry practice, although some users might find the interpretation of 61X509v3 extension fields somewhat liberal. 62However, the identity keys are probably not compatible with anything 63other than Autokey. 64.Pp 65Some files used by this program are encrypted using a private password. 66The 67.Fl p 68option specifies the read password for local encrypted files and the 69.Fl q 70option the write password for encrypted files sent to remote sites. 71If no password is specified, the host name returned by the Unix 72.Xr hostname 1 73command, normally the DNS name of the host, is used as the the default read 74password, for convenience. 75The 76.Nm 77program prompts for the password if it reads an encrypted file 78and the password is missing or incorrect. 79If an encrypted file is read successfully and 80no write password is specified, the read password is used 81as the write password by default. 82.Pp 83The 84.Cm pw 85option of the 86.Ic crypto 87.Xr ntpd 8 88configuration command specifies the read 89password for previously encrypted local files. 90This must match the local read password used by this program. 91If not specified, the host name is used. 92Thus, if files are generated by this program without an explicit password, 93they can be read back by 94.Xr ntpd 8 95without specifying an explicit password but only on the same host. 96If the write password used for encryption is specified as the host name, 97these files can be read by that host with no explicit password. 98.Pp 99Normally, encrypted files for each host are generated by that host and 100used only by that host, although exceptions exist as noted later on 101this page. 102The symmetric keys file, normally called 103.Pa ntp.keys , 104is usually installed in 105.Pa /etc . 106Other files and links are usually installed in 107.Pa /usr/local/etc , 108which is normally in a shared filesystem in 109NFS\-mounted networks and cannot be changed by shared clients. 110In these cases, NFS clients can specify the files in another 111directory such as 112.Pa /etc 113using the 114.Ic keysdir 115.Xr ntpd 8 116configuration file command. 117.Pp 118This program directs commentary and error messages to the standard 119error stream 120.Pa stderr 121and remote files to the standard output stream 122.Pa stdout 123where they can be piped to other applications or redirected to files. 124The names used for generated files and links all begin with the 125string 126.Pa ntpkey\&* 127and include the file type, generating host and filestamp, 128as described in the 129.Sx "Cryptographic Data Files" 130section below. 131.Ss Running the Program 132The safest way to run the 133.Nm 134program is logged in directly as root. 135The recommended procedure is change to the 136.Ar keys 137directory, usually 138.Pa /usr/local/etc , 139then run the program. 140.Pp 141To test and gain experience with Autokey concepts, log in as root and 142change to the 143.Ar keys 144directory, usually 145.Pa /usr/local/etc . 146When run for the first time, or if all files with names beginning with 147.Pa ntpkey\&* 148have been removed, use the 149.Nm 150command without arguments to generate a default 151.Cm RSA 152host key and matching 153.Cm RSA\-MD5 154certificate file with expiration date one year hence, 155which is all that is necessary in many cases. 156The program also generates soft links from the generic names 157to the respective files. 158If run again without options, the program uses the 159existing keys and parameters and generates a new certificate file with 160new expiration date one year hence, and soft link. 161.Pp 162The host key is used to encrypt the cookie when required and so must be 163.Cm RSA 164type. 165By default, the host key is also the sign key used to encrypt signatures. 166When necessary, a different sign key can be specified and this can be 167either 168.Cm RSA 169or 170.Cm DSA 171type. 172By default, the message digest type is 173.Cm MD5 , 174but any combination 175of sign key type and message digest type supported by the OpenSSL library 176can be specified, including those using the 177.Cm AES128CMAC , MD2 , MD5 , MDC2 , SHA , SHA1 178and 179.Cm RIPE160 180message digest algorithms. 181However, the scheme specified in the certificate must be compatible 182with the sign key. 183Certificates using any digest algorithm are compatible with 184.Cm RSA 185sign keys; 186however, only 187.Cm SHA 188and 189.Cm SHA1 190certificates are compatible with 191.Cm DSA 192sign keys. 193.Pp 194Private/public key files and certificates are compatible with 195other OpenSSL applications and very likely other libraries as well. 196Certificates or certificate requests derived from them should be compatible 197with extant industry practice, although some users might find 198the interpretation of X509v3 extension fields somewhat liberal. 199However, the identification parameter files, although encoded 200as the other files, are probably not compatible with anything other than Autokey. 201.Pp 202Running the program as other than root and using the Unix 203.Xr su 1 204command 205to assume root may not work properly, since by default the OpenSSL library 206looks for the random seed file 207.Pa .rnd 208in the user home directory. 209However, there should be only one 210.Pa .rnd , 211most conveniently 212in the root directory, so it is convenient to define the 213.Ev RANDFILE 214environment variable used by the OpenSSL library as the path to 215.Pa .rnd . 216.Pp 217Installing the keys as root might not work in NFS\-mounted 218shared file systems, as NFS clients may not be able to write 219to the shared keys directory, even as root. 220In this case, NFS clients can specify the files in another 221directory such as 222.Pa /etc 223using the 224.Ic keysdir 225.Xr ntpd 8 226configuration file command. 227There is no need for one client to read the keys and certificates 228of other clients or servers, as these data are obtained automatically 229by the Autokey protocol. 230.Pp 231Ordinarily, cryptographic files are generated by the host that uses them, 232but it is possible for a trusted agent (TA) to generate these files 233for other hosts; however, in such cases files should always be encrypted. 234The subject name and trusted name default to the hostname 235of the host generating the files, but can be changed by command line options. 236It is convenient to designate the owner name and trusted name 237as the subject and issuer fields, respectively, of the certificate. 238The owner name is also used for the host and sign key files, 239while the trusted name is used for the identity files. 240.Pp 241All files are installed by default in the keys directory 242.Pa /usr/local/etc , 243which is normally in a shared filesystem 244in NFS\-mounted networks. 245The actual location of the keys directory 246and each file can be overridden by configuration commands, 247but this is not recommended. 248Normally, the files for each host are generated by that host 249and used only by that host, although exceptions exist 250as noted later on this page. 251.Pp 252Normally, files containing private values, 253including the host key, sign key and identification parameters, 254are permitted root read/write\-only; 255while others containing public values are permitted world readable. 256Alternatively, files containing private values can be encrypted 257and these files permitted world readable, 258which simplifies maintenance in shared file systems. 259Since uniqueness is insured by the 260.Ar hostname 261and 262.Ar filestamp 263file name extensions, the files for an NTP server and 264dependent clients can all be installed in the same shared directory. 265.Pp 266The recommended practice is to keep the file name extensions 267when installing a file and to install a soft link 268from the generic names specified elsewhere on this page 269to the generated files. 270This allows new file generations to be activated simply 271by changing the link. 272If a link is present, 273.Xr ntpd 8 274follows it to the file name to extract the 275.Ar filestamp . 276If a link is not present, 277.Xr ntpd 8 278extracts the 279.Ar filestamp 280from the file itself. 281This allows clients to verify that the file and generation times 282are always current. 283The 284.Nm 285program uses the same 286.Ar filestamp 287extension for all files generated 288at one time, so each generation is distinct and can be readily 289recognized in monitoring data. 290.Pp 291Run the command on as many hosts as necessary. 292Designate one of them as the trusted host (TH) using 293.Nm 294with the 295.Fl T 296option and configure it to synchronize from reliable Internet servers. 297Then configure the other hosts to synchronize to the TH directly or 298indirectly. 299A certificate trail is created when Autokey asks the immediately 300ascendant host towards the TH to sign its certificate, which is then 301provided to the immediately descendant host on request. 302All group hosts should have acyclic certificate trails ending on the TH. 303.Pp 304The host key is used to encrypt the cookie when required and so must be 305RSA type. 306By default, the host key is also the sign key used to encrypt 307signatures. 308A different sign key can be assigned using the 309.Fl S 310option and this can be either 311.Cm RSA 312or 313.Cm DSA 314type. 315By default, the signature 316message digest type is 317.Cm MD5 , 318but any combination of sign key type and 319message digest type supported by the OpenSSL library can be specified 320using the 321.Fl c 322option. 323.Pp 324The rules say cryptographic media should be generated with proventic 325filestamps, which means the host should already be synchronized before 326this program is run. 327This of course creates a chicken\-and\-egg problem 328when the host is started for the first time. 329Accordingly, the host time 330should be set by some other means, such as eyeball\-and\-wristwatch, at 331least so that the certificate lifetime is within the current year. 332After that and when the host is synchronized to a proventic source, the 333certificate should be re\-generated. 334.Pp 335Additional information on trusted groups and identity schemes is on the 336.Dq Autokey Public\-Key Authentication 337page. 338.Pp 339File names begin with the prefix 340.Pa ntpkey Ns _ 341and end with the suffix 342.Pa _ Ns Ar hostname . Ar filestamp , 343where 344.Ar hostname 345is the owner name, usually the string returned 346by the Unix 347.Xr hostname 1 348command, and 349.Ar filestamp 350is the NTP seconds when the file was generated, in decimal digits. 351This both guarantees uniqueness and simplifies maintenance 352procedures, since all files can be quickly removed 353by a 354.Ic rm Pa ntpkey\&* 355command or all files generated 356at a specific time can be removed by a 357.Ic rm Pa \&* Ns Ar filestamp 358command. 359To further reduce the risk of misconfiguration, 360the first two lines of a file contain the file name 361and generation date and time as comments. 362.Ss Trusted Hosts and Groups 363Each cryptographic configuration involves selection of a signature scheme 364and identification scheme, called a cryptotype, 365as explained in the 366.Sx Authentication Options 367section of 368.Xr ntp.conf 5 . 369The default cryptotype uses 370.Cm RSA 371encryption, 372.Cm MD5 373message digest 374and 375.Cm TC 376identification. 377First, configure a NTP subnet including one or more low\-stratum 378trusted hosts from which all other hosts derive synchronization 379directly or indirectly. 380Trusted hosts have trusted certificates; 381all other hosts have nontrusted certificates. 382These hosts will automatically and dynamically build authoritative 383certificate trails to one or more trusted hosts. 384A trusted group is the set of all hosts that have, directly or indirectly, 385a certificate trail ending at a trusted host. 386The trail is defined by static configuration file entries 387or dynamic means described on the 388.Sx Automatic NTP Configuration Options 389section of 390.Xr ntp.conf 5 . 391.Pp 392On each trusted host as root, change to the keys directory. 393To insure a fresh fileset, remove all 394.Pa ntpkey 395files. 396Then run 397.Nm 398.Fl T 399to generate keys and a trusted certificate. 400On all other hosts do the same, but leave off the 401.Fl T 402flag to generate keys and nontrusted certificates. 403When complete, start the NTP daemons beginning at the lowest stratum 404and working up the tree. 405It may take some time for Autokey to instantiate the certificate trails 406throughout the subnet, but setting up the environment is completely automatic. 407.Pp 408If it is necessary to use a different sign key or different digest/signature 409scheme than the default, run 410.Nm 411with the 412.Fl S Ar type 413option, where 414.Ar type 415is either 416.Cm RSA 417or 418.Cm DSA . 419The most frequent need to do this is when a 420.Cm DSA Ns \-signed 421certificate is used. 422If it is necessary to use a different certificate scheme than the default, 423run 424.Nm 425with the 426.Fl c Ar scheme 427option and selected 428.Ar scheme 429as needed. 430If 431.Nm 432is run again without these options, it generates a new certificate 433using the same scheme and sign key, and soft link. 434.Pp 435After setting up the environment it is advisable to update certificates 436from time to time, if only to extend the validity interval. 437Simply run 438.Nm 439with the same flags as before to generate new certificates 440using existing keys, and soft links. 441However, if the host or sign key is changed, 442.Xr ntpd 8 443should be restarted. 444When 445.Xr ntpd 8 446is restarted, it loads any new files and restarts the protocol. 447Other dependent hosts will continue as usual until signatures are refreshed, 448at which time the protocol is restarted. 449.Ss Identity Schemes 450As mentioned on the Autonomous Authentication page, 451the default 452.Cm TC 453identity scheme is vulnerable to a middleman attack. 454However, there are more secure identity schemes available, 455including 456.Cm PC , IFF , GQ 457and 458.Cm MV 459schemes described below. 460These schemes are based on a TA, one or more trusted hosts 461and some number of nontrusted hosts. 462Trusted hosts prove identity using values provided by the TA, 463while the remaining hosts prove identity using values provided 464by a trusted host and certificate trails that end on that host. 465The name of a trusted host is also the name of its sugroup 466and also the subject and issuer name on its trusted certificate. 467The TA is not necessarily a trusted host in this sense, but often is. 468.Pp 469In some schemes there are separate keys for servers and clients. 470A server can also be a client of another server, 471but a client can never be a server for another client. 472In general, trusted hosts and nontrusted hosts that operate 473as both server and client have parameter files that contain 474both server and client keys. 475Hosts that operate 476only as clients have key files that contain only client keys. 477.Pp 478The PC scheme supports only one trusted host in the group. 479On trusted host alice run 480.Nm 481.Fl P 482.Fl p Ar password 483to generate the host key file 484.Pa ntpkey Ns _ Cm RSA Pa key_alice. Ar filestamp 485and trusted private certificate file 486.Pa ntpkey Ns _ Cm RSA\-MD5 _ Pa cert_alice. Ar filestamp , 487and soft links. 488Copy both files to all group hosts; 489they replace the files which would be generated in other schemes. 490On each host 491.Ar bob 492install a soft link from the generic name 493.Pa ntpkey_host_ Ns Ar bob 494to the host key file and soft link 495.Pa ntpkey_cert_ Ns Ar bob 496to the private certificate file. 497Note the generic links are on bob, but point to files generated 498by trusted host alice. 499In this scheme it is not possible to refresh 500either the keys or certificates without copying them 501to all other hosts in the group, and recreating the soft links. 502.Pp 503For the 504.Cm IFF 505scheme proceed as in the 506.Cm TC 507scheme to generate keys 508and certificates for all group hosts, then for every trusted host in the group, 509generate the 510.Cm IFF 511parameter file. 512On trusted host alice run 513.Nm 514.Fl T 515.Fl I 516.Fl p Ar password 517to produce her parameter file 518.Pa ntpkey_IFFpar_alice. Ns Ar filestamp , 519which includes both server and client keys. 520Copy this file to all group hosts that operate as both servers 521and clients and install a soft link from the generic 522.Pa ntpkey_iff_alice 523to this file. 524If there are no hosts restricted to operate only as clients, 525there is nothing further to do. 526As the 527.Cm IFF 528scheme is independent 529of keys and certificates, these files can be refreshed as needed. 530.Pp 531If a rogue client has the parameter file, it could masquerade 532as a legitimate server and present a middleman threat. 533To eliminate this threat, the client keys can be extracted 534from the parameter file and distributed to all restricted clients. 535After generating the parameter file, on alice run 536.Nm 537.Fl e 538and pipe the output to a file or email program. 539Copy or email this file to all restricted clients. 540On these clients install a soft link from the generic 541.Pa ntpkey_iff_alice 542to this file. 543To further protect the integrity of the keys, 544each file can be encrypted with a secret password. 545.Pp 546For the 547.Cm GQ 548scheme proceed as in the 549.Cm TC 550scheme to generate keys 551and certificates for all group hosts, then for every trusted host 552in the group, generate the 553.Cm IFF 554parameter file. 555On trusted host alice run 556.Nm 557.Fl T 558.Fl G 559.Fl p Ar password 560to produce her parameter file 561.Pa ntpkey_GQpar_alice. Ns Ar filestamp , 562which includes both server and client keys. 563Copy this file to all group hosts and install a soft link 564from the generic 565.Pa ntpkey_gq_alice 566to this file. 567In addition, on each host 568.Ar bob 569install a soft link 570from generic 571.Pa ntpkey_gq_ Ns Ar bob 572to this file. 573As the 574.Cm GQ 575scheme updates the 576.Cm GQ 577parameters file and certificate 578at the same time, keys and certificates can be regenerated as needed. 579.Pp 580For the 581.Cm MV 582scheme, proceed as in the 583.Cm TC 584scheme to generate keys 585and certificates for all group hosts. 586For illustration assume trish is the TA, alice one of several trusted hosts 587and bob one of her clients. 588On TA trish run 589.Nm 590.Fl V Ar n 591.Fl p Ar password , 592where 593.Ar n 594is the number of revokable keys (typically 5) to produce 595the parameter file 596.Pa ntpkeys_MVpar_trish. Ns Ar filestamp 597and client key files 598.Pa ntpkeys_MVkey Ns Ar d _ Pa trish. Ar filestamp 599where 600.Ar d 601is the key number (0 \&< 602.Ar d 603\&< 604.Ar n ) . 605Copy the parameter file to alice and install a soft link 606from the generic 607.Pa ntpkey_mv_alice 608to this file. 609Copy one of the client key files to alice for later distribution 610to her clients. 611It does not matter which client key file goes to alice, 612since they all work the same way. 613Alice copies the client key file to all of her clients. 614On client bob install a soft link from generic 615.Pa ntpkey_mvkey_bob 616to the client key file. 617As the 618.Cm MV 619scheme is independent of keys and certificates, 620these files can be refreshed as needed. 621.Ss Command Line Options 622.Bl -tag -width indent 623.It Fl b Fl \-imbits Ns = Ar modulus 624Set the number of bits in the identity modulus for generating identity keys to 625.Ar modulus 626bits. 627The number of bits in the identity modulus defaults to 256, but can be set to 628values from 256 to 2048 (32 to 256 octets). 629Use the larger moduli with caution, as this can consume considerable computing 630resources and increases the size of authenticated packets. 631.It Fl c Fl \-certificate Ns = Ar scheme 632Select certificate signature encryption/message digest scheme. 633The 634.Ar scheme 635can be one of the following: 636.Cm RSA\-MD2 , RSA\-MD5 , RSA\-MDC2 , RSA\-SHA , RSA\-SHA1 , RSA\-RIPEMD160 , DSA\-SHA , 637or 638.Cm DSA\-SHA1 . 639Note that 640.Cm RSA 641schemes must be used with an 642.Cm RSA 643sign key and 644.Cm DSA 645schemes must be used with a 646.Cm DSA 647sign key. 648The default without this option is 649.Cm RSA\-MD5 . 650If compatibility with FIPS 140\-2 is required, either the 651.Cm DSA\-SHA 652or 653.Cm DSA\-SHA1 654scheme must be used. 655.It Fl C Fl \-cipher Ns = Ar cipher 656Select the OpenSSL cipher to encrypt the files containing private keys. 657The default without this option is three\-key triple DES in CBC mode, 658.Cm des\-ede3\-cbc . 659The 660.Ic openssl Fl h 661command provided with OpenSSL displays available ciphers. 662.It Fl d Fl \-debug\-level 663Increase debugging verbosity level. 664This option displays the cryptographic data produced in eye\-friendly billboards. 665.It Fl D Fl \-set\-debug\-level Ns = Ar level 666Set the debugging verbosity to 667.Ar level . 668This option displays the cryptographic data produced in eye\-friendly billboards. 669.It Fl e Fl \-id\-key 670Write the 671.Cm IFF 672or 673.Cm GQ 674public parameters from the 675.Ar IFFkey or GQkey 676client keys file previously specified 677as unencrypted data to the standard output stream 678.Pa stdout . 679This is intended for automatic key distribution by email. 680.It Fl G Fl \-gq\-params 681Generate a new encrypted 682.Cm GQ 683parameters and key file for the Guillou\-Quisquater (GQ) identity scheme. 684This option is mutually exclusive with the 685.Fl I 686and 687.Fl V 688options. 689.It Fl H Fl \-host\-key 690Generate a new encrypted 691.Cm RSA 692public/private host key file. 693.It Fl I Fl \-iffkey 694Generate a new encrypted 695.Cm IFF 696key file for the Schnorr (IFF) identity scheme. 697This option is mutually exclusive with the 698.Fl G 699and 700Fl V 701options. 702.It Fl i Fl \-ident Ns = Ar group 703Set the optional Autokey group name to 704.Ar group . 705This is used in the identity scheme parameter file names of 706.Cm IFF , GQ , 707and 708.Cm MV 709client parameters files. 710In that role, the default is the host name if no group is provided. 711The group name, if specified using 712.Fl i 713or 714.Fl s 715following an 716.Ql @ 717character, is also used in certificate subject and issuer names in the form 718.Ar host @ group 719and should match the group specified via 720.Ic crypto Cm ident 721or 722.Ic server Cm ident 723in the ntpd configuration file. 724.It Fl l Fl \-lifetime Ns = Ar days 725Set the lifetime for certificate expiration to 726.Ar days . 727The default lifetime is one year (365 days). 728.It Fl m Fl \-modulus Ns = Ar bits 729Set the number of bits in the prime modulus for generating files to 730.Ar bits . 731The modulus defaults to 512, but can be set from 256 to 2048 (32 to 256 octets). 732Use the larger moduli with caution, as this can consume considerable computing 733resources and increases the size of authenticated packets. 734.It Fl M Fl \-md5key 735Generate a new symmetric keys file containing 10 736.Cm MD5 737keys, and if OpenSSL is available, 10 738.Cm SHA 739keys. 740An 741.Cm MD5 742key is a string of 20 random printable ASCII characters, while a 743.Cm SHA 744key is a string of 40 random hex digits. 745The file can be edited using a text editor to change the key type or key content. 746This option is mutually exclusive with all other options. 747.It Fl p Fl \-password Ns = Ar passwd 748Set the password for reading and writing encrypted files to 749.Ar passwd . 750These include the host, sign and identify key files. 751By default, the password is the string returned by the Unix 752.Ic hostname 753command. 754.It Fl P Fl \-pvt\-cert 755Generate a new private certificate used by the 756.Cm PC 757identity scheme. 758By default, the program generates public certificates. 759Note: the PC identity scheme is not recommended for new installations. 760.It Fl q Fl \-export\-passwd Ns = Ar passwd 761Set the password for writing encrypted 762.Cm IFF , GQ and MV 763identity files redirected to 764.Pa stdout 765to 766.Ar passwd . 767In effect, these files are decrypted with the 768.Fl p 769password, then encrypted with the 770.Fl q 771password. 772By default, the password is the string returned by the Unix 773.Ic hostname 774command. 775.It Fl s Fl \-subject\-key Ns = Ar Oo host Oc Op @ Ar group 776Specify the Autokey host name, where 777.Ar host 778is the optional host name and 779.Ar group 780is the optional group name. 781The host name, and if provided, group name are used in 782.Ar host @ group 783form as certificate subject and issuer. 784Specifying 785.Fl s @ Ar group 786is allowed, and results in leaving the host name unchanged, as with 787.Fl i Ar group . 788The group name, or if no group is provided, the host name are also used in the 789file names of 790.Cm IFF , GQ , 791and 792.Cm MV 793identity scheme client parameter files. 794If 795.Ar host 796is not specified, the default host name is the string returned by the Unix 797.Ic hostname 798command. 799.It Fl S Fl \-sign\-key Ns = Op Cm RSA | DSA 800Generate a new encrypted public/private sign key file of the specified type. 801By default, the sign key is the host key and has the same type. 802If compatibility with FIPS 140\-2 is required, the sign key type must be 803.Cm DSA . 804.It Fl T Fl \-trusted\-cert 805Generate a trusted certificate. 806By default, the program generates a non\-trusted certificate. 807.It Fl V Fl \-mv\-params Ar nkeys 808Generate 809.Ar nkeys 810encrypted server keys and parameters for the Mu\-Varadharajan (MV) 811identity scheme. 812This option is mutually exclusive with the 813.Fl I 814and 815.Fl G 816options. 817Note: support for this option should be considered a work in progress. 818.El 819.Ss Random Seed File 820All cryptographically sound key generation schemes must have means 821to randomize the entropy seed used to initialize 822the internal pseudo\-random number generator used 823by the library routines. 824The OpenSSL library uses a designated random seed file for this purpose. 825The file must be available when starting the NTP daemon and 826.Nm 827program. 828If a site supports OpenSSL or its companion OpenSSH, 829it is very likely that means to do this are already available. 830.Pp 831It is important to understand that entropy must be evolved 832for each generation, for otherwise the random number sequence 833would be predictable. 834Various means dependent on external events, such as keystroke intervals, 835can be used to do this and some systems have built\-in entropy sources. 836Suitable means are described in the OpenSSL software documentation, 837but are outside the scope of this page. 838.Pp 839The entropy seed used by the OpenSSL library is contained in a file, 840usually called 841.Pa .rnd , 842which must be available when starting the NTP daemon 843or the 844.Nm 845program. 846The NTP daemon will first look for the file 847using the path specified by the 848.Cm randfile 849subcommand of the 850.Ic crypto 851configuration command. 852If not specified in this way, or when starting the 853.Nm 854program, 855the OpenSSL library will look for the file using the path specified 856by the 857.Ev RANDFILE 858environment variable in the user home directory, 859whether root or some other user. 860If the 861.Ev RANDFILE 862environment variable is not present, 863the library will look for the 864.Pa .rnd 865file in the user home directory. 866Since both the 867.Nm 868program and 869.Xr ntpd 8 870daemon must run as root, the logical place to put this file is in 871.Pa /.rnd 872or 873.Pa /root/.rnd . 874If the file is not available or cannot be written, 875the daemon exits with a message to the system log and the program 876exits with a suitable error message. 877.Ss Cryptographic Data Files 878All file formats begin with two nonencrypted lines. 879The first line contains the file name, including the generated host name 880and filestamp, in the format 881.Pa ntpkey_ Ns Ar key _ Ar name . Ar filestamp , 882where 883.Ar key 884is the key or parameter type, 885.Ar name 886is the host or group name and 887.Ar filestamp 888is the filestamp (NTP seconds) when the file was created. 889By convention, 890.Ar key 891names in generated file names include both upper and lower case 892characters, while 893.Ar key 894names in generated link names include only lower case characters. 895The filestamp is not used in generated link names. 896The second line contains the datestamp in conventional Unix 897.Pa date 898format. 899Lines beginning with 900.Ql # 901are considered comments and ignored by the 902.Nm 903program and 904.Xr ntpd 8 905daemon. 906.Pp 907The remainder of the file contains cryptographic data, encoded first using ASN.1 908rules, then encrypted if necessary, and finally written in PEM\-encoded 909printable ASCII text, preceded and followed by MIME content identifier lines. 910.Pp 911The format of the symmetric keys file, ordinarily named 912.Pa ntp.keys , 913is somewhat different than the other files in the interest of backward compatibility. 914Ordinarily, the file is generated by this program, but it can be constructed 915and edited using an ordinary text editor. 916.Bd -literal -unfilled -offset center 917# ntpkey_MD5key_bk.ntp.org.3595864945 918# Thu Dec 12 19:22:25 2013 9191 MD5 L";Nw<\`.I<f4U0)247"i # MD5 key 9202 MD5 &>l0%XXK9O'51VwV<xq~ # MD5 key 9213 MD5 lb4zLW~d^!K:]RsD'qb6 # MD5 key 9224 MD5 Yue:tL[+vR)M\`n~bY,'? # MD5 key 9235 MD5 B;fx'Kgr/&4ZTbL6=RxA # MD5 key 9246 MD5 4eYwa\`o}3i@@V@..R9!l # MD5 key 9257 MD5 \`A.([h+;wTQ|xfi%Sn_! # MD5 key 9268 MD5 45:V,r4]l6y^JH6"Sh?F # MD5 key 9279 MD5 3\-5vcn*6l29DS?Xdsg)* # MD5 key 92810 MD5 2late4Me # MD5 key 92911 SHA1 a27872d3030a9025b8446c751b4551a7629af65c # SHA1 key 93012 SHA1 21bc3b4865dbb9e920902abdccb3e04ff97a5e74 # SHA1 key 93113 SHA1 2b7736fe24fef5ba85ae11594132ab5d6f6daba9 # SHA1 key 93214 SHA a5332809c8878dd3a5b918819108a111509aeceb # SHA key 93315 MD2 2fe16c88c760ff2f16d4267e36c1aa6c926e6964 # MD2 key 93416 MD4 b2691811dc19cfc0e2f9bcacd74213f29812183d # MD4 key 93517 MD5 e4d6735b8bdad58ec5ffcb087300a17f7fef1f7c # MD5 key 93618 MDC2 a8d5e2315c025bf3a79174c87fbd10477de2eabc # MDC2 key 93719 RIPEMD160 77ca332cafb30e3cafb174dcd5b80ded7ba9b3d2 # RIPEMD160 key 93820 AES128CMAC f92ff73eee86c1e7dc638d6489a04e4e555af878 # AES128CMAC key 939.Ed 940.D1 Figure 1. Typical Symmetric Key File 941.Pp 942Figure 1 shows a typical symmetric keys file used by the reference 943implementation. 944Following the header the keys are entered one per line in the format 945.D1 Ar keyno Ar type Ar key 946where 947.Ar keyno 948is a positive integer in the range 1\-65535; 949.Ar type 950is the key type for the message digest algorithm, which in the absence of the 951OpenSSL library must be 952.Cm MD5 953to designate the MD5 message digest algorithm; 954if the OpenSSL library is installed, the key type can be any 955message digest algorithm supported by that library; 956however, if compatibility with FIPS 140\-2 is required, 957the key type must be either 958.Cm SHA 959or 960.Cm SHA1 ; 961.Ar key 962is the key itself, 963which is a printable ASCII string 20 characters or less in length: 964each character is chosen from the 93 printable characters 965in the range 0x21 through 0x7e ( 966.Ql ! 967through 968.Ql ~ 969\&) excluding space and the 970.Ql # 971character, and terminated by whitespace or a 972.Ql # 973character. 974An OpenSSL key consists of a hex\-encoded ASCII string of 40 characters, which 975is truncated as necessary. 976.Pp 977Note that the keys used by the 978.Xr ntpq 8 979and 980.Xr ntpdc 8 981programs 982are checked against passwords requested by the programs 983and entered by hand, so it is generally appropriate to specify these keys 984in human readable ASCII format. 985.Pp 986The 987.Nm 988program generates a symmetric keys file 989.Pa ntpkey_MD5key_ Ns Ar hostname Ns . Ns Ar filestamp . 990Since the file contains private shared keys, 991it should be visible only to root and distributed by secure means 992to other subnet hosts. 993The NTP daemon loads the file 994.Pa ntp.keys , 995so 996.Nm 997installs a soft link from this name to the generated file. 998Subsequently, similar soft links must be installed by manual 999or automated means on the other subnet hosts. 1000While this file is not used with the Autokey Version 2 protocol, 1001it is needed to authenticate some remote configuration commands 1002used by the 1003.Xr ntpq 8 1004and 1005.Xr ntpdc 8 1006utilities. 1007.Sh "OPTIONS" 1008.Bl -tag 1009.It Fl b Ar imbits , Fl \-imbits Ns = Ns Ar imbits 1010identity modulus bits. 1011This option takes an integer number as its argument. 1012The value of 1013.Ar imbits 1014is constrained to being: 1015.in +4 1016.nf 1017.na 1018in the range 256 through 2048 1019.fi 1020.in -4 1021.sp 1022The number of bits in the identity modulus. The default is 256. 1023.It Fl c Ar scheme , Fl \-certificate Ns = Ns Ar scheme 1024certificate scheme. 1025.sp 1026scheme is one of 1027RSA\-MD2, RSA\-MD5, RSA\-MDC2, RSA\-SHA, RSA\-SHA1, RSA\-RIPEMD160, 1028DSA\-SHA, or DSA\-SHA1. 1029.sp 1030Select the certificate signature encryption/message digest scheme. 1031Note that RSA schemes must be used with a RSA sign key and DSA 1032schemes must be used with a DSA sign key. The default without 1033this option is RSA\-MD5. 1034.It Fl C Ar cipher , Fl \-cipher Ns = Ns Ar cipher 1035privatekey cipher. 1036.sp 1037Select the cipher which is used to encrypt the files containing 1038private keys. The default is three\-key triple DES in CBC mode, 1039equivalent to "\fB\-C des\-ede3\-cbc\fP". The openssl tool lists ciphers 1040available in "\fBopenssl \-h\fP" output. 1041.It Fl d , Fl \-debug\-level 1042Increase debug verbosity level. 1043This option may appear an unlimited number of times. 1044.sp 1045.It Fl D Ar number , Fl \-set\-debug\-level Ns = Ns Ar number 1046Set the debug verbosity level. 1047This option may appear an unlimited number of times. 1048This option takes an integer number as its argument. 1049.sp 1050.It Fl e , Fl \-id\-key 1051Write IFF or GQ identity keys. 1052.sp 1053Write the public parameters from the IFF or GQ client keys to 1054the standard output. 1055This is intended for automatic key distribution by email. 1056.It Fl G , Fl \-gq\-params 1057Generate GQ parameters and keys. 1058.sp 1059Generate parameters and keys for the GQ identification scheme, 1060obsoleting any that may exist. 1061.It Fl H , Fl \-host\-key 1062generate RSA host key. 1063.sp 1064Generate new host keys, obsoleting any that may exist. 1065.It Fl I , Fl \-iffkey 1066generate IFF parameters. 1067.sp 1068Generate parameters for the IFF identification scheme, obsoleting 1069any that may exist. 1070.It Fl i Ar group , Fl \-ident Ns = Ns Ar group 1071set Autokey group name. 1072.sp 1073Set the optional Autokey group name to name. This is used in 1074the file name of IFF, GQ, and MV client parameters files. In 1075that role, the default is the host name if this option is not 1076provided. The group name, if specified using \fB\-i/\-\-ident\fP or 1077using \fB\-s/\-\-subject\-name\fP following an '\fB@\fP' character, 1078is also a part of the self\-signed host certificate subject and 1079issuer names in the form \fBhost@group\fP and should match the 1080\'\fBcrypto ident\fP' or '\fBserver ident\fP' configuration in the 1081\fBntpd\fP configuration file. 1082.It Fl l Ar lifetime , Fl \-lifetime Ns = Ns Ar lifetime 1083set certificate lifetime. 1084This option takes an integer number as its argument. 1085.sp 1086Set the certificate expiration to lifetime days from now. 1087.It Fl m Ar modulus , Fl \-modulus Ns = Ns Ar modulus 1088prime modulus. 1089This option takes an integer number as its argument. 1090The value of 1091.Ar modulus 1092is constrained to being: 1093.in +4 1094.nf 1095.na 1096in the range 256 through 2048 1097.fi 1098.in -4 1099.sp 1100The number of bits in the prime modulus. The default is 512. 1101.It Fl M , Fl \-md5key 1102generate symmetric keys. 1103.sp 1104Generate symmetric keys, obsoleting any that may exist. 1105.It Fl P , Fl \-pvt\-cert 1106generate PC private certificate. 1107.sp 1108Generate a private certificate. By default, the program generates 1109public certificates. 1110.It Fl p Ar passwd , Fl \-password Ns = Ns Ar passwd 1111local private password. 1112.sp 1113Local files containing private data are encrypted with the 1114DES\-CBC algorithm and the specified password. The same password 1115must be specified to the local ntpd via the "crypto pw password" 1116configuration command. The default password is the local 1117hostname. 1118.It Fl q Ar passwd , Fl \-export\-passwd Ns = Ns Ar passwd 1119export IFF or GQ group keys with password. 1120.sp 1121Export IFF or GQ identity group keys to the standard output, 1122encrypted with the DES\-CBC algorithm and the specified password. 1123The same password must be specified to the remote ntpd via the 1124"crypto pw password" configuration command. See also the option 1125-\-id\-key (\-e) for unencrypted exports. 1126.It Fl s Ar host@group , Fl \-subject\-name Ns = Ns Ar host@group 1127set host and optionally group name. 1128.sp 1129Set the Autokey host name, and optionally, group name specified 1130following an '\fB@\fP' character. The host name is used in the file 1131name of generated host and signing certificates, without the 1132group name. The host name, and if provided, group name are used 1133in \fBhost@group\fP form for the host certificate subject and issuer 1134fields. Specifying '\fB\-s @group\fP' is allowed, and results in 1135leaving the host name unchanged while appending \fB@group\fP to the 1136subject and issuer fields, as with \fB\-i group\fP. The group name, or 1137if not provided, the host name are also used in the file names 1138of IFF, GQ, and MV client parameter files. 1139.It Fl S Ar sign , Fl \-sign\-key Ns = Ns Ar sign 1140generate sign key (RSA or DSA). 1141.sp 1142Generate a new sign key of the designated type, obsoleting any 1143that may exist. By default, the program uses the host key as the 1144sign key. 1145.It Fl T , Fl \-trusted\-cert 1146trusted certificate (TC scheme). 1147.sp 1148Generate a trusted certificate. By default, the program generates 1149a non\-trusted certificate. 1150.It Fl V Ar num , Fl \-mv\-params Ns = Ns Ar num 1151generate <num> MV parameters. 1152This option takes an integer number as its argument. 1153.sp 1154Generate parameters and keys for the Mu\-Varadharajan (MV) 1155identification scheme. 1156.It Fl v Ar num , Fl \-mv\-keys Ns = Ns Ar num 1157update <num> MV keys. 1158This option takes an integer number as its argument. 1159.sp 1160This option has not been fully documented. 1161.It Fl \&? , Fl \-help 1162Display usage information and exit. 1163.It Fl \&! , Fl \-more\-help 1164Pass the extended usage information through a pager. 1165.It Fl > Oo Ar cfgfile Oc , Fl \-save\-opts Oo Ns = Ns Ar cfgfile Oc 1166Save the option state to \fIcfgfile\fP. The default is the \fIlast\fP 1167configuration file listed in the \fBOPTION PRESETS\fP section, below. 1168The command will exit after updating the config file. 1169.It Fl < Ar cfgfile , Fl \-load\-opts Ns = Ns Ar cfgfile , Fl \-no\-load\-opts 1170Load options from \fIcfgfile\fP. 1171The \fIno\-load\-opts\fP form will disable the loading 1172of earlier config/rc/ini files. \fI\-\-no\-load\-opts\fP is handled early, 1173out of order. 1174.It Fl \-version Op Brq Ar v|c|n 1175Output version of program and exit. The default mode is `v', a simple 1176version. The `c' mode will print copyright information and `n' will 1177print the full copyright notice. 1178.El 1179.Sh "OPTION PRESETS" 1180Any option that is not marked as \fInot presettable\fP may be preset 1181by loading values from configuration ("RC" or ".INI") file(s) and values from 1182environment variables named: 1183.nf 1184 \fBNTP_KEYGEN_<option\-name>\fP or \fBNTP_KEYGEN\fP 1185.fi 1186.ad 1187The environmental presets take precedence (are processed later than) 1188the configuration files. 1189The \fIhomerc\fP files are "\fI$HOME\fP", and "\fI.\fP". 1190If any of these are directories, then the file \fI.ntprc\fP 1191is searched for within those directories. 1192.Sh USAGE 1193.Sh "ENVIRONMENT" 1194See \fBOPTION PRESETS\fP for configuration environment variables. 1195.Sh "FILES" 1196See \fBOPTION PRESETS\fP for configuration files. 1197.Sh "EXIT STATUS" 1198One of the following exit values will be returned: 1199.Bl -tag 1200.It 0 " (EXIT_SUCCESS)" 1201Successful program execution. 1202.It 1 " (EXIT_FAILURE)" 1203The operation failed or the command syntax was not valid. 1204.It 66 " (EX_NOINPUT)" 1205A specified configuration file could not be loaded. 1206.It 70 " (EX_SOFTWARE)" 1207libopts had an internal operational error. Please report 1208it to autogen\-users@lists.sourceforge.net. Thank you. 1209.El 1210.Sh "AUTHORS" 1211The University of Delaware and Network Time Foundation 1212.Sh "COPYRIGHT" 1213Copyright (C) 1992\-2017 The University of Delaware and Network Time Foundation all rights reserved. 1214This program is released under the terms of the NTP license, <http://ntp.org/license>. 1215.Sh BUGS 1216It can take quite a while to generate some cryptographic values. 1217.Pp 1218Please report bugs to http://bugs.ntp.org . 1219.Pp 1220Please send bug reports to: http://bugs.ntp.org, bugs@ntp.org 1221.Sh NOTES 1222Portions of this document came from FreeBSD. 1223.Pp 1224This manual page was \fIAutoGen\fP\-erated from the \fBntp\-keygen\fP 1225option definitions. 1226