mirror of https://github.com/CGAL/cgal
fix known_hosts and ask for permission. Clean-up.
This commit is contained in:
parent
2078b804db
commit
634b0cf7e9
|
|
@ -1,6 +1,5 @@
|
|||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
#undef CGAL_USE_WEBSOCKETS
|
||||
#include "config.h"
|
||||
#include "MainWindow_config.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -478,12 +478,13 @@
|
|||
<string>&Start a Session</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Start a WebSocket Server to share your camera with others on your network.</string>
|
||||
<string>Start a WebSocket Server to Share your Camera with Others on your Network.</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="Polyhedron_3.qrc"/>
|
||||
<include location="Polyhedron_3.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
#ifdef CGAL_USE_SSH
|
||||
|
||||
#include <CGAL/Three/Three.h>
|
||||
|
||||
#include "CGAL/Use_ssh.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
|
@ -7,6 +10,8 @@
|
|||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue