ntp-keygen.mdoc.in revision 293650
1193326Sed.Dd January 7 2016
2193326Sed.Dt NTP_KEYGEN @NTP_KEYGEN_MS@ User Commands
3353358Sdim.Os
4353358Sdim.\"  EDIT THIS FILE WITH CAUTION  (ntp-keygen-opts.mdoc)
5353358Sdim.\"
6193326Sed.\"  It has been AutoGen-ed  January  7, 2016 at 11:32:43 PM by AutoGen 5.18.5
7193326Sed.\"  From the definitions    ntp-keygen-opts.def
8193326Sed.\"  and the template file   agmdoc-cmd.tpl
9193326Sed.Sh NAME
10193326Sed.Nm ntp-keygen
11193326Sed.Nd Create a NTP host key
12193326Sed.Sh SYNOPSIS
13193326Sed.Nm
14193326Sed.\" Mixture of short (flag) options and long options
15280031Sdim.Op Fl flags
16280031Sdim.Op Fl flag Op Ar value
17193326Sed.Op Fl \-option\-name Ns Oo Oo Ns "=| " Oc Ns Ar value Oc
18193326Sed.Pp
19341825SdimAll arguments must be options.
20193326Sed.Pp
21249423Sdim.Sh DESCRIPTION
22249423SdimThis program generates cryptographic data files used by the NTPv4
23193326Sedauthentication and identification schemes.
24193326SedIt generates MD5 key files used in symmetric key cryptography.
25193326SedIn addition, if the OpenSSL software library has been installed,
26193326Sedit generates keys, certificate and identity files used in public key
27193326Sedcryptography.
28193326SedThese files are used for cookie encryption,
29193326Seddigital signature and challenge/response identification algorithms
30193326Sedcompatible with the Internet standard security infrastructure.
31193326Sed.Pp
32193326SedAll files are in PEM\-encoded printable ASCII format,
33193326Sedso they can be embedded as MIME attachments in mail to other sites
34193326Sedand certificate authorities.
35193326SedBy default, files are not encrypted.
36193326Sed.Pp
37193326SedWhen used to generate message digest keys, the program produces a file
38193326Sedcontaining ten pseudo\-random printable ASCII strings suitable for the
39193326SedMD5 message digest algorithm included in the distribution.
40193326SedIf the OpenSSL library is installed, it produces an additional ten
41193326Sedhex\-encoded random bit strings suitable for the SHA1 and other message
42193326Seddigest algorithms.
43193326SedThe message digest keys file must be distributed and stored
44193326Sedusing secure means beyond the scope of NTP itself.
45193326SedBesides the keys used for ordinary NTP associations, additional keys
46193326Sedcan be defined as passwords for the
47193326Sed.Xr ntpq @NTPQ_MS@
48193326Sedand
49193326Sed.Xr ntpdc @NTPDC_MS@
50193326Sedutility programs.
51193326Sed.Pp
52193326SedThe remaining generated files are compatible with other OpenSSL
53212904Sdimapplications and other Public Key Infrastructure (PKI) resources.
54193326SedCertificates generated by this program are compatible with extant
55193326Sedindustry practice, although some users might find the interpretation of
56193326SedX509v3 extension fields somewhat liberal.
57218893SdimHowever, the identity keys are probably not compatible with anything
58193326Sedother than Autokey.
59193326Sed.Pp
60193326SedSome files used by this program are encrypted using a private password.
61193326SedThe
62193326Sed.Fl p
63193326Sedoption specifies the password for local encrypted files and the
64206275Srdivacky.Fl q
65234353Sdimoption the password for encrypted files sent to remote sites.
66234353SdimIf no password is specified, the host name returned by the Unix
67234353Sdim.Fn gethostname
68193326Sedfunction, normally the DNS name of the host is used.
69193326Sed.Pp
70193326SedThe
71193326Sed.Ar pw
72193326Sedoption of the
73193326Sed.Ar crypto
74193326Sedconfiguration command specifies the read
75193326Sedpassword for previously encrypted local files.
76193326SedThis must match the local password used by this program.
77193326SedIf not specified, the host name is used.
78193326SedThus, if files are generated by this program without password,
79193326Sedthey can be read back by
80193326Sed.Ar ntpd
81193326Sedwithout password but only on the same host.
82193326Sed.Pp
83193326SedNormally, encrypted files for each host are generated by that host and
84193326Sedused only by that host, although exceptions exist as noted later on
85193326Sedthis page.
86193326SedThe symmetric keys file, normally called
87193326Sed.Ar ntp.keys ,
88193326Sedis usually installed in
89193326Sed.Pa /etc .
90198092SrdivackyOther files and links are usually installed in
91221345Sdim.Pa /usr/local/etc ,
92221345Sdimwhich is normally in a shared filesystem in
93239462SdimNFS\-mounted networks and cannot be changed by shared clients.
94239462SdimThe location of the keys directory can be changed by the
95239462Sdim.Ar keysdir
96239462Sdimconfiguration command in such cases.
97239462SdimNormally, this is in
98353358Sdim.Pa /etc .
99353358Sdim.Pp
100353358SdimThis program directs commentary and error messages to the standard
101353358Sdimerror stream
102296417Sdim.Ar stderr
103296417Sdimand remote files to the standard output stream
104296417Sdim.Ar stdout
105296417Sdimwhere they can be piped to other applications or redirected to files.
106239462SdimThe names used for generated files and links all begin with the
107239462Sdimstring
108239462Sdim.Ar ntpkey
109239462Sdimand include the file type, generating host and filestamp,
110221345Sdimas described in the
111353358Sdim.Dq Cryptographic Data Files
112353358Sdimsection below.
113353358Sdim.Ss Running the Program
114193326SedTo test and gain experience with Autokey concepts, log in as root and
115193326Sedchange to the keys directory, usually
116193326Sed.Pa /usr/local/etc 
117193326SedWhen run for the first time, or if all files with names beginning with
118193326Sed.Ar ntpkey
119193326Sedhave been removed, use the
120193326Sed.Nm
121193326Sedcommand without arguments to generate a
122296417Sdimdefault RSA host key and matching RSA\-MD5 certificate with expiration
123296417Sdimdate one year hence.
124296417SdimIf run again without options, the program uses the
125296417Sdimexisting keys and parameters and generates only a new certificate with
126296417Sdimnew expiration date one year hence.
127296417Sdim.Pp
128296417SdimRun the command on as many hosts as necessary.
129296417SdimDesignate one of them as the trusted host (TH) using
130193326Sed.Nm
131296417Sdimwith the
132193326Sed.Fl T
133198092Srdivackyoption and configure it to synchronize from reliable Internet servers.
134249423SdimThen configure the other hosts to synchronize to the TH directly or
135193326Sedindirectly.
136193326SedA certificate trail is created when Autokey asks the immediately
137212904Sdimascendant host towards the TH to sign its certificate, which is then
138212904Sdimprovided to the immediately descendant host on request.
139212904SdimAll group hosts should have acyclic certificate trails ending on the TH.
140212904Sdim.Pp
141212904SdimThe host key is used to encrypt the cookie when required and so must be
142212904SdimRSA type.
143341825SdimBy default, the host key is also the sign key used to encrypt
144341825Sdimsignatures.
145193326SedA different sign key can be assigned using the
146296417Sdim.Fl S
147341825Sdimoption and this can be either RSA or DSA type.
148193326SedBy default, the signature
149193326Sedmessage digest type is MD5, but any combination of sign key type and
150193326Sedmessage digest type supported by the OpenSSL library can be specified
151193326Sedusing the
152221345Sdim.Fl c
153193326Sedoption.
154198092SrdivackyThe rules say cryptographic media should be generated with proventic
155234353Sdimfilestamps, which means the host should already be synchronized before
156234353Sdimthis program is run.
157234353SdimThis of course creates a chicken\-and\-egg problem
158198092Srdivackywhen the host is started for the first time.
159198092SrdivackyAccordingly, the host time
160198092Srdivackyshould be set by some other means, such as eyeball\-and\-wristwatch, at
161198092Srdivackyleast so that the certificate lifetime is within the current year.
162198092SrdivackyAfter that and when the host is synchronized to a proventic source, the
163193326Sedcertificate should be re\-generated.
164208600Srdivacky.Pp
165193326SedAdditional information on trusted groups and identity schemes is on the
166193326Sed.Dq Autokey Public\-Key Authentication
167193326Sedpage.
168193326Sed.Pp
169276479SdimThe
170276479Sdim.Xr ntpd @NTPD_MS@
171193326Sedconfiguration command
172360784Sdim.Ic crypto pw Ar password
173360784Sdimspecifies the read password for previously encrypted files.
174360784SdimThe daemon expires on the spot if the password is missing
175360784Sdimor incorrect.
176360784SdimFor convenience, if a file has been previously encrypted,
177360784Sdimthe default read password is the name of the host running
178360784Sdimthe program.
179360784SdimIf the previous write password is specified as the host name,
180360784Sdimthese files can be read by that host with no explicit password.
181360784Sdim.Pp
182360784SdimFile names begin with the prefix
183360784Sdim.Cm ntpkey_
184360784Sdimand end with the postfix
185360784Sdim.Ar _hostname.filestamp ,
186360784Sdimwhere
187193326Sed.Ar hostname
188193326Sedis the owner name, usually the string returned
189193326Sedby the Unix gethostname() routine, and
190198092Srdivacky.Ar filestamp
191198092Srdivackyis the NTP seconds when the file was generated, in decimal digits.
192198092SrdivackyThis both guarantees uniqueness and simplifies maintenance
193193326Sedprocedures, since all files can be quickly removed
194193326Sedby a
195208600Srdivacky.Ic rm ntpkey\&*
196193326Sedcommand or all files generated
197193326Sedat a specific time can be removed by a
198193326Sed.Ic rm
199193326Sed.Ar \&*filestamp
200193326Sedcommand.
201193326SedTo further reduce the risk of misconfiguration,
202198092Srdivackythe first two lines of a file contain the file name
203276479Sdimand generation date and time as comments.
204193326Sed.Pp
205193326SedAll files are installed by default in the keys directory
206239462Sdim.Pa /usr/local/etc ,
207249423Sdimwhich is normally in a shared filesystem
208193326Sedin NFS\-mounted networks.
209193326SedThe actual location of the keys directory
210198092Srdivackyand each file can be overridden by configuration commands,
211198092Srdivackybut this is not recommended.
212193326SedNormally, the files for each host are generated by that host
213193326Sedand used only by that host, although exceptions exist
214193326Sedas noted later on this page.
215198092Srdivacky.Pp
216193326SedNormally, files containing private values,
217193326Sedincluding the host key, sign key and identification parameters,
218193326Sedare permitted root read/write\-only;
219193326Sedwhile others containing public values are permitted world readable.
220198092SrdivackyAlternatively, files containing private values can be encrypted
221193326Sedand these files permitted world readable,
222193326Sedwhich simplifies maintenance in shared file systems.
223360784SdimSince uniqueness is insured by the hostname and
224360784Sdimfile name extensions, the files for a NFS server and
225360784Sdimdependent clients can all be installed in the same shared directory.
226360784Sdim.Pp
227360784SdimThe recommended practice is to keep the file name extensions
228360784Sdimwhen installing a file and to install a soft link
229193326Sedfrom the generic names specified elsewhere on this page
230353358Sdimto the generated files.
231198092SrdivackyThis allows new file generations to be activated simply
232193326Sedby changing the link.
233353358SdimIf a link is present, ntpd follows it to the file name
234193326Sedto extract the filestamp.
235234353SdimIf a link is not present,
236353358Sdim.Xr ntpd @NTPD_MS@
237353358Sdimextracts the filestamp from the file itself.
238234353SdimThis allows clients to verify that the file and generation times
239218893Sdimare always current.
240353358SdimThe
241218893Sdim.Nm
242353358Sdimprogram uses the same timestamp extension for all files generated
243249423Sdimat one time, so each generation is distinct and can be readily
244249423Sdimrecognized in monitoring data.
245353358Sdim.Ss Running the program
246249423SdimThe safest way to run the
247249423Sdim.Nm
248353358Sdimprogram is logged in directly as root.
249341825SdimThe recommended procedure is change to the keys directory,
250193326Sedusually
251193326Sed.Pa /usr/local/etc ,
252249423Sdimthen run the program.
253193326SedWhen run for the first time,
254341825Sdimor if all
255341825Sdim.Cm ntpkey
256249423Sdimfiles have been removed,
257226633Sdimthe program generates a RSA host key file and matching RSA\-MD5 certificate file,
258224145Sdimwhich is all that is necessary in many cases.
259341825SdimThe program also generates soft links from the generic names
260193326Sedto the respective files.
261193326SedIf run again, the program uses the same host key file,
262353358Sdimbut generates a new certificate file and link.
263198092Srdivacky.Pp
264210299SedThe host key is used to encrypt the cookie when required and so must be RSA type.
265210299SedBy default, the host key is also the sign key used to encrypt signatures.
266210299SedWhen necessary, a different sign key can be specified and this can be
267210299Sedeither RSA or DSA type.
268193326SedBy default, the message digest type is MD5, but any combination
269249423Sdimof sign key type and message digest type supported by the OpenSSL library
270249423Sdimcan be specified, including those using the MD2, MD5, SHA, SHA1, MDC2
271193326Sedand RIPE160 message digest algorithms.
272296417SdimHowever, the scheme specified in the certificate must be compatible
273193326Sedwith the sign key.
274296417SdimCertificates using any digest algorithm are compatible with RSA sign keys;
275193326Sedhowever, only SHA and SHA1 certificates are compatible with DSA sign keys.
276296417Sdim.Pp
277212904SdimPrivate/public key files and certificates are compatible with
278193326Sedother OpenSSL applications and very likely other libraries as well.
279296417SdimCertificates or certificate requests derived from them should be compatible
280198092Srdivackywith extant industry practice, although some users might find
281193326Sedthe interpretation of X509v3 extension fields somewhat liberal.
282296417SdimHowever, the identification parameter files, although encoded
283198092Srdivackyas the other files, are probably not compatible with anything other than Autokey.
284193326Sed.Pp
285193326SedRunning the program as other than root and using the Unix
286193326Sed.Ic su
287193326Sedcommand
288193326Sedto assume root may not work properly, since by default the OpenSSL library
289193326Sedlooks for the random seed file
290193326Sed.Cm .rnd
291193326Sedin the user home directory.
292198092SrdivackyHowever, there should be only one
293296417Sdim.Cm .rnd ,
294296417Sdimmost conveniently
295210299Sedin the root directory, so it is convenient to define the
296218893Sdim.Cm $RANDFILE
297218893Sdimenvironment variable used by the OpenSSL library as the path to
298243830Sdim.Cm /.rnd .
299243830Sdim.Pp
300344779SdimInstalling the keys as root might not work in NFS\-mounted
301344779Sdimshared file systems, as NFS clients may not be able to write
302344779Sdimto the shared keys directory, even as root.
303344779SdimIn this case, NFS clients can specify the files in another
304296417Sdimdirectory such as
305296417Sdim.Pa /etc
306249423Sdimusing the
307249423Sdim.Ic keysdir
308296417Sdimcommand.
309234353SdimThere is no need for one client to read the keys and certificates
310234353Sdimof other clients or servers, as these data are obtained automatically
311234353Sdimby the Autokey protocol.
312234353Sdim.Pp
313234353SdimOrdinarily, cryptographic files are generated by the host that uses them,
314234353Sdimbut it is possible for a trusted agent (TA) to generate these files
315234353Sdimfor other hosts; however, in such cases files should always be encrypted.
316234353SdimThe subject name and trusted name default to the hostname
317234353Sdimof the host generating the files, but can be changed by command line options.
318234353SdimIt is convenient to designate the owner name and trusted name
319234353Sdimas the subject and issuer fields, respectively, of the certificate.
320234353SdimThe owner name is also used for the host and sign key files,
321243830Sdimwhile the trusted name is used for the identity files.
322243830Sdim.Pp
323243830SdimAll files are installed by default in the keys directory
324243830Sdim.Pa /usr/local/etc ,
325243830Sdimwhich is normally in a shared filesystem
326243830Sdimin NFS\-mounted networks.
327193326SedThe actual location of the keys directory
328193326Sedand each file can be overridden by configuration commands,
329198092Srdivackybut this is not recommended.
330193326SedNormally, the files for each host are generated by that host
331193326Sedand used only by that host, although exceptions exist
332193326Sedas noted later on this page.
333193326Sed.Pp
334193326SedNormally, files containing private values,
335193326Sedincluding the host key, sign key and identification parameters,
336are permitted root read/write\-only;
337while others containing public values are permitted world readable.
338Alternatively, files containing private values can be encrypted
339and these files permitted world readable,
340which simplifies maintenance in shared file systems.
341Since uniqueness is insured by the hostname and
342file name extensions, the files for a NFS server and
343dependent clients can all be installed in the same shared directory.
344.Pp
345The recommended practice is to keep the file name extensions
346when installing a file and to install a soft link
347from the generic names specified elsewhere on this page
348to the generated files.
349This allows new file generations to be activated simply
350by changing the link.
351If a link is present, ntpd follows it to the file name
352to extract the filestamp.
353If a link is not present,
354.Xr ntpd @NTPD_MS@
355extracts the filestamp from the file itself.
356This allows clients to verify that the file and generation times
357are always current.
358The
359.Nm
360program uses the same timestamp extension for all files generated
361at one time, so each generation is distinct and can be readily
362recognized in monitoring data.
363.Ss Running the program
364The safest way to run the
365.Nm
366program is logged in directly as root.
367The recommended procedure is change to the keys directory,
368usually
369.Pa /usr/local/etc ,
370then run the program.
371When run for the first time,
372or if all
373.Cm ntpkey
374files have been removed,
375the program generates a RSA host key file and matching RSA\-MD5 certificate file,
376which is all that is necessary in many cases.
377The program also generates soft links from the generic names
378to the respective files.
379If run again, the program uses the same host key file,
380but generates a new certificate file and link.
381.Pp
382The host key is used to encrypt the cookie when required and so must be RSA type.
383By default, the host key is also the sign key used to encrypt signatures.
384When necessary, a different sign key can be specified and this can be
385either RSA or DSA type.
386By default, the message digest type is MD5, but any combination
387of sign key type and message digest type supported by the OpenSSL library
388can be specified, including those using the MD2, MD5, SHA, SHA1, MDC2
389and RIPE160 message digest algorithms.
390However, the scheme specified in the certificate must be compatible
391with the sign key.
392Certificates using any digest algorithm are compatible with RSA sign keys;
393however, only SHA and SHA1 certificates are compatible with DSA sign keys.
394.Pp
395Private/public key files and certificates are compatible with
396other OpenSSL applications and very likely other libraries as well.
397Certificates or certificate requests derived from them should be compatible
398with extant industry practice, although some users might find
399the interpretation of X509v3 extension fields somewhat liberal.
400However, the identification parameter files, although encoded
401as the other files, are probably not compatible with anything other than Autokey.
402.Pp
403Running the program as other than root and using the Unix
404.Ic su
405command
406to assume root may not work properly, since by default the OpenSSL library
407looks for the random seed file
408.Cm .rnd
409in the user home directory.
410However, there should be only one
411.Cm .rnd ,
412most conveniently
413in the root directory, so it is convenient to define the
414.Cm $RANDFILE
415environment variable used by the OpenSSL library as the path to
416.Cm /.rnd .
417.Pp
418Installing the keys as root might not work in NFS\-mounted
419shared file systems, as NFS clients may not be able to write
420to the shared keys directory, even as root.
421In this case, NFS clients can specify the files in another
422directory such as
423.Pa /etc
424using the
425.Ic keysdir
426command.
427There is no need for one client to read the keys and certificates
428of other clients or servers, as these data are obtained automatically
429by the Autokey protocol.
430.Pp
431Ordinarily, cryptographic files are generated by the host that uses them,
432but it is possible for a trusted agent (TA) to generate these files
433for other hosts; however, in such cases files should always be encrypted.
434The subject name and trusted name default to the hostname
435of the host generating the files, but can be changed by command line options.
436It is convenient to designate the owner name and trusted name
437as the subject and issuer fields, respectively, of the certificate.
438The owner name is also used for the host and sign key files,
439while the trusted name is used for the identity files.
440seconds.
441seconds.
442s Trusted Hosts and Groups
443Each cryptographic configuration involves selection of a signature scheme
444and identification scheme, called a cryptotype,
445as explained in the
446.Sx Authentication Options
447section of
448.Xr ntp.conf 5 .
449The default cryptotype uses RSA encryption, MD5 message digest
450and TC identification.
451First, configure a NTP subnet including one or more low\-stratum
452trusted hosts from which all other hosts derive synchronization
453directly or indirectly.
454Trusted hosts have trusted certificates;
455all other hosts have nontrusted certificates.
456These hosts will automatically and dynamically build authoritative
457certificate trails to one or more trusted hosts.
458A trusted group is the set of all hosts that have, directly or indirectly,
459a certificate trail ending at a trusted host.
460The trail is defined by static configuration file entries
461or dynamic means described on the
462.Sx Automatic NTP Configuration Options
463section of
464.Xr ntp.conf 5 .
465.Pp
466On each trusted host as root, change to the keys directory.
467To insure a fresh fileset, remove all
468.Cm ntpkey
469files.
470Then run
471.Nm
472.Fl T
473to generate keys and a trusted certificate.
474On all other hosts do the same, but leave off the
475.Fl T
476flag to generate keys and nontrusted certificates.
477When complete, start the NTP daemons beginning at the lowest stratum
478and working up the tree.
479It may take some time for Autokey to instantiate the certificate trails
480throughout the subnet, but setting up the environment is completely automatic.
481.Pp
482If it is necessary to use a different sign key or different digest/signature
483scheme than the default, run
484.Nm
485with the
486.Fl S Ar type
487option, where
488.Ar type
489is either
490.Cm RSA
491or
492.Cm DSA .
493The most often need to do this is when a DSA\-signed certificate is used.
494If it is necessary to use a different certificate scheme than the default,
495run
496.Nm
497with the
498.Fl c Ar scheme
499option and selected
500.Ar scheme
501as needed.
502f
503.Nm
504is run again without these options, it generates a new certificate
505using the same scheme and sign key.
506.Pp
507After setting up the environment it is advisable to update certificates
508from time to time, if only to extend the validity interval.
509Simply run
510.Nm
511with the same flags as before to generate new certificates
512using existing keys.
513However, if the host or sign key is changed,
514.Xr ntpd @NTPD_MS@
515should be restarted.
516When
517.Xr ntpd @NTPD_MS@
518is restarted, it loads any new files and restarts the protocol.
519Other dependent hosts will continue as usual until signatures are refreshed,
520at which time the protocol is restarted.
521.Ss Identity Schemes
522As mentioned on the Autonomous Authentication page,
523the default TC identity scheme is vulnerable to a middleman attack.
524However, there are more secure identity schemes available,
525including PC, IFF, GQ and MV described on the
526.Qq Identification Schemes
527page
528(maybe available at
529.Li http://www.eecis.udel.edu/%7emills/keygen.html ) .
530These schemes are based on a TA, one or more trusted hosts
531and some number of nontrusted hosts.
532Trusted hosts prove identity using values provided by the TA,
533while the remaining hosts prove identity using values provided
534by a trusted host and certificate trails that end on that host.
535The name of a trusted host is also the name of its sugroup
536and also the subject and issuer name on its trusted certificate.
537The TA is not necessarily a trusted host in this sense, but often is.
538.Pp
539In some schemes there are separate keys for servers and clients.
540A server can also be a client of another server,
541but a client can never be a server for another client.
542In general, trusted hosts and nontrusted hosts that operate
543as both server and client have parameter files that contain
544both server and client keys.
545Hosts that operate
546only as clients have key files that contain only client keys.
547.Pp
548The PC scheme supports only one trusted host in the group.
549On trusted host alice run
550.Nm
551.Fl P
552.Fl p Ar password
553to generate the host key file
554.Pa ntpkey_RSAkey_ Ns Ar alice.filestamp
555and trusted private certificate file
556.Pa ntpkey_RSA\-MD5_cert_ Ns Ar alice.filestamp .
557Copy both files to all group hosts;
558they replace the files which would be generated in other schemes.
559On each host bob install a soft link from the generic name
560.Pa ntpkey_host_ Ns Ar bob
561to the host key file and soft link
562.Pa ntpkey_cert_ Ns Ar bob
563to the private certificate file.
564Note the generic links are on bob, but point to files generated
565by trusted host alice.
566In this scheme it is not possible to refresh
567either the keys or certificates without copying them
568to all other hosts in the group.
569.Pp
570For the IFF scheme proceed as in the TC scheme to generate keys
571and certificates for all group hosts, then for every trusted host in the group,
572generate the IFF parameter file.
573On trusted host alice run
574.Nm
575.Fl T
576.Fl I
577.Fl p Ar password
578to produce her parameter file
579.Pa ntpkey_IFFpar_ Ns Ar alice.filestamp ,
580which includes both server and client keys.
581Copy this file to all group hosts that operate as both servers
582and clients and install a soft link from the generic
583.Pa ntpkey_iff_ Ns Ar alice
584to this file.
585If there are no hosts restricted to operate only as clients,
586there is nothing further to do.
587As the IFF scheme is independent
588of keys and certificates, these files can be refreshed as needed.
589.Pp
590If a rogue client has the parameter file, it could masquerade
591as a legitimate server and present a middleman threat.
592To eliminate this threat, the client keys can be extracted
593from the parameter file and distributed to all restricted clients.
594After generating the parameter file, on alice run
595.Nm
596.Fl e
597and pipe the output to a file or mail program.
598Copy or mail this file to all restricted clients.
599On these clients install a soft link from the generic
600.Pa ntpkey_iff_ Ns Ar alice
601to this file.
602To further protect the integrity of the keys,
603each file can be encrypted with a secret password.
604.Pp
605For the GQ scheme proceed as in the TC scheme to generate keys
606and certificates for all group hosts, then for every trusted host
607in the group, generate the IFF parameter file.
608On trusted host alice run
609.Nm
610.Fl T
611.Fl G
612.Fl p Ar password
613to produce her parameter file
614.Pa ntpkey_GQpar_ Ns Ar alice.filestamp ,
615which includes both server and client keys.
616Copy this file to all group hosts and install a soft link
617from the generic
618.Pa ntpkey_gq_ Ns Ar alice
619to this file.
620In addition, on each host bob install a soft link
621from generic
622.Pa ntpkey_gq_ Ns Ar bob
623to this file.
624As the GQ scheme updates the GQ parameters file and certificate
625at the same time, keys and certificates can be regenerated as needed.
626.Pp
627For the MV scheme, proceed as in the TC scheme to generate keys
628and certificates for all group hosts.
629For illustration assume trish is the TA, alice one of several trusted hosts
630and bob one of her clients.
631On TA trish run
632.Nm
633.Fl V Ar n
634.Fl p Ar password ,
635where
636.Ar n
637is the number of revokable keys (typically 5) to produce
638the parameter file
639.Pa ntpkeys_MVpar_ Ns Ar trish.filestamp
640and client key files
641.Pa ntpkeys_MVkeyd_ Ns Ar trish.filestamp
642where
643.Ar d
644is the key number (0 \&<
645.Ar d
646\&<
647.Ar n ) .
648Copy the parameter file to alice and install a soft link
649from the generic
650.Pa ntpkey_mv_ Ns Ar alice
651to this file.
652Copy one of the client key files to alice for later distribution
653to her clients.
654It doesn't matter which client key file goes to alice,
655since they all work the same way.
656Alice copies the client key file to all of her cliens.
657On client bob install a soft link from generic
658.Pa ntpkey_mvkey_ Ns Ar bob
659to the client key file.
660As the MV scheme is independent of keys and certificates,
661these files can be refreshed as needed.
662.Ss Command Line Options
663.Bl -tag -width indent
664.It Fl c Ar scheme
665Select certificate message digest/signature encryption scheme.
666The
667.Ar scheme
668can be one of the following:
669. Cm RSA\-MD2 , RSA\-MD5 , RSA\-SHA , RSA\-SHA1 , RSA\-MDC2 , RSA\-RIPEMD160 , DSA\-SHA ,
670or
671.Cm DSA\-SHA1 .
672Note that RSA schemes must be used with a RSA sign key and DSA
673schemes must be used with a DSA sign key.
674The default without this option is
675.Cm RSA\-MD5 .
676.It Fl d
677Enable debugging.
678This option displays the cryptographic data produced in eye\-friendly billboards.
679.It Fl e
680Write the IFF client keys to the standard output.
681This is intended for automatic key distribution by mail.
682.It Fl G
683Generate parameters and keys for the GQ identification scheme,
684obsoleting any that may exist.
685.It Fl g
686Generate keys for the GQ identification scheme
687using the existing GQ parameters.
688If the GQ parameters do not yet exist, create them first.
689.It Fl H
690Generate new host keys, obsoleting any that may exist.
691.It Fl I
692Generate parameters for the IFF identification scheme,
693obsoleting any that may exist.
694.It Fl i Ar name
695Set the suject name to
696.Ar name .
697This is used as the subject field in certificates
698and in the file name for host and sign keys.
699.It Fl M
700Generate MD5 keys, obsoleting any that may exist.
701.It Fl P
702Generate a private certificate.
703By default, the program generates public certificates.
704.It Fl p Ar password
705Encrypt generated files containing private data with
706.Ar password
707and the DES\-CBC algorithm.
708.It Fl q
709Set the password for reading files to password.
710.It Fl S Oo Cm RSA | DSA Oc
711Generate a new sign key of the designated type,
712obsoleting any that may exist.
713By default, the program uses the host key as the sign key.
714.It Fl s Ar name
715Set the issuer name to
716.Ar name .
717This is used for the issuer field in certificates
718and in the file name for identity files.
719.It Fl T
720Generate a trusted certificate.
721By default, the program generates a non\-trusted certificate.
722.It Fl V Ar nkeys
723Generate parameters and keys for the Mu\-Varadharajan (MV) identification scheme.
724.El
725.Ss Random Seed File
726All cryptographically sound key generation schemes must have means
727to randomize the entropy seed used to initialize
728the internal pseudo\-random number generator used
729by the library routines.
730The OpenSSL library uses a designated random seed file for this purpose.
731The file must be available when starting the NTP daemon and
732.Nm
733program.
734If a site supports OpenSSL or its companion OpenSSH,
735it is very likely that means to do this are already available.
736.Pp
737It is important to understand that entropy must be evolved
738for each generation, for otherwise the random number sequence
739would be predictable.
740Various means dependent on external events, such as keystroke intervals,
741can be used to do this and some systems have built\-in entropy sources.
742Suitable means are described in the OpenSSL software documentation,
743but are outside the scope of this page.
744.Pp
745The entropy seed used by the OpenSSL library is contained in a file,
746usually called
747.Cm .rnd ,
748which must be available when starting the NTP daemon
749or the
750.Nm
751program.
752The NTP daemon will first look for the file
753using the path specified by the
754.Ic randfile
755subcommand of the
756.Ic crypto
757configuration command.
758If not specified in this way, or when starting the
759.Nm
760program,
761the OpenSSL library will look for the file using the path specified
762by the
763.Ev RANDFILE
764environment variable in the user home directory,
765whether root or some other user.
766If the
767.Ev RANDFILE
768environment variable is not present,
769the library will look for the
770.Cm .rnd
771file in the user home directory.
772If the file is not available or cannot be written,
773the daemon exits with a message to the system log and the program
774exits with a suitable error message.
775.Ss Cryptographic Data Files
776All other file formats begin with two lines.
777The first contains the file name, including the generated host name
778and filestamp.
779The second contains the datestamp in conventional Unix date format.
780Lines beginning with # are considered comments and ignored by the
781.Nm
782program and
783.Xr ntpd @NTPD_MS@
784daemon.
785Cryptographic values are encoded first using ASN.1 rules,
786then encrypted if necessary, and finally written PEM\-encoded
787printable ASCII format preceded and followed by MIME content identifier lines.
788.Pp
789The format of the symmetric keys file is somewhat different
790than the other files in the interest of backward compatibility.
791Since DES\-CBC is deprecated in NTPv4, the only key format of interest
792is MD5 alphanumeric strings.
793Following hte heard the keys are
794entered one per line in the format
795.D1 Ar keyno type key
796where
797.Ar keyno
798is a positive integer in the range 1\-65,535,
799.Ar type
800is the string MD5 defining the key format and
801.Ar key
802is the key itself,
803which is a printable ASCII string 16 characters or less in length.
804Each character is chosen from the 93 printable characters
805in the range 0x21 through 0x7f excluding space and the
806.Ql #
807character.
808.Pp
809Note that the keys used by the
810.Xr ntpq @NTPQ_MS@
811and
812.Xr ntpdc @NTPDC_MS@
813programs
814are checked against passwords requested by the programs
815and entered by hand, so it is generally appropriate to specify these keys
816in human readable ASCII format.
817.Pp
818The
819.Nm
820program generates a MD5 symmetric keys file
821.Pa ntpkey_MD5key_ Ns Ar hostname.filestamp .
822Since the file contains private shared keys,
823it should be visible only to root and distributed by secure means
824to other subnet hosts.
825The NTP daemon loads the file
826.Pa ntp.keys ,
827so
828.Nm
829installs a soft link from this name to the generated file.
830Subsequently, similar soft links must be installed by manual
831or automated means on the other subnet hosts.
832While this file is not used with the Autokey Version 2 protocol,
833it is needed to authenticate some remote configuration commands
834used by the
835.Xr ntpq @NTPQ_MS@
836and
837.Xr ntpdc @NTPDC_MS@
838utilities.
839.Sh "OPTIONS"
840.Bl -tag
841.It  Fl b Ar imbits , Fl \-imbits Ns = Ns Ar imbits 
842identity modulus bits.
843This option takes an integer number as its argument.
844The value of
845.Ar imbits
846is constrained to being:
847.in +4
848.nf
849.na
850in the range  256 through 2048
851.fi
852.in -4
853.sp
854The number of bits in the identity modulus.  The default is 256.
855.It  Fl c Ar scheme , Fl \-certificate Ns = Ns Ar scheme 
856certificate scheme.
857.sp
858scheme is one of
859RSA\-MD2, RSA\-MD5, RSA\-SHA, RSA\-SHA1, RSA\-MDC2, RSA\-RIPEMD160,
860DSA\-SHA, or DSA\-SHA1.
861.sp
862Select the certificate message digest/signature encryption scheme.
863Note that RSA schemes must be used with a RSA sign key and DSA
864schemes must be used with a DSA sign key.  The default without
865this option is RSA\-MD5.
866.It  Fl C Ar cipher , Fl \-cipher Ns = Ns Ar cipher 
867privatekey cipher.
868.sp
869Select the cipher which is used to encrypt the files containing
870private keys.  The default is three\-key triple DES in CBC mode,
871equivalent to "@code{\-C des\-ede3\-cbc".  The openssl tool lists ciphers
872available in "\fBopenssl \-h\fP" output.
873.It  Fl d , Fl \-debug\-level 
874Increase debug verbosity level.
875This option may appear an unlimited number of times.
876.sp
877.It  Fl D Ar number , Fl \-set\-debug\-level Ns = Ns Ar number 
878Set the debug verbosity level.
879This option may appear an unlimited number of times.
880This option takes an integer number as its argument.
881.sp
882.It  Fl e , Fl \-id\-key 
883Write IFF or GQ identity keys.
884.sp
885Write the IFF or GQ client keys to the standard output.  This is
886intended for automatic key distribution by mail.
887.It  Fl G , Fl \-gq\-params 
888Generate GQ parameters and keys.
889.sp
890Generate parameters and keys for the GQ identification scheme,
891obsoleting any that may exist.
892.It  Fl H , Fl \-host\-key 
893generate RSA host key.
894.sp
895Generate new host keys, obsoleting any that may exist.
896.It  Fl I , Fl \-iffkey 
897generate IFF parameters.
898.sp
899Generate parameters for the IFF identification scheme, obsoleting
900any that may exist.
901.It  Fl i Ar group , Fl \-ident Ns = Ns Ar group 
902set Autokey group name.
903.sp
904Set the optional Autokey group name to name.  This is used in
905the file name of IFF, GQ, and MV client parameters files.  In
906that role, the default is the host name if this option is not
907provided.  The group name, if specified using \fB\-i/\-\-ident\fP or
908using \fB\-s/\-\-subject\-name\fP following an '\fB@\fP' character,
909is also a part of the self\-signed host certificate's subject and
910issuer names in the form \fBhost@group\fP and should match the
911\'\fBcrypto ident\fP' or '\fBserver ident\fP' configuration in
912\fBntpd\fP's configuration file. 
913.It  Fl l Ar lifetime , Fl \-lifetime Ns = Ns Ar lifetime 
914set certificate lifetime.
915This option takes an integer number as its argument.
916.sp
917Set the certificate expiration to lifetime days from now.
918.It  Fl M , Fl \-md5key 
919generate MD5 keys.
920.sp
921Generate MD5 keys, obsoleting any that may exist.
922.It  Fl m Ar modulus , Fl \-modulus Ns = Ns Ar modulus 
923modulus.
924This option takes an integer number as its argument.
925The value of
926.Ar modulus
927is constrained to being:
928.in +4
929.nf
930.na
931in the range  256 through 2048
932.fi
933.in -4
934.sp
935The number of bits in the prime modulus.  The default is 512.
936.It  Fl P , Fl \-pvt\-cert 
937generate PC private certificate.
938.sp
939Generate a private certificate.  By default, the program generates
940public certificates.
941.It  Fl p Ar passwd , Fl \-password Ns = Ns Ar passwd 
942local private password.
943.sp
944Local files containing private data are encrypted with the
945DES\-CBC algorithm and the specified password.  The same password
946must be specified to the local ntpd via the "crypto pw password"
947configuration command.  The default password is the local
948hostname.
949.It  Fl q Ar passwd , Fl \-export\-passwd Ns = Ns Ar passwd 
950export IFF or GQ group keys with password.
951.sp
952Export IFF or GQ identity group keys to the standard output,
953encrypted with the DES\-CBC algorithm and the specified password.
954The same password must be specified to the remote ntpd via the
955"crypto pw password" configuration command.  See also the option
956-\-id\-key (\-e) for unencrypted exports.
957.It  Fl S Ar sign , Fl \-sign\-key Ns = Ns Ar sign 
958generate sign key (RSA or DSA).
959.sp
960Generate a new sign key of the designated type, obsoleting any
961that may exist.  By default, the program uses the host key as the
962sign key.
963.It  Fl s Ar host@group , Fl \-subject\-name Ns = Ns Ar host@group 
964set host and optionally group name.
965.sp
966Set the Autokey host name, and optionally, group name specified
967following an '\fB@\fP' character.  The host name is used in the file
968name of generated host and signing certificates, without the
969group name.  The host name, and if provided, group name are used
970in \fBhost@group\fP form for the host certificate's subject and issuer
971fields.  Specifying '\fB\-s @group\fP' is allowed, and results in
972leaving the host name unchanged while appending \fB@group\fP to the
973subject and issuer fields, as with \fB\-i group\fP.  The group name, or
974if not provided, the host name are also used in the file names
975of IFF, GQ, and MV client parameter files.
976.It  Fl T , Fl \-trusted\-cert 
977trusted certificate (TC scheme).
978.sp
979Generate a trusted certificate.  By default, the program generates
980a non\-trusted certificate.
981.It  Fl V Ar num , Fl \-mv\-params Ns = Ns Ar num 
982generate <num> MV parameters.
983This option takes an integer number as its argument.
984.sp
985Generate parameters and keys for the Mu\-Varadharajan (MV)
986identification scheme.
987.It  Fl v Ar num , Fl \-mv\-keys Ns = Ns Ar num 
988update <num> MV keys.
989This option takes an integer number as its argument.
990.sp
991This option has not been fully documented.
992.It Fl \&? , Fl \-help
993Display usage information and exit.
994.It Fl \&! , Fl \-more\-help
995Pass the extended usage information through a pager.
996.It Fl > Oo Ar cfgfile Oc , Fl \-save\-opts Oo Ns = Ns Ar cfgfile Oc
997Save the option state to \fIcfgfile\fP.  The default is the \fIlast\fP
998configuration file listed in the \fBOPTION PRESETS\fP section, below.
999The command will exit after updating the config file.
1000.It Fl < Ar cfgfile , Fl \-load\-opts Ns = Ns Ar cfgfile , Fl \-no\-load\-opts
1001Load options from \fIcfgfile\fP.
1002The \fIno\-load\-opts\fP form will disable the loading
1003of earlier config/rc/ini files.  \fI\-\-no\-load\-opts\fP is handled early,
1004out of order.
1005.It Fl \-version Op Brq Ar v|c|n
1006Output version of program and exit.  The default mode is `v', a simple
1007version.  The `c' mode will print copyright information and `n' will
1008print the full copyright notice.
1009.El
1010.Sh "OPTION PRESETS"
1011Any option that is not marked as \fInot presettable\fP may be preset
1012by loading values from configuration ("RC" or ".INI") file(s) and values from
1013environment variables named:
1014.nf
1015  \fBNTP_KEYGEN_<option\-name>\fP or \fBNTP_KEYGEN\fP
1016.fi
1017.ad
1018The environmental presets take precedence (are processed later than)
1019the configuration files.
1020The \fIhomerc\fP files are "\fI$HOME\fP", and "\fI.\fP".
1021If any of these are directories, then the file \fI.ntprc\fP
1022is searched for within those directories.
1023.Sh USAGE
1024The
1025.Fl p Ar password
1026option specifies the write password and
1027.Fl q Ar password
1028option the read password for previously encrypted files.
1029The
1030.Nm
1031program prompts for the password if it reads an encrypted file
1032and the password is missing or incorrect.
1033If an encrypted file is read successfully and
1034no write password is specified, the read password is used
1035as the write password by default.
1036.Sh "ENVIRONMENT"
1037See \fBOPTION PRESETS\fP for configuration environment variables.
1038.Sh "FILES"
1039See \fBOPTION PRESETS\fP for configuration files.
1040.Sh "EXIT STATUS"
1041One of the following exit values will be returned:
1042.Bl -tag
1043.It 0 " (EXIT_SUCCESS)"
1044Successful program execution.
1045.It 1 " (EXIT_FAILURE)"
1046The operation failed or the command syntax was not valid.
1047.It 66 " (EX_NOINPUT)"
1048A specified configuration file could not be loaded.
1049.It 70 " (EX_SOFTWARE)"
1050libopts had an internal operational error.  Please report
1051it to autogen\-users@lists.sourceforge.net.  Thank you.
1052.El
1053.Sh "AUTHORS"
1054The University of Delaware and Network Time Foundation
1055.Sh "COPYRIGHT"
1056Copyright (C) 1992\-2015 The University of Delaware and Network Time Foundation all rights reserved.
1057This program is released under the terms of the NTP license, <http://ntp.org/license>.
1058.Sh BUGS
1059It can take quite a while to generate some cryptographic values,
1060from one to several minutes with modern architectures
1061such as UltraSPARC and up to tens of minutes to an hour
1062with older architectures such as SPARC IPC.
1063.Pp
1064Please report bugs to http://bugs.ntp.org .
1065.Pp
1066Please send bug reports to: http://bugs.ntp.org, bugs@ntp.org
1067.Sh NOTES
1068Portions of this document came from FreeBSD.
1069.Pp
1070This manual page was \fIAutoGen\fP\-erated from the \fBntp\-keygen\fP
1071option definitions.
1072