我可以让HttpClient使用Weblogic';s自定义密钥库/信任库设置?
我的应用程序使用部署在Weblogic 10.3上的Apache的HttpClient 3.1来执行使用SSL相互身份验证的POST。我可以通过使用以下系统属性来配置密钥库和信任库来实现这一点:- 有没有办法让HttpClient识别并使用自定义密钥库和信任库设置(如console/config.xml中配置的)。除其他外,这将提供在配置文件/控制台等中保持密码“隐藏”且不以明文形式可见的能力我可以让HttpClient使用Weblogic';s自定义密钥库/信任库设置?,weblogic,httpclient,keystore,truststore,Weblogic,Httpclient,Keystore,Truststore,我的应用程序使用部署在Weblogic 10.3上的Apache的HttpClient 3.1来执行使用SSL相互身份验证的POST。我可以通过使用以下系统属性来配置密钥库和信任库来实现这一点:- 有没有办法让HttpClient识别并使用自定义密钥库和信任库设置(如console/config.xml中配置的)。除其他外,这将提供在配置文件/控制台等中保持密码“隐藏”且不以明文形式可见的能力 有人能告诉我吗?您可以通过JMX使用获取这些值。不过,请预先警告,由于以下原因,这可能不是一个微不足道
有人能告诉我吗?您可以通过JMX使用获取这些值。不过,请预先警告,由于以下原因,这可能不是一个微不足道的练习:
- 这需要在JMX客户机中以明文形式存储密钥库密码(现在您将在应用程序中编写密钥库密码)。这是不安全的,安全审计可能因此而失败,这取决于审计的目的
- 由于JMX服务配置的原因,MBean在运行时可能无法访问,或者在不同的场景中必须以不同的方式访问。假设WebLogic 11g,则可以通过将值设置为只读
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
SSLSocketFactory sslSocketFactory = new SSLSocketFactory(new WeblogicSSLTrustStrategy());
schemeRegistry.register(new Scheme("https", 443, sslSocketFactory));
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);
唯一未知的参数是Weblogic领域名称,它可以取自Weblogic JMX API,也可以只是预配置。这样,它不需要实例化信任存储或重新配置Weblogic启动参数
import sun.security.provider.certpath.X509CertPath;
import weblogic.security.pk.CertPathValidatorParameters;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertPath;
import java.security.cert.CertPathParameters;
import java.security.cert.CertPathValidator;
import java.security.cert.CertPathValidatorException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Arrays;
public class WeblogicSSLTrustStrategy implements TrustStrategy {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
validator = CertPathValidator.getInstance("WLSCertPathValidator");
CertPath certPath = new X509CertPath(Arrays.asList(chain));
// supply here the weblogic realm name, configured in weblogic console
// "myrealm" is the default one
CertPathParameters params = new CertPathValidatorParameters("myrealm", null, null);
try {
validator.validate(certPath, params);
} catch (CertPathValidatorException e) {
throw new CertificateException(e);
} catch (InvalidAlgorithmParameterException e) {
throw new CertificateException(e);
}
return true;
}
}
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
SSLSocketFactory sslSocketFactory = new SSLSocketFactory(new WeblogicSSLTrustStrategy());
schemeRegistry.register(new Scheme("https", 443, sslSocketFactory));
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);