Repository navigation
OpenSSL ByteBuffer BIO - #6201
Scottmitch wants to merge 1 commit into
Conversation
|
|
7ebf55f to
13266f9
Compare
13266f9 to
e7aaa16
Compare
There was a problem hiding this comment.
@normanmaurer - this is meant to be a discussion point.
e7aaa16 to
8661327
Compare
There was a problem hiding this comment.
@normanmaurer will update this before the next release
c2bbaab to
affc6ac
Compare
There was a problem hiding this comment.
@Scottmitch can we ensure we also release when the assert fails. Just in case :)
There was a problem hiding this comment.
I don't think this is necessary. The assert signifies a programatic error and was added to aid development and unit tests. Do you have a suggestion which doesn't introduce runtime checks or additional try/catch?
There was a problem hiding this comment.
@Scottmitch I think we can remove this via a constructor option ? Like strict and non-strict mode ?
There was a problem hiding this comment.
@normanmaurer - great! I noticed this was thrashing a lot during my testing. let me break this out into another PR.
There was a problem hiding this comment.
@Scottmitch can you open an issue and link it here ?
There was a problem hiding this comment.
false alarm ... issue was pre-existing but has been fixed in this PR.
There was a problem hiding this comment.
@Scottmitch like discussed before I think we should factor this out in a separate PR.
6039419 to
c6ab13f
Compare
There was a problem hiding this comment.
The OpenSSL team has advised against doing this. The current approach involving SSL.SSL_ST_ACCEPT had issues so I fixed them in this PR and will investigate removal in of SSL.SSL_ST_ACCEPT in #6320.
Motivation: Currently Netty utilizes BIO_new_bio_pair so we can control all FD lifetime and event notification but delegates to OpenSSL for encryption/decryption. The current implementation sets up a pair of BIO buffers to read/write encrypted/plaintext data. This approach requires copying of data from Java ByteBuffers to native memory BIO buffers, and also requires both BIO buffers to be sufficiently large to hold application data. If direct ByteBuffers are used we can avoid coyping to/from the intermediate BIO buffer and just read/write directly from the direct ByteBuffer memory. We still need an internal buffer because OpenSSL may generate write data as a result of read calls (e.g. handshake, alerts, renegotiation, etc..), but this buffer doesn't have to be be large enough to hold application data. Modifications: - Take advantage of the new ByteBuffer based BIO provided by netty-tcnative instead of using BIO_read and BIO_write. Result: Less copying and lower memory footprint requirement per TLS connection.
c6ab13f to
40d8b45
Compare
| AccessController.doPrivileged(new PrivilegedAction<Integer>() { | ||
| @Override | ||
| public Integer run() { | ||
| return Math.max(1, |
There was a problem hiding this comment.
why 1 and not 0 (which will use the default then) ?
There was a problem hiding this comment.
I removed support for the default at the tcnative level, and disallowed setting 0. Users should explicitly set the size they want. Default of 16k is likely way to big anyways.
Also not having a buffer is not an option because I don't know of a way to ask SSL how much data it has pending (SSL_pending didn't work) ... so we can't distinguish between NEED_WRAP and NEED_UNWRAP when SSL wants to write some non-application data.
|
LGTM... Thanks! |
Motivation:
Currently Netty utilizes BIO_new_bio_pair so we can control all FD lifetime and event notification but delegates to OpenSSL for encryption/decryption. The current implementation sets up a pair of BIO buffers to read/write encrypted/plaintext data. This approach requires copying of data from Java ByteBuffers to native memory BIO buffers, and also requires both BIO buffers to be sufficiently large to hold application data. If direct ByteBuffers are used we can avoid coyping to/from the intermediate BIO buffer and just read/write directly from the direct ByteBuffer memory. We still need an internal buffer because OpenSSL may generate write data as a result of read calls (e.g. handshake, alerts, renegotiation, etc..), but this buffer doesn't have to be be large enough to hold application data.
Modifications:
Result:
Less copying and lower memory footprint requirement per TLS connection.