Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to banner #206

Merged
merged 13 commits into from
Oct 25, 2024
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml
nb-configuration.xml

#vscode
.vscode/
13 changes: 13 additions & 0 deletions src/com/trilead/ssh2/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.net.InetSocketAddress;
import java.net.SocketTimeoutException;
import java.security.SecureRandom;
import java.util.Collections;
import java.util.List;
import java.util.Vector;

/**
Expand Down Expand Up @@ -515,6 +517,17 @@ public synchronized boolean authenticateWithPublicKey(String user, File pemFile,

return authenticateWithPublicKey(user, cw.toCharArray(), password);
}
/**
* Method will return the banners provided by the server.
* {@link AuthenticationManager#getBanners()}
* @return a list of banner strings or empty if no banners is sent.
*/
public List<String> getBanners(){
if(am != null ){
return am.getBanners();
}
return Collections.emptyList();
}

/**
* Add a {@link ConnectionMonitor} to this connection. Can be invoked at any
Expand Down
17 changes: 15 additions & 2 deletions src/com/trilead/ssh2/auth/AuthenticationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Vector;
Expand All @@ -34,7 +35,7 @@ public class AuthenticationManager implements MessageHandler
Vector packets = new Vector();
boolean connectionClosed = false;

String banner;
List<String> banners = new ArrayList<>();

String[] remainingMethods = new String[0];
boolean isPartialSuccess = false;
Expand Down Expand Up @@ -104,9 +105,21 @@ byte[] getNextMessage() throws IOException

PacketUserauthBanner sb = new PacketUserauthBanner(msg, 0, msg.length);

banner = sb.getBanner();
banners.add(sb.getBanner());
}
}
/**
* This method contains the SSH_MSG_USERAUTH_BANNER messages
* sent by the server. Messages can be sent at any time before
* SSH protocol starts and the authentication is complete.
* The purpose of the message is to display info to the user
* before authentication starts.
* Note: If there are messages sent make sure authentication
* is complete before using this method.
*/
public List<String> getBanners(){
return banners;
}

public String[] getRemainingMethods(String user) throws IOException
{
Expand Down