Repository navigation
Correct guard against non SSL data in ReferenceCountedOpenSslEngine - #6089
normanmaurer wants to merge 1 commit into
Conversation
|
@nmittler you also want this for conscrypt |
9b74f31 to
6c9597d
Compare
|
@Scottmitch PTAL |
|
|
||
| int packetLength = SslUtils.getEncryptedPacketLength(srcs, srcsOffset); | ||
|
|
||
| if (packetLength == SslUtils.NOT_ENCRYPTED) { |
There was a problem hiding this comment.
should this go above the BUFFER_UNDERFLOW above?
There was a problem hiding this comment.
@Scottmitch its the same order in the JDK implementation. So let me keep it like this
There was a problem hiding this comment.
@normanmaurer - can you provide a link? From what I can tell it looks like the JDK does this check up front.
http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/8b04ee324a1a/src/share/classes/sun/security/ssl/SSLEngineImpl.java#l868 -> http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/8b04ee324a1a/src/share/classes/sun/security/ssl/EngineInputRecord.java#l156
Also it doesn't make sense to report underflow/overflow if the data isn't legitimate.
There was a problem hiding this comment.
Brain fart... let me change
There was a problem hiding this comment.
@Scottmitch actually no... we need to keep it as it is as we need to have at least 5 bytes to call SslUtils.getEncryptedPacketLength(srcs, srcsOffset);.
Also I don't think it really matters too much... I mean at worst we will just delay the detection until we have at least 5 bytes ready to be read.
Agree ?
| } | ||
| if (writerIndex - readerIndex - SslUtils.SSL_RECORD_HEADER_LENGTH < len) { | ||
| if (writerIndex - readerIndex - SslUtils.SSL_RECORD_HEADER_LENGTH < len || | ||
| len == SslUtils.NOT_ENOUGH_DATA) { |
There was a problem hiding this comment.
consider switching the order of conditionals to short circuit if the arithmetic may not make sense because len is a "special" value
Motivation: When non SSL data is passed into SSLEngine.unwrap(...) we need to throw an SSLException. This was not done at the moment. Even worse we threw an IllegalArgumentException as we tried to allocate a direct buffer with capacity of -1. Modifications: - Guard against non SSL data and added an unit test. - Make code more consistent Result: Correct behaving SSLEngine implementation.
6c9597d to
1f5e062
Compare
|
@Scottmitch PTAL again |
|
|
||
| int packetLength = SslUtils.getEncryptedPacketLength(srcs, srcsOffset); | ||
|
|
||
| if (packetLength == SslUtils.NOT_ENCRYPTED) { |
There was a problem hiding this comment.
@normanmaurer - can you provide a link? From what I can tell it looks like the JDK does this check up front.
http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/8b04ee324a1a/src/share/classes/sun/security/ssl/SSLEngineImpl.java#l868 -> http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/8b04ee324a1a/src/share/classes/sun/security/ssl/EngineInputRecord.java#l156
Also it doesn't make sense to report underflow/overflow if the data isn't legitimate.
Motivation:
When non SSL data is passed into SSLEngine.unwrap(...) we need to throw an SSLException. This was not done at the moment. Even worse we threw an IllegalArgumentException as we tried to allocate a direct buffer with capacity of -1.
Modifications:
Result:
Correct behaving SSLEngine implementation.