Skip to content

Commit

Permalink
Infer fixes for WolfSSLEngineHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
cconlon committed Apr 5, 2024
1 parent eaa6690 commit b173f29
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions src/java/com/wolfssl/provider/jsse/WolfSSLEngineHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ else if (engine != null) {
* @throws IOException on error concatenating certificate chain into
* single byte array
*/
protected void LoadKeyAndCertChain(Socket sock, SSLEngine engine)
protected synchronized void LoadKeyAndCertChain(
Socket sock, SSLEngine engine)
throws WolfSSLException, CertificateEncodingException, IOException {

int ret;
Expand Down Expand Up @@ -388,7 +389,7 @@ protected void LoadKeyAndCertChain(Socket sock, SSLEngine engine)
* @param hostname peer hostname String
* @param port peer port number
*/
protected void setHostAndPort(String hostname, int port) {
protected synchronized void setHostAndPort(String hostname, int port) {

WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
"entered setHostAndPort()");
Expand All @@ -403,7 +404,7 @@ protected void setHostAndPort(String hostname, int port) {
*
* @param peerAddr InetAddress of peer
*/
protected void setPeerAddress(InetAddress peerAddr) {
protected synchronized void setPeerAddress(InetAddress peerAddr) {

WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
"entered setPeerAddress()");
Expand All @@ -416,7 +417,7 @@ protected void setPeerAddress(InetAddress peerAddr) {
*
* @return com.wolfssl.WolfSSLSession for this object
*/
protected WolfSSLSession getWolfSSLSession() {
protected synchronized WolfSSLSession getWolfSSLSession() {
return ssl;
}

Expand All @@ -425,7 +426,7 @@ protected WolfSSLSession getWolfSSLSession() {
*
* @return WolfSSLImplementSession for this object
*/
protected WolfSSLImplementSSLSession getSession() {
protected synchronized WolfSSLImplementSSLSession getSession() {

if (this.session == null) {
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
Expand All @@ -444,7 +445,7 @@ protected WolfSSLImplementSSLSession getSession() {
*
* @return String array of all supported cipher suites
*/
protected String[] getAllCiphers() {
protected synchronized String[] getAllCiphers() {
return WolfSSLUtil.sanitizeSuites(WolfSSL.getCiphersIana());
}

Expand All @@ -454,7 +455,7 @@ protected String[] getAllCiphers() {
*
* @return String array of all enabled cipher suites
*/
protected String[] getCiphers() {
protected synchronized String[] getCiphers() {
return WolfSSLUtil.sanitizeSuites(this.params.getCipherSuites());
}

Expand All @@ -469,7 +470,8 @@ protected String[] getCiphers() {
* cipher suites, input array is null, or input array has length
* zero
*/
protected void setCiphers(String[] suites) throws IllegalArgumentException {
protected synchronized void setCiphers(String[] suites)
throws IllegalArgumentException {

if (suites == null) {
throw new IllegalArgumentException("input array is null");
Expand Down Expand Up @@ -501,7 +503,8 @@ protected void setCiphers(String[] suites) throws IllegalArgumentException {
* @throws IllegalArgumentException if input array is null,
* has length zero, or contains invalid/unsupported protocols
*/
protected void setProtocols(String[] p) throws IllegalArgumentException {
protected synchronized void setProtocols(String[] p)
throws IllegalArgumentException {

if (p == null) {
throw new IllegalArgumentException("input array is null");
Expand All @@ -528,7 +531,7 @@ protected void setProtocols(String[] p) throws IllegalArgumentException {
*
* @return String array of enabled SSL/TLS protocols
*/
protected String[] getProtocols() {
protected synchronized String[] getProtocols() {
return WolfSSLUtil.sanitizeProtocols(this.params.getProtocols());
}

Expand All @@ -539,7 +542,7 @@ protected String[] getProtocols() {
*
* @return String array of supported protocols
*/
protected String[] getAllProtocols() {
protected synchronized String[] getAllProtocols() {
return WolfSSLUtil.sanitizeProtocols(WolfSSL.getProtocols());
}

Expand All @@ -551,7 +554,7 @@ protected String[] getAllProtocols() {
* @throws IllegalArgumentException if called after SSL/TLS handshake
* has been completed. Only allowed before.
*/
protected void setUseClientMode(boolean mode)
protected synchronized void setUseClientMode(boolean mode)
throws IllegalArgumentException {

if (this.ssl.handshakeDone()) {
Expand All @@ -574,7 +577,7 @@ protected void setUseClientMode(boolean mode)
*
* @return boolean value of clientMode set for this session
*/
protected boolean getUseClientMode() {
protected synchronized boolean getUseClientMode() {
return this.clientMode;
}

Expand All @@ -583,7 +586,7 @@ protected boolean getUseClientMode() {
*
* @param need boolean if session needs client authentication
*/
protected void setNeedClientAuth(boolean need) {
protected synchronized void setNeedClientAuth(boolean need) {
this.params.setNeedClientAuth(need);
}

Expand All @@ -592,7 +595,7 @@ protected void setNeedClientAuth(boolean need) {
*
* @return boolean value for needClientAuth
*/
protected boolean getNeedClientAuth() {
protected synchronized boolean getNeedClientAuth() {
return this.params.getNeedClientAuth();
}

Expand All @@ -601,7 +604,7 @@ protected boolean getNeedClientAuth() {
*
* @param want boolean value of wantClientAuth for this session
*/
protected void setWantClientAuth(boolean want) {
protected synchronized void setWantClientAuth(boolean want) {
this.params.setWantClientAuth(want);
}

Expand All @@ -610,7 +613,7 @@ protected void setWantClientAuth(boolean want) {
*
* @return boolean value for wantClientAuth
*/
protected boolean getWantClientAuth() {
protected synchronized boolean getWantClientAuth() {
return this.params.getWantClientAuth();
}

Expand All @@ -619,7 +622,7 @@ protected boolean getWantClientAuth() {
*
* @param flag boolean to set enable session creation
*/
protected void setEnableSessionCreation(boolean flag) {
protected synchronized void setEnableSessionCreation(boolean flag) {
this.sessionCreation = flag;
}

Expand All @@ -628,7 +631,7 @@ protected void setEnableSessionCreation(boolean flag) {
*
* @return boolean value for enableSessionCreation
*/
protected boolean getEnableSessionCreation() {
protected synchronized boolean getEnableSessionCreation() {
return this.sessionCreation;
}

Expand All @@ -637,7 +640,7 @@ protected boolean getEnableSessionCreation() {
*
* @param flag boolean to enable/disable session tickets
*/
protected void setUseSessionTickets(boolean flag) {
protected synchronized void setUseSessionTickets(boolean flag) {
this.params.setUseSessionTickets(flag);
}

Expand All @@ -646,7 +649,7 @@ protected void setUseSessionTickets(boolean flag) {
*
* @param alpnProtos encoded byte array of ALPN protocols
*/
protected void setAlpnProtocols(byte[] alpnProtos) {
protected synchronized void setAlpnProtocols(byte[] alpnProtos) {
this.params.setAlpnProtocols(alpnProtos);
}

Expand All @@ -658,7 +661,7 @@ protected void setAlpnProtocols(byte[] alpnProtos) {
* @return encoded byte array for selected ALPN protocol or null if
* handshake has not finished
*/
protected byte[] getAlpnSelectedProtocol() {
protected synchronized byte[] getAlpnSelectedProtocol() {
if (this.ssl.handshakeDone()) {
return ssl.getAlpnSelected();
}
Expand All @@ -672,7 +675,7 @@ protected byte[] getAlpnSelectedProtocol() {
* if protocol is not available yet, or empty String if
* ALPN will not be used for this connection.
*/
protected String getAlpnSelectedProtocolString() {
protected synchronized String getAlpnSelectedProtocolString() {
String proto = ssl.getAlpnSelectedString();

WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
Expand Down Expand Up @@ -1133,7 +1136,9 @@ private void setLocalParams(SSLSocket socket, SSLEngine engine)
* @throws SSLHandshakeException session creation is not allowed
*
*/
protected void initHandshake(SSLSocket socket) throws SSLException {
protected synchronized void initHandshake(SSLSocket socket)
throws SSLException {

initHandshakeInternal(socket, null);
}

Expand All @@ -1152,7 +1157,9 @@ protected void initHandshake(SSLSocket socket) throws SSLException {
* @throws SSLHandshakeException session creation is not allowed
*
*/
protected void initHandshake(SSLEngine engine) throws SSLException {
protected synchronized void initHandshake(SSLEngine engine)
throws SSLException {

initHandshakeInternal(null, engine);
}

Expand Down Expand Up @@ -1235,7 +1242,7 @@ private void initHandshakeInternal(SSLSocket socket, SSLEngine engine)
* on native socket error
* @throws SocketTimeoutException if socket timed out
*/
protected int doHandshake(int isSSLEngine, int timeout)
protected synchronized int doHandshake(int isSSLEngine, int timeout)
throws SSLException, SocketTimeoutException {

int ret, err;
Expand Down

0 comments on commit b173f29

Please sign in to comment.