Merge pull request #228 from cconlon/initSockFixes

JSSE: correct SSLSocket exception types, fix for setting fd
pull/230/head
JacobBarthelmeh 2024-11-01 10:54:22 -06:00 committed by GitHub
commit 30e40424a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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; protected volatile boolean connectionClosed = false;
/** Flag representing if I/O callbacks have been set */ /** Flag representing if I/O callbacks have been set */
private boolean ioCallbacksSet = false; private boolean ioCallbacksSet = false;
/** Flag representing if native fd has been set */
private boolean fdSet = false;
/* lock for handshakInitCalled and handshakeComplete */ /* lock for handshakInitCalled and handshakeComplete */
private final Object handshakeLock = new Object(); private final Object handshakeLock = new Object();
@ -502,23 +504,33 @@ public class WolfSSLSocket extends SSLSocket {
synchronized (initLock) { 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) { if (isInitialized) {
return; return;
} }
try { try {
/* Load private key and cert chain from WolfSSLAuthStore */ /* Load private key and cert chain from WolfSSLAuthStore */
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
"loading private key and cert chain");
if (this.socket != null) { if (this.socket != null) {
EngineHelper.LoadKeyAndCertChain(this.socket, null); EngineHelper.LoadKeyAndCertChain(this.socket, null);
} else { } else {
EngineHelper.LoadKeyAndCertChain(this, null); EngineHelper.LoadKeyAndCertChain(this, null);
} }
/* If underlying Socket connected, set fd */
if (isConnected()) {
setFd();
}
isInitialized = true; isInitialized = true;
} catch (WolfSSLException | CertificateEncodingException | } catch (WolfSSLException | CertificateEncodingException |
@ -610,6 +622,9 @@ public class WolfSSLSocket extends SSLSocket {
"registered Socket(this.socket) with native wolfSSL"); "registered Socket(this.socket) with native wolfSSL");
} }
} }
/* Mark fd set */
this.fdSet = true;
} }
} }
@ -1715,7 +1730,7 @@ public class WolfSSLSocket extends SSLSocket {
checkAndInitSSLSocket(); checkAndInitSSLSocket();
if (!this.isConnected()) { if (!this.isConnected()) {
throw new IOException("Socket is not connected"); throw new SocketException("Socket is not connected");
} }
if (this.isClosed()) { if (this.isClosed()) {
@ -1747,7 +1762,7 @@ public class WolfSSLSocket extends SSLSocket {
checkAndInitSSLSocket(); checkAndInitSSLSocket();
if (!this.isConnected()) { if (!this.isConnected()) {
throw new IOException("Socket is not connected"); throw new SocketException("Socket is not connected");
} }
if (this.isClosed()) { if (this.isClosed()) {