Skip to content

Commit

Permalink
JSSE: add debug and close Socket if doHandshake() throws SSLException…
Browse files Browse the repository at this point in the history
… in startHandshake()
  • Loading branch information
cconlon committed Nov 18, 2024
1 parent f718187 commit 59c30d3
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/java/com/wolfssl/provider/jsse/WolfSSLSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,8 @@ public synchronized void removeHandshakeCompletedListener(
@Override
public synchronized void startHandshake() throws IOException {
int ret;
int err = 0;
String errStr = "";

WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
"entered startHandshake(), trying to get handshakeLock");
Expand Down Expand Up @@ -1506,19 +1508,25 @@ public synchronized void startHandshake() throws IOException {

try {
ret = EngineHelper.doHandshake(0, this.getSoTimeout());
err = ssl.getError(ret);
errStr = WolfSSL.getErrorString(err);

/* close socket if the handshake is unsuccessful */
} catch (SocketTimeoutException e) {
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
"got socket timeout in doHandshake()");
/* close socket if the handshake is unsuccessful */
close();
throw e;

} catch (SSLException e) {
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
"native handshake failed in doHandshake(): error code: " +
err + ", TID " + Thread.currentThread().getId() + ")");
close();
throw e;
}

if (ret != WolfSSL.SSL_SUCCESS) {
int err = ssl.getError(ret);
String errStr = WolfSSL.getErrorString(err);

/* close socket if the handshake is unsuccessful */
close();
throw new SSLHandshakeException(errStr + " (error code: " +
err + ", TID " + Thread.currentThread().getId() + ")");
Expand Down

0 comments on commit 59c30d3

Please sign in to comment.