@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))); }
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(); }
private SshServer defaultSshServer() { SshServer sshServer = SshServer.setUpDefaultServer(); sshServer.setPort(randomPort()); ClassLoadableResourceKeyPairProvider fileKeyPairProvider = new ClassLoadableResourceKeyPairProvider(hostkey); sshServer.setKeyPairProvider(fileKeyPairProvider); sshServer.setPasswordAuthenticator(new PasswordAuthenticator() { @Override public boolean authenticate(String username, String password, ServerSession session) { return username.equals(password); } }); sshServer.setGSSAuthenticator(new BogusGSSAuthenticator()); sshServer.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory())); ScpCommandFactory commandFactory = new ScpCommandFactory(); commandFactory.setDelegateCommandFactory(new CommandFactory() { @Override public Command createCommand(String command) { return new ProcessShellFactory(command.split(" ")).create(); } }); sshServer.setCommandFactory(commandFactory); sshServer.setShellFactory(new ProcessShellFactory("ls")); return sshServer; }
@BeforeClass public static void createServer() throws Exception { server = SshServer.setUpDefaultServer(); server.setPasswordAuthenticator((username, password, session) -> true); server.setPort(0); server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath())); server.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory())); server.setFileSystemFactory(new VirtualFileSystemFactory(remoteTemporaryFolder.getRoot().toPath())); server.start(); port = server.getPort(); }
private DefaultSftpSessionFactory createServerAndClient(SshServer server) throws IOException { server.setPublickeyAuthenticator((username, key, session) -> true); server.setPort(0); server.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory())); server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath())); server.start(); DefaultSftpSessionFactory f = new DefaultSftpSessionFactory(); f.setHost("localhost"); f.setPort(server.getPort()); f.setUser("user"); Resource privateKey = new ClassPathResource("id_rsa"); f.setPrivateKey(privateKey); return f; }
@Test public void testUcPw() throws Exception { SshServer server = SshServer.setUpDefaultServer(); try { server.setPasswordAuthenticator((arg0, arg1, arg2) -> true); server.setPort(0); server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath())); 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))); server.start(); DefaultSftpSessionFactory f = new DefaultSftpSessionFactory(); f.setHost("localhost"); f.setPort(server.getPort()); f.setUser("user"); f.setPassword("pass"); f.setAllowUnknownKeys(true); Session<LsEntry> session = f.getSession(); doTest(server, session); } finally { server.stop(true); } }
private void testKeyExchange(String pubKey, String privKey, String passphrase) throws Exception { SshServer server = SshServer.setUpDefaultServer(); final PublicKey allowedKey = decodePublicKey(pubKey); try { server.setPublickeyAuthenticator((username, key, session) -> key.equals(allowedKey)); server.setPort(0); server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath())); 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))); server.start(); DefaultSftpSessionFactory f = new DefaultSftpSessionFactory(); f.setHost("localhost"); f.setPort(server.getPort()); f.setUser("user"); f.setAllowUnknownKeys(true); InputStream stream = new ClassPathResource(privKey).getInputStream(); f.setPrivateKey(new ByteArrayResource(FileCopyUtils.copyToByteArray(stream))); f.setPrivateKeyPassphrase(passphrase); Session<LsEntry> session = f.getSession(); doTest(server, session); } finally { server.stop(true); } }
protected void setupFactories() { final CustomSftpSubsystemFactory sftpSubsys = new CustomSftpSubsystemFactory(); sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(sftpSubsys)); sshd.setMacFactories(Arrays.<NamedFactory<Mac>>asList( // BuiltinMacs.hmacsha512, // BuiltinMacs.hmacsha256, // BuiltinMacs.hmacsha1)); sshd.setChannelFactories(Arrays.<NamedFactory<Channel>>asList(ChannelSessionFactory.INSTANCE)); }
public void setupSftp() { this.sshServer.setCommandFactory(new ScpCommandFactory()); this.sshServer.setSubsystemFactories(Arrays.asList(new SftpSubsystemFactory())); }
public void setupSftp() { this.sshServer.setCommandFactory(new ScpCommandFactory()); this.sshServer.setSubsystemFactories(Arrays.asList(new SftpSubsystemFactory())); }
private void initSftp() { sshServer.setCommandFactory(new ScpCommandFactory()); sshServer.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory())); }
private void configureSshdServer(SftpSubsystemFactory factory) { sshdServer.setPort(port); sshdServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser"))); sshdServer.setSubsystemFactories(asList(factory)); sshdServer.setCommandFactory(new ScpCommandFactory()); }
private void configureServerForSshAndFileTransfer(SshServer server) { server.setCommandFactory(sshAndScpCommandFactory()); server.setFileSystemFactory(new SshdNativeFileSystemFactory(properties.getFilesystem().getBase().getDir())); server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList( new SftpSubsystemFactory.Builder().build())); }
@Override protected void before() throws Throwable { sshd = SshServer.setUpDefaultServer(); sshd.setPort(findRandomOpenPortOnAllLocalInterfaces()); sshd.setKeyPairProvider( new ClassLoadableResourceKeyPairProvider(getClass().getClassLoader(), "server_key")); sshd.setCommandFactory(new ScpCommandFactory()); sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory())); sshd.setUserAuthFactories(Collections.singletonList(new UserAuthPublicKeyFactory())); sshd.setHost("localhost"); sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE); sshd.setHostBasedAuthenticator(new StaticHostBasedAuthenticator(true)); VirtualFileSystemFactory fileSystemFactory = new VirtualFileSystemFactory(); fileSystemFactory.setDefaultHomeDir(currentFolder.get().toPath()); sshd.setFileSystemFactory(fileSystemFactory); sshd.start(); }
namedFactoryList.add(plugin.getFactory()); server.setSubsystemFactories(namedFactoryList);
private void start() throws IOException { server = serverBuilder.get(); server.setPort(port); server.setHost(ip); server.setShellFactory(new ShellFactoryImpl(shell)); server.setCommandFactory(new ScpCommandFactory.Builder() .withDelegate(command -> new ShellCommand(execute, command)).build()); server.setSubsystemFactories(Collections.singletonList( new SftpSubsystemFactory.Builder().build() )); server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()); server.start(); }
private void start() throws IOException { server = serverBuilder.get(); server.setPort(port); server.setHost(ip); server.setShellFactory(new ShellFactoryImpl(shell)); server.setCommandFactory(new ScpCommandFactory.Builder() .withDelegate(command -> new ShellCommand(execute, command)).build()); server.setSubsystemFactories(Collections.singletonList( new SftpSubsystemFactory.Builder().build() )); server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()); server.start(); }
@Override public void afterPropertiesSet() throws Exception { this.sftpFolder.create(); this.localFolder.create(); this.server.setPasswordAuthenticator((username, password, session) -> true); this.server.setPort(this.port); this.server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser"))); this.server.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory())); this.server.setFileSystemFactory(new VirtualFileSystemFactory(sftpRootFolder.toPath())); this.server.start(); }
public static SshServer create() { SshServer sshd = SshServer.setUpDefaultServer(); sshd.setPort(SpashConfig.getInstance().spashListenPort()); AbstractGeneratorHostKeyProvider keyProvider = new SimpleGeneratorHostKeyProvider(new File(SpashConfig.getInstance().spashKeyFileName())); keyProvider.setAlgorithm(SpashConfig.getInstance().spashKeyAlgorithm()); keyProvider.setKeySize(SpashConfig.getInstance().spashKeyLength()); sshd.setKeyPairProvider(keyProvider); List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>(); userAuthFactories.add(new UserAuthPasswordFactory()); sshd.setUserAuthFactories(userAuthFactories); sshd.setPasswordAuthenticator(new PasswordAuthenticator() { @Override public boolean authenticate(String username, String password, ServerSession serverSession) throws PasswordChangeRequiredException { return username!=null && username.length()>0 && username.equals(password); } }); sshd.setShellFactory(new SpashShellFactory()); List<NamedFactory<Command>> namedFactoryList = new ArrayList<>(); namedFactoryList.add(new SftpSubsystemFactory()); sshd.setSubsystemFactories(namedFactoryList); sshd.setCommandFactory(new ScpCommandFactory()); sshd.setFileSystemFactory(new FileSystemFactory() { @Override public FileSystem createFileSystem(Session session) throws IOException { return SpashFileSystem.get().getFileSystem(); } }); return sshd; }
if (sftpEnabled) { server.setCommandFactory(new ScpCommandFactory.Builder().withDelegate(cmd -> new ShellCommand(sessionFactory, cmd)).build()); server.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory())); server.setFileSystemFactory(new VirtualFileSystemFactory(Paths.get(System.getProperty("karaf.base")))); } else {