]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - usr.sbin/ntp/doc/ntp-keygen.8
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / usr.sbin / ntp / doc / ntp-keygen.8
1 .\"
2 .\" $FreeBSD$
3 .\"
4 .Dd May 17, 2006
5 .Dt NTP-KEYGEN 8
6 .Os
7 .Sh NAME
8 .Nm ntp-keygen
9 .Nd key generation program for ntpd
10 .Sh SYNOPSIS
11 .Nm
12 .Op Fl deGgHIMnPT
13 .Op Fl c Ar scheme
14 .Op Fl i Ar name
15 .Op Fl p Ar password
16 .Op Fl S Op Cm RSA | DSA
17 .Op Fl s Ar name
18 .Op Fl v Ar nkeys
19 .Sh DESCRIPTION
20 This program generates cryptographic data files used by the NTPv4
21 authentication and identification schemes.
22 It generates MD5 key files used in symmetric key cryptography.
23 In addition, if the OpenSSL software library has been installed,
24 it generates keys, certificate and identity files used in public key
25 cryptography.
26 These files are used for cookie encryption,
27 digital signature and challenge/response identification algorithms
28 compatible with the Internet standard security infrastructure.
29 .Pp
30 All files are in PEM-encoded printable ASCII format,
31 so they can be embedded as MIME attachments in mail to other sites
32 and certificate authorities.
33 By default, files are not encrypted.
34 The
35 .Fl p Ar password
36 option specifies the write password and
37 .Fl q Ar password
38 option the read password for previously encrypted files.
39 The
40 .Nm
41 program prompts for the password if it reads an encrypted file
42 and the password is missing or incorrect.
43 If an encrypted file is read successfully and
44 no write password is specified, the read password is used
45 as the write password by default.
46 .Pp
47 The
48 .Xr ntpd 8
49 configuration command
50 .Ic crypto pw Ar password
51 specifies the read password for previously encrypted files.
52 The daemon expires on the spot if the password is missing
53 or incorrect.
54 For convenience, if a file has been previously encrypted,
55 the default read password is the name of the host running
56 the program.
57 If the previous write password is specified as the host name,
58 these files can be read by that host with no explicit password.
59 .Pp
60 File names begin with the prefix
61 .Cm ntpkey_
62 and end with the postfix
63 .Ar _hostname.filestamp ,
64 where
65 .Ar hostname
66 is the owner name, usually the string returned
67 by the Unix gethostname() routine, and
68 .Ar filestamp
69 is the NTP seconds when the file was generated, in decimal digits.
70 This both guarantees uniqueness and simplifies maintenance
71 procedures, since all files can be quickly removed
72 by a
73 .Ic rm ntpkey\&*
74 command or all files generated
75 at a specific time can be removed by a
76 .Ic rm
77 .Ar \&*filestamp
78 command.
79 To further reduce the risk of misconfiguration,
80 the first two lines of a file contain the file name
81 and generation date and time as comments.
82 .Pp
83 All files are installed by default in the keys directory
84 .Pa /usr/local/etc ,
85 which is normally in a shared filesystem
86 in NFS-mounted networks.
87 The actual location of the keys directory
88 and each file can be overridden by configuration commands,
89 but this is not recommended.
90 Normally, the files for each host are generated by that host
91 and used only by that host, although exceptions exist
92 as noted later on this page.
93 .Pp
94 Normally, files containing private values,
95 including the host key, sign key and identification parameters,
96 are permitted root read/write-only;
97 while others containing public values are permitted world readable.
98 Alternatively, files containing private values can be encrypted
99 and these files permitted world readable,
100 which simplifies maintenance in shared file systems.
101 Since uniqueness is insured by the hostname and
102 file name extensions, the files for a NFS server and
103 dependent clients can all be installed in the same shared directory.
104 .Pp
105 The recommended practice is to keep the file name extensions
106 when installing a file and to install a soft link
107 from the generic names specified elsewhere on this page
108 to the generated files.
109 This allows new file generations to be activated simply
110 by changing the link.
111 If a link is present, ntpd follows it to the file name
112 to extract the filestamp.
113 If a link is not present,
114 .Xr ntpd 8
115 extracts the filestamp from the file itself.
116 This allows clients to verify that the file and generation times
117 are always current.
118 The
119 .Nm
120 program uses the same timestamp extension for all files generated
121 at one time, so each generation is distinct and can be readily
122 recognized in monitoring data.
123 .Ss Running the program
124 The safest way to run the
125 .Nm
126 program is logged in directly as root.
127 The recommended procedure is change to the keys directory,
128 usually
129 .Pa /usr/local/etc ,
130 then run the program.
131 When run for the first time,
132 or if all
133 .Cm ntpkey
134 files have been removed,
135 the program generates a RSA host key file and matching RSA-MD5 certificate file,
136 which is all that is necessary in many cases.
137 The program also generates soft links from the generic names
138 to the respective files.
139 If run again, the program uses the same host key file,
140 but generates a new certificate file and link.
141 .Pp
142 The host key is used to encrypt the cookie when required and so must be RSA type.
143 By default, the host key is also the sign key used to encrypt signatures.
144 When necessary, a different sign key can be specified and this can be
145 either RSA or DSA type.
146 By default, the message digest type is MD5, but any combination
147 of sign key type and message digest type supported by the OpenSSL library
148 can be specified, including those using the MD2, MD5, SHA, SHA1, MDC2
149 and RIPE160 message digest algorithms.
150 However, the scheme specified in the certificate must be compatible
151 with the sign key.
152 Certificates using any digest algorithm are compatible with RSA sign keys;
153 however, only SHA and SHA1 certificates are compatible with DSA sign keys.
154 .Pp
155 Private/public key files and certificates are compatible with
156 other OpenSSL applications and very likely other libraries as well.
157 Certificates or certificate requests derived from them should be compatible
158 with extant industry practice, although some users might find
159 the interpretation of X509v3 extension fields somewhat liberal.
160 However, the identification parameter files, although encoded
161 as the other files, are probably not compatible with anything other than Autokey.
162 .Pp
163 Running the program as other than root and using the Unix
164 .Ic su
165 command
166 to assume root may not work properly, since by default the OpenSSL library
167 looks for the random seed file
168 .Cm .rnd
169 in the user home directory.
170 However, there should be only one
171 .Cm .rnd ,
172 most conveniently
173 in the root directory, so it is convenient to define the
174 .Cm $RANDFILE
175 environment variable used by the OpenSSL library as the path to
176 .Cm /.rnd .
177 .Pp
178 Installing the keys as root might not work in NFS-mounted
179 shared file systems, as NFS clients may not be able to write
180 to the shared keys directory, even as root.
181 In this case, NFS clients can specify the files in another
182 directory such as
183 .Pa /etc
184 using the
185 .Ic keysdir
186 command.
187 There is no need for one client to read the keys and certificates
188 of other clients or servers, as these data are obtained automatically
189 by the Autokey protocol.
190 .Pp
191 Ordinarily, cryptographic files are generated by the host that uses them,
192 but it is possible for a trusted agent (TA) to generate these files
193 for other hosts; however, in such cases files should always be encrypted.
194 The subject name and trusted name default to the hostname
195 of the host generating the files, but can be changed by command line options.
196 It is convenient to designate the owner name and trusted name
197 as the subject and issuer fields, respectively, of the certificate.
198 The owner name is also used for the host and sign key files,
199 while the trusted name is used for the identity files.
200 .Ss Trusted Hosts and Groups
201 Each cryptographic configuration involves selection of a signature scheme
202 and identification scheme, called a cryptotype,
203 as explained in the
204 .Sx Authentication Options
205 section of
206 .Xr ntp.conf 5 .
207 The default cryptotype uses RSA encryption, MD5 message digest
208 and TC identification.
209 First, configure a NTP subnet including one or more low-stratum
210 trusted hosts from which all other hosts derive synchronization
211 directly or indirectly.
212 Trusted hosts have trusted certificates;
213 all other hosts have nontrusted certificates.
214 These hosts will automatically and dynamically build authoritative
215 certificate trails to one or more trusted hosts.
216 A trusted group is the set of all hosts that have, directly or indirectly,
217 a certificate trail ending at a trusted host.
218 The trail is defined by static configuration file entries
219 or dynamic means described on the
220 .Sx Automatic NTP Configuration Options
221 section of
222 .Xr ntp.conf 5 .
223 .Pp
224 On each trusted host as root, change to the keys directory.
225 To insure a fresh fileset, remove all
226 .Cm ntpkey
227 files.
228 Then run
229 .Nm
230 .Fl T
231 to generate keys and a trusted certificate.
232 On all other hosts do the same, but leave off the
233 .Fl T
234 flag to generate keys and nontrusted certificates.
235 When complete, start the NTP daemons beginning at the lowest stratum
236 and working up the tree.
237 It may take some time for Autokey to instantiate the certificate trails
238 throughout the subnet, but setting up the environment is completely automatic.
239 .Pp
240 If it is necessary to use a different sign key or different digest/signature
241 scheme than the default, run
242 .Nm
243 with the
244 .Fl S Ar type
245 option, where
246 .Ar type
247 is either
248 .Cm RSA
249 or
250 .Cm DSA .
251 The most often need to do this is when a DSA-signed certificate is used.
252 If it is necessary to use a different certificate scheme than the default,
253 run
254 .Nm
255 with the
256 .Fl c Ar scheme
257 option and selected
258 .Ar scheme
259 as needed.
260 If
261 .Nm
262 is run again without these options, it generates a new certificate
263 using the same scheme and sign key.
264 .Pp
265 After setting up the environment it is advisable to update certificates
266 from time to time, if only to extend the validity interval.
267 Simply run
268 .Nm
269 with the same flags as before to generate new certificates
270 using existing keys.
271 However, if the host or sign key is changed,
272 .Xr ntpd 8
273 should be restarted.
274 When
275 .Xr ntpd 8
276 is restarted, it loads any new files and restarts the protocol.
277 Other dependent hosts will continue as usual until signatures are refreshed,
278 at which time the protocol is restarted.
279 .Ss Identity Schemes
280 As mentioned on the Autonomous Authentication page,
281 the default TC identity scheme is vulnerable to a middleman attack.
282 However, there are more secure identity schemes available,
283 including PC, IFF, GQ and MV described on the
284 .Qq Identification Schemes
285 page
286 (maybe available at
287 .Li http://www.eecis.udel.edu/%7emills/keygen.html ) .
288 These schemes are based on a TA, one or more trusted hosts
289 and some number of nontrusted hosts.
290 Trusted hosts prove identity using values provided by the TA,
291 while the remaining hosts prove identity using values provided
292 by a trusted host and certificate trails that end on that host.
293 The name of a trusted host is also the name of its sugroup
294 and also the subject and issuer name on its trusted certificate.
295 The TA is not necessarily a trusted host in this sense, but often is.
296 .Pp
297 In some schemes there are separate keys for servers and clients.
298 A server can also be a client of another server,
299 but a client can never be a server for another client.
300 In general, trusted hosts and nontrusted hosts that operate
301 as both server and client have parameter files that contain
302 both server and client keys.
303 Hosts that operate
304 only as clients have key files that contain only client keys.
305 .Pp
306 The PC scheme supports only one trusted host in the group.
307 On trusted host alice run
308 .Nm
309 .Fl P
310 .Fl p Ar password
311 to generate the host key file
312 .Pa ntpkey_RSAkey_ Ns Ar alice.filestamp
313 and trusted private certificate file
314 .Pa ntpkey_RSA-MD5_cert_ Ns Ar alice.filestamp .
315 Copy both files to all group hosts;
316 they replace the files which would be generated in other schemes.
317 On each host bob install a soft link from the generic name
318 .Pa ntpkey_host_ Ns Ar bob
319 to the host key file and soft link
320 .Pa ntpkey_cert_ Ns Ar bob
321 to the private certificate file.
322 Note the generic links are on bob, but point to files generated
323 by trusted host alice.
324 In this scheme it is not possible to refresh
325 either the keys or certificates without copying them
326 to all other hosts in the group.
327 .Pp
328 For the IFF scheme proceed as in the TC scheme to generate keys
329 and certificates for all group hosts, then for every trusted host in the group,
330 generate the IFF parameter file.
331 On trusted host alice run
332 .Nm
333 .Fl T
334 .Fl I
335 .Fl p Ar password
336 to produce her parameter file
337 .Pa ntpkey_IFFpar_ Ns Ar alice.filestamp ,
338 which includes both server and client keys.
339 Copy this file to all group hosts that operate as both servers
340 and clients and install a soft link from the generic
341 .Pa ntpkey_iff_ Ns Ar alice
342 to this file.
343 If there are no hosts restricted to operate only as clients,
344 there is nothing further to do.
345 As the IFF scheme is independent
346 of keys and certificates, these files can be refreshed as needed.
347 .Pp
348 If a rogue client has the parameter file, it could masquerade
349 as a legitimate server and present a middleman threat.
350 To eliminate this threat, the client keys can be extracted
351 from the parameter file and distributed to all restricted clients.
352 After generating the parameter file, on alice run
353 .Nm
354 .Fl e
355 and pipe the output to a file or mail program.
356 Copy or mail this file to all restricted clients.
357 On these clients install a soft link from the generic
358 .Pa ntpkey_iff_ Ns Ar alice
359 to this file.
360 To further protect the integrity of the keys,
361 each file can be encrypted with a secret password.
362 .Pp
363 For the GQ scheme proceed as in the TC scheme to generate keys
364 and certificates for all group hosts, then for every trusted host
365 in the group, generate the IFF parameter file.
366 On trusted host alice run
367 .Nm
368 .Fl T
369 .Fl G
370 .Fl p Ar password
371 to produce her parameter file
372 .Pa ntpkey_GQpar_ Ns Ar alice.filestamp ,
373 which includes both server and client keys.
374 Copy this file to all group hosts and install a soft link
375 from the generic
376 .Pa ntpkey_gq_ Ns Ar alice
377 to this file.
378 In addition, on each host bob install a soft link
379 from generic
380 .Pa ntpkey_gq_ Ns Ar bob
381 to this file.
382 As the GQ scheme updates the GQ parameters file and certificate
383 at the same time, keys and certificates can be regenerated as needed.
384 .Pp
385 For the MV scheme, proceed as in the TC scheme to generate keys
386 and certificates for all group hosts.
387 For illustration assume trish is the TA, alice one of several trusted hosts
388 and bob one of her clients.
389 On TA trish run
390 .Nm
391 .Fl V Ar n
392 .Fl p Ar password ,
393 where
394 .Ar n
395 is the number of revokable keys (typically 5) to produce
396 the parameter file
397 .Pa ntpkeys_MVpar_ Ns Ar trish.filestamp
398 and client key files
399 .Pa ntpkeys_MVkeyd_ Ns Ar trish.filestamp
400 where
401 .Ar d
402 is the key number (0 \&<
403 .Ar d
404 \&<
405 .Ar n ) .
406 Copy the parameter file to alice and install a soft link
407 from the generic
408 .Pa ntpkey_mv_ Ns Ar alice
409 to this file.
410 Copy one of the client key files to alice for later distribution
411 to her clients.
412 It doesn't matter which client key file goes to alice,
413 since they all work the same way.
414 Alice copies the client key file to all of her cliens.
415 On client bob install a soft link from generic
416 .Pa ntpkey_mvkey_ Ns Ar bob
417 to the client key file.
418 As the MV scheme is independent of keys and certificates,
419 these files can be refreshed as needed.
420 .Ss Command Line Options
421 .Bl -tag -width indent
422 .It Fl c Ar scheme
423 Select certificate message digest/signature encryption scheme.
424 The
425 .Ar scheme
426 can be one of the following:
427 . Cm RSA-MD2 , RSA-MD5 , RSA-SHA , RSA-SHA1 , RSA-MDC2 , RSA-RIPEMD160 , DSA-SHA ,
428 or
429 .Cm DSA-SHA1 .
430 Note that RSA schemes must be used with a RSA sign key and DSA
431 schemes must be used with a DSA sign key.
432 The default without this option is
433 .Cm RSA-MD5 .
434 .It Fl d
435 Enable debugging.
436 This option displays the cryptographic data produced in eye-friendly billboards.
437 .It Fl e
438 Write the IFF client keys to the standard output.
439 This is intended for automatic key distribution by mail.
440 .It Fl G
441 Generate parameters and keys for the GQ identification scheme,
442 obsoleting any that may exist.
443 .It Fl g
444 Generate keys for the GQ identification scheme
445 using the existing GQ parameters.
446 If the GQ parameters do not yet exist, create them first.
447 .It Fl H
448 Generate new host keys, obsoleting any that may exist.
449 .It Fl I
450 Generate parameters for the IFF identification scheme,
451 obsoleting any that may exist.
452 .It Fl i Ar name
453 Set the suject name to
454 .Ar name .
455 This is used as the subject field in certificates
456 and in the file name for host and sign keys.
457 .It Fl M
458 Generate MD5 keys, obsoleting any that may exist.
459 .It Fl P
460 Generate a private certificate.
461 By default, the program generates public certificates.
462 .It Fl p Ar password
463 Encrypt generated files containing private data with
464 .Ar password
465 and the DES-CBC algorithm.
466 .It Fl q
467 Set the password for reading files to password.
468 .It Fl S Oo Cm RSA | DSA Oc
469 Generate a new sign key of the designated type,
470 obsoleting any that may exist.
471 By default, the program uses the host key as the sign key.
472 .It Fl s Ar name
473 Set the issuer name to
474 .Ar name .
475 This is used for the issuer field in certificates
476 and in the file name for identity files.
477 .It Fl T
478 Generate a trusted certificate.
479 By default, the program generates a non-trusted certificate.
480 .It Fl V Ar nkeys
481 Generate parameters and keys for the Mu-Varadharajan (MV) identification scheme.
482 .El
483 .Ss Random Seed File
484 All cryptographically sound key generation schemes must have means
485 to randomize the entropy seed used to initialize
486 the internal pseudo-random number generator used
487 by the library routines.
488 The OpenSSL library uses a designated random seed file for this purpose.
489 The file must be available when starting the NTP daemon and
490 .Nm
491 program.
492 If a site supports OpenSSL or its companion OpenSSH,
493 it is very likely that means to do this are already available.
494 .Pp
495 It is important to understand that entropy must be evolved
496 for each generation, for otherwise the random number sequence
497 would be predictable.
498 Various means dependent on external events, such as keystroke intervals,
499 can be used to do this and some systems have built-in entropy sources.
500 Suitable means are described in the OpenSSL software documentation,
501 but are outside the scope of this page.
502 .Pp
503 The entropy seed used by the OpenSSL library is contained in a file,
504 usually called
505 .Cm .rnd ,
506 which must be available when starting the NTP daemon
507 or the
508 .Nm
509 program.
510 The NTP daemon will first look for the file
511 using the path specified by the
512 .Ic randfile
513 subcommand of the
514 .Ic crypto
515 configuration command.
516 If not specified in this way, or when starting the
517 .Nm
518 program,
519 the OpenSSL library will look for the file using the path specified
520 by the
521 .Ev RANDFILE
522 environment variable in the user home directory,
523 whether root or some other user.
524 If the
525 .Ev RANDFILE
526 environment variable is not present,
527 the library will look for the
528 .Cm .rnd
529 file in the user home directory.
530 If the file is not available or cannot be written,
531 the daemon exits with a message to the system log and the program
532 exits with a suitable error message.
533 .Ss Cryptographic Data Files
534 All other file formats begin with two lines.
535 The first contains the file name, including the generated host name
536 and filestamp.
537 The second contains the datestamp in conventional Unix date format.
538 Lines beginning with # are considered comments and ignored by the
539 .Nm
540 program and
541 .Xr ntpd 8
542 daemon.
543 Cryptographic values are encoded first using ASN.1 rules,
544 then encrypted if necessary, and finally written PEM-encoded
545 printable ASCII format preceded and followed by MIME content identifier lines.
546 .Pp
547 The format of the symmetric keys file is somewhat different
548 than the other files in the interest of backward compatibility.
549 Since DES-CBC is deprecated in NTPv4, the only key format of interest
550 is MD5 alphanumeric strings.
551 Following hte heard the keys are
552 entered one per line in the format
553 .D1 Ar keyno type key
554 where
555 .Ar keyno
556 is a positive integer in the range 1-65,535,
557 .Ar type
558 is the string MD5 defining the key format and
559 .Ar key
560 is the key itself,
561 which is a printable ASCII string 16 characters or less in length.
562 Each character is chosen from the 93 printable characters
563 in the range 0x21 through 0x7f excluding space and the
564 .Ql #
565 character.
566 .Pp
567 Note that the keys used by the
568 .Xr ntpq 8
569 and
570 .Xr ntpdc 8
571 programs
572 are checked against passwords requested by the programs
573 and entered by hand, so it is generally appropriate to specify these keys
574 in human readable ASCII format.
575 .Pp
576 The
577 .Nm
578 program generates a MD5 symmetric keys file
579 .Pa ntpkey_MD5key_ Ns Ar hostname.filestamp .
580 Since the file contains private shared keys,
581 it should be visible only to root and distributed by secure means
582 to other subnet hosts.
583 The NTP daemon loads the file
584 .Pa ntp.keys ,
585 so
586 .Nm
587 installs a soft link from this name to the generated file.
588 Subsequently, similar soft links must be installed by manual
589 or automated means on the other subnet hosts.
590 While this file is not used with the Autokey Version 2 protocol,
591 it is needed to authenticate some remote configuration commands
592 used by the
593 .Xr ntpq 8
594 and
595 .Xr ntpdc 8
596 utilities.
597 .Sh Bugs
598 It can take quite a while to generate some cryptographic values,
599 from one to several minutes with modern architectures
600 such as UltraSPARC and up to tens of minutes to an hour
601 with older architectures such as SPARC IPC.