add script to run Facebook Infer, fix reported issues
parent
6b821787ad
commit
2eaa54d892
|
@ -29,3 +29,7 @@ IDE/WIN/DLL Release FIPS
|
|||
# RPM package files
|
||||
rpm/spec
|
||||
*.rpm
|
||||
|
||||
# infer RacerD
|
||||
infer-out/
|
||||
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Simple script to run Facebook Infer over java files included in this package.
|
||||
#
|
||||
# This is set up to run entire infer over Java classes in this package. To
|
||||
# only run the RacerD thread safety analysis tool, change the command
|
||||
# invocation below from "run" to "--racerd-only", ie:
|
||||
#
|
||||
# infer --racerd-only -- javac \
|
||||
#
|
||||
# Run from wolfssljni root:
|
||||
#
|
||||
# $ cd wolfssljni
|
||||
# $ ./scripts/infer.sh
|
||||
#
|
||||
# wolfSSL Inc, May 2023
|
||||
#
|
||||
|
||||
infer run -- javac \
|
||||
src/java/com/wolfssl/WolfSSLCertificate.java \
|
||||
src/java/com/wolfssl/WolfSSLCertManager.java \
|
||||
src/java/com/wolfssl/WolfSSLContext.java \
|
||||
src/java/com/wolfssl/WolfSSLCustomUser.java \
|
||||
src/java/com/wolfssl/WolfSSLDecryptVerifyCallback.java \
|
||||
src/java/com/wolfssl/WolfSSLEccSharedSecretCallback.java \
|
||||
src/java/com/wolfssl/WolfSSLEccSignCallback.java \
|
||||
src/java/com/wolfssl/WolfSSLEccVerifyCallback.java \
|
||||
src/java/com/wolfssl/WolfSSLException.java \
|
||||
src/java/com/wolfssl/WolfSSLFIPSErrorCallback.java \
|
||||
src/java/com/wolfssl/WolfSSLGenCookieCallback.java \
|
||||
src/java/com/wolfssl/WolfSSLIORecvCallback.java \
|
||||
src/java/com/wolfssl/WolfSSLIOSendCallback.java \
|
||||
src/java/com/wolfssl/WolfSSL.java \
|
||||
src/java/com/wolfssl/WolfSSLJNIException.java \
|
||||
src/java/com/wolfssl/WolfSSLLoggingCallback.java \
|
||||
src/java/com/wolfssl/WolfSSLMacEncryptCallback.java \
|
||||
src/java/com/wolfssl/WolfSSLMissingCRLCallback.java \
|
||||
src/java/com/wolfssl/WolfSSLPskClientCallback.java \
|
||||
src/java/com/wolfssl/WolfSSLPskServerCallback.java \
|
||||
src/java/com/wolfssl/WolfSSLRsaDecCallback.java \
|
||||
src/java/com/wolfssl/WolfSSLRsaEncCallback.java \
|
||||
src/java/com/wolfssl/WolfSSLRsaSignCallback.java \
|
||||
src/java/com/wolfssl/WolfSSLRsaVerifyCallback.java \
|
||||
src/java/com/wolfssl/WolfSSLSession.java \
|
||||
src/java/com/wolfssl/WolfSSLVerifyCallback.java \
|
||||
src/java/com/wolfssl/WolfSSLX509StoreCtx.java \
|
||||
src/java/com/wolfssl/wolfcrypt/ECC.java \
|
||||
src/java/com/wolfssl/wolfcrypt/EccKey.java \
|
||||
src/java/com/wolfssl/wolfcrypt/RSA.java \
|
||||
src/java/com/wolfssl/provider/jsse/WolfSSLAuthStore.java \
|
||||
src/java/com/wolfssl/provider/jsse/WolfSSLContext.java \
|
||||
src/java/com/wolfssl/provider/jsse/WolfSSLDebug.java \
|
||||
src/java/com/wolfssl/provider/jsse/WolfSSLEngineHelper.java \
|
||||
src/java/com/wolfssl/provider/jsse/WolfSSLEngine.java \
|
||||
src/java/com/wolfssl/provider/jsse/WolfSSLGenericHostName.java \
|
||||
src/java/com/wolfssl/provider/jsse/WolfSSLImplementSSLSession.java \
|
||||
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/WolfSSLParametersHelper.java \
|
||||
src/java/com/wolfssl/provider/jsse/WolfSSLParameters.java \
|
||||
src/java/com/wolfssl/provider/jsse/WolfSSLProvider.java \
|
||||
src/java/com/wolfssl/provider/jsse/WolfSSLServerSocketFactory.java \
|
||||
src/java/com/wolfssl/provider/jsse/WolfSSLServerSocket.java \
|
||||
src/java/com/wolfssl/provider/jsse/WolfSSLSessionContext.java \
|
||||
src/java/com/wolfssl/provider/jsse/WolfSSLSNIServerName.java \
|
||||
src/java/com/wolfssl/provider/jsse/WolfSSLSocketFactory.java \
|
||||
src/java/com/wolfssl/provider/jsse/WolfSSLSocket.java \
|
||||
src/java/com/wolfssl/provider/jsse/WolfSSLTrustManager.java \
|
||||
src/java/com/wolfssl/provider/jsse/WolfSSLTrustX509.java \
|
||||
src/java/com/wolfssl/provider/jsse/WolfSSLX509.java \
|
||||
src/java/com/wolfssl/provider/jsse/WolfSSLX509X.java \
|
||||
src/java/com/wolfssl/provider/jsse/adapter/WolfSSLJDK8Helper.java
|
||||
|
||||
# remove compiled class files
|
||||
rm -r ./com
|
||||
|
||||
# remove infer out directory (comment this out to inspect logs if needed)
|
||||
rm -r ./infer-out
|
||||
|
|
@ -430,8 +430,8 @@ public class WolfSSL {
|
|||
|
||||
int fipsLoaded = 0;
|
||||
|
||||
String osName = System.getProperty("os.name").toLowerCase();
|
||||
if (osName.contains("win")) {
|
||||
String osName = System.getProperty("os.name");
|
||||
if (osName != null && osName.toLowerCase().contains("win")) {
|
||||
try {
|
||||
/* Default wolfCrypt FIPS library on Windows is compiled
|
||||
* as "wolfssl-fips" by Visual Studio solution */
|
||||
|
|
|
@ -70,7 +70,7 @@ public class WolfSSLCertManager {
|
|||
*
|
||||
* @return WolfSSL.SSL_SUCESS on success, negative on error
|
||||
*/
|
||||
public int CertManagerLoadCA(String f, String d) {
|
||||
public synchronized int CertManagerLoadCA(String f, String d) {
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
|
||||
|
@ -88,7 +88,9 @@ public class WolfSSLCertManager {
|
|||
*
|
||||
* @return WolfSSL.SSL_SUCCESS on success, negative on error
|
||||
*/
|
||||
public int CertManagerLoadCABuffer(byte[] in, long sz, int format) {
|
||||
public synchronized int CertManagerLoadCABuffer(
|
||||
byte[] in, long sz, int format) {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
|
||||
|
@ -103,7 +105,9 @@ public class WolfSSLCertManager {
|
|||
* @return WolfSSL.SSL_SUCCESS if at least one cert was loaded
|
||||
* successfully, otherwise WolfSSL.SSL_FAILURE.
|
||||
*/
|
||||
public int CertManagerLoadCAKeyStore(KeyStore ks) throws WolfSSLException {
|
||||
public synchronized int CertManagerLoadCAKeyStore(KeyStore ks)
|
||||
throws WolfSSLException {
|
||||
|
||||
int ret = 0;
|
||||
int loadedCerts = 0;
|
||||
|
||||
|
@ -156,7 +160,7 @@ public class WolfSSLCertManager {
|
|||
*
|
||||
* @return WolfSSL.SSL_SUCCESS on success, negative on error.
|
||||
*/
|
||||
public int CertManagerUnloadCAs() {
|
||||
public synchronized int CertManagerUnloadCAs() {
|
||||
if (this.active == false) {
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
}
|
||||
|
@ -176,7 +180,9 @@ public class WolfSSLCertManager {
|
|||
* @return WolfSSL.SSL_SUCCESS on successful verification, otherwise
|
||||
* negative on error.
|
||||
*/
|
||||
public int CertManagerVerifyBuffer(byte[] in, long sz, int format) {
|
||||
public synchronized int CertManagerVerifyBuffer(
|
||||
byte[] in, long sz, int format) {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
|
||||
|
@ -206,13 +212,11 @@ public class WolfSSLCertManager {
|
|||
@Override
|
||||
protected void finalize() throws Throwable
|
||||
{
|
||||
if (this.active == true) {
|
||||
try {
|
||||
this.free();
|
||||
} catch (IllegalStateException e) {
|
||||
/* already freed */
|
||||
}
|
||||
this.active = false;
|
||||
try {
|
||||
/* checks active state in this.free() */
|
||||
this.free();
|
||||
} catch (IllegalStateException e) {
|
||||
/* already freed */
|
||||
}
|
||||
super.finalize();
|
||||
}
|
||||
|
|
|
@ -641,9 +641,9 @@ public class WolfSSLCertificate {
|
|||
|
||||
/* cache altNames collection for later use */
|
||||
this.altNames = Collections.unmodifiableCollection(names);
|
||||
}
|
||||
|
||||
return this.altNames;
|
||||
return this.altNames;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -97,7 +97,7 @@ public class WolfSSLContext {
|
|||
|
||||
/* ------------------- private/protected methods -------------------- */
|
||||
|
||||
long getContextPtr()
|
||||
protected synchronized long getContextPtr()
|
||||
{
|
||||
if (this.active == false) {
|
||||
return 0;
|
||||
|
@ -310,6 +310,19 @@ public class WolfSSLContext {
|
|||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that the current WolfSSLContext object is active.
|
||||
*
|
||||
* @throws IllegalStateException if object has been freed
|
||||
*/
|
||||
private synchronized void confirmObjectIsActive()
|
||||
throws IllegalStateException {
|
||||
|
||||
if (this.active == false) {
|
||||
throw new IllegalStateException(
|
||||
"WolfSSLContext object has been freed");
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------ native method declarations -------------------- */
|
||||
|
||||
|
@ -392,8 +405,7 @@ public class WolfSSLContext {
|
|||
public int useCertificateFile(String file, int format)
|
||||
throws IllegalStateException, NullPointerException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return useCertificateFile(getContextPtr(), file, format);
|
||||
}
|
||||
|
@ -426,8 +438,7 @@ public class WolfSSLContext {
|
|||
public int usePrivateKeyFile(String file, int format)
|
||||
throws IllegalStateException, NullPointerException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return usePrivateKeyFile(getContextPtr(), file, format);
|
||||
}
|
||||
|
@ -478,8 +489,7 @@ public class WolfSSLContext {
|
|||
public int loadVerifyLocations(String file, String path)
|
||||
throws IllegalStateException, NullPointerException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return loadVerifyLocations(getContextPtr(), file, path);
|
||||
}
|
||||
|
@ -507,8 +517,7 @@ public class WolfSSLContext {
|
|||
public int useCertificateChainFile(String file)
|
||||
throws IllegalStateException, NullPointerException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return useCertificateChainFile(getContextPtr(), file);
|
||||
}
|
||||
|
@ -551,8 +560,7 @@ public class WolfSSLContext {
|
|||
public void setVerify(int mode, WolfSSLVerifyCallback callback)
|
||||
throws IllegalStateException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
setVerify(getContextPtr(), mode, callback);
|
||||
}
|
||||
|
@ -569,8 +577,7 @@ public class WolfSSLContext {
|
|||
public long setOptions(long op)
|
||||
throws IllegalStateException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return setOptions(getContextPtr(), op);
|
||||
}
|
||||
|
@ -586,8 +593,7 @@ public class WolfSSLContext {
|
|||
public long getOptions()
|
||||
throws IllegalStateException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return getOptions(getContextPtr());
|
||||
}
|
||||
|
@ -602,8 +608,7 @@ public class WolfSSLContext {
|
|||
*/
|
||||
public synchronized void free() throws IllegalStateException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
/* free native resources */
|
||||
freeContext(this.sslCtxPtr);
|
||||
|
@ -641,8 +646,7 @@ public class WolfSSLContext {
|
|||
public int memsaveCertCache(byte[] mem, int sz, int[] used)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return memsaveCertCache(getContextPtr(), mem, sz, used);
|
||||
}
|
||||
|
@ -675,8 +679,7 @@ public class WolfSSLContext {
|
|||
public int memrestoreCertCache(byte[] mem, int sz)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return memrestoreCertCache(getContextPtr(), mem, sz);
|
||||
}
|
||||
|
@ -698,8 +701,7 @@ public class WolfSSLContext {
|
|||
public int getCertCacheMemsize()
|
||||
throws IllegalStateException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return getCertCacheMemsize(getContextPtr());
|
||||
}
|
||||
|
@ -715,8 +717,8 @@ public class WolfSSLContext {
|
|||
* @throws IllegalStateException WolfSSLContext has been freed
|
||||
*/
|
||||
public long setCacheSize(long sz) throws IllegalStateException {
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
|
||||
confirmObjectIsActive();
|
||||
|
||||
return setCacheSize(getContextPtr(), sz);
|
||||
}
|
||||
|
@ -730,8 +732,8 @@ public class WolfSSLContext {
|
|||
* @throws IllegalStateException WolfSSLContext has been freed
|
||||
*/
|
||||
public long getCacheSize() throws IllegalStateException {
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
|
||||
confirmObjectIsActive();
|
||||
|
||||
return getCacheSize(getContextPtr());
|
||||
}
|
||||
|
@ -765,8 +767,7 @@ public class WolfSSLContext {
|
|||
public int setCipherList(String list)
|
||||
throws IllegalStateException, NullPointerException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return setCipherList(getContextPtr(), list);
|
||||
}
|
||||
|
@ -811,8 +812,7 @@ public class WolfSSLContext {
|
|||
public int loadVerifyBuffer(byte[] in, long sz, int format)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return loadVerifyBuffer(getContextPtr(), in, sz, format);
|
||||
}
|
||||
|
@ -848,8 +848,7 @@ public class WolfSSLContext {
|
|||
public int useCertificateBuffer(byte[] in, long sz, int format)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return useCertificateBuffer(getContextPtr(), in, sz, format);
|
||||
}
|
||||
|
@ -888,8 +887,7 @@ public class WolfSSLContext {
|
|||
public int usePrivateKeyBuffer(byte[] in, long sz, int format)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return usePrivateKeyBuffer(getContextPtr(), in, sz, format);
|
||||
}
|
||||
|
@ -928,8 +926,7 @@ public class WolfSSLContext {
|
|||
public int useCertificateChainBuffer(byte[] in, long sz)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return useCertificateChainBuffer(getContextPtr(), in, sz);
|
||||
}
|
||||
|
@ -972,8 +969,7 @@ public class WolfSSLContext {
|
|||
public int useCertificateChainBufferFormat(byte[] in, long sz, int format)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return useCertificateChainBufferFormat(getContextPtr(), in, sz, format);
|
||||
}
|
||||
|
@ -989,8 +985,7 @@ public class WolfSSLContext {
|
|||
*/
|
||||
public int setGroupMessages() throws IllegalStateException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return setGroupMessages(getContextPtr());
|
||||
}
|
||||
|
@ -1018,8 +1013,7 @@ public class WolfSSLContext {
|
|||
public void setIORecv(WolfSSLIORecvCallback callback)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
/* set user I/O recv */
|
||||
internRecvCb = callback;
|
||||
|
@ -1051,8 +1045,7 @@ public class WolfSSLContext {
|
|||
public void setIOSend(WolfSSLIOSendCallback callback)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
/* set user I/O send */
|
||||
internSendCb = callback;
|
||||
|
@ -1084,8 +1077,7 @@ public class WolfSSLContext {
|
|||
public void setGenCookie(WolfSSLGenCookieCallback callback)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
/* set DTLS cookie generation callback */
|
||||
internCookieCb = callback;
|
||||
|
@ -1119,8 +1111,7 @@ public class WolfSSLContext {
|
|||
*/
|
||||
public int enableCRL(int options) throws IllegalStateException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return enableCRL(getContextPtr(), options);
|
||||
}
|
||||
|
@ -1144,8 +1135,7 @@ public class WolfSSLContext {
|
|||
*/
|
||||
public int disableCRL() throws IllegalStateException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return disableCRL(getContextPtr());
|
||||
}
|
||||
|
@ -1192,8 +1182,7 @@ public class WolfSSLContext {
|
|||
public int loadCRL(String path, int type, int monitor)
|
||||
throws IllegalStateException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return loadCRL(getContextPtr(), path, type, monitor);
|
||||
}
|
||||
|
@ -1218,8 +1207,7 @@ public class WolfSSLContext {
|
|||
public int setCRLCb(WolfSSLMissingCRLCallback cb)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return setCRLCb(getContextPtr(), cb);
|
||||
}
|
||||
|
@ -1249,8 +1237,7 @@ public class WolfSSLContext {
|
|||
public int enableOCSP(long options)
|
||||
throws IllegalStateException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return enableOCSP(getContextPtr(), options);
|
||||
}
|
||||
|
@ -1265,8 +1252,7 @@ public class WolfSSLContext {
|
|||
*/
|
||||
public int disableOCSP() throws IllegalStateException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return disableOCSP(getContextPtr());
|
||||
}
|
||||
|
@ -1291,8 +1277,7 @@ public class WolfSSLContext {
|
|||
public int setOCSPOverrideUrl(String url)
|
||||
throws IllegalStateException, NullPointerException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return setOCSPOverrideUrl(getContextPtr(), url);
|
||||
}
|
||||
|
@ -1325,8 +1310,7 @@ public class WolfSSLContext {
|
|||
public void setMacEncryptCb(WolfSSLMacEncryptCallback callback)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
/* set MAC encrypt callback */
|
||||
internMacEncryptCb = callback;
|
||||
|
@ -1363,8 +1347,7 @@ public class WolfSSLContext {
|
|||
public void setDecryptVerifyCb(WolfSSLDecryptVerifyCallback callback)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
/* set decrypt/verify callback */
|
||||
internDecryptVerifyCb = callback;
|
||||
|
@ -1398,8 +1381,7 @@ public class WolfSSLContext {
|
|||
public void setEccSignCb(WolfSSLEccSignCallback callback)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
/* set ecc sign callback */
|
||||
internEccSignCb = callback;
|
||||
|
@ -1433,8 +1415,7 @@ public class WolfSSLContext {
|
|||
public void setEccVerifyCb(WolfSSLEccVerifyCallback callback)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
/* set ecc verify callback */
|
||||
internEccVerifyCb = callback;
|
||||
|
@ -1483,8 +1464,7 @@ public class WolfSSLContext {
|
|||
public void setEccSharedSecretCb(WolfSSLEccSharedSecretCallback callback)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
/* set ecc shared secret callback */
|
||||
internEccSharedSecretCb = callback;
|
||||
|
@ -1518,8 +1498,7 @@ public class WolfSSLContext {
|
|||
public void setRsaSignCb(WolfSSLRsaSignCallback callback)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
/* set rsa sign callback */
|
||||
internRsaSignCb = callback;
|
||||
|
@ -1553,8 +1532,7 @@ public class WolfSSLContext {
|
|||
public void setRsaVerifyCb(WolfSSLRsaVerifyCallback callback)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
/* set rsa verify callback */
|
||||
internRsaVerifyCb = callback;
|
||||
|
@ -1588,8 +1566,7 @@ public class WolfSSLContext {
|
|||
public void setRsaEncCb(WolfSSLRsaEncCallback callback)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
/* set rsa public encrypt callback */
|
||||
internRsaEncCb = callback;
|
||||
|
@ -1622,8 +1599,7 @@ public class WolfSSLContext {
|
|||
public void setRsaDecCb(WolfSSLRsaDecCallback callback)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
/* set rsa private decrypt callback */
|
||||
internRsaDecCb = callback;
|
||||
|
@ -1660,8 +1636,7 @@ public class WolfSSLContext {
|
|||
public void setPskClientCb(WolfSSLPskClientCallback callback)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
/* set PSK client callback */
|
||||
internPskClientCb = callback;
|
||||
|
@ -1697,8 +1672,7 @@ public class WolfSSLContext {
|
|||
public void setPskServerCb(WolfSSLPskServerCallback callback)
|
||||
throws IllegalStateException, WolfSSLJNIException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
/* set PSK server callback */
|
||||
internPskServerCb = callback;
|
||||
|
@ -1725,8 +1699,7 @@ public class WolfSSLContext {
|
|||
*/
|
||||
public int usePskIdentityHint(String hint) {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return usePskIdentityHint(getContextPtr(), hint);
|
||||
}
|
||||
|
@ -1744,8 +1717,7 @@ public class WolfSSLContext {
|
|||
*/
|
||||
public int useSecureRenegotiation() throws IllegalStateException {
|
||||
|
||||
if (this.active == false)
|
||||
throw new IllegalStateException("Object has been freed");
|
||||
confirmObjectIsActive();
|
||||
|
||||
return useSecureRenegotiation(getContextPtr());
|
||||
}
|
||||
|
@ -1754,13 +1726,11 @@ public class WolfSSLContext {
|
|||
@Override
|
||||
protected void finalize() throws Throwable
|
||||
{
|
||||
if (this.active == true) {
|
||||
try {
|
||||
this.free();
|
||||
} catch (IllegalStateException e) {
|
||||
/* already freed */
|
||||
}
|
||||
this.active = false;
|
||||
try {
|
||||
/* free() checks and resets this.active */
|
||||
this.free();
|
||||
} catch (IllegalStateException e) {
|
||||
/* already freed */
|
||||
}
|
||||
super.finalize();
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1065,7 +1065,7 @@ public class WolfSSLEngine extends SSLEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean getUseClientMode() {
|
||||
public synchronized boolean getUseClientMode() {
|
||||
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
|
||||
"entered getUseClientMode()");
|
||||
return EngineHelper.getUseClientMode();
|
||||
|
@ -1079,7 +1079,7 @@ public class WolfSSLEngine extends SSLEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean getNeedClientAuth() {
|
||||
public synchronized boolean getNeedClientAuth() {
|
||||
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
|
||||
"entered getNeedClientAuth()");
|
||||
return EngineHelper.getNeedClientAuth();
|
||||
|
@ -1093,7 +1093,7 @@ public class WolfSSLEngine extends SSLEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean getWantClientAuth() {
|
||||
public synchronized boolean getWantClientAuth() {
|
||||
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
|
||||
"entered getWantClientAuth()");
|
||||
return EngineHelper.getWantClientAuth();
|
||||
|
@ -1107,7 +1107,7 @@ public class WolfSSLEngine extends SSLEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean getEnableSessionCreation() {
|
||||
public synchronized boolean getEnableSessionCreation() {
|
||||
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
|
||||
"entered getEnableSessionCreation()");
|
||||
return EngineHelper.getEnableSessionCreation();
|
||||
|
|
|
@ -690,32 +690,33 @@ public class WolfSSLEngineHelper {
|
|||
this.session = this.authStore.getSession(ssl, this.port, this.hostname,
|
||||
this.clientMode);
|
||||
|
||||
if (this.session != null && this.clientMode) {
|
||||
this.session.setSessionContext(authStore.getClientContext());
|
||||
this.session.setSide(WolfSSL.WOLFSSL_CLIENT_END);
|
||||
}
|
||||
else {
|
||||
this.session.setSessionContext(authStore.getServerContext());
|
||||
this.session.setSide(WolfSSL.WOLFSSL_SERVER_END);
|
||||
}
|
||||
if (this.session != null) {
|
||||
if (this.clientMode) {
|
||||
this.session.setSessionContext(authStore.getClientContext());
|
||||
this.session.setSide(WolfSSL.WOLFSSL_CLIENT_END);
|
||||
}
|
||||
else {
|
||||
this.session.setSessionContext(authStore.getServerContext());
|
||||
this.session.setSide(WolfSSL.WOLFSSL_SERVER_END);
|
||||
}
|
||||
|
||||
if (this.session != null && this.sessionCreation == false &&
|
||||
!this.session.fromTable) {
|
||||
/* new handshakes can not be made in this case. */
|
||||
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
|
||||
"session creation not allowed");
|
||||
if (this.sessionCreation == false && !this.session.fromTable) {
|
||||
/* new handshakes can not be made in this case. */
|
||||
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
|
||||
"session creation not allowed");
|
||||
|
||||
/* send CloseNotify */
|
||||
/* TODO: SunJSSE sends a Handshake Failure alert instead here */
|
||||
this.ssl.shutdownSSL();
|
||||
/* send CloseNotify */
|
||||
/* TODO: SunJSSE sends a Handshake Failure alert instead here */
|
||||
this.ssl.shutdownSSL();
|
||||
|
||||
throw new SSLHandshakeException("Session creation not allowed");
|
||||
}
|
||||
throw new SSLHandshakeException("Session creation not allowed");
|
||||
}
|
||||
|
||||
if (this.session != null && this.sessionCreation) {
|
||||
/* can only add new sessions to the resumption table if session
|
||||
* creation is allowed */
|
||||
this.authStore.addSession(this.session);
|
||||
if (this.sessionCreation) {
|
||||
/* can only add new sessions to the resumption table if session
|
||||
* creation is allowed */
|
||||
this.authStore.addSession(this.session);
|
||||
}
|
||||
}
|
||||
|
||||
this.setLocalParams();
|
||||
|
|
|
@ -526,7 +526,7 @@ public class WolfSSLImplementSSLSession implements SSLSession {
|
|||
* Sets the native WOLFSSL_SESSION timeout
|
||||
* @param in timeout in seconds
|
||||
*/
|
||||
protected void setNativeTimeout(long in) {
|
||||
protected synchronized void setNativeTimeout(long in) {
|
||||
ssl.setSessTimeout(in);
|
||||
}
|
||||
|
||||
|
|
|
@ -1354,7 +1354,7 @@ public class WolfSSLSocket extends SSLSocket {
|
|||
* @throws IOException if InputStream is not able to be returned
|
||||
*/
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
public synchronized InputStream getInputStream() throws IOException {
|
||||
|
||||
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
|
||||
"entered getInputStream()");
|
||||
|
@ -1376,7 +1376,7 @@ public class WolfSSLSocket extends SSLSocket {
|
|||
* @throws IOException if OutputStream is not able to be returned
|
||||
*/
|
||||
@Override
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
public synchronized OutputStream getOutputStream() throws IOException {
|
||||
|
||||
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
|
||||
"entered getOutputStream()");
|
||||
|
@ -1509,6 +1509,12 @@ public class WolfSSLSocket extends SSLSocket {
|
|||
/* Connection is closed, free native WOLFSSL session
|
||||
* to release native memory earlier than garbage
|
||||
* collector might with finalize(). */
|
||||
Object readCtx = this.ssl.getIOReadCtx();
|
||||
if (readCtx != null &&
|
||||
readCtx instanceof ConsumedRecvCtx) {
|
||||
ConsumedRecvCtx rctx = (ConsumedRecvCtx)readCtx;
|
||||
rctx.closeDataStreams();
|
||||
}
|
||||
this.ssl.freeSSL();
|
||||
this.ssl = null;
|
||||
}
|
||||
|
@ -1528,10 +1534,10 @@ public class WolfSSLSocket extends SSLSocket {
|
|||
} else {
|
||||
if (this.socket != null) {
|
||||
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
|
||||
"socket (external) not closed, autoClose set to false");
|
||||
"socket (external) not closed, autoClose set to false");
|
||||
} else {
|
||||
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
|
||||
"socket (super) not closed, autoClose set to false");
|
||||
"socket (super) not closed, autoClose set to false");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1655,8 +1661,14 @@ public class WolfSSLSocket extends SSLSocket {
|
|||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
protected synchronized void finalize() throws Throwable {
|
||||
if (this.ssl != null) {
|
||||
Object readCtx = this.ssl.getIOReadCtx();
|
||||
if (readCtx != null &&
|
||||
readCtx instanceof ConsumedRecvCtx) {
|
||||
ConsumedRecvCtx rctx = (ConsumedRecvCtx)readCtx;
|
||||
rctx.closeDataStreams();
|
||||
}
|
||||
this.ssl.freeSSL();
|
||||
this.ssl = null;
|
||||
}
|
||||
|
@ -1664,21 +1676,43 @@ public class WolfSSLSocket extends SSLSocket {
|
|||
}
|
||||
|
||||
class ConsumedRecvCtx {
|
||||
private Socket s;
|
||||
private DataInputStream consumed;
|
||||
private Socket s = null;
|
||||
private DataInputStream consumed = null;
|
||||
private DataInputStream sockStream = null;
|
||||
|
||||
public ConsumedRecvCtx(Socket s, InputStream in) {
|
||||
this.s = s;
|
||||
this.consumed = new DataInputStream(in);
|
||||
}
|
||||
|
||||
public DataInputStream getSocketDataStream() throws IOException {
|
||||
return new DataInputStream(this.s.getInputStream());
|
||||
public synchronized DataInputStream getSocketDataStream()
|
||||
throws IOException {
|
||||
|
||||
if (this.s != null) {
|
||||
if (this.sockStream == null) {
|
||||
this.sockStream =
|
||||
new DataInputStream(this.s.getInputStream());
|
||||
}
|
||||
return this.sockStream;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public DataInputStream getConsumedDataStream() {
|
||||
public synchronized DataInputStream getConsumedDataStream() {
|
||||
return this.consumed;
|
||||
}
|
||||
|
||||
public synchronized void closeDataStreams()
|
||||
throws IOException {
|
||||
if (consumed != null) {
|
||||
consumed.close();
|
||||
}
|
||||
if (sockStream != null) {
|
||||
sockStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ConsumedRecvCallback implements WolfSSLIORecvCallback {
|
||||
|
@ -1686,7 +1720,7 @@ public class WolfSSLSocket extends SSLSocket {
|
|||
public int receiveCallback(WolfSSLSession ssl, byte[] buf,
|
||||
int sz, Object ctx) {
|
||||
|
||||
int ret;
|
||||
int ret = 0;
|
||||
|
||||
try {
|
||||
ConsumedRecvCtx context = (ConsumedRecvCtx)ctx;
|
||||
|
@ -1701,7 +1735,7 @@ public class WolfSSLSocket extends SSLSocket {
|
|||
ret = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
} else if (current != null) {
|
||||
/* read directly from Socket, may throw SocketException
|
||||
* if underlying socket is non-blocking and returns
|
||||
* WANT_READ. */
|
||||
|
|
Loading…
Reference in New Issue