From d5aaa1dd302ceb7d8d4ae6d0fd640823976ef86f Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Sat, 15 Apr 2023 16:03:19 +0200 Subject: [PATCH] SSH auth tries to login with simply password if auth with public key failed --- .../jetpackduba/gitnuro/credentials/GRemoteSession.kt | 4 ++++ .../com/jetpackduba/gitnuro/ssh/libssh/LibSshSession.kt | 9 +++++++++ .../com/jetpackduba/gitnuro/ssh/libssh/LibSshWrapper.kt | 1 + 3 files changed, 14 insertions(+) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/credentials/GRemoteSession.kt b/src/main/kotlin/com/jetpackduba/gitnuro/credentials/GRemoteSession.kt index 86ae9ce..f868cad 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/credentials/GRemoteSession.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/credentials/GRemoteSession.kt @@ -57,6 +57,10 @@ class GRemoteSession @Inject constructor( credentials.password result = session.userAuthPublicKeyAuto(null, password) + + if (result != 0) { + result = session.userAuthPassword(password) + } } if (result != 0) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ssh/libssh/LibSshSession.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ssh/libssh/LibSshSession.kt index cdda554..8c38eed 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ssh/libssh/LibSshSession.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ssh/libssh/LibSshSession.kt @@ -33,6 +33,15 @@ class LibSshSession @Inject constructor() { return result } + fun userAuthPassword(password: String): Int { + val result = sshLib.ssh_userauth_password(session, null, password) + + if (result != 0) + printError(TAG, "Result is: $result.\nError is: ${getError()}") + + return result + } + fun createChannel(): LibSshChannel { val newChannel = LibSshChannel(session) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ssh/libssh/LibSshWrapper.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ssh/libssh/LibSshWrapper.kt index 1fff5ac..2210058 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ssh/libssh/LibSshWrapper.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ssh/libssh/LibSshWrapper.kt @@ -19,6 +19,7 @@ interface SSHLibrary : Library { fun ssh_userauth_agent(session: ssh_session, username: String?): Int fun ssh_userauth_publickey_auto(session: ssh_session, username: String?, password: String?): Int + fun ssh_userauth_password(session: ssh_session, username: String?, password: String?): Int fun ssh_get_error(session: ssh_session): String fun ssh_channel_new(sshSession: ssh_session): ssh_channel