當前位置: 首頁>>代碼示例>>Java>>正文


Java SimpleGeneratorHostKeyProvider類代碼示例

本文整理匯總了Java中org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider的典型用法代碼示例。如果您正苦於以下問題:Java SimpleGeneratorHostKeyProvider類的具體用法?Java SimpleGeneratorHostKeyProvider怎麽用?Java SimpleGeneratorHostKeyProvider使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SimpleGeneratorHostKeyProvider類屬於org.apache.sshd.server.keyprovider包,在下文中一共展示了SimpleGeneratorHostKeyProvider類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: startServer

import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; //導入依賴的package包/類
public void startServer() throws IOException {
    SshServer sshd = SshServer.setUpDefaultServer();
    port = getPort();
    sshd.setPort(port);
    sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE);
    SimpleGeneratorHostKeyProvider provider = new SimpleGeneratorHostKeyProvider();
    sshd.setKeyPairProvider(provider);
    SftpSubsystemFactory.Builder builder = new SftpSubsystemFactory.Builder();

    SftpSubsystemFactory sftpFactory = builder.build();
    sshd.setSubsystemFactories(new ArrayList<NamedFactory<Command>>() {
        {
            add(sftpFactory);
        }
    });
    sshd.setHost(LOCALHOST);
    String msg = String.format("Local SSH Server started on [%s] and listening on port [%d]", sshd.getHost(), sshd
        .getPort());
    LOGGER.info(msg);
    ScpCommandFactory factory = new ScpCommandFactory();
    factory.setDelegateCommandFactory(new FakeCommandFactory());
    sshd.setCommandFactory(factory);
    Runtime.getRuntime().addShutdownHook(new Thread(new Close(sshd)));
    sshd.start();
}
 
開發者ID:RationaleEmotions,項目名稱:SimpleSSH,代碼行數:26,代碼來源:LocalServer.java

示例2: startClient

import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; //導入依賴的package包/類
private void startClient() throws IOException {
    client = SshClient.setUpDefaultClient();
    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();
}
 
開發者ID:opennetworkinglab,項目名稱:onos,代碼行數:11,代碼來源:NetconfSessionMinaImpl.java

示例3: sshServer

import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; //導入依賴的package包/類
@Bean
SshServer sshServer() {
    SshdShellProperties.Shell props = properties.getShell();
    if (Objects.isNull(props.getPassword())) {
        props.setPassword(UUID.randomUUID().toString());
        log.info("********** User password not set. Use following password to login: {} **********",
                props.getPassword());
    }
    SshServer server = SshServer.setUpDefaultServer();
    server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File(props.getHostKeyFile())));
    server.setPublickeyAuthenticator(Objects.isNull(props.getPublicKeyFile())
            ? RejectAllPublickeyAuthenticator.INSTANCE
            : new SshdAuthorizedKeysAuthenticator(new File(props.getPublicKeyFile())));
    server.setHost(props.getHost());
    server.setPasswordAuthenticator(passwordAuthenticator());
    server.setPort(props.getPort());
    server.setShellFactory(() -> sshSessionInstance());
    server.setCommandFactory(command -> sshSessionInstance());
    return server;
}
 
開發者ID:anand1st,項目名稱:sshd-shell-spring-boot,代碼行數:21,代碼來源:SshdServerConfiguration.java

示例4: startServer

import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; //導入依賴的package包/類
private SshServer startServer(
    FileSystem fileSystem
) throws IOException {
    SshServer server = SshServer.setUpDefaultServer();
    server.setPort(port);
    server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
    server.setPasswordAuthenticator(new StaticPasswordAuthenticator(true));
    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;
}
 
開發者ID:stefanbirkner,項目名稱:fake-sftp-server-rule,代碼行數:18,代碼來源:FakeSftpServerRule.java

示例5: main

import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; //導入依賴的package包/類
public static synchronized void main(String[] args) throws Exception {

         AbstractGeneratorHostKeyProvider hostKeyProvider =
            new SimpleGeneratorHostKeyProvider(     new File("hostkey.ser").toPath());
         hostKeyProvider.setAlgorithm("RSA");
        NettySshTtyBootstrap bootstrap = new NettySshTtyBootstrap().
                setPort(5000).
                setHost("localhost")
                .setKeyPairProvider(hostKeyProvider)
                //.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("/tmp/mysample").toPath()))

                ;
        bootstrap.start(new ShellExample()).get(10, TimeUnit.SECONDS);
        System.out.println("SSH started on localhost:5000");
        SSHShellExample.class.wait();
    }
 
開發者ID:aeshell,項目名稱:aesh-readline,代碼行數:17,代碼來源:SSHShellExample.java

示例6: server

import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; //導入依賴的package包/類
@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);
    }
}
 
開發者ID:aeshell,項目名稱:aesh-readline,代碼行數:17,代碼來源:SshTtyTestBase.java

示例7: init

import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; //導入依賴的package包/類
public void init(Context context, Device device) {

        sshd.setKeyExchangeFactories(Arrays.asList(
                new DHG14.Factory(),
                new DHG1.Factory()));

        sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(context.getFilesDir() + "/sftpd.ser"));

        sshd.setFileSystemFactory(new AndroidFileSystemFactory(context));
        sshd.setCommandFactory(new ScpCommandFactory());
        sshd.setSubsystemFactories(Collections.singletonList((NamedFactory<Command>)new SftpSubsystem.Factory()));

        if (device.publicKey != null) {
            keyAuth.deviceKey = device.publicKey;
            sshd.setPublickeyAuthenticator(keyAuth);
        }
        sshd.setPasswordAuthenticator(passwordAuth);
    }
 
開發者ID:KDE,項目名稱:kdeconnect-android,代碼行數:19,代碼來源:SimpleSftpServer.java

示例8: setupSftp

import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; //導入依賴的package包/類
protected void setupSftp(int port, final String username, final String password, File fileSystemFolder)
    throws IOException {
    sshd = SshServer.setUpDefaultServer();
    sshd.setPort(port);
    SftpSubsystem.Factory factory = new SftpSubsystem.Factory();

    @SuppressWarnings("unchecked")
    List<NamedFactory<Command>> factoryList = Arrays.<NamedFactory<Command>> asList(new NamedFactory[] {factory});
    this.sshd.setSubsystemFactories(factoryList);

    sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
        public boolean authenticate(String tryUsername, String tryPassword, ServerSession session) {
            return (username.equals(tryUsername)) && (password.equals(tryPassword));
        }

    });
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
    sshd.start();

    VirtualFileSystemFactory vfSysFactory = new VirtualFileSystemFactory();
    vfSysFactory.setDefaultHomeDir(fileSystemFolder.getCanonicalPath());
    sshd.setFileSystemFactory(vfSysFactory);
    LOGGER.info("Embedded SFTP started on port {}", Integer.valueOf(sshd.getPort()));
}
 
開發者ID:northlander,項目名稱:activemft,代碼行數:25,代碼來源:EmbeddedSftp.java

示例9: setUp

import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; //導入依賴的package包/類
@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();
}
 
開發者ID:termd,項目名稱:termd,代碼行數:18,代碼來源:WindowAdjustTest.java

示例10: server

import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; //導入依賴的package包/類
@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);
  }
}
 
開發者ID:termd,項目名稱:termd,代碼行數:17,代碼來源:SshTtyTestBase.java

示例11: startSshServer

import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; //導入依賴的package包/類
@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();
}
 
開發者ID:Alexey1Gavrilov,項目名稱:ExpectIt,代碼行數:22,代碼來源:AntHarnessTest.java

示例12: setupSftpServer

import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; //導入依賴的package包/類
public void setupSftpServer() throws IOException {
    sshd = SshServer.setUpDefaultServer();
    sshd.setHost("127.0.0.1");
    sshd.setPort(4922);
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("target/hostkey.ser"));
    sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
        @Override
        public boolean authenticate(String username, String password, ServerSession session) {
            return "ftpuser".equals(username) && "topsecret".equals(password);
        }
    });

    List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
    userAuthFactories.add(new UserAuthPassword.Factory());
    sshd.setUserAuthFactories(userAuthFactories);

    sshd.setCommandFactory(new ScpCommandFactory());

    List<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>();
    namedFactoryList.add(new SftpSubsystem.Factory());
    sshd.setSubsystemFactories(namedFactoryList);

    // prepare directory for test files
    VirtualFileSystemFactory fileSystemFactory = new VirtualFileSystemFactory(ROOT.getAbsolutePath());
    sshd.setFileSystemFactory(fileSystemFactory);

    sshd.start();
}
 
開發者ID:AludraTest,項目名稱:aludratest,代碼行數:29,代碼來源:SftpFileServiceTest.java

示例13: start

import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; //導入依賴的package包/類
@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 PEMGeneratorHostKeyProvider(new File(basePath, KEY_NAME + ".pem").getPath()));
    } else {
        sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File(basePath, KEY_NAME + ".ser").getPath()));
    }

    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
    }
}
 
開發者ID:apache,項目名稱:tomee,代碼行數:27,代碼來源:SSHServer.java

示例14: initializeServer

import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; //導入依賴的package包/類
private void initializeServer(String host, int listeningPort) {
	log.info("Configuring server...");
	sshd = SshServer.setUpDefaultServer();
	sshd.setHost(host);
	sshd.setPort(listeningPort);

	log.info("Host: '" + host + "', listenig port: " + listeningPort);

	sshd.setPasswordAuthenticator(new AlwaysTruePasswordAuthenticator());
	sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(""));

	List<NamedFactory<Command>> subsystemFactories = new ArrayList<NamedFactory<Command>>();
	subsystemFactories.add(NetconfSubsystem.Factory.createFactory(this, this));
	sshd.setSubsystemFactories(subsystemFactories);

	log.info("Server configured.");
}
 
開發者ID:dana-i2cat,項目名稱:netconf-server,代碼行數:18,代碼來源:Server.java

示例15: onEnable

import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; //導入依賴的package包/類
@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));
    sshd.setCommandFactory(new ConsoleCommandFactory());
    try {
        sshd.start();
    } catch (IOException e) {
        getLogger().severe("Failed to start SSH server! " + e.getMessage());
    }
}
 
開發者ID:rmichela,項目名稱:Bukkit-SSHD,代碼行數:24,代碼來源:SshdPlugin.java


注:本文中的org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。