Dea*_*nna 14 java https android bouncycastle keystore
我正在尝试与证书设置为2013年4月到期的服务器建立HTTPS连接,并使用GlobalSign作为根证书.
HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
// urlConnection.setSSLSocketFactory(sslSocketFactory);
urlConnection.setDoOutput(true);
urlConnection.setChunkedStreamingMode(0);
// Send the POST data
OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
out.write(postParamString.toString().getBytes("UTF8"));
// Read the reply
InputStream in = urlConnection.getInputStream();
Run Code Online (Sandbox Code Playgroud)
就目前而言,这会javax.net.ssl.SSLHandshakeException: org.bouncycastle.jce.exception.ExtCertPathValidatorException: Could not validate certificate signature.在getOutputStream()被召唤时抛出.
此相同的站点和证书在HTC Web浏览器和桌面浏览器中有效.当我使用相同的代码访问Google时,它可以工作(但随后会抱怨404错误).StackOverflow上的各种帖子暗示它应该"正常工作"而其他人说要设置自己的密钥库(或禁用所有HTTPS验证!)我假设行为的差异归结为使用中的不同根密钥库(任何人都可以澄清这一点?).
我现在尝试使用充气城堡创建一个密钥库,但我无法将其加载到我的设备上.
从Firefox导出证书后,我使用以下方法创建密钥库:
keytool.exe -import -alias onlinescoutmanager -file www.onlinescoutmanager.co.uk.crt -storetype BKS -keystore res\raw\keystore
Run Code Online (Sandbox Code Playgroud)
然后使用以下命令加载并在应用程序中使用:
InputStream stream = context.getResources().openRawResource(R.raw.keystore);
// BKS seems to be the default but we want to be explicit
KeyStore ks = KeyStore.getInstance("BKS");
ks.load(stream, "www.onlinescoutmanager.co.uk".toCharArray());
stream.close();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ks);
X509TrustManager defaultTrustManager = (X509TrustManager) tmf.getTrustManagers()[0];
SSLContext context2 = SSLContext.getInstance("TLS");
context2.init(null, new TrustManager[] { defaultTrustManager }, null);
sslSocketFactory = context2.getSocketFactory();
Run Code Online (Sandbox Code Playgroud)
调用java.io.IOException: Wrong version of key store.时失败了keystore.Load().
我确保我正在通过-storetype BKS,使用<= 7个字符的密钥库密码,将CA证书添加到密钥存储区,并使用Bouncy Castle版本1.45和1.47创建密钥存储区,而不报告错误消息.
我的环境是Eclipse Juno 4.2.1,在Windows 8上运行JRE 1.7u9b5.我正在测试的设备是HTC感觉运行的股票Android 2.3.该应用程序的最低SDK版本为7,目标为15.
如果有人可以解释如何在Windows 8上创建有效的BKS密钥存储区,或者我如何让Java使用与浏览器(或系统?)相同的密钥存储区,这将是值得赞赏的.
Bouncy Castle 1.47 使用不同的版本标头。你可以尝试一下1.46版本,它应该可以工作。
keytool -import -alias onlinescoutmanager -file www.onlinescoutmanager.co.uk.crt -storetype BKS -storepass osmosm -keystore C:/keystore -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath bcprov-ext-jdk15on-1.46.jar
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11446 次 |
| 最近记录: |