SSL不工作在Android 2.2(仅限2.3) [英] SSL not working on Android 2.2 (only in 2.3)
问题描述
我在LogCat中得到这个被称为当httpsURLConnection.getInputStream()
SSL握手失败:失败的SSL库,通常一个协议 错误错误:14094412:SSL例程:SSL3_READ_BYTES:SSLv3的警报不好 证书(外部/ OpenSSL的/ SSL / s3_pkt.c:1127 0x29eb40:0x00000003)
我已经测试了它的Andorid 2.3和它工作得很好。
我的服务器需要客户端身份验证!也许升级Froyo不支持这种握手......我不知道......
我尝试使用HttpClient的为好。失败在任何情况下...
私人无效处理()抛出异常{
的char []通=clientpass.toCharArray();
InputStream的ksStream = getAssets()开(clientKeyStore.bks)。
密钥库的keyStore = KeyStore.getInstance(BKS);
keyStore.load(ksStream,通);
的KeyManagerFactory KMF = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(密钥库通过);
ksStream.close();
X509TrustManager [] TM =新X509TrustManager [] {新X509TrustManager(){
公共无效checkClientTrusted(x509证书[]链,字符串的authType)抛出CertificateException {
}
公共无效checkServerTrusted(x509证书[]链,字符串的authType)抛出CertificateException {
}
公共x509证书[] getAcceptedIssuers(){
返回新的X509证书[0];
}
}};
的SSL连接上下文= SSLContext.getInstance(TLS);
context.init(kmf.getKeyManagers(),TM,NULL);
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(新的HostnameVerifier(){
公共布尔验证(字符串主机名,的SSLSession会话){
返回true;
}
});
网址URL =新的URL(https://192.168.2.101:8443/RestTomcat/resources/veiculos/KKK1234);
HttpsURLConnection httpsURLConnection =(HttpsURLConnection)url.openConnection();
的BufferedReader BR =新的BufferedReader(新的InputStreamReader(httpsURLConnection.getInputStream()));
StringBuilder的SB =新的StringBuilder();
串线= NULL;
而((行= br.readLine())!= NULL)
sb.append(行+\ N);
br.close();
Log.e(输出,sb.toString());
httpsURLConnection.disconnect();
}
确认日期,时间和时区设置是2.2设备上正确的。
I'm getting this on LogCat when httpsURLConnection.getInputStream() is called
SSL handshake failure: Failure in SSL library, usually a protocol error error:14094412:SSL routines:SSL3_READ_BYTES:sslv3 alert bad certificate (external/openssl/ssl/s3_pkt.c:1127 0x29eb40:0x00000003)
I have tested it on Andorid 2.3 and it works nicely.
My server requires client authentication! Maybe FROYO does not support this kind of handshake... I don't know...
I tried using httpclient as well. Fail in every case...
private void process() throws Exception {
char[] pass = "clientpass".toCharArray();
InputStream ksStream = getAssets().open("clientKeyStore.bks");
KeyStore keyStore = KeyStore.getInstance("BKS");
keyStore.load(ksStream, pass);
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, pass);
ksStream.close();
X509TrustManager[] tm = new X509TrustManager[] { new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
} };
SSLContext context = SSLContext.getInstance("TLS");
context.init(kmf.getKeyManagers(), tm, null);
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
URL url = new URL("https://192.168.2.101:8443/RestTomcat/resources/veiculos/KKK1234");
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(httpsURLConnection.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = br.readLine()) != null)
sb.append(line + "\n");
br.close();
Log.e("OUTPUT", sb.toString());
httpsURLConnection.disconnect();
}
Make sure the date, time and timezone settings are correct on the 2.2 device.
这篇关于SSL不工作在Android 2.2(仅限2.3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!