[X2Go-Commits] [x2goclient] 03/03: src/onmainwindow.h: rename ONMainWindow::generateHostDsaKey () to ONMainWindow::generateHostKey () and make key type selectible. Fixes: #1003.

git-admin at x2go.org git-admin at x2go.org
Wed May 25 00:56:59 CEST 2016


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch bugfix/osx
in repository x2goclient.

commit 60960bacf28a794f30567119d20f16b619fbbd15
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Wed May 25 00:56:14 2016 +0200

    src/onmainwindow.h: rename ONMainWindow::generateHostDsaKey () to ONMainWindow::generateHostKey () and make key type selectible. Fixes: #1003.
    
    Host key type selection currently only works within the code. Replace
    calls to former ONMainWindow::generateHostDsaKey () with the generalized
    function and request an RSA-type key.
---
 debian/changelog     |    5 ++++
 src/onmainwindow.cpp |   76 +++++++++++++++++++++++++++++++++++++-------------
 src/onmainwindow.h   |    6 ++--
 3 files changed, 64 insertions(+), 23 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index e6ca030..68f8d9b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -308,6 +308,11 @@ x2goclient (4.0.5.2-0x2go1) UNRELEASED; urgency=medium
       standard output from temporary process, not our "main" server process
       (which at this point is not even started yet.)
     - src/onmainwindow.h: add new enum for selecting SSH host key types.
+    - src/onmainwindow.h: rename ONMainWindow::generateHostDsaKey () to
+      ONMainWindow::generateHostKey () and make key type selectible. Fixes:
+      #1003. Host key type selection currently only works within the code. Replace
+      calls to former ONMainWindow::generateHostDsaKey () with the generalized
+      function and request an RSA-type key.
 
   [ Mike DePaulo ]
   * New upstream release (4.0.5.2):
diff --git a/src/onmainwindow.cpp b/src/onmainwindow.cpp
index 084184d..f0ad66c 100644
--- a/src/onmainwindow.cpp
+++ b/src/onmainwindow.cpp
@@ -8094,14 +8094,14 @@ QString ONMainWindow::createRSAKey()
     if ( !rsa.open ( QIODevice::ReadOnly | QIODevice::Text ) )
     {
 #if defined (Q_OS_LINUX) || defined (Q_OS_DARWIN)
-        generateHostDsaKey ();
+        generateHostKey (RSA_KEY_TYPE);
         generateEtcFiles ();
 
         if (!startSshd ()) {
             return (QString::null);
         }
 
-        rsa.setFileName ( homeDir+"/.x2go/etc/ssh_host_dsa_key.pub" );
+        rsa.setFileName ( homeDir+"/.x2go/etc/ssh_host_rsa_key.pub" );
         rsa.open ( QIODevice::ReadOnly | QIODevice::Text );
 #else
         printSshDError_noHostPubKey();
@@ -10043,7 +10043,7 @@ void ONMainWindow::startWinServers()
     {
 
         dr.mkpath ( etcDir );
-        generateHostDsaKey();
+        generateHostKey(RSA_KEY_TYPE);
         generateEtcFiles();
         sshStarter->start();
     }
@@ -10213,27 +10213,63 @@ void ONMainWindow::generateEtcFiles()
     x2goDebug<<etcDir +"/sshd_config created.";
 }
 
-void ONMainWindow::generateHostDsaKey()
-{
-    QString etcDir=homeDir+"/.x2go/etc";
-    QDir dr ( homeDir );
-    dr.mkpath ( etcDir );
-    if ( !QFile::exists ( etcDir+"/ssh_host_dsa_key" ) ||
-            !QFile::exists ( etcDir+"/ssh_host_dsa_key.pub" ) )
-    {
-
-        x2goDebug<<"Generating host DSA key.";
+void ONMainWindow::generateHostKey(ONMainWindow::key_types key_type)
+{
+    ONMainWindow::key_types sanitized_key_type = UNKNOWN_KEY_TYPE;
+    QString stringified_key_type = "";
+    switch (key_type) {
+        case RSA_KEY_TYPE:
+                               sanitized_key_type = key_type;
+                               stringified_key_type = "rsa";
+                               break;
+        case DSA_KEY_TYPE:
+                               sanitized_key_type = key_type;
+                               stringified_key_type = "dsa";
+                               break;
+        case ECDSA_KEY_TYPE:
+                               sanitized_key_type = key_type;
+                               stringified_key_type = "ecdsa";
+                               break;
+        case ED25519_KEY_TYPE:
+                               sanitized_key_type = key_type;
+                               stringified_key_type = "ed25519";
+                               break;
+        default:
+                               sanitized_key_type = UNKNOWN_KEY_TYPE;
+                               stringified_key_type = "unknown";
+    }
+
+    if (sanitized_key_type == UNKNOWN_KEY_TYPE) {
+        QMessageBox::critical (this, tr ("Host key type selection error"),
+                               tr ("Unknown host key selected.\nTerminating application."));
+        close ();
+    }
+
+    QString etcDir = homeDir + "/.x2go/etc/";
+    QDir dr (homeDir);
+    dr.mkpath (etcDir);
+    QString private_key_file = etcDir + "/ssh_host_" + stringified_key_type + "_key";
+    QString public_key_file = private_key_file + ".pub";
+
+    if ((!(QFile::exists (private_key_file))) || (!(QFile::exists (public_key_file))))
+    {
+        x2goDebug << "Generating host key. Type: " << stringified_key_type;
 
 #ifdef Q_OS_WIN
-        QString fname=cygwinPath ( wapiShortFileName ( etcDir ) ) +
-                      "/ssh_host_dsa_key";
-#else
-        QString fname=etcDir+"/ssh_host_dsa_key";
+        private_key_file = cygwinPath (wapiShortFileName (etcDir))
+                         + "/ssh_host_" + stringified_key_type + "_key";
 #endif
+
         QStringList args;
-        args<<"-t"<<"dsa"<<"-N"<<""<<"-C"<<
-            "x2goclient DSA host key"<<"-f"<<fname;
-        QProcess::execute ( "ssh-keygen",args );
+        args << "-t"
+             << stringified_key_type
+             << "-N"
+             << ""
+             << "-C"
+             << QString ("X2Go Client " + stringified_key_type + "host key")
+             << "-f"
+             << private_key_file;
+        QProcess::execute ("ssh-keygen", args);
     }
 }
 
diff --git a/src/onmainwindow.h b/src/onmainwindow.h
index cb71871..f17101f 100644
--- a/src/onmainwindow.h
+++ b/src/onmainwindow.h
@@ -342,13 +342,13 @@ public:
         ESD
     };
 
-    enum {
+    enum key_types {
         RSA_KEY_TYPE,
         DSA_KEY_TYPE,
         ECDSA_KEY_TYPE,
         ED25519_KEY_TYPE,
         UNKNOWN_KEY_TYPE
-    } key_types;
+    };
 
     static bool debugging;
 
@@ -1204,7 +1204,7 @@ private:
 #endif
     void filterDesktops ( const QString& filter,
                           bool strict=false );
-    void generateHostDsaKey();
+    void generateHostKey(key_types key_type);
     void generateEtcFiles();
     QString u3DataPath();
     void cleanPortable();

--
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