use of org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider 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();
}
use of org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider in project felix by apache.
the class Ssh method start.
private void start() throws IOException {
server = ServerBuilder.builder().build();
server.setPort(port);
server.setHost(ip);
server.setShellFactory(new ShellFactoryImpl(processor));
server.setCommandFactory(new ScpCommandFactory.Builder().withDelegate(new ShellCommandFactory(processor)).build());
server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystemFactory.Builder().build()));
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
server.start();
}
use of org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider in project pentaho-kettle by pentaho.
the class SftpServer method createSshServer.
private SshServer createSshServer(int port, String homeDir, String hostKeyPath) {
SshServer server = SshServer.setUpDefaultServer();
server.setHost("localhost");
server.setPort(port);
server.setFileSystemFactory(new VirtualFileSystemFactory(homeDir));
server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystem.Factory()));
server.setCommandFactory(new ScpCommandFactory());
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(hostKeyPath));
server.setPasswordAuthenticator(this);
return server;
}
use of org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider in project gerrit by GerritCodeReview.
the class InMemoryTestingDatabaseModule method getHostKeys.
private static synchronized KeyPairProvider getHostKeys() {
if (keys == null) {
keys = new SimpleGeneratorHostKeyProvider();
keys.setAlgorithm("RSA");
keys.loadKeys();
}
return keys;
}
use of org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider in project gerrit by GerritCodeReview.
the class ConvertKey method main.
public static void main(String[] args) throws GeneralSecurityException, JSchException, IOException {
SimpleGeneratorHostKeyProvider p;
if (args.length != 1) {
System.err.println("Error: requires path to the SSH host key");
return;
} else {
File file = new File(args[0]);
if (!file.exists() || !file.isFile() || !file.canRead()) {
System.err.println("Error: ssh key should exist and be readable");
return;
}
}
p = new SimpleGeneratorHostKeyProvider();
// Gerrit's SSH "simple" keys are always RSA.
p.setPath(args[0]);
p.setAlgorithm("RSA");
// forces the key to generate.
Iterable<KeyPair> keys = p.loadKeys();
for (KeyPair k : keys) {
System.out.println("Public Key (" + k.getPublic().getAlgorithm() + "):");
// From Gerrit's SshDaemon class; use JSch to get the public
// key/type
final Buffer buf = new Buffer();
buf.putRawPublicKey(k.getPublic());
final byte[] keyBin = buf.getCompactData();
HostKey pub = new HostKey("localhost", keyBin);
System.out.println(pub.getType() + " " + pub.getKey());
System.out.println("Private Key:");
// Use Bouncy Castle to write the private key back in PEM format
// (PKCS#1)
// http://stackoverflow.com/questions/25129822/export-rsa-public-key-to-pem-string-using-java
StringWriter privout = new StringWriter();
JcaPEMWriter privWriter = new JcaPEMWriter(privout);
privWriter.writeObject(k.getPrivate());
privWriter.close();
System.out.println(privout);
}
}
Aggregations