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();
}
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();
}
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();
}
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;
}
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)));
}
Aggregations