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