Search in sources :

Example 1 with ScpCommandFactory

use of org.apache.sshd.server.command.ScpCommandFactory 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 ScpCommandFactory

use of org.apache.sshd.server.command.ScpCommandFactory 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 3 with ScpCommandFactory

use of org.apache.sshd.server.command.ScpCommandFactory 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 4 with ScpCommandFactory

use of org.apache.sshd.server.command.ScpCommandFactory 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)4 ScpCommandFactory (org.apache.sshd.server.command.ScpCommandFactory)4 Command (org.apache.sshd.server.Command)3 ServerSession (org.apache.sshd.server.session.ServerSession)3 IOException (java.io.IOException)2 PublicKey (java.security.PublicKey)2 FileKeyPairProvider (org.apache.sshd.common.keyprovider.FileKeyPairProvider)2 PublickeyAuthenticator (org.apache.sshd.server.PublickeyAuthenticator)2 ChannelSftp (com.jcraft.jsch.ChannelSftp)1 JSch (com.jcraft.jsch.JSch)1 Session (com.jcraft.jsch.Session)1 File (java.io.File)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 FtpServerFactory (org.apache.ftpserver.FtpServerFactory)1 NativeFileSystemFactory (org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory)1 UserManager (org.apache.ftpserver.ftplet.UserManager)1 ListenerFactory (org.apache.ftpserver.listener.ListenerFactory)1 SslConfigurationFactory (org.apache.ftpserver.ssl.SslConfigurationFactory)1 ClearTextPasswordEncryptor (org.apache.ftpserver.usermanager.ClearTextPasswordEncryptor)1 PropertiesUserManagerFactory (org.apache.ftpserver.usermanager.PropertiesUserManagerFactory)1