本文整理汇总了Java中net.schmizz.sshj.transport.verification.PromiscuousVerifier类的典型用法代码示例。如果您正苦于以下问题:Java PromiscuousVerifier类的具体用法?Java PromiscuousVerifier怎么用?Java PromiscuousVerifier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PromiscuousVerifier类属于net.schmizz.sshj.transport.verification包,在下文中一共展示了PromiscuousVerifier类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SshConnection
import net.schmizz.sshj.transport.verification.PromiscuousVerifier; //导入依赖的package包/类
/**
* Connects to a ssh server
*
* <p>
* Do not call this constructor directly, use {@link SshConnector} instead for IoC
*
* @param config the ssh configuration
* @param client an instance of {@link SSHClient} to use
* @throws IOException failed to connect to the server
*/
public SshConnection(SshConfig config, SSHClient client) throws IOException {
// TODO see if the SSHClient can be injected differently
this.client = client;
this.config = config;
if (!config.getVerifyHostKey()) {
client.addHostKeyVerifier(new PromiscuousVerifier());
}
client.connect(config.getHost(), config.getPort());
if (config.getPassword() != null) {
client.authPassword(config.getUser(), config.getPassword());
} else if (config.getKeyFile() != null) {
client.authPublickey(config.getUser(), config.getKeyFile().toString());
} else {
client.authPassword(config.getUser(), "");
}
}
示例2: execute
import net.schmizz.sshj.transport.verification.PromiscuousVerifier; //导入依赖的package包/类
@Override
public OperationFuture<ShellResponse> execute() throws SshException {
ShellResponse response = null;
Session session = null;
try {
ssh.addHostKeyVerifier(new PromiscuousVerifier());
withTimeout(ofMinutes(CONNECTION_TIMEOUT), () -> ssh.connect(host));
ssh.authPassword(credentials.getUserName(), credentials.getPassword());
for (String command : commandList) {
session = ssh.startSession();
response = execCommand(session, command);
}
} catch (IOException e) {
throw new SshException(e);
} finally {
closeQuietly(ssh, session);
}
return new OperationFuture<>(response, new NoWaitingJobFuture());
}
示例3: executeCommand
import net.schmizz.sshj.transport.verification.PromiscuousVerifier; //导入依赖的package包/类
public static boolean executeCommand(String host, String defaultPrivateKeyFile, String sshCommand, String sshUser, Map<String, List<String>> sshCheckMap)
throws IOException {
if (sshCheckMap.isEmpty()) {
return false;
}
try (SSHClient sshClient = new SSHClient()) {
sshClient.addHostKeyVerifier(new PromiscuousVerifier());
sshClient.connect(host, 22);
sshClient.authPublickey(sshUser, defaultPrivateKeyFile);
Pair<Integer, String> cmdOut = execute(sshClient, sshCommand);
LOGGER.info("Ssh command status code and output: " + cmdOut);
for (Map.Entry<String, List<String>> entry : sshCheckMap.entrySet()) {
for (String listValue: entry.getValue()) {
if (cmdOut.getLeft() != 0 || !checkCommandOutput(cmdOut, entry.getKey(), listValue)) {
LOGGER.error("Ssh command output is not proper: " + entry.getKey() + ' ' + listValue);
return false;
}
}
}
}
return true;
}
示例4: getTempLocalInstance
import net.schmizz.sshj.transport.verification.PromiscuousVerifier; //导入依赖的package包/类
public File getTempLocalInstance( String remoteFilePath )
{
File tempFile = null;
SSHClient client = new SSHClient();
// required if host is not in knownLocalHosts
client.addHostKeyVerifier(new PromiscuousVerifier());
try {
client.connect(hostName);
client.authPassword(userName, userPass);
tempFile = File.createTempFile("tmp", null, null);
tempFile.deleteOnExit();
SFTPClient sftp = client.newSFTPClient();
sftp.get(remoteFilePath, new FileSystemFile(tempFile));
sftp.close();
client.disconnect();
} catch( Exception e ) {
//TODO: this needs to be more robust than just catching all exceptions
e.printStackTrace();
logger.error( e.toString() );
return null;
}
return tempFile;
}
示例5: getConnectedClient
import net.schmizz.sshj.transport.verification.PromiscuousVerifier; //导入依赖的package包/类
private SSHClient getConnectedClient() throws Exception {
if (password == null && key == null)
throw new Exception("You need to provide one among the key and the password to be used.");
DefaultConfig defaultConfig = new DefaultConfig();
defaultConfig.setKeepAliveProvider(KeepAliveProvider.KEEP_ALIVE);
final SSHClient ssh = new SSHClient(defaultConfig);
ssh.addHostKeyVerifier(new PromiscuousVerifier());
ssh.connect(ip, SSH_PORT);
if (key != null) {
if (!key.endsWith(".pem"))
key = key.concat(".pem");
Path p = Configuration.getPathToFile(key);
if (p != null)
ssh.authPublickey(user, p.toString());
} else {
ssh.authPassword(user, password);
}
ssh.getConnection().getKeepAlive().setKeepAliveInterval(5);
return ssh;
}
示例6: getSshClient
import net.schmizz.sshj.transport.verification.PromiscuousVerifier; //导入依赖的package包/类
private static SSHClient getSshClient(HostInfo hostInfo) throws IOException {
long sleepTimeMs = INITIAL_SLEEP_TIME_MS;
for (int attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
try {
SSHClient ssh = new SSHClient(DEFAULT_CONFIG);
ssh.addHostKeyVerifier(new PromiscuousVerifier());
ssh.connect(hostInfo.host);
ssh.authPublickey(hostInfo.user, hostInfo.privateKeyPath);
ssh.useCompression();
return ssh;
} catch (IOException exception) {
System.out.format("Failed to login to host %s as user %s. Exception: %s.%n", hostInfo.host, hostInfo.user, exception.getMessage());
System.out.format("Attempt %d of %d. Sleeping for %d ms.%n", attempt, MAX_ATTEMPTS, sleepTimeMs);
boolean lastAttempt = attempt == MAX_ATTEMPTS;
if (lastAttempt) {
throw exception;
}
try {
Thread.sleep(sleepTimeMs);
} catch (InterruptedException e) {
}
sleepTimeMs *= BACKOFF_FACTOR;
}
}
throw new RuntimeException(String.format("Unable to login to host %s as user %s after %d attempts.", hostInfo.host, hostInfo.user, MAX_ATTEMPTS));
}
示例7: main
import net.schmizz.sshj.transport.verification.PromiscuousVerifier; //导入依赖的package包/类
public static void main(String... args)
throws IOException {
String privateKey = "-----BEGIN RSA PRIVATE KEY-----\n"
+ "MIIEogIBAAKCAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzI\n"
+ "w+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoP\n"
+ "kcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2\n"
+ "hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJn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HvxB3Tcz\n"
+ "6+jJF85D5BNAG3DBMKBjAoGBAOAxZvgsKN+JuENXsST7F89Tck2iTcQIT8g5rwWC\n"
+ "P9Vt74yboe2kDT531w8+egz7nAmRBKNM751U/95P9t88EDacDI/Z2OwnuFQHCPDF\n"
+ "llYOUI+SpLJ6/vURRbHSnnn8a/XG+nzedGH5JGqEJNQsz+xT2axM0/W/CRknmGaJ\n"
+ "kda/AoGANWrLCz708y7VYgAtW2Uf1DPOIYMdvo6fxIB5i9ZfISgcJ/bbCUkFrhoH\n"
+ "+vq/5CIWxCPp0f85R4qxxQ5ihxJ0YDQT9Jpx4TMss4PSavPaBH3RXow5Ohe+bYoQ\n"
+ "NE5OgEXk2wVfZczCZpigBKbKZHNYcelXtTt/nP3rsCuGcM4h53s=\n"
+ "-----END RSA PRIVATE KEY-----";
String publicKey = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key";
SSHClient client = new SSHClient();
client.addHostKeyVerifier(new PromiscuousVerifier());
KeyProvider keys = client.loadKeys(privateKey, publicKey, null);
client.connect("192.168.33.10", 22);
client.authPublickey("vagrant", keys);
try {
final Session session = client.startSession();
try {
session.allocateDefaultPTY();
final Shell shell = session.startShell();
new StreamCopier(shell.getInputStream(), System.out)
.bufSize(shell.getLocalMaxPacketSize())
.spawn("stdout");
new StreamCopier(shell.getErrorStream(), System.err)
.bufSize(shell.getLocalMaxPacketSize())
.spawn("stderr");
// Now make System.in act as stdin. To exit, hit Ctrl+D (since that results in an EOF on System.in)
// This is kinda messy because java only allows console input after you hit return
// But this is just an example... a GUI app could implement a proper PTY
new StreamCopier(System.in, shell.getOutputStream())
.bufSize(shell.getRemoteMaxPacketSize())
.copy();
} finally {
session.close();
}
} finally {
client.disconnect();
}
}
示例8: openConnection
import net.schmizz.sshj.transport.verification.PromiscuousVerifier; //导入依赖的package包/类
/**
* Opens ssh connection.
* Method must be executed before any attempt to read from remote host.
*/
void openConnection(String remoteHost, int sshPort, String remoteUser) {
try {
sshClient.addHostKeyVerifier(new PromiscuousVerifier());
sshClient.connect(remoteHost, sshPort);
sshClient.authPublickey(remoteUser);
} catch (IOException e) {
throw new RuntimeException("Error in opening ssh connection", e);
}
}
示例9: Sshj
import net.schmizz.sshj.transport.verification.PromiscuousVerifier; //导入依赖的package包/类
public Sshj(@Nonnull Config config, @Nonnull Prompt prompt) throws IOException {
checkNotNull(config);
this.prompt = checkNotNull(prompt);
getConnection().setMaxPacketSize(config.getInt("shell.maxPacketSize", getConnection().getMaxPacketSize()));
getConnection().setWindowSize(config.getLong("shell.windowSize", getConnection().getWindowSize()));
long defaultTimeout = config.getTime("shell.timeout", "10s");
getConnection().setTimeoutMs((int) config.getTime("shell.timeout.connection", String.valueOf(defaultTimeout)));
getTransport().setTimeoutMs((int) config.getTime("shell.timeout.transport", String.valueOf(defaultTimeout)));
if (config.getBoolean("shell.compress", true)) {
useCompression();
}
if (config.getBoolean("shell.promiscuous", true)) {
addHostKeyVerifier(new PromiscuousVerifier());
} else {
if (config.getBoolean("shell.loadKnownHosts", true)) {
if (config.containsKey("shell.knownHosts")) {
loadKnownHosts(new File(config.getString("shell.knownHosts")));
} else {
loadKnownHosts();
}
}
addHostKeyVerifier((host, port, key) -> {
String fingerprint = SecurityUtils.getFingerprint(key);
String name = "fingerprint[" + fingerprint + "]@" + host;
String message = "Enter yes/no to verify fingerprint " + fingerprint + " for " + host + ": ";
return prompt.prompt(name, message, Type.PLAIN).accept().equals("yes");
});
}
pty = config.getBoolean("shell.pty", false);
retries = config.getInt("shell.retries", 3);
}
示例10: createSSHClient
import net.schmizz.sshj.transport.verification.PromiscuousVerifier; //导入依赖的package包/类
private SSHClient createSSHClient(String host, int port, String user, String privateKeyFile) throws IOException {
SSHClient sshClient = new SSHClient();
sshClient.addHostKeyVerifier(new PromiscuousVerifier());
sshClient.connect(host, port);
sshClient.authPublickey(user, privateKeyFile);
return sshClient;
}
示例11: getFilesInPath
import net.schmizz.sshj.transport.verification.PromiscuousVerifier; //导入依赖的package包/类
public ArrayList< String > getFilesInPath( String path )
{
ArrayList< String > ret = new ArrayList< String >();
SSHClient client = new SSHClient();
client.addHostKeyVerifier(new PromiscuousVerifier());
try {
client.connect(hostName);
client.authPassword(userName, userPass);
SFTPClient sftp = client.newSFTPClient();
List< RemoteResourceInfo > files = sftp.ls( path );
for( RemoteResourceInfo file: files )
{
ret.add( file.getPath() );
}
sftp.close();
client.disconnect();
} catch( Exception e ) {
logger.error( e.toString() );
}
return ret;
}
示例12: testReadLogfile
import net.schmizz.sshj.transport.verification.PromiscuousVerifier; //导入依赖的package包/类
public void testReadLogfile() throws IOException {
String privateKey = "-----BEGIN RSA PRIVATE KEY-----\n"
+ "MIIEogIBAAKCAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzI\n"
+ "w+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoP\n"
+ "kcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2\n"
+ "hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NO\n"
+ "Td0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcW\n"
+ "yLb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Vt74yboe2kDT531w8+egz7nAmRBKNM751U/95P9t88EDacDI/Z2OwnuFQHCPDF\n"
+ "llYOUI+SpLJ6/vURRbHSnnn8a/XG+nzedGH5JGqEJNQsz+xT2axM0/W/CRknmGaJ\n"
+ "kda/AoGANWrLCz708y7VYgAtW2Uf1DPOIYMdvo6fxIB5i9ZfISgcJ/bbCUkFrhoH\n"
+ "+vq/5CIWxCPp0f85R4qxxQ5ihxJ0YDQT9Jpx4TMss4PSavPaBH3RXow5Ohe+bYoQ\n"
+ "NE5OgEXk2wVfZczCZpigBKbKZHNYcelXtTt/nP3rsCuGcM4h53s=\n"
+ "-----END RSA PRIVATE KEY-----";
String publicKey = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key";
SSHClient client = new SSHClient();
client.addHostKeyVerifier(new PromiscuousVerifier());
KeyProvider keys = client.loadKeys(privateKey, publicKey, null);
client.connect("192.168.33.10", 22);
client.authPublickey("vagrant", keys);
Session session = client.startSession();
final Session.Command cmd = session.exec("ls");
cmd.join();
final byte[] buffer = new byte[65536];
InputStream is = cmd.getInputStream();
int r;
while ((r = is.read(buffer)) > 0) {
String decoded = new String(buffer, "UTF-8");
System.out.println(decoded);
}
}