[英]Is Java SSL broken in OpenJDK on Ubuntu?
I am on a fresh install of Ubuntu having just installed OpenJDK: 我在刚刚安装OpenJDK的Ubuntu的全新安装中:
OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode) on Ubuntu 64 bit 10.10
Not sure if this is relevant, but I'm running it from within VMWare Fusion. 不知道这是否相关,但是我正在VMWare Fusion中运行它。
The following line: 下一行:
javax.net.SSLContext.getDefault(); // same as getInstance("Default")
throws the following exception:
java.net.SocketException: java.security.NoSuchAlgorithmException: Default SSLContext not available
My colleagues and I have tried this on several machines, all fresh installs of Ubuntu, and keep getting this. 我和我的同事已经在几台计算机上尝试了这一点,所有这些都是Ubuntu的全新安装,并且一直在使用。 I was advised to try getInstance("TLSv1"), but this threw the same error.
建议我尝试getInstance(“ TLSv1”),但这会引发相同的错误。 Seems like something really fundamental to not be working so I figure we must be doing something wrong.
似乎有些根本不起作用的东西,所以我认为我们一定做错了。
guido's answer pointed me in the right direction. guido的回答为我指明了正确的方向。 It's just a matter of doing:
这只是一个问题:
sudo apt-get install libbcprov-java
openjdk shipped with ubuntu may be missing a JCE provider; ubuntu附带的openjdk可能缺少JCE提供程序; download the bouncycastle crypto api from http://www.bouncycastle.org/ (its an open source project implementing JCE) and put it in your project classpath.
从http://www.bouncycastle.org/下载bouncycastle crypto api(这是一个实现JCE的开源项目),并将其放在您的项目类路径中。
Then in your class refer to the following sample code: 然后在您的班级中,参考以下示例代码:
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; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.