Java Code Examples for org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider

The following examples show how to use org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: onos   Source File: NetconfSessionMinaImpl.java    License: Apache License 2.0 8 votes vote down vote up
private void startClient() throws IOException {
    log.info("Creating NETCONF session to {}",
            deviceInfo.getDeviceId());

    client = SshClient.setUpDefaultClient();
    if (idleTimeout != NetconfControllerImpl.netconfIdleTimeout) {
        client.getProperties().putIfAbsent(FactoryManager.IDLE_TIMEOUT,
                TimeUnit.SECONDS.toMillis(idleTimeout));
        client.getProperties().putIfAbsent(FactoryManager.NIO2_READ_TIMEOUT,
                TimeUnit.SECONDS.toMillis(idleTimeout + 15L));
    }
    client.start();
    client.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
    startSession();

    disconnected = false;
}
 
Example 2
Source Project: termd   Source File: WindowAdjustTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    sshServer = setupTestServer();

    final byte[] msg = Files.readAllBytes(
            Paths.get(getClass().getResource("/big-msg.txt").toURI()));
    sshServer.setShellFactory(new Factory<Command>() {
        @Override
        public Command create() {
            return new FloodingAsyncCommand(msg, BIG_MSG_SEND_COUNT, END_FILE);
        }
    });

    sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
    sshServer.start();
    port = sshServer.getPort();
}
 
Example 3
Source Project: termd   Source File: SshTtyTestBase.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void server(final Consumer<TtyConnection> onConnect) {
  if (sshd != null) {
    throw failure("Already a server");
  }
  try {
    sshd = createServer();
    sshd.setPort(5000);
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath()));
    sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
      @Override
      public boolean authenticate(String username, String password, ServerSession session) throws PasswordChangeRequiredException {
        return true;
      }
    });
    sshd.setShellFactory(new Factory<Command>() {
      @Override
      public Command create() {
        return createConnection(onConnect);
      }
    });
    sshd.start();
  } catch (Exception e) {
    throw failure(e);
  }
}
 
Example 4
Source Project: termd   Source File: AsyncAuthTestBase.java    License: Apache License 2.0 6 votes vote down vote up
public void startServer(Integer timeout) throws Exception {
  if (server != null) {
    throw failure("Server already started");
  }
  server = SshServer.setUpDefaultServer();
  if (timeout != null) {
    server.getProperties().put(FactoryManager.AUTH_TIMEOUT, timeout.toString());
  }
  server.setPort(5000);
  server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath()));
  server.setPasswordAuthenticator(new PasswordAuthenticator() {
    @Override
    public boolean authenticate(String username, String password, ServerSession session) throws PasswordChangeRequiredException {
      return authenticator.authenticate(username, password, session);
    }
  });
  server.setShellFactory(new EchoShellFactory());
  server.setServiceFactories(Arrays.asList(ServerConnectionServiceFactory.INSTANCE, AsyncUserAuthServiceFactory.INSTANCE));
  server.start();
}
 
Example 5
/**
 * Construct ssh server thanks to ssh shell properties
 *
 * @return ssh server
 */
@Bean
public SshServer sshServer() {
    SshServer server = SshServer.setUpDefaultServer();
    server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(properties.getHostKeyFile().toPath()));
    server.setHost(properties.getHost());
    server.setPasswordAuthenticator(passwordAuthenticator);
    server.setPublickeyAuthenticator(RejectAllPublickeyAuthenticator.INSTANCE);
    if (properties.getAuthorizedPublicKeysFile() != null) {
        if (properties.getAuthorizedPublicKeysFile().exists() && properties.getAuthorizedPublicKeysFile().canRead()) {
            server.setPublickeyAuthenticator(new SshShellPublicKeyAuthenticationProvider(properties.getAuthorizedPublicKeysFile()));
        } else {
            LOGGER.warn("Could not read authorized public keys file [{}], public key authentication is disabled.",
                    properties.getAuthorizedPublicKeysFile().getAbsolutePath());
        }
    }
    server.setPort(properties.getPort());
    server.setShellFactory(channelSession -> shellCommandFactory);
    server.setCommandFactory((channelSession, s) -> shellCommandFactory);
    return server;
}
 
Example 6
Source Project: java-examples   Source File: EmbeddedSftpServer.java    License: MIT License 6 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
    final PublicKey allowedKey = decodePublicKey();
    this.server.setPublickeyAuthenticator(new PublickeyAuthenticator() {

        @Override
        public boolean authenticate(String username, PublicKey key, ServerSession session) {
            return key.equals(allowedKey);
        }

    });
    this.server.setPort(this.port);
    this.server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Files.createTempFile("host_file", ".ser")));
    this.server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystemFactory()));
    server.setFileSystemFactory(new VirtualFileSystemFactory(Files.createTempDirectory("SFTP_TEMP")));
    server.setCommandFactory(new ScpCommandFactory());
}
 
Example 7
Source Project: java-examples   Source File: EmbeddedSftpServer.java    License: MIT License 6 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
    final PublicKey allowedKey = decodePublicKey();
    this.server.setPublickeyAuthenticator(new PublickeyAuthenticator() {

        @Override
        public boolean authenticate(String username, PublicKey key, ServerSession session) {
            return key.equals(allowedKey);
        }

    });
    this.server.setPort(this.port);
    this.server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Files.createTempFile("host_file", ".ser")));
    this.server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystemFactory()));
    server.setFileSystemFactory(new VirtualFileSystemFactory(Files.createTempDirectory("SFTP_TEMP")));
    server.setCommandFactory(new ScpCommandFactory());
}
 
Example 8
Source Project: fake-sftp-server-rule   Source File: FakeSftpServerRule.java    License: MIT License 6 votes vote down vote up
private SshServer startServer(
    FileSystem fileSystem
) throws IOException {
    SshServer server = SshServer.setUpDefaultServer();
    server.setPort(port);
    server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
    server.setPasswordAuthenticator(this::authenticate);
    server.setSubsystemFactories(singletonList(new SftpSubsystemFactory()));
    /* When a channel is closed SshServer calls close() on the file system.
     * In order to use the file system for multiple channels/sessions we
     * have to use a file system wrapper whose close() does nothing.
     */
    server.setFileSystemFactory(session -> new DoNotClose(fileSystem));
    server.start();
    this.server = server;
    return server;
}
 
Example 9
Source Project: product-ei   Source File: SftpServerRunner.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    sshd.setPort(port);
    sshd.setSubsystemFactories(
            Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory()));
    sshd.setCommandFactory(new ScpCommandFactory());
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
    sshd.setFileSystemFactory(new VirtualFileSystemFactory(Paths.get(path)));
    sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
        @Override
        public boolean authenticate(final String username, final String password, final ServerSession session) {
            return StringUtils.equals(username, ftpUser) && StringUtils.equals(password, ftpPassword);
        }
    });
    try {
        LOGGER.info("Starting SFTP server on port {}", port);
        sshd.start();
    } catch (IOException e) {
        LOGGER.error("Error starting SFTP server", e);
    }
}
 
Example 10
Source Project: aesh-readline   Source File: SshTtyTestBase.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void server(Consumer<Connection> onConnect) {
    if (sshd != null) {
        throw failure("Already a server");
    }
    try {
        sshd = createServer();
        sshd.setPort(5000);
        sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath()));
        sshd.setPasswordAuthenticator((username, password, session) -> true);
        sshd.setShellFactory(() -> createConnection(onConnect));
        sshd.start();
    } catch (Exception e) {
        throw failure(e);
    }
}
 
Example 11
Source Project: termd   Source File: WindowAdjustTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    sshServer = setupTestServer();

    final byte[] msg = Files.readAllBytes(
            Paths.get(getClass().getResource("/big-msg.txt").toURI()));
    sshServer.setShellFactory(new Factory<Command>() {
        @Override
        public Command create() {
            return new FloodingAsyncCommand(msg, BIG_MSG_SEND_COUNT, END_FILE);
        }
    });

    sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
    sshServer.start();
    port = sshServer.getPort();
}
 
Example 12
Source Project: termd   Source File: SshTtyTestBase.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void server(Consumer<TtyConnection> onConnect) {
  if (sshd != null) {
    throw failure("Already a server");
  }
  try {
    sshd = createServer();
    sshd.setPort(5000);
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath()));
    sshd.setPasswordAuthenticator((username, password, session) -> true);
    sshd.setShellFactory(() -> createConnection(onConnect));
    sshd.start();
  } catch (Exception e) {
    throw failure(e);
  }
}
 
Example 13
Source Project: ExpectIt   Source File: AntHarnessTest.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void startSshServer() throws IOException {
    sshServer = SshServer.setUpDefaultServer();
    ServerSocket serverSocket = new ServerSocket(0);
    sshPort = serverSocket.getLocalPort();
    serverSocket.close();
    sshServer.setPort(sshPort);
    sshServer.setPasswordAuthenticator(
            new PasswordAuthenticator() {
                @Override
                public boolean authenticate(
                        String username,
                        String password,
                        ServerSession session) {
                    return "ssh".equals(username) && "secret".equals(password);
                }
            });
    sshServer.setShellFactory(new SshEchoCommandFactory());
    sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
    sshServer.start();
}
 
Example 14
Source Project: tomee   Source File: SSHServer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void start() throws ServiceException {
    sshServer = SshServer.setUpDefaultServer();
    sshServer.setPort(port);
    sshServer.setHost(bind);

    final String basePath = SystemInstance.get().getBase().getDirectory().getAbsolutePath();
    if (SecurityUtils.isBouncyCastleRegistered()) {
        sshServer.setKeyPairProvider(new BouncyCastleGeneratorHostKeyProvider(new File(basePath, KEY_NAME + ".pem").toPath()));
    } else {
        sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File(basePath, KEY_NAME + ".ser").toPath()));
    }

    final OpenEJBShellFactory sf = new OpenEJBShellFactory(bind, port);
    sshServer.setShellFactory(sf);

    final JaasPasswordAuthenticator authenticator = new OpenEJBJaasPasswordAuthenticator();
    authenticator.setDomain(domain);
    sshServer.setPasswordAuthenticator(authenticator);

    try {
        sshServer.start();
    } catch (IOException e) {
        // no-op
    }
}
 
Example 15
Source Project: pentaho-kettle   Source File: SftpServer.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 16
Source Project: micro-integrator   Source File: SftpServerRunner.java    License: Apache License 2.0 5 votes vote down vote up
SftpServer(int port, String path, String ftpUser, String ftpPassword) {

            sshd.setPort(port);
            sshd.setSubsystemFactories(
                    Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory()));
            sshd.setCommandFactory(new ScpCommandFactory());
            sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
            sshd.setFileSystemFactory(new VirtualFileSystemFactory(Paths.get(path)));
            sshd.setPasswordAuthenticator((username, password, session) -> StringUtils.equals(username, ftpUser)
                                                                           && StringUtils.equals(password,
                                                                                                 ftpPassword));
        }
 
Example 17
Source Project: termd   Source File: NettySshTtyBootstrap.java    License: Apache License 2.0 5 votes vote down vote up
public NettySshTtyBootstrap() {
  this.host = "localhost";
  this.port = 5000;
  this.charset = UTF_8;
  this.parentGroup = new NioEventLoopGroup(1);
  this.childGroup = new NioEventLoopGroup();
  this.keyPairProvider = new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath());
  this.passwordAuthenticator = new PasswordAuthenticator() {
    @Override
    public boolean authenticate(String username, String password, ServerSession session) throws PasswordChangeRequiredException {
      return true;
    }
  };
}
 
Example 18
Source Project: quarkus   Source File: JSchTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setupSSHDServer() throws Exception {
    sshd = SshServer.setUpDefaultServer();
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Files.createTempFile("host", "key")));
    sshd.setHostBasedAuthenticator(AcceptAllHostBasedAuthenticator.INSTANCE);
    sshd.setPasswordAuthenticator(AcceptAllPasswordAuthenticator.INSTANCE);
    sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE);
    sshd.setCommandFactory(UnknownCommandFactory.INSTANCE);
    sshd.setHost("localhost");
    sshd.start();
}
 
Example 19
@Before
public void startSerer() throws Exception {
    server = SshServer.setUpDefaultServer();
    server.setPort(PORT_NUMBER);
    server.setPasswordAuthenticator((username, password, session) -> true);
    server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
    server.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory()));
    final java.nio.file.Path tempDir = Files.createTempDirectory(String.format("%s-", this.getClass().getName()));
    final java.nio.file.Path vault = tempDir.resolve("vault");
    Files.createDirectory(vault);
    passphrase = new AlphanumericRandomStringService().random();
    cryptoFileSystem = CryptoFileSystemProvider.newFileSystem(vault, CryptoFileSystemProperties.cryptoFileSystemProperties().withPassphrase(passphrase).build());
    server.setFileSystemFactory(new VirtualFileSystemFactory(cryptoFileSystem.getPathToVault().getParent().toAbsolutePath()));
    server.start();
}
 
Example 20
private void configureAuthenticationPolicies(SshServer server, Shell props) {
    server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Paths.get(props.getHostKeyFile())));
    server.setPublickeyAuthenticator(Objects.isNull(props.getPublicKeyFile())
            ? RejectAllPublickeyAuthenticator.INSTANCE
            : new SshdAuthorizedKeysAuthenticator(Paths.get(props.getPublicKeyFile())));
    server.setPasswordAuthenticator(passwordAuthenticator(props));
}
 
Example 21
Source Project: aesh-readline   Source File: NettySshTtyBootstrap.java    License: Apache License 2.0 5 votes vote down vote up
public NettySshTtyBootstrap() {
    this.host = "localhost";
    this.port = 5000;
    this.charset = StandardCharsets.UTF_8;
    this.parentGroup = new NioEventLoopGroup(1);
    this.childGroup = new NioEventLoopGroup();
    this.keyPairProvider = new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath());
    this.passwordAuthenticator = (username, password, session) -> true;
}
 
Example 22
Source Project: aesh-readline   Source File: AsyncAuthTestBase.java    License: Apache License 2.0 5 votes vote down vote up
public void startServer(Integer timeout) throws Exception {
  if (server != null) {
    throw failure("Server already started");
  }
  server = SshServer.setUpDefaultServer();
  if (timeout != null) {
    server.setProperties(Collections.singletonMap(FactoryManager.AUTH_TIMEOUT, timeout.toString()));
  }
  server.setPort(5000);
  server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath()));
  server.setPasswordAuthenticator((username, password, sess) -> authenticator.authenticate(username, password, sess));
  server.setShellFactory(new EchoShellFactory());
  server.setServiceFactories(Arrays.asList(ServerConnectionServiceFactory.INSTANCE, AsyncUserAuthServiceFactory.INSTANCE));
  server.start();
}
 
Example 23
Source Project: termd   Source File: NettySshTtyBootstrap.java    License: Apache License 2.0 5 votes vote down vote up
public NettySshTtyBootstrap() {
  this.host = "localhost";
  this.port = 5000;
  this.charset = StandardCharsets.UTF_8;
  this.parentGroup = new NioEventLoopGroup(1);
  this.childGroup = new NioEventLoopGroup();
  this.keyPairProvider = new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath());
  this.passwordAuthenticator = (username, password, session) -> true;
}
 
Example 24
Source Project: termd   Source File: AsyncAuthTestBase.java    License: Apache License 2.0 5 votes vote down vote up
public void startServer(Integer timeout) throws Exception {
  if (server != null) {
    throw failure("Server already started");
  }
  server = SshServer.setUpDefaultServer();
  if (timeout != null) {
    server.getProperties().put(FactoryManager.AUTH_TIMEOUT, timeout.toString());
  }
  server.setPort(5000);
  server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath()));
  server.setPasswordAuthenticator((username, password, sess) -> authenticator.authenticate(username, password, sess));
  server.setShellFactory(new EchoShellFactory());
  server.setServiceFactories(Arrays.asList(ServerConnectionServiceFactory.INSTANCE, AsyncUserAuthServiceFactory.INSTANCE));
  server.start();
}
 
Example 25
Source Project: gameserver   Source File: AdminServer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void startServer(String bindAddr, int port) {
	try {
		sshd = SshServer.setUpDefaultServer();
		sshd.setHost(bindAddr);
		sshd.setPort(port);
		
		SimpleGeneratorHostKeyProvider provider = new SimpleGeneratorHostKeyProvider("hostkey.ser", "RSA", 4096);
		sshd.setKeyPairProvider(provider);
		
		EnumSet<ProcessShellFactory.TtyOptions> options = EnumSet.allOf(ProcessShellFactory.TtyOptions.class);
		options.remove(ProcessShellFactory.TtyOptions.Echo);
		sshd.setShellFactory(new ProcessShellFactory(new String[] { "/bin/bash", "-i" }, options));
		
		sshd.setCommandFactory(commandFactory);
		
    sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
      public boolean authenticate(String username, String password, ServerSession session) {
          return username != null && password.equals("VpWk5ujKA1c");
      }
	  });
    
		sshd.start();
		
		logger.info("AdminServer bind at " + bindAddr + ":" + port);
		
	} catch (Exception e) {
		logger.warn("Failed to start AdminServer", e);
	}
}
 
Example 26
Source Project: gerrit-events   Source File: SshdServerMock.java    License: MIT License 5 votes vote down vote up
/**
 * Starts a ssh server on the provided port.
 *
 * @param port the port to listen to.
 * @param server the server mock to start
 *
 * @return the server.
 * @throws IOException if so.
 */
public static SshServer startServer(int port, SshdServerMock server) throws IOException {
    SshServer sshd = SshServer.setUpDefaultServer();
    sshd.setPort(port);
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));
    sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {
        @Override
        public boolean authenticate(String s, PublicKey publicKey, ServerSession serverSession) {
            return true;
        }
    });
    sshd.setCommandFactory(server);
    sshd.start();
    return sshd;
}
 
Example 27
Source Project: nifi   Source File: SSHTestServer.java    License: Apache License 2.0 5 votes vote down vote up
public void startServer() throws IOException {
    sshd = SshServer.setUpDefaultServer();
    sshd.setHost("localhost");

    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());

    //Accept all keys for authentication
    sshd.setPublickeyAuthenticator((s, publicKey, serverSession) -> true);

    //Allow username/password authentication using pre-defined credentials
    sshd.setPasswordAuthenticator((username, password, serverSession) ->  this.username.equals(username) && this.password.equals(password));

    //Setup Virtual File System (VFS)
    //Ensure VFS folder exists
    Path dir = Paths.get(getVirtualFileSystemPath());
    Files.createDirectories(dir);
    sshd.setFileSystemFactory(new VirtualFileSystemFactory(dir.toAbsolutePath()));

    //Add SFTP support
    List<NamedFactory<Command>> sftpCommandFactory = new ArrayList<>();
    sftpCommandFactory.add(new SftpSubsystemFactory());
    sshd.setSubsystemFactories(sftpCommandFactory);

    sshd.start();
}
 
Example 28
Source Project: wildfly-camel   Source File: EmbeddedSSHServer.java    License: Apache License 2.0 5 votes vote down vote up
public EmbeddedSSHServer(Path homeDir, int port) {
    this.sshServer = SshServer.setUpDefaultServer();
    this.sshServer.setPort(port);
    this.sshServer.setCommandFactory(new EchoCommandFactory());
    this.sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
    this.sshServer.setPasswordAuthenticator((username, password, serverSession) -> username.equals("admin") && password.equals("admin"));
    this.sshServer.setPublickeyAuthenticator((s, publicKey, serverSession) -> true);
    this.homeDir = homeDir;

    if (EnvironmentUtils.isWindows()) {
        sshServer.setShellFactory(new ProcessShellFactory(new String[] { "cmd.exe " }));
    } else {
        sshServer.setShellFactory(new ProcessShellFactory(new String[] { "/bin/sh", "-i", "-s" }));
    }
}
 
Example 29
Source Project: Bukkit-SSHD   Source File: SshdPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onEnable() {
    instance = this;

    sshd = SshServer.setUpDefaultServer();
    sshd.setPort(getConfig().getInt("port", 22));
    String host = getConfig().getString("listenAddress", "all");
    sshd.setHost(host.equals("all") ? null : host);

    File hostKey = new File(getDataFolder(), "hostkey");
    File authorizedKeys = new File(getDataFolder(), "authorized_keys");

    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(hostKey));
    sshd.setShellFactory(new ConsoleShellFactory());
    sshd.setPasswordAuthenticator(new ConfigPasswordAuthenticator());
    sshd.setPublickeyAuthenticator(new PublicKeyAuthenticator(authorizedKeys));

    if (getConfig().getBoolean("enableSFTP")) {
        sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory()));
        sshd.setFileSystemFactory(new VirtualFileSystemFactory(
                FileSystems.getDefault().getPath(
                        getDataFolder().getAbsolutePath()
                ).getParent().getParent()
        ));
    }

    sshd.setCommandFactory(new ConsoleCommandFactory());
    try {
        sshd.start();
    } catch (IOException e) {
        getLogger().log(Level.SEVERE, "Failed to start SSH server! ", e);
    }
}
 
Example 30
Source Project: micro-integrator   Source File: ESBJAVA3470.java    License: Apache License 2.0 4 votes vote down vote up
public static KeyPairProvider createTestHostKeyProvider(Path path) {
    SimpleGeneratorHostKeyProvider keyProvider = new SimpleGeneratorHostKeyProvider();
    keyProvider.setPath(ValidateUtils.checkNotNull(path, "No path"));
    keyProvider.setAlgorithm(DEFAULT_TEST_HOST_KEY_PROVIDER_ALGORITHM);
    return keyProvider;
}