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


Java HostKeyVerifier类代码示例

本文整理汇总了Java中net.schmizz.sshj.transport.verification.HostKeyVerifier的典型用法代码示例。如果您正苦于以下问题:Java HostKeyVerifier类的具体用法?Java HostKeyVerifier怎么用?Java HostKeyVerifier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HostKeyVerifier类属于net.schmizz.sshj.transport.verification包,在下文中一共展示了HostKeyVerifier类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: build

import net.schmizz.sshj.transport.verification.HostKeyVerifier; //导入依赖的package包/类
private void build() throws IOException {
    if (init) {
        return;
    }

    ssh = new SSHClient();
    ssh.addHostKeyVerifier(new HostKeyVerifier() {
        @Override
        public boolean verify(String arg0, int arg1, PublicKey arg2) {
            return true;
        }
    });
    ssh.connect(hostname, port);
    if (privateKey != null) {
        privateKeyFile = File.createTempFile("zstack", "tmp");
        FileUtils.writeStringToFile(privateKeyFile, privateKey);
        ssh.authPublickey(username, privateKeyFile.getAbsolutePath());
    } else {
        ssh.authPassword(username, password);
    }

    init = true;
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:24,代码来源:Ssh.java

示例2: doInBackground

import net.schmizz.sshj.transport.verification.HostKeyVerifier; //导入依赖的package包/类
@Override
protected Boolean doInBackground(String... cmd) {
	String ssh_command = cmd[0];
	SSHClient ssh = new SSHClient();
	HostKeyVerifier always_verify = new HostKeyVerifier() {
				public boolean verify(String arg0, int arg1, PublicKey arg2) {
					return true;
				}  
	}; 
	ssh.addHostKeyVerifier(always_verify);  
	Boolean success = false;
	try {
		ssh.connect(this.ssh_server);
		ssh.authPassword(this.ssh_user, this.ssh_password);
		Session session = ssh.startSession();
		Command command = session.exec(ssh_command);
		command.join();
		Integer exit_status = command.getExitStatus(); 
		if (exit_status == this.expected_exit_status) {
			success = true;
		}
		session.close();
		ssh.close();
	} catch (IOException e) { }
	return success;
}
 
开发者ID:hkparker,项目名称:ComputerManager,代码行数:27,代码来源:BackgroundSSHExec.java

示例3: removeTemporarySShKey

import net.schmizz.sshj.transport.verification.HostKeyVerifier; //导入依赖的package包/类
public void removeTemporarySShKey(Stack stack, String publicIp, int sshPort, String user, Set<String> sshFingerprints) throws CloudbreakException {
    SSHClient ssh = new SSHClient();
    try {
        String privateKey = stack.getSecurityConfig().getCloudbreakSshPrivateKeyDecoded();
        HostKeyVerifier hostKeyVerifier = new VerboseHostKeyVerifier(sshFingerprints);
        prepareSshConnection(ssh, publicIp, sshPort, hostKeyVerifier, user, privateKey, stack);
        removeTemporarySShKey(ssh, user, stack);
    } catch (IOException ignored) {
        LOGGER.info("Unable to delete temporary SSH key for stack {}", stack.getId());
    } finally {
        try {
            ssh.disconnect();
        } catch (IOException e) {
            throw new CloudbreakException("Couldn't disconnect temp SSH session", e);
        }
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:18,代码来源:TlsSetupService.java

示例4: prepareSshConnection

import net.schmizz.sshj.transport.verification.HostKeyVerifier; //导入依赖的package包/类
private void prepareSshConnection(SSHClient ssh, String ip, int port, HostKeyVerifier hostKeyVerifier, String user,
        String privateKeyString, Stack stack) throws CloudbreakException, IOException {
    ssh.addHostKeyVerifier(hostKeyVerifier);
    ssh.connect(ip, port);
    if (stack.getStackAuthentication().passwordAuthenticationRequired()) {
        ssh.authPassword(user, stack.getStackAuthentication().getLoginPassword());
    } else {
        try {
            KeyPair keyPair = KeyStoreUtil.createKeyPair(privateKeyString);
            KeyPairWrapper keyPairWrapper = new KeyPairWrapper(keyPair);
            ssh.authPublickey(user, keyPairWrapper);
        } catch (Exception e) {
            throw new CloudbreakException("Couldn't prepare SSH connection", e);
        }
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:17,代码来源:TlsSetupService.java

示例5: onPreExecute

import net.schmizz.sshj.transport.verification.HostKeyVerifier; //导入依赖的package包/类
@Override
protected void onPreExecute() {
	super.onPreExecute();
	Toast.makeText(activity, getString(R.string.command_executor_execute),
			Toast.LENGTH_LONG).show();
	
	myTerminal.show();
	
	ssh = new SSHClient(new AndroidConfig());
	ssh.addHostKeyVerifier(new HostKeyVerifier() {
		@Override
		public boolean verify(String arg0, int arg1, PublicKey arg2) {
			return true;
		}
	});
}
 
开发者ID:joakim-ribier,项目名称:JOneTouch,代码行数:17,代码来源:CommandExecutor.java

示例6: connect

import net.schmizz.sshj.transport.verification.HostKeyVerifier; //导入依赖的package包/类
protected SSHClient connect(final HostKeyCallback key, final Config configuration) throws IOException {
    final SSHClient connection = new SSHClient(configuration);
    final int timeout = preferences.getInteger("connection.timeout.seconds") * 1000;
    connection.setTimeout(timeout);
    connection.setSocketFactory(socketFactory);
    connection.addHostKeyVerifier(new HostKeyVerifier() {
        @Override
        public boolean verify(String hostname, int port, PublicKey publicKey) {
            try {
                return key.verify(hostname, port, publicKey);
            }
            catch(ConnectionCanceledException | ChecksumException e) {
                return false;
            }
        }
    });
    connection.addAlgorithmsVerifier(new AlgorithmsVerifier() {
        @Override
        public boolean verify(final NegotiatedAlgorithms negotiatedAlgorithms) {
            log.info(String.format("Negotiated algorithms %s", negotiatedAlgorithms));
            algorithms = negotiatedAlgorithms;
            return true;
        }
    });
    disconnectListener = new StateDisconnectListener();
    final Transport transport = connection.getTransport();
    transport.setDisconnectListener(disconnectListener);
    connection.connect(HostnameConfiguratorFactory.get(host.getProtocol()).getHostname(host.getHostname()), host.getPort());
    final KeepAlive keepalive = connection.getConnection().getKeepAlive();
    keepalive.setKeepAliveInterval(preferences.getInteger("ssh.heartbeat.seconds"));
    return connection;
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:33,代码来源:SFTPSession.java

示例7: initialize

import net.schmizz.sshj.transport.verification.HostKeyVerifier; //导入依赖的package包/类
@PostConstruct
public void initialize() throws Exception {
    ssh = new SSHClient();
    ssh.addHostKeyVerifier(new HostKeyVerifier() {
        @Override
        public boolean verify(final String s, final int i, final PublicKey publicKey) {
            return true;
        }
    });
    ssh.connect(cecSshHost);
    ssh.authPassword(cecSshUser, cecSshPass);

    session = ssh.startSession();

    command = session.exec(String.format("cec-client --osd-name \"%s\"", cecOsdName));

    outputStream = command.getOutputStream();
    inputStream = command.getInputStream();

    OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
    printWriter = new PrintWriter(outputStreamWriter);
    streamGobbler = new StreamGobbler(inputStream, new StreamGobbler.OnLineListener() {
        @Override
        public void onLine(final String line) {
            logger.info("CEC: " + line);
            for (LineHandler lineHandler : lineHandlerList) {
                lineHandler.onLine(line);
            }
        }
    });
    streamGobbler.start();
}
 
开发者ID:rpardini,项目名称:libcec-rest,代码行数:33,代码来源:SSHCECManager.java

示例8: newSSHClient

import net.schmizz.sshj.transport.verification.HostKeyVerifier; //导入依赖的package包/类
/**
 * Creates the new instance of net.schmizz.sshj.SSHClient.
 * 
 * @return the new instance of SSHClient
 */
protected SSHClient newSSHClient(){
	SSHClient client = new SSHClient();
	client.addHostKeyVerifier(new HostKeyVerifier() {
		@Override
		public boolean verify(String arg0, int arg1, PublicKey arg2) {
			// skip host key verification
			return true;
		}
	});
	return client;
}
 
开发者ID:cyron,项目名称:byteman-framework,代码行数:17,代码来源:SSH.java

示例9: main

import net.schmizz.sshj.transport.verification.HostKeyVerifier; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
    SSHClient ssh = new SSHClient();
    ssh.addHostKeyVerifier(
            new HostKeyVerifier() {
                @Override
                public boolean verify(String s, int i, PublicKey publicKey) {
                    return true;
                }
            });
    ssh.connect("sdf.org");
    ssh.authPassword("new", "");
    Session session = ssh.startSession();
    session.allocateDefaultPTY();
    Shell shell = session.startShell();
    Expect expect = new ExpectBuilder()
            .withOutput(shell.getOutputStream())
            .withInputs(shell.getInputStream(), shell.getErrorStream())
            .withEchoInput(System.out)
            .withEchoOutput(System.err)
            .withInputFilters(removeColors(), removeNonPrintable())
            .withExceptionOnFailure()
            .build();
    try {
        expect.expect(contains("[RETURN]"));
        expect.sendLine();
        String ipAddress = expect.expect(regexp("Trying (.*)\\.\\.\\.")).group(1);
        System.out.println("Captured IP: " + ipAddress);
        expect.expect(contains("login:"));
        expect.sendLine("new");
        expect.expect(contains("(Y/N)"));
        expect.send("N");
        expect.expect(regexp(": $"));
        expect.send("\b");
        expect.expect(regexp("\\(y\\/n\\)"));
        expect.sendLine("y");
        expect.expect(contains("Would you like to sign the guestbook?"));
        expect.send("n");
        expect.expect(contains("[RETURN]"));
        expect.sendLine();
    } finally {
        expect.close();
        session.close();
        ssh.close();
    }
}
 
开发者ID:Alexey1Gavrilov,项目名称:ExpectIt,代码行数:46,代码来源:SshJExample.java

示例10: SshCheckerTaskContext

import net.schmizz.sshj.transport.verification.HostKeyVerifier; //导入依赖的package包/类
public SshCheckerTaskContext(Stack stack, HostKeyVerifier hostKeyVerifier, String publicIp, int sshPort, String user, String sshPrivateKey) {
    super(stack);
    this.hostKeyVerifier = hostKeyVerifier;
    this.publicIp = publicIp;
    this.sshPort = sshPort;
    this.user = user;
    this.sshPrivateKey = sshPrivateKey;
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:9,代码来源:SshCheckerTaskContext.java

示例11: setupTemporarySsh

import net.schmizz.sshj.transport.verification.HostKeyVerifier; //导入依赖的package包/类
private void setupTemporarySsh(SSHClient ssh, String ip, int port, HostKeyVerifier hostKeyVerifier, String user,
        SecurityConfig securityConfig, Stack stack) throws IOException, CloudbreakException {
    LOGGER.info("Setting up temporary ssh...");
    prepareSshConnection(ssh, ip, port, hostKeyVerifier, user, securityConfig.getCloudbreakSshPrivateKeyDecoded(), stack);
    String remoteTlsCertificatePath = "/tmp/cb-client.pem";
    ssh.newSCPFileTransfer().upload(uploadParameterFile(securityConfig.getClientCertDecoded(), "client.pem"), remoteTlsCertificatePath);
    LOGGER.info("Temporary ssh setup finished succesfully, public key is uploaded to {}", remoteTlsCertificatePath);
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:9,代码来源:TlsSetupService.java

示例12: login

import net.schmizz.sshj.transport.verification.HostKeyVerifier; //导入依赖的package包/类
@Override
public boolean login(String username, String password) throws AuthenticationException {
    try {
        logout();
        // ssh.authPublickey(System.getProperty("user.name"));
        log.info("new SSHClient");
        ssh = new SSHClient();
        log.info("verify all hosts");
        ssh.addHostKeyVerifier(new HostKeyVerifier() {
            public boolean verify(String arg0, int arg1, PublicKey arg2) {
                return true; // don't bother verifying
            }
        });
        log.info("connecting");
        ssh.connect("127.0.0.1");
        log.info("authenticating: {}", username);
        ssh.authPassword(username, password);
        log.info("starting session");
        session = ssh.startSession();
        log.info("allocating PTY");
        session.allocateDefaultPTY();
        log.info("starting shell");
        shell = session.startShell();
        log.info("SSH session established");
        this.username = username;
        input = new BufferedReader(new InputStreamReader(shell.getInputStream()));
        output = shell.getOutputStream();
        sender = new SSHSessionOutput(input);
    } catch (Exception e) {
        log.error(e.getMessage());
        finalize();
        throw new SSHAuthenticationException(e.getMessage(), e);
    }
    return true;

}
 
开发者ID:the-james-burton,项目名称:sshw,代码行数:37,代码来源:SSHSessionImpl.java

示例13: getHostKeyVerifier

import net.schmizz.sshj.transport.verification.HostKeyVerifier; //导入依赖的package包/类
public HostKeyVerifier getHostKeyVerifier() {
    return hostKeyVerifier;
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:4,代码来源:SshCheckerTaskContext.java

示例14: waitForSsh

import net.schmizz.sshj.transport.verification.HostKeyVerifier; //导入依赖的package包/类
private void waitForSsh(Stack stack, String publicIp, int sshPort, HostKeyVerifier hostKeyVerifier, String user) {
    sshCheckerTaskContextPollingService.pollWithTimeoutSingleFailure(
            sshCheckerTask,
            new SshCheckerTaskContext(stack, hostKeyVerifier, publicIp, sshPort, user, stack.getSecurityConfig().getCloudbreakSshPrivateKeyDecoded()),
            SSH_POLLING_INTERVAL, SSH_MAX_ATTEMPTS_FOR_HOSTS);
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:7,代码来源:TlsSetupService.java


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