From 804b83769fc0c683aaef9af966b0a066daebff09 Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Mon, 28 Aug 2023 10:51:53 +0200 Subject: [PATCH] Fixed ssh crash when username in URI is null --- .../jetpackduba/gitnuro/credentials/GRemoteSession.kt | 11 +++++++++-- .../jetpackduba/gitnuro/ssh/libssh/LibSshSession.kt | 2 +- .../ssh/libssh/streams/LibSshChannelOutputStream.kt | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/credentials/GRemoteSession.kt b/src/main/kotlin/com/jetpackduba/gitnuro/credentials/GRemoteSession.kt index 67fe47f..4d77843 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/credentials/GRemoteSession.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/credentials/GRemoteSession.kt @@ -34,8 +34,15 @@ class GRemoteSession @Inject constructor( fun setup(uri: URIish) { val session = processSession.get() session.setOptions(LibSshOptions.SSH_OPTIONS_HOST, uri.host) - session.setOptions(LibSshOptions.SSH_OPTIONS_USER, uri.user) - session.setOptions(LibSshOptions.SSH_OPTIONS_PUBLICKEY_ACCEPTED_TYPES, "ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-rsa,rsa-sha2-512,rsa-sha2-256,ssh-dss") + + uri.user?.let { + session.setOptions(LibSshOptions.SSH_OPTIONS_USER, uri.user) + } + + session.setOptions( + LibSshOptions.SSH_OPTIONS_PUBLICKEY_ACCEPTED_TYPES, + "ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-rsa,rsa-sha2-512,rsa-sha2-256,ssh-dss" + ) session.loadOptionsFromConfig() session.connect() 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 8c38eed..7720540 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ssh/libssh/LibSshSession.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ssh/libssh/LibSshSession.kt @@ -17,7 +17,7 @@ class LibSshSession @Inject constructor() { } fun loadOptionsFromConfig() { - checkValidResult(sshLib.ssh_options_parse_config(session, null)) + checkValidResult("loadOptionsFromConfig", sshLib.ssh_options_parse_config(session, null)) } fun connect() { diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ssh/libssh/streams/LibSshChannelOutputStream.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ssh/libssh/streams/LibSshChannelOutputStream.kt index abde2d1..fed94e9 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ssh/libssh/streams/LibSshChannelOutputStream.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ssh/libssh/streams/LibSshChannelOutputStream.kt @@ -20,7 +20,7 @@ class LibSshChannelOutputStream(private val sshChannel: ssh_channel) : OutputStr } } -fun checkValidResult(result: Int) { +fun checkValidResult(tag: String, result: Int) { if (result != 0) - throw Exception("Result is $result") + throw Exception("$tag - Result is $result") } \ No newline at end of file