<div dir="ltr"><div dir="ltr">On Wed, Mar 23, 2022 at 10:38 AM Bradford Wetmore <<a href="mailto:bradford.wetmore@oracle.com">bradford.wetmore@oracle.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Offhand, sounds like a bug to me. I've filed:<br>
<br>
<a href="https://bugs.openjdk.java.net/browse/JDK-8283577" rel="noreferrer" target="_blank">https://bugs.openjdk.java.net/browse/JDK-8283577</a></blockquote><div><br></div><div>Thanks. The in-place use of the input buffer might also be unexpected even when the buffer is not read-only.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
By chance, do you have a simple reproducer handy?<br></blockquote><div><br></div><div>See <a href="https://github.com/netty/netty/pull/12213#issuecomment-1077796917">https://github.com/netty/netty/pull/12213#issuecomment-1077796917</a></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
Brad<br>
<br>
<br>
<br>
On 3/23/2022 9:54 AM, Chris Vest wrote:<br>
> Hi,<br>
> <br>
> In Netty we've been trying to design some safer APIs, and attempted to <br>
> make more use of read-only ByteBuffers.<br>
> <br>
> We discovered that SSLEngine.unwrap does not like read-only input <br>
> buffers, even though the input buffers should in theory only be read <br>
> from. We obviously make sure that the output buffers are writable.<br>
> <br>
> By my reading of the javadoc, and the code, I believe this was intended <br>
> to work - or at least not intended to not work - but probably wasn't <br>
> tested directly.<br>
> <br>
> When we try we get this stack trace on adopt-openjdk-11.0.7:<br>
> <br>
> javax.net.ssl.SSLProtocolException: null<br>
> at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:129)<br>
> at<br>
> java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:326)<br>
> at<br>
> java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:269)<br>
> at<br>
> java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:264)<br>
> at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:118)<br>
> at<br>
> java.base/sun.security.ssl.SSLEngineImpl.decode(SSLEngineImpl.java:668)<br>
> at<br>
> java.base/sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:623)<br>
> at<br>
> java.base/sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:441)<br>
> at<br>
> java.base/sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:420)<br>
> at java.base/javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:674)<br>
> at io.netty5.handler.ssl.EngineWrapper.unwrap(EngineWrapper.java:100)<br>
> at io.netty5.handler.ssl.SslHandler.unwrap(SslHandler.java:1227)<br>
> at<br>
> io.netty5.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1105)<br>
> at io.netty5.handler.ssl.SslHandler.decode(SslHandler.java:1165)<br>
> at<br>
> io.netty5.handler.codec.ByteToMessageDecoderForBuffer.decodeRemovalReentryProtection(ByteToMessageDecoderForBuffer.java:384)<br>
> at<br>
> io.netty5.handler.codec.ByteToMessageDecoderForBuffer.callDecode(ByteToMessageDecoderForBuffer.java:327)<br>
> ... 20 common frames omitted<br>
> Caused by: java.nio.ReadOnlyBufferException: null<br>
> at java.base/javax.crypto.Cipher.doFinal(Cipher.java:2493)<br>
> at<br>
> java.base/sun.security.ssl.SSLCipher$T12GcmReadCipherGenerator$GcmReadCipher.decrypt(SSLCipher.java:1629)<br>
> at<br>
> java.base/sun.security.ssl.SSLEngineInputRecord.decodeInputRecord(SSLEngineInputRecord.java:240)<br>
> at<br>
> java.base/sun.security.ssl.SSLEngineInputRecord.decode(SSLEngineInputRecord.java:197)<br>
> at<br>
> java.base/sun.security.ssl.SSLEngineInputRecord.decode(SSLEngineInputRecord.java:160)<br>
> at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:108)<br>
> ... 31 common frames omitted<br>
> <br>
> <br>
> I also tried this on a panama-preview snapshot JDK I have, and got a <br>
> similar stack trace:<br>
> <br>
> % java -version<br>
> openjdk version "19-internal" 2022-09-20<br>
> OpenJDK Runtime Environment (fastdebug build<br>
> 19-internal-adhoc.chris.panama-foreign)<br>
> OpenJDK 64-Bit Server VM (fastdebug build<br>
> 19-internal-adhoc.chris.panama-foreign, mixed mode)<br>
> <br>
> <br>
> % git show<br>
> commit 144af9f43cd2d6f88b675b8c85e4034e5b9d6695 (HEAD -><br>
> foreign-preview, origin/foreign-preview)<br>
> <br>
> <br>
> javax.net.ssl.SSLProtocolException: null<br>
> at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:129)<br>
> at<br>
> java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:371)<br>
> at<br>
> java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:314)<br>
> at<br>
> java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:309)<br>
> at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:121)<br>
> at<br>
> java.base/sun.security.ssl.SSLEngineImpl.decode(SSLEngineImpl.java:736)<br>
> at<br>
> java.base/sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:691)<br>
> at<br>
> java.base/sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:506)<br>
> at<br>
> java.base/sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:482)<br>
> at java.base/javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:719)<br>
> at io.netty5.handler.ssl.EngineWrapper.unwrap(EngineWrapper.java:100)<br>
> at io.netty5.handler.ssl.SslHandler.unwrap(SslHandler.java:1227)<br>
> at<br>
> io.netty5.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1105)<br>
> at io.netty5.handler.ssl.SslHandler.decode(SslHandler.java:1165)<br>
> at<br>
> io.netty5.handler.codec.ByteToMessageDecoderForBuffer.decodeRemovalReentryProtection(ByteToMessageDecoderForBuffer.java:384)<br>
> at<br>
> io.netty5.handler.codec.ByteToMessageDecoderForBuffer.callDecode(ByteToMessageDecoderForBuffer.java:327)<br>
> ... 20 common frames omitted<br>
> Caused by: java.nio.ReadOnlyBufferException: null<br>
> at java.base/javax.crypto.Cipher.doFinal(Cipher.java:2497)<br>
> at<br>
> java.base/sun.security.ssl.SSLCipher$T13GcmReadCipherGenerator$GcmReadCipher.decrypt(SSLCipher.java:1933)<br>
> at<br>
> java.base/sun.security.ssl.SSLEngineInputRecord.decodeInputRecord(SSLEngineInputRecord.java:239)<br>
> at<br>
> java.base/sun.security.ssl.SSLEngineInputRecord.decode(SSLEngineInputRecord.java:196)<br>
> at<br>
> java.base/sun.security.ssl.SSLEngineInputRecord.decode(SSLEngineInputRecord.java:159)<br>
> at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:111)<br>
> ... 31 common frames omitted<br>
> <br>
> <br>
> We can work around this in Netty since we need to support JDK versions <br>
> that has this issue anyway, but I think it's a bug that should be fixed <br>
> at some point.<br>
> <br>
> Thanks,<br>
> Chris<br>
> <br>
</blockquote></div></div>