我有一個Apache Http客戶端需要連接到需要TLS 1.2的服務器,但現在這個客戶端在jdk 1.6上運行,此時升級是不可能的。所以我選擇了Bouncy Castle。我在此Mac上設置它,如post所示。在Java 6上運行TLS 1.2和BouncyCastle
這裏是我的代碼,它採用了SSLContextBuilder ...
import org.apache.http.ssl.SSLContextBuilder;
SSLContextBuilder sslContextBuilder = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
return true;
}
});
// set SSL context builder to use TLSv1 protocoil
sslContextBuilder = sslContextBuilder.useProtocol("TLSv1.1");
但在這裏的最後一行我得到這個例外...
Caught: java.security.NoSuchAlgorithmException: TLSv1.1 SSLContext not available
java.security.NoSuchAlgorithmException: TLSv1.1 SSLContext not available
at org.apache.http.ssl.SSLContextBuilder.build(SSLContextBuilder.java:271)
貌似是SSLContextBuilder沒有看到我的充氣城堡。或者我的BouncyCastle不支持TLS 1.1?如果我將它改爲「TLSv1」,那麼它就可以工作。
或者是否有更好的方法來做到這一點(將我的apache httpclient連接到bouncycastle,以便我的java 6程序可以連接到tlsv1.2服務器)?