Skip to content

Introduce a new native method to access the master key - #421

Merged
normanmaurer merged 1 commit into
netty:masterfrom
fzakaria:get_master_key
Feb 4, 2019
Merged

normanmaurer merged 1 commit into
netty:masterfrom
fzakaria:get_master_key

Conversation

@fzakaria

Copy link
Copy Markdown
Contributor

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

Accessing the master key is useful if you ever need to decrypt the TLS session for debugging purposes with tools such as Wireshark.

Access of the field from the SSL session struct is direct as the wrapper method was only introduced in 1.1.0+ https://www.openssl.org/docs/man1.1.0/ssl/SSL_SESSION_get_master_key.html

@netty-bot

Copy link
Copy Markdown

Can one of the admins verify this patch?

@normanmaurer

Copy link
Copy Markdown
Member

@netty-bot test this please

Comment thread openssl-dynamic/src/main/c/ssl.c Resolved
Comment thread openssl-dynamic/src/main/c/ssl.c Outdated
size_t SSL_SESSION_get_master_key(const SSL_SESSION *session,
unsigned char *out, size_t outlen)
{
if (outlen == 0)

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.

please use {...}

Comment thread openssl-dynamic/src/main/c/ssl.c Resolved
Comment thread openssl-dynamic/src/main/c/ssl.c Resolved
Comment thread openssl-dynamic/src/main/c/ssl.c Resolved
Comment thread openssl-dynamic/src/main/c/ssl.c Resolved
@fzakaria

Copy link
Copy Markdown
Contributor Author

@normanmaurer Thanks for the comments. I'll address the feedback. I'd like to include a unit test, do you have a good example of how to start a TLS session with the code in this JAR?

I'd only know how to write a test by starting client+server but that would need a cyclic dependency on SslHandler in Netty.

@normanmaurer

Copy link
Copy Markdown
Member

@fzakaria unfortually no :( I guess the best bet is to include a test in Netty itself.

@fzakaria

Copy link
Copy Markdown
Contributor Author

Thanks. I'll work on that for a post PR commit I guess.
A good test would be if in Netty itself I could also keep a copy of the encrypted messages before the engine grabs it and then manually decrypt it as well.

@fzakaria

Copy link
Copy Markdown
Contributor Author

@normanmaurer Addressed your feedback --
I really wanted to include a test for posterity but I've been stuck on getting it to work.

I've packaged the work on the test case so far:
https://gist.github.com/fzakaria/f1de28943c8932280254dd90ffbc4ebd

@fzakaria

Copy link
Copy Markdown
Contributor Author

@normanmaurer I've included a test in netty that proves the methods work by manually decrypting the TLS application data -- netty/netty#8699

@fzakaria

Copy link
Copy Markdown
Contributor Author

@normanmaurer ping

@normanmaurer

Copy link
Copy Markdown
Member

@fzakaria sorry for the delay... Will try to review tomorrow latest.

TCN_ASSERT(bytesMoved == keyLength);

jbyteArray jKey = (*e)->NewByteArray(e, (jsize) bytesMoved);
(*e)->SetByteArrayRegion(e, jKey, 0, bytesMoved, (jbyte*) key);

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.

I think we need to guard against when NewByteArray(...) returns NULL (like if there is no memory left).

@fzakaria fzakaria Jan 31, 2019 •

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 can add the NULL checks however I stuck to previous convention where the other JNI calls did no such guard.
Maybe a separate post-PR to add the null checks to all the methods ?

size_t bytesMoved = SSL_get_server_random(ssl_, key, keyLength);
TCN_ASSERT(bytesMoved == keyLength);

jbyteArray jKey = (*e)->NewByteArray(e, (jsize) bytesMoved);

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.

same as above.

size_t bytesMoved = SSL_SESSION_get_master_key(session, key, keyLength);
TCN_ASSERT(bytesMoved == keyLength);

jbyteArray jKey = (*e)->NewByteArray(e, (jsize) bytesMoved);

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.

same as above

@normanmaurer

Copy link
Copy Markdown
Member

@Lukasa may I ask you to check this as well...

@fzakaria

Copy link
Copy Markdown
Contributor Author

@normanmaurer normanmaurer self-assigned this Feb 4, 2019
@normanmaurer normanmaurer added this to the 2.0.21.Final milestone Feb 4, 2019
@normanmaurer

Copy link
Copy Markdown
Member

@fzakaria please sign our ICLA and let me know once done: https://netty.io/s/icla

I will pull it in after this is done . Thanks for the work!

@normanmaurer
normanmaurer self-requested a review February 4, 2019 08:43
@fzakaria

fzakaria commented Feb 4, 2019

Copy link
Copy Markdown
Contributor Author

Done.

@normanmaurer

Copy link
Copy Markdown
Member

@fzakaria can you do me a favour and squash + adjust the commit message to match our template:

https://netty.io/wiki/writing-a-commit-message.html

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 <[email protected]>
@normanmaurer
normanmaurer merged commit 2eca10a into netty:master Feb 4, 2019
@normanmaurer

Copy link
Copy Markdown
Member

@fzakaria thanks

@fzakaria

fzakaria commented Feb 4, 2019

Copy link
Copy Markdown
Contributor Author

Thanks for merging @normanmaurer
As soon as new version is released -- I will bump the pom.xml in the netty pull-request and it should be good-to-go as well.

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 <[email protected]>
normanmaurer pushed a commit to netty/netty 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 <[email protected]>
normanmaurer pushed a commit to netty/netty 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 <[email protected]>
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.

3 participants