当前位置: 首页>>代码示例>>Java>>正文


Java PromiscuousVerifier类代码示例

本文整理汇总了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(), "");
	}
}
 
开发者ID:bugminer,项目名称:bugminer,代码行数:27,代码来源:SshConnection.java

示例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());
}
 
开发者ID:CenturyLinkCloud,项目名称:clc-java-sdk,代码行数:22,代码来源:SshjClient.java

示例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;
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:23,代码来源:SshUtil.java

示例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;
}
 
开发者ID:prateek,项目名称:ssh-spool-source,代码行数:29,代码来源:SshClientJ.java

示例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;
}
 
开发者ID:rickdesantis,项目名称:cloud-runner,代码行数:28,代码来源:Sshj.java

示例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));
}
 
开发者ID:electronicarts,项目名称:gatling-aws-maven-plugin,代码行数:32,代码来源:SshClient.java

示例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+GPXQ2MWZWFYbAGjyiYJnAmCP3NO\n"
      + "Td0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcW\n"
      + "yLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQIBIwKCAQEA4iqWPJXtzZA68mKd\n"
      + "ELs4jJsdyky+ewdZeNds5tjcnHU5zUYE25K+ffJED9qUWICcLZDc81TGWjHyAqD1\n"
      + "Bw7XpgUwFgeUJwUlzQurAv+/ySnxiwuaGJfhFM1CaQHzfXphgVml+fZUvnJUTvzf\n"
      + "TK2Lg6EdbUE9TarUlBf/xPfuEhMSlIE5keb/Zz3/LUlRg8yDqz5w+QWVJ4utnKnK\n"
      + "iqwZN0mwpwU7YSyJhlT4YV1F3n4YjLswM5wJs2oqm0jssQu/BT0tyEXNDYBLEF4A\n"
      + "sClaWuSJ2kjq7KhrrYXzagqhnSei9ODYFShJu8UWVec3Ihb5ZXlzO6vdNQ1J9Xsf\n"
      + "4m+2ywKBgQD6qFxx/Rv9CNN96l/4rb14HKirC2o/orApiHmHDsURs5rUKDx0f9iP\n"
      + "cXN7S1uePXuJRK/5hsubaOCx3Owd2u9gD6Oq0CsMkE4CUSiJcYrMANtx54cGH7Rk\n"
      + "EjFZxK8xAv1ldELEyxrFqkbE4BKd8QOt414qjvTGyAK+OLD3M2QdCQKBgQDtx8pN\n"
      + "CAxR7yhHbIWT1AH66+XWN8bXq7l3RO/ukeaci98JfkbkxURZhtxV/HHuvUhnPLdX\n"
      + "3TwygPBYZFNo4pzVEhzWoTtnEtrFueKxyc3+LjZpuo+mBlQ6ORtfgkr9gBVphXZG\n"
      + "YEzkCD3lVdl8L4cw9BVpKrJCs1c5taGjDgdInQKBgHm/fVvv96bJxc9x1tffXAcj\n"
      + "3OVdUN0UgXNCSaf/3A/phbeBQe9xS+3mpc4r6qvx+iy69mNBeNZ0xOitIjpjBo2+\n"
      + "dBEjSBwLk5q5tJqHmy/jKMJL4n9ROlx93XS+njxgibTvU6Fp9w+NOFD/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();
  }
}
 
开发者ID:karamelchef,项目名称:karamel,代码行数:69,代码来源:RudimentaryPTY.java

示例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);
	}
}
 
开发者ID:openaire,项目名称:iis,代码行数:14,代码来源:SshSimpleConnection.java

示例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);
}
 
开发者ID:lithiumtech,项目名称:flow,代码行数:38,代码来源:Sshj.java

示例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;
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:8,代码来源:CountRecipeResultsTest.java

示例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;
}
 
开发者ID:prateek,项目名称:ssh-spool-source,代码行数:28,代码来源:SshClientJ.java

示例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"
      + "yLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQIBIwKCAQEA4iqWPJXtzZA68mKd\n"
      + "ELs4jJsdyky+ewdZeNds5tjcnHU5zUYE25K+ffJED9qUWICcLZDc81TGWjHyAqD1\n"
      + "Bw7XpgUwFgeUJwUlzQurAv+/ySnxiwuaGJfhFM1CaQHzfXphgVml+fZUvnJUTvzf\n"
      + "TK2Lg6EdbUE9TarUlBf/xPfuEhMSlIE5keb/Zz3/LUlRg8yDqz5w+QWVJ4utnKnK\n"
      + "iqwZN0mwpwU7YSyJhlT4YV1F3n4YjLswM5wJs2oqm0jssQu/BT0tyEXNDYBLEF4A\n"
      + "sClaWuSJ2kjq7KhrrYXzagqhnSei9ODYFShJu8UWVec3Ihb5ZXlzO6vdNQ1J9Xsf\n"
      + "4m+2ywKBgQD6qFxx/Rv9CNN96l/4rb14HKirC2o/orApiHmHDsURs5rUKDx0f9iP\n"
      + "cXN7S1uePXuJRK/5hsubaOCx3Owd2u9gD6Oq0CsMkE4CUSiJcYrMANtx54cGH7Rk\n"
      + "EjFZxK8xAv1ldELEyxrFqkbE4BKd8QOt414qjvTGyAK+OLD3M2QdCQKBgQDtx8pN\n"
      + "CAxR7yhHbIWT1AH66+XWN8bXq7l3RO/ukeaci98JfkbkxURZhtxV/HHuvUhnPLdX\n"
      + "3TwygPBYZFNo4pzVEhzWoTtnEtrFueKxyc3+LjZpuo+mBlQ6ORtfgkr9gBVphXZG\n"
      + "YEzkCD3lVdl8L4cw9BVpKrJCs1c5taGjDgdInQKBgHm/fVvv96bJxc9x1tffXAcj\n"
      + "3OVdUN0UgXNCSaf/3A/phbeBQe9xS+3mpc4r6qvx+iy69mNBeNZ0xOitIjpjBo2+\n"
      + "dBEjSBwLk5q5tJqHmy/jKMJL4n9ROlx93XS+njxgibTvU6Fp9w+NOFD/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);

  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);
  }

}
 
开发者ID:karamelchef,项目名称:karamel,代码行数:49,代码来源:SshMachineTest.java


注:本文中的net.schmizz.sshj.transport.verification.PromiscuousVerifier类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。