Skip to content

Commit

Permalink
[CONJ-1021] GSSAPI authentication might result in connection reset
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Nov 2, 2022
1 parent d5e44be commit 7da254a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,21 @@ public void authenticate(

byte[] inToken = new byte[0];
byte[] outToken;
while (!context.isEstablished()) {

while (true) {
outToken = context.initSecContext(inToken, 0, inToken.length);

// Send a token to the peer if one was generated by acceptSecContext
if (outToken != null) {
out.writeBytes(outToken);
out.flush();
}
if (!context.isEstablished()) {
ReadableByteBuf buf = in.readPacket(true);
inToken = new byte[buf.readableBytes()];
buf.readBytes(inToken);
if (context.isEstablished()) {
break;
}
ReadableByteBuf buf = in.readPacket(true);
inToken = new byte[buf.readableBytes()];
buf.readBytes(inToken);
}

} catch (GSSException le) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,24 @@ public void authenticate(

// Step 1: send token to server
byte[] tokenForTheServerOnTheClient = clientContext.getToken();
out.writeBytes(tokenForTheServerOnTheClient);
out.flush();
if (tokenForTheServerOnTheClient != null && tokenForTheServerOnTheClient.length > 0) {
out.writeBytes(tokenForTheServerOnTheClient);
out.flush();
}
if (!clientContext.isContinue()) {
break;
}

// Step 2: read server response token
if (clientContext.isContinue()) {
ReadableByteBuf buf = in.readPacket(true);
byte[] tokenForTheClientOnTheServer = new byte[buf.readableBytes()];
buf.readBytes(tokenForTheClientOnTheServer);
Sspi.SecBufferDesc continueToken =
new SspiUtil.ManagedSecBufferDesc(Sspi.SECBUFFER_TOKEN, tokenForTheClientOnTheServer);
clientContext.initialize(clientContext.getHandle(), continueToken, servicePrincipalName);
}
ReadableByteBuf buf = in.readPacket(true);
byte[] tokenForTheClientOnTheServer = new byte[buf.readableBytes()];
buf.readBytes(tokenForTheClientOnTheServer);
Sspi.SecBufferDesc continueToken =
new SspiUtil.ManagedSecBufferDesc(Sspi.SECBUFFER_TOKEN, tokenForTheClientOnTheServer);
clientContext.initialize(clientContext.getHandle(), continueToken, servicePrincipalName);


} while (clientContext.isContinue());
} while (true);

clientContext.dispose();
}
Expand Down

0 comments on commit 7da254a

Please sign in to comment.