]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
keys: warn about short key only if used by source
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 25 Jan 2016 15:50:51 +0000 (16:50 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 29 Jan 2016 16:55:58 +0000 (17:55 +0100)
After restricting authentication of servers and peers to the specified
key, a short key in the key file is a security problem from the client's
point of view only if it's specified for a source.

keys.c
keys.h
ntp_core.c

diff --git a/keys.c b/keys.c
index 0fc9d4eb0de21d94820d2ab28ceb2ffeb9da3f82..4af7eb689181b5c2b5942e82d4d36338e9875049 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -198,9 +198,6 @@ KEY_Reload(void)
       continue;
     }
 
-    if (key.len < MIN_SECURE_KEY_LENGTH)
-      LOG(LOGS_WARN, LOGF_Keys, "Key %"PRIu32" is too short", key_id);
-
     key.id = key_id;
     key.val = MallocArray(char, key.len);
     memcpy(key.val, keyval, key.len);
@@ -295,6 +292,21 @@ KEY_GetAuthDelay(uint32_t key_id)
 
 /* ================================================== */
 
+int
+KEY_CheckKeyLength(uint32_t key_id)
+{
+  Key *key;
+
+  key = get_key_by_id(key_id);
+
+  if (!key)
+    return 0;
+
+  return key->len >= MIN_SECURE_KEY_LENGTH;
+}
+
+/* ================================================== */
+
 int
 KEY_GenerateAuth(uint32_t key_id, const unsigned char *data, int data_len,
     unsigned char *auth, int auth_len)
diff --git a/keys.h b/keys.h
index e6e51aab2109f1165c614fa29c8700fd74fb0acb..65536cff0680486da283803c0998c7fe0b33a7c0 100644 (file)
--- a/keys.h
+++ b/keys.h
@@ -37,6 +37,7 @@ extern void KEY_Reload(void);
 extern int KEY_GetKey(uint32_t key_id, char **key, int *len);
 extern int KEY_KeyKnown(uint32_t key_id);
 extern int KEY_GetAuthDelay(uint32_t key_id);
+extern int KEY_CheckKeyLength(uint32_t key_id);
 
 extern int KEY_GenerateAuth(uint32_t key_id, const unsigned char *data,
     int data_len, unsigned char *auth, int auth_len);
index 8428642e68f3cae0968de002d162a77cae315079..4087c98636af26d56a5d00e56ede31e15c5674f8 100644 (file)
@@ -497,8 +497,13 @@ NCR_GetInstance(NTP_Remote_Address *remote_addr, NTP_Source_Type type, SourcePar
     result->do_auth = 1;
     result->auth_key_id = params->authkey;
     if (!KEY_KeyKnown(result->auth_key_id)) {
-      LOG(LOGS_WARN, LOGF_NtpCore, "Source %s added with unknown key %"PRIu32,
-          UTI_IPToString(&result->remote_addr.ip_addr), result->auth_key_id);
+      LOG(LOGS_WARN, LOGF_NtpCore, "Key %"PRIu32" used by source %s is %s",
+          result->auth_key_id, UTI_IPToString(&result->remote_addr.ip_addr),
+          "missing");
+    } else if (!KEY_CheckKeyLength(result->auth_key_id)) {
+      LOG(LOGS_WARN, LOGF_NtpCore, "Key %"PRIu32" used by source %s is %s",
+          result->auth_key_id, UTI_IPToString(&result->remote_addr.ip_addr),
+          "too short");
     }
   }