2011-01-09 41 views
10

我是一個新的安裝Ubuntu的剛剛安裝的OpenJDK:Ubuntu上的OpenJDK中的Java SSL是否被破壞?

OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode) on Ubuntu 64 bit 10.10 

不知道這是否是相關的,但我從VMware Fusion的內部運行它。

以下行:

javax.net.SSLContext.getDefault(); // same as getInstance("Default") 

throws the following exception: 

java.net.SocketException: java.security.NoSuchAlgorithmException: Default SSLContext not available 

我的同事和我已經試過這幾臺機器上,Ubuntu的所有全新安裝,並不斷收到這一點。我被建議嘗試getInstance(「TLSv1」),但是這拋出了相同的錯誤。看起來像是一件非常重要的事情,因爲我不知道該怎麼做,所以我認爲我們必須做錯事。

回答

6

圭多的回答我指出了正確的方向。這只是一個問題:

sudo apt-get install libbcprov-java 
2

ubuntu發佈的openjdk可能缺少JCE提供程序;從http://www.bouncycastle.org/(它是一個實現JCE的開源項目)下載bouncycastle加密API並將其放入項目類路徑中。

然後在你的類指的是下面的示例代碼:

 
static { 
    Security.addProvider(new BouncyCastleProvider()); 
} 

public SSLSocket getSSLSocket() { 

    // Load the Keystore 
    KeyStore ks = KeyStore.getInstance(keystoreType); 
    ks.load(new FileInputStream(this.keyStorePath),this.keyStorePass.toCharArray()); 

    // Get a KeyManager and initialize it 
    KeyManagerFactory kmf = KeyManagerFactory.getInstance("sunx509"); 
    kmf.init(ks, this.keyStorePass.toCharArray()); 

    // Get a TrustManagerFactory and init with KeyStore 
    TrustManagerFactory tmf = TrustManagerFactory.getInstance("sunx509"); 
    tmf.init(ks); 

    // Get the SSLContext to help create SSLSocketFactory 
    SSLContext sslc = SSLContext.getInstance("TLS"); 
    sslc.init(kmf.getKeyManagers(), null, null); 

    // Get SSLSocketFactory and get a SSLSocket 
    SSLSocketFactory sslsf = sslc.getSocketFactory(); 
    SSLSocket socket = (SSLSocket) sslsf.createSocket(host, port); 
    return socket; 
}