KeyManager and TrustManager throw exceptions if used when uninitialized
parent
2353670bd8
commit
90627f0864
|
@ -42,6 +42,7 @@ import javax.net.ssl.ManagerFactoryParameters;
|
||||||
public class WolfSSLKeyManager extends KeyManagerFactorySpi {
|
public class WolfSSLKeyManager extends KeyManagerFactorySpi {
|
||||||
private char[] pswd;
|
private char[] pswd;
|
||||||
private KeyStore store;
|
private KeyStore store;
|
||||||
|
private boolean initialized = false;
|
||||||
|
|
||||||
/** Default WolfSSLKeyManager constructor */
|
/** Default WolfSSLKeyManager constructor */
|
||||||
public WolfSSLKeyManager() { }
|
public WolfSSLKeyManager() { }
|
||||||
|
@ -136,6 +137,7 @@ public class WolfSSLKeyManager extends KeyManagerFactorySpi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.store = certs;
|
this.store = certs;
|
||||||
|
this.initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -151,11 +153,17 @@ public class WolfSSLKeyManager extends KeyManagerFactorySpi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected KeyManager[] engineGetKeyManagers() {
|
protected KeyManager[] engineGetKeyManagers()
|
||||||
|
throws IllegalStateException {
|
||||||
|
|
||||||
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
|
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
|
||||||
"entered engineGetKeyManagers()");
|
"entered engineGetKeyManagers()");
|
||||||
|
|
||||||
|
if (!this.initialized) {
|
||||||
|
throw new IllegalStateException("KeyManagerFactory must be " +
|
||||||
|
"initialized before use, please call init()");
|
||||||
|
}
|
||||||
|
|
||||||
KeyManager[] km = {new WolfSSLKeyX509(this.store, this.pswd)};
|
KeyManager[] km = {new WolfSSLKeyX509(this.store, this.pswd)};
|
||||||
return km;
|
return km;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ import com.wolfssl.WolfSSLJNIException;
|
||||||
*/
|
*/
|
||||||
public class WolfSSLTrustManager extends TrustManagerFactorySpi {
|
public class WolfSSLTrustManager extends TrustManagerFactorySpi {
|
||||||
private KeyStore store;
|
private KeyStore store;
|
||||||
|
private boolean initialized = false;
|
||||||
|
|
||||||
/** Default WolfSSLTrustManager constructor */
|
/** Default WolfSSLTrustManager constructor */
|
||||||
public WolfSSLTrustManager() { }
|
public WolfSSLTrustManager() { }
|
||||||
|
@ -352,6 +353,7 @@ public class WolfSSLTrustManager extends TrustManagerFactorySpi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.store = certs;
|
this.store = certs;
|
||||||
|
this.initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -367,11 +369,18 @@ public class WolfSSLTrustManager extends TrustManagerFactorySpi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TrustManager[] engineGetTrustManagers() {
|
protected TrustManager[] engineGetTrustManagers()
|
||||||
|
throws IllegalStateException {
|
||||||
|
|
||||||
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
|
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
|
||||||
"entered engineGetTrustManagers()");
|
"entered engineGetTrustManagers()");
|
||||||
|
|
||||||
|
if (!this.initialized) {
|
||||||
|
throw new IllegalStateException("TrustManagerFactory must be " +
|
||||||
|
"initialized before use, please call init()");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* array of WolfSSLX509Trust objects to use */
|
/* array of WolfSSLX509Trust objects to use */
|
||||||
TrustManager[] tm = {new WolfSSLTrustX509(this.store)};
|
TrustManager[] tm = {new WolfSSLTrustX509(this.store)};
|
||||||
return tm;
|
return tm;
|
||||||
|
|
Loading…
Reference in New Issue