Skip to content

Commit

Permalink
Access to banner (#206)
Browse files Browse the repository at this point in the history
* Update TimeoutService.java

interrupt hanging timeoutservice threads

* Update TimeoutService.java

* Update TimeoutService.java

* Update Connection.java

* Update Connection.java

* Update TimeoutService.java

* Update TimeoutService.java

* Update Connection.java

* JENKINS-74733: Not possible to access banner content

* JENKINS-74733: Not possible to access banner content

---------

Co-authored-by: mpet <mikael.petterson@ericsson.com>
  • Loading branch information
mpet and eraonel authored Oct 25, 2024
1 parent 418c3a4 commit fcfe746
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
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

0 comments on commit fcfe746

Please sign in to comment.