2010-01-20 52 views

回答

3

它沒有出現,你可以傳入文件名以外的任何東西。如果您查看source並查看validateConfiguration()createSSLContext()方法,則會看到它將keyStoreFile變量直接傳遞給FileInputStream構造函數。

短期來看,您可能會停留在解壓縮並使用直接文件名。或者你可以重寫上面列出的兩個方法來正確驗證和初始化SSLContext。長期來看,我會提交一個補丁。

2

@ Kevin的想法奏效了!利用灰熊-servlet的Web服務器1.9.8,這裏是我的代碼:


SSLConfig ssl = new SSLConfig(){ 
@Override 
public SSLContext createSSLContext() { 
    try{ 
    //Load the keystore. 
    KeyStore keyStore=KeyStore.getInstance(KeyStore.getDefaultType()); 
    InputStream keyStream=ClassLoader.getSystemResourceAsStream("my.jks"); 
    //InputStream keyStream=new java.net.URL("jar:file:/C:/dir/my.jar!/my.jks").openStream(); 
    keyStore.load(keyStream,"mypassword"); 
    keyStream.close(); 

    //Create the factory from the keystore. 
    String kmfAlgorithm=System.getProperty("ssl.KeyManagerFactory.algorithm",KeyManagerFactory.getDefaultAlgorithm()); 
    KeyManagerFactory keyManagerFactory=KeyManagerFactory.getInstance(kmfAlgorithm); 
    keyManagerFactory.init(keyStore,"mypassword"); 

    //Create the SSLContext 
    SSLContext sslContext=SSLContext.getInstance("TLS"); 
    sslContext.init(keyManagerFactory.getKeyManagers(), null, null); 
    return sslContext; 
    } 

    //Wrap all Exceptions in a RuntimeException. 
    catch(Exception e){ 
    throw new RuntimeException(e); 
    } 
} 
}; 

我花了幾個快捷方式(不記錄異常,使用幾個字符串常量,等等),但你可以得到的想法。