You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by 于 洋 <hu...@msn.com> on 2022/04/26 00:33:56 UTC
Is there possible to response customized response through sshd channel exec?
Hi Apache MINA SSHD Project team,
Thanks for creating MINA SSHD. It help me a lot on my current project.
Recently, I am using mina sshd library 2.3.0 to mock an ssh server for testing purpose.
One of our service provider only provide ssh command through exec channel. So the client source need a mock server on test case.
This mock server will receive command through ssh exec channel and response result. Because I can't actually execute the command during test case, I need to send a dummy response directly by java code.
I have setup the simple ssh server by following code and successfully execute the command on server side. But I don't know how to send dummy response within the SSHD framework.
Can any expert help me on this case? If I am trying the incorrect way, please feel free to tell I am wrong.
Any response is appreciated. Thank you!
Tyler
Attached the code below.
public void startSshServer() throws IOException {
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(2222);
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("d:\\hostkey.ser").toPath()));
sshd.setPasswordAuthenticator((u, p, s) -> true);
sshd.setPublickeyAuthenticator((s, publicKey, serverSession) -> true);
sshd.setCommandFactory(new ProcessShellCommandFactory());
sshd.setCommandFactory((channelSession, command) -> {
System.out.println("command:" + command);
Command cmd = ProcessShellCommandFactory.INSTANCE.createCommand(channelSession, command);
return cmd;
});
sshd.start();
}