mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-08 16:18:05 +03:00
Upgraded sshd to 2.1.0
This commit is contained in:
@@ -48,6 +48,7 @@ targetCompatibility = 1.6
|
|||||||
configurations.compile.transitive = false
|
configurations.compile.transitive = false
|
||||||
|
|
||||||
def bouncycastleVersion = "1.60"
|
def bouncycastleVersion = "1.60"
|
||||||
|
def sshdVersion = "2.1.0"
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
signature 'org.codehaus.mojo.signature:java16:1.1@signature'
|
signature 'org.codehaus.mojo.signature:java16:1.1@signature'
|
||||||
@@ -62,7 +63,9 @@ dependencies {
|
|||||||
testCompile "junit:junit:4.11"
|
testCompile "junit:junit:4.11"
|
||||||
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
|
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
|
||||||
testCompile "org.mockito:mockito-core:2.9.2"
|
testCompile "org.mockito:mockito-core:2.9.2"
|
||||||
testCompile "org.apache.sshd:sshd-core:1.2.0"
|
testCompile "org.apache.sshd:sshd-core:$sshdVersion"
|
||||||
|
testCompile "org.apache.sshd:sshd-sftp:$sshdVersion"
|
||||||
|
testCompile "org.apache.sshd:sshd-scp:$sshdVersion"
|
||||||
testRuntime "ch.qos.logback:logback-classic:1.1.2"
|
testRuntime "ch.qos.logback:logback-classic:1.1.2"
|
||||||
testCompile 'org.glassfish.grizzly:grizzly-http-server:2.3.17'
|
testCompile 'org.glassfish.grizzly:grizzly-http-server:2.3.17'
|
||||||
testCompile 'org.apache.httpcomponents:httpclient:4.5.2'
|
testCompile 'org.apache.httpcomponents:httpclient:4.5.2'
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class RemotePortForwarderTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws IOException {
|
public void setUp() throws IOException {
|
||||||
fixture.getServer().setTcpipForwardingFilter(new AcceptAllForwardingFilter());
|
fixture.getServer().setForwardingFilter(new AcceptAllForwardingFilter());
|
||||||
File file = httpServer.getDocRoot().newFile("index.html");
|
File file = httpServer.getDocRoot().newFile("index.html");
|
||||||
FileUtil.writeToFile(file, "<html><head/><body><h1>Hi!</h1></body></html>");
|
FileUtil.writeToFile(file, "<html><head/><body><h1>Hi!</h1></body></html>");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,12 +20,11 @@ import net.schmizz.sshj.DefaultConfig;
|
|||||||
import net.schmizz.sshj.SSHClient;
|
import net.schmizz.sshj.SSHClient;
|
||||||
import net.schmizz.sshj.util.gss.BogusGSSAuthenticator;
|
import net.schmizz.sshj.util.gss.BogusGSSAuthenticator;
|
||||||
import org.apache.sshd.common.NamedFactory;
|
import org.apache.sshd.common.NamedFactory;
|
||||||
import org.apache.sshd.common.keyprovider.AbstractClassLoadableResourceKeyPairProvider;
|
import org.apache.sshd.common.keyprovider.ClassLoadableResourceKeyPairProvider;
|
||||||
import org.apache.sshd.common.util.SecurityUtils;
|
|
||||||
import org.apache.sshd.server.Command;
|
|
||||||
import org.apache.sshd.server.CommandFactory;
|
|
||||||
import org.apache.sshd.server.SshServer;
|
import org.apache.sshd.server.SshServer;
|
||||||
import org.apache.sshd.server.auth.password.PasswordAuthenticator;
|
import org.apache.sshd.server.auth.password.PasswordAuthenticator;
|
||||||
|
import org.apache.sshd.server.command.Command;
|
||||||
|
import org.apache.sshd.server.command.CommandFactory;
|
||||||
import org.apache.sshd.server.scp.ScpCommandFactory;
|
import org.apache.sshd.server.scp.ScpCommandFactory;
|
||||||
import org.apache.sshd.server.session.ServerSession;
|
import org.apache.sshd.server.session.ServerSession;
|
||||||
import org.apache.sshd.server.shell.ProcessShellFactory;
|
import org.apache.sshd.server.shell.ProcessShellFactory;
|
||||||
@@ -35,7 +34,6 @@ import org.junit.rules.ExternalResource;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -108,8 +106,7 @@ public class SshFixture extends ExternalResource {
|
|||||||
private SshServer defaultSshServer() {
|
private SshServer defaultSshServer() {
|
||||||
SshServer sshServer = SshServer.setUpDefaultServer();
|
SshServer sshServer = SshServer.setUpDefaultServer();
|
||||||
sshServer.setPort(randomPort());
|
sshServer.setPort(randomPort());
|
||||||
AbstractClassLoadableResourceKeyPairProvider fileKeyPairProvider = SecurityUtils.createClassLoadableResourceKeyPairProvider();
|
ClassLoadableResourceKeyPairProvider fileKeyPairProvider = new ClassLoadableResourceKeyPairProvider(hostkey);
|
||||||
fileKeyPairProvider.setResources(Collections.singletonList(hostkey));
|
|
||||||
sshServer.setKeyPairProvider(fileKeyPairProvider);
|
sshServer.setKeyPairProvider(fileKeyPairProvider);
|
||||||
sshServer.setPasswordAuthenticator(new PasswordAuthenticator() {
|
sshServer.setPasswordAuthenticator(new PasswordAuthenticator() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import org.apache.sshd.server.auth.UserAuth;
|
|||||||
import org.apache.sshd.server.auth.password.PasswordAuthenticator;
|
import org.apache.sshd.server.auth.password.PasswordAuthenticator;
|
||||||
import org.apache.sshd.server.auth.password.PasswordChangeRequiredException;
|
import org.apache.sshd.server.auth.password.PasswordChangeRequiredException;
|
||||||
import org.apache.sshd.server.auth.password.UserAuthPassword;
|
import org.apache.sshd.server.auth.password.UserAuthPassword;
|
||||||
|
import org.apache.sshd.server.auth.password.UserAuthPasswordFactory;
|
||||||
import org.apache.sshd.server.session.ServerSession;
|
import org.apache.sshd.server.session.ServerSession;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
@@ -50,20 +51,24 @@ public class AuthPasswordTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setPasswordAuthenticator() throws IOException {
|
public void setPasswordAuthenticator() throws IOException {
|
||||||
fixture.getServer().setUserAuthFactories(Collections.<NamedFactory<UserAuth>>singletonList(new NamedFactory<UserAuth>() {
|
fixture.getServer().setUserAuthFactories(Collections.<NamedFactory<UserAuth>>singletonList(new NamedFactory<UserAuth>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "password";
|
return UserAuthPasswordFactory.NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserAuth get() {
|
||||||
|
return new UserAuthPassword() {
|
||||||
|
@Override
|
||||||
|
protected Boolean handleClientPasswordChangeRequest(Buffer buffer, ServerSession session, String username, String oldPassword, String newPassword) throws Exception {
|
||||||
|
return session.getPasswordAuthenticator().authenticate(username, newPassword, session);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserAuth create() {
|
public UserAuth create() {
|
||||||
return new UserAuthPassword() {
|
return get();
|
||||||
@Override
|
|
||||||
protected Boolean handleClientPasswordChangeRequest(Buffer buffer, ServerSession session, String username, String oldPassword, String newPassword) throws Exception {
|
|
||||||
return checkPassword(buffer, session, username, newPassword);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
fixture.getServer().setPasswordAuthenticator(new PasswordAuthenticator() {
|
fixture.getServer().setPasswordAuthenticator(new PasswordAuthenticator() {
|
||||||
|
|||||||
@@ -18,13 +18,13 @@ package net.schmizz.sshj.keyprovider;
|
|||||||
import com.hierynomus.sshj.userauth.certificate.Certificate;
|
import com.hierynomus.sshj.userauth.certificate.Certificate;
|
||||||
import com.hierynomus.sshj.userauth.keyprovider.OpenSSHKeyV1KeyFile;
|
import com.hierynomus.sshj.userauth.keyprovider.OpenSSHKeyV1KeyFile;
|
||||||
import net.schmizz.sshj.common.KeyType;
|
import net.schmizz.sshj.common.KeyType;
|
||||||
|
import net.schmizz.sshj.common.SecurityUtils;
|
||||||
import net.schmizz.sshj.userauth.keyprovider.FileKeyProvider;
|
import net.schmizz.sshj.userauth.keyprovider.FileKeyProvider;
|
||||||
import net.schmizz.sshj.userauth.keyprovider.OpenSSHKeyFile;
|
import net.schmizz.sshj.userauth.keyprovider.OpenSSHKeyFile;
|
||||||
import net.schmizz.sshj.userauth.password.PasswordFinder;
|
import net.schmizz.sshj.userauth.password.PasswordFinder;
|
||||||
import net.schmizz.sshj.userauth.password.PasswordUtils;
|
import net.schmizz.sshj.userauth.password.PasswordUtils;
|
||||||
import net.schmizz.sshj.userauth.password.Resource;
|
import net.schmizz.sshj.userauth.password.Resource;
|
||||||
import net.schmizz.sshj.util.KeyUtil;
|
import net.schmizz.sshj.util.KeyUtil;
|
||||||
import org.apache.sshd.common.util.SecurityUtils;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@@ -197,7 +197,7 @@ public class OpenSSHKeyFileTest {
|
|||||||
checkOpenSSHKeyV1("src/test/resources/keytypes/ed25519_aes256cbc.pem", "foobar");
|
checkOpenSSHKeyV1("src/test/resources/keytypes/ed25519_aes256cbc.pem", "foobar");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkOpenSSHKeyV1(String key, String password) throws IOException {
|
private void checkOpenSSHKeyV1(String key, final String password) throws IOException {
|
||||||
OpenSSHKeyV1KeyFile keyFile = new OpenSSHKeyV1KeyFile();
|
OpenSSHKeyV1KeyFile keyFile = new OpenSSHKeyV1KeyFile();
|
||||||
keyFile.init(new File(key), new PasswordFinder() {
|
keyFile.init(new File(key), new PasswordFinder() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user