diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index e0c0504..12dedab 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -189,6 +189,10 @@ "message": "Initialization of SSH2 session failed", "description": "libssh2_session_init() failed" }, + "sftpThreadError_sshKEXMethodPrefsFailed" : { + "message": "Couldn't set key exchange method preferences", + "description": "libssh_session_method_prefs() failed" + }, "sftpThreadError_sshSessionHandshakeFailed" : { "message": "Finishing SSH2 session failed", "description": "Error when starting up SSH session" diff --git a/src/_locales/nl/messages.json b/src/_locales/nl/messages.json index 37da962..08e01bd 100644 --- a/src/_locales/nl/messages.json +++ b/src/_locales/nl/messages.json @@ -185,6 +185,9 @@ "sftpThreadError_sshInitSessionFailed" : { "message": "Initialiseren van een SSH2-sessie is mislukt" }, + "sftpThreadError_sshKEXMethodPrefsFailed" : { + "message": "Kan de voorkeuren voor de sleuteluitwisseling methode niet instellen" + }, "sftpThreaderror_sshSessionHandshakeFailed" : { "message": "Voltooien van een SSH2-sessie is mislukt" }, diff --git a/src/nacl_src/sftp_thread.cc b/src/nacl_src/sftp_thread.cc index 97fd42f..1dc1dd1 100644 --- a/src/nacl_src/sftp_thread.cc +++ b/src/nacl_src/sftp_thread.cc @@ -300,6 +300,7 @@ void SftpThread::ConnectAndHandshakeImpl() InitializeLibssh2(); sock = ConnectToSshServer(server_hostname_, server_port_); session = InitializeSession(); + SetKEXMethodPrefs(session); HandshakeSession(session, sock); std::string fingerprint; fingerprint = GetHostKeyHash(session); @@ -374,6 +375,20 @@ LIBSSH2_SESSION* SftpThread::InitializeSession() throw(CommunicationException) return session; } +void SftpThread::SetKEXMethodPrefs(LIBSSH2_SESSION *session) + throw(CommunicationException) +{ + fprintf(stderr, "SftpThread::SetKEXMethodPrefs\n"); + const char *methods; + methods = "curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256"; + int rc; + while ((rc = libssh2_session_method_pref(session, LIBSSH2_METHOD_HOSTKEY, methods)) == LIBSSH2_ERROR_EAGAIN); + fprintf(stderr, "SftpThread::SetKEXMethodPrefs rc=%d\n", rc); + if (rc) { + THROW_COMMUNICATION_EXCEPTION("sftpThreadError_sshKEXMethodPrefsFailed", rc); + } +} + void SftpThread::HandshakeSession(LIBSSH2_SESSION *session, int sock) throw(CommunicationException) { diff --git a/src/nacl_src/sftp_thread.h b/src/nacl_src/sftp_thread.h index 72575ef..763561c 100644 --- a/src/nacl_src/sftp_thread.h +++ b/src/nacl_src/sftp_thread.h @@ -71,6 +71,7 @@ class SftpThread void InitializeLibssh2() throw(CommunicationException); int ConnectToSshServer(const std::string &hostname, const int port) throw(CommunicationException); LIBSSH2_SESSION* InitializeSession() throw(CommunicationException); + void SetKEXMethodPrefs(LIBSSH2_SESSION *session) throw(CommunicationException); void HandshakeSession(LIBSSH2_SESSION *session, int sock) throw(CommunicationException); std::string GetHostKeyHash(LIBSSH2_SESSION *session);