Skip to content

Commit b173f29

Browse files
committed
Infer fixes for WolfSSLEngineHelper
1 parent eaa6690 commit b173f29

1 file changed

Lines changed: 33 additions & 26 deletions

File tree

src/java/com/wolfssl/provider/jsse/WolfSSLEngineHelper.java

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ else if (engine != null) {
284284
* @throws IOException on error concatenating certificate chain into
285285
* single byte array
286286
*/
287-
protected void LoadKeyAndCertChain(Socket sock, SSLEngine engine)
287+
protected synchronized void LoadKeyAndCertChain(
288+
Socket sock, SSLEngine engine)
288289
throws WolfSSLException, CertificateEncodingException, IOException {
289290

290291
int ret;
@@ -388,7 +389,7 @@ protected void LoadKeyAndCertChain(Socket sock, SSLEngine engine)
388389
* @param hostname peer hostname String
389390
* @param port peer port number
390391
*/
391-
protected void setHostAndPort(String hostname, int port) {
392+
protected synchronized void setHostAndPort(String hostname, int port) {
392393

393394
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
394395
"entered setHostAndPort()");
@@ -403,7 +404,7 @@ protected void setHostAndPort(String hostname, int port) {
403404
*
404405
* @param peerAddr InetAddress of peer
405406
*/
406-
protected void setPeerAddress(InetAddress peerAddr) {
407+
protected synchronized void setPeerAddress(InetAddress peerAddr) {
407408

408409
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
409410
"entered setPeerAddress()");
@@ -416,7 +417,7 @@ protected void setPeerAddress(InetAddress peerAddr) {
416417
*
417418
* @return com.wolfssl.WolfSSLSession for this object
418419
*/
419-
protected WolfSSLSession getWolfSSLSession() {
420+
protected synchronized WolfSSLSession getWolfSSLSession() {
420421
return ssl;
421422
}
422423

@@ -425,7 +426,7 @@ protected WolfSSLSession getWolfSSLSession() {
425426
*
426427
* @return WolfSSLImplementSession for this object
427428
*/
428-
protected WolfSSLImplementSSLSession getSession() {
429+
protected synchronized WolfSSLImplementSSLSession getSession() {
429430

430431
if (this.session == null) {
431432
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
@@ -444,7 +445,7 @@ protected WolfSSLImplementSSLSession getSession() {
444445
*
445446
* @return String array of all supported cipher suites
446447
*/
447-
protected String[] getAllCiphers() {
448+
protected synchronized String[] getAllCiphers() {
448449
return WolfSSLUtil.sanitizeSuites(WolfSSL.getCiphersIana());
449450
}
450451

@@ -454,7 +455,7 @@ protected String[] getAllCiphers() {
454455
*
455456
* @return String array of all enabled cipher suites
456457
*/
457-
protected String[] getCiphers() {
458+
protected synchronized String[] getCiphers() {
458459
return WolfSSLUtil.sanitizeSuites(this.params.getCipherSuites());
459460
}
460461

@@ -469,7 +470,8 @@ protected String[] getCiphers() {
469470
* cipher suites, input array is null, or input array has length
470471
* zero
471472
*/
472-
protected void setCiphers(String[] suites) throws IllegalArgumentException {
473+
protected synchronized void setCiphers(String[] suites)
474+
throws IllegalArgumentException {
473475

474476
if (suites == null) {
475477
throw new IllegalArgumentException("input array is null");
@@ -501,7 +503,8 @@ protected void setCiphers(String[] suites) throws IllegalArgumentException {
501503
* @throws IllegalArgumentException if input array is null,
502504
* has length zero, or contains invalid/unsupported protocols
503505
*/
504-
protected void setProtocols(String[] p) throws IllegalArgumentException {
506+
protected synchronized void setProtocols(String[] p)
507+
throws IllegalArgumentException {
505508

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

@@ -539,7 +542,7 @@ protected String[] getProtocols() {
539542
*
540543
* @return String array of supported protocols
541544
*/
542-
protected String[] getAllProtocols() {
545+
protected synchronized String[] getAllProtocols() {
543546
return WolfSSLUtil.sanitizeProtocols(WolfSSL.getProtocols());
544547
}
545548

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

557560
if (this.ssl.handshakeDone()) {
@@ -574,7 +577,7 @@ protected void setUseClientMode(boolean mode)
574577
*
575578
* @return boolean value of clientMode set for this session
576579
*/
577-
protected boolean getUseClientMode() {
580+
protected synchronized boolean getUseClientMode() {
578581
return this.clientMode;
579582
}
580583

@@ -583,7 +586,7 @@ protected boolean getUseClientMode() {
583586
*
584587
* @param need boolean if session needs client authentication
585588
*/
586-
protected void setNeedClientAuth(boolean need) {
589+
protected synchronized void setNeedClientAuth(boolean need) {
587590
this.params.setNeedClientAuth(need);
588591
}
589592

@@ -592,7 +595,7 @@ protected void setNeedClientAuth(boolean need) {
592595
*
593596
* @return boolean value for needClientAuth
594597
*/
595-
protected boolean getNeedClientAuth() {
598+
protected synchronized boolean getNeedClientAuth() {
596599
return this.params.getNeedClientAuth();
597600
}
598601

@@ -601,7 +604,7 @@ protected boolean getNeedClientAuth() {
601604
*
602605
* @param want boolean value of wantClientAuth for this session
603606
*/
604-
protected void setWantClientAuth(boolean want) {
607+
protected synchronized void setWantClientAuth(boolean want) {
605608
this.params.setWantClientAuth(want);
606609
}
607610

@@ -610,7 +613,7 @@ protected void setWantClientAuth(boolean want) {
610613
*
611614
* @return boolean value for wantClientAuth
612615
*/
613-
protected boolean getWantClientAuth() {
616+
protected synchronized boolean getWantClientAuth() {
614617
return this.params.getWantClientAuth();
615618
}
616619

@@ -619,7 +622,7 @@ protected boolean getWantClientAuth() {
619622
*
620623
* @param flag boolean to set enable session creation
621624
*/
622-
protected void setEnableSessionCreation(boolean flag) {
625+
protected synchronized void setEnableSessionCreation(boolean flag) {
623626
this.sessionCreation = flag;
624627
}
625628

@@ -628,7 +631,7 @@ protected void setEnableSessionCreation(boolean flag) {
628631
*
629632
* @return boolean value for enableSessionCreation
630633
*/
631-
protected boolean getEnableSessionCreation() {
634+
protected synchronized boolean getEnableSessionCreation() {
632635
return this.sessionCreation;
633636
}
634637

@@ -637,7 +640,7 @@ protected boolean getEnableSessionCreation() {
637640
*
638641
* @param flag boolean to enable/disable session tickets
639642
*/
640-
protected void setUseSessionTickets(boolean flag) {
643+
protected synchronized void setUseSessionTickets(boolean flag) {
641644
this.params.setUseSessionTickets(flag);
642645
}
643646

@@ -646,7 +649,7 @@ protected void setUseSessionTickets(boolean flag) {
646649
*
647650
* @param alpnProtos encoded byte array of ALPN protocols
648651
*/
649-
protected void setAlpnProtocols(byte[] alpnProtos) {
652+
protected synchronized void setAlpnProtocols(byte[] alpnProtos) {
650653
this.params.setAlpnProtocols(alpnProtos);
651654
}
652655

@@ -658,7 +661,7 @@ protected void setAlpnProtocols(byte[] alpnProtos) {
658661
* @return encoded byte array for selected ALPN protocol or null if
659662
* handshake has not finished
660663
*/
661-
protected byte[] getAlpnSelectedProtocol() {
664+
protected synchronized byte[] getAlpnSelectedProtocol() {
662665
if (this.ssl.handshakeDone()) {
663666
return ssl.getAlpnSelected();
664667
}
@@ -672,7 +675,7 @@ protected byte[] getAlpnSelectedProtocol() {
672675
* if protocol is not available yet, or empty String if
673676
* ALPN will not be used for this connection.
674677
*/
675-
protected String getAlpnSelectedProtocolString() {
678+
protected synchronized String getAlpnSelectedProtocolString() {
676679
String proto = ssl.getAlpnSelectedString();
677680

678681
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
@@ -1133,7 +1136,9 @@ private void setLocalParams(SSLSocket socket, SSLEngine engine)
11331136
* @throws SSLHandshakeException session creation is not allowed
11341137
*
11351138
*/
1136-
protected void initHandshake(SSLSocket socket) throws SSLException {
1139+
protected synchronized void initHandshake(SSLSocket socket)
1140+
throws SSLException {
1141+
11371142
initHandshakeInternal(socket, null);
11381143
}
11391144

@@ -1152,7 +1157,9 @@ protected void initHandshake(SSLSocket socket) throws SSLException {
11521157
* @throws SSLHandshakeException session creation is not allowed
11531158
*
11541159
*/
1155-
protected void initHandshake(SSLEngine engine) throws SSLException {
1160+
protected synchronized void initHandshake(SSLEngine engine)
1161+
throws SSLException {
1162+
11561163
initHandshakeInternal(null, engine);
11571164
}
11581165

@@ -1235,7 +1242,7 @@ private void initHandshakeInternal(SSLSocket socket, SSLEngine engine)
12351242
* on native socket error
12361243
* @throws SocketTimeoutException if socket timed out
12371244
*/
1238-
protected int doHandshake(int isSSLEngine, int timeout)
1245+
protected synchronized int doHandshake(int isSSLEngine, int timeout)
12391246
throws SSLException, SocketTimeoutException {
12401247

12411248
int ret, err;

0 commit comments

Comments
 (0)