Begining of Sponge port for Minecraft-SSHD

The main class and MkpasswordCommand are (hopefully) working, the config
is getting there.
This commit is contained in:
Zachery 2019-10-11 20:21:28 -05:00
parent 7c6ae57513
commit 67aa5c63ea
No known key found for this signature in database
GPG Key ID: 0C6201265CE80EEE
8 changed files with 886 additions and 571 deletions

89
Sponge-SSHD.iml Normal file
View File

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>SPONGE</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.apache.sshd:sshd-core:2.3.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.sshd:sshd-mina:2.3.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.sshd:sshd-common:2.3.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.sshd:sshd-sftp:2.3.0" level="project" />
<orderEntry type="library" name="Maven: net.i2p.crypto:eddsa:0.3.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.mina:mina-core:2.1.3" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.28" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-jdk14:1.7.28" level="project" />
<orderEntry type="library" name="Maven: jline:jline:2.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.logging.log4j:log4j-core:2.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.logging.log4j:log4j-api:2.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-codec:commons-codec:1.10" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spongepowered:spongeapi:7.1.0" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:21.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.errorprone:error_prone_annotations:2.0.15" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.commons:commons-lang3:3.5" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:jsr305:3.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.inject:guice:4.1.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.inject:javax.inject:1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: aopalliance:aopalliance:1.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.ben-manes.caffeine:caffeine:2.5.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.ben-manes.caffeine:guava:2.5.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spongepowered:plugin-meta:0.4.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spongepowered:configurate-hocon:3.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spongepowered:configurate-core:3.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.checkerframework:checker-qual:2.4.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.typesafe:config:1.3.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spongepowered:configurate-gson:3.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spongepowered:configurate-yaml:3.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.18" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.flowpowered:flow-math:1.0.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.flowpowered:flow-noise:1.0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm:5.2" level="project" />
<orderEntry type="library" name="Maven: pl.project13.maven:git-commit-id-plugin:maven-plugin:3.0.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-plugin-api:3.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-model:3.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-artifact:3.0" level="project" />
<orderEntry type="library" name="Maven: org.sonatype.sisu:sisu-inject-plexus:1.4.2" level="project" />
<orderEntry type="library" name="Maven: org.sonatype.sisu:sisu-inject-bean:1.4.2" level="project" />
<orderEntry type="library" name="Maven: org.sonatype.sisu:sisu-guice:noaop:2.1.7" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-core:3.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-settings:3.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-settings-builder:3.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-repository-metadata:3.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-model-builder:3.0" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.apache.maven:maven-aether-provider:3.0" level="project" />
<orderEntry type="library" name="Maven: org.sonatype.aether:aether-impl:1.7" level="project" />
<orderEntry type="library" name="Maven: org.sonatype.aether:aether-spi:1.7" level="project" />
<orderEntry type="library" name="Maven: org.sonatype.aether:aether-api:1.7" level="project" />
<orderEntry type="library" name="Maven: org.sonatype.aether:aether-util:1.7" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-interpolation:1.14" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-utils:2.0.4" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-classworlds:2.2.3" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-component-annotations:1.5.5" level="project" />
<orderEntry type="library" name="Maven: org.sonatype.plexus:plexus-sec-dispatcher:1.3" level="project" />
<orderEntry type="library" name="Maven: org.sonatype.plexus:plexus-cipher:1.4" level="project" />
<orderEntry type="library" name="Maven: org.sonatype.plexus:plexus-build-api:0.0.7" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.9.3" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.9" level="project" />
<orderEntry type="library" name="Maven: joda-time:joda-time:2.10.3" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jgit:org.eclipse.jgit:5.2.2.201904231744-r" level="project" />
<orderEntry type="library" name="Maven: com.jcraft:jsch:0.1.54" level="project" />
<orderEntry type="library" name="Maven: com.jcraft:jzlib:1.1.1" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.javaewah:JavaEWAH:1.1.6" level="project" />
</component>
</module>

324
pom.xml
View File

@ -1,175 +1,189 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ryanmichela</groupId>
<artifactId>sshd</artifactId>
<description>Minecraft-SSHD: The SSH daemon for Minecraft servers.</description>
<version>1.3.7</version>
<url>https://github.com/Justasic/Minecraft-SSHD/</url>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<groupId>com.ryanmichela</groupId>
<artifactId>Sponge-SSHD</artifactId>
<version>1.3.7</version>
<packaging>jar</packaging>
<name>Sponge-SSHD</name>
<description>Sponge port for Minecraft-SSHD. SSH for your minecraft server!</description>
<url>https://github.com/Justasic/Minecraft-SSHD/</url>
<!-- Repositories -->
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public</url>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<!-- License -->
<licenses>
<license>
<name>GPL2</name>
<url>http://www.gnu.org/licenses/gpl-2.0.html</url>
</license>
</licenses>
<repositories>
<repository>
<id>sponge</id>
<url>https://repo.spongepowered.org/maven</url>
</repository>
</repositories>
<!-- Dependencies -->
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.14.4-R0.1-SNAPSHOT</version>
</dependency>
<dependencies>
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-core</artifactId>
<version>2.3.0</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
<!--Just include a *few* things.-->
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-core</artifactId>
<version>2.3.0</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-mina</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-mina</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-common</artifactId>
<version>2.3.0</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-common</artifactId>
<version>2.3.0</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-sftp</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-sftp</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>net.i2p.crypto</groupId>
<artifactId>eddsa</artifactId>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>net.i2p.crypto</groupId>
<artifactId>eddsa</artifactId>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.28</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.28</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.28</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.28</version>
</dependency>
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
<scope>provided</scope>
</dependency>
<!-- include Sponge API -->
<dependency>
<groupId>org.spongepowered</groupId>
<artifactId>spongeapi</artifactId>
<version>7.1.0</version>
<scope>provided</scope>
</dependency>
<!-- Used for getting the git hash -->
<dependency>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>3.0.1</version>
<type>maven-plugin</type>
</dependency>
</dependencies>
<!-- Build -->
<build>
<defaultGoal>clean package</defaultGoal>
<build>
<!-- Set our default goal to be clean and build a package -->
<defaultGoal>clean package</defaultGoal>
<!-- Include our git hash in the final name -->
<finalName>${project.name}-${project.version}-${git.commit.id.abbrev}</finalName>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>plugin.yml</include>
<include>config.yml</include>
<include>motd.txt</include>
</includes>
</resource>
</resources>
<!-- Plugins -->
<plugins>
<!-- Run the get git info stuff so we have revisions and whatnot -->
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.5</version>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>${project.name}-${project.version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<!-- Compile plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>
<packaging>jar</packaging>
<configuration>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
</configuration>
</plugin>
<!-- Shade plugin (resolves Jar dependencies) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<!-- Remove jar signing from other jars -->
<filters>
<filter>
<artifact>*:*:*:*</artifact>
<excludes>
<exclude>META-INF/*.RSA</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
</excludes>
</filter>
</filters>
<createDependencyReducedPom>true</createDependencyReducedPom>
<dependencyReducedPomLocation>${java.io.tmpdir}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
</configuration>
</execution>
</executions>
</plugin>
<!-- Maven templates for our PomData file -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>templating-maven-plugin</artifactId>
<version>1.0-alpha-3</version>
<executions>
<execution>
<id>filter-src</id>
<goals>
<goal>filter-sources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,14 +1,23 @@
package com.ryanmichela.sshd;
/*
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
*/
import java.util.Arrays;
import com.ryanmichela.sshd.Cryptography;
import com.ryanmichela.sshd.SshdPlugin;
import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.spec.CommandExecutor;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.command.TabCompleteEvent;
import org.spongepowered.api.text.Text;
class MkpasswdCommand implements CommandExecutor
{
@ -19,16 +28,16 @@ class MkpasswdCommand implements CommandExecutor
// or hash leakages from the user to other connected users. Plus this syntax will show how
// to both use the command and what hashes we support which is important for people who don't
// know how to RTFM. - Justin
private void SendSyntax(CommandSender sender, boolean invalid)
private void SendSyntax(CommandSource sender, boolean invalid)
{
if (invalid)
sender.sendMessage("\u00A7cInvalid Syntax\u00A7r");
sender.sendMessage("\u00A7a/mkpasswd <help|hash> <password>\u00A7r");
sender.sendMessage("\u00A79Supported Hashes: SHA256, PBKDF2, BCRYPT, PLAIN\u00A7r");
// So, to send a message in sponge, you must use "Text.of()" for some reason.
sender.sendMessage(Text.of("\u00A7cInvalid Syntax\u00A7r"));
sender.sendMessage(Text.of("\u00A7a/mkpasswd <help|hash> <password>\u00A7r"));
sender.sendMessage(Text.of("\u00A79Supported Hashes: SHA256, PBKDF2, BCRYPT, PLAIN\u00A7r"));
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
public boolean onCommand(CommandSource sender, TabCompleteEvent.Command command, String label, String[] args)
{
// If we're not mkpasswd, just fuck off.
if (!label.equalsIgnoreCase("mkpasswd"))
@ -51,7 +60,7 @@ class MkpasswdCommand implements CommandExecutor
return true;
}
boolean hasperm = (sender instanceof Player) ? ((Player)sender).hasPermission("sshd.mkpasswd") : true;
boolean hasperm = (!(sender instanceof Player)) || ((Player) sender).hasPermission("sshd.mkpasswd");
if (hasperm)
{
@ -62,7 +71,7 @@ class MkpasswdCommand implements CommandExecutor
if (algoritm.equalsIgnoreCase("PLAIN"))
{
// I mean c'mon...
sender.sendMessage("Bro really? it's literally your unencrypted password...");
sender.sendMessage(Text.of("Bro really? it's literally your unencrypted password..."));
return true;
}
else if (algoritm.equalsIgnoreCase("pbkdf2"))
@ -77,16 +86,23 @@ class MkpasswdCommand implements CommandExecutor
return true;
}
sender.sendMessage("\u00A79Your Hash: " + hash + "\u00A7r");
sender.sendMessage(Text.of("\u00A79Your Hash: " + hash + "\u00A7r"));
}
catch (Exception e)
{
// We're console, just print the stack trace.
e.printStackTrace();
sender.sendMessage("\u00A7cAn error occured. Please check console for details.\u00A7r");
sender.sendMessage(Text.of("\u00A7cAn error occured. Please check console for details.\u00A7r"));
}
}
return true;
}
// so sponge needed this, still figuring out the sponge API ~ Zach
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException
{
return null;
}
}

View File

@ -1,6 +1,5 @@
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;
@ -27,7 +26,7 @@ public class PublicKeyAuthenticator implements PublickeyAuthenticator
{
byte[] keyBytes = key.getEncoded();
File keyFile = new File(authorizedKeysDir, username);
Integer tries = SshdPlugin.instance.getConfig().getInt("LoginRetries");
Integer tries = SshdPlugin.instance.LoginRetries;
if (keyFile.exists())
{
@ -68,12 +67,12 @@ public class PublicKeyAuthenticator implements PublickeyAuthenticator
}
catch (Exception e)
{
SshdPlugin.instance.getLogger().severe("Failed to process public key " + keyFile.getAbsolutePath() + " " + e.getMessage());
SshdPlugin.instance.getLogger().error("Failed to process public key " + keyFile.getAbsolutePath() + " " + e.getMessage());
}
}
else
{
SshdPlugin.instance.getLogger().warning("Could not locate public key for " + username
SshdPlugin.instance.getLogger().error("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.");
}

View File

@ -1,10 +1,16 @@
package com.ryanmichela.sshd;
import com.ryanmichela.sshd.utils.Config;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.spec.CommandSpec;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
import org.apache.sshd.server.SshServer;
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 com.ryanmichela.sshd.MkpasswdCommand;
@ -17,53 +23,62 @@ import java.nio.file.Files;
import java.util.Collections;
import java.util.logging.Level;
/**
* Copyright 2013 Ryan Michela
*/
public
class SshdPlugin extends JavaPlugin
import com.google.inject.Inject;
import org.slf4j.Logger;
import org.spongepowered.api.text.Text;
@Plugin(id = "spongesshd", name = "Sponge-SSHD", version = "1.3.7", description = "Sponge port for Minecraft-SSHD. SSH for your minecraft server!")
public class SshdPlugin
{
String ListenAddress = "";
Integer Port = 1025;
String Mode = "";
Boolean EnableSFTP = true;
Integer LoginRetries = 3;
String PasswordType = "";
// Credentials
private SshServer sshd;
public static SshdPlugin instance;
private File modConfigFolder;
CommandSpec MkpasswdCommand = CommandSpec.builder()
.description(Text.of("Make a SSHD password hash"))
.permission("sshd.mkpasswd")
.build();
@Override public void onLoad()
public File getDataFolder()
{
return modConfigFolder;
}
private SshServer sshd;
public static SshdPlugin instance;
@Inject
public Logger logger;
public Config config;
@Listener
public void onServerStart(GameStartedServerEvent event)
{
saveDefaultConfig();
File authorizedKeys = new File(getDataFolder(), "authorized_keys");
if (!authorizedKeys.exists())
authorizedKeys.mkdirs();
instance = this;
// Parse our config
config = new Config();
config.setup();
try
{
File motd = new File(getDataFolder(), "motd.txt");
if (!motd.exists())
{
InputStream link = (getClass().getResourceAsStream("/motd.txt"));
Files.copy(link, motd.getAbsoluteFile().toPath());
}
}
catch (IOException e)
{
e.printStackTrace();
}
// Now include it in our dealio here
this.Mode = config.configNode.getNode("Mode").getString();
this.PasswordType = config.configNode.getNode("PasswordType").getString();
this.ListenAddress = config.configNode.getNode("ListenAddress").getString();
this.Port = config.configNode.getNode("Port").getInt();
this.LoginRetries = config.configNode.getNode("LoginRetries").getInt();
this.EnableSFTP = config.configNode.getNode("EnableSFTP").getBoolean();
// 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;
sshd = SshServer.setUpDefaultServer();
sshd.setPort(getConfig().getInt("Port", 1025));
String host = getConfig().getString("ListenAddress", "all");
sshd.setPort(this.Port);
String host = this.ListenAddress;
sshd.setHost(host.equals("all") ? null : host);
File hostKey = new File(getDataFolder(), "hostkey");
File hostKey = new File(getDataFolder(), "hostkey");
File authorizedKeys = new File(getDataFolder(), "authorized_keys");
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(hostKey.toPath()));
@ -71,14 +86,17 @@ class SshdPlugin extends JavaPlugin
sshd.setPasswordAuthenticator(new ConfigPasswordAuthenticator());
sshd.setPublickeyAuthenticator(new PublicKeyAuthenticator(authorizedKeys));
if (getConfig().getBoolean("EnableSFTP"))
if (this.EnableSFTP)
{
sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory()));
sshd.setFileSystemFactory(
new VirtualFileSystemFactory(FileSystems.getDefault().getPath(getDataFolder().getAbsolutePath()).getParent().getParent()));
new VirtualFileSystemFactory(FileSystems.getDefault().getPath(getDataFolder().getAbsolutePath()).getParent().getParent()));
}
this.getCommand("mkpasswd").setExecutor(new MkpasswdCommand());
Sponge.getCommandManager().register(instance, MkpasswdCommand, "mkpasswd");
//this.getCommand("mkpasswd").setExecutor(new MkpasswdCommand());
sshd.setCommandFactory(new ConsoleCommandFactory());
try
@ -87,19 +105,14 @@ class SshdPlugin extends JavaPlugin
}
catch (IOException e)
{
getLogger().log(Level.SEVERE, "Failed to start SSH server! ", e);
getLogger().error("Failed to start SSH server! ", e);
}
logger.info("Successfully running ExamplePlugin!!!");
}
@Override public void onDisable()
public Logger getLogger()
{
try
{
sshd.stop();
}
catch (Exception e)
{
// do nothing
}
return logger;
}
}

View File

@ -1,29 +1,17 @@
package com.ryanmichela.sshd.implementations;
import com.ryanmichela.sshd.SshdPlugin;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.conversations.Conversation;
import org.bukkit.conversations.ConversationAbandonedEvent;
import org.bukkit.conversations.ManuallyAbandonedConversationCanceller;
import org.bukkit.permissions.PermissibleBase;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
import com.ryanmichela.sshd.ConsoleShellFactory;
import com.ryanmichela.sshd.ConsoleLogFormatter;
import org.spongepowered.api.command.CommandSource;
import java.io.IOException;
import java.util.Arrays;
import java.util.Set;
import java.util.logging.Level;
public class SSHDCommandSender implements ConsoleCommandSender, CommandSender
// This is gonna be a mess.
public class SSHDCommandSender implements ConsoleCommandSender, CommandSource
{
private final PermissibleBase perm = new PermissibleBase(this);
private final SSHDConversationTracker conversationTracker = new SSHDConversationTracker();

View File

@ -0,0 +1,124 @@
package com.ryanmichela.sshd.utils;
import ninja.leaping.configurate.loader.ConfigurationLoader;
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
import org.spongepowered.api.config.DefaultConfig;
import com.google.inject.Inject;
import com.ryanmichela.sshd.SshdPlugin;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.io.IOException;
public class Config
{
// Give us a config!
@Inject
@DefaultConfig(sharedRoot = true)
// idk what to do with this one.
private ConfigurationLoader<CommentedConfigurationNode> configLoader = HoconConfigurationLoader.builder().setPath(SshdPlugin.instance.defaultConfig).build();
public CommentedConfigurationNode configNode;
public void setup()
{
// I'm not sure if this will even work, the sponge config API is confusing.
if (!Files.exists((Path) SshdPlugin.instance.config.configLoader.getDefaultOptions()))
{
try
{
Files.createFile((Path) SshdPlugin.instance.config.configLoader.getDefaultOptions());
this.load();
this.populate();
this.save();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
else
this.load();
}
public void load()
{
try
{
configNode = this.configLoader.load();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
public void save()
{
try
{
this.configLoader.save(this.configNode);
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
public void populate()
{
this.configNode.getNode("ListenAddress").setValue("all").setComment
("The IP addresses(s) the SSH server will listen on. Use a comma separated list for multiple addresses.\n" +
"Leave as \"all\" for all addresses.");
this.configNode.getNode("Port").setValue("1025").setComment(
"# The port the SSH server will listen on. Note that anything above 1024 will require you to run\n" +
"# the whole minecraft server with elevated privileges, this is not recommended and you should\n" +
"# use iptables to route packets from a lower port.");
this.configNode.getNode("Mode").setValue("DEFAULT").setComment("Operational mode. Don't touch if you don't know what you're doing. Can be either DEFAULT or RPC");
this.configNode.getNode("EnableSFTP").setValue("true").setComment(
"# Enable built-in SFTP server or not. You'll be able to connect and upload/download files via SFTP protocol.\n" +
"# Might be useful for testing purposes as well , i. e. docker containers.");
this.configNode.getNode("LoginRetries").setValue("3").setComment(
"# Number of times a person can fail to use an SSH key or enter a password\n" +
"# before it terminates the connection.");
this.configNode.getNode("PasswordType").setValue("bcrypt").setComment
("########################################################################################\n" +
"# By default, only public key authentication is enabled. This is the most secure mode.\n" +
"# To authorize a user to login with their public key, install their key using the\n" +
"# OpenSSH authorized_keys file format in the authorized_users directory. Name the key\n" +
"# file with the user's username and no extension. Note: If you want to let a user have\n" +
"# many keys, you can append the keys to their file in authorized_users.\n" +
"########################################################################################\n" +
"For less secure username and password based authentication, complete the sections below.\n" +
"\n" +
"# Type of hashing to use for the passwords below.\n" +
"# Options are: PLAIN (insecure), bcrypt, pbkdf2, sha256\n" +
"#\n" +
"# You can use the console/in-game command `/mkpasswd [hash] PASSWORD` to\n" +
"# generate a password hash string then copy it for your passwords below.\n" +
"# You can also use `/mkpasswd help` to see what algorithms are supported.");
//this.configNode.getNode("").setValue("").setComment("");
/*
this.Mode = config.configNode.getNode("Mode").getString();
this.PasswordType = config.configNode.getNode("PasswordType").getString();
this.ListenAddress = config.configNode.getNode("ListenAddress").getString();
this.Port = config.configNode.getNode("Port").getInt();
this.LoginRetries = config.configNode.getNode("LoginRetries").getInt();
this.EnableSFTP = config.configNode.getNode("EnableSFTP").getBoolean();
this.configNode.getNode("mysql").setComment("MySQL database for Whitelisting");
this.configNode.getNode("mysql", "port").setValue(3306).setComment("MySQL server port");
this.configNode.getNode("mysql", "host").setValue("localhost").setComment("MySQL server to connect to");
this.configNode.getNode("mysql", "database").setValue("WhitelistSync").setComment("MySQL database for Whitelisting");
this.configNode.getNode("mysql", "username").setValue("Whitelist").setComment("MySQL username for the database");
this.configNode.getNode("mysql", "password").setValue("letmein").setComment("MySQL password for the database");
*/
}
}

View File

@ -12,339 +12,411 @@ import java.util.logging.Level;
/**
* Copyright 2013 Ryan Michela
*/
public class PluginSlf4jFactory implements ILoggerFactory {
@Override
public Logger getLogger(String name) {
return new PluginSlf4jAdapter(name);
}
public class PluginSlf4jAdapter implements Logger {
private String name;
private boolean isEnabled(Level level) {
return SshdPlugin.instance != null && SshdPlugin.instance.getLogger().isLoggable(level);
}
private void log(Level level, String s, Object[] objects) {
if (SshdPlugin.instance != null && isEnabled(level)) {
FormattingTuple ft = MessageFormatter.arrayFormat(s, objects);
SshdPlugin.instance.getLogger().log(level, ft.getMessage(), ft.getThrowable());
}
}
private void log(Level level, String s, Throwable throwable) {
if (SshdPlugin.instance != null && isEnabled(level)) {
SshdPlugin.instance.getLogger().log(level, s, throwable);
}
}
public PluginSlf4jAdapter(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
}
@Override
public boolean isTraceEnabled() {
return isEnabled(Level.FINEST);
}
@Override
public void trace(String s) {
trace(s, new Object[]{});
}
@Override
public void trace(String s, Object o) {
trace(s, new Object[]{o});
}
@Override
public void trace(String s, Object o, Object o1) {
trace(s, new Object[]{o, o1});
}
@Override
public void trace(String s, Object[] objects) {
log(Level.FINEST, s, objects);
}
@Override
public void trace(String s, Throwable throwable) {
log(Level.FINEST, s, throwable);
}
@Override
public boolean isTraceEnabled(Marker marker) {
return isTraceEnabled();
}
@Override
public void trace(Marker marker, String s) {
trace(s);
}
@Override
public void trace(Marker marker, String s, Object o) {
trace(s, o);
}
@Override
public void trace(Marker marker, String s, Object o, Object o1) {
trace(s, o, o1);
}
@Override
public void trace(Marker marker, String s, Object[] objects) {
trace(s, objects);
}
@Override
public void trace(Marker marker, String s, Throwable throwable) {
trace(s, throwable);
}
@Override
public boolean isDebugEnabled() {
return isEnabled(Level.FINE);
}
@Override
public void debug(String s) {
debug(s, new Object[]{});
}
@Override
public void debug(String s, Object o) {
debug(s, new Object[]{o});
}
@Override
public void debug(String s, Object o, Object o1) {
debug(s, new Object[]{o, o1});
}
@Override
public void debug(String s, Object[] objects) {
log(Level.FINE, s, objects);
}
@Override
public void debug(String s, Throwable throwable) {
log(Level.FINE, s, throwable);
}
@Override
public boolean isDebugEnabled(Marker marker) {
return isDebugEnabled();
}
@Override
public void debug(Marker marker, String s) {
debug(s);
}
@Override
public void debug(Marker marker, String s, Object o) {
debug(s, o);
}
@Override
public void debug(Marker marker, String s, Object o, Object o1) {
debug(s, o, o1);
}
@Override
public void debug(Marker marker, String s, Object[] objects) {
debug(s, objects);
}
@Override
public void debug(Marker marker, String s, Throwable throwable) {
debug(s, throwable);
}
@Override
public boolean isInfoEnabled() {
return isEnabled(Level.INFO);
}
@Override
public void info(String s) {
info(s, new Object[]{});
}
@Override
public void info(String s, Object o) {
info(s, new Object[]{o});
}
@Override
public void info(String s, Object o, Object o1) {
info(s, new Object[]{o, o1});
}
@Override
public void info(String s, Object[] objects) {
log(Level.INFO, s, objects);
}
@Override
public void info(String s, Throwable throwable) {
log(Level.INFO, s, throwable);
}
@Override
public boolean isInfoEnabled(Marker marker) {
return isInfoEnabled();
}
@Override
public void info(Marker marker, String s) {
info(s);
}
@Override
public void info(Marker marker, String s, Object o) {
info(s, o);
}
@Override
public void info(Marker marker, String s, Object o, Object o1) {
info(s, o, o1);
}
@Override
public void info(Marker marker, String s, Object[] objects) {
info(s, objects);
}
@Override
public void info(Marker marker, String s, Throwable throwable) {
info(s, throwable);
}
@Override
public boolean isWarnEnabled() {
return isEnabled(Level.WARNING);
}
@Override
public void warn(String s) {
warn(s, new Object[]{});
}
@Override
public void warn(String s, Object o) {
warn(s, new Object[]{o});
}
@Override
public void warn(String s, Object o, Object o1) {
warn(s, new Object[]{o, o1});
}
@Override
public void warn(String s, Object[] objects) {
log(Level.WARNING, s, objects);
}
@Override
public void warn(String s, Throwable throwable) {
log(Level.WARNING, s, throwable);
}
@Override
public boolean isWarnEnabled(Marker marker) {
return isWarnEnabled();
}
@Override
public void warn(Marker marker, String s) {
warn(s);
}
@Override
public void warn(Marker marker, String s, Object o) {
warn(s, o);
}
@Override
public void warn(Marker marker, String s, Object o, Object o1) {
warn(s, o, o1);
}
@Override
public void warn(Marker marker, String s, Object[] objects) {
warn(s, objects);
}
@Override
public void warn(Marker marker, String s, Throwable throwable) {
warn(s, throwable);
}
@Override
public boolean isErrorEnabled() {
return isEnabled(Level.SEVERE);
}
@Override
public void error(String s) {
error(s, new Object[]{});
}
@Override
public void error(String s, Object o) {
error(s, new Object[]{o});
}
@Override
public void error(String s, Object o, Object o1) {
error(s, new Object[]{o, o1});
}
@Override
public void error(String s, Object[] objects) {
log(Level.SEVERE, s, objects);
}
@Override
public void error(String s, Throwable throwable) {
log(Level.SEVERE, s, throwable);
}
@Override
public boolean isErrorEnabled(Marker marker) {
return isErrorEnabled();
}
@Override
public void error(Marker marker, String s) {
error(s);
}
@Override
public void error(Marker marker, String s, Object o) {
error(s, o);
}
@Override
public void error(Marker marker, String s, Object o, Object o1) {
error(s, o, o1);
}
@Override
public void error(Marker marker, String s, Object[] objects) {
error(s, objects);
}
@Override
public void error(Marker marker, String s, Throwable throwable) {
error(s, throwable);
}
}
// figure out logging...
public class PluginSlf4jFactory implements ILoggerFactory
{
@Override
public Logger getLogger(String name)
{
return new PluginSlf4jAdapter(name);
}
public class PluginSlf4jAdapter implements Logger
{
private String name;
private boolean isEnabled(Level level)
{
// ???
return SshdPlugin.instance != null && SshdPlugin.instance.logger.isLoggable(level);
}
private void log(Level level, String s, Object[] objects)
{
if (SshdPlugin.instance != null && isEnabled(level))
{
FormattingTuple ft = MessageFormatter.arrayFormat(s, objects);
SshdPlugin.instance.getLogger().log(level, ft.getMessage(), ft.getThrowable());
}
}
private void log(Level level, String s, Throwable throwable)
{
if (SshdPlugin.instance != null && isEnabled(level))
{
SshdPlugin.instance.logger.log(level, s, throwable);
}
}
public PluginSlf4jAdapter(String name)
{
this.name = name;
}
@Override
public String getName()
{
return name;
}
@Override
public boolean isTraceEnabled()
{
return isEnabled(Level.FINEST);
}
@Override
public void trace(String s)
{
trace(s, new Object[]{});
}
@Override
public void trace(String s, Object o)
{
trace(s, new Object[]{o});
}
@Override
public void trace(String s, Object o, Object o1)
{
trace(s, new Object[]{o, o1});
}
@Override
public void trace(String s, Object[] objects)
{
log(Level.FINEST, s, objects);
}
@Override
public void trace(String s, Throwable throwable)
{
log(Level.FINEST, s, throwable);
}
@Override
public boolean isTraceEnabled(Marker marker)
{
return isTraceEnabled();
}
@Override
public void trace(Marker marker, String s)
{
trace(s);
}
@Override
public void trace(Marker marker, String s, Object o)
{
trace(s, o);
}
@Override
public void trace(Marker marker, String s, Object o, Object o1)
{
trace(s, o, o1);
}
@Override
public void trace(Marker marker, String s, Object[] objects)
{
trace(s, objects);
}
@Override
public void trace(Marker marker, String s, Throwable throwable)
{
trace(s, throwable);
}
@Override
public boolean isDebugEnabled()
{
return isEnabled(Level.FINE);
}
@Override
public void debug(String s)
{
debug(s, new Object[]{});
}
@Override
public void debug(String s, Object o)
{
debug(s, new Object[]{o});
}
@Override
public void debug(String s, Object o, Object o1)
{
debug(s, new Object[]{o, o1});
}
@Override
public void debug(String s, Object[] objects)
{
log(Level.FINE, s, objects);
}
@Override
public void debug(String s, Throwable throwable)
{
log(Level.FINE, s, throwable);
}
@Override
public boolean isDebugEnabled(Marker marker)
{
return isDebugEnabled();
}
@Override
public void debug(Marker marker, String s)
{
debug(s);
}
@Override
public void debug(Marker marker, String s, Object o)
{
debug(s, o);
}
@Override
public void debug(Marker marker, String s, Object o, Object o1)
{
debug(s, o, o1);
}
@Override
public void debug(Marker marker, String s, Object[] objects)
{
debug(s, objects);
}
@Override
public void debug(Marker marker, String s, Throwable throwable)
{
debug(s, throwable);
}
@Override
public boolean isInfoEnabled()
{
return isEnabled(Level.INFO);
}
@Override
public void info(String s)
{
info(s, new Object[]{});
}
@Override
public void info(String s, Object o)
{
info(s, new Object[]{o});
}
@Override
public void info(String s, Object o, Object o1)
{
info(s, new Object[]{o, o1});
}
@Override
public void info(String s, Object[] objects)
{
log(Level.INFO, s, objects);
}
@Override
public void info(String s, Throwable throwable)
{
log(Level.INFO, s, throwable);
}
@Override
public boolean isInfoEnabled(Marker marker)
{
return isInfoEnabled();
}
@Override
public void info(Marker marker, String s)
{
info(s);
}
@Override
public void info(Marker marker, String s, Object o)
{
info(s, o);
}
@Override
public void info(Marker marker, String s, Object o, Object o1)
{
info(s, o, o1);
}
@Override
public void info(Marker marker, String s, Object[] objects)
{
info(s, objects);
}
@Override
public void info(Marker marker, String s, Throwable throwable)
{
info(s, throwable);
}
@Override
public boolean isWarnEnabled()
{
return isEnabled(Level.WARNING);
}
@Override
public void warn(String s)
{
warn(s, new Object[]{});
}
@Override
public void warn(String s, Object o)
{
warn(s, new Object[]{o});
}
@Override
public void warn(String s, Object o, Object o1)
{
warn(s, new Object[]{o, o1});
}
@Override
public void warn(String s, Object[] objects)
{
log(Level.WARNING, s, objects);
}
@Override
public void warn(String s, Throwable throwable)
{
log(Level.WARNING, s, throwable);
}
@Override
public boolean isWarnEnabled(Marker marker)
{
return isWarnEnabled();
}
@Override
public void warn(Marker marker, String s)
{
warn(s);
}
@Override
public void warn(Marker marker, String s, Object o)
{
warn(s, o);
}
@Override
public void warn(Marker marker, String s, Object o, Object o1)
{
warn(s, o, o1);
}
@Override
public void warn(Marker marker, String s, Object[] objects)
{
warn(s, objects);
}
@Override
public void warn(Marker marker, String s, Throwable throwable)
{
warn(s, throwable);
}
@Override
public boolean isErrorEnabled()
{
return isEnabled(Level.SEVERE);
}
@Override
public void error(String s)
{
error(s, new Object[]{});
}
@Override
public void error(String s, Object o)
{
error(s, new Object[]{o});
}
@Override
public void error(String s, Object o, Object o1)
{
error(s, new Object[]{o, o1});
}
@Override
public void error(String s, Object[] objects)
{
log(Level.SEVERE, s, objects);
}
@Override
public void error(String s, Throwable throwable)
{
log(Level.SEVERE, s, throwable);
}
@Override
public boolean isErrorEnabled(Marker marker)
{
return isErrorEnabled();
}
@Override
public void error(Marker marker, String s)
{
error(s);
}
@Override
public void error(Marker marker, String s, Object o)
{
error(s, o);
}
@Override
public void error(Marker marker, String s, Object o, Object o1)
{
error(s, o, o1);
}
@Override
public void error(Marker marker, String s, Object[] objects)
{
error(s, objects);
}
@Override
public void error(Marker marker, String s, Throwable throwable)
{
error(s, throwable);
}
}
}