Search in sources :

Example 11 with SimpleGeneratorHostKeyProvider

use of org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider in project testcases by coheigea.

the class SFTPTest method setup.

@Before
public void setup() throws Exception {
    int port = AvailablePortFinder.getNextAvailable(10000);
    // Write port number to configuration file in target
    String basedir = System.getProperty("basedir");
    if (basedir == null) {
        basedir = new File(".").getCanonicalPath();
    }
    // Read in camel configuration file and substitute in the correct port
    File f = new File(basedir + "/src/test/resources/camel-sftp.xml");
    FileInputStream inputStream = new FileInputStream(f);
    String content = IOUtils.toString(inputStream, "UTF-8");
    inputStream.close();
    content = content.replaceAll("portno", "" + port);
    File f2 = new File(basedir + "/target/test-classes/camel-sftp.xml");
    FileOutputStream outputStream = new FileOutputStream(f2);
    IOUtils.write(content, outputStream, "UTF-8");
    outputStream.close();
    sshServer = SshServer.setUpDefaultServer();
    sshServer.setPort(port);
    // Generate a key
    sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Paths.get("target/generatedkey.pem")));
    List<NamedFactory<Command>> subsystemFactories = new ArrayList<NamedFactory<Command>>(1);
    subsystemFactories.add(new SftpSubsystemFactory());
    sshServer.setSubsystemFactories(subsystemFactories);
    sshServer.setCommandFactory(new ScpCommandFactory());
    sshServer.setPasswordAuthenticator(new CamelPasswordAuthenticator());
    sshServer.start();
    // Create "storage_sftp" directory (delete it first if it exists)
    File storageDirectory = new File(basedir + "/target/storage_sftp");
    if (storageDirectory.exists()) {
        storageDirectory.delete();
    }
    storageDirectory.mkdir();
}
Also used : SimpleGeneratorHostKeyProvider(org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) SftpSubsystemFactory(org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory) ScpCommandFactory(org.apache.sshd.server.scp.ScpCommandFactory) Command(org.apache.sshd.server.Command) FileOutputStream(java.io.FileOutputStream) NamedFactory(org.apache.sshd.common.NamedFactory) File(java.io.File) Before(org.junit.Before)

Example 12 with SimpleGeneratorHostKeyProvider

use of org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider in project testcases by coheigea.

the class SSHTest method setup.

@Before
public void setup() throws Exception {
    int port = AvailablePortFinder.getNextAvailable(10000);
    // Write port number to configuration file in target
    String basedir = System.getProperty("basedir");
    if (basedir == null) {
        basedir = new File(".").getCanonicalPath();
    }
    // Read in camel configuration file and substitute in the correct port
    File f = new File(basedir + "/src/test/resources/camel-ssh.xml");
    FileInputStream inputStream = new FileInputStream(f);
    String content = IOUtils.toString(inputStream, "UTF-8");
    inputStream.close();
    content = content.replaceAll("portno", "" + port);
    File f2 = new File(basedir + "/target/test-classes/camel-ssh.xml");
    FileOutputStream outputStream = new FileOutputStream(f2);
    IOUtils.write(content, outputStream, "UTF-8");
    outputStream.close();
    sshServer = SshServer.setUpDefaultServer();
    sshServer.setPort(port);
    // Generate a key
    sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Paths.get("target/generatedkey.pem")));
    // Simple CommandFactory to run commands in a process
    sshServer.setCommandFactory(new CommandFactory() {

        public Command createCommand(String command) {
            return new ProcessShellFactory(command.split(";")).create();
        }
    });
    // sshServer.setShellFactory(new ProcessShellFactory(new String[] { "/bin/sh", "-i", "-l" }));
    sshServer.setPasswordAuthenticator(new CamelPasswordAuthenticator());
    sshServer.start();
}
Also used : SimpleGeneratorHostKeyProvider(org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider) Command(org.apache.sshd.server.Command) FileOutputStream(java.io.FileOutputStream) ProcessShellFactory(org.apache.sshd.server.shell.ProcessShellFactory) CommandFactory(org.apache.sshd.server.CommandFactory) File(java.io.File) FileInputStream(java.io.FileInputStream) Before(org.junit.Before)

Example 13 with SimpleGeneratorHostKeyProvider

use of org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider in project testcases by coheigea.

the class SCPTest method setup.

@Before
public void setup() throws Exception {
    int port = AvailablePortFinder.getNextAvailable(10000);
    // Write port number to configuration file in target
    String basedir = System.getProperty("basedir");
    if (basedir == null) {
        basedir = new File(".").getCanonicalPath();
    }
    // Read in camel configuration file and substitute in the correct port
    File f = new File(basedir + "/src/test/resources/camel-scp.xml");
    FileInputStream inputStream = new FileInputStream(f);
    String content = IOUtils.toString(inputStream, "UTF-8");
    inputStream.close();
    content = content.replaceAll("portno", "" + port);
    File f2 = new File(basedir + "/target/test-classes/camel-scp.xml");
    FileOutputStream outputStream = new FileOutputStream(f2);
    IOUtils.write(content, outputStream, "UTF-8");
    outputStream.close();
    sshServer = SshServer.setUpDefaultServer();
    sshServer.setPort(port);
    // Generate a key
    sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Paths.get("target/generatedkey.pem")));
    sshServer.setCommandFactory(new ScpCommandFactory());
    sshServer.setPasswordAuthenticator(new CamelPasswordAuthenticator());
    sshServer.start();
    setupKnownHosts(port);
    // Create "storage" directory (delete it first if it exists)
    File storageDirectory = new File(basedir + "/target/storage");
    if (storageDirectory.exists()) {
        storageDirectory.delete();
    }
    storageDirectory.mkdir();
}
Also used : SimpleGeneratorHostKeyProvider(org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider) ScpCommandFactory(org.apache.sshd.server.scp.ScpCommandFactory) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) Before(org.junit.Before)

Example 14 with SimpleGeneratorHostKeyProvider

use of org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider in project gerrit by GerritCodeReview.

the class SshdModule method getHostKeys.

private static synchronized KeyPairProvider getHostKeys() {
    if (keys == null) {
        keys = new SimpleGeneratorHostKeyProvider();
        keys.setAlgorithm("RSA");
        keys.loadKeys(null);
    }
    return keys;
}
Also used : SimpleGeneratorHostKeyProvider(org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider)

Example 15 with SimpleGeneratorHostKeyProvider

use of org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider in project spring-integration-samples by spring-projects.

the class EmbeddedSftpServer method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    final PublicKey allowedKey = decodePublicKey();
    this.server.setPublickeyAuthenticator((username, key, session) -> key.equals(allowedKey));
    this.server.setPort(this.port);
    this.server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser")));
    this.server.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory()));
    final String pathname = System.getProperty("java.io.tmpdir") + File.separator + "sftptest" + File.separator;
    new File(pathname).mkdirs();
    server.setFileSystemFactory(new VirtualFileSystemFactory(Paths.get(pathname)));
}
Also used : SimpleGeneratorHostKeyProvider(org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider) SftpSubsystemFactory(org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory) PublicKey(java.security.PublicKey) VirtualFileSystemFactory(org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory) File(java.io.File)

Aggregations

SimpleGeneratorHostKeyProvider (org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider)21 File (java.io.File)13 Command (org.apache.sshd.server.Command)9 SftpSubsystemFactory (org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory)7 VirtualFileSystemFactory (org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory)5 ArrayList (java.util.ArrayList)4 NamedFactory (org.apache.sshd.common.NamedFactory)4 FileInputStream (java.io.FileInputStream)3 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 SshServer (org.apache.sshd.server.SshServer)3 ScpCommandFactory (org.apache.sshd.server.scp.ScpCommandFactory)3 Before (org.junit.Before)3 LsEntry (com.jcraft.jsch.ChannelSftp.LsEntry)2 PublicKey (java.security.PublicKey)2 CommandFactory (org.apache.sshd.server.CommandFactory)2 PasswordAuthenticator (org.apache.sshd.server.PasswordAuthenticator)2 UserAuthPassword (org.apache.sshd.server.auth.UserAuthPassword)2 ScpCommandFactory (org.apache.sshd.server.command.ScpCommandFactory)2 ServerSession (org.apache.sshd.server.session.ServerSession)2