mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
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
This commit is contained in:
parent
dad71b863b
commit
f2a8c2053e
1 changed files with 33 additions and 30 deletions
|
@ -54,7 +54,7 @@ public class JSchConnection implements IRemoteConnection {
|
||||||
* Class to supply credentials from connection attributes without user interaction.
|
* Class to supply credentials from connection attributes without user interaction.
|
||||||
*/
|
*/
|
||||||
private class JSchUserInfo implements UserInfo, UIKeyboardInteractive {
|
private class JSchUserInfo implements UserInfo, UIKeyboardInteractive {
|
||||||
private boolean firstTry;
|
private boolean firstTryPassphrase = true;
|
||||||
private final IUserAuthenticator fAuthenticator;
|
private final IUserAuthenticator fAuthenticator;
|
||||||
|
|
||||||
public JSchUserInfo(IUserAuthenticator authenticator) {
|
public JSchUserInfo(IUserAuthenticator authenticator) {
|
||||||
|
@ -86,13 +86,17 @@ public class JSchConnection implements IRemoteConnection {
|
||||||
System.out.println(" " + p); //$NON-NLS-1$
|
System.out.println(" " + p); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String password;
|
|
||||||
if (!isPasswordAuth()) {
|
if (fAuthenticator != null) {
|
||||||
password = getPassphrase();
|
String[] result = fAuthenticator.prompt(destination, name, instruction, prompt, echo);
|
||||||
} else {
|
if (result != null) {
|
||||||
password = getPassword();
|
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
|
@Override
|
||||||
|
@ -100,27 +104,8 @@ public class JSchConnection implements IRemoteConnection {
|
||||||
if (logging) {
|
if (logging) {
|
||||||
System.out.println("promptPassphrase:" + message); //$NON-NLS-1$
|
System.out.println("promptPassphrase:" + message); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
if (firstTry && !getPassphrase().equals("")) { //$NON-NLS-1$
|
if (firstTryPassphrase && !getPassphrase().equals("")) { //$NON-NLS-1$
|
||||||
firstTry = false;
|
firstTryPassphrase = 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;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (fAuthenticator != null) {
|
if (fAuthenticator != null) {
|
||||||
|
@ -129,9 +114,27 @@ public class JSchConnection implements IRemoteConnection {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
fAttributes.setAttribute(JSchConnectionAttributes.USERNAME_ATTR, auth.getUserName());
|
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
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue