diff options
author | Udo Walter | 2021-03-10 00:22:27 +0100 |
---|---|---|
committer | Udo Walter | 2021-03-10 00:22:27 +0100 |
commit | 4c01065a751030d078b802934bca3b16c1d7441c (patch) | |
tree | ee34ed57c3551636488a3b12c2d7133fd61ddbed | |
parent | [MountVmStore] Better handling of concurrent invocations (diff) | |
download | tmlite-bwlp-4c01065a751030d078b802934bca3b16c1d7441c.tar.gz tmlite-bwlp-4c01065a751030d078b802934bca3b16c1d7441c.tar.xz tmlite-bwlp-4c01065a751030d078b802934bca3b16c1d7441c.zip |
[RemoteExec/RemoteReboot] convert ssh key to a format supported by JSch
-rw-r--r-- | pom.xml | 10 | ||||
-rw-r--r-- | src/main/java/org/openslx/taskmanager/tasks/RemoteExec.java | 13 | ||||
-rw-r--r-- | src/main/java/org/openslx/taskmanager/tasks/RemoteReboot.java | 17 |
3 files changed, 39 insertions, 1 deletions
@@ -120,5 +120,15 @@ <artifactId>irclib</artifactId> <version>2.0.0.Alpha3</version> </dependency> + <dependency> + <groupId>com.sshtools</groupId> + <artifactId>maverick-synergy-client</artifactId> + <version>3.0.0-RC3</version> + </dependency> + <dependency> + <groupId>com.sshtools</groupId> + <artifactId>maverick-bc</artifactId> + <version>3.0.0-RC3</version> + </dependency> </dependencies> </project> diff --git a/src/main/java/org/openslx/taskmanager/tasks/RemoteExec.java b/src/main/java/org/openslx/taskmanager/tasks/RemoteExec.java index 3bd0954..8e88599 100644 --- a/src/main/java/org/openslx/taskmanager/tasks/RemoteExec.java +++ b/src/main/java/org/openslx/taskmanager/tasks/RemoteExec.java @@ -9,6 +9,10 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import com.sshtools.common.publickey.InvalidPassphraseException; +import com.sshtools.common.publickey.SshKeyUtils; +import com.sshtools.common.publickey.bc.OpenSSHPrivateKeyFileBC; +import com.sshtools.common.ssh.components.SshKeyPair; import org.openslx.satserver.util.Util; import org.openslx.taskmanager.api.AbstractTask; @@ -77,6 +81,15 @@ public class RemoteExec extends AbstractTask if ( status.error != null ) return false; + // Convert ssh key to old rsa format supported by JSch + try { + SshKeyPair key = SshKeyUtils.getPrivateKey(sshkey, ""); + sshkey = new String(new OpenSSHPrivateKeyFileBC(key, "").getFormattedKey(), + StandardCharsets.UTF_8); + } catch (IOException | InvalidPassphraseException e) { + e.printStackTrace(); + } + JSch.setConfig( "StrictHostKeyChecking", "no" ); sshClient = new JSch(); try { diff --git a/src/main/java/org/openslx/taskmanager/tasks/RemoteReboot.java b/src/main/java/org/openslx/taskmanager/tasks/RemoteReboot.java index f5d9a4b..1913891 100644 --- a/src/main/java/org/openslx/taskmanager/tasks/RemoteReboot.java +++ b/src/main/java/org/openslx/taskmanager/tasks/RemoteReboot.java @@ -1,7 +1,9 @@ package org.openslx.taskmanager.tasks; +import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; +import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -13,6 +15,10 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import com.sshtools.common.publickey.InvalidPassphraseException; +import com.sshtools.common.publickey.SshKeyUtils; +import com.sshtools.common.publickey.bc.OpenSSHPrivateKeyFileBC; +import com.sshtools.common.ssh.components.SshKeyPair; import org.openslx.taskmanager.api.AbstractTask; import com.google.gson.annotations.Expose; @@ -80,7 +86,16 @@ public class RemoteReboot extends AbstractTask if ( status.error != null ) return false; - + + // Convert ssh key to old rsa format supported by JSch + try { + SshKeyPair key = SshKeyUtils.getPrivateKey(sshkey, ""); + sshkey = new String(new OpenSSHPrivateKeyFileBC(key, "").getFormattedKey(), + StandardCharsets.UTF_8); + } catch (IOException | InvalidPassphraseException e) { + e.printStackTrace(); + } + Date shutdownTime = new Date( System.currentTimeMillis() + minutes * 60 * 1000 ); SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm" ); status.time = sdf.format( shutdownTime ); |