我的应用程序使用 Weblogic 10.3 上部署的 Apache的HttpClient 3.1 ,使用 SSL 相互身份验证执行 POST 。我可以使用以下系统属性来配置密钥库& 信任: -
-Djavax.net.ssl.keyStore=C:\Keystore\KEYSTORE.jks
-Djavax.net.ssl.keyStorePassword=changeit
-Djavax.net.ssl.trustStore=C:\Truststore\TRUSTSTORE.jks
-Djavax.net.ssl.trustStorePassword=changeit
有没有办法让 HttpClient 识别并使用 Weblogic 自定义密钥库& truststore 设置(在console / config.xml中配置)。除此之外,这将提供保持密码“隐藏”并且在配置文件/控制台等中不作为纯文本可见的能力。
任何人都可以启发我吗?
答案 0 :(得分:2)
我已经能够通过实现自定义TrustStrategy让HttpClient使用自定义weblogic信任存储证书进行SSL连接:
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;
}
}
此代码基于Weblogic documentation。策略可以通过SSLSocketFactory传递给HttpClient:
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 Realm名称,可以从Weblogic JMX API获取,也可以简单地预先配置。这样,它不需要实例化信任库或重新配置Weblogic启动参数。
答案 1 :(得分:0)
您可以使用KeyStoreMBean通过JMX获取这些值。不过要预先警告,由于以下原因,这可能不是一项微不足道的工作: