Skip to content

Commit bd8606d

Browse files
committed
JNI/JSSE: Fix visibility and access modifiers found by SpotBugs
- Add missing final to WOLFSSL_LEFT_MOST_WILDCARD_ONLY constant - Update generated JNI header for WOLFSSL_LEFT_MOST_WILDCARD_ONLY - Make WolfSSLProvider.setDevId() static - Reduce visibility of WolfSSLCustomUser fields to package-protected - Make WolfSSLEngine debug flags private - Rename internal PascalCase methods to camelCase (LoadKeyAndCertChain, GetJavaHome, LoadKeyStoreFileByType, GetCtxAttributes)
1 parent dbcdcf3 commit bd8606d

12 files changed

Lines changed: 27 additions & 84 deletions

native/com_wolfssl_WolfSSL.h

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spotbugs-exclude.xml

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -299,19 +299,6 @@
299299
<Bug pattern="IS2_INCONSISTENT_SYNC"/>
300300
</Match>
301301

302-
<!--
303-
IS2_INCONSISTENT_SYNC: WolfSSLParameters objects are copied
304-
via copy() before being shared across threads. The copy()
305-
method is synchronized to protect the source object during
306-
copying. Individual getters/setters are intentionally not
307-
synchronized to match JDK SSLParameters behavior.
308-
-->
309-
<Match>
310-
<Class name=
311-
"com.wolfssl.provider.jsse.WolfSSLParameters"/>
312-
<Bug pattern="IS2_INCONSISTENT_SYNC"/>
313-
</Match>
314-
315302
<!--
316303
NM_METHOD_NAMING_CONVENTION: Public native JNI methods use
317304
PascalCase to match native wolfSSL C function naming.
@@ -461,50 +448,4 @@
461448
<Bug pattern="PA_PUBLIC_PRIMITIVE_ATTRIBUTE"/>
462449
</Match>
463450

464-
<!--
465-
AT_STALE_THREAD_WRITE_OF_PRIMITIVE: WolfSSLParameters
466-
objects are copied via copy() before being shared across
467-
threads, providing the thread-safety boundary. Matching
468-
the JDK SSLParameters pattern which also does not
469-
synchronize primitive getters/setters.
470-
471-
WolfSSLImplementSSLSession.side is set once during setup
472-
before the session is used across threads.
473-
-->
474-
<Match>
475-
<Class name=
476-
"com.wolfssl.provider.jsse.WolfSSLParameters"/>
477-
<Bug pattern="AT_STALE_THREAD_WRITE_OF_PRIMITIVE"/>
478-
</Match>
479-
<Match>
480-
<Class name=
481-
"com.wolfssl.provider.jsse.WolfSSLImplementSSLSession"/>
482-
<Field name="side"/>
483-
<Bug pattern="AT_STALE_THREAD_WRITE_OF_PRIMITIVE"/>
484-
</Match>
485-
486-
<!--
487-
RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE: Defensive null
488-
check on getSession() return value. The session could be
489-
null depending on engine state, keeping as defensive check.
490-
-->
491-
<Match>
492-
<Class name="com.wolfssl.provider.jsse.WolfSSLEngine"/>
493-
<Method name="cacheRequestedServerNamesFromNetData"/>
494-
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE"/>
495-
</Match>
496-
497-
<!--
498-
RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE: Defensive null check
499-
on certPem in catch block after constructor threw. Kept as
500-
defensive coding to free native resources if constructor
501-
behavior changes in the future.
502-
-->
503-
<Match>
504-
<Class name=
505-
"com.wolfssl.provider.jsse.WolfSSLTrustManager"/>
506-
<Method name="LoadAndroidSystemCertsManually"/>
507-
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"/>
508-
</Match>
509-
510451
</FindBugsFilter>

src/java/com/wolfssl/WolfSSL.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ public enum TLS_VERSION {
586586
/* ------------------------- Flag Values ---------------------------- */
587587
/** WolfSSLCertificate.checkHost() match only wildcards in left-most
588588
* position, used for LDAPS hostname verification. */
589-
public static int WOLFSSL_LEFT_MOST_WILDCARD_ONLY = 0x40;
589+
public static final int WOLFSSL_LEFT_MOST_WILDCARD_ONLY = 0x40;
590590

591591
/* ------------------------ Internal state -------------------------- */
592592

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private void createCtx() throws WolfSSLException {
8686
/* Allow ability for user to hard-code and override version, cipher
8787
* suite, and NO_* disable options. Otherwise just sets defaults
8888
* into ctxAttr. */
89-
WolfSSLCustomUser ctxAttr = WolfSSLCustomUser.GetCtxAttributes
89+
WolfSSLCustomUser ctxAttr = WolfSSLCustomUser.getCtxAttributes
9090
(this.currentVersion, ciphersIana);
9191

9292
/* Explicitly set SSLContext version if overridden by

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939
*/
4040
public class WolfSSLCustomUser {
4141
/** SSL/TLS version to be used with new SSLContext objects. */
42-
public TLS_VERSION version;
42+
TLS_VERSION version;
4343
/** String array of allowed cipher suites for new SSLContext objects */
44-
public String[] list;
44+
String[] list;
4545
/** Mask of options to set for the associated native WOLFSSL_CTX */
46-
public long noOptions;
46+
long noOptions;
4747

4848
/** Default WolfSSLCustomUser constructor */
4949
public WolfSSLCustomUser() { }
@@ -65,7 +65,7 @@ public WolfSSLCustomUser() { }
6565
* list needs to contain a subset of the default cipher
6666
* list. If it is null, default list is applied.
6767
*/
68-
public static WolfSSLCustomUser GetCtxAttributes(TLS_VERSION version,
68+
public static WolfSSLCustomUser getCtxAttributes(TLS_VERSION version,
6969
String[] list) {
7070

7171
WolfSSLCustomUser ctxAttr = new WolfSSLCustomUser();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ public class WolfSSLEngine extends SSLEngine {
167167
protected BiFunction<SSLEngine, List<String>, String> alpnSelector = null;
168168

169169
/** Turn on extra/verbose SSLEngine debug logging */
170-
public boolean extraDebugEnabled = false;
170+
private boolean extraDebugEnabled = false;
171171

172172
/** Turn on Send/Recv callback debug to print out bytes sent/received.
173173
* WARNING: enabling this will slow down sending and receiving data,
174174
* enough so that app may run into timeouts. Enable with caution. */
175-
public boolean ioDebugEnabled = false;
175+
private boolean ioDebugEnabled = false;
176176

177177
/**
178178
* Turns on additional debugging based on system properties set.
@@ -264,7 +264,7 @@ private synchronized void LoadCertAndKey() throws SSLException {
264264
}
265265

266266
try {
267-
this.engineHelper.LoadKeyAndCertChain(null, this);
267+
this.engineHelper.loadKeyAndCertChain(null, this);
268268
certKeyLoaded = true;
269269
} catch (CertificateEncodingException | IOException |
270270
WolfSSLException e) {
@@ -281,7 +281,7 @@ private synchronized void LoadCertAndKey() throws SSLException {
281281
*
282282
* This logic is not included directly in WolfSSLEngine constructors
283283
* to avoid possible 'this' escape before subclass is fully initialized
284-
* when using 'this' in LoadKeyAndCertChain().
284+
* when using 'this' in loadKeyAndCertChain().
285285
*
286286
* @throws SSLException if initialization fails
287287
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ else if (engine != null) {
329329
* @throws IOException on error concatenating certificate chain into
330330
* single byte array
331331
*/
332-
protected synchronized void LoadKeyAndCertChain(
332+
protected synchronized void loadKeyAndCertChain(
333333
Socket sock, SSLEngine engine)
334334
throws WolfSSLException, CertificateEncodingException, IOException {
335335

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ private KeyStore LoadKeyStoreFromSystemProperties(String requiredType)
106106
"KeyStore type from wolfjsse.keystore.type.required");
107107
}
108108

109-
sysStore = WolfSSLUtil.LoadKeyStoreFileByType(
109+
sysStore = WolfSSLUtil.loadKeyStoreFileByType(
110110
file, this.pswd, type);
111111
}
112112
else {
113113
/* Try with wolfJCE WKS type first, in case wolfCrypt
114114
* FIPS is being used */
115115
if (wksAvailable &&
116116
(requiredType == null || requiredType.equals("WKS"))) {
117-
sysStore = WolfSSLUtil.LoadKeyStoreFileByType(
117+
sysStore = WolfSSLUtil.loadKeyStoreFileByType(
118118
file, this.pswd, "WKS");
119119
}
120120

@@ -123,7 +123,7 @@ private KeyStore LoadKeyStoreFromSystemProperties(String requiredType)
123123
(requiredType == null || requiredType.equals("BKS"))) {
124124
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
125125
() -> "Detected Android VM, trying BKS KeyStore type");
126-
sysStore = WolfSSLUtil.LoadKeyStoreFileByType(
126+
sysStore = WolfSSLUtil.loadKeyStoreFileByType(
127127
file, this.pswd, "BKS");
128128
}
129129

@@ -133,7 +133,7 @@ private KeyStore LoadKeyStoreFromSystemProperties(String requiredType)
133133
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
134134
() -> "javax.net.ssl.keyStoreType system property " +
135135
"not set, trying type: JKS");
136-
sysStore = WolfSSLUtil.LoadKeyStoreFileByType(
136+
sysStore = WolfSSLUtil.loadKeyStoreFileByType(
137137
file, this.pswd, "JKS");
138138
}
139139
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public WolfSSLProvider() {
168168
* @throws WolfSSLException if error registering native crypto callback
169169
* function
170170
*/
171-
public void setDevId(int devId) throws WolfSSLException {
171+
public static void setDevId(int devId) throws WolfSSLException {
172172

173173
/* Store devId into static WolfSSL variable, used by
174174
* WolfSSLContext (SSLContext) */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,9 @@ private void checkAndInitSSLSocket() throws IOException {
543543
() -> "loading private key and cert chain");
544544

545545
if (this.socket != null) {
546-
EngineHelper.LoadKeyAndCertChain(this.socket, null);
546+
EngineHelper.loadKeyAndCertChain(this.socket, null);
547547
} else {
548-
EngineHelper.LoadKeyAndCertChain(this, null);
548+
EngineHelper.loadKeyAndCertChain(this, null);
549549
}
550550
} else {
551551
throw new WolfSSLException(

0 commit comments

Comments
 (0)