[X2Go-Commits] [x2goclient] 01/01: SSH Iteraction for method keyboard-interactive.

git-admin at x2go.org git-admin at x2go.org
Fri May 12 15:43:32 CEST 2017


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

x2go pushed a commit to branch master
in repository x2goclient.

commit 42f3369f19639cd43978c98911a46cafb70122b9
Author: Oleksandr Shneyder <o.shneyder at phoca-gmbh.de>
Date:   Fri May 12 15:42:33 2017 +0200

    SSH Iteraction for method keyboard-interactive.
---
 debian/changelog            |  1 +
 src/InteractionDialog.cpp   |  3 +-
 src/InteractionDialog.h     |  3 +-
 src/httpbrokerclient.cpp    |  2 +
 src/onmainwindow.h          |  2 +-
 src/sshmasterconnection.cpp | 97 +++++++++++++++++++++++++++++++++++++++++++--
 src/sshmasterconnection.h   |  1 +
 7 files changed, 100 insertions(+), 9 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index abc52ab..832c740 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -160,6 +160,7 @@ x2goclient (4.1.0.1-0x2go1) UNRELEASED; urgency=medium
       expired password). Fixes: #592.
     - Fixing setting widget style issue in InteractionDialog on
     - SSH Interaction for SSH Broker and SSH Server.
+    - SSH Iteraction for method keyboard-interactive.
       Windows client.
   [ Robert Parts ]
   * New upstream version (4.1.0.1):
diff --git a/src/InteractionDialog.cpp b/src/InteractionDialog.cpp
index f6a95aa..25d0936 100644
--- a/src/InteractionDialog.cpp
+++ b/src/InteractionDialog.cpp
@@ -24,6 +24,7 @@
 #include <QLabel>
 #include <QLineEdit>
 #include <QScrollBar>
+#include <QTimer>
 
 #ifndef Q_OS_LINUX
 #if QT_VERSION < 0x050000
@@ -114,9 +115,7 @@ void InteractionDialog::appendText(QString txt)
     interrupted=false;
     display=false;
     cancelButton->setText(tr("Cancel"));
-#ifdef Q_OS_WIN
     QTimer::singleShot(0, textEntry, SLOT(setFocus()));
-#endif
 }
 
 void InteractionDialog::reset()
diff --git a/src/InteractionDialog.h b/src/InteractionDialog.h
index 76efcfd..8c9d531 100644
--- a/src/InteractionDialog.h
+++ b/src/InteractionDialog.h
@@ -31,7 +31,7 @@ class InteractionDialog: public SVGFrame
 
     Q_OBJECT
 public:
-    enum IMode{SESSION,BROKER};
+    enum IMode {SESSION,BROKER};
     InteractionDialog ( QWidget* parent=0);
     virtual ~InteractionDialog();
     void reset();
@@ -63,4 +63,3 @@ signals:
 };
 
 #endif
-
diff --git a/src/httpbrokerclient.cpp b/src/httpbrokerclient.cpp
index c652d8e..7cc1403 100644
--- a/src/httpbrokerclient.cpp
+++ b/src/httpbrokerclient.cpp
@@ -131,6 +131,7 @@ void HttpBrokerClient::slotSshConnectionError(QString message, QString lastSessi
 
 void HttpBrokerClient::slotSshConnectionOk()
 {
+    mainWindow->getInteractionDialog()->hide();
     getUserSessions();
 }
 
@@ -252,6 +253,7 @@ void HttpBrokerClient::slotSshUserAuthError(QString error)
         delete sshConnection;
         sshConnection=0l;
     }
+    mainWindow->getInteractionDialog()->hide();
 
     if(error!="NO_ERROR")
 
diff --git a/src/onmainwindow.h b/src/onmainwindow.h
index 7d9c008..a294d1e 100644
--- a/src/onmainwindow.h
+++ b/src/onmainwindow.h
@@ -342,7 +342,7 @@ public:
     void suspendSession ( QString sessId );
     bool termSession ( QString sessId,
                        bool warn=true );
-    const InteractionDialog* getInteractionDialog()
+    InteractionDialog* getInteractionDialog()
     {
       return interDlg;
     }
diff --git a/src/sshmasterconnection.cpp b/src/sshmasterconnection.cpp
index 2d03044..ea34c68 100644
--- a/src/sshmasterconnection.cpp
+++ b/src/sshmasterconnection.cpp
@@ -1021,6 +1021,95 @@ void SshMasterConnection::setVerficationCode(QString code)
 }
 
 
+
+bool SshMasterConnection::userAuthKeyboardInteractive(QString prompt)
+{
+    x2goDebug<<"Open Interaction dialog to complete authentication";
+    emit startInteraction(this, prompt);
+    interactionInterrupt=false;
+    interactionInputText=QString::null;
+    int rez=SSH_AUTH_INFO;
+    bool firstLoop=true;
+    int prompts=1;
+    while (rez==SSH_AUTH_INFO)
+    {
+
+        if(firstLoop)
+        {
+            firstLoop=false;
+        }
+        else
+        {
+            prompts=ssh_userauth_kbdint_getnprompts(my_ssh_session);
+            if(prompts>0)
+                emit updateInteraction(this, ssh_userauth_kbdint_getprompt(my_ssh_session,0,NULL));
+
+            QString name= ssh_userauth_kbdint_getname(my_ssh_session);
+            QString instruction = ssh_userauth_kbdint_getinstruction(my_ssh_session);
+#ifdef DEBUG
+            x2goDebug<<"Have prompts: "<<prompts<<endl;
+            x2goDebug<<"Name: "<<name<<endl;
+            x2goDebug<<"Instruction: "<<instruction<<endl;
+#endif
+        }
+        if(prompts>0)
+        {
+            while(true)
+            {
+                bool interrupt;
+                interactionInputMutex.lock();
+                interrupt=interactionInterrupt;
+                QString textToSend=interactionInputText;
+                interactionInputText=QString::null;
+                interactionInputMutex.unlock();
+                if(textToSend.length()>0)
+                {
+                    x2goDebug<<"SEND Input to SERVER";
+                    textToSend.replace("\n","");
+                    ssh_userauth_kbdint_setanswer(my_ssh_session,0,textToSend.toLocal8Bit());
+                    break;
+                }
+                if(interrupt)
+                {
+                    x2goDebug<<"Keyboard authentication failed";
+//         QString err=ssh_get_error ( my_ssh_session );
+                    authErrors<<"NO_ERROR";
+                    emit finishInteraction(this);
+
+                    return false;
+                }
+                this->usleep(30);
+            }
+        }
+
+        rez=ssh_userauth_kbdint(my_ssh_session, NULL, NULL);
+
+    }
+    if(rez==SSH_AUTH_SUCCESS)
+    {
+        x2goDebug<<"Keyboard authentication successful";
+        emit finishInteraction(this);
+        return true;
+    }
+    if(rez==SSH_AUTH_DENIED)
+    {
+        x2goDebug<<"Keyboard authentication failed";
+        QString err=ssh_get_error ( my_ssh_session );
+        authErrors<<err;
+        emit finishInteraction(this);
+
+        return false;
+    }
+
+    QString err=ssh_get_error ( my_ssh_session );
+    authErrors<<err;
+
+    return false;
+
+}
+
+
+
 bool SshMasterConnection::userChallengeAuth()
 {
     int rez=ssh_userauth_kbdint(my_ssh_session, NULL, NULL);
@@ -1103,10 +1192,10 @@ bool SshMasterConnection::userChallengeAuth()
                 ssh_userauth_kbdint_setanswer(my_ssh_session,0,challengeAuthVerificationCode.toLatin1());
                 return userChallengeAuth();
             }
-            QString err=ssh_get_error ( my_ssh_session );
-            authErrors<<err;
-
-            return false;
+            else
+	    {
+	        return userAuthKeyboardInteractive(prompt);
+	    }
         }
         else
         {
diff --git a/src/sshmasterconnection.h b/src/sshmasterconnection.h
index 96c2165..18ef0a4 100644
--- a/src/sshmasterconnection.h
+++ b/src/sshmasterconnection.h
@@ -125,6 +125,7 @@ private:
     bool checkLogin();
     bool userAuth();
     bool userAuthKrb();
+    bool userAuthKeyboardInteractive(QString prompt);
     void channelLoop();
     void finalize(int arg1);
     void copy();

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