1275970Scy\input texinfo    @c -*-texinfo-*-
2275970Scy@c %**start of header
3275970Scy@setfilename ntp-keygen.info
4275970Scy@settitle Ntp-keygen User's Manual
5275970Scy@include ../sntp/include/version.texi
6275970Scy@paragraphindent 2
7275970Scy@c %**end of header
8275970Scy
9275970Scy@ifinfo
10275970ScyThis file documents the use of the NTP Project's @code{ntp-keygen}
11275970Scyprogram, which generates various keys for @code{ntpd},
12275970Scy@end ifinfo
13275970Scy
14275970Scy@direntry
15275970Scy* ntp-keygen: (ntp-keygen).                   NTP Key Generation
16275970Scy@end direntry
17275970Scy
18275970Scy@titlepage
19275970Scy@title NTP Key Generation User's Manual
20275970Scy@subtitle ntp-keygen, version @value{VERSION}, @value{UPDATED}
21275970Scy@c @author Max @email{foo@ntp.org}
22275970Scy@end titlepage
23275970Scy
24275970Scy@c @page
25275970Scy@c @vskip 0pt plus 1filll
26275970Scy
27275970Scy@shortcontents
28275970Scy
29275970Scy@menu
30275970Scy* Description::                 
31275970Scy* ntp-keygen Invocation::	Invoking ntp-keygen
32275970Scy* Running the Program::         
33275970Scy* Random Seed File::            
34275970Scy* Cryptographic Data Files::    
35275970Scy@end menu
36275970Scy
37275970Scy@node Top, Description, (dir), (dir)
38275970Scy@top NTP Key Generation Program User Manual
39275970Scy
40275970ScyThis document describes the use of the NTP Project's @code{ntp-keygen}
41275970Scyprogram, that generates cryptographic data files used by the NTPv4
42275970Scyauthentication and identity schemes.
43275970ScyIt can generate message digest keys used in symmetric key cryptography and,
44275970Scyif the OpenSSL software
45275970Scylibrary has been installed, it can generate host keys, sign keys,
46275970Scycertificates, and identity keys and parameters used by the Autokey
47275970Scypublic key cryptography.
48275970ScyThe message digest keys file is generated in a
49275970Scyformat compatible with NTPv3.
50275970ScyAll other files are in PEM-encoded
51275970Scyprintable ASCII format so they can be embedded as MIME attachments in
52275970Scymail to other sites.
53275970Scy
54275970ScyThis document applies to version @value{VERSION} of @code{ntp-keygen}.
55275970Scy
56275970Scy@node Description, Running the Program, Top, Top
57275970Scy@comment  node-name,  next,  previous,  up
58275970Scy@section Description
59275970Scy
60275970ScyThis program generates cryptographic data files used by the NTPv4
61275970Scyauthentication and identity schemes. It can generate message digest
62275970Scykeys used in symmetric key cryptography and, if the OpenSSL software
63275970Scylibrary has been installed, it can generate host keys, sign keys,
64275970Scycertificates, and identity keys and parameters used by the Autokey
65275970Scypublic key cryptography. The message digest keys file is generated in a
66275970Scyformat compatible with NTPv3. All other files are in PEM-encoded
67275970Scyprintable ASCII format so they can be embedded as MIME attachments in
68275970Scymail to other sites.
69275970Scy
70275970ScyWhen used to generate message digest keys, the program produces a file
71275970Scycontaining ten pseudo-random printable ASCII strings suitable for the
72275970ScyMD5 message digest algorithm included in the distribution.
73275970ScyIf the
74275970ScyOpenSSL library is installed, it produces an additional ten hex-encoded
75275970Scyrandom bit strings suitable for the SHA1 and other message digest
76275970Scyalgorithms.
77275970ScyThe message digest keys file must be distributed and stored
78275970Scyusing secure means beyond the scope of NTP itself.
79275970ScyBesides the keys
80275970Scyused for ordinary NTP associations, additional keys can be defined as
81275970Scypasswords for the ntpq and ntpdc utility programs.
82275970Scy
83275970ScyThe remaining generated files are compatible with other OpenSSL
84275970Scyapplications and other Public Key Infrastructure (PKI) resources.
85275970ScyCertificates generated by this program are compatible with extant
86275970Scyindustry practice, although some users might find the interpretation of
87275970ScyX509v3 extension fields somewhat liberal.
88275970ScyHowever, the identity keys
89275970Scyare probably not compatible with anything other than Autokey.
90275970Scy
91275970ScySome files used by this program are encrypted using a private password.
92275970ScyThe @code{-p} option specifies the password for local encrypted files and the
93275970Scy@code{-q} option the password for encrypted files sent to remote sites.
94275970ScyIf no password is specified, the host name returned by the Unix
95275970Scy@code{gethostname()} function, normally the DNS name of the host, is used.
96275970Scy
97275970ScyThe @kbd{pw} option of the @code{crypto} configuration command
98275970Scyspecifies the read password for previously encrypted local files.
99275970ScyThis must match the local password used by this program.
100275970ScyIf not specified, the host name is used.
101275970ScyThus, if files are generated by this program without password,
102275970Scythey can be read back by ntpd without password, but only on the same
103275970Scyhost.
104275970Scy
105275970ScyNormally, encrypted files for each host are generated by that host and
106275970Scyused only by that host, although exceptions exist as noted later on
107275970Scythis page.
108275970ScyThe symmetric keys file, normally called @code{ntp.keys}, is
109275970Scyusually installed in @code{/etc}.
110275970ScyOther files and links are usually installed
111275970Scyin @code{/usr/local/etc}, which is normally in a shared filesystem in
112275970ScyNFS-mounted networks and cannot be changed by shared clients.
113275970ScyThe location of the keys directory can be changed by the keysdir
114275970Scyconfiguration command in such cases.
115275970ScyNormally, this is in @code{/etc}.
116275970Scy
117275970ScyThis program directs commentary and error messages to the standard
118275970Scyerror stream @code{stderr} and remote files to the standard output stream
119275970Scy@code{stdout} where they can be piped to other applications or redirected to
120275970Scyfiles.
121275970ScyThe names used for generated files and links all begin with the
122275970Scystring @code{ntpkey} and include the file type,
123275970Scygenerating host and filestamp,
124275970Scyas described in the @ref{Cryptographic Data Files} section below.
125275970Scy
126275970Scy@node Running the Program, Random Seed File, Description, Top
127275970Scy@comment  node-name,  next,  previous,  up
128275970Scy@section Running the Program
129275970Scy
130275970ScyTo test and gain experience with Autokey concepts, log in as root and
131275970Scychange to the keys directory, usually @code{/usr/local/etc}.
132275970ScyWhen run for the
133275970Scyfirst time, or if all files with names beginning @code{ntpkey}] have been
134275970Scyremoved, use the @code{ntp-keygen} command without arguments to generate a
135275970Scydefault RSA host key and matching RSA-MD5 certificate with expiration
136275970Scydate one year hence.
137275970ScyIf run again without options, the program uses the
138275970Scyexisting keys and parameters and generates only a new certificate with
139275970Scynew expiration date one year hence.
140275970Scy
141275970ScyRun the command on as many hosts as necessary.
142275970ScyDesignate one of them as the trusted host (TH) using @code{ntp-keygen}
143275970Scywith the @code{-T} option and configure
144275970Scyit to synchronize from reliable Internet servers.
145275970ScyThen configure the other hosts to synchronize to the TH directly or indirectly.
146275970ScyA certificate trail is created when Autokey asks the immediately
147275970Scyascendant host towards the TH to sign its certificate, which is then
148275970Scyprovided to the immediately descendant host on request.
149275970ScyAll group hosts should have acyclic certificate trails ending on the TH.
150275970Scy
151275970ScyThe host key is used to encrypt the cookie when required and so must be
152275970ScyRSA type.
153275970ScyBy default, the host key is also the sign key used to encrypt signatures.
154275970ScyA different sign key can be assigned using the @code{-S} option
155275970Scyand this can be either RSA or DSA type.
156275970ScyBy default, the signature
157275970Scymessage digest type is MD5, but any combination of sign key type and
158275970Scymessage digest type supported by the OpenSSL library can be specified
159275970Scyusing the @code{-c} option.
160275970Scy
161275970ScyThe rules say cryptographic media should be generated with proventic
162275970Scyfilestamps, which means the host should already be synchronized before
163275970Scythis program is run.
164275970ScyThis of course creates a chicken-and-egg problem
165275970Scywhen the host is started for the first time.
166275970ScyAccordingly, the host time
167275970Scyshould be set by some other means, such as eyeball-and-wristwatch, at
168275970Scyleast so that the certificate lifetime is within the current year.
169275970ScyAfter that and when the host is synchronized to a proventic source, the
170275970Scycertificate should be re-generated.
171275970Scy
172275970ScyAdditional information on trusted groups and identity schemes is on the
173275970ScyAutokey Public-Key Authentication page.
174275970Scy
175275970Scy@include invoke-ntp-keygen.texi
176275970Scy
177275970Scy@node Random Seed File, Cryptographic Data Files, Running the Program, Top
178275970Scy@comment  node-name,  next,  previous,  up
179275970Scy@section Random Seed File
180275970Scy
181275970ScyAll cryptographically sound key generation schemes must have means to
182275970Scyrandomize the entropy seed used to initialize the internal
183275970Scypseudo-random number generator used by the OpenSSL library routines.
184275970ScyIf a site supports ssh, it is very likely that means to do this are
185275970Scyalready available.
186275970ScyThe entropy seed used by the OpenSSL library is contained in a file,
187275970Scyusually called @code{.rnd}, which must be available when
188275970Scystarting the @code{ntp-keygen} program or @code{ntpd} daemon.
189275970Scy
190275970ScyThe OpenSSL library looks for the file using the path specified by the
191275970Scy@code{RANDFILE} environment variable in the user home directory, whether root
192275970Scyor some other user.
193275970ScyIf the @code{RANDFILE} environment variable is not
194275970Scypresent, the library looks for the @code{.rnd} file in the user home
195275970Scydirectory.
196275970ScySince both the @code{ntp-keygen} program and @code{ntpd} daemon must run
197275970Scyas root, the logical place to put this file is in @code{/.rnd} or
198275970Scy@code{/root/.rnd}.
199275970ScyIf the file is not available or cannot be written, the program exits
200275970Scywith a message to the system log.
201275970Scy
202275970Scy@node Cryptographic Data Files,  , Random Seed File, Top
203275970Scy@comment  node-name,  next,  previous,  up
204275970Scy@section Cryptographic Data Files
205275970Scy
206275970ScyFile and link names are in the @code{form ntpkey_key_name.fstamp},
207275970Scywhere @code{key} is the key or parameter type,
208275970Scy@code{name} is the host or group name and
209275970Scy@code{fstamp} is the filestamp (NTP seconds) when the file was created).
210275970ScyBy convention, key names in generated file names include both upper and
211275970Scylower case characters, while key names in generated link names include
212275970Scyonly lower case characters. The filestamp is not used in generated link
213275970Scynames.
214275970Scy
215275970ScyThe key name is a string defining the cryptographic key type.
216275970ScyKey types include public/private keys host and sign, certificate cert
217275970Scyand several challenge/response key types.
218275970ScyBy convention, client files used for
219275970Scychallenges have a par subtype, as in the IFF challenge IFFpar, while
220275970Scyserver files for responses have a key subtype, as in the GQ response
221275970ScyGQkey.
222275970Scy
223275970ScyAll files begin with two nonencrypted lines. The first line contains
224275970Scythe file name in the format @code{ntpkey_key_host.fstamp}.
225275970ScyThe second line contains the datestamp in conventional Unix date format.
226275970ScyLines beginning with @code{#} are ignored.
227275970Scy
228275970ScyThe remainder of the file contains cryptographic data encoded first
229275970Scyusing ASN.1 rules, then encrypted using the DES-CBC algorithm with
230275970Scygiven password and finally written in PEM-encoded printable ASCII text
231275970Scypreceded and followed by MIME content identifier lines.
232275970Scy
233275970ScyThe format of the symmetric keys file, ordinarily named @code{ntp.keys},
234275970Scyis somewhat different than the other files in the interest of backward
235275970Scycompatibility.
236275970ScyOrdinarily, the file is generated by this program, but
237275970Scyit can be constructed and edited using an ordinary text editor.
238275970Scy
239275970Scy@example
240275970Scy# ntpkey_MD5key_hms.local.3564038757
241275970Scy# Sun Dec  9 02:45:57 2012
242275970Scy
243275970Scy 1 MD5 "]!ghT%O;3)WJ,/Nc:>I  # MD5 key
244275970Scy 2 MD5 lu+H^tF46BKR-6~p{V_5  # MD5 key
245275970Scy 3 MD5 :lnoVsE%Y}z*avh%EtNC  # MD5 key
246275970Scy 4 MD5 |fdZrf0sF~@PHZ;w-i^V  # MD5 key
247275970Scy 5 MD5 IyAG>O"}y"LmCRS!*bHC  # MD5 key
248275970Scy 6 MD5 ">e\A@>hT/661ri52,,H  # MD5 key
249275970Scy 7 MD5 c9x=M'CfLxax9v)PV-si  # MD5 key
250275970Scy 8 MD5 E|=jvFVov?Bn|Ev=&aK\  # MD5 key
251275970Scy 9 MD5 T!c4UT&`(m$+m+B6,`Q0  # MD5 key
252275970Scy10 MD5 JVF/1=)=IFbHbJQz..Cd  # MD5 key
253275970Scy11 SHA1 6dea311109529e436c2b4fccae9bc753c16d1b48  # SHA1 key
254275970Scy12 SHA1 7076f373d86c4848c59ff8046e49cb7d614ec394  # SHA1 key
255275970Scy13 SHA1 5f48b1b60591eb01b7cf1d33b7774f08d20262d3  # SHA1 key
256275970Scy14 SHA1 eed5ab9d9497319ec60cf3781d52607e76720178  # SHA1 key
257275970Scy15 SHA1 f283562611a04c964da8126296f5f8e58c3f85de  # SHA1 key
258275970Scy16 SHA1 1930da171297dd63549af50b29449de17dcf341f  # SHA1 key
259275970Scy17 SHA1 fee892110358cd4382322b889869e750db8e8a8f  # SHA1 key
260275970Scy18 SHA1 b5520c9fadd7ad3fd8bfa061c8821b65d029bb37  # SHA1 key
261275970Scy19 SHA1 8c74fb440ec80f453ec6aaa62b9baed0ab723b92  # SHA1 key
262275970Scy20 SHA1 6bc05f734306a189326000970c19b3910f403795  # SHA1 key
263275970Scy@end example
264275970Scy
265275970Scy                  Figure 1. Typical Symmetric Key File
266275970Scy
267275970ScyFigure 1 shows a typical symmetric keys file used by the reference
268275970Scyimplementation.
269275970ScyEach line of the file contains three fields, first an
270275970Scyinteger between 1 and 65534, inclusive, representing the key identifier
271275970Scyused in the server and peer configuration commands.
272275970ScyNext is the key type for the message digest algorithm,
273275970Scywhich in the absence of the
274275970ScyOpenSSL library must be MD5 to designate the MD5 message digest
275275970Scyalgorithm.
276275970ScyIf the OpenSSL library is installed, the key type can be any
277275970Scymessage digest algorithm supported by that library.
278275970ScyHowever, if
279275970Scycompatibility with FIPS 140-2 is required, the key type must be either
280275970ScySHA or SHA1.
281275970ScyThe key type can be changed using an ASCII text editor.
282275970Scy
283275970ScyAn MD5 key consists of a printable ASCII string less than or equal to
284275970Scy16 characters and terminated by whitespace or a # character.
285275970ScyAn OpenSSL
286275970Scykey consists of a hex-encoded ASCII string of 40 characters, which is
287275970Scytruncated as necessary.
288275970Scy
289275970ScyNote that the keys used by the @code{ntpq} and @code{ntpdc} programs are
290275970Scychecked against passwords requested by the programs and entered by hand,
291275970Scyso it
292275970Scyis generally appropriate to specify these keys in human readable ASCII
293275970Scyformat.
294275970Scy
295275970ScyThe @code{ntp-keygen} program generates a MD5 symmetric keys file
296275970Scy@code{ntpkey_MD5key_hostname.filestamp}.
297275970ScySince the file contains private
298275970Scyshared keys, it should be visible only to root and distributed by
299275970Scysecure means to other subnet hosts.
300275970ScyThe NTP daemon loads the file @code{ntp.keys}, so @code{ntp-keygen}
301275970Scyinstalls a soft link from this name to the generated file.
302275970ScySubsequently, similar soft links must be installed by
303275970Scymanual or automated means on the other subnet hosts.
304275970ScyWhile this file is
305275970Scynot used with the Autokey Version 2 protocol, it is needed to
306275970Scyauthenticate some remote configuration commands used by the @code{ntpq} and
307275970Scy@code{ntpdc} utilities.
308