Skip to content

Commit db577ac

Browse files
authored
Merge pull request #334 from JeremiahM37/testing-fixes
Netty, OkHTTP, Springboot test fixes.
2 parents f23ae91 + 71d3182 commit db577ac

19 files changed

Lines changed: 1857 additions & 266 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: 25 additions & 9 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

@@ -693,9 +694,15 @@ protected int addSession(WolfSSLImplementSSLSession session) {
693694
}
694695

695696
/**
696-
* Internal function to return a list of all session ID's
697+
* Internal function to return a list of valid session IDs.
698+
*
699+
* Expired sessions should already have been invalidated before this call
700+
* via updateTimeouts(), but callers may also invalidate sessions for
701+
* other reasons. Filter validity here so callers can avoid an extra
702+
* per-ID lookup.
703+
*
697704
* @param side server or client side to get list of ID's from
698-
* @return enumerated session IDs
705+
* @return enumerated valid session IDs
699706
*/
700707
protected Enumeration<byte[]> getAllIDs(int side) {
701708
List<byte[]> ret = new ArrayList<>();
@@ -704,7 +711,7 @@ protected Enumeration<byte[]> getAllIDs(int side) {
704711
for (Object obj : store.values()) {
705712
WolfSSLImplementSSLSession current =
706713
(WolfSSLImplementSSLSession)obj;
707-
if (current.getSide() == side) {
714+
if (current.getSide() == side && current.isValid()) {
708715
ret.add(current.getId());
709716
}
710717
}
@@ -758,14 +765,24 @@ protected void updateTimeouts(int in, int side) {
758765
diff = (now - current.creation.getTime()) / 1000;
759766

760767
if (diff < 0) {
761-
/* session is from the future ... */ //@TODO
768+
/* session is from the future ... */ /* TODO */
762769

763770
}
764771

765-
if (in > 0 && diff > in) {
772+
if (in > 0 && diff >= in) {
773+
current.invalidate();
774+
}
775+
try {
776+
current.setNativeTimeout(in);
777+
} catch (IllegalStateException e) {
778+
/* Native WolfSSLSession has been freed,
779+
* invalidate this session entry */
780+
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
781+
() -> "Native session freed while updating " +
782+
"timeout, invalidating cache entry: " +
783+
e.getMessage());
766784
current.invalidate();
767785
}
768-
current.setNativeTimeout(in);
769786
}
770787
}
771788
}
@@ -803,4 +820,3 @@ protected synchronized void finalize() throws Throwable {
803820
super.finalize();
804821
}
805822
}
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)