You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2013/05/13 22:05:26 UTC
svn commit: r1482062 -
/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/SSLUtil.java
Author: doogie
Date: Mon May 13 20:05:26 2013
New Revision: 1482062
URL: http://svn.apache.org/r1482062
Log:
FEATURE: Reworked to expose a getSSLContext helper method, called by
everything else.
Modified:
ofbiz/trunk/framework/base/src/org/ofbiz/base/util/SSLUtil.java
Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/SSLUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/SSLUtil.java?rev=1482062&r1=1482061&r2=1482062&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/SSLUtil.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/SSLUtil.java Mon May 13 20:05:26 2013
@@ -157,15 +157,28 @@ public class SSLUtil {
}
public static SSLSocketFactory getSSLSocketFactory(KeyStore ks, String password, String alias) throws IOException, GeneralSecurityException, GenericConfigException {
+ return getSSLContext(ks, password, alias, false).getSocketFactory();
+ }
+
+ public static SSLContext getSSLContext(KeyStore ks, String password, String alias, boolean trustAny) throws IOException, GeneralSecurityException, GenericConfigException {
KeyManager[] km = SSLUtil.getKeyManagers(ks, password, alias);
- TrustManager[] tm = SSLUtil.getTrustManagers();
+ TrustManager[] tm;
+ if (trustAny) {
+ tm = SSLUtil.getTrustAnyManagers();
+ } else {
+ tm = SSLUtil.getTrustManagers();
+ }
SSLContext context = SSLContext.getInstance("SSL");
context.init(km, tm, new SecureRandom());
- return context.getSocketFactory();
+ return context;
}
public static SSLSocketFactory getSSLSocketFactory(String alias, boolean trustAny) throws IOException, GeneralSecurityException, GenericConfigException {
+ return getSSLContext(alias, trustAny).getSocketFactory();
+ }
+
+ public static SSLContext getSSLContext(String alias, boolean trustAny) throws IOException, GeneralSecurityException, GenericConfigException {
KeyManager[] km = SSLUtil.getKeyManagers(alias);
TrustManager[] tm;
if (trustAny) {
@@ -176,7 +189,7 @@ public class SSLUtil {
SSLContext context = SSLContext.getInstance("SSL");
context.init(km, tm, new SecureRandom());
- return context.getSocketFactory();
+ return context;
}
public static SSLSocketFactory getSSLSocketFactory(String alias) throws IOException, GeneralSecurityException, GenericConfigException {
@@ -188,21 +201,11 @@ public class SSLUtil {
}
public static SSLServerSocketFactory getSSLServerSocketFactory(KeyStore ks, String password, String alias) throws IOException, GeneralSecurityException, GenericConfigException {
- TrustManager[] tm = SSLUtil.getTrustManagers();
- KeyManager[] km = SSLUtil.getKeyManagers(ks, password, alias);
-
- SSLContext context = SSLContext.getInstance("SSL");
- context.init(km, tm, new SecureRandom());
- return context.getServerSocketFactory();
+ return getSSLContext(ks, password, alias, false).getServerSocketFactory();
}
public static SSLServerSocketFactory getSSLServerSocketFactory(String alias) throws IOException, GeneralSecurityException, GenericConfigException {
- TrustManager[] tm = SSLUtil.getTrustManagers();
- KeyManager[] km = SSLUtil.getKeyManagers(alias);
-
- SSLContext context = SSLContext.getInstance("SSL");
- context.init(km, tm, new SecureRandom());
- return context.getServerSocketFactory();
+ return getSSLContext(alias, false).getServerSocketFactory();
}
public static HostnameVerifier getHostnameVerifier(int level) {