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