]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - usr.sbin/ntp/doc/ntp-keygen.8
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.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 .Pp
201 .Ss Trusted Hosts and Groups
202 Each cryptographic configuration involves selection of a signature scheme
203 and identification scheme, called a cryptotype,
204 as explained in the
205 .Sx Authentication Options
206 section of
207 .Xr ntp.conf 5 .
208 The default cryptotype uses RSA encryption, MD5 message digest
209 and TC identification.
210 First, configure a NTP subnet including one or more low-stratum
211 trusted hosts from which all other hosts derive synchronization
212 directly or indirectly.
213 Trusted hosts have trusted certificates;
214 all other hosts have nontrusted certificates.
215 These hosts will automatically and dynamically build authoritative
216 certificate trails to one or more trusted hosts.
217 A trusted group is the set of all hosts that have, directly or indirectly,
218 a certificate trail ending at a trusted host.
219 The trail is defined by static configuration file entries
220 or dynamic means described on the
221 .Sx Automatic NTP Configuration Options
222 section of
223 .Xr ntp.conf 5 .
224 .Pp
225 On each trusted host as root, change to the keys directory.
226 To insure a fresh fileset, remove all
227 .Cm ntpkey
228 files.
229 Then run
230 .Nm
231 .Fl T
232 to generate keys and a trusted certificate.
233 On all other hosts do the same, but leave off the
234 .Fl T
235 flag to generate keys and nontrusted certificates.
236 When complete, start the NTP daemons beginning at the lowest stratum
237 and working up the tree.
238 It may take some time for Autokey to instantiate the certificate trails
239 throughout the subnet, but setting up the environment is completely automatic.
240 .Pp
241 If it is necessary to use a different sign key or different digest/signature
242 scheme than the default, run
243 .Nm
244 with the
245 .Fl S Ar type
246 option, where
247 .Ar type
248 is either
249 .Cm RSA
250 or
251 .Cm DSA .
252 The most often need to do this is when a DSA-signed certificate is used.
253 If it is necessary to use a different certificate scheme than the default,
254 run
255 .Nm
256 with the
257 .Fl c Ar scheme
258 option and selected
259 .Ar scheme
260 as needed.
261 If
262 .Nm
263 is run again without these options, it generates a new certificate
264 using the same scheme and sign key.
265 .Pp
266 After setting up the environment it is advisable to update certificates
267 from time to time, if only to extend the validity interval.
268 Simply run
269 .Nm
270 with the same flags as before to generate new certificates
271 using existing keys.
272 However, if the host or sign key is changed,
273 .Xr ntpd 8
274 should be restarted.
275 When
276 .Xr ntpd 8
277 is restarted, it loads any new files and restarts the protocol.
278 Other dependent hosts will continue as usual until signatures are refreshed,
279 at which time the protocol is restarted.
280 .Ss Identity Schemes
281 As mentioned on the Autonomous Authentication page,
282 the default TC identity scheme is vulnerable to a middleman attack.
283 However, there are more secure identity schemes available,
284 including PC, IFF, GQ and MV described on the
285 .Qq Identification Schemes
286 page
287 (maybe available at
288 .Li http://www.eecis.udel.edu/%7emills/keygen.html ) .
289 These schemes are based on a TA, one or more trusted hosts
290 and some number of nontrusted hosts.
291 Trusted hosts prove identity using values provided by the TA,
292 while the remaining hosts prove identity using values provided
293 by a trusted host and certificate trails that end on that host.
294 The name of a trusted host is also the name of its sugroup
295 and also the subject and issuer name on its trusted certificate.
296 The TA is not necessarily a trusted host in this sense, but often is.
297 .Pp
298 In some schemes there are separate keys for servers and clients.
299 A server can also be a client of another server,
300 but a client can never be a server for another client.
301 In general, trusted hosts and nontrusted hosts that operate
302 as both server and client have parameter files that contain
303 both server and client keys.
304 Hosts that operate
305 only as clients have key files that contain only client keys.
306 .Pp
307 The PC scheme supports only one trusted host in the group.
308 On trusted host alice run
309 .Nm
310 .Fl P
311 .Fl p Ar password
312 to generate the host key file
313 .Pa ntpkey_RSAkey_ Ns Ar alice.filestamp
314 and trusted private certificate file
315 .Pa ntpkey_RSA-MD5_cert_ Ns Ar alice.filestamp .
316 Copy both files to all group hosts;
317 they replace the files which would be generated in other schemes.
318 On each host bob install a soft link from the generic name
319 .Pa ntpkey_host_ Ns Ar bob
320 to the host key file and soft link
321 .Pa ntpkey_cert_ Ns Ar bob
322 to the private certificate file.
323 Note the generic links are on bob, but point to files generated
324 by trusted host alice.
325 In this scheme it is not possible to refresh
326 either the keys or certificates without copying them
327 to all other hosts in the group.
328 .Pp
329 For the IFF scheme proceed as in the TC scheme to generate keys
330 and certificates for all group hosts, then for every trusted host in the group,
331 generate the IFF parameter file.
332 On trusted host alice run
333 .Nm
334 .Fl T
335 .Fl I
336 .Fl p Ar password
337 to produce her parameter file
338 .Pa ntpkey_IFFpar_ Ns Ar alice.filestamp ,
339 which includes both server and client keys.
340 Copy this file to all group hosts that operate as both servers
341 and clients and install a soft link from the generic
342 .Pa ntpkey_iff_ Ns Ar alice
343 to this file.
344 If there are no hosts restricted to operate only as clients,
345 there is nothing further to do.
346 As the IFF scheme is independent
347 of keys and certificates, these files can be refreshed as needed.
348 .Pp
349 If a rogue client has the parameter file, it could masquerade
350 as a legitimate server and present a middleman threat.
351 To eliminate this threat, the client keys can be extracted
352 from the parameter file and distributed to all restricted clients.
353 After generating the parameter file, on alice run
354 .Nm
355 .Fl e
356 and pipe the output to a file or mail program.
357 Copy or mail this file to all restricted clients.
358 On these clients install a soft link from the generic
359 .Pa ntpkey_iff_ Ns Ar alice
360 to this file.
361 To further protect the integrity of the keys,
362 each file can be encrypted with a secret password.
363 .Pp
364 For the GQ scheme proceed as in the TC scheme to generate keys
365 and certificates for all group hosts, then for every trusted host
366 in the group, generate the IFF parameter file.
367 On trusted host alice run
368 .Nm
369 .Fl T
370 .Fl G
371 .Fl p Ar password
372 to produce her parameter file
373 .Pa ntpkey_GQpar_ Ns Ar alice.filestamp ,
374 which includes both server and client keys.
375 Copy this file to all group hosts and install a soft link
376 from the generic
377 .Pa ntpkey_gq_ Ns Ar alice
378 to this file.
379 In addition, on each host bob install a soft link
380 from generic
381 .Pa ntpkey_gq_ Ns Ar bob
382 to this file.
383 As the GQ scheme updates the GQ parameters file and certificate
384 at the same time, keys and certificates can be regenerated as needed.
385 .Pp
386 For the MV scheme, proceed as in the TC scheme to generate keys
387 and certificates for all group hosts.
388 For illustration assume trish is the TA, alice one of several trusted hosts
389 and bob one of her clients.
390 On TA trish run
391 .Nm
392 .Fl V Ar n
393 .Fl p Ar password ,
394 where
395 .Ar n
396 is the number of revokable keys (typically 5) to produce
397 the parameter file
398 .Pa ntpkeys_MVpar_ Ns Ar trish.filestamp
399 and client key files
400 .Pa ntpkeys_MVkeyd_ Ns Ar trish.filestamp
401 where
402 .Ar d
403 is the key number (0 \&<
404 .Ar d
405 \&<
406 .Ar n ) .
407 Copy the parameter file to alice and install a soft link
408 from the generic
409 .Pa ntpkey_mv_ Ns Ar alice
410 to this file.
411 Copy one of the client key files to alice for later distribution
412 to her clients.
413 It doesn't matter which client key file goes to alice,
414 since they all work the same way.
415 Alice copies the client key file to all of her cliens.
416 On client bob install a soft link from generic
417 .Pa ntpkey_mvkey_ Ns Ar bob
418 to the client key file.
419 As the MV scheme is independent of keys and certificates,
420 these files can be refreshed as needed.
421 .Ss Command Line Options
422 .Bl -tag -width indent
423 .It Fl c Ar scheme
424 Select certificate message digest/signature encryption scheme.
425 The
426 .Ar scheme
427 can be one of the following:
428 . Cm RSA-MD2 , RSA-MD5 , RSA-SHA , RSA-SHA1 , RSA-MDC2 , RSA-RIPEMD160 , DSA-SHA ,
429 or
430 .Cm DSA-SHA1 .
431 Note that RSA schemes must be used with a RSA sign key and DSA
432 schemes must be used with a DSA sign key.
433 The default without this option is
434 .Cm RSA-MD5 .
435 .It Fl d
436 Enable debugging.
437 This option displays the cryptographic data produced in eye-friendly billboards.
438 .It Fl e
439 Write the IFF client keys to the standard output.
440 This is intended for automatic key distribution by mail.
441 .It Fl G
442 Generate parameters and keys for the GQ identification scheme,
443 obsoleting any that may exist.
444 .It Fl g
445 Generate keys for the GQ identification scheme
446 using the existing GQ parameters.
447 If the GQ parameters do not yet exist, create them first.
448 .It Fl H
449 Generate new host keys, obsoleting any that may exist.
450 .It Fl I
451 Generate parameters for the IFF identification scheme,
452 obsoleting any that may exist.
453 .It Fl i Ar name
454 Set the suject name to
455 .Ar name .
456 This is used as the subject field in certificates
457 and in the file name for host and sign keys.
458 .It Fl M
459 Generate MD5 keys, obsoleting any that may exist.
460 .It Fl P
461 Generate a private certificate.
462 By default, the program generates public certificates.
463 .It Fl p Ar password
464 Encrypt generated files containing private data with
465 .Ar password
466 and the DES-CBC algorithm.
467 .It Fl q
468 Set the password for reading files to password.
469 .It Fl S Oo Cm RSA | DSA Oc
470 Generate a new sign key of the designated type,
471 obsoleting any that may exist.
472 By default, the program uses the host key as the sign key.
473 .It Fl s Ar name
474 Set the issuer name to
475 .Ar name .
476 This is used for the issuer field in certificates
477 and in the file name for identity files.
478 .It Fl T
479 Generate a trusted certificate.
480 By default, the program generates a non-trusted certificate.
481 .It Fl V Ar nkeys
482 Generate parameters and keys for the Mu-Varadharajan (MV) identification scheme.
483 .El
484 .Ss Random Seed File
485 All cryptographically sound key generation schemes must have means
486 to randomize the entropy seed used to initialize
487 the internal pseudo-random number generator used
488 by the library routines.
489 The OpenSSL library uses a designated random seed file for this purpose.
490 The file must be available when starting the NTP daemon and
491 .Nm
492 program.
493 If a site supports OpenSSL or its companion OpenSSH,
494 it is very likely that means to do this are already available.
495 .Pp
496 It is important to understand that entropy must be evolved
497 for each generation, for otherwise the random number sequence
498 would be predictable.
499 Various means dependent on external events, such as keystroke intervals,
500 can be used to do this and some systems have built-in entropy sources.
501 Suitable means are described in the OpenSSL software documentation,
502 but are outside the scope of this page.
503 .Pp
504 The entropy seed used by the OpenSSL library is contained in a file,
505 usually called
506 .Cm .rnd ,
507 which must be available when starting the NTP daemon
508 or the
509 .Nm
510 program.
511 The NTP daemon will first look for the file
512 using the path specified by the
513 .Ic randfile
514 subcommand of the
515 .Ic crypto
516 configuration command.
517 If not specified in this way, or when starting the
518 .Nm
519 program,
520 the OpenSSL library will look for the file using the path specified
521 by the
522 .Ev RANDFILE
523 environment variable in the user home directory,
524 whether root or some other user.
525 If the
526 .Ev RANDFILE
527 environment variable is not present,
528 the library will look for the
529 .Cm .rnd
530 file in the user home directory.
531 If the file is not available or cannot be written,
532 the daemon exits with a message to the system log and the program
533 exits with a suitable error message.
534 .Ss Cryptographic Data Files
535 All other file formats begin with two lines.
536 The first contains the file name, including the generated host name
537 and filestamp.
538 The second contains the datestamp in conventional Unix date format.
539 Lines beginning with # are considered comments and ignored by the
540 .Nm
541 program and
542 .Xr ntpd 8
543 daemon.
544 Cryptographic values are encoded first using ASN.1 rules,
545 then encrypted if necessary, and finally written PEM-encoded
546 printable ASCII format preceded and followed by MIME content identifier lines.
547 .Pp
548 The format of the symmetric keys file is somewhat different
549 than the other files in the interest of backward compatibility.
550 Since DES-CBC is deprecated in NTPv4, the only key format of interest
551 is MD5 alphanumeric strings.
552 Following hte heard the keys are
553 entered one per line in the format
554 .D1 Ar keyno type key
555 where
556 .Ar keyno
557 is a positive integer in the range 1-65,535,
558 .Ar type
559 is the string MD5 defining the key format and
560 .Ar key
561 is the key itself,
562 which is a printable ASCII string 16 characters or less in length.
563 Each character is chosen from the 93 printable characters
564 in the range 0x21 through 0x7f excluding space and the
565 .Ql #
566 character.
567 .Pp
568 Note that the keys used by the
569 .Xr ntpq 8
570 and
571 .Xr ntpdc 8
572 programs
573 are checked against passwords requested by the programs
574 and entered by hand, so it is generally appropriate to specify these keys
575 in human readable ASCII format.
576 .Pp
577 The
578 .Nm
579 program generates a MD5 symmetric keys file
580 .Pa ntpkey_MD5key_ Ns Ar hostname.filestamp .
581 Since the file contains private shared keys,
582 it should be visible only to root and distributed by secure means
583 to other subnet hosts.
584 The NTP daemon loads the file
585 .Pa ntp.keys ,
586 so
587 .Nm
588 installs a soft link from this name to the generated file.
589 Subsequently, similar soft links must be installed by manual
590 or automated means on the other subnet hosts.
591 While this file is not used with the Autokey Version 2 protocol,
592 it is needed to authenticate some remote configuration commands
593 used by the
594 .Xr ntpq 8
595 and
596 .Xr ntpdc 8
597 utilities.
598 .Sh Bugs
599 It can take quite a while to generate some cryptographic values,
600 from one to several minutes with modern architectures
601 such as UltraSPARC and up to tens of minutes to an hour
602 with older architectures such as SPARC IPC.