]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
add AES-128 CMAC digest support as key type AES128CMAC length *MUST BE* 16 bytes
authorBrian Inglis <bwi@ntp.org>
Mon, 20 Feb 2017 05:21:29 +0000 (05:21 +0000)
committerBrian Inglis <bwi@ntp.org>
Mon, 20 Feb 2017 05:21:29 +0000 (05:21 +0000)
bk: 58aa7cd9a-QoqXcJfrwAi1FQiIW7iA

12 files changed:
html/authentic.html
html/keygen.html
html/ntpq.html
include/ntp_md5.h
libntp/ssl_init.c
ntpq/ntpq.c
ports/winnt/scripts/mkver.bat
sntp/crypto.c
sntp/tests/crypto.c
sntp/tests/packetProcessing.c
tests/libntp/ssl_init.c
util/ntp-keygen-opts.def

index e529a6d184803f7130efc1f5f5fc6028220a5b7c..06bb67bc727ae2b57818213456fd5bd965eaf8cf 100644 (file)
@@ -46,14 +46,40 @@ required.</p>
 <p>By default, the client sends non-authenticated packets and the server responds with non-authenticated packets.  If the client sends authenticated packets, the server responds with authenticated packets if correct, or a crypto-NAK packet if not.  In the case of unsolicited packets which might consume significant resources, such as broadcast or symmetric mode packets, authentication is required, unless overridden by a <tt>disable auth</tt> command.  In the current climate of targeted broadcast or &quot;letterbomb&quot; attacks, defeating this requirement would be decidedly dangerous.  In any case, the <tt>notrust </tt>flag, described on the <a href="authopt.html">Access Control Options</a> page, can be used to disable access to all but correctly authenticated clients.</p>
 <h4 id="symm">Symmetric Key Cryptography</h4>
 <p>The original NTPv3 specification (RFC-1305), as well as the current NTPv4 specification (RFC-5905), allows any one of possibly 65,534 message digest keys (excluding zero), each distinguished by a 32-bit key ID, to authenticate an association.  The servers and clients involved must agree on the key ID, key type and key to authenticate NTP packets.</p>
-<p>The message digest is a cryptographic hash computed by an algorithm such as MD5 or SHA.  When authentication is specified, a message authentication code (MAC) is appended to the NTP packet header.  The MAC consists of a 32-bit key identifier (key ID) followed by a 128- or 160-bit message digest.  The algorithm computes the digest as the hash of a 128- or 160- bit message digest key concatenated with the NTP packet header fields with the exception of the MAC.  On transmit, the message digest is computed and inserted in the MAC.  On receive, the message digest is computed and compared with the MAC.  The packet is accepted only if the two MACs are identical.  If a discrepancy is found by the client, the client ignores the packet, but raises an alarm.  If this happens at the server, the server returns a special message called a <em>crypto-NAK</em>.  Since the crypto-NAK is protected by the loopback test, an intruder cannot disrupt the protocol by sending a bogus crypto-NAK.</p>
+<p>The message digest is a cryptographic hash computed by an algorithm such as MD5, SHA, or AES-128 CMAC.  When authentication is specified, a message authentication code (MAC) is appended to the NTP packet header.  The MAC consists of a 32-bit key identifier (key ID) followed by a 128- or 160-bit message digest.  The algorithm computes the digest as the hash of a 128- or 160- bit message digest key concatenated with the NTP packet header fields with the exception of the MAC.  On transmit, the message digest is computed and inserted in the MAC.  On receive, the message digest is computed and compared with the MAC.  The packet is accepted only if the two MACs are identical.  If a discrepancy is found by the client, the client ignores the packet, but raises an alarm.  If this happens at the server, the server returns a special message called a <em>crypto-NAK</em>.  Since the crypto-NAK is protected by the loopback test, an intruder cannot disrupt the protocol by sending a bogus crypto-NAK.</p>
 <p>Keys and related information are specified in a keys file, which must be distributed and stored using secure means beyond the scope of the NTP protocol itself.  Besides the keys used for ordinary NTP associations, additional keys can be used as passwords for the <tt><a href="ntpq.html">ntpq</a></tt> and <tt><a href="ntpdc.html">ntpdc</a></tt> utility programs.  Ordinarily, the <tt>ntp.keys</tt> file is generated by the <tt><a href="keygen.html">ntp-keygen</a></tt> program, but it can be constructed and edited using an ordinary text editor.</p>
 <p> Each line of the keys file consists of three or four fields: a key ID in the range 1 to 65,534, inclusive, a key type, a message digest key consisting of a printable ASCII string less than 40 characters or a 40-character hex digit string, and an optional comma-separated list of IPs that are allowed to serve time.  If the OpenSSL library is installed, the key type can be any message digest algorithm supported by the library.  If the OpenSSL library is not installed, the only permitted key type is MD5.</p>
-<div align="center">
-  <p><img src="pic/sx5.gif" alt="gif"></p>
-  <p>Figure 1. Typical Symmetric Key File</p>
-</div>
-<p>Figure 1 shows a typical keys file used by the reference implementation when the OpenSSL library is installed.  In this figure, for key IDs in he range 1-10, the key is interpreted as a printable ASCII string.  For key IDs in the range 11-20, the key is a 40-character hex digit string.  The key is truncated or zero-filled internally to either 128 or 160 bits, depending on the key type.  The line can be edited later or new lines can be added to change any field.  The key can be change to a password, such as <tt>2late4Me</tt> for key ID 10.  Note that two or more keys files can be combined in any order as long as the key IDs are distinct.</p>
+<table>
+  <caption style="caption-side: bottom;">
+    Figure 1. Typical Symmetric Key File
+  </caption>
+  <tr><td style="border: 1px solid black; border-spacing: 0;">
+       <pre style="color:grey;">
+# ntpkey_MD5key_bk.ntp.org.3595864945
+# Thu Dec 12 19:22:25 2013
+
+1  MD5 L";Nw&lt;`.I&lt;f4U0)247"i  # MD5 key
+2  MD5 &amp;&gt;l0%XXK9O'51VwV&lt;xq~  # MD5 key
+3  MD5 lb4zLW~d^!K:]RsD'qb6  # MD5 key
+4  MD5 Yue:tL[+vR)M`n~bY,'?  # MD5 key
+5  MD5 B;fxlKgr/&amp;4ZTbL6=RxA  # MD5 key
+6  MD5 4eYwa`o}3i@@V@..R9!l  # MD5 key
+7  MD5 `A.([h+;wTQ|xfi%Sn_!  # MD5 key
+8  MD5 45:V,r4]l6y^JH6"Sh?F  # MD5 key
+9  MD5 3-5vcn*6l29DS?Xdsg)*  # MD5 key
+10 MD5 2late4Me              # MD5 key
+11 SHA1 a27872d3030a9025b8446c751b4551a7629af65c  # SHA1 key
+12 SHA1 21bc3b4865dbb9e920902abdccb3e04ff97a5e74  # SHA1 key
+13 SHA1 2b7736fe24fef5ba85ae11594132ab5d6f6daba9  # SHA1 key
+14 SHA  a5332809c8878dd3a5b918819108a111509aeceb  # SHA  key
+15 MD2  2fe16c88c760ff2f16d4267e36c1aa6c926e6964  # MD2  key
+16 MD4  b2691811dc19cfc0e2f9bcacd74213f29812183d  # MD4  key
+17 MD5  e4d6735b8bdad58ec5ffcb087300a17f7fef1f7c  # MD5  key
+18 MDC2 a8d5e2315c025bf3a79174c87fbd10477de2eabc  # MDC2 key
+19 RIPEMD160 77ca332cafb30e3cafb174dcd5b80ded7ba9b3d2  # RIPEMD160 key
+20 AES128CMAC f92ff73eee86c1e7dc638d6489a04e4e555af878  # AES128CMAC key
+  </pre></td></tr></table>
+<p>Figure 1 shows a typical keys file used by the reference implementation when the OpenSSL library is installed.  In this figure, for key IDs in he range 1-10, the key is interpreted as a printable ASCII string.  For key IDs in the range 11-20, the key is a 40-character hex digit string.  The key is truncated or zero-filled internally to either 128 or 160 bits, depending on the key type.  The line can be edited later or new lines can be added to change any field.  The key can be changed to a password, such as <tt>2late4Me</tt> for key ID 10.  Note that two or more keys files can be combined in any order as long as the key IDs are distinct.</p>
 <p>When <tt>ntpd</tt> is started, it reads the keys file specified by the <tt>keys</tt> command and installs the keys in the key cache.  However, individual keys must be activated with the <tt>trustedkey</tt> configuration command before use.  This allows, for instance, the installation of possibly several batches of keys and then activating a key remotely using <tt>ntpq</tt> or <tt>ntpdc</tt>.  The <tt>requestkey</tt> command selects the key ID used as the password for the <tt>ntpdc</tt> utility, while the <tt>controlkey</tt> command selects the key ID used as the password for the <tt>ntpq</tt> utility.</p>
 <h4 id="windows">Microsoft Windows Authentication</h4>
 <p>In addition to the above means, <tt>ntpd</tt> now supports Microsoft Windows MS-SNTP authentication using Active Directory services.  This support was contributed by the Samba Team and is still in development.  It is enabled using the <tt>mssntp</tt> flag of the <tt>restrict</tt> command described on the <a href="accopt.html#restrict">Access Control Options</a> page.  <span class="style1">Note: Potential users should be aware that these services involve a TCP connection to another process that could potentially block, denying services to other users.  Therefore, this flag should be used only for a dedicated server with no clients other than MS-SNTP.</span></p>
index 191b7147b514eea43218cf5dfc66a863a9d933d8..bad97fb9455344c4d7b70b662aef29fd4ca1dde6 100644 (file)
@@ -1,42 +1,42 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
-<head>
-<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
-<meta name="generator" content="HTML Tidy, see www.w3.org">
-<title>ntp-keygen - generate public and private keys</title>
-<link href="scripts/style.css" type="text/css" rel="stylesheet">
-</head>
-<body>
-<h3><tt>ntp-keygen</tt> - generate public and private keys</h3>
-<p><img src="pic/alice23.gif" alt="gif" align="left"><a href="http://www.eecis.udel.edu/%7emills/pictures.html">from <i>Alice's Adventures in Wonderland</i>, Lewis Carroll</a></p>
-<p>Alice holds the key.</p>
-<p>Last update:
-  <!-- #BeginDate format:En2m -->10-Mar-2014  05:11<!-- #EndDate -->
-    UTC</p>
-<br clear="left">
-<h4>Related Links</h4>
-<script type="text/javascript" language="javascript" src="scripts/manual.txt"></script>
-<h4>Table of Contents</h4>
-<ul>
-  <li class="inline"><a href="#synop">Synopsis</a></li>
-  <li class="inline"><a href="#descrip">Description</a></li>
-  <li class="inline"><a href="#run">Running the program</a></li>
-  <li class="inline"><a href="#cmd">Command Line Options</a></li>
-  <li class="inline"><a href="#rand">Random Seed File</a></li>
-  <li class="inline"><a href="#fmt">Cryptographic Data Files</a></li>
-  <li class="inline"><a href="#bug">Bugs</a></li>
-</ul>
-<hr>
-<h4 id="synop">Synopsis</h4>
-<p id="intro"><tt>ntp-keygen [ -deGHIMPT ] [ -b <i>modulus</i> ] [ -c [ RSA-MD2 | RSA-MD5 | RSA-SHA
-  | RSA-SHA1 | RSA-MDC2 | RSA-RIPEMD160 | DSA-SHA | DSA-SHA1 ] ]
+       <head>
+               <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
+               <meta name="generator" content="HTML Tidy, see www.w3.org">
+               <title>ntp-keygen - generate public and private keys</title>
+               <link href="scripts/style.css" type="text/css" rel="stylesheet">
+       </head>
+       <body>
+               <h3><tt>ntp-keygen</tt> - generate public and private keys</h3>
+               <p><img src="pic/alice23.gif" alt="gif" align="left"><a href="http://www.eecis.udel.edu/%7emills/pictures.html">from <i>Alice's Adventures in Wonderland</i>, Lewis Carroll</a></p>
+               <p>Alice holds the key.</p>
+               <p>Last update:
+               <!-- #BeginDate format:En2m -->10-Mar-2014  05:11<!-- #EndDate -->
+               UTC</p>
+               <br clear="left">
+               <h4>Related Links</h4>
+               <script type="text/javascript" language="javascript" src="scripts/manual.txt"></script>
+               <h4>Table of Contents</h4>
+               <ul>
+                       <li class="inline"><a href="#synop">Synopsis</a></li>
+                       <li class="inline"><a href="#descrip">Description</a></li>
+                       <li class="inline"><a href="#run">Running the program</a></li>
+                       <li class="inline"><a href="#cmd">Command Line Options</a></li>
+                       <li class="inline"><a href="#rand">Random Seed File</a></li>
+                       <li class="inline"><a href="#fmt">Cryptographic Data Files</a></li>
+                       <li class="inline"><a href="#bug">Bugs</a></li>
+               </ul>
+               <hr>
+               <h4 id="synop">Synopsis</h4>
+               <p id="intro"><tt>ntp-keygen [ -deGHIMPT ] [ -b <i>modulus</i> ] [ -c [ RSA-MD2 | RSA-MD5 | RSA-SHA
+                       | RSA-SHA1 | RSA-MDC2 | RSA-RIPEMD160 | DSA-SHA | DSA-SHA1 ] ]
   [ -C <i>cipher</i> ] [-i <i>group</i> ] [ -l <em>days</em>]
   [ -m <i>modulus</i> ]  [ -p <i>passwd1</i> ] [ -q <i>passwd2</i> ] 
   [ -S [ RSA | DSA ] ] [ -s <i>host</i> ] [ -V <i>nkeys</i> ]</tt></p>
 <h4 id="descrip">Description</h4>
 <p>This program generates cryptographic data files used by the NTPv4 authentication and identity schemes. It can generate  message digest keys used in symmetric   key cryptography and, if the OpenSSL software library has been installed, it can generate host keys, sign keys, certificates, and identity keys and parameters used by the Autokey public key cryptography. The message digest keys file is generated in a format compatible with NTPv3. All other files are in PEM-encoded printable ASCII format so they can be embedded as MIME attachments in mail to other sites.</p>
 <p>When used to generate message digest keys, the program produces a file containing
-  ten pseudo-random printable ASCII strings suitable for the MD5 message digest algorithm included in the distribution. If the OpenSSL library is installed, it produces an additional ten hex-encoded random bit strings suitable for the SHA1 and other message digest algorithms. The message digest keys file  must be distributed and stored using secure means beyond the scope of  NTP  itself. Besides the keys used for ordinary NTP associations, additional keys can be defined as passwords for the <tt><a href="ntpq.html">ntpq</a></tt> and <tt><a href="ntpdc.html">ntpdc</a></tt> utility programs.</p>
+  ten pseudo-random printable ASCII strings suitable for the MD5 message digest algorithm included in the distribution. If the OpenSSL library is installed, it produces an additional ten hex-encoded random bit strings suitable for the SHA1, AES-128 CMAC, and other message digest algorithms. The message digest keys file  must be distributed and stored using secure means beyond the scope of  NTP  itself. Besides the keys used for ordinary NTP associations, additional keys can be defined as passwords for the <tt><a href="ntpq.html">ntpq</a></tt> and <tt><a href="ntpdc.html">ntpdc</a></tt> utility programs.</p>
 <p>The remaining generated files are compatible with other OpenSSL applications and other Public Key Infrastructure (PKI) resources. Certificates generated by this program are compatible with extant industry practice, although some users might find the interpretation of X509v3 extension fields somewhat liberal. However, the identity keys are probably not compatible with anything other than Autokey.</p>
 <p>Some files used by this program are encrypted using a private password. The <tt>-p</tt> option specifies the password for local encrypted files and the <tt>-q</tt> option the password for encrypted files sent to remote sites. If no  password is specified, the host name returned by the Unix <tt>gethostname()</tt> function, normally the DNS name of the host, is used.</p>
 <p>The <tt>pw</tt> option of the <tt>crypto</tt> configuration command specifies the read password for previously encrypted local files. This must match the local password used by this program. If not specified, the host name is used. Thus, if files are generated by this program without password, they can be read back by <tt>ntpd</tt> without password, but only on the same host.</p>
@@ -46,7 +46,7 @@
 <p>To test and gain experience with Autokey concepts, log in as root and change to the keys directory, usually <tt>/usr/local/etc</tt>. When run for the first time, or if all files with names beginning <tt>ntpkey</tt> have been removed, use the <tt>ntp-keygen </tt>command without arguments to generate a default RSA host key and matching RSA-MD5 certificate with expiration date one year hence. If run again without options, the program uses the existing keys and parameters and generates only a new certificate with new expiration date one year hence.</p>
 <p>Run the command on as many hosts as necessary. Designate one of them as the trusted host (TH) using <tt>ntp-keygen</tt> with the <tt>-T</tt> option and configure it to synchronize from reliable Internet servers. Then configure the other hosts to synchronize to the TH directly or indirectly. A certificate trail is created when Autokey asks the immediately ascendant host towards the TH to sign its certificate, which is then provided to the immediately descendant host on request. All group hosts should have acyclic certificate trails ending on the TH.</p>
 <p>The host key is used to encrypt the cookie when required and so must be RSA type. By default, the host key is also the sign key used to encrypt signatures. A different sign key can be assigned using the <tt>-S</tt> option and this can be either RSA or DSA type. By default, the signature message digest type is MD5, but any combination of sign key type and message digest type supported by the OpenSSL library can be specified using the <tt>-c</tt> option.</p>
-<dd>The rules say cryptographic media should be generated with proventic filestamps, which means the host should already be synchronized before this program is run. This of course creates a chicken-and-egg problem when the host is started for the first time. Accordingly, the host time should be set by some other means, such as eyeball-and-wristwatch, at least so that the certificate lifetime is within the current year. After that and when the host is synchronized to a proventic source, the certificate should be re-generated.</dd>
+<p>The rules say cryptographic media should be generated with proventic filestamps, which means the host should already be synchronized before this program is run. This of course creates a chicken-and-egg problem when the host is started for the first time. Accordingly, the host time should be set by some other means, such as eyeball-and-wristwatch, at least so that the certificate lifetime is within the current year. After that and when the host is synchronized to a proventic source, the certificate should be re-generated.</p>
 <p>Additional information on trusted groups and identity schemes is on the <a href="autokey.html">Autokey Public-Key Authentication</a> page.</p>
 <h4 id="cmd">Command Line Options</h4>
 <dl>
 <p>All files begin with two nonencrypted lines. The first line contains the file name in the format <tt>ntpkey_<i>key</i>_<i>host</i>.<i>fstamp</i></tt>. The second line contains the datestamp in conventional Unix <tt>date</tt> format. Lines beginning with <tt>#</tt> are ignored.</p>
 <p>The remainder of the file contains cryptographic data encoded first using ASN.1 rules, then encrypted using the DES-CBC algorithm with given password and finally written in PEM-encoded printable ASCII text preceded and followed by MIME content identifier lines.</p>
 <p>The format of the symmetric keys file, ordinarily named <tt>ntp.keys,</tt> is somewhat different than the other files in the interest of backward compatibility. Ordinarily, the file is generated by this program, but it can be constructed and edited using an ordinary text editor.</p>
-<div align="center">
-  <p><img src="pic/sx5.gif" alt="gif"></p>
-  <p>Figure 1. Typical Symmetric Key File</p>
-</div>
+<table>
+  <caption style="caption-side: bottom;">
+    Figure 1. Typical Symmetric Key File
+  </caption>
+  <tr><td style="border: 1px solid black; border-spacing: 0;">
+       <pre style="color:grey;">
+# ntpkey_MD5key_bk.ntp.org.3595864945
+# Thu Dec 12 19:22:25 2013
+
+1  MD5 L";Nw&lt;`.I&lt;f4U0)247"i  # MD5 key
+2  MD5 &amp;&gt;l0%XXK9O'51VwV&lt;xq~  # MD5 key
+3  MD5 lb4zLW~d^!K:]RsD'qb6  # MD5 key
+4  MD5 Yue:tL[+vR)M`n~bY,'?  # MD5 key
+5  MD5 B;fxlKgr/&amp;4ZTbL6=RxA  # MD5 key
+6  MD5 4eYwa`o}3i@@V@..R9!l  # MD5 key
+7  MD5 `A.([h+;wTQ|xfi%Sn_!  # MD5 key
+8  MD5 45:V,r4]l6y^JH6"Sh?F  # MD5 key
+9  MD5 3-5vcn*6l29DS?Xdsg)*  # MD5 key
+10 MD5 2late4Me              # MD5 key
+11 SHA1 a27872d3030a9025b8446c751b4551a7629af65c  # SHA1 key
+12 SHA1 21bc3b4865dbb9e920902abdccb3e04ff97a5e74  # SHA1 key
+13 SHA1 2b7736fe24fef5ba85ae11594132ab5d6f6daba9  # SHA1 key
+14 SHA  a5332809c8878dd3a5b918819108a111509aeceb  # SHA  key
+15 MD2  2fe16c88c760ff2f16d4267e36c1aa6c926e6964  # MD2  key
+16 MD4  b2691811dc19cfc0e2f9bcacd74213f29812183d  # MD4  key
+17 MD5  e4d6735b8bdad58ec5ffcb087300a17f7fef1f7c  # MD5  key
+18 MDC2 a8d5e2315c025bf3a79174c87fbd10477de2eabc  # MDC2 key
+19 RIPEMD160 77ca332cafb30e3cafb174dcd5b80ded7ba9b3d2  # RIPEMD160 key
+20 AES128CMAC f92ff73eee86c1e7dc638d6489a04e4e555af878  # AES128CMAC key
+  </pre></td></tr></table>
 <p>Figure 1 shows a typical symmetric keys file used by the reference implementation.  Each line of the file contains three fields, first an integer between 1 and 65534, inclusive, representing the key identifier used in the <tt>server</tt> and <tt>peer</tt> configuration commands. Next is the key type for the message digest algorithm, which in the absence of the OpenSSL library must be  <tt>MD5</tt> to designate the  MD5 message digest algorithm. If the OpenSSL library is installed, the key type can be any message digest algorithm supported by that library. However, if compatibility with FIPS 140-2 is required, the key type must be either <tt>SHA</tt> or <tt>SHA1</tt>. The key type can be changed using an ASCII text editor.</p>
 <p>   An MD5 key consists of a   printable ASCII string less than or equal to 16 characters and terminated by  whitespace or a # character.   An OpenSSL key consists of a hex-encoded ASCII string of 40 characters, which is truncated as necessary.</p>
 <p>Note that the keys used by the <tt>ntpq</tt> and <tt>ntpdc</tt> programs are checked against passwords requested by the programs and entered by hand, so it is generally appropriate to specify these keys in human readable ASCII format.</p>
 <p>The <tt>ntp-keygen</tt> program generates a MD5 symmetric keys file <tt>ntpkey_MD5key_<i>hostname.filestamp</i></tt>. Since the file contains private shared keys, it should be visible only to root and distributed by secure means to other subnet hosts. The NTP daemon loads the file <tt>ntp.keys</tt>, so <tt>ntp-keygen</tt> installs a soft link from this name to the generated file. Subsequently, similar soft links must be installed by manual or automated means on the other subnet hosts. While this file is not used with the Autokey Version 2 protocol, it is needed to authenticate some remote configuration commands used by the <a href="ntpq.html"><tt>ntpq</tt></a> and <a href="ntpdc.html"><tt>ntpdc</tt></a> utilities.</p>
 <h4 id="bug">Bugs</h4>
-<p>It can take quite a while to generate some cryptographic values, from one to several minutes with modern architectures such as UltraSPARC and up to tens of minutes to an hour with older architectures such as SPARC IPC.</p>
+<p>It can take quite a while to generate some cryptographic values.</p>
 <hr>
 <script type="text/javascript" language="javascript" src="scripts/footer.txt"></script>
 </body>
index 1aa8df3fcd29f46e1ad120808e285cc501e12683..6fe4dfc098200099462ff49cfde5d813636c17bf 100644 (file)
@@ -71,7 +71,7 @@
   <dt id="keyid"><tt>keyid <i>keyid</i></tt></dt>
   <dd>This command specifies the key number to be used to authenticate configuration requests. This must correspond to a key ID configured in <tt>ntp.conf</tt> for this purpose.</dd>
   <dt id="keytype"><tt>keytype</tt></dt>
-  <dd>Specify the digest algorithm to use for authenticated requests, with default <tt>MD5</tt>. If the OpenSSL library is installed, digest can be be any message digest algorithm supported by the library. The current selections are: <tt>MD2</tt>, <tt>MD4</tt>, <tt>MD5</tt>, <tt>MDC2</tt>, <tt>RIPEMD160</tt>, <tt>SHA</tt> and <tt>SHA1</tt>.</dd>
+  <dd>Specify the digest algorithm to use for authenticated requests, with default <tt>MD5</tt>. If the OpenSSL library is installed, digest can be be any message digest algorithm supported by the library. The current selections are: <tt>MD2</tt>, <tt>MD4</tt>, <tt>MD5</tt>, <tt>MDC2</tt>, <tt>RIPEMD160</tt>, <tt>SHA</tt>, <tt>SHA1</tt>, and <tt>AES128CMAC</tt>.</dd>
   <dt id="ntpversion"><tt>ntpversion 1 | 2 | 3 | 4</tt></dt>
   <dd>Sets the NTP version number which <tt>ntpq</tt> claims in packets. Defaults to 2, Note that mode-6 control messages (and modes, for that matter) didn't exist in NTP version 1.</dd>
   <dt id="passwd"><tt>passwd</tt></dt>
index 01b417a805169eb7d4912f772046aca82a41d487..71332644fe9d482c08a80a2e872eb10741c0c6e9 100644 (file)
@@ -7,6 +7,7 @@
 #define NTP_MD5_H
 
 #ifdef OPENSSL
+# include "openssl/cmac.h"
 # include "openssl/evp.h"
 # include "libssl_compat.h"
 #else  /* !OPENSSL follows */
index bebf6e1755310b79a0877e42d7b3a8938fc44332..bf3f0c04c92cb82016c27a530eebf1adfb9e71eb 100644 (file)
 #include <lib_strbuf.h>
 
 #ifdef OPENSSL
+#include "openssl/cmac.h"
 #include "openssl/crypto.h"
 #include "openssl/err.h"
 #include "openssl/evp.h"
 #include "openssl/opensslv.h"
 #include "libssl_compat.h"
 
+#define MD5_LENGTH     16
+#define CMAC_LENGTH    16
+#define CMAC           "AES128CMAC"
+
 int ssl_init_done;
 
 #if OPENSSL_VERSION_NUMBER < 0x10100000L
@@ -26,8 +31,9 @@ int ssl_init_done;
 static void
 atexit_ssl_cleanup(void)
 {
-       if (!ssl_init_done)
+       if (!ssl_init_done) {
                return;
+       }
 
        ssl_init_done = FALSE;
        EVP_cleanup();
@@ -103,46 +109,69 @@ keytype_from_text(
        /*
         * OpenSSL digest short names are capitalized, so uppercase the
         * digest name before passing to OBJ_sn2nid().  If it is not
-        * recognized but begins with 'M' use NID_md5 to be consistent
-        * with past behavior.
+        * recognized but matches our CMAC string use NID_cmac, or if
+        * it begins with 'M' use NID_md5 to be consistent with past
+        * behavior.
         */
        INIT_SSL();
        LIB_GETBUF(upcased);
        strlcpy(upcased, text, LIB_BUFLENGTH);
-       for (pch = upcased; '\0' != *pch; pch++)
+
+       for (pch = upcased; '\0' != *pch; pch++) {
                *pch = (char)toupper((unsigned char)*pch);
+       }
+
        key_type = OBJ_sn2nid(upcased);
+
+       if (!key_type && !strncmp(CMAC, upcased, strlen(CMAC) + 1)) {
+               key_type = NID_cmac;
+       }
 #else
        key_type = 0;
 #endif
 
-       if (!key_type && 'm' == tolower((unsigned char)text[0]))
+       if (!key_type && 'm' == tolower((unsigned char)text[0])) {
                key_type = NID_md5;
+       }
 
-       if (!key_type)
+       if (!key_type) {
                return 0;
+       }
 
        if (NULL != pdigest_len) {
 #ifdef OPENSSL
-               EVP_MD_CTX      *ctx;
+               EVP_MD *        md;
 
-               ctx = EVP_MD_CTX_new();
-               EVP_DigestInit(ctx, EVP_get_digestbynid(key_type));
-               EVP_DigestFinal(ctx, digest, &digest_len);
-               EVP_MD_CTX_free(ctx);
-               if (digest_len > max_digest_len) {
+               md = EVP_get_digestbynid(key_type);
+               digest_len = (md) ? EVP_MD_size(md) : 0;
+
+               if (!md || digest_len <= 0) {
+                   if (key_type == NID_cmac) {
+                       digest_len = CMAC_LENGTH;
+                   } else {
                        fprintf(stderr,
-                               "key type %s %u octet digests are too big, max %lu\n",
-                               keytype_name(key_type), digest_len,
-                               max_digest_len);
+                               "key type %s is not supported by OpenSSL\n",
+                               keytype_name(key_type));
                        msyslog(LOG_ERR,
-                               "key type %s %u octet digests are too big, max %lu",
-                               keytype_name(key_type), digest_len,
-                               max_digest_len);
+                               "key type %s is not supported by OpenSSL\n",
+                               keytype_name(key_type));
                        return 0;
+                   }
+               }
+
+               if (digest_len > max_digest_len) {
+                   fprintf(stderr,
+                           "key type %s %u octet digests are too big, max %lu\n",
+                           keytype_name(key_type), digest_len,
+                           max_digest_len);
+                   msyslog(LOG_ERR,
+                           "key type %s %u octet digests are too big, max %lu",
+                           keytype_name(key_type), digest_len,
+                           max_digest_len);
+                   return 0;
                }
 #else
-               digest_len = 16;
+               digest_len = MD5_LENGTH;
 #endif
                *pdigest_len = digest_len;
        }
@@ -167,8 +196,13 @@ keytype_name(
 #ifdef OPENSSL
        INIT_SSL();
        name = OBJ_nid2sn(nid);
-       if (NULL == name)
+
+       if (NID_cmac == nid) {
+               name = CMAC;
+       } else
+       if (NULL == name) {
                name = unknown_type;
+       }
 #else  /* !OPENSSL follows */
        if (NID_md5 == nid)
                name = "MD5";
@@ -203,3 +237,4 @@ getpass_keytype(
 
        return getpass(pass_prompt);
 }
+
index bfc5fa9cfad0fe815e27b3ab3eb6158a1a8fefcc..2efc7c74cbbaff767004254739f2687c43541359 100644 (file)
@@ -35,6 +35,8 @@
 #include "openssl/objects.h"
 #include "openssl/err.h"
 #include "libssl_compat.h"
+
+#define CMAC "AES128CMAC"
 #endif
 #include <ssl_applink.c>
 
@@ -459,6 +461,17 @@ ntpqmain(
 {
        u_int ihost;
        size_t icmd;
+#ifdef OPENSSL
+# ifdef HAVE_EVP_MD_DO_ALL_SORTED
+#  define K_PER_LINE 8
+#  define K_NL_PFX_STR "\n    "
+#  define K_DELIM_STR ", "
+
+       int nl;
+       int append;
+       size_t len;
+# endif
+#endif
 
 
 #ifdef SYS_VXWORKS
@@ -495,6 +508,52 @@ ntpqmain(
 
 #ifdef OPENSSL
            builtins[icmd].desc[0] = "digest-name";
+
+# ifdef HAVE_EVP_MD_DO_ALL_SORTED
+           /* Append CMAC to SSL digests */
+
+           /* If list empty, we need to append CMAC and new line */
+           append = nl = (!list || !*list);
+
+           if (append) {
+               len = strlen(K_NL_PFX_STR) + strlen(CMAC);
+               list = (char *)erealloc(list, len + 1);
+               list[0] = '\0';
+           } else {
+               /* Check if CMAC already in list */
+               const char *cmac_sn;
+               char *cmac_p;
+
+               cmac_sn = OBJ_nid2sn(NID_cmac);
+               cmac_p = strstr(list, cmac_sn);
+
+               /* CMAC in list if found followed by null or "," */
+               if (cmac_p)
+                       cmac_p += strlen(cmac_sn);
+
+               append = !(cmap_p && (!*cmap_p || ',' == *cmap_p));
+
+               if (append) {
+                   char *last_nl;
+
+                   len = strlen(list) + strlen(CMAC);
+                   /* Check if new entry will fit on last line */
+                   last_nl = strrchr(list, "\n");
+                   if (!last_nl)       last_nl = list;
+                   /* Do we need a new line? */
+                   nl = (len - (last_nl - list) + strlen(K_DELIM_STR) > 72);
+                   len += (nl) ? strlen(K_NL_PFX_STR) : strlen(K_DELIM_STR);
+                   list = (char *)erealloc(list, len + 1);
+               }
+           }
+
+           /* Check if we need to append an entry */
+           if (append)
+               sprintf(list + strlen(list), "%s%s",
+                       ((nl) ? K_NL_PFX_STR : K_DELIM_STR),
+                       CMAC);
+# endif
+
            my_easprintf(&msg,
                         "set key type to use for authenticated requests, one of:%s",
                         list);
@@ -3575,9 +3634,8 @@ struct hstate {
    const char **seen;
    int idx;
 };
-#define K_PER_LINE 8
-#define K_NL_PFX_STR "\n    "
-#define K_DELIM_STR ", "
+
+
 static void list_md_fn(const EVP_MD *m, const char *from, const char *to, void *arg )
 {
     size_t len, n;
index 7b448299607d6b8450ce006621e1afe9db59728e..eac3f1065733f4f1f2a418642b343cac8ad85ecc 100755 (executable)
@@ -1,4 +1,4 @@
-@echo off
+@echo on
 GOTO PROG
 
 see notes/remarks directly below this header:
@@ -142,6 +142,8 @@ REM ****************************************************************************
        IF NOT EXIST %TEMP%\TZ-%GENERATED_PROGRAM%.TMP GOTO NOTZINFO
 
        for /f "Tokens=1* Delims==" %%a in ('type %TEMP%\TZ-%GENERATED_PROGRAM%.TMP') do if %%a == "ActiveTimeBias" SET ACTIVEBIAS=%%b
+       REM Windows 10 - Home and possibly others
+       IF "%ACTIVEBIAS%" == "" for /f "Tokens=1* Delims==" %%a in ('type %TEMP%\TZ-%GENERATED_PROGRAM%.TMP') do if %%a == "Bias" SET ACTIVEBIAS=%%b
        for /f "Tokens=1* Delims=:" %%a in ('echo %ACTIVEBIAS%') do ( SET ACTIVEBIAS=%%b & SET PARTYP=%%a )
        
        REM *** Clean up temporary file
index e45b21360aa9bb3e3834143b27ff14003ca12230..b0b360c8016eaf9f5a6660daf2a7555b9b3ce6c3 100644 (file)
@@ -18,7 +18,6 @@ make_mac(
 {
        u_int           len = mac_size;
        int             key_type;
-       EVP_MD_CTX *    ctx;
        
        if (cmp_key->key_len > 64)
                return 0;
@@ -27,13 +26,80 @@ make_mac(
 
        INIT_SSL();
        key_type = keytype_from_text(cmp_key->type, NULL);
-       
-       ctx = EVP_MD_CTX_new();
-       EVP_DigestInit(ctx, EVP_get_digestbynid(key_type));
-       EVP_DigestUpdate(ctx, (const u_char *)cmp_key->key_seq, (u_int)cmp_key->key_len);
-       EVP_DigestUpdate(ctx, pkt_data, (u_int)pkt_size);
-       EVP_DigestFinal(ctx, digest, &len);
-       EVP_MD_CTX_free(ctx);
+
+#ifdef OPENSSL
+       /* Check if CMAC key type specific code required */
+       if (key_type = NID_cmac) {
+           CMAC_CTX *      ctx;
+
+           if (!(ctx = CMAC_CTX_new())) {
+               fprintf(stderr,  "make_mac: CMAC %s CTX new failed.\n", CMAC);
+               msyslog(LOG_ERR, "make_mac: CMAC %s CTX new failed.",   CMAC);
+           } else
+           if (!CMAC_Init(ctx, (const u_char *)cmp_key->key_seq,
+                       (u_int)cmp_key->key_len, EVP_aes_128_cbc(), NULL)) {
+               fprintf(stderr,  "make_mac: CMAC %s Init failed.\n",    CMAC);
+               msyslog(LOG_ERR, "make_mac: CMAC %s Init failed.",      CMAC);
+           } else
+           if (!CMAC_Update(ctx, pkt_data, (u_int)pkt_size)) {
+               fprintf(stderr,  "make_mac: CMAC %s Update failed.\n",  CMAC);
+               msyslog(LOG_ERR, "make_mac: CMAC %s Update failed.",    CMAC);
+           } else
+           if (!CMAC_Final(ctx, digest, &len)) {
+               fprintf(stderr,  "make_mac: CMAC %s Final failed.\n",   CMAC);
+               msyslog(LOG_ERR, "make_mac: CMAC %s Final failed.",     CMAC);
+           }
+
+           CMAC_CTX_cleanup(ctx);
+       } else {        /* generic MAC handling */
+#endif
+           EVP_MD_CTX *        ctx;
+
+#ifdef OPENSSL
+           if (!(ctx = EVP_MD_CTX_new())) {
+               fprintf(stderr,  "make_mac: MAC %s Digest CTX new failed.\n",
+                                                       cmp_key->type);
+               msyslog(LOG_ERR, "make_mac: MAC %s Digest CTX new failed.",
+                                                       cmp_key->type);
+           } else
+           if (!EVP_DigestInit(ctx, EVP_get_digestbynid(key_type))) {
+               fprintf(stderr,  "make_mac: MAC %s Digest Init failed.\n",
+                                                       cmp_key->type);
+               msyslog(LOG_ERR, "make_mac: MAC %s Digest Init failed.",
+                                                       cmp_key->type);
+           } else
+           if (!EVP_DigestUpdate(ctx, (const u_char *)cmp_key->key_seq,
+                                               (u_int)cmp_key->key_len)) {
+               fprintf(stderr,  "make_mac: MAC %s Digest Update key failed.\n",
+                                                       cmp_key->type);
+               msyslog(LOG_ERR, "make_mac: MAC %s Digest Update key failed.",
+                                                       cmp_key->type);
+           } else
+           if (!EVP_DigestUpdate(ctx, pkt_data, (u_int)pkt_size)) {
+               fprintf(stderr,  "make_mac: MAC %s Digest Update data failed.\n",
+                                                       cmp_key->type);
+               msyslog(LOG_ERR, "make_mac: MAC %s Digest Update data failed.",
+                                                       cmp_key->type);
+           } else
+           if (!EVP_DigestFinal(ctx, digest, &len)) {
+               fprintf(stderr,  "make_mac: MAC %s Digest Final failed.\n",
+                                                       cmp_key->type);
+               msyslog(LOG_ERR, "make_mac: MAC %s Digest Final failed.",
+                                                       cmp_key->type);
+           }
+#else /* !OPENSSL */
+           ctx = EVP_MD_CTX_new();
+           EVP_DigestInit(ctx, EVP_get_digestbynid(key_type));
+           EVP_DigestUpdate(ctx, (const u_char *)cmp_key->key_seq,
+                                               (u_int)cmp_key->key_len);
+           EVP_DigestUpdate(ctx, pkt_data, (u_int)pkt_size);
+           EVP_DigestFinal(ctx, digest, &len);
+#endif
+
+           EVP_MD_CTX_free(ctx);
+#ifdef OPENSSL
+       }
+#endif
        
        return (int)len;
 }
index fb2dc62981f35fc25068d7388eb4de1dca5f0e6a..61323c505370fa105ba339e448da5d352102fb78 100644 (file)
@@ -5,14 +5,19 @@
 #include "sntptest.h"
 #include "crypto.h"
 
+#define CMAC "AES128CMAC"
+
 #define MD5_LENGTH 16
 #define SHA1_LENGTH 20
+#define CMAC_LENGTH 16
 
 
 void test_MakeMd5Mac(void);
 void test_MakeSHA1Mac(void);
+void test_MakeCMac(void);
 void test_VerifyCorrectMD5(void);
 void test_VerifySHA1(void);
+void test_VerifyCMAC(void);
 void test_VerifyFailure(void);
 void test_PacketSizeNotMultipleOfFourBytes(void);
 
@@ -72,6 +77,38 @@ test_MakeSHA1Mac(void)
 }
 
 
+void
+test_MakeCMac(void)
+{
+#ifdef OPENSSL
+
+       const char* PKT_DATA = "abcdefgh0123";
+       const int PKT_LEN = strlen(PKT_DATA);
+       const char* EXPECTED_DIGEST =
+               "\xdd\x35\xd5\xf5\x14\x23\xd9\xd6"
+               "\x38\x5d\x29\x80\xfe\x51\xb9\x6b";
+       char actual[CMAC_LENGTH];
+
+       struct key cmac;
+       cmac.next = NULL;
+       cmac.key_id = 30;
+       cmac.key_len = CMAC_LENGTH;
+       memcpy(&cmac.key_seq, "aes-128-cmac-seq", cmac.key_len);
+       memcpy(&cmac.type, CMAC, strlen(CMAC) + 1);
+
+       TEST_ASSERT_EQUAL(CMAC_LENGTH,
+                   make_mac(PKT_DATA, PKT_LEN, CMAC_LENGTH, &cmac, actual));
+
+       TEST_ASSERT_EQUAL_MEMORY(EXPECTED_DIGEST, actual, CMAC_LENGTH);
+       
+#else
+       
+       TEST_IGNORE_MESSAGE("OpenSSL not found, skipping...");
+       
+#endif /* OPENSSL */
+}
+
+
 void
 test_VerifyCorrectMD5(void)
 {
@@ -121,6 +158,36 @@ test_VerifySHA1(void)
 #endif /* OPENSSL */
 }
 
+
+void
+test_VerifyCMAC(void)
+{
+#ifdef OPENSSL
+
+       const char* PKT_DATA =
+           "sometestdata"                              /* Data */
+           "\0\0\0\0"                                  /* Key-ID (unused) */
+           "\x4e\x0c\xf0\xe2\xc7\x8e\xbb\xbf"          /* MAC */
+           "\x79\xfc\x87\xc7\x8b\xb7\x4a\x0b";
+       const int PKT_LEN = 12;
+
+       struct key cmac;
+       cmac.next = NULL;
+       cmac.key_id = 0;
+       cmac.key_len = CMAC_LENGTH;
+       memcpy(&cmac.key_seq, "aes-128-cmac-key", cmac.key_len);
+       memcpy(&cmac.type, CMAC, strlen(CMAC) + 1);
+
+       TEST_ASSERT_TRUE(auth_md5(PKT_DATA, PKT_LEN, CMAC_LENGTH, &cmac));
+       
+#else
+       
+       TEST_IGNORE_MESSAGE("OpenSSL not found, skipping...");
+       
+#endif /* OPENSSL */
+}
+
+
 void
 test_VerifyFailure(void)
 {
index 660b5b6e20f15916fbb6a77046d99899a7c609c6..ef03cb1f6a78ed523c6effaec2605e7d939064fd 100644 (file)
@@ -5,6 +5,8 @@
 #include "ntp_stdlib.h"
 #include "unity.h"
 
+#define CMAC "AES128CMAC"
+
 
 const char * Version = "stub unit test Version string";
 
@@ -35,6 +37,7 @@ void test_AcceptNoSentPacketBroadcastMode(void);
 void test_CorrectUnauthenticatedPacket(void);
 void test_CorrectAuthenticatedPacketMD5(void);
 void test_CorrectAuthenticatedPacketSHA1(void);
+void test_CorrectAuthenticatedPacketCMAC(void);
 
 /* [Bug 2998] There are some issues whith the definition of 'struct pkt'
  * when AUTOKEY is undefined -- the formal struct is too small to hold
@@ -455,3 +458,26 @@ test_CorrectAuthenticatedPacketSHA1(void)
                          process_pkt(&testpkt.p, &testsock, pkt_len,
                                      MODE_SERVER, &testspkt.p, "UnitTest"));
 }
+
+
+void
+test_CorrectAuthenticatedPacketCMAC(void)
+{
+       PrepareAuthenticationTest(30, 15, CMAC, "abcdefghijklmno");
+       TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
+
+       int pkt_len = LEN_PKT_NOMAC;
+
+       /* Prepare the packet. */
+       testpkt.p.exten[0] = htonl(20);
+       int mac_len = make_mac(&testpkt.p, pkt_len,
+                              MAX_MAC_LEN, key_ptr,
+                              &testpkt.p.exten[1]);
+
+       pkt_len += 4 + mac_len;
+
+       TEST_ASSERT_EQUAL(pkt_len,
+                         process_pkt(&testpkt.p, &testsock, pkt_len,
+                                     MODE_SERVER, &testspkt.p, "UnitTest"));
+}
+
index 435e5c912fd602bbe19767a606c88ce66e2f2782..9a59a9b42548e7c94c420503703bd7f7dd63adb8 100644 (file)
@@ -6,6 +6,8 @@
 # include "openssl/err.h"
 # include "openssl/rand.h"
 # include "openssl/evp.h"
+
+#define CMAC "AES128CMAC"
 #endif
 
 #include "unity.h"
 
 static const size_t TEST_MD5_DIGEST_LENGTH = 16;
 static const size_t TEST_SHA1_DIGEST_LENGTH = 20;
+static const size_t TEST_CMAC_DIGEST_LENGTH = 16;
 
 void test_MD5KeyTypeWithoutDigestLength(void);
 void test_MD5KeyTypeWithDigestLength(void);
 void test_SHA1KeyTypeWithDigestLength(void);
+void test_CMACKeyTypeWithDigestLength(void);
 void test_MD5KeyName(void);
 void test_SHA1KeyName(void);
+void test_CMACKeyName(void);
 
 
 // keytype_from_text()
@@ -52,6 +57,21 @@ test_SHA1KeyTypeWithDigestLength(void) {
 }
 
 
+void
+test_CMACKeyTypeWithDigestLength(void) {
+#ifdef OPENSSL
+       size_t digestLength;
+       size_t expected = TEST_CMAC_DIGEST_LENGTH;
+
+       TEST_ASSERT_EQUAL(NID_cmac, keytype_from_text(CMAC, &digestLength));
+       TEST_ASSERT_EQUAL(expected, digestLength);
+       /* OPENSSL */
+#else 
+       TEST_IGNORE_MESSAGE("Skipping because OPENSSL isn't defined");
+#endif
+}
+
+
 // keytype_name()
 void
 test_MD5KeyName(void) {
@@ -67,3 +87,14 @@ test_SHA1KeyName(void) {
        TEST_IGNORE_MESSAGE("Skipping because OPENSSL isn't defined");
 #endif /* OPENSSL */
 }
+
+
+void
+test_CMACKeyName(void) {
+#ifdef OPENSSL
+       TEST_ASSERT_EQUAL_STRING(CMAC, keytype_name(NID_cmac));
+#else
+       TEST_IGNORE_MESSAGE("Skipping because OPENSSL isn't defined");
+#endif /* OPENSSL */
+}
+
index 3088cf52804c55e2c609d75be29b44629fba11c6..5df2ddf3a57a8a890cdf35322e8b1c165ed9b152 100644 (file)
@@ -297,8 +297,8 @@ When used to generate message digest keys, the program produces a file
 containing ten pseudo-random printable ASCII strings suitable for the
 MD5 message digest algorithm included in the distribution.
 If the OpenSSL library is installed, it produces an additional ten
-hex-encoded random bit strings suitable for the SHA1 and other message
-digest algorithms.
+hex-encoded random bit strings suitable for the SHA1, AES-128-CMAC, and
+other message digest algorithms.
 The message digest keys file must be distributed and stored
 using secure means beyond the scope of NTP itself.
 Besides the keys used for ordinary NTP associations, additional keys
@@ -1054,8 +1054,7 @@ The format of the symmetric keys file is somewhat different
 than the other files in the interest of backward compatibility.
 Since DES-CBC is deprecated in NTPv4, the only key format of interest
 is MD5 alphanumeric strings.
-Following hte heard the keys are
-entered one per line in the format
+Following the header the keys are entered one per line in the format
 .D1 Ar keyno type key
 where
 .Ar keyno
@@ -1134,10 +1133,7 @@ doc-section      = {
   ds-type      = 'BUGS';
   ds-format    = 'mdoc';
   ds-text      = <<- _END_MDOC_BUGS
-It can take quite a while to generate some cryptographic values,
-from one to several minutes with modern architectures
-such as UltraSPARC and up to tens of minutes to an hour
-with older architectures such as SPARC IPC.
+It can take quite a while to generate some cryptographic values.
 .Pp
 Please report bugs to http://bugs.ntp.org .
        _END_MDOC_BUGS;