Each user can have a set of authorized keys for public key authentication. This is better to support as it lets us use different algorithms and not just RSA. In the age of security, it's good to have variety. I also added additional libraries to support ed25519-based public keys. I updated the SSH libraries so any upstream bug fixes are applied, fixed some warnings and a few other things.
70 lines
2.0 KiB
Java
70 lines
2.0 KiB
Java
package com.ryanmichela.sshd;
|
|
|
|
import org.apache.sshd.server.command.Command;
|
|
import org.apache.sshd.server.command.CommandFactory;
|
|
import org.apache.sshd.server.channel.ChannelSession;
|
|
import org.apache.sshd.server.Environment;
|
|
import org.apache.sshd.server.ExitCallback;
|
|
import org.bukkit.Bukkit;
|
|
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
|
|
/**
|
|
* Copyright 2013 Ryan Michela
|
|
*/
|
|
public class ConsoleCommandFactory implements CommandFactory {
|
|
|
|
@Override
|
|
public Command createCommand(ChannelSession cs, String command) {
|
|
return new ConsoleCommand(command);
|
|
}
|
|
|
|
public class ConsoleCommand implements Command {
|
|
|
|
private String command;
|
|
|
|
private InputStream in;
|
|
private OutputStream out;
|
|
private OutputStream err;
|
|
private ExitCallback callback;
|
|
|
|
public ConsoleCommand(String command) {
|
|
this.command = command;
|
|
}
|
|
|
|
public void setInputStream(InputStream in) {
|
|
this.in = in;
|
|
}
|
|
|
|
public void setOutputStream(OutputStream out) {
|
|
this.out = out;
|
|
}
|
|
|
|
public void setErrorStream(OutputStream err) {
|
|
this.err = err;
|
|
}
|
|
|
|
public void setExitCallback(ExitCallback callback) {
|
|
this.callback = callback;
|
|
}
|
|
|
|
@Override
|
|
public void start(ChannelSession cs, Environment environment) throws IOException {
|
|
try {
|
|
SshdPlugin.instance.getLogger()
|
|
.info("[U: " + environment.getEnv().get(Environment.ENV_USER) + "] " + command);
|
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
|
} catch (Exception e) {
|
|
SshdPlugin.instance.getLogger().severe("Error processing command from SSH -" + e.getMessage());
|
|
} finally {
|
|
callback.onExit(0);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void destroy(ChannelSession cn) {}
|
|
}
|
|
}
|