为了准备Java 11及更高版本,我目前正致力于将我们的应用程序从Java 8迁移到Java 10.我在我们的一个测试中遇到了一个问题,我们期望由于发送错误而导致SSLHandshakeException证书。而不是接收提到的异常,而是应用程序抛出SocketException。
意外SocketException的堆栈跟踪:
Yes
预期的SSLHandshakeException的堆栈跟踪如下所示:
java.lang.Exception: Unexpected exception, expected<javax.net.ssl.SSLHandshakeException> but was<java.net.SocketException>
Caused by: java.net.SocketException: Datenübergabe unterbrochen (broken pipe) (Write failed)
at java.base/java.net.SocketOutputStream.socketWrite0(Native Method)
at java.base/java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)
at java.base/java.net.SocketOutputStream.write(SocketOutputStream.java:155)
at java.base/sun.security.ssl.SSLSocketOutputRecord.flush(SSLSocketOutputRecord.java:236)
at java.base/sun.security.ssl.HandshakeOutStream.flush(HandshakeOutStream.java:79)
at java.base/sun.security.ssl.Handshaker.sendChangeCipherSpec(Handshaker.java:1208)
at java.base/sun.security.ssl.ClientHandshaker.sendChangeCipherAndFinish(ClientHandshaker.java:1408)
at java.base/sun.security.ssl.ClientHandshaker.serverHelloDone(ClientHandshaker.java:1312)
at java.base/sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:418)
at java.base/sun.security.ssl.Handshaker.processLoop(Handshaker.java:1098)
at java.base/sun.security.ssl.Handshaker.processRecord(Handshaker.java:1026)
at java.base/sun.security.ssl.SSLSocketImpl.processInputRecord(SSLSocketImpl.java:1137)
at java.base/sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1074)
at java.base/sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
at java.base/sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1402)
at java.base/sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:733)
at java.base/sun.security.ssl.AppOutputStream.write(AppOutputStream.java:67)
at java.base/sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:233)
at java.base/sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:312)
at java.base/sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:316)
at java.base/sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:153)
at java.base/java.io.OutputStreamWriter.flush(OutputStreamWriter.java:254)
at java.base/java.io.BufferedWriter.flush(BufferedWriter.java:257)
at de.sourcepark.security.cryptolib.ssl.DefaultSSLContextProviderTest.testMutualAuthFail(DefaultSSLContextProviderTest.java:203)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:21)
... 23 more
通过阅读Java 9和10的发行说明,我已经收集到他们改变了一些关于SSL / TLS的东西,但我还没有发现任何提及这种特殊行为的事情。
在发送错误证书后现在预期的行为是否收到SocketException?如果没有,可能会出错?如果是这样,为什么要做出这种改变?我知道他们计划从JEP 332开始将TLS 1.3集成到Java 11中。这可能是原因吗?
我感到茫然,不胜感激任何帮助,谢谢你们。