Skip to content

Commit

Permalink
Fix NPE in AuthenticationProtocolClient with more agressive synchroni…
Browse files Browse the repository at this point in the history
…zation.

Moved isStopped in callback session to prevent retry wait if client has been stopped prior.
  • Loading branch information
ludup committed Oct 17, 2024
1 parent 28ed204 commit 5a240a7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ public void connect() throws IOException, SshException {
future = app.getSshEngine().connect(
hostname,
port,
createContext(config));
createContext(config),
30000L);

future.waitFor(30000L);
if(future.isDone() && future.isSuccess()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ public boolean processMessage(byte[] msg) throws IOException, SshException {
ByteArrayReader bar = new ByteArrayReader(msg);

try {

ClientAuthenticator currentAuthenticator;
synchronized (this) {
currentAuthenticator = this.currentAuthenticator;
}

/**
* Try the authenticator first. It may want to handle
Expand Down Expand Up @@ -149,14 +144,17 @@ public boolean processMessage(byte[] msg) throws IOException, SshException {
transport.setActiveService(con);
con.start();

synchronized(currentAuthenticator) {

completedAuthentications.add(currentAuthenticator.getName());
completedAuthentications.add(currentAuthenticator.getName());

if(currentAuthenticator.getName().equals("none")) {
transport.getConnectFuture().connected(transport, transport.getConnection());
}

if(currentAuthenticator.getName().equals("none")) {
transport.getConnectFuture().connected(transport, transport.getConnection());
}

currentAuthenticator.success();
currentAuthenticator.success();

}


EventServiceImplementation
Expand Down Expand Up @@ -195,26 +193,31 @@ public boolean processMessage(byte[] msg) throws IOException, SshException {
while(t.hasMoreTokens()) {
supportedAuths.add(t.nextToken());
}

if(currentAuthenticator.getName().equals("none")) {
transport.getConnectFuture().connected(transport, transport.getConnection());
}

if(partial) {
completedAuthentications.add(currentAuthenticator.getName());
currentAuthenticator.success(true, auths.split(","));
} else {
currentAuthenticator.failure();
}

if(!doNextAuthentication()) {
transport.addTask(ExecutorOperationSupport.EVENTS, new ConnectionTaskWrapper(transport.getConnection(), new Runnable() {
public void run() {
for (ClientStateListener stateListener : context.getStateListeners()) {
stateListener.authenticate(AuthenticationProtocolClient.this, transport.getConnection(), supportedAuths, partial);
synchronized(currentAuthenticator) {

if(currentAuthenticator.getName().equals("none")) {
transport.getConnectFuture().connected(transport, transport.getConnection());
}

if(partial) {
completedAuthentications.add(currentAuthenticator.getName());
currentAuthenticator.success(true, auths.split(","));
} else {
currentAuthenticator.failure();
}


if(!doNextAuthentication()) {
transport.addTask(ExecutorOperationSupport.EVENTS, new ConnectionTaskWrapper(transport.getConnection(), new Runnable() {
public void run() {
for (ClientStateListener stateListener : context.getStateListeners()) {
stateListener.authenticate(AuthenticationProtocolClient.this, transport.getConnection(), supportedAuths, partial);
}
}
}
}));
}));
}

}

return true;
Expand Down

0 comments on commit 5a240a7

Please sign in to comment.