GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add a bypass for getting a non-read-only ByteBuffer from ReadableComponent by chrisvest · Pull Request #12213 · netty/netty

Conversation

@chrisvest

@chrisvest chrisvest commented Mar 22, 2022

Copy link
Copy Markdown
Member

Motivation:
The JDK SSLEngine implementation apparently cannot decode TLS packets out of ByteBuffers that are read-only.

Modification:
Make it possible to bypass the read-only restriction on ReadableComponent.readableBuffer().

Result:
When the SslHandler is ported to use Buffer, it will not run into this problem that would have prevented us from being able to decode any TLS packets.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@chrisvest
chrisvest requested a review from normanmaurer March 22, 2022 19:50
@normanmaurer

normanmaurer commented Mar 22, 2022

Copy link
Copy Markdown
Member

@chrisvest this is surprising... what happened when you used read-only ? exceptions ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisvest

chrisvest commented Mar 22, 2022

Copy link
Copy Markdown
Member Author

@normanmaurer Yes, you get an exception somewhere deep inside handshake decoding. I think it's a JDK bug, but we'll have to work around it regardless.

normanmaurer reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer

normanmaurer commented Mar 22, 2022

Copy link
Copy Markdown
Member

@chrisvest we should open a JDK bug for it . Can you please send an email to the security-dev mailing list with your findings and include the stacktrace ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisvest
Add a bypass for getting a non-read-only ByteBuffer from ReadableComp…
07b9c55
…onent

Motivation:
The JDK `SSLEngine` implementation apparently cannot *decode* TLS packets out of `ByteBuffers` that are read-only.

Modification:
Make it possible to bypass the read-only restriction on `ReadableComponent.readableBuffer()`.

Result:
When the `SslHandler` is ported to use `Buffer`, it will not run into this problem that would have prevented us from being able to decode any TLS packets.
@chrisvest
chrisvest force-pushed the 5x-writing-to-readable-component-bypass branch from 6e9f291 to 07b9c55 Compare March 22, 2022 20:11
@chrisvest

chrisvest commented Mar 23, 2022

Copy link
Copy Markdown
Member Author

@normanmaurer Reported: https://mail.openjdk.java.net/pipermail/security-dev/2022-March/029478.html

normanmaurer reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

normanmaurer
normanmaurer approved these changes Mar 23, 2022
View reviewed changes
@chrisvest
chrisvest merged commit bf8260d into netty:main Mar 23, 2022
@chrisvest
chrisvest deleted the 5x-writing-to-readable-component-bypass branch March 23, 2022 17:57
@chrisvest

chrisvest commented Mar 23, 2022

Copy link
Copy Markdown
Member Author

https://bugs.openjdk.java.net/browse/JDK-8283577

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisvest

chrisvest commented Mar 24, 2022

Copy link
Copy Markdown
Member Author

For the record, the JDK issue shows up at the end of the handshake, as is demonstrated by something like this:

SelfSignedCertificate ssc = new SelfSignedCertificate();
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null, null);
ks.setKeyEntry("key", ssc.key(), new char[0], new X509Certificate[] { ssc.cert() });
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(ks, new char[0]);
SSLContext context = SSLContext.getInstance("TLS");
context.init(keyManagerFactory.getKeyManagers(), null, null);
SSLEngine client = context.createSSLEngine();
SSLEngine server = context.createSSLEngine();
client.setUseClientMode(true);
server.setUseClientMode(false);
ByteBuffer cp = ByteBuffer.allocate(32 * 1024); // Packet from client.
ByteBuffer sp = ByteBuffer.allocate(32 * 1024); // Packet from server.
SSLEngineResult result;

{
    // Client initiates handshake.
    result = client.wrap(ByteBuffer.allocate(0), cp);
    assert result.getHandshakeStatus() == HandshakeStatus.NEED_UNWRAP;
}
{
    // Server received ClientHello and responds with ServerHello.
    ByteBuffer packet = cp.flip().asReadOnlyBuffer();
    sp.clear();

    result = server.unwrap(packet, sp);
    assert result.getHandshakeStatus() == HandshakeStatus.NEED_TASK;
    server.getDelegatedTask().run();
    result = server.wrap(packet, sp);
    assert result.getHandshakeStatus() == HandshakeStatus.NEED_WRAP;
    result = server.wrap(packet, sp);
    assert result.getHandshakeStatus() == HandshakeStatus.NEED_WRAP;
    result = server.wrap(packet, sp);
    assert result.getHandshakeStatus() == HandshakeStatus.NEED_UNWRAP;
}
{
    // Client receives ServerHello.
    ByteBuffer packet = sp.flip().asReadOnlyBuffer();
    cp.clear();

    result = client.unwrap(packet, cp);
    assert result.getHandshakeStatus() == HandshakeStatus.NEED_TASK;
    client.getDelegatedTask().run();
    result = client.wrap(packet, cp);
    assert result.getHandshakeStatus() == HandshakeStatus.NEED_UNWRAP;
    result = client.unwrap(packet, cp);
    assert result.getHandshakeStatus() == HandshakeStatus.NEED_UNWRAP;
    result = client.unwrap(packet, cp); // ReadOnlyBufferException.
}
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisvest chrisvest added this to the 5.0.0.Alpha2 milestone May 16, 2022
@chrisvest chrisvest added the netty5 label Feb 13, 2024
@lhotari lhotari mentioned this pull request May 27, 2024
Support read-only input buffers in SslHandler #14079
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@normanmaurer normanmaurer normanmaurer approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

netty5

Projects

None yet

Milestone

5.0.0.Alpha2

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@chrisvest @normanmaurer
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.