本文整理汇总了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;
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
}
示例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;
}
});
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}
}
示例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;
}
示例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);
}
示例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;
}
示例13: getHostKeyVerifier
import net.schmizz.sshj.transport.verification.HostKeyVerifier; //导入依赖的package包/类
public HostKeyVerifier getHostKeyVerifier() {
return hostKeyVerifier;
}
示例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);
}