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