diff --git a/.clangformat b/.clangformat
new file mode 100644
index 0000000..dbbd5f6
--- /dev/null
+++ b/.clangformat
@@ -0,0 +1,68 @@
+---
+#BasedOnStyle: WebKit
+TabWidth: '4'
+IndentWidth: '4'
+UseTab: 'Always'
+AlignOperands: 'true'
+AlignAfterOpenBracket: 'Align'
+AlignConsecutiveAssignments: 'true'
+AlignConsecutiveDeclarations: 'true'
+AlignEscapedNewlines: 'Left'
+AlignTrailingComments: 'true'
+AllowAllParametersOfDeclarationOnNextLine: 'true'
+AllowShortBlocksOnASingleLine: 'false'
+AllowShortCaseLabelsOnASingleLine: 'false'
+AllowShortFunctionsOnASingleLine: 'All'
+AllowShortIfStatementsOnASingleLine: 'false'
+AllowShortLoopsOnASingleLine: 'false'
+AlwaysBreakAfterReturnType: 'None'
+AlwaysBreakTemplateDeclarations: 'true'
+AlwaysBreakBeforeMultilineStrings: 'false'
+BinPackArguments: 'false'
+BinPackParameters: 'false'
+BreakBeforeBraces: 'Custom'
+BraceWrapping:
+ AfterEnum: 'true'
+ AfterClass: 'true'
+ AfterControlStatement: 'true'
+ AfterStruct: 'true'
+ AfterFunction: 'true'
+ AfterNamespace: 'true'
+ AfterUnion: 'true'
+ AfterExternBlock: 'true'
+ BeforeCatch: 'true'
+ BeforeElse: 'true'
+ SplitEmptyRecord: 'false'
+ SplitEmptyNamespace: 'false'
+ SplitEmptyFunction: 'false'
+BreakBeforeBinaryOperators: 'true'
+BreakBeforeTernaryOperators: 'false'
+BreakConstructorInitializersBeforeComma: 'false'
+BreakBeforeInheritanceComma: 'false'
+BreakStringLiterals: 'true'
+ColumnLimit: '140'
+CompactNamespaces: 'false'
+Cpp11BracedListStyle: 'true'
+ConstructorInitializerAllOnOneLineOrOnePerLine: 'false'
+DerivePointerAlignment: 'false'
+IndentCaseLabels: 'true'
+IndentPPDirectives: 'AfterHash'
+KeepEmptyLinesAtTheStartOfBlocks: 'true'
+Language: 'Java'
+NamespaceIndentation: 'All'
+PointerAlignment: 'Right'
+ReflowComments: 'true'
+SortIncludes: 'true'
+SortUsingDeclarations: 'true'
+SpaceAfterCStyleCast: 'false'
+SpaceAfterTemplateKeyword: 'false'
+SpaceBeforeAssignmentOperators: 'true'
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: 'false'
+SpacesInAngles: 'false'
+SpacesInCStyleCastParentheses: 'false'
+SpacesInContainerLiterals: 'false'
+SpacesInParentheses: 'false'
+SpacesInSquareBrackets: 'false'
+Standard: 'Auto'
+...
diff --git a/README.md b/README.md
index 275c1e5..1f518a8 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,70 @@
-Bukkit-SSHD
+Spigot-SSHD
===========
[![Build Status](https://travis-ci.org/rmichela/Bukkit-SSHD.png)](https://travis-ci.org/rmichela/Bukkit-SSHD)
-An SSHD daemon embedded in a Bukkit plugin.
+Have you ever wished you could remotely access your server's admin console without having to setup a complex remote access system? Now you can with SSHD.
+
+SSHD securely exposes your Spigot admin console using the SSH protocol - the same protocol that serves as the secure foundation for nearly all remote server administration.
+
+- Compatible with all ssh clients, regardless of operating system.
+- Remotely view your server log in real-time.
+- Remotely issue commands from the server console, just as if you were on the server itself.
+- Supports multiple concurrent remote connections.
+- Strong identity support using public key authentication.
+- Remotely script your server by issuing one-off console commands with ssh.
+
+## Why should I use SSHD?
+
+- Your server runs on Windows.
+- You are in a shared hosting environment that only gives you access to the - log files.
+- You want to share access to your server console, but don't want to give anybody access to the machine its running on.
+- You always wanted to use RCON, but want to see the server log as well.
+- You are tired of running your server in a Screen session.
+- You just want to access your server console using SSH.
+
+## Configuration
+
+- **listenAddress** - The network interface(s) SSHD should listen on. (Default all)
+- **port** - Specify the port SSHD should listen on. (Default 22)
+- **username/password** - The credentials used to log into the server console. (Default blank)
+
+Note: By default, only public key authentication is enabled. This is the most secure authentication mode! Setting a username and password will make your server less secure.
+
+## Setting Up Public Key Authentication
+
+Setting up public key authentication with SSH requires first generating a public and private key pair and then installing just the public key on your Spigot server.
+
+On Windows
+
+1. TODO
+
+On Linux/OS X
+
+1. TODO
+
+## Commands
+None - just install and go.
+
+## Permissions
+
+None - SSHD uses cryptographic certificates or a secure username and password to verify remote access.
+
+## Source Code
+[Get the source on GitHub](https://github.com/Justasic/Bukkit-SSHD "Source Code")
+
+## Metrics
+
+This plugin utilizes Hidendra's plugin metrics system. the following information is collected and sent to mcstats.org unless opted out:
+
+- A unique identifier
+- The server's version of Java
+- Whether the server is in offline or online mode
+- Plugin's version
+- Server's version
+- OS version/name and architecture
+- core count for the CPU
+- Number of players online
+- Metrics version
+
+Opting out of this service can be done by editing plugins/Plugin Metrics/config.yml and changing opt-out to true.
diff --git a/pom.xml b/pom.xml
index aee005b..b126ae3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,9 +5,14 @@
4.0.0
com.ryanmichela
- SSHD
- 1.3.4.1
- http://dev.bukkit.org/server-mods/sshd/
+ sshd
+ 1.3.4.2
+ https://github.com/Justasic/Bukkit-SSHD/
+
+
+ 1.8
+ UTF-8
+
@@ -30,33 +35,57 @@
org.bukkit
bukkit
- 1.12.2-R0.1-SNAPSHOT
+ 1.14.4-R0.1-SNAPSHOT
org.apache.sshd
sshd-core
- 1.6.0
+ 2.3.0
compile
jar
+
+
+ org.apache.sshd
+ sshd-mina
+ 2.3.0
+
+
+
+ org.apache.sshd
+ sshd-common
+ 2.3.0
+
+
+
+ org.apache.sshd
+ sshd-sftp
+ 2.3.0
+
+
+
+ net.i2p.crypto
+ eddsa
+ 0.3.0
+
org.apache.mina
mina-core
- 2.0.16
+ 2.1.3
org.slf4j
slf4j-api
- 1.7.25
+ 1.7.28
org.slf4j
slf4j-jdk14
- 1.7.25
+ 1.7.28
@@ -85,10 +114,12 @@
1.10
provided
-
+
+ clean package
+
.
@@ -104,7 +135,7 @@
maven-assembly-plugin
- 3.1.0
+ 3.1.1
package
@@ -126,7 +157,7 @@
org.apache.maven.plugins
maven-compiler-plugin
- 3.5.1
+ 3.7.0
1.8
diff --git a/src/main/java/com/ryanmichela/sshd/ConsoleCommandFactory.java b/src/main/java/com/ryanmichela/sshd/ConsoleCommandFactory.java
index 11ea4da..10c56e7 100644
--- a/src/main/java/com/ryanmichela/sshd/ConsoleCommandFactory.java
+++ b/src/main/java/com/ryanmichela/sshd/ConsoleCommandFactory.java
@@ -1,7 +1,8 @@
package com.ryanmichela.sshd;
-import org.apache.sshd.server.Command;
-import org.apache.sshd.server.CommandFactory;
+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;
@@ -16,7 +17,7 @@ import java.io.OutputStream;
public class ConsoleCommandFactory implements CommandFactory {
@Override
- public Command createCommand(String command) {
+ public Command createCommand(ChannelSession cs, String command) {
return new ConsoleCommand(command);
}
@@ -50,7 +51,7 @@ public class ConsoleCommandFactory implements CommandFactory {
}
@Override
- public void start(Environment environment) throws IOException {
+ public void start(ChannelSession cs, Environment environment) throws IOException {
try {
SshdPlugin.instance.getLogger()
.info("[U: " + environment.getEnv().get(Environment.ENV_USER) + "] " + command);
@@ -63,8 +64,6 @@ public class ConsoleCommandFactory implements CommandFactory {
}
@Override
- public void destroy() {
-
- }
- }
+ public void destroy(ChannelSession cn) {}
+ }
}
diff --git a/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java b/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java
index 2e9ab32..aab350e 100644
--- a/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java
+++ b/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java
@@ -1,11 +1,20 @@
package com.ryanmichela.sshd;
+import com.ryanmichela.sshd.ConsoleCommandCompleter;
+import com.ryanmichela.sshd.ConsoleLogFormatter;
+import com.ryanmichela.sshd.FlushyOutputStream;
+import com.ryanmichela.sshd.FlushyStreamHandler;
+import com.ryanmichela.sshd.SshTerminal;
+import com.ryanmichela.sshd.SshdPlugin;
+import com.ryanmichela.sshd.StreamHandlerAppender;
import com.ryanmichela.sshd.implementations.SSHDCommandSender;
import jline.console.ConsoleReader;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;
import org.apache.sshd.common.Factory;
-import org.apache.sshd.server.Command;
+import org.apache.sshd.server.shell.ShellFactory;
+import org.apache.sshd.server.command.Command;
+import org.apache.sshd.server.channel.ChannelSession;
import org.apache.sshd.server.Environment;
import org.apache.sshd.server.ExitCallback;
import org.bukkit.Bukkit;
@@ -16,15 +25,11 @@ import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.StreamHandler;
-public class ConsoleShellFactory implements Factory {
+public class ConsoleShellFactory implements ShellFactory {
static SSHDCommandSender sshdCommandSender = new SSHDCommandSender();
- public Command get() {
- return this.create();
- }
-
- public Command create() {
+ public Command createShell(ChannelSession cs) {
return new ConsoleShell();
}
@@ -72,58 +77,76 @@ public class ConsoleShellFactory implements Factory {
this.callback = callback;
}
- public void start(Environment env) throws IOException {
- try {
- consoleReader = new ConsoleReader(in, new FlushyOutputStream(out), new SshTerminal());
- consoleReader.setExpandEvents(true);
- consoleReader.addCompleter(new ConsoleCommandCompleter());
+ @Override
+ public void start(ChannelSession cs, Environment env) throws IOException
+ {
+ try
+ {
+ consoleReader = new ConsoleReader(in, new FlushyOutputStream(out), new SshTerminal());
+ consoleReader.setExpandEvents(true);
+ consoleReader.addCompleter(new ConsoleCommandCompleter());
- StreamHandler streamHandler = new FlushyStreamHandler(out, new ConsoleLogFormatter(), consoleReader);
- streamHandlerAppender = new StreamHandlerAppender(streamHandler);
+ StreamHandler streamHandler = new FlushyStreamHandler(out, new ConsoleLogFormatter(), consoleReader);
+ streamHandlerAppender = new StreamHandlerAppender(streamHandler);
- ((Logger) LogManager.getRootLogger()).addAppender(streamHandlerAppender);
+ ((Logger)LogManager.getRootLogger()).addAppender(streamHandlerAppender);
- environment = env;
- thread = new Thread(this, "SSHD ConsoleShell " + env.getEnv().get(Environment.ENV_USER));
- thread.start();
- } catch (Exception e) {
- throw new IOException("Error starting shell", e);
- }
+ environment = env;
+ thread = new Thread(this, "SSHD ConsoleShell " + env.getEnv().get(Environment.ENV_USER));
+ thread.start();
+ }
+ catch (Exception e)
+ {
+ throw new IOException("Error starting shell", e);
+ }
}
- public void destroy() {
- ((Logger) LogManager.getRootLogger()).removeAppender(streamHandlerAppender);
- }
+ @Override
+ public void destroy(ChannelSession cs) { ((Logger)LogManager.getRootLogger()).removeAppender(streamHandlerAppender); }
- public void run() {
- try {
+ public void run()
+ {
+ try
+ {
if (!SshdPlugin.instance.getConfig().getString("mode").equals("RPC"))
printPreamble(consoleReader);
- while (true) {
+ while (true)
+ {
String command = consoleReader.readLine("\r>", null);
- if (command == null) continue;
- if (command.equals("exit") || command.equals("quit")) break;
- Bukkit.getScheduler().runTask(SshdPlugin.instance, () -> {
- if (SshdPlugin.instance.getConfig().getString("mode").equals("RPC") &&
- command.startsWith("rpc")) {
- //NO ECHO NO PREAMBLE AND SHIT
- String cmd = command.substring("rpc".length() + 1, command.length());
- Bukkit.dispatchCommand(sshdCommandSender, cmd);
- } else {
- SshdPlugin.instance.getLogger()
- .info("<" + environment.getEnv().get(Environment.ENV_USER) + "> " + command);
- Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
- }
- });
+ if (command == null)
+ continue;
+ if (command.equals("exit") || command.equals("quit"))
+ break;
+ Bukkit.getScheduler().runTask(
+ SshdPlugin.instance, () ->
+ {
+ if (SshdPlugin.instance.getConfig().getString("mode").equals("RPC") && command.startsWith("rpc"))
+ {
+ // NO ECHO NO PREAMBLE AND SHIT
+ String cmd = command.substring("rpc".length() + 1, command.length());
+ Bukkit.dispatchCommand(sshdCommandSender, cmd);
+ }
+ else
+ {
+ SshdPlugin.instance.getLogger().info("<" + environment.getEnv().get(Environment.ENV_USER) + "> "
+ + command);
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
+ }
+ });
}
- } catch (IOException e) {
+ }
+ catch (IOException e)
+ {
SshdPlugin.instance.getLogger().log(Level.SEVERE, "Error processing command from SSH", e);
- } finally {
+ }
+ finally
+ {
callback.onExit(0);
}
}
- private void printPreamble(ConsoleReader consoleReader) throws IOException {
+ private void printPreamble(ConsoleReader consoleReader) throws IOException
+ {
consoleReader.println(" _____ _____ _ _ _____" + "\r");
consoleReader.println(" / ____/ ____| | | | __ \\" + "\r");
consoleReader.println("| (___| (___ | |__| | | | |" + "\r");
@@ -136,5 +159,5 @@ public class ConsoleShellFactory implements Factory {
consoleReader.println("Type 'exit' to exit the shell." + "\r");
consoleReader.println("===============================================" + "\r");
}
- }
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/ryanmichela/sshd/PemDecoder.java b/src/main/java/com/ryanmichela/sshd/PemDecoder.java
deleted file mode 100644
index 26d0a0a..0000000
--- a/src/main/java/com/ryanmichela/sshd/PemDecoder.java
+++ /dev/null
@@ -1,98 +0,0 @@
-package com.ryanmichela.sshd;
-
-import org.apache.commons.codec.binary.Base64;
-
-import java.io.Reader;
-import java.math.BigInteger;
-import java.security.KeyFactory;
-import java.security.PublicKey;
-import java.security.spec.DSAPublicKeySpec;
-import java.security.spec.RSAPublicKeySpec;
-
-/**
- * Copyright 2013 Ryan Michela
- */
-public class PemDecoder extends java.io.BufferedReader {
-
- private static final String BEGIN = "^-+\\s*BEGIN.+";
- private static final String END = "^-+\\s*END.+";
- private static final String COMMENT = "Comment:";
-
- public PemDecoder(Reader in) {
- super(in);
- }
-
- public PublicKey getPemBytes() throws Exception {
- StringBuilder b64 = new StringBuilder();
-
- String line = readLine();
- if (!line.matches(BEGIN)) {
- return null;
- }
-
- for (line = readLine(); line != null; line = readLine()) {
- if (!line.matches(END) && !line.startsWith(COMMENT)) {
- b64.append(line.trim());
- }
- }
-
- return decodePublicKey(b64.toString());
- }
-
- private byte[] bytes;
- private int pos;
-
- private PublicKey decodePublicKey(String keyLine) throws Exception {
- bytes = null;
- pos = 0;
-
- // look for the Base64 encoded part of the line to decode
- // both ssh-rsa and ssh-dss begin with "AAAA" due to the length bytes
- for (String part : keyLine.split(" ")) {
- if (part.startsWith("AAAA")) {
- bytes = Base64.decodeBase64(part.getBytes());
- break;
- }
- }
- if (bytes == null) {
- throw new IllegalArgumentException("no Base64 part to decode");
- }
-
- String type = decodeType();
- if (type.equals("ssh-rsa")) {
- BigInteger e = decodeBigInt();
- BigInteger m = decodeBigInt();
- RSAPublicKeySpec spec = new RSAPublicKeySpec(m, e);
- return KeyFactory.getInstance("RSA").generatePublic(spec);
- } else if (type.equals("ssh-dss")) {
- BigInteger p = decodeBigInt();
- BigInteger q = decodeBigInt();
- BigInteger g = decodeBigInt();
- BigInteger y = decodeBigInt();
- DSAPublicKeySpec spec = new DSAPublicKeySpec(y, p, q, g);
- return KeyFactory.getInstance("DSA").generatePublic(spec);
- } else {
- throw new IllegalArgumentException("unknown type " + type);
- }
- }
-
- private String decodeType() {
- int len = decodeInt();
- String type = new String(bytes, pos, len);
- pos += len;
- return type;
- }
-
- private int decodeInt() {
- return ((bytes[pos++] & 0xFF) << 24) | ((bytes[pos++] & 0xFF) << 16)
- | ((bytes[pos++] & 0xFF) << 8) | (bytes[pos++] & 0xFF);
- }
-
- private BigInteger decodeBigInt() {
- int len = decodeInt();
- byte[] bigIntBytes = new byte[len];
- System.arraycopy(bytes, pos, bigIntBytes, 0, len);
- pos += len;
- return new BigInteger(bigIntBytes);
- }
-}
diff --git a/src/main/java/com/ryanmichela/sshd/PublicKeyAuthenticator.java b/src/main/java/com/ryanmichela/sshd/PublicKeyAuthenticator.java
index a7c34d6..b9f4ee3 100644
--- a/src/main/java/com/ryanmichela/sshd/PublicKeyAuthenticator.java
+++ b/src/main/java/com/ryanmichela/sshd/PublicKeyAuthenticator.java
@@ -1,54 +1,85 @@
package com.ryanmichela.sshd;
import org.apache.commons.lang.ArrayUtils;
+import org.apache.sshd.common.config.keys.AuthorizedKeyEntry;
+import org.apache.sshd.common.config.keys.PublicKeyEntryResolver;
import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;
import org.apache.sshd.server.session.ServerSession;
import java.io.File;
+import java.util.List;
import java.io.FileReader;
import java.security.PublicKey;
/**
* Copyright 2013 Ryan Michela
*/
-public class PublicKeyAuthenticator implements PublickeyAuthenticator {
+public class PublicKeyAuthenticator implements PublickeyAuthenticator
+{
- private File authorizedKeysDir;
+ private File authorizedKeysDir;
- public PublicKeyAuthenticator(File authorizedKeysDir) {
- this.authorizedKeysDir = authorizedKeysDir;
- }
+ public PublicKeyAuthenticator(File authorizedKeysDir) { this.authorizedKeysDir = authorizedKeysDir; }
- @Override
- public boolean authenticate(String username, PublicKey key, ServerSession session) {
- byte[] keyBytes = key.getEncoded();
- File keyFile = new File(authorizedKeysDir, username);
+ @Override public boolean authenticate(String username, PublicKey key, ServerSession session)
+ {
+ byte[] keyBytes = key.getEncoded();
+ File keyFile = new File(authorizedKeysDir, username);
- if (keyFile.exists()) {
- try {
+ if (keyFile.exists())
+ {
+ try
+ {
+ List pklist = AuthorizedKeyEntry.readAuthorizedKeys(keyFile.toPath());
+
+ PublickeyAuthenticator auth = PublickeyAuthenticator.fromAuthorizedEntries(username, session, pklist,
+ PublicKeyEntryResolver.IGNORING);
- FileReader fr = new FileReader(keyFile);
- PemDecoder pd = new PemDecoder(fr);
- PublicKey k = pd.getPemBytes();
- pd.close();
+ boolean accepted = auth.authenticate(username, key, session);
- if (k != null) {
- if (ArrayUtils.isEquals(key.getEncoded(), k.getEncoded())) {
- return true;
- }
- } else {
- SshdPlugin.instance.getLogger().severe("Failed to parse PEM file. " + keyFile.getAbsolutePath());
+ if (accepted)
+ {
+ SshdPlugin.instance.getLogger().info(
+ username + " successfully authenticated via SSH session using key file " + keyFile.getAbsolutePath());
+ }
+ else
+ {
+ SshdPlugin.instance.getLogger().info(
+ username + " failed authentication via SSH session using key file " + keyFile.getAbsolutePath());
+ }
+ return accepted;
+ /*
+
+ FileReader fr = new FileReader(keyFile);
+ PemDecoder pd = new PemDecoder(fr);
+ PublicKey k = pd.getPemBytes();
+ pd.close();
+
+ if (k != null)
+ {
+ if (ArrayUtils.isEquals(key.getEncoded(), k.getEncoded()))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ SshdPlugin.instance.getLogger().severe("Failed to parse PEM file. " + keyFile.getAbsolutePath());
}
- } catch (Exception e) {
- SshdPlugin.instance.getLogger()
- .severe("Failed to process public key " + keyFile.getAbsolutePath() + ". " + e.getMessage());
- }
- } else {
- SshdPlugin.instance.getLogger().warning("Could not locate public key for " + username +
- ". Make sure the user's key is named the same as their user name " +
- "without a file extension.");
- }
+ */
+ }
+ catch (Exception e)
+ {
+ SshdPlugin.instance.getLogger().severe("Failed to process public key " + keyFile.getAbsolutePath() + " " + e.getMessage());
+ }
+ }
+ else
+ {
+ SshdPlugin.instance.getLogger().warning("Could not locate public key for " + username
+ + ". Make sure the user's key is named the same as their user name "
+ + "without a file extension.");
+ }
- return false;
- }
+ return false;
+ }
}
diff --git a/src/main/java/com/ryanmichela/sshd/SshdPlugin.java b/src/main/java/com/ryanmichela/sshd/SshdPlugin.java
index 401d7ad..79d84e4 100644
--- a/src/main/java/com/ryanmichela/sshd/SshdPlugin.java
+++ b/src/main/java/com/ryanmichela/sshd/SshdPlugin.java
@@ -6,6 +6,8 @@ import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
import org.bukkit.plugin.java.JavaPlugin;
+import com.ryanmichela.sshd.ConsoleShellFactory;
+
import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
@@ -15,65 +17,72 @@ import java.util.logging.Level;
/**
* Copyright 2013 Ryan Michela
*/
-public class SshdPlugin extends JavaPlugin {
+public
+class SshdPlugin extends JavaPlugin
+{
- private SshServer sshd;
- public static SshdPlugin instance;
+ private SshServer sshd;
+ public static SshdPlugin instance;
- @Override
- public void onLoad() {
- saveDefaultConfig();
- File authorizedKeys = new File(getDataFolder(), "authorized_keys");
- if (!authorizedKeys.exists()) {
- authorizedKeys.mkdirs();
- }
+ @Override public void onLoad()
+ {
+ saveDefaultConfig();
+ File authorizedKeys = new File(getDataFolder(), "authorized_keys");
+ if (!authorizedKeys.exists())
+ {
+ authorizedKeys.mkdirs();
+ }
- // Don't go any lower than INFO or SSHD will cause a stack overflow exception.
- // SSHD will log that it wrote bites to the output stream, which writes
- // bytes to the output stream - ad nauseaum.
- getLogger().setLevel(Level.INFO);
- }
+ // Don't go any lower than INFO or SSHD will cause a stack overflow exception.
+ // SSHD will log that it wrote bites to the output stream, which writes
+ // bytes to the output stream - ad nauseaum.
+ getLogger().setLevel(Level.INFO);
+ }
- @Override
- public void onEnable() {
- instance = this;
+ @Override public void onEnable()
+ {
+ instance = this;
- sshd = SshServer.setUpDefaultServer();
- sshd.setPort(getConfig().getInt("port", 22));
- String host = getConfig().getString("listenAddress", "all");
- sshd.setHost(host.equals("all") ? null : host);
+ sshd = SshServer.setUpDefaultServer();
+ sshd.setPort(getConfig().getInt("port", 22));
+ String host = getConfig().getString("listenAddress", "all");
+ sshd.setHost(host.equals("all") ? null : host);
- File hostKey = new File(getDataFolder(), "hostkey");
- File authorizedKeys = new File(getDataFolder(), "authorized_keys");
+ File hostKey = new File(getDataFolder(), "hostkey");
+ File authorizedKeys = new File(getDataFolder(), "authorized_keys");
- sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(hostKey));
- sshd.setShellFactory(new ConsoleShellFactory());
- sshd.setPasswordAuthenticator(new ConfigPasswordAuthenticator());
- sshd.setPublickeyAuthenticator(new PublicKeyAuthenticator(authorizedKeys));
+ sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(hostKey.toPath()));
+ sshd.setShellFactory(new ConsoleShellFactory());
+ sshd.setPasswordAuthenticator(new ConfigPasswordAuthenticator());
+ sshd.setPublickeyAuthenticator(new PublicKeyAuthenticator(authorizedKeys));
- if (getConfig().getBoolean("enableSFTP")) {
- sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory()));
- sshd.setFileSystemFactory(new VirtualFileSystemFactory(
- FileSystems.getDefault().getPath(
- getDataFolder().getAbsolutePath()
- ).getParent().getParent()
- ));
- }
+ if (getConfig().getBoolean("enableSFTP"))
+ {
+ sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory()));
+ sshd.setFileSystemFactory(
+ new VirtualFileSystemFactory(FileSystems.getDefault().getPath(getDataFolder().getAbsolutePath()).getParent().getParent()));
+ }
- sshd.setCommandFactory(new ConsoleCommandFactory());
- try {
- sshd.start();
- } catch (IOException e) {
- getLogger().log(Level.SEVERE, "Failed to start SSH server! ", e);
- }
- }
+ sshd.setCommandFactory(new ConsoleCommandFactory());
+ try
+ {
+ sshd.start();
+ }
+ catch (IOException e)
+ {
+ getLogger().log(Level.SEVERE, "Failed to start SSH server! ", e);
+ }
+ }
- @Override
- public void onDisable() {
- try {
- sshd.stop();
- } catch (Exception e) {
- // do nothing
- }
- }
+ @Override public void onDisable()
+ {
+ try
+ {
+ sshd.stop();
+ }
+ catch (Exception e)
+ {
+ // do nothing
+ }
+ }
}
diff --git a/src/main/java/com/ryanmichela/sshd/implementations/SSHDCommandSender.java b/src/main/java/com/ryanmichela/sshd/implementations/SSHDCommandSender.java
index 5f4975a..5442e00 100644
--- a/src/main/java/com/ryanmichela/sshd/implementations/SSHDCommandSender.java
+++ b/src/main/java/com/ryanmichela/sshd/implementations/SSHDCommandSender.java
@@ -1,6 +1,5 @@
package com.ryanmichela.sshd.implementations;
-import com.ryanmichela.sshd.ConsoleShellFactory;
import com.ryanmichela.sshd.SshdPlugin;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -16,6 +15,8 @@ import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
+import com.ryanmichela.sshd.ConsoleShellFactory;
+
import java.io.IOException;
import java.util.Arrays;
import java.util.Set;
@@ -44,7 +45,7 @@ public class SSHDCommandSender implements ConsoleCommandSender, CommandSender {
}
public String getName() {
- return "SSHD CONSOLE";
+ return "Console";
}
public boolean isOp() {
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 981c1d3..deec6e1 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,4 +1,4 @@
name: SSHD
version: ${project.version}
-author: Ryan Michela, Haarolean, toxuin
+author: Ryan Michela, Haarolean, toxuin, Justin Crawford
main: com.ryanmichela.sshd.SshdPlugin
\ No newline at end of file