pgreco / rpms / cockpit

Forked from forks/areguera/rpms/cockpit 5 years ago
Clone

Blame SOURCES/0001-ssh-Use-SHA256-fingerprints-when-available.patch

9bca77
From 50873a820f9d9c655b93e8ff2d4158aff29761ff Mon Sep 17 00:00:00 2001
9bca77
From: Martin Pitt <martin@piware.de>
9bca77
Date: Mon, 8 Oct 2018 15:19:02 +0200
9bca77
Subject: [PATCH 1/2] ssh: Use SHA256 fingerprints when available
9bca77
9bca77
libssh 0.8 offers SHA256 fingerprints in addition to the old MD5/SHA1
9bca77
ones. The latter are both cryptographically broken, and not allowed when
9bca77
running in FIPS mode -- these cause an assertion crash in OpenSSL.
9bca77
9bca77
The "ssh" CLI hasn't shown MD5 fingerprints in a long time, not even on
9bca77
RHEL 7 (it shows SHA1 and SHA256 there by default), so this actually
9bca77
improves compatibility with ssh.
9bca77
9bca77
Use libssh 0.8's ssh_get_fingerprint_hash() function, as ssh itself
9bca77
shows SHA256 fingerprints  in base64 instead of hex. cockpit-ssh's
9bca77
fingerprint prompts should be compatible, and hex fingerprints would be
9bca77
overly long.
9bca77
9bca77
Adjust most check-multi-machine tests to not care about the particular
9bca77
type of fingerprint, as they don't check the actual fingerprint anyway.
9bca77
Only `TestMultiMachine.testDirectLogin` does, so adjust the test to
9bca77
accept both MD5 and SHA256 fingerprints.
9bca77
9bca77
https://bugzilla.redhat.com/show_bug.cgi?id=1585191
9bca77
9bca77
Closes #10241
9bca77
---
9bca77
 configure.ac              |  2 ++
9bca77
 src/ssh/cockpitsshrelay.c | 17 +++++++++++++++--
9bca77
 src/ssh/test-sshbridge.c  |  8 +++++++-
9bca77
 3 files changed, 24 insertions(+), 3 deletions(-)
9bca77
9bca77
diff --git a/configure.ac b/configure.ac
9bca77
index af8b1e3..b0d4879 100644
9bca77
--- a/configure.ac
9bca77
+++ b/configure.ac
9bca77
@@ -132,6 +132,8 @@ if test "$enable_ssh" != "no"; then
9bca77
     AC_DEFINE_UNQUOTED(HAVE_SSH_GET_SERVER_PUBLICKEY, 1, Whether ssh_get_server_publickey is available)
9bca77
   ])
9bca77
 
9bca77
+  AC_CHECK_DECLS([SSH_PUBLICKEY_HASH_SHA256, ssh_get_fingerprint_hash], [], [], [[#include <libssh/libssh.h>]])
9bca77
+
9bca77
   COCKPIT_SSH_SESSION_CFLAGS="$COCKPIT_CFLAGS $LIBSSH_CFLAGS $KRB5_CFLAGS"
9bca77
   COCKPIT_SSH_SESSION_LIBS="$COCKPIT_LIBS $LIBSSH_LIBS $KRB5_LIBS"
9bca77
   AC_SUBST(COCKPIT_SSH_SESSION_LIBS)
9bca77
diff --git a/src/ssh/cockpitsshrelay.c b/src/ssh/cockpitsshrelay.c
9bca77
index 41286c3..1798345 100644
9bca77
--- a/src/ssh/cockpitsshrelay.c
9bca77
+++ b/src/ssh/cockpitsshrelay.c
9bca77
@@ -52,6 +52,15 @@
9bca77
 #include <fcntl.h>
9bca77
 #include <time.h>
9bca77
 
9bca77
+/* libssh 0.8 offers SHA256 fingerprints, use them if available */
9bca77
+#if HAVE_DECL_SSH_PUBLICKEY_HASH_SHA256
9bca77
+#define SSH_PUBLICKEY_HASH SSH_PUBLICKEY_HASH_SHA256
9bca77
+#define SSH_PUBLICKEY_HASH_NAME "SHA256"
9bca77
+#else
9bca77
+#define SSH_PUBLICKEY_HASH SSH_PUBLICKEY_HASH_MD5
9bca77
+#define SSH_PUBLICKEY_HASH_NAME "MD5"
9bca77
+#endif
9bca77
+
9bca77
 /* we had a private one before moving to /etc/ssh/ssh_known_hosts */
9bca77
 #define LEGACY_KNOWN_HOSTS PACKAGE_LOCALSTATE_DIR "/known_hosts"
9bca77
 
9bca77
@@ -505,7 +514,7 @@ prompt_for_host_key (CockpitSshData *data)
9bca77
 
9bca77
   message = g_strdup_printf ("The authenticity of host '%s:%d' can't be established. Do you want to proceed this time?",
9bca77
                              host, port);
9bca77
-  prompt = g_strdup_printf ("MD5 Fingerprint (%s):", data->host_key_type);
9bca77
+  prompt = g_strdup_printf (SSH_PUBLICKEY_HASH_NAME " Fingerprint (%s):", data->host_key_type);
9bca77
 
9bca77
   reply = prompt_with_authorize (data, prompt, message, data->host_fingerprint, data->host_key, TRUE);
9bca77
 
9bca77
@@ -674,7 +683,7 @@ verify_knownhost (CockpitSshData *data,
9bca77
       goto done;
9bca77
     }
9bca77
 
9bca77
-  if (ssh_get_publickey_hash (key, SSH_PUBLICKEY_HASH_MD5, &hash, &len) < 0)
9bca77
+  if (ssh_get_publickey_hash (key, SSH_PUBLICKEY_HASH, &hash, &len) < 0)
9bca77
     {
9bca77
       g_warning ("Couldn't hash ssh public key");
9bca77
       ret = "internal-error";
9bca77
@@ -682,7 +691,11 @@ verify_knownhost (CockpitSshData *data,
9bca77
     }
9bca77
   else
9bca77
     {
9bca77
+#if HAVE_DECL_SSH_GET_FINGERPRINT_HASH
9bca77
+      data->host_fingerprint = ssh_get_fingerprint_hash (SSH_PUBLICKEY_HASH, hash, len);
9bca77
+#else
9bca77
       data->host_fingerprint = ssh_get_hexa (hash, len);
9bca77
+#endif
9bca77
       ssh_clean_pubkey_hash (&hash);
9bca77
     }
9bca77
 
9bca77
diff --git a/src/ssh/test-sshbridge.c b/src/ssh/test-sshbridge.c
9bca77
index e86f639..bc5bc3a 100644
9bca77
--- a/src/ssh/test-sshbridge.c
9bca77
+++ b/src/ssh/test-sshbridge.c
9bca77
@@ -563,7 +563,13 @@ test_echo_large (TestCase *tc,
9bca77
 
9bca77
 static const gchar MOCK_RSA_KEY[] = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCYzo07OA0H6f7orVun9nIVjGYrkf8AuPDScqWGzlKpAqSipoQ9oY/mwONwIOu4uhKh7FTQCq5p+NaOJ6+Q4z++xBzSOLFseKX+zyLxgNG28jnF06WSmrMsSfvPdNuZKt9rZcQFKn9fRNa8oixa+RsqEEVEvTYhGtRf7w2wsV49xIoIza/bln1ABX1YLaCByZow+dK3ZlHn/UU0r4ewpAIZhve4vCvAsMe5+6KJH8ft/OKXXQY06h6jCythLV4h18gY/sYosOa+/4XgpmBiE7fDeFRKVjP3mvkxMpxce+ckOFae2+aJu51h513S9kxY2PmKaV/JU9HBYO+yO4j+j24v";
9bca77
 
9bca77
+#if HAVE_DECL_SSH_PUBLICKEY_HASH_SHA256
9bca77
+static const gchar MOCK_RSA_FP[] = "SHA256:XQ8a7zGxMFstDrGecBRUP9OMnOUXd/T3vkNGtYShs2w";
9bca77
+#define SSH_PUBLICKEY_HASH_NAME "SHA256"
9bca77
+#else
9bca77
 static const gchar MOCK_RSA_FP[] = "0e:6a:c8:b1:07:72:e2:04:95:9f:0e:b3:56:af:48:e2";
9bca77
+#define SSH_PUBLICKEY_HASH_NAME "MD5"
9bca77
+#endif
9bca77
 
9bca77
 
9bca77
 static void
9bca77
@@ -634,7 +640,7 @@ do_hostkey_conversation (TestCase *tc,
9bca77
                                  (int)tc->ssh_port, MOCK_RSA_FP,
9bca77
                                  (int)tc->ssh_port, MOCK_RSA_KEY);
9bca77
 
9bca77
-  do_auth_conversation (tc->transport, "MD5 Fingerprint (ssh-rsa):",
9bca77
+  do_auth_conversation (tc->transport, SSH_PUBLICKEY_HASH_NAME " Fingerprint (ssh-rsa):",
9bca77
                         expect_json, response, add_header);
9bca77
   g_free (expect_json);
9bca77
 }
9bca77
-- 
9bca77
2.19.1
9bca77