本文整理匯總了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();
}
示例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();
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
}
示例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);
}
示例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()));
}
示例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();
}
示例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);
}
}
示例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();
}
示例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();
}
示例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
}
}
示例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.");
}
示例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());
}
}