Skip to content

Commit f85402f

Browse files
committed
wolfJSSE fixes for FIPS coverage and PR wolfSSL#334 feedback
1 parent bbb0153 commit f85402f

18 files changed

Lines changed: 1858 additions & 230 deletions

native/com_wolfssl_WolfSSLSession.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2761,11 +2761,11 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_sendHrrCookie
27612761
JNIEXPORT jlong JNICALL Java_com_wolfssl_WolfSSLSession_getDtlsMacDropCount
27622762
(JNIEnv* jenv, jobject jcl, jlong sslPtr)
27632763
{
2764+
word32 dropCount = 0;
2765+
27642766
(void)jenv;
27652767
(void)jcl;
27662768
(void)sslPtr;
2767-
2768-
word32 dropCount = 0;
27692769
#if defined(WOLFSSL_DTLS) && defined(WOLFSSL_DTLS_DROP_STATS)
27702770
int ret = 0;
27712771
WOLFSSL* ssl = (WOLFSSL*)(uintptr_t)sslPtr;
@@ -2782,11 +2782,11 @@ JNIEXPORT jlong JNICALL Java_com_wolfssl_WolfSSLSession_getDtlsMacDropCount
27822782
JNIEXPORT jlong JNICALL Java_com_wolfssl_WolfSSLSession_getDtlsReplayDropCount
27832783
(JNIEnv* jenv, jobject jcl, jlong sslPtr)
27842784
{
2785+
word32 dropCount = 0;
2786+
27852787
(void)jenv;
27862788
(void)jcl;
27872789
(void)sslPtr;
2788-
2789-
word32 dropCount = 0;
27902790
#if defined(WOLFSSL_DTLS) && defined(WOLFSSL_DTLS_DROP_STATS)
27912791
int ret = 0;
27922792
WOLFSSL* ssl = (WOLFSSL*)(uintptr_t)sslPtr;

src/java/com/wolfssl/WolfSSLCertManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ public synchronized int CertManagerLoadCAKeyStore(KeyStore ks)
179179
cert = (X509Certificate) ks.getCertificate(name);
180180
}
181181

182-
if (cert != null && cert.getBasicConstraints() >= 0) {
182+
if (cert != null && (cert.getBasicConstraints() >= 0 ||
183+
WolfSSL.trustPeerCertEnabled())) {
183184
ret = CertManagerLoadCABuffer(cert.getEncoded(),
184185
cert.getEncoded().length,
185186
WolfSSL.SSL_FILETYPE_ASN1);

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,9 @@ protected WolfSSLImplementSSLSession getSession(
331331
return null;
332332
}
333333

334-
/* Return new session if in server mode, or if host is null */
335-
if (!clientMode || host == null) {
334+
/* Unknown port (-1) is a valid SSLEngine host hint.
335+
* Skip cache keying. */
336+
if (!clientMode || host == null || port < 0) {
336337
return this.getSession(ssl, clientMode, host, port);
337338
}
338339

@@ -758,14 +759,24 @@ protected void updateTimeouts(int in, int side) {
758759
diff = (now - current.creation.getTime()) / 1000;
759760

760761
if (diff < 0) {
761-
/* session is from the future ... */ //@TODO
762+
/* session is from the future ... */ /* TODO */
762763

763764
}
764765

765-
if (in > 0 && diff > in) {
766+
if (in > 0 && diff >= in) {
767+
current.invalidate();
768+
}
769+
try {
770+
current.setNativeTimeout(in);
771+
} catch (IllegalStateException e) {
772+
/* Native WolfSSLSession has been freed,
773+
* invalidate this session entry */
774+
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
775+
() -> "Native session freed while updating " +
776+
"timeout, invalidating cache entry: " +
777+
e.getMessage());
766778
current.invalidate();
767779
}
768-
current.setNativeTimeout(in);
769780
}
770781
}
771782
}
@@ -803,4 +814,3 @@ protected synchronized void finalize() throws Throwable {
803814
super.finalize();
804815
}
805816
}
806-

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ protected SSLEngine engineCreateSSLEngine()
488488
try {
489489
return new WolfSSLEngine(this.ctx, this.authStore, this.params);
490490
} catch (WolfSSLException ex) {
491-
throw new IllegalStateException("Unable to create engine");
491+
throw new IllegalStateException("Unable to create engine", ex);
492492
}
493493
}
494494

@@ -516,7 +516,7 @@ protected SSLEngine engineCreateSSLEngine(String host, int port)
516516
return new WolfSSLEngine(this.ctx, this.authStore, this.params,
517517
host, port);
518518
} catch (WolfSSLException ex) {
519-
throw new IllegalStateException("Unable to create engine");
519+
throw new IllegalStateException("Unable to create engine", ex);
520520
}
521521
}
522522

0 commit comments

Comments
 (0)