From f2a8c2053e0a8cb0efbda7fab5a1f0fcad8314de Mon Sep 17 00:00:00 2001 From: Roland Schulz Date: Thu, 5 Jun 2014 19:03:08 -0400 Subject: [PATCH] Bug 428658 - fix keyboard-interactive authentication Also removes unnecessary code for firstTry for password/ keyboard-interactive. And fixes firstTry for pubKey auth. JSchConnection.newSession is storing the password with session.setPassword. This password is used first before jsch is using the UserInfo to prompt. Thus it isn't necessary to return from the prompt first the same stored password. Change-Id: I17a4ae057fc595c2afe452c550bf47b70b696ef4 --- .../internal/jsch/core/JSchConnection.java | 63 ++++++++++--------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnection.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnection.java index e42e41c12da..1ebc6b4a284 100644 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnection.java +++ b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnection.java @@ -54,7 +54,7 @@ public class JSchConnection implements IRemoteConnection { * Class to supply credentials from connection attributes without user interaction. */ private class JSchUserInfo implements UserInfo, UIKeyboardInteractive { - private boolean firstTry; + private boolean firstTryPassphrase = true; private final IUserAuthenticator fAuthenticator; public JSchUserInfo(IUserAuthenticator authenticator) { @@ -86,13 +86,17 @@ public class JSchConnection implements IRemoteConnection { System.out.println(" " + p); //$NON-NLS-1$ } } - String password; - if (!isPasswordAuth()) { - password = getPassphrase(); - } else { - password = getPassword(); + + if (fAuthenticator != null) { + String[] result = fAuthenticator.prompt(destination, name, instruction, prompt, echo); + if (result != null) { + if (prompt.length == 1 && prompt[0].trim().equalsIgnoreCase("password:")) { //$NON-NLS-1$ + fAttributes.setSecureAttribute(JSchConnectionAttributes.PASSWORD_ATTR, result[0]); + } + } + return result; } - return new String[] { password }; + return null; } @Override @@ -100,27 +104,8 @@ public class JSchConnection implements IRemoteConnection { if (logging) { System.out.println("promptPassphrase:" + message); //$NON-NLS-1$ } - if (firstTry && !getPassphrase().equals("")) { //$NON-NLS-1$ - firstTry = false; - return true; - } - if (fAuthenticator != null) { - PasswordAuthentication auth = fAuthenticator.prompt(null, message); - if (auth == null) { - return false; - } - fAttributes.setSecureAttribute(JSchConnectionAttributes.PASSPHRASE_ATTR, new String(auth.getPassword())); - } - return true; - } - - @Override - public boolean promptPassword(String message) { - if (logging) { - System.out.println("promptPassword:" + message); //$NON-NLS-1$ - } - if (firstTry && !getPassword().equals("")) { //$NON-NLS-1$ - firstTry = false; + if (firstTryPassphrase && !getPassphrase().equals("")) { //$NON-NLS-1$ + firstTryPassphrase = false; return true; } if (fAuthenticator != null) { @@ -129,9 +114,27 @@ public class JSchConnection implements IRemoteConnection { return false; } fAttributes.setAttribute(JSchConnectionAttributes.USERNAME_ATTR, auth.getUserName()); - fAttributes.setSecureAttribute(JSchConnectionAttributes.PASSWORD_ATTR, new String(auth.getPassword())); + fAttributes.setSecureAttribute(JSchConnectionAttributes.PASSPHRASE_ATTR, new String(auth.getPassword())); + return true; } - return true; + return false; + } + + @Override + public boolean promptPassword(String message) { + if (logging) { + System.out.println("promptPassword:" + message); //$NON-NLS-1$ + } + if (fAuthenticator != null) { + PasswordAuthentication auth = fAuthenticator.prompt(null, message); + if (auth == null) { + return false; + } + fAttributes.setAttribute(JSchConnectionAttributes.USERNAME_ATTR, auth.getUserName()); + fAttributes.setSecureAttribute(JSchConnectionAttributes.PASSWORD_ATTR, new String(auth.getPassword())); + return true; + } + return false; } @Override