JSSE: correct IOException to SocketException, fix for setting fd once socket is connected

pull/228/head
Chris Conlon 2024-10-30 17:25:33 -06:00
parent 14685a6634
commit d8c18c5f5b
1 changed files with 22 additions and 7 deletions

View File

@ -91,6 +91,8 @@ public class WolfSSLSocket extends SSLSocket {
protected volatile boolean connectionClosed = false;
/** Flag representing if I/O callbacks have been set */
private boolean ioCallbacksSet = false;
/** Flag representing if native fd has been set */
private boolean fdSet = false;
/* lock for handshakInitCalled and handshakeComplete */
private final Object handshakeLock = new Object();
@ -502,23 +504,33 @@ public class WolfSSLSocket extends SSLSocket {
synchronized (initLock) {
/* If underlying Socket connected, set fd. Check before
* initialized flag, since we may have already initialized
* certs/keys but not fd in previous call */
if (!this.fdSet && isConnected()) {
try {
setFd();
} catch (WolfSSLException e) {
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
"Failed to set native fd, may try again later");
}
}
if (isInitialized) {
return;
}
try {
/* Load private key and cert chain from WolfSSLAuthStore */
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
"loading private key and cert chain");
if (this.socket != null) {
EngineHelper.LoadKeyAndCertChain(this.socket, null);
} else {
EngineHelper.LoadKeyAndCertChain(this, null);
}
/* If underlying Socket connected, set fd */
if (isConnected()) {
setFd();
}
isInitialized = true;
} catch (WolfSSLException | CertificateEncodingException |
@ -610,6 +622,9 @@ public class WolfSSLSocket extends SSLSocket {
"registered Socket(this.socket) with native wolfSSL");
}
}
/* Mark fd set */
this.fdSet = true;
}
}
@ -1715,7 +1730,7 @@ public class WolfSSLSocket extends SSLSocket {
checkAndInitSSLSocket();
if (!this.isConnected()) {
throw new IOException("Socket is not connected");
throw new SocketException("Socket is not connected");
}
if (this.isClosed()) {
@ -1747,7 +1762,7 @@ public class WolfSSLSocket extends SSLSocket {
checkAndInitSSLSocket();
if (!this.isConnected()) {
throw new IOException("Socket is not connected");
throw new SocketException("Socket is not connected");
}
if (this.isClosed()) {