From d5c181e0c24b170ed0851f536da630aa71efa3c4 Mon Sep 17 00:00:00 2001 From: Chris Conlon Date: Thu, 23 Jan 2025 14:52:44 -0700 Subject: [PATCH 1/4] JNI/JSSE: bump version to 1.15 --- README.md | 2 +- build.xml | 2 +- pom.xml | 2 +- src/java/com/wolfssl/provider/jsse/WolfSSLProvider.java | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d47efc42..1adb3b83 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,7 @@ an application can include this as a dependency in the application's com.wolfssl wolfssl-jsse - 1.14.0-SNAPSHOT + 1.15.0-SNAPSHOT ... diff --git a/build.xml b/build.xml index 53fa1eb2..9a1bbf7d 100644 --- a/build.xml +++ b/build.xml @@ -14,7 +14,7 @@ - + diff --git a/pom.xml b/pom.xml index afb25b5c..4cd7626c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.wolfssl wolfssl-jsse - 1.14.0-SNAPSHOT + 1.15.0-SNAPSHOT jar wolfssl-jsse https://www.wolfssl.com diff --git a/src/java/com/wolfssl/provider/jsse/WolfSSLProvider.java b/src/java/com/wolfssl/provider/jsse/WolfSSLProvider.java index 30f79bc1..76fff4b4 100644 --- a/src/java/com/wolfssl/provider/jsse/WolfSSLProvider.java +++ b/src/java/com/wolfssl/provider/jsse/WolfSSLProvider.java @@ -74,8 +74,8 @@ public void errorCallback(int ok, int err, String hash) { * wolfSSL JSSE Provider class */ public WolfSSLProvider() { - super("wolfJSSE", 1.14, "wolfSSL JSSE Provider"); - //super("wolfJSSE", "1.14", "wolfSSL JSSE Provider"); + super("wolfJSSE", 1.15, "wolfSSL JSSE Provider"); + //super("wolfJSSE", "1.15", "wolfSSL JSSE Provider"); /* load native wolfSSLJNI library */ WolfSSL.loadLibrary(); From 4b00da2c7bf4f07071d05c85ca09b997925f80cc Mon Sep 17 00:00:00 2001 From: Chris Conlon Date: Thu, 23 Jan 2025 16:15:58 -0700 Subject: [PATCH 2/4] JNI: fix Facebook Infer script exit code, and reported thread safety violations / potential deadlock issues --- scripts/infer.sh | 8 +- src/java/com/wolfssl/WolfSSLCertRequest.java | 81 ++++++++----- src/java/com/wolfssl/WolfSSLCertificate.java | 120 ++++++++++++------- src/java/com/wolfssl/WolfSSLSession.java | 74 ++++++------ 4 files changed, 170 insertions(+), 113 deletions(-) diff --git a/scripts/infer.sh b/scripts/infer.sh index c11057fd..c7f3c3d6 100755 --- a/scripts/infer.sh +++ b/scripts/infer.sh @@ -39,6 +39,7 @@ infer --fail-on-issue run -- javac \ src/java/com/wolfssl/WolfSSLCertRequest.java \ src/java/com/wolfssl/WolfSSLCertificate.java \ src/java/com/wolfssl/WolfSSLContext.java \ + src/java/com/wolfssl/WolfSSLDebug.java \ src/java/com/wolfssl/WolfSSLDecryptVerifyCallback.java \ src/java/com/wolfssl/WolfSSLEccSharedSecretCallback.java \ src/java/com/wolfssl/WolfSSLEccSignCallback.java \ @@ -52,6 +53,7 @@ infer --fail-on-issue run -- javac \ src/java/com/wolfssl/WolfSSLLoggingCallback.java \ src/java/com/wolfssl/WolfSSLMacEncryptCallback.java \ src/java/com/wolfssl/WolfSSLMissingCRLCallback.java \ + src/java/com/wolfssl/WolfSSLNativeLoggingCallback.java \ src/java/com/wolfssl/WolfSSLPskClientCallback.java \ src/java/com/wolfssl/WolfSSLPskServerCallback.java \ src/java/com/wolfssl/WolfSSLRsaDecCallback.java \ @@ -69,7 +71,6 @@ infer --fail-on-issue run -- javac \ src/java/com/wolfssl/provider/jsse/WolfSSLAuthStore.java \ src/java/com/wolfssl/provider/jsse/WolfSSLContext.java \ src/java/com/wolfssl/provider/jsse/WolfSSLCustomUser.java \ - src/java/com/wolfssl/provider/jsse/WolfSSLDebug.java \ src/java/com/wolfssl/provider/jsse/WolfSSLEngine.java \ src/java/com/wolfssl/provider/jsse/WolfSSLEngineHelper.java \ src/java/com/wolfssl/provider/jsse/WolfSSLGenericHostName.java \ @@ -77,7 +78,6 @@ infer --fail-on-issue run -- javac \ src/java/com/wolfssl/provider/jsse/WolfSSLInternalVerifyCb.java \ src/java/com/wolfssl/provider/jsse/WolfSSLKeyManager.java \ src/java/com/wolfssl/provider/jsse/WolfSSLKeyX509.java \ - src/java/com/wolfssl/provider/jsse/WolfSSLNativeLoggingCallback.java \ src/java/com/wolfssl/provider/jsse/WolfSSLParametersHelper.java \ src/java/com/wolfssl/provider/jsse/WolfSSLParameters.java \ src/java/com/wolfssl/provider/jsse/WolfSSLProvider.java \ @@ -104,8 +104,10 @@ if [ "$RETVAL" == '0' ] && [ "$KEEP" == 'no' ]; then rm -r ./infer-out fi -if [ "$RETVAL" == '2' ]; then +if [ "$RETVAL" == '1' ] || [ "$RETVAL" == '2' ]; then # GitHub Actions expects return of 1 to mark step as failure exit 1 fi +exit 0 + diff --git a/src/java/com/wolfssl/WolfSSLCertRequest.java b/src/java/com/wolfssl/WolfSSLCertRequest.java index 6cc6de23..9c453ef8 100644 --- a/src/java/com/wolfssl/WolfSSLCertRequest.java +++ b/src/java/com/wolfssl/WolfSSLCertRequest.java @@ -172,9 +172,11 @@ public void addAttribute(int nid, byte[] value) confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509ReqPtr, - "entered addAttribute(nid: " + nid + ", byte[])"); + synchronized (x509ReqLock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509ReqPtr, + "entered addAttribute(nid: " + nid + ", byte[])"); + } if (nid != WolfSSL.NID_pkcs9_challengePassword && nid != WolfSSL.NID_serialNumber && @@ -262,9 +264,11 @@ public void setPublicKey(String filePath, int keyType, int format) confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509ReqPtr, "entered setPublicKey(" + - filePath + ", type: " + keyType + ", format: " + format + ")"); + synchronized (x509ReqLock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509ReqPtr, "entered setPublicKey(" + + filePath + ", type: " + keyType + ", format: " + format + ")"); + } if (filePath == null || filePath.isEmpty()) { throw new WolfSSLException("File path is null or empty"); @@ -309,10 +313,12 @@ public void setPublicKey(byte[] key, int keyType, int format) confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509ReqPtr, - "entered setPublicKey(byte[], type: " + keyType + ", format: " + - format + ")"); + synchronized (x509ReqLock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509ReqPtr, + "entered setPublicKey(byte[], type: " + keyType + ", format: " + + format + ")"); + } if (key == null || key.length == 0) { throw new WolfSSLException("Key array is null or empty"); @@ -366,9 +372,11 @@ public void setPublicKey(PublicKey key) confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509ReqPtr, - "entered setPublicKey(" + key + ")"); + synchronized (x509ReqLock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509ReqPtr, + "entered setPublicKey(" + key + ")"); + } if (key instanceof RSAPublicKey) { keyType = WolfSSL.RSAk; @@ -442,9 +450,12 @@ public void addExtension(int nid, String value, boolean isCritical) confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509ReqPtr, "entered addExtension(nid: " + - nid + ", value: " + value + ", isCritical: " + isCritical + ")"); + synchronized (x509ReqLock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509ReqPtr, + "entered addExtension(nid: " + nid + ", value: " + value + + ", isCritical: " + isCritical + ")"); + } if (nid != WolfSSL.NID_key_usage && nid != WolfSSL.NID_subject_alt_name && @@ -502,9 +513,12 @@ public void addExtension(int nid, boolean value, boolean isCritical) confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509ReqPtr, "entered addExtension(nid: " + - nid + ", value: " + value + ", isCritical: " + isCritical + ")"); + synchronized (x509ReqLock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509ReqPtr, + "entered addExtension(nid: " + nid + ", value: " + value + + ", isCritical: " + isCritical + ")"); + } if (nid != WolfSSL.NID_basic_constraints) { throw new WolfSSLException( @@ -553,10 +567,12 @@ public void signRequest(String filePath, int keyType, int format, confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509ReqPtr, "entered signRequest(" + - filePath + ", keyType: " + keyType + ", format: " + format + - ", digestAlg: " + digestAlg + ")"); + synchronized (x509ReqLock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509ReqPtr, "entered signRequest(" + + filePath + ", keyType: " + keyType + ", format: " + format + + ", digestAlg: " + digestAlg + ")"); + } if (filePath == null || filePath.isEmpty()) { throw new WolfSSLException("File path is null or empty"); @@ -604,10 +620,12 @@ public void signRequest(byte[] key, int keyType, int format, confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509ReqPtr, - "entered signRequest(byte[], keyType: " + keyType + ", format: " + - format + ", digestAlg: " + digestAlg + ")"); + synchronized (x509ReqLock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509ReqPtr, + "entered signRequest(byte[], keyType: " + keyType + + ", format: " + format + ", digestAlg: " + digestAlg + ")"); + } if (key == null || key.length == 0) { throw new WolfSSLException("Key array is null or empty"); @@ -665,9 +683,12 @@ public void signRequest(PrivateKey key, String digestAlg) confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509ReqPtr, "entered signRequest(key: " + - key + ", digestAlg: " + digestAlg + ")"); + synchronized (x509ReqLock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509ReqPtr, + "entered signRequest(key: " + key + ", digestAlg: " + + digestAlg + ")"); + } if (key == null) { throw new WolfSSLException("Key object is null"); diff --git a/src/java/com/wolfssl/WolfSSLCertificate.java b/src/java/com/wolfssl/WolfSSLCertificate.java index bf8d04d4..3daaaf55 100644 --- a/src/java/com/wolfssl/WolfSSLCertificate.java +++ b/src/java/com/wolfssl/WolfSSLCertificate.java @@ -462,9 +462,11 @@ public void setIssuerName(WolfSSLCertificate cert) confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509Ptr, "entering setIssuerName(" + - cert + ")"); + synchronized (x509Lock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509Ptr, "entering setIssuerName(" + + cert + ")"); + } x509NamePtr = X509_get_issuer_name_ptr(cert.getX509Ptr()); if (x509NamePtr == 0) { @@ -505,9 +507,11 @@ public void setIssuerName(X509Certificate cert) confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509Ptr, "entering setIssuerName(" + - cert + ")"); + synchronized (x509Lock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509Ptr, "entering setIssuerName(" + + cert + ")"); + } /* Get DER encoding of certificate */ certDer = cert.getEncoded(); @@ -547,9 +551,12 @@ public void setPublicKey(String filePath, int keyType, int format) confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509Ptr, "entering setPublicKey(" + - filePath + ", keyType: " + keyType + ", format: " + format + ")"); + synchronized (x509Lock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509Ptr, "entering setPublicKey(" + + filePath + ", keyType: " + keyType + ", format: " + + format + ")"); + } if (filePath == null || filePath.isEmpty()) { throw new WolfSSLException("File path is null or empty"); @@ -594,10 +601,12 @@ public void setPublicKey(byte[] key, int keyType, int format) confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509Ptr, - "entering setPublicKey(byte[], keyType: " + - keyType + ", format: " + format + ")"); + synchronized (x509Lock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509Ptr, + "entering setPublicKey(byte[], keyType: " + + keyType + ", format: " + format + ")"); + } if (key == null || key.length == 0) { throw new WolfSSLException("Key array is null or empty"); @@ -651,9 +660,11 @@ public void setPublicKey(PublicKey key) confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509Ptr, "entering setPublicKey(" + - key + ")"); + synchronized (x509Lock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509Ptr, "entering setPublicKey(" + + key + ")"); + } if (key instanceof RSAPublicKey) { keyType = WolfSSL.RSAk; @@ -693,9 +704,11 @@ public void setSerialNumber(BigInteger serial) confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509Ptr, "entering setSerialNumber(" + - serial + ")"); + synchronized (x509Lock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509Ptr, "entering setSerialNumber(" + + serial + ")"); + } if (serial == null) { throw new WolfSSLException("Input BigInteger is null"); @@ -734,11 +747,11 @@ public void setNotBefore(Date notBefore) confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509Ptr, "entering setNotBefore(" + - notBefore + ")"); - synchronized (x509Lock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509Ptr, "entering setNotBefore(" + + notBefore + ")"); + ret = X509_set_notBefore(this.x509Ptr, notBefore.getTime() / 1000); } @@ -765,11 +778,11 @@ public void setNotAfter(Date notAfter) confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509Ptr, "entering setNotAfter(" + - notAfter + ")"); - synchronized (x509Lock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509Ptr, "entering setNotAfter(" + + notAfter + ")"); + ret = X509_set_notAfter(this.x509Ptr, notAfter.getTime() / 1000); } @@ -866,9 +879,12 @@ public void addExtension(int nid, String value, boolean isCritical) confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509Ptr, "entering addExtension(nid: " + - nid + ", value: " + value + ", isCritical: " + isCritical + ")"); + synchronized (x509Lock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509Ptr, + "entering addExtension(nid: " + nid + ", value: " + value + + ", isCritical: " + isCritical + ")"); + } if (nid != WolfSSL.NID_key_usage && nid != WolfSSL.NID_subject_alt_name && @@ -926,9 +942,12 @@ public void addExtension(int nid, boolean value, boolean isCritical) confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509Ptr, "entering addExtension(nid: " + - nid + ", value: " + value + ", isCritical: " + isCritical + ")"); + synchronized (x509Lock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509Ptr, + "entering addExtension(nid: " + nid + ", value: " + value + + ", isCritical: " + isCritical + ")"); + } if (nid != WolfSSL.NID_basic_constraints) { throw new WolfSSLException( @@ -977,10 +996,12 @@ public void signCert(String filePath, int keyType, int format, confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509Ptr, "entering signCert(" + filePath + - ", keyType: " + keyType + ", format: " + format + ", digestAlg: " + - digestAlg + ")"); + synchronized (x509Lock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509Ptr, "entering signCert(" + + filePath + ", keyType: " + keyType + ", format: " + format + + ", digestAlg: " + digestAlg + ")"); + } if (filePath == null || filePath.isEmpty()) { throw new WolfSSLException("File path is null or empty"); @@ -1028,10 +1049,12 @@ public void signCert(byte[] key, int keyType, int format, confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509Ptr, - "entering signCert(byte[], keyType: " + keyType + ", format: " + - format + ", digestAlg: " + digestAlg + ")"); + synchronized (x509Lock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509Ptr, + "entering signCert(byte[], keyType: " + keyType + ", format: " + + format + ", digestAlg: " + digestAlg + ")"); + } if (key == null || key.length == 0) { throw new WolfSSLException("Key array is null or empty"); @@ -1088,9 +1111,11 @@ public void signCert(PrivateKey key, String digestAlg) confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509Ptr, "entering signCert(" + key + - ", digestAlg: " + digestAlg + ")"); + synchronized (x509Lock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509Ptr, "entering signCert(" + key + + ", digestAlg: " + digestAlg + ")"); + } if (key == null) { throw new WolfSSLException("Key object is null"); @@ -1697,8 +1722,11 @@ public X509Certificate getX509Certificate() confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.x509Ptr, "entering getX509Certificate()"); + synchronized (x509Lock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.x509Ptr, + "entering getX509Certificate()"); + } try { in = new ByteArrayInputStream(this.getDer()); diff --git a/src/java/com/wolfssl/WolfSSLSession.java b/src/java/com/wolfssl/WolfSSLSession.java index e34891ec..da2f8db1 100644 --- a/src/java/com/wolfssl/WolfSSLSession.java +++ b/src/java/com/wolfssl/WolfSSLSession.java @@ -1349,18 +1349,18 @@ public int accept(int timeout) * @see WolfSSLContext#newContext(long) * @see WolfSSLContext#free() */ - public synchronized void freeSSL() + public void freeSSL() throws IllegalStateException, WolfSSLJNIException { - synchronized (stateLock) { - if (this.active == false) { - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, "entered freeSSL(), already freed"); - /* already freed, just return */ - return; - } + synchronized (sslLock) { + synchronized (stateLock) { + if (this.active == false) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, "entered freeSSL(), already freed"); + /* already freed, just return */ + return; + } - synchronized (sslLock) { WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, WolfSSLDebug.INFO, this.sslPtr, "entered freeSSL()"); @@ -2867,7 +2867,7 @@ public int setGroupMessages() * @see WolfSSLContext#setIORecv(WolfSSLIORecvCallback) * @see WolfSSLContext#setIOSend(WolfSSLIOSendCallback) */ - public synchronized void setIOReadCtx(Object ctx) + public void setIOReadCtx(Object ctx) throws IllegalStateException, WolfSSLJNIException { confirmObjectIsActive(); @@ -2886,7 +2886,7 @@ public synchronized void setIOReadCtx(Object ctx) * @return Object that was set with setIOReadCtx(). * @throws IllegalStateException WolfSSLContext has been freed */ - public synchronized Object getIOReadCtx() + public Object getIOReadCtx() throws IllegalStateException { confirmObjectIsActive(); @@ -2918,7 +2918,7 @@ public synchronized Object getIOReadCtx() * @see WolfSSLContext#setIOSend(WolfSSLIOSendCallback) * @see WolfSSLContext#setIORecv(WolfSSLIORecvCallback) */ - public synchronized void setIOWriteCtx(Object ctx) + public void setIOWriteCtx(Object ctx) throws IllegalStateException, WolfSSLJNIException { confirmObjectIsActive(); @@ -2937,7 +2937,7 @@ public synchronized void setIOWriteCtx(Object ctx) * @return Object that was set with setIOWriteCtx(). * @throws IllegalStateException WolfSSLContext has been freed */ - public synchronized Object getIOWriteCtx() + public Object getIOWriteCtx() throws IllegalStateException { confirmObjectIsActive(); @@ -2964,7 +2964,7 @@ public synchronized Object getIOWriteCtx() * @throws WolfSSLJNIException Internal JNI error * @see WolfSSLContext#setGenCookie(WolfSSLGenCookieCallback) */ - public synchronized void setGenCookieCtx(Object ctx) + public void setGenCookieCtx(Object ctx) throws IllegalStateException, WolfSSLJNIException { confirmObjectIsActive(); @@ -3541,7 +3541,7 @@ public int setTlsHmacInner(byte[] inner, long sz, int content, * @throws WolfSSLJNIException Internal JNI error * @see WolfSSLContext#setMacEncryptCb(WolfSSLMacEncryptCallback) */ - public synchronized void setMacEncryptCtx(Object ctx) + public void setMacEncryptCtx(Object ctx) throws IllegalStateException, WolfSSLJNIException { confirmObjectIsActive(); @@ -3565,7 +3565,7 @@ public synchronized void setMacEncryptCtx(Object ctx) * @throws WolfSSLJNIException Internal JNI error * @see WolfSSLContext#setDecryptVerifyCb(WolfSSLDecryptVerifyCallback) */ - public synchronized void setDecryptVerifyCtx(Object ctx) + public void setDecryptVerifyCtx(Object ctx) throws IllegalStateException, WolfSSLJNIException { confirmObjectIsActive(); @@ -3588,7 +3588,7 @@ public synchronized void setDecryptVerifyCtx(Object ctx) * @throws WolfSSLJNIException Internal JNI error * @see WolfSSLContext#setEccSignCb(WolfSSLEccSignCallback) */ - public synchronized void setEccSignCtx(Object ctx) + public void setEccSignCtx(Object ctx) throws IllegalStateException, WolfSSLJNIException { confirmObjectIsActive(); @@ -3612,7 +3612,7 @@ public synchronized void setEccSignCtx(Object ctx) * @throws WolfSSLJNIException Internal JNI error * @see WolfSSLContext#setEccVerifyCb(WolfSSLEccVerifyCallback) */ - public synchronized void setEccVerifyCtx(Object ctx) + public void setEccVerifyCtx(Object ctx) throws IllegalStateException, WolfSSLJNIException { confirmObjectIsActive(); @@ -3637,7 +3637,7 @@ public synchronized void setEccVerifyCtx(Object ctx) * @see WolfSSLContext#setEccSignCb(WolfSSLEccSignCallback) * @see WolfSSLContext#setEccVerifyCb(WolfSSLEccVerifyCallback) */ - public synchronized void setEccSharedSecretCtx(Object ctx) + public void setEccSharedSecretCtx(Object ctx) throws IllegalStateException, WolfSSLJNIException { confirmObjectIsActive(); @@ -3661,7 +3661,7 @@ public synchronized void setEccSharedSecretCtx(Object ctx) * @throws WolfSSLJNIException Internal JNI error * @see WolfSSLContext#setRsaSignCb(WolfSSLRsaSignCallback) */ - public synchronized void setRsaSignCtx(Object ctx) + public void setRsaSignCtx(Object ctx) throws IllegalStateException, WolfSSLJNIException { confirmObjectIsActive(); @@ -3686,7 +3686,7 @@ public synchronized void setRsaSignCtx(Object ctx) * @throws WolfSSLJNIException Internal JNI error * @see WolfSSLContext#setRsaVerifyCb(WolfSSLRsaVerifyCallback) */ - public synchronized void setRsaVerifyCtx(Object ctx) + public void setRsaVerifyCtx(Object ctx) throws IllegalStateException, WolfSSLJNIException { confirmObjectIsActive(); @@ -3711,7 +3711,7 @@ public synchronized void setRsaVerifyCtx(Object ctx) * @throws WolfSSLJNIException Internal JNI error * @see WolfSSLContext#setRsaEncCb(WolfSSLRsaEncCallback) */ - public synchronized void setRsaEncCtx(Object ctx) + public void setRsaEncCtx(Object ctx) throws IllegalStateException, WolfSSLJNIException { confirmObjectIsActive(); @@ -3736,7 +3736,7 @@ public synchronized void setRsaEncCtx(Object ctx) * @throws WolfSSLJNIException Internal JNI error * @see WolfSSLContext#setRsaDecCb(WolfSSLRsaDecCallback) */ - public synchronized void setRsaDecCtx(Object ctx) + public void setRsaDecCtx(Object ctx) throws IllegalStateException, WolfSSLJNIException { confirmObjectIsActive(); @@ -3782,7 +3782,7 @@ public synchronized void setRsaDecCtx(Object ctx) * @see WolfSSLSession#getPskIdentity() * @see WolfSSLSession#getPskIdentityHint() */ - public synchronized void setPskClientCb(WolfSSLPskClientCallback callback) + public void setPskClientCb(WolfSSLPskClientCallback callback) throws IllegalStateException, WolfSSLJNIException { confirmObjectIsActive(); @@ -3827,7 +3827,7 @@ public synchronized void setPskClientCb(WolfSSLPskClientCallback callback) * @see WolfSSLSession#getPskIdentity() * @see WolfSSLSession#getPskIdentityHint() */ - public synchronized void setPskServerCb(WolfSSLPskServerCallback callback) + public void setPskServerCb(WolfSSLPskServerCallback callback) throws IllegalStateException, WolfSSLJNIException { confirmObjectIsActive(); @@ -4126,7 +4126,7 @@ public boolean gotCloseNotify() { * @throws WolfSSLJNIException Internal JNI error * @see #setIOSend(WolfSSLIOSendCallback) */ - public synchronized void setIORecv(WolfSSLIORecvCallback callback) + public void setIORecv(WolfSSLIORecvCallback callback) throws IllegalStateException, WolfSSLJNIException { confirmObjectIsActive(); @@ -4164,7 +4164,7 @@ public synchronized void setIORecv(WolfSSLIORecvCallback callback) * @throws WolfSSLJNIException Internal JNI error * @see #setIORecv(WolfSSLIORecvCallback) */ - public synchronized void setIOSend(WolfSSLIOSendCallback callback) + public void setIOSend(WolfSSLIOSendCallback callback) throws IllegalStateException, WolfSSLJNIException { confirmObjectIsActive(); @@ -4237,7 +4237,7 @@ public synchronized int getThreadsBlockedInPoll() * @throws IllegalStateException if called when WolfSSLSession is not * active */ - public synchronized int useSNI(byte type, byte[] data) + public int useSNI(byte type, byte[] data) throws IllegalStateException { int ret; @@ -4268,7 +4268,7 @@ public synchronized int useSNI(byte type, byte[] data) * @throws IllegalStateException if called when WolfSSLSession is not * active */ - public synchronized byte[] getClientSNIRequest() + public byte[] getClientSNIRequest() throws IllegalStateException { confirmObjectIsActive(); @@ -4347,7 +4347,7 @@ public String getSNIRequest(byte type) throws IllegalStateException { * @return WolfSSL.SSL_SUCCESS on success, otherwise negative. * @throws IllegalStateException WolfSSLSession has been freed */ - public synchronized int useSessionTicket() + public int useSessionTicket() throws IllegalStateException { int ret; @@ -4441,8 +4441,11 @@ public int useALPN(String[] protocols, int options) { confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.sslPtr, "entered useALPN(String[], int)"); + synchronized (sslLock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.sslPtr, + "entered useALPN(String[], int)"); + } if (protocols == null) { return WolfSSL.BAD_FUNC_ARG; @@ -4493,8 +4496,11 @@ public String getAlpnSelectedString() throws IllegalStateException { confirmObjectIsActive(); - WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, - WolfSSLDebug.INFO, this.sslPtr, "entered getAlpnSelectedString()"); + synchronized (sslLock) { + WolfSSLDebug.log(getClass(), WolfSSLDebug.Component.JNI, + WolfSSLDebug.INFO, this.sslPtr, + "entered getAlpnSelectedString()"); + } alpnSelectedBytes = getAlpnSelected(); From ff26562bdba9bc61dd100cc5d7bfc32dcead9e1c Mon Sep 17 00:00:00 2001 From: Chris Conlon Date: Fri, 24 Jan 2025 11:38:34 -0700 Subject: [PATCH 3/4] Android: update example app CMakeLists.txt for wolfSSL FIPS Ready compatibility --- IDE/Android/.idea/misc.xml | 1 - IDE/Android/README.md | 2 + IDE/Android/app/src/main/cpp/CMakeLists.txt | 114 ++++++++++++------ .../com/example/wolfssl/MainActivity.java | 30 ++++- 4 files changed, 100 insertions(+), 47 deletions(-) diff --git a/IDE/Android/.idea/misc.xml b/IDE/Android/.idea/misc.xml index 6d2b9cfd..3e48d412 100644 --- a/IDE/Android/.idea/misc.xml +++ b/IDE/Android/.idea/misc.xml @@ -1,4 +1,3 @@ -