Skip to content

Introduce TlsMasterKeyHandler#8653

Merged
normanmaurer merged 1 commit intonetty:4.1from
fzakaria:tls-key-handler
Jul 10, 2019
Merged

Introduce TlsMasterKeyHandler#8653
normanmaurer merged 1 commit intonetty:4.1from
fzakaria:tls-key-handler

Conversation

@fzakaria
Copy link
Copy Markdown
Contributor

@fzakaria fzakaria commented Dec 13, 2018

Motivation

Debugging SSL/TLS connections through wireshark is a pain -- if the cipher used involves Diffie-Hellman then it is essentially impossible unless you can have the client dump out the master key [1]

This is a work-in-progress change (tests & comments to come!) that introduces a new handler you can set on the SslContext to receive the master key & session id. I'm hoping to get feedback if a change in this vein would be welcomed.

An implementation that conforms to Wireshark's NSS key log[2] file is also included.

Depending on feedback on the PR going forward I am planning to "clean it up" by adding documentation, example server & tests. Implementation will need to be finished as well for retrieving the master key from the OpenSSL context.

[1] https://jimshaver.net/2015/02/11/decrypting-tls-browser-traffic-with-wireshark-the-easy-way/
[2] https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Key_Log_Format

Modification

I've wired up a new functional handler that gets passed eventually to SSLHandler to be called with the SSL session id & master key.

An implementation of the handler that conforms to Wireshark's key log format is included.

Result

I was able to set the handler to log to a file, which when provided to Wireshark, decrypted the TLS flow.

I did a quick test by modifying HttpHelloWorldServer

            sslCtx = SslContextBuilder
                    .forServer(ssc.certificate(), ssc.privateKey())
                    .sslProvider(SslProvider.JDK)
                    .sslMasterKeyHandler(TlsMasterKeyHandler.WiresharkTlsMasterKeyHandler.INSTANCE)
                    .build();
cat ~/key.log
RSA Session-ID:5c11f6c920488f4dc9891771ae001bd645a16791ab47b337f89136e0deba3cdb Master-Key:6a3aed11200f26d115de4fb7c6aaa01222532520592e93b45ae1e243d4ec06099f4057f3f75616ea6e741c9318f36a30

Fixes #8663

screenshot 2018-12-12 22 36 55

screenshot 2018-12-12 22 37 06

@netty-bot
Copy link
Copy Markdown

Can one of the admins verify this patch?

@normanmaurer
Copy link
Copy Markdown
Member

@fzakaria will check soon. Just a bit busy atm

@fzakaria
Copy link
Copy Markdown
Contributor Author

Sounds good @normanmaurer

@fzakaria
Copy link
Copy Markdown
Contributor Author

@normanmaurer thanks for the feedback.

What do you think overall about the motivation of the PR with respect to having it accepted? I'd like to propose having it submitting in two parts: support for JDK engine (the majority of this pull-request) and a latter commit that introduces it for OpenSSL
(I'm not sure yet on the work needed for netty-tcnative)

If that sounds good, I'd like to address your feedback + clean it up (add comments, tests etc..) to get it ready for approval.

fzakaria pushed a commit to fzakaria/netty-tcnative that referenced this pull request Dec 21, 2018
This change accompanies the broader pull-request introduced by netty/netty#8653
to allow access to the SSL session master key for debugging purposes.
@normanmaurer
Copy link
Copy Markdown
Member

@fzakaria this sounds good yes :)

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 we use PlatformDependent (Which will use usafe) to access it ? This way it will also work with jigsaw.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not familiar with this class: do I just need to access the fieldOffset then get the object ?
(no need to set Accessible on the field?)

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.

Sorry I meant to say use ReflectionUtil 🤦‍♂️

Copy link
Copy Markdown
Member

@normanmaurer normanmaurer left a comment

Choose a reason for hiding this comment

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

left some comments that should be addressed

fzakaria added a commit to fzakaria/netty-tcnative that referenced this pull request Feb 4, 2019
Motivation:

This change accompanies the broader pull-request introduced by netty/netty#8653
to allow access to the SSL session master key for debugging purposes.

For instance, you would be able to log the master key to decrypt the SSL
session in Wireshark.

Modifications:

Exported two new functions through the JNI interface that allow access
to the necessary information to decrypt the SSL session.

Result:

After this change, you can easily decrypt SSL sessions that use
Diffie-Hellman key exchange (perfect forward secrecy) with tools like
Wireshark or decrypt the payloads in Java following the example outlined
https://github.com/netty/netty/pull/8699/files#diff-7a4cbf2f526e2066184fb9ef098cd815R1127

Signed-off-by: Farid Zakaria <farid.m.zakaria@gmail.com>
fzakaria added a commit to fzakaria/netty-tcnative that referenced this pull request Feb 4, 2019
Motivation:

This change accompanies the broader pull-request introduced by netty/netty#8653
to allow access to the SSL session master key for debugging purposes.

For instance, you would be able to log the master key to decrypt the SSL
session in Wireshark.

Modifications:

Exported two new functions through the JNI interface that allow access
to the necessary information to decrypt the SSL session.

Result:

After this change, you can easily decrypt SSL sessions that use
Diffie-Hellman key exchange (perfect forward secrecy) with tools like
Wireshark or decrypt the payloads in Java following the example outlined
https://github.com/netty/netty/pull/8699/files#diff-7a4cbf2f526e2066184fb9ef098cd815R1127

Signed-off-by: Farid Zakaria <farid.m.zakaria@gmail.com>
normanmaurer pushed a commit to netty/netty-tcnative that referenced this pull request Feb 4, 2019
Motivation:

This change accompanies the broader pull-request introduced by netty/netty#8653
to allow access to the SSL session master key for debugging purposes.

For instance, you would be able to log the master key to decrypt the SSL
session in Wireshark.

Modifications:

Exported two new functions through the JNI interface that allow access
to the necessary information to decrypt the SSL session.

Result:

After this change, you can easily decrypt SSL sessions that use
Diffie-Hellman key exchange (perfect forward secrecy) with tools like
Wireshark or decrypt the payloads in Java following the example outlined
https://github.com/netty/netty/pull/8699/files#diff-7a4cbf2f526e2066184fb9ef098cd815R1127

Signed-off-by: Farid Zakaria <farid.m.zakaria@gmail.com>
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 re really lookup the property every time ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've left this in for now -- I'm open to making it once lookup.
I imagined this is largely a test driven handler anyways not to be included in typical pipelines?

Copy link
Copy Markdown
Member

@normanmaurer normanmaurer left a comment

Choose a reason for hiding this comment

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

Can you also add a test ?

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.

final

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

(see note above)

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.

maybe not expose the class directly but just add a static method that returns this instance ?

@fzakaria
Copy link
Copy Markdown
Contributor Author

fzakaria commented Mar 8, 2019

@normanmaurer do you have a good idea for a test or other tests I can draw inspiration from ?
I would need some sort of "TeeClient" that stores the encrypted TLS message (without TLS record header) so that I could then go and decrypt them with the logged master key ?
or
Are we just looking for a more surface-level test for TlsMasterKeyHandler that verifies it gets a non-null key material ?
(leaving the more functional test to the one I introduced in #8699)

@normanmaurer
Copy link
Copy Markdown
Member

@fzakaria no idea for a test yet :(

fzakaria added a commit to fzakaria/netty that referenced this pull request Jun 27, 2019
Motivation:
I've introduced netty/netty-tcnative#421 that introduced exposing OpenSSL master key & client/server
random values with the purpose of allowing someone to log them to debug the traffic via auxiliary tools like Wireshark (see also netty#8653)

Modification:
Augmented OpenSslEngineTest to include a test which manually decrypts the TLS ciphertext
after exposing the masterkey + client/server random. This acts as proof that the tc-native new methods work correctly!

Signed-off-by: Farid Zakaria <farid.m.zakaria@gmail.com>
normanmaurer pushed a commit that referenced this pull request Jun 28, 2019
Motivation:
I've introduced netty/netty-tcnative#421 that introduced exposing OpenSSL master key & client/server
random values with the purpose of allowing someone to log them to debug the traffic via auxiliary tools like Wireshark (see also #8653)

Modification:
Augmented OpenSslEngineTest to include a test which manually decrypts the TLS ciphertext
after exposing the masterkey + client/server random. This acts as proof that the tc-native new methods work correctly!

Result:

More tests

Signed-off-by: Farid Zakaria <farid.m.zakaria@gmail.com>
Copy link
Copy Markdown
Member

@normanmaurer normanmaurer left a comment

Choose a reason for hiding this comment

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

Sorry not done yet and did miss this before .

@normanmaurer
Copy link
Copy Markdown
Member

@netty-bot test this please

@fzakaria
Copy link
Copy Markdown
Contributor Author

fzakaria commented Jul 1, 2019

That's a good point. Let me do that.

@fzakaria
Copy link
Copy Markdown
Contributor Author

fzakaria commented Jul 1, 2019

For those following this pull-request a demo logback.xml would be (just the raw message and new line):

  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>key.log</file>
    <encoder>
      <pattern>%m%n</pattern>
    </encoder>
  </appender>

   <logger name="io.netty.wireshark" addivity="false">
    <appender-ref ref="FILE" />
  </logger>

Don't forget to also -Dio.netty.ssl.masterKeyHandler=true

@normanmaurer
Copy link
Copy Markdown
Member

@netty-bot test this please

@fzakaria
Copy link
Copy Markdown
Contributor Author

fzakaria commented Jul 2, 2019

Yes it passed :)
6 months in the making this PR 👍

@normanmaurer normanmaurer added this to the 4.1.38.Final milestone Jul 3, 2019
Debugging SSL/TLS connections through wireshark is a pain --
if the cipher used involves Diffie-Hellman then it is
essentially impossible unless you can have the client dump
out the master key.

Introduce a new TLS handler which accepts the master key
of the TLS session. An implementation that conforms to
Wireshark's NSS key log format is included.

Signed-off-by: Farid Zakaria <farid.m.zakaria@gmail.com>
@fzakaria
Copy link
Copy Markdown
Contributor Author

fzakaria commented Jul 3, 2019

@carl-mastrangelo responded to your feedback.

Copy link
Copy Markdown
Member

@carl-mastrangelo carl-mastrangelo left a comment

Choose a reason for hiding this comment

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

LGTM

@fzakaria
Copy link
Copy Markdown
Contributor Author

@normanmaurer good to go ? :P

@normanmaurer
Copy link
Copy Markdown
Member

@netty-bot test this please

@normanmaurer normanmaurer merged commit 7fc355a into netty:4.1 Jul 10, 2019
@normanmaurer
Copy link
Copy Markdown
Member

@fzakaria thanks a lot!

normanmaurer pushed a commit that referenced this pull request Jul 10, 2019
Motivation

Debugging SSL/TLS connections through wireshark is a pain -- if the cipher used involves Diffie-Hellman then it is essentially impossible unless you can have the client dump out the master key [1]

This is a work-in-progress change (tests & comments to come!) that introduces a new handler you can set on the SslContext to receive the master key & session id. I'm hoping to get feedback if a change in this vein would be welcomed.

An implementation that conforms to Wireshark's NSS key log[2] file is also included.

Depending on feedback on the PR going forward I am planning to "clean it up" by adding documentation, example server & tests. Implementation will need to be finished as well for retrieving the master key from the OpenSSL context.

[1] https://jimshaver.net/2015/02/11/decrypting-tls-browser-traffic-with-wireshark-the-easy-way/
[2] https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Key_Log_Format

Modification

- Added SslMasterKeyHandler
- An implementation of the handler that conforms to Wireshark's key log format is included.

Result:

Be able to debug SSL / TLS connections more easily.

Signed-off-by: Farid Zakaria <farid.m.zakaria@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow easier TLS debugging by Wireshark

4 participants