Merge pull request #205 from sstefonic/handshakeFailureClose

Close socket if handshake fails
pull/201/head
Chris Conlon 2024-06-27 13:42:42 -06:00 committed by GitHub
commit a35247541e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 0 deletions

View File

@ -1297,6 +1297,18 @@ public class WolfSSLSocket extends SSLSocket {
/* Log error, but continue. Session returned will be empty */
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
"Handshake attempt failed in SSLSocket.getSession()");
/* close SSLSocket */
try {
close();
} catch (Exception ex) {
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
"close attempt failed in SSLSocket.getSession(): " + ex);
}
/* return invalid session object with cipher suite
* "SSL_NULL_WITH_NULL_NULL" */
return new WolfSSLImplementSSLSession(this.authStore);
}
return EngineHelper.getSession();
@ -1446,6 +1458,8 @@ public class WolfSSLSocket extends SSLSocket {
} catch (SocketTimeoutException e) {
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
"got socket timeout in doHandshake()");
/* close socket if the handshake is unsuccessful */
close();
throw e;
}
@ -1453,6 +1467,8 @@ public class WolfSSLSocket extends SSLSocket {
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() + ")");
}