[X2Go-Commits] [x2goclient] 02/02: src/sshmasterconnection.cpp: with libssh 0.6.0 and newer, get the public key via ssh_get_server_publickey () 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
Sat Jan 28 17:10:37 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 81d90855f1f182c713b4500fe158f140c11caf19
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 () 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            |    8 ++++++++
 src/sshmasterconnection.cpp |   32 ++++++++++++++++++++++++++------
 2 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 8824554..5e6557e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -559,6 +559,14 @@ x2goclient (4.1.0.0-0x2go1) UNRELEASED; urgency=medium
       commit. Fixes compile issues on Linux and other systems.
     - src/sshmasterconnection.cpp: use ssh_channel_listen_forward () instead
       of ssh_forward_listen () for newer libssh versions.
+    - src/sshmasterconnection.cpp: with libssh 0.6.0 and newer, get the public
+      key via ssh_get_server_publickey () 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.
 
   [ Bernard Cafarelli ]
   * New upstream version (4.1.0.0):
diff --git a/src/sshmasterconnection.cpp b/src/sshmasterconnection.cpp
index b3f9aa3..e5da19c 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,13 +813,33 @@ int SshMasterConnection::serverAuth ( QString& errorMsg )
     x2goDebug<<"cserverAuth";
 #endif
 
-    int state, hlen;
+    int state = SSH_SERVER_ERROR;
+    size_t hlen = 0;
     unsigned char *hash = NULL;
-    char *hexa;
+    char *hexa = NULL;
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
+    ssh_key srv_pubkey = { };
+    int rc = SSH_ERROR;
+#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)
+    rc = ssh_get_server_publickey (session, &srv_pubkey);
+
+    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 (0 != rc) {
+        return (SSH_SERVER_ERROR);
+    }
+#else
+    hlen = ssh_get_pubkey_hash ( my_ssh_session, &hash );
+#endif
 
     if ( hlen < 0 )
         return SSH_SERVER_ERROR;
@@ -827,7 +848,6 @@ int SshMasterConnection::serverAuth ( QString& errorMsg )
     x2goDebug<<"state: "<<state<<endl;
 #endif
 
-
     switch ( state )
     {
     case SSH_SERVER_KNOWN_OK:
@@ -836,7 +856,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 +866,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