From 634b0cf7e91dd44a80fc63e3e454efd32dfc57fb Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 20 Feb 2020 13:30:15 +0100 Subject: [PATCH] fix known_hosts and ask for permission. Clean-up. --- Polyhedron/demo/Polyhedron/MainWindow.h | 1 - Polyhedron/demo/Polyhedron/MainWindow.ui | 3 +- Polyhedron/demo/Polyhedron/Use_ssh.cpp | 60 ++++++++++++++++-------- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/MainWindow.h b/Polyhedron/demo/Polyhedron/MainWindow.h index b10e9fc7273..b7650b52b34 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.h +++ b/Polyhedron/demo/Polyhedron/MainWindow.h @@ -1,6 +1,5 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#undef CGAL_USE_WEBSOCKETS #include "config.h" #include "MainWindow_config.h" diff --git a/Polyhedron/demo/Polyhedron/MainWindow.ui b/Polyhedron/demo/Polyhedron/MainWindow.ui index e8fee1ec699..6273a37bd16 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.ui +++ b/Polyhedron/demo/Polyhedron/MainWindow.ui @@ -478,12 +478,13 @@ &Start a Session - Start a WebSocket Server to share your camera with others on your network. + Start a WebSocket Server to Share your Camera with Others on your Network. + diff --git a/Polyhedron/demo/Polyhedron/Use_ssh.cpp b/Polyhedron/demo/Polyhedron/Use_ssh.cpp index d529acbcb4c..8af5e1ee7f8 100644 --- a/Polyhedron/demo/Polyhedron/Use_ssh.cpp +++ b/Polyhedron/demo/Polyhedron/Use_ssh.cpp @@ -1,4 +1,7 @@ #ifdef CGAL_USE_SSH + +#include + #include "CGAL/Use_ssh.h" #include #include @@ -7,6 +10,8 @@ #include #include +#include + bool test_result(int res) { switch(res){ @@ -50,30 +55,47 @@ bool establish_ssh_session(ssh_session &session, //Can use SSH_LOG_PROTOCOL here for verbose output int verbosity = SSH_LOG_NOLOG; - - session = ssh_new(); - ssh_options_set( session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity ); - ssh_options_set( session, SSH_OPTIONS_PORT, &port ); - ssh_options_set( session, SSH_OPTIONS_USER, user ); - ssh_options_set( session, SSH_OPTIONS_HOST, server); - - ssh_connect(session); - - if( ssh_is_server_known(session) != SSH_SERVER_KNOWN_OK ) + int res; + //retry 4 times max each time the connection asks to be retried. + for(int k = 0; k < 4; ++k) { - if( ssh_write_knownhost(session) != SSH_OK ) + session = ssh_new(); + ssh_options_set( session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity ); + ssh_options_set( session, SSH_OPTIONS_PORT, &port ); + ssh_options_set( session, SSH_OPTIONS_USER, user ); + ssh_options_set( session, SSH_OPTIONS_HOST, server); + + ssh_connect(session); + + if( ssh_is_server_known(session) != SSH_SERVER_KNOWN_OK ) { - std::cerr << "writeKnownHost failed" << std::endl; - return false; + if(QMessageBox::warning(CGAL::Three::Three::mainWindow(), QString("Unknown Server"), + QString ("The server you are trying to join is not known.\n" + "Do you wish to add it to the known servers list and continue?"), + QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) + { + return false; + } + + if( ssh_write_knownhost(session) != SSH_OK ) + { + std::cerr << "writeKnownHost failed" << std::endl; + return false; + } + else + { + ssh_connect(session); + } } + ssh_key pubkey = ssh_key_new(); + ssh_pki_import_pubkey_file(pub_key_path, &pubkey); + res = ssh_userauth_try_publickey(session, NULL, pubkey); + if(res == SSH_AUTH_AGAIN) + ssh_disconnect(session); else - { - ssh_connect(session); - } + break; } - ssh_key pubkey = ssh_key_new(); - ssh_pki_import_pubkey_file(pub_key_path, &pubkey); - int res = ssh_userauth_try_publickey(session, NULL, pubkey); + if(!test_result(res)) { ssh_disconnect(session);