2011-05-25 95 views
2

我的應用程序正在使用Apache的HttpClient的3.1部署在的Weblogic 10.3執行POST使用SSL相互認證。我能得到這個使用下面的系統屬性來配置密鑰庫 & 信任工作: -我可以讓HttpClient使用Weblogic的自定義密鑰存儲/信任存儲設置嗎?

-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定製密鑰庫 & 信任庫設置(在console/config.xml中配置)。除此之外,這將提供保持密碼「隱藏」並且不能在配置文件/控制檯中以明文形式顯示的能力等。

任何人都可以啓發我嗎?

回答

0

您可能可以通過使用KeyStoreMBean的JMX獲取這些值。雖然被預先警告,這可能不是一件容易的事,由於以下幾點:

  • 這就要求存儲明文密鑰庫的密碼在你的JMX客戶端(現在你會寫一個在你的應用程序)。這是不安全的,並且由於這個原因,安全審計可能會失敗,這取決於審計的目的。
  • 由於JMX服務配置的原因,MBean可能無法在運行時訪問,或者必須在不同的方案中以不同方式訪問MBean。假設WebLogic 11g的值可能爲只讀,setting the value of the EditMBeanServerEnabled attribute of the JMXMBean to false
2

我已經能夠獲得通過的HttpClient實現自定義TrustStrategy用於SSL連接定製的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; 
    } 
} 

這個代碼是基於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域的名稱,它可以從Weblogic的JMX API,或者乾脆預先服用。這樣,它不需要實例化信任庫或重新配置Weblogic啓動參數。

相關問題