@Test public void testOpenConnectionUseKey_2() throws Exception { when( fileObject.exists() ).thenReturn( true ); when( fileObject.getContent() ).thenReturn( fileContent ); when( fileContent.getSize() ).thenReturn( 1000L ); when( fileContent.getInputStream() ).thenReturn( new ByteArrayInputStream( new byte[] { 1, 2, 3, 4, 5 } ) ); when( variableSpace.environmentSubstitute( passPhrase ) ).thenReturn( passPhrase ); when( connection.authenticateWithPublicKey( eq( username ), Matchers.<char[]>any(), eq( passPhrase ) ) ).thenReturn( true ); SSHData.OpenConnection( server, port, username, null, true, keyFilePath, passPhrase, 0, variableSpace, null, 0, null, null ); verify( connection ).connect(); verify( connection ).authenticateWithPublicKey( eq( username ), Matchers.<char[]>any(), eq( passPhrase ) ); }
isAuthenticated = conn.authenticateWithPublicKey( realUsername, new File( realkeyFilename ), realkeyPass ); } else { isAuthenticated = conn.authenticateWithPassword( realUsername, realserverpassword );
conn.authenticateWithPublicKey( username, content, space.environmentSubstitute( passPhrase ) ); } else { isAuthenticated = conn.authenticateWithPassword( username, password );
conn.authenticateWithPublicKey( jobMeta.environmentSubstitute( wUserName.getText() ), new java.io.File( jobMeta .environmentSubstitute( wKeyFilename.getText() ) ), jobMeta
public static void scpTo(String host, int port, String user, File pemKeyFile, String password, String remoteTargetDirectory, String localFile, String fileMode, int connectTimeoutInMs, int kexTimeoutInMs) throws Exception { com.trilead.ssh2.Connection conn = null; com.trilead.ssh2.SCPClient scpClient = null; try { conn = new com.trilead.ssh2.Connection(host, port); conn.connect(null, connectTimeoutInMs, kexTimeoutInMs); if (pemKeyFile == null) { if (!conn.authenticateWithPassword(user, password)) { String msg = "Failed to authentication SSH user " + user + " on host " + host; s_logger.error(msg); throw new Exception(msg); } } else { if (!conn.authenticateWithPublicKey(user, pemKeyFile, password)) { String msg = "Failed to authentication SSH user " + user + " on host " + host; s_logger.error(msg); throw new Exception(msg); } } scpClient = conn.createSCPClient(); if (fileMode != null) scpClient.put(localFile, remoteTargetDirectory, fileMode); else scpClient.put(localFile, remoteTargetDirectory); } finally { if (conn != null) conn.close(); } }
public static void scpTo(String host, int port, String user, File pemKeyFile, String password, String remoteTargetDirectory, byte[] data, String remoteFileName, String fileMode, int connectTimeoutInMs, int kexTimeoutInMs) throws Exception { com.trilead.ssh2.Connection conn = null; com.trilead.ssh2.SCPClient scpClient = null; try { conn = new com.trilead.ssh2.Connection(host, port); conn.connect(null, connectTimeoutInMs, kexTimeoutInMs); if (pemKeyFile == null) { if (!conn.authenticateWithPassword(user, password)) { String msg = "Failed to authentication SSH user " + user + " on host " + host; s_logger.error(msg); throw new Exception(msg); } } else { if (!conn.authenticateWithPublicKey(user, pemKeyFile, password)) { String msg = "Failed to authentication SSH user " + user + " on host " + host; s_logger.error(msg); throw new Exception(msg); } } scpClient = conn.createSCPClient(); if (fileMode != null) scpClient.put(data, remoteFileName, remoteTargetDirectory, fileMode); else scpClient.put(data, remoteFileName, remoteTargetDirectory); } finally { if (conn != null) conn.close(); } }
if (!conn.authenticateWithPublicKey(user, pemKeyFile, password)) { String msg = "Failed to authentication SSH user " + user + " on host " + host; s_logger.error(msg);
return authenticateWithPublicKey(user, cw.toCharArray(), password);
return authenticateWithPublicKey(user, cw.toCharArray(), password);
return authenticateWithPublicKey(user, cw.toCharArray(), password);
/** * Private helper function, etablishes a connection to a remote host. * @param host Hostname or IP address. * @param key Private RSA key for auhentification. * @return Connection object representing the connection or null in case of error. */ private Connection connect(String host, String key){ try { /* Create a connection instance */ Connection conn = new Connection(host); /* Now connect */ conn.connect(); /* Authenticate */ boolean isAuthenticated = conn.authenticateWithPublicKey("root", key.toCharArray(), ""); if (isAuthenticated == false) throw new IOException("Authentication failed."); return conn; } catch (IOException e){ e.printStackTrace(System.err); return null; } }
@Override public void authenticate(Connection connection) throws IOException { String u = credentials.getUser(); if(!connection.authenticateWithPublicKey(u, credentials.getPrivateKey().toCharArray(), credentials.getPassword())){ throw new IOException(String.format("Public key authentication failed: trying to login as %s@%s with %s", u, connection.getHostname(), keyPair.privateKey)); } }
private int bootstrap(Connection bootstrapConn, EC2Computer computer, PrintStream logger) throws IOException, InterruptedException, AmazonClientException { logger.println("bootstrap()" ); boolean closeBootstrap = true; try { int tries = 20; boolean isAuthenticated = false; logger.println("Getting keypair..." ); KeyPair key = computer.getCloud().getKeyPair(); logger.println("Using key: " + key.getKeyName() + "\n" + key.getKeyFingerprint() + "\n" + key.getKeyMaterial().substring(0, 160) ); while (tries-- > 0) { logger.println("Authenticating as " + computer.getRemoteAdmin()); isAuthenticated = bootstrapConn.authenticateWithPublicKey(computer.getRemoteAdmin(), key.getKeyMaterial().toCharArray(), ""); if (isAuthenticated) { break; } logger.println("Authentication failed. Trying again..."); Thread.sleep(10000); } if (!isAuthenticated) { logger.println("Authentication failed"); return FAILED; } closeBootstrap = false; return SAMEUSER; } finally { if (closeBootstrap) bootstrapConn.close(); } }
private void authConnect() { String userName = remoteCmdClientConfig.getUserName(); String passWord = remoteCmdClientConfig.getPassword(); String errorMsg = String.format("Open connection failed because of remoteCmdClient's auth [ip=%s,userName=%s]", remoteCmdClientConfig.getIp(), remoteCmdClientConfig.getUserName()); try { if (StringUtils.isBlank(passWord)) { ready = connection.authenticateWithPublicKey(userName, new File(System.getProperty("user.home") + File.separator + ".ssh" + File.separator + "id_rsa"), null); } else { ready = connection.authenticateWithPassword(userName, passWord); } } catch (IOException e) { log.error(errorMsg, e); } if (!ready || !checkConnectionStatus(connection)) { connection.close(); throw new ConnectException(); } }
if (!conn.authenticateWithPublicKey(user, pemKeyFile, password)) { final String msg = "Failed to authentication SSH user " + user + " on host " + host; s_logger.error(msg);
if (!conn.authenticateWithPublicKey(user, pemKeyFile, password)) { final String msg = "Failed to authentication SSH user " + user + " on host " + host; s_logger.error(msg);
authenticated = connection.authenticateWithPublicKey(myUserName, myPrivateKey, passphrase);
for (String privateKey : getPrivateKeys(user)) { try { if (connection.authenticateWithPublicKey(username, privateKey.toCharArray(), passphrase)) { LOGGER.fine("Authentication with 'publickey' succeeded."); return true;
try { bootstrapConn = connectToSsh(computer, listener); isAuthenticated = bootstrapConn.authenticateWithPublicKey(computer.getRemoteAdmin(), key.getKeyMaterial().toCharArray(), ""); } catch(IOException e) { logException(computer, listener, "Exception trying to authenticate", e);
boolean authenticated = false; if (privateKey != null) { authenticated = connection.authenticateWithPublicKey(userName, privateKey, passphrase); } else if (password != null) { String[] methods = connection.getRemainingAuthMethods(userName);