]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: restrict authentication of server/peer to specified key
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 8 Jan 2016 14:03:09 +0000 (15:03 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 19 Jan 2016 07:15:12 +0000 (08:15 +0100)
When a server/peer was specified with a key number to enable
authentication with a symmetric key, packets received from the
server/peer were accepted if they were authenticated with any of
the keys contained in the key file and not just the specified key.

This allowed an attacker who knew one key of a client/peer to modify
packets from its servers/peers that were authenticated with other
keys in a man-in-the-middle (MITM) attack. For example, in a network
where each NTP association had a separate key and all hosts had only
keys they needed, a client of a server could not attack other clients
of the server, but it could attack the server and also attack its own
clients (i.e. modify packets from other servers).

To not allow the server/peer to be authenticated with other keys
extend the authentication test to check if the key ID in the received
packet is equal to the configured key number. As a consequence, it's
no longer possible to authenticate two peers to each other with two
different keys, both peers have to be configured to use the same key.

This issue was discovered by Matt Street of Cisco ASIG.

chrony.texi.in
ntp_core.c

index 8ce658b7e4fe99c5e431914a8126bee56ba47166..56b2758e01a8fcb27b931fc569bf41fa2b2d18f4 100644 (file)
@@ -2461,6 +2461,9 @@ The syntax of this directive is identical to that for the @code{server}
 directive (@pxref{server directive}), except that it is used to specify
 an NTP peer rather than an NTP server.
 
+When a key is specified by the @code{key} option to enable authentication, both
+peers must be configured to use the same key and the same key number.
+
 Please note that NTP peers that are not configured with a key to enable
 authentication are vulnerable to a denial-of-service attack.  An attacker
 knowing that NTP hosts A and B are peering with each other can send a packet
index e654c880473442ab0bc812b60b59c1f8ed70fec4..9594c7ebffb10b598b3c76ab0a75ee834bb16ffd 100644 (file)
@@ -1140,7 +1140,8 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins
   if (inst->do_auth) {
     if (auth_len > 0) {
       auth_key_id = ntohl(message->auth_keyid);
-      test5 = check_packet_auth(message, auth_key_id, auth_len);
+      test5 = check_packet_auth(message, auth_key_id, auth_len) &&
+              auth_key_id == inst->auth_key_id;
     } else {
       /* If we expect authenticated info from this peer/server and the packet
          doesn't have it, it's got to fail */