18585484eSchristos\input texinfo @c -*-texinfo-*- 28585484eSchristos@c %**start of header 38585484eSchristos@setfilename ntp-keygen.info 48585484eSchristos@settitle Ntp-keygen User's Manual 58585484eSchristos@include ../sntp/include/version.texi 68585484eSchristos@paragraphindent 2 78585484eSchristos@c %**end of header 88585484eSchristos 98585484eSchristos@ifinfo 108585484eSchristosThis file documents the use of the NTP Project's @code{ntp-keygen} 118585484eSchristosprogram, which generates various keys for @code{ntpd}, 128585484eSchristos@end ifinfo 138585484eSchristos 148585484eSchristos@direntry 158585484eSchristos* ntp-keygen: (ntp-keygen). NTP Key Generation 168585484eSchristos@end direntry 178585484eSchristos 188585484eSchristos@titlepage 198585484eSchristos@title NTP Key Generation User's Manual 208585484eSchristos@subtitle ntp-keygen, version @value{VERSION}, @value{UPDATED} 218585484eSchristos@c @author Max @email{foo@ntp.org} 228585484eSchristos@end titlepage 238585484eSchristos 248585484eSchristos@c @page 258585484eSchristos@c @vskip 0pt plus 1filll 268585484eSchristos 278585484eSchristos@shortcontents 288585484eSchristos 298585484eSchristos@menu 308585484eSchristos* Description:: 318585484eSchristos* ntp-keygen Invocation:: Invoking ntp-keygen 328585484eSchristos* Running the Program:: 338585484eSchristos* Random Seed File:: 348585484eSchristos* Cryptographic Data Files:: 358585484eSchristos@end menu 368585484eSchristos 378585484eSchristos@node Top, Description, (dir), (dir) 388585484eSchristos@top NTP Key Generation Program User Manual 398585484eSchristos 408585484eSchristosThis document describes the use of the NTP Project's @code{ntp-keygen} 418585484eSchristosprogram, that generates cryptographic data files used by the NTPv4 428585484eSchristosauthentication and identity schemes. 438585484eSchristosIt can generate message digest keys used in symmetric key cryptography and, 448585484eSchristosif the OpenSSL software 458585484eSchristoslibrary has been installed, it can generate host keys, sign keys, 468585484eSchristoscertificates, and identity keys and parameters used by the Autokey 478585484eSchristospublic key cryptography. 488585484eSchristosThe message digest keys file is generated in a 498585484eSchristosformat compatible with NTPv3. 508585484eSchristosAll other files are in PEM-encoded 518585484eSchristosprintable ASCII format so they can be embedded as MIME attachments in 528585484eSchristosmail to other sites. 538585484eSchristos 548585484eSchristosThis document applies to version @value{VERSION} of @code{ntp-keygen}. 558585484eSchristos 568585484eSchristos@node Description, Running the Program, Top, Top 578585484eSchristos@comment node-name, next, previous, up 588585484eSchristos@section Description 598585484eSchristos 608585484eSchristosThis program generates cryptographic data files used by the NTPv4 618585484eSchristosauthentication and identity schemes. It can generate message digest 628585484eSchristoskeys used in symmetric key cryptography and, if the OpenSSL software 638585484eSchristoslibrary has been installed, it can generate host keys, sign keys, 648585484eSchristoscertificates, and identity keys and parameters used by the Autokey 658585484eSchristospublic key cryptography. The message digest keys file is generated in a 668585484eSchristosformat compatible with NTPv3. All other files are in PEM-encoded 678585484eSchristosprintable ASCII format so they can be embedded as MIME attachments in 688585484eSchristosmail to other sites. 698585484eSchristos 708585484eSchristosWhen used to generate message digest keys, the program produces a file 718585484eSchristoscontaining ten pseudo-random printable ASCII strings suitable for the 728585484eSchristosMD5 message digest algorithm included in the distribution. 738585484eSchristosIf the 748585484eSchristosOpenSSL library is installed, it produces an additional ten hex-encoded 758585484eSchristosrandom bit strings suitable for the SHA1 and other message digest 768585484eSchristosalgorithms. 778585484eSchristosThe message digest keys file must be distributed and stored 788585484eSchristosusing secure means beyond the scope of NTP itself. 798585484eSchristosBesides the keys 808585484eSchristosused for ordinary NTP associations, additional keys can be defined as 818585484eSchristospasswords for the ntpq and ntpdc utility programs. 828585484eSchristos 838585484eSchristosThe remaining generated files are compatible with other OpenSSL 848585484eSchristosapplications and other Public Key Infrastructure (PKI) resources. 858585484eSchristosCertificates generated by this program are compatible with extant 868585484eSchristosindustry practice, although some users might find the interpretation of 878585484eSchristosX509v3 extension fields somewhat liberal. 888585484eSchristosHowever, the identity keys 898585484eSchristosare probably not compatible with anything other than Autokey. 908585484eSchristos 918585484eSchristosSome files used by this program are encrypted using a private password. 928585484eSchristosThe @code{-p} option specifies the password for local encrypted files and the 938585484eSchristos@code{-q} option the password for encrypted files sent to remote sites. 948585484eSchristosIf no password is specified, the host name returned by the Unix 958585484eSchristos@code{gethostname()} function, normally the DNS name of the host, is used. 968585484eSchristos 978585484eSchristosThe @kbd{pw} option of the @code{crypto} configuration command 988585484eSchristosspecifies the read password for previously encrypted local files. 998585484eSchristosThis must match the local password used by this program. 1008585484eSchristosIf not specified, the host name is used. 1018585484eSchristosThus, if files are generated by this program without password, 1028585484eSchristosthey can be read back by ntpd without password, but only on the same 1038585484eSchristoshost. 1048585484eSchristos 1058585484eSchristosNormally, encrypted files for each host are generated by that host and 1068585484eSchristosused only by that host, although exceptions exist as noted later on 1078585484eSchristosthis page. 1088585484eSchristosThe symmetric keys file, normally called @code{ntp.keys}, is 1098585484eSchristosusually installed in @code{/etc}. 1108585484eSchristosOther files and links are usually installed 1118585484eSchristosin @code{/usr/local/etc}, which is normally in a shared filesystem in 1128585484eSchristosNFS-mounted networks and cannot be changed by shared clients. 1138585484eSchristosThe location of the keys directory can be changed by the keysdir 1148585484eSchristosconfiguration command in such cases. 1158585484eSchristosNormally, this is in @code{/etc}. 1168585484eSchristos 1178585484eSchristosThis program directs commentary and error messages to the standard 1188585484eSchristoserror stream @code{stderr} and remote files to the standard output stream 1198585484eSchristos@code{stdout} where they can be piped to other applications or redirected to 1208585484eSchristosfiles. 1218585484eSchristosThe names used for generated files and links all begin with the 1228585484eSchristosstring @code{ntpkey} and include the file type, 1238585484eSchristosgenerating host and filestamp, 1248585484eSchristosas described in the @ref{Cryptographic Data Files} section below. 1258585484eSchristos 1268585484eSchristos@node Running the Program, Random Seed File, Description, Top 1278585484eSchristos@comment node-name, next, previous, up 1288585484eSchristos@section Running the Program 1298585484eSchristos 1308585484eSchristosTo test and gain experience with Autokey concepts, log in as root and 1318585484eSchristoschange to the keys directory, usually @code{/usr/local/etc}. 1328585484eSchristosWhen run for the 1338585484eSchristosfirst time, or if all files with names beginning @code{ntpkey}] have been 1348585484eSchristosremoved, use the @code{ntp-keygen} command without arguments to generate a 1358585484eSchristosdefault RSA host key and matching RSA-MD5 certificate with expiration 1368585484eSchristosdate one year hence. 1378585484eSchristosIf run again without options, the program uses the 1388585484eSchristosexisting keys and parameters and generates only a new certificate with 1398585484eSchristosnew expiration date one year hence. 1408585484eSchristos 1418585484eSchristosRun the command on as many hosts as necessary. 1428585484eSchristosDesignate one of them as the trusted host (TH) using @code{ntp-keygen} 1438585484eSchristoswith the @code{-T} option and configure 1448585484eSchristosit to synchronize from reliable Internet servers. 1458585484eSchristosThen configure the other hosts to synchronize to the TH directly or indirectly. 1468585484eSchristosA certificate trail is created when Autokey asks the immediately 1478585484eSchristosascendant host towards the TH to sign its certificate, which is then 1488585484eSchristosprovided to the immediately descendant host on request. 1498585484eSchristosAll group hosts should have acyclic certificate trails ending on the TH. 1508585484eSchristos 1518585484eSchristosThe host key is used to encrypt the cookie when required and so must be 1528585484eSchristosRSA type. 1538585484eSchristosBy default, the host key is also the sign key used to encrypt signatures. 1548585484eSchristosA different sign key can be assigned using the @code{-S} option 1558585484eSchristosand this can be either RSA or DSA type. 1568585484eSchristosBy default, the signature 1578585484eSchristosmessage digest type is MD5, but any combination of sign key type and 1588585484eSchristosmessage digest type supported by the OpenSSL library can be specified 1598585484eSchristosusing the @code{-c} option. 1608585484eSchristos 1618585484eSchristosThe rules say cryptographic media should be generated with proventic 1628585484eSchristosfilestamps, which means the host should already be synchronized before 1638585484eSchristosthis program is run. 1648585484eSchristosThis of course creates a chicken-and-egg problem 1658585484eSchristoswhen the host is started for the first time. 1668585484eSchristosAccordingly, the host time 1678585484eSchristosshould be set by some other means, such as eyeball-and-wristwatch, at 1688585484eSchristosleast so that the certificate lifetime is within the current year. 1698585484eSchristosAfter that and when the host is synchronized to a proventic source, the 1708585484eSchristoscertificate should be re-generated. 1718585484eSchristos 1728585484eSchristosAdditional information on trusted groups and identity schemes is on the 1738585484eSchristosAutokey Public-Key Authentication page. 1748585484eSchristos 1758585484eSchristos@include invoke-ntp-keygen.texi 1768585484eSchristos 1778585484eSchristos@node Random Seed File, Cryptographic Data Files, Running the Program, Top 1788585484eSchristos@comment node-name, next, previous, up 1798585484eSchristos@section Random Seed File 1808585484eSchristos 1818585484eSchristosAll cryptographically sound key generation schemes must have means to 1828585484eSchristosrandomize the entropy seed used to initialize the internal 1838585484eSchristospseudo-random number generator used by the OpenSSL library routines. 1848585484eSchristosIf a site supports ssh, it is very likely that means to do this are 1858585484eSchristosalready available. 1868585484eSchristosThe entropy seed used by the OpenSSL library is contained in a file, 1878585484eSchristosusually called @code{.rnd}, which must be available when 1888585484eSchristosstarting the @code{ntp-keygen} program or @code{ntpd} daemon. 1898585484eSchristos 1908585484eSchristosThe OpenSSL library looks for the file using the path specified by the 1918585484eSchristos@code{RANDFILE} environment variable in the user home directory, whether root 1928585484eSchristosor some other user. 1938585484eSchristosIf the @code{RANDFILE} environment variable is not 1948585484eSchristospresent, the library looks for the @code{.rnd} file in the user home 1958585484eSchristosdirectory. 1968585484eSchristosSince both the @code{ntp-keygen} program and @code{ntpd} daemon must run 1978585484eSchristosas root, the logical place to put this file is in @code{/.rnd} or 1988585484eSchristos@code{/root/.rnd}. 1998585484eSchristosIf the file is not available or cannot be written, the program exits 2008585484eSchristoswith a message to the system log. 2018585484eSchristos 2028585484eSchristos@node Cryptographic Data Files, , Random Seed File, Top 2038585484eSchristos@comment node-name, next, previous, up 2048585484eSchristos@section Cryptographic Data Files 2058585484eSchristos 2068585484eSchristosFile and link names are in the @code{form ntpkey_key_name.fstamp}, 2078585484eSchristoswhere @code{key} is the key or parameter type, 2088585484eSchristos@code{name} is the host or group name and 2098585484eSchristos@code{fstamp} is the filestamp (NTP seconds) when the file was created). 2108585484eSchristosBy convention, key names in generated file names include both upper and 2118585484eSchristoslower case characters, while key names in generated link names include 2128585484eSchristosonly lower case characters. The filestamp is not used in generated link 2138585484eSchristosnames. 2148585484eSchristos 2158585484eSchristosThe key name is a string defining the cryptographic key type. 2168585484eSchristosKey types include public/private keys host and sign, certificate cert 2178585484eSchristosand several challenge/response key types. 2188585484eSchristosBy convention, client files used for 2198585484eSchristoschallenges have a par subtype, as in the IFF challenge IFFpar, while 2208585484eSchristosserver files for responses have a key subtype, as in the GQ response 2218585484eSchristosGQkey. 2228585484eSchristos 2238585484eSchristosAll files begin with two nonencrypted lines. The first line contains 2248585484eSchristosthe file name in the format @code{ntpkey_key_host.fstamp}. 2258585484eSchristosThe second line contains the datestamp in conventional Unix date format. 2268585484eSchristosLines beginning with @code{#} are ignored. 2278585484eSchristos 2288585484eSchristosThe remainder of the file contains cryptographic data encoded first 2298585484eSchristosusing ASN.1 rules, then encrypted using the DES-CBC algorithm with 2308585484eSchristosgiven password and finally written in PEM-encoded printable ASCII text 2318585484eSchristospreceded and followed by MIME content identifier lines. 2328585484eSchristos 2338585484eSchristosThe format of the symmetric keys file, ordinarily named @code{ntp.keys}, 2348585484eSchristosis somewhat different than the other files in the interest of backward 2358585484eSchristoscompatibility. 2368585484eSchristosOrdinarily, the file is generated by this program, but 2378585484eSchristosit can be constructed and edited using an ordinary text editor. 2388585484eSchristos 2398585484eSchristos@example 2408585484eSchristos# ntpkey_MD5key_hms.local.3564038757 2418585484eSchristos# Sun Dec 9 02:45:57 2012 2428585484eSchristos 2438585484eSchristos 1 MD5 "]!ghT%O;3)WJ,/Nc:>I # MD5 key 2448585484eSchristos 2 MD5 lu+H^tF46BKR-6~p{V_5 # MD5 key 2458585484eSchristos 3 MD5 :lnoVsE%Y}z*avh%EtNC # MD5 key 2468585484eSchristos 4 MD5 |fdZrf0sF~@PHZ;w-i^V # MD5 key 2478585484eSchristos 5 MD5 IyAG>O"}y"LmCRS!*bHC # MD5 key 2488585484eSchristos 6 MD5 ">e\A@>hT/661ri52,,H # MD5 key 2498585484eSchristos 7 MD5 c9x=M'CfLxax9v)PV-si # MD5 key 2508585484eSchristos 8 MD5 E|=jvFVov?Bn|Ev=&aK\ # MD5 key 2518585484eSchristos 9 MD5 T!c4UT&`(m$+m+B6,`Q0 # MD5 key 2528585484eSchristos10 MD5 JVF/1=)=IFbHbJQz..Cd # MD5 key 2538585484eSchristos11 SHA1 6dea311109529e436c2b4fccae9bc753c16d1b48 # SHA1 key 2548585484eSchristos12 SHA1 7076f373d86c4848c59ff8046e49cb7d614ec394 # SHA1 key 2558585484eSchristos13 SHA1 5f48b1b60591eb01b7cf1d33b7774f08d20262d3 # SHA1 key 2568585484eSchristos14 SHA1 eed5ab9d9497319ec60cf3781d52607e76720178 # SHA1 key 2578585484eSchristos15 SHA1 f283562611a04c964da8126296f5f8e58c3f85de # SHA1 key 2588585484eSchristos16 SHA1 1930da171297dd63549af50b29449de17dcf341f # SHA1 key 2598585484eSchristos17 SHA1 fee892110358cd4382322b889869e750db8e8a8f # SHA1 key 2608585484eSchristos18 SHA1 b5520c9fadd7ad3fd8bfa061c8821b65d029bb37 # SHA1 key 2618585484eSchristos19 SHA1 8c74fb440ec80f453ec6aaa62b9baed0ab723b92 # SHA1 key 2628585484eSchristos20 SHA1 6bc05f734306a189326000970c19b3910f403795 # SHA1 key 2638585484eSchristos@end example 2648585484eSchristos 2658585484eSchristos Figure 1. Typical Symmetric Key File 2668585484eSchristos 2678585484eSchristosFigure 1 shows a typical symmetric keys file used by the reference 2688585484eSchristosimplementation. 2698585484eSchristosEach line of the file contains three fields, first an 270*397d6dd6Schristosinteger between 1 and 65535, inclusive, representing the key identifier 2718585484eSchristosused in the server and peer configuration commands. 2728585484eSchristosNext is the key type for the message digest algorithm, 2738585484eSchristoswhich in the absence of the 2748585484eSchristosOpenSSL library must be MD5 to designate the MD5 message digest 2758585484eSchristosalgorithm. 2768585484eSchristosIf the OpenSSL library is installed, the key type can be any 2778585484eSchristosmessage digest algorithm supported by that library. 2788585484eSchristosHowever, if 2798585484eSchristoscompatibility with FIPS 140-2 is required, the key type must be either 2808585484eSchristosSHA or SHA1. 2818585484eSchristosThe key type can be changed using an ASCII text editor. 2828585484eSchristos 2838585484eSchristosAn MD5 key consists of a printable ASCII string less than or equal to 2848585484eSchristos16 characters and terminated by whitespace or a # character. 2858585484eSchristosAn OpenSSL 2868585484eSchristoskey consists of a hex-encoded ASCII string of 40 characters, which is 2878585484eSchristostruncated as necessary. 2888585484eSchristos 2898585484eSchristosNote that the keys used by the @code{ntpq} and @code{ntpdc} programs are 2908585484eSchristoschecked against passwords requested by the programs and entered by hand, 2918585484eSchristosso it 2928585484eSchristosis generally appropriate to specify these keys in human readable ASCII 2938585484eSchristosformat. 2948585484eSchristos 2958585484eSchristosThe @code{ntp-keygen} program generates a MD5 symmetric keys file 2968585484eSchristos@code{ntpkey_MD5key_hostname.filestamp}. 2978585484eSchristosSince the file contains private 2988585484eSchristosshared keys, it should be visible only to root and distributed by 2998585484eSchristossecure means to other subnet hosts. 3008585484eSchristosThe NTP daemon loads the file @code{ntp.keys}, so @code{ntp-keygen} 3018585484eSchristosinstalls a soft link from this name to the generated file. 3028585484eSchristosSubsequently, similar soft links must be installed by 3038585484eSchristosmanual or automated means on the other subnet hosts. 3048585484eSchristosWhile this file is 3058585484eSchristosnot used with the Autokey Version 2 protocol, it is needed to 3068585484eSchristosauthenticate some remote configuration commands used by the @code{ntpq} and 3078585484eSchristos@code{ntpdc} utilities. 308