应用程序在具有低于Nougat的os版本的设备中正常运行。 已经给出了服务器的证书(使用firefox下载)。
EXCEPTION CAUSE:
Caused by: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0xabad5f00: Failure in SSL library, usually a protocol error
03-03 20:54:52.507 12993-12993/com.mummysocial W/System.err: error:10000410:SSL routines:OPENSSL_internal:SSLV3_ALERT_HANDSHAKE_FAILURE (external/boringssl/src/ssl/s3_pkt.c:610 0xaba93a80:0x00000001)
03-03 20:54:52.507 12993-12993/com.mummysocial W/System.err: error:1000009a:SSL routines:OPENSSL_internal:HANDSHAKE_FAILURE_ON_CLIENT_HELLO (external/boringssl/src/ssl/s3_clnt.c:764 0xa7dc5912:0x00000000)
03-03 20:54:52.507 12993-12993/com.mummysocial W/System.err: at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
03-03 20:54:52.507 12993-12993/com.mummysocial W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java :357)
03-03 20:54:52.507 12993-12993/com.mummysocial W/System.err: ... 17 more
03-03 20:54:52.507 12993-12993/com.mummysocial W/System.err: Caused by: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0xabad5f00: Failure in SSL library, usually a protocol error
03-03 20:54:52.508 12993-12993/com.mummysocial W/System.err: error:1000043e:SSL routines:OPENSSL_internal:TLSV1_ALERT_INAPPROPRIATE_FALLBACK (external/boringssl/src/ssl/s3_pkt.c:610 0xaba93a80:0x00000001)
03-03 20:54:52.508 12993-12993/com.mummysocial W/System.err: at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
03-03 20:54:52.508 12993-12993/com.mummysocial W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357)
03-03 20:54:52.508 12993-12993/com.mummysocial W/System.err: ... 17 more
03-03 20:54:52.508 12993-12993/com.mummysocial W/System.err: Caused by: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0xabad5f00: Failure in SSL library, usually a protocol error
03-03 20:54:52.508 12993-12993/com.mummysocial W/System.err: error:1000043e:SSL routines:OPENSSL_internal:TLSV1_ALERT_INAPPROPRIATE_FALLBACK (external/boringssl/src/ssl/s3_pkt.c:610 0xaba93a80:0x00000001)
03-03 20:54:52.508 12993-12993/com.mummysocial W/System.err: at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
03-03 20:54:52.508 12993-12993/com.mummysocial W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357)
03-03 20:54:52.508 12993-12993/com.mummysocial W/System.err: ... 17 more
的链接
private SSLSocketFactory getSSLSocketFactory()
throws CertificateException, KeyStoreException, IOException, NoSuchAlgorithmException, KeyManagementException {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
InputStream caInput = getResources().openRawResource(R.raw.ms); // this cert file stored in \app\src\main\res\raw folder path
Certificate ca = cf.generateCertificate(caInput);
caInput.close();
String keyStoreType = KeyStore.getDefaultType();
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(null, null);
keyStore.setCertificateEntry("ca", ca);
String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
tmf.init(keyStore);
//TrustManager[] wrappedTrustManagers = getWrappedTrustManagers(tmf.getTrustManagers());
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, tmf.getTrustManagers(), null);
return sslContext.getSocketFactory();
}
private HostnameVerifier getHostnameVerifier() {
return new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
}
并创建了一个HurlStack变量并将其传递给volley.init()方法。
hurlStack = new HurlStack() {
@Override
protected HttpURLConnection createConnection(URL url) throws IOException {
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) super.createConnection(url);
try {
httpsURLConnection.setSSLSocketFactory(getSSLSocketFactory());
httpsURLConnection.setHostnameVerifier(getHostnameVerifier());
} catch (Exception e) {
e.printStackTrace();
}
return httpsURLConnection;
}
};
MyVolley.init(this,hurlStack);
我的init方法看起来像这样:
public static void init(Context context, HurlStack hurlStack) {
if(mRequestQueue==null) {
mRequestQueue = Volley.newRequestQueue(context,hurlStack);
}
}
我使用firefox下载了证书。并且在Firefox中提到:此证书已经过ssl客户端认证和ssl服务器认证的验证,并且getSSLSOcketFactory()
方法内部正在通过SSLContext.getInstance("TLS")
< - 不知道是否由于这个原因,(我试过了)将此参数更改为“SSL”,但没有成功。