Search in sources :

Example 1 with NamedFactory

use of org.apache.sshd.common.NamedFactory in project camel by apache.

the class SftpServerTestSupport method setUpServer.

protected void setUpServer() throws Exception {
    canTest = true;
    try {
        sshd = SshServer.setUpDefaultServer();
        sshd.setPort(getPort());
        sshd.setKeyPairProvider(new FileKeyPairProvider(new String[] { "src/test/resources/hostkey.pem" }));
        sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
        sshd.setCommandFactory(new ScpCommandFactory());
        sshd.setPasswordAuthenticator(new MyPasswordAuthenticator());
        PublickeyAuthenticator publickeyAuthenticator = new PublickeyAuthenticator() {

            // consider all keys as authorized for all users
            @Override
            public boolean authenticate(String username, PublicKey key, ServerSession session) {
                return true;
            }
        };
        sshd.setPublickeyAuthenticator(publickeyAuthenticator);
        sshd.start();
    } catch (Exception e) {
        // ignore if algorithm is not on the OS
        NoSuchAlgorithmException nsae = ObjectHelper.getException(NoSuchAlgorithmException.class, e);
        if (nsae != null) {
            canTest = false;
            String name = System.getProperty("os.name");
            String message = nsae.getMessage();
            log.warn("SunX509 is not avail on this platform [{}] Testing is skipped! Real cause: {}", name, message);
        } else {
            // some other error then throw it so the test can fail
            throw e;
        }
    }
}
Also used : ScpCommandFactory(org.apache.sshd.server.command.ScpCommandFactory) FileKeyPairProvider(org.apache.sshd.common.keyprovider.FileKeyPairProvider) ServerSession(org.apache.sshd.server.session.ServerSession) PublickeyAuthenticator(org.apache.sshd.server.PublickeyAuthenticator) Command(org.apache.sshd.server.Command) PublicKey(java.security.PublicKey) ScpCommandFactory(org.apache.sshd.server.command.ScpCommandFactory) NamedFactory(org.apache.sshd.common.NamedFactory) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 2 with NamedFactory

use of org.apache.sshd.common.NamedFactory in project hadoop by apache.

the class TestSFTPFileSystem method startSshdServer.

private static void startSshdServer() throws IOException {
    sshd = SshServer.setUpDefaultServer();
    // ask OS to assign a port
    sshd.setPort(0);
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
    List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
    userAuthFactories.add(new UserAuthPassword.Factory());
    sshd.setUserAuthFactories(userAuthFactories);
    sshd.setPasswordAuthenticator(new PasswordAuthenticator() {

        @Override
        public boolean authenticate(String username, String password, ServerSession session) {
            if (username.equals("user") && password.equals("password")) {
                return true;
            }
            return false;
        }
    });
    sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
    sshd.start();
    port = sshd.getPort();
}
Also used : SimpleGeneratorHostKeyProvider(org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider) ServerSession(org.apache.sshd.server.session.ServerSession) ArrayList(java.util.ArrayList) NamedFactory(org.apache.sshd.common.NamedFactory) PasswordAuthenticator(org.apache.sshd.server.PasswordAuthenticator) Command(org.apache.sshd.server.Command) NamedFactory(org.apache.sshd.common.NamedFactory) UserAuth(org.apache.sshd.server.UserAuth) UserAuthPassword(org.apache.sshd.server.auth.UserAuthPassword)

Example 3 with NamedFactory

use of org.apache.sshd.common.NamedFactory in project quickstarts by jboss-switchyard.

the class CamelFtpBindingTest method startUp.

@BeforeClass
public static void startUp() throws Exception {
    FtpServerFactory serverFactory = new FtpServerFactory();
    ListenerFactory listenerFactory = new ListenerFactory();
    listenerFactory.setPort(2222);
    serverFactory.addListener("default", listenerFactory.createListener());
    ListenerFactory sslListenerFactory = new ListenerFactory();
    sslListenerFactory.setPort(2221);
    SslConfigurationFactory ssl = new SslConfigurationFactory();
    ssl.setKeystoreFile(new File("src/test/resources/ftpserver.jks"));
    ssl.setKeystorePassword("password");
    sslListenerFactory.setSslConfiguration(ssl.createSslConfiguration());
    // Setting it to true will not read the file
    sslListenerFactory.setImplicitSsl(false);
    serverFactory.addListener("ftps", sslListenerFactory.createListener());
    PropertiesUserManagerFactory managerFactory = new PropertiesUserManagerFactory();
    managerFactory.setPasswordEncryptor(new ClearTextPasswordEncryptor());
    managerFactory.setFile(new File("src/test/resources/users.properties"));
    UserManager createUserManager = managerFactory.createUserManager();
    serverFactory.setUserManager(createUserManager);
    NativeFileSystemFactory fileSystemFactory = new NativeFileSystemFactory();
    fileSystemFactory.setCreateHome(true);
    serverFactory.setFileSystem(fileSystemFactory);
    File file = new File("target/ftp/ftps");
    file.mkdirs();
    file = new File("target/ftp/sftp");
    file.mkdirs();
    ftpServer = serverFactory.createServer();
    ftpServer.start();
    SshServer sshd = SshServer.setUpDefaultServer();
    sshd.setPort(2220);
    sshd.setKeyPairProvider(createTestKeyPairProvider("src/test/resources/hostkey.pem"));
    sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
    sshd.setCommandFactory(new ScpCommandFactory());
    sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
    sshd.start();
    JSch sch = new JSch();
    Session session = sch.getSession("camel", "localhost", 2220);
    session.setUserInfo(new SimpleUserInfo("isMyFriend"));
    session.connect();
    ChannelSftp c = (ChannelSftp) session.openChannel("sftp");
    c.connect();
    System.out.println("Home: " + c.getHome());
    c.chmod(777, ".");
    c.chmod(777, "target");
    c.chmod(777, "target/ftp");
    c.chmod(777, "target/ftp/sftp");
    c.disconnect();
    session.disconnect();
}
Also used : FtpServerFactory(org.apache.ftpserver.FtpServerFactory) NativeFileSystemFactory(org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory) NativeFileSystemFactory(org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory) ScpCommandFactory(org.apache.sshd.server.command.ScpCommandFactory) PropertiesUserManagerFactory(org.apache.ftpserver.usermanager.PropertiesUserManagerFactory) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory) SslConfigurationFactory(org.apache.ftpserver.ssl.SslConfigurationFactory) FtpServerFactory(org.apache.ftpserver.FtpServerFactory) NamedFactory(org.apache.sshd.common.NamedFactory) JSch(com.jcraft.jsch.JSch) ClearTextPasswordEncryptor(org.apache.ftpserver.usermanager.ClearTextPasswordEncryptor) SshServer(org.apache.sshd.SshServer) ScpCommandFactory(org.apache.sshd.server.command.ScpCommandFactory) ChannelSftp(com.jcraft.jsch.ChannelSftp) Command(org.apache.sshd.server.Command) UserManager(org.apache.ftpserver.ftplet.UserManager) PropertiesUserManagerFactory(org.apache.ftpserver.usermanager.PropertiesUserManagerFactory) SslConfigurationFactory(org.apache.ftpserver.ssl.SslConfigurationFactory) File(java.io.File) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory) ServerSession(org.apache.sshd.server.session.ServerSession) Session(com.jcraft.jsch.Session) BeforeClass(org.junit.BeforeClass)

Example 4 with NamedFactory

use of org.apache.sshd.common.NamedFactory in project camel by apache.

the class ScpServerTestSupport method startSshd.

protected boolean startSshd() {
    sshd = SshServer.setUpDefaultServer();
    sshd.setPort(getPort());
    sshd.setKeyPairProvider(new FileKeyPairProvider(new String[] { "src/test/resources/hostkey.pem" }));
    sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
    sshd.setCommandFactory(new ScpCommandFactory());
    sshd.setPasswordAuthenticator(new PasswordAuthenticator() {

        @Override
        public boolean authenticate(String username, String password, ServerSession session) {
            // dummy authentication: allow any user whose password is the same as the username
            return username != null && username.equals(password);
        }
    });
    sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {

        @Override
        public boolean authenticate(String username, PublicKey key, ServerSession session) {
            return true;
        }
    });
    try {
        sshd.start();
        return true;
    } catch (IOException e) {
        LOG.info("Failed to start ssh server.", e);
    }
    return false;
}
Also used : ScpCommandFactory(org.apache.sshd.server.command.ScpCommandFactory) FileKeyPairProvider(org.apache.sshd.common.keyprovider.FileKeyPairProvider) ServerSession(org.apache.sshd.server.session.ServerSession) PasswordAuthenticator(org.apache.sshd.server.PasswordAuthenticator) PublickeyAuthenticator(org.apache.sshd.server.PublickeyAuthenticator) Command(org.apache.sshd.server.Command) PublicKey(java.security.PublicKey) LoggerFactory(org.slf4j.LoggerFactory) ScpCommandFactory(org.apache.sshd.server.command.ScpCommandFactory) NamedFactory(org.apache.sshd.common.NamedFactory) IOException(java.io.IOException)

Example 5 with NamedFactory

use of org.apache.sshd.common.NamedFactory in project kdeconnect-android by KDE.

the class SimpleSftpServer method init.

public void init(Context context, Device device) {
    sshd.setKeyExchangeFactories(Arrays.asList(new DHG14.Factory(), new DHG1.Factory()));
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(context.getFilesDir() + "/sftpd.ser"));
    sshd.setFileSystemFactory(new AndroidFileSystemFactory(context));
    sshd.setCommandFactory(new ScpCommandFactory());
    sshd.setSubsystemFactories(Collections.singletonList((NamedFactory<Command>) new SftpSubsystem.Factory()));
    if (device.publicKey != null) {
        keyAuth.deviceKey = device.publicKey;
        sshd.setPublickeyAuthenticator(keyAuth);
    }
    sshd.setPasswordAuthenticator(passwordAuth);
}
Also used : SimpleGeneratorHostKeyProvider(org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider) ScpCommandFactory(org.apache.sshd.server.command.ScpCommandFactory) NamedFactory(org.apache.sshd.common.NamedFactory) FileSystemFactory(org.apache.sshd.server.FileSystemFactory) ScpCommandFactory(org.apache.sshd.server.command.ScpCommandFactory) NamedFactory(org.apache.sshd.common.NamedFactory) SftpSubsystem(org.apache.sshd.server.sftp.SftpSubsystem)

Aggregations

NamedFactory (org.apache.sshd.common.NamedFactory)6 Command (org.apache.sshd.server.Command)4 ScpCommandFactory (org.apache.sshd.server.command.ScpCommandFactory)4 ServerSession (org.apache.sshd.server.session.ServerSession)4 IOException (java.io.IOException)3 PublicKey (java.security.PublicKey)2 FileKeyPairProvider (org.apache.sshd.common.keyprovider.FileKeyPairProvider)2 PasswordAuthenticator (org.apache.sshd.server.PasswordAuthenticator)2 PublickeyAuthenticator (org.apache.sshd.server.PublickeyAuthenticator)2 SimpleGeneratorHostKeyProvider (org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider)2 ChannelSftp (com.jcraft.jsch.ChannelSftp)1 JSch (com.jcraft.jsch.JSch)1 JSchException (com.jcraft.jsch.JSchException)1 Session (com.jcraft.jsch.Session)1 File (java.io.File)1 UnknownHostException (java.net.UnknownHostException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 FtpServerFactory (org.apache.ftpserver.FtpServerFactory)1