[X2Go-Commits] [x2goclient] 02/18: src/sshmasterconnection.cpp: with libssh 0.6.0 and newer, get the public key via ssh_get_server_publickey () (0.8.0 and higher) or ssh_get_publickey () (0.7.x and lower) and its hash via ssh_get_publickey_hash () instead of using the deprecated ssh_get_pubkey_hash () function.
git-admin at x2go.org
git-admin at x2go.org
Wed Feb 22 09:10:03 CET 2017
This is an automated email from the git hooks/post-receive script.
x2go pushed a commit to branch feature/libssh-api-upgrade
in repository x2goclient.
commit 15ce4dac9b7d32e667eb946d815270d4915429b6
Author: Mihai Moldovan <ionic at ionic.de>
Date: Sat Jan 28 17:08:43 2017 +0100
src/sshmasterconnection.cpp: with libssh 0.6.0 and newer, get the public key via ssh_get_server_publickey () (0.8.0 and higher) or ssh_get_publickey () (0.7.x and lower) and its hash via ssh_get_publickey_hash () instead of using the deprecated ssh_get_pubkey_hash () function.
Additionally, replace free () with the more appropriate
ssh_string_free_char () function after using ssh_get_hexa ().
This will break on very old systems with a hopelessly outdated libssh
version, but we do not care about these systems in the first place.
---
debian/changelog | 9 +++++++++
src/sshmasterconnection.cpp | 40 +++++++++++++++++++++++++++++++++-------
2 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index f911630..8c8a2e6 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -4,6 +4,15 @@ x2goclient (4.1.0.1-0x2go1) UNRELEASED; urgency=medium
* New upstream version (4.1.0.1):
- src/sshmasterconnection.cpp: use ssh_channel_listen_forward () instead
of ssh_forward_listen () for newer libssh versions. Fixes: #870.
+ - src/sshmasterconnection.cpp: with libssh 0.6.0 and newer, get the public
+ key via ssh_get_server_publickey () (0.8.0 and higher) or
+ ssh_get_publickey () (0.7.x and lower) and its hash via
+ ssh_get_publickey_hash () instead of using the deprecated
+ ssh_get_pubkey_hash () function. Additionally, replace free () with the
+ more appropriate ssh_string_free_char () function after using
+ ssh_get_hexa (). This will break on very old systems with a hopelessly
+ outdated libssh version, but we do not care about these systems in the
+ first place.
-- X2Go Release Manager <git-admin at x2go.org> Wed, 22 Feb 2017 07:13:10 +0100
diff --git a/src/sshmasterconnection.cpp b/src/sshmasterconnection.cpp
index b3f9aa3..c786717 100644
--- a/src/sshmasterconnection.cpp
+++ b/src/sshmasterconnection.cpp
@@ -20,6 +20,7 @@
#include "sshmasterconnection.h"
#include <stdlib.h>
#include <stdio.h>
+#include <stddef.h>
#include "sshprocess.h"
@@ -812,22 +813,47 @@ int SshMasterConnection::serverAuth ( QString& errorMsg )
x2goDebug<<"cserverAuth";
#endif
- int state, hlen;
+ int state = SSH_SERVER_ERROR;
unsigned char *hash = NULL;
- char *hexa;
+ char *hexa = NULL;
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
+ ssh_key srv_pubkey = { 0 };
+ int rc = SSH_ERROR;
+ size_t hlen = 0;
+#else
+ int hlen = 0;
+#endif
state = ssh_is_server_known ( my_ssh_session );
- hlen = ssh_get_pubkey_hash ( my_ssh_session, &hash );
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 8, 0)
+ rc = ssh_get_server_publickey (my_ssh_session, &srv_pubkey);
+#else /* LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 8, 0) */
+ rc = ssh_get_publickey (my_ssh_session, &srv_pubkey);
+#endif /* LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 8, 0) */
+
+ if (SSH_OK != rc) {
+ return (SSH_SERVER_ERROR);
+ }
+
+ rc = ssh_get_publickey_hash (srv_pubkey, SSH_PUBLICKEY_HASH_SHA1, &hash, &hlen);
+ ssh_key_free (srv_pubkey);
- if ( hlen < 0 )
+ if (0 != rc) {
+ return (SSH_SERVER_ERROR);
+ }
+#else
+ hlen = ssh_get_pubkey_hash ( my_ssh_session, &hash );
+#endif
+
+ if ( 0 >= hlen )
return SSH_SERVER_ERROR;
#ifdef DEBUG
x2goDebug<<"state: "<<state<<endl;
#endif
-
switch ( state )
{
case SSH_SERVER_KNOWN_OK:
@@ -836,7 +862,7 @@ int SshMasterConnection::serverAuth ( QString& errorMsg )
case SSH_SERVER_KNOWN_CHANGED:
hexa = ssh_get_hexa ( hash, hlen );
errorMsg=host+":"+QString::number(port)+" - "+hexa;
- free ( hexa );
+ ssh_string_free_char ( hexa );
break;
case SSH_SERVER_FOUND_OTHER:
break;
@@ -846,7 +872,7 @@ int SshMasterConnection::serverAuth ( QString& errorMsg )
{
hexa = ssh_get_hexa ( hash, hlen );
errorMsg=host+":"+QString::number(port)+" - "+hexa;
- free ( hexa );
+ ssh_string_free_char ( hexa );
break;
}
ssh_write_knownhost ( my_ssh_session );
--
Alioth's /srv/git/code.x2go.org/x2goclient.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2goclient.git
More information about the x2go-commits
mailing list