我已经使用“TLSv1”协议为客户端-服务器通信添加了自签名证书,在所有设备中都能完美运行,但在握手过程中的 Android Q 预览中出现以下异常
错误可以从procedtoUnsafe产生或从浏览器添加异常
D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=9551, firebase_screen_class(_sc)=HomeActivity, firebase_screen_id(_si)=-2452361814686810599}]
D/FA: Connected to remote service
W/antra.rdservic: Accessing hidden method Ljava/net/InetAddress;->holder()Ljava/net/InetAddress$InetAddressHolder; (greylist, reflection, allowed)
W/antra.rdservic: Accessing hidden method Ljava/net/InetAddress$InetAddressHolder;->getOriginalHostName()Ljava/lang/String; (greylist-max-o, reflection, denied)
W/antra.rdservic: Accessing hidden method Ldalvik/system/CloseGuard;->close()V (greylist,core-platform-api, linking, allowed)
W/System.err: javax.net.ssl.SSLHandshakeException: Handshake failed
W/System.err: at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(:com.google.android.gms@17122037@17.1.22 (100400-245988633):35)
W/System.err: at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.waitForHandshake(:com.google.android.gms@17122037@17.1.22 (100400-245988633):1)
W/System.err: at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.getOutputStream(:com.google.android.gms@17122037@17.1.22 (100400-245988633):5)
W/System.err: at com.mantra.rdservice.sslservice.SslServer.runSecureServer(SslServer.java:121)
W/System.err: at com.mantra.rdservice.sslservice.SslServer.runServer(SslServer.java:157)
W/System.err: at com.mantra.rdservice.sslservice.SslServer.findPort(SslServer.java:106)
W/System.err: at com.mantra.rdservice.sslservice.SecureService$1.run(SecureService.java:74)
W/System.err: at java.lang.Thread.run(Thread.java:919)
W/System.err: Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xc386a398: Failure in SSL library, usually a protocol error
W/System.err: error:10000416:SSL routines:OPENSSL_internal:SSLV3_ALERT_CERTIFICATE_UNKNOWN (third_party/openssl/boringssl/src/ssl/tls_record.cc:587 0xc5e7a888:0x00000001)
W/System.err: at com.google.android.gms.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
W/System.err: at com.google.android.gms.org.conscrypt.NativeSsl.doHandshake(:com.google.android.gms@17122037@17.1.22 (100400-245988633):7)
W/System.err: at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(:com.google.android.gms@17122037@17.1.22 (100400-245988633):14)
W/System.err: ... 7 more
W/antra.rdservic: Accessing hidden method Ljava/net/InetAddress$InetAddressHolder;->getOriginalHostName()Ljava/lang/String; (greylist-max-o, reflection, denied)
W/antra.rdservic: Accessing hidden method Ljava/net/InetAddress$InetAddressHolder;->getOriginalHostName()Ljava/lang/String; (greylist-max-o, reflection, denied)
我添加了创建连接的功能
Loopback ="127.0.0.1";
private void runSecureServer(final int port) throws Exception {
final ServerSocket socket = createSSLSocket();
socket.bind(new InetSocketAddress(Loopback, port));
socket.setReuseAddress(true);
this._url = "https://" + Loopback + ":" + String.valueOf(port) + "/";
while (true) {
try {
Socket client = socket.accept();
PrintWriter outputStream = new PrintWriter(client.getOutputStream(), true);
BufferedReader inputStream = new BufferedReader(new InputStreamReader(client.getInputStream()));
StringBuilder finalData = new StringBuilder();
String inputLine;
while ((inputLine = inputStream.readLine()) != null && !inputLine.equals("")) {
finalData.append(inputLine).append("\r\n");
}
executorService.execute(new HttpProcessor(ctx, _url, client, outputStream, inputStream, finalData.toString()));
} catch (Exception ex) {
ex.printStackTrace();
socket.close();
runServer(port);
break;
}
}
}
我提到了 StackOverflow问题,但没有找到解决方案