Skip to content

Correct guard against non SSL data in ReferenceCountedOpenSslEngine - #6089

Closed
normanmaurer wants to merge 1 commit into
4.1from
ssl_engine_non_ssl_data
Closed

normanmaurer wants to merge 1 commit into
4.1from
ssl_engine_non_ssl_data

Conversation

@normanmaurer

Copy link
Copy Markdown
Member

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.

@normanmaurer

Copy link
Copy Markdown
Member Author

@nmittler you also want this for conscrypt

@normanmaurer
normanmaurer force-pushed the ssl_engine_non_ssl_data branch from 9b74f31 to 6c9597d Compare December 1, 2016 18:47
@normanmaurer

Copy link
Copy Markdown
Member Author

@Scottmitch PTAL


int packetLength = SslUtils.getEncryptedPacketLength(srcs, srcsOffset);

if (packetLength == SslUtils.NOT_ENCRYPTED) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this go above the BUFFER_UNDERFLOW above?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Scottmitch its the same order in the JDK implementation. So let me keep it like this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brain fart... let me change

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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 ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@normanmaurer - good point ... fine as is

}
if (writerIndex - readerIndex - SslUtils.SSL_RECORD_HEADER_LENGTH < len) {
if (writerIndex - readerIndex - SslUtils.SSL_RECORD_HEADER_LENGTH < len ||
len == SslUtils.NOT_ENOUGH_DATA) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider switching the order of conditionals to short circuit if the arithmetic may not make sense because len is a "special" value

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@normanmaurer
normanmaurer force-pushed the ssl_engine_non_ssl_data branch from 6c9597d to 1f5e062 Compare December 2, 2016 06:51
@normanmaurer

Copy link
Copy Markdown
Member Author

@Scottmitch PTAL again

@normanmaurer normanmaurer self-assigned this Dec 2, 2016
@normanmaurer normanmaurer added this to the 4.0.43.Final milestone Dec 2, 2016

int packetLength = SslUtils.getEncryptedPacketLength(srcs, srcsOffset);

if (packetLength == SslUtils.NOT_ENCRYPTED) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@normanmaurer

Copy link
Copy Markdown
Member Author

Cherry-picked into 4.1 (0ca2c30) and 4.0 (4d32746)

@normanmaurer
normanmaurer deleted the ssl_engine_non_ssl_data branch December 4, 2016 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants