Add -msg and -servername support to openssl s_client#3098
Add -msg and -servername support to openssl s_client#3098
Conversation
Add -msg flag with full implementation using SSL_set_msg_callback to print TLS protocol messages in OpenSSL-compatible format. Add -servername flag that maps to DoClient's existing -server-name for SNI support.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3098 +/- ##
==========================================
+ Coverage 78.19% 78.33% +0.14%
==========================================
Files 689 689
Lines 122037 122099 +62
Branches 17026 17036 +10
==========================================
+ Hits 95430 95652 +222
+ Misses 25701 25540 -161
- Partials 906 907 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
justsmth
left a comment
There was a problem hiding this comment.
Could we add a few tests to cover the new options?
| static const char *MsgHandshakeTypeStr(uint8_t type) { | ||
| switch (type) { | ||
| case SSL3_MT_CLIENT_HELLO: | ||
| return "ClientHello"; | ||
| case SSL3_MT_SERVER_HELLO: | ||
| return "ServerHello"; | ||
| case SSL3_MT_CERTIFICATE: | ||
| return "Certificate"; | ||
| case SSL3_MT_CERTIFICATE_REQUEST: | ||
| return "CertificateRequest"; | ||
| case SSL3_MT_CERTIFICATE_VERIFY: | ||
| return "CertificateVerify"; | ||
| case SSL3_MT_FINISHED: | ||
| return "Finished"; | ||
| case SSL3_MT_ENCRYPTED_EXTENSIONS: | ||
| return "EncryptedExtensions"; | ||
| case SSL3_MT_NEW_SESSION_TICKET: | ||
| return "NewSessionTicket"; | ||
| default: | ||
| return nullptr; | ||
| } |
There was a problem hiding this comment.
- What about
ServerKeyExchange,ServerHelloDone,ClientKeyExchange, others? - Should the default be something like "Unknown" or "Other" instead of
nullptr?
There was a problem hiding this comment.
nullptr ends up printing nothing after the length which I think is fine. Didn't feel like being exhaustive here unless we feel strongly about it. I implemented enough to avoid any unhandled cases for a typical endpoint.
>>> TLS 1.2, Handshake [length 05c8]
I wanted to, but I couldn't find any patterns in the test framework for capturing stdout and asserting on that. Is there something I'm missing? Or should I cobble something together? I suppose we could assert that passing these args in does not give an error return code, but is that really helpful? |
WillChilds-Klein
left a comment
There was a problem hiding this comment.
Could we add a few tests to cover the new options?
I wanted to, but I couldn't find any patterns in the test framework for capturing stdout and asserting on that.
you're printing to stderr, no?
I suppose we could assert that passing these args in does not give an error return code, but is that really helpful?
i don't think the juice is worth the squeeze here if we're just asserting exit codes.
| case SSL3_MT_NEW_SESSION_TICKET: | ||
| return "NewSessionTicket"; | ||
| default: | ||
| return nullptr; |
There was a problem hiding this comment.
np: others return "Unknown" here, should this do same?
We have a bunch of "comparison tests" that capture our command output and compare it to the output of openssl. See the usage of RunCommandsAndCompareOutput. Could that be used? |
Description of changes:
Add -msg flag with full implementation using SSL_set_msg_callback to
print TLS protocol messages in OpenSSL-compatible format.
Add -servername flag that maps to DoClient's existing -server-name
for SNI support.
Call-outs:
I did not end up printing the hex dumps of each message like OpenSSL does. Should be easy enough to add if we wanted to, but the compatibility gap being addressed by this does not require it.
The
-msgargument only applies tos_clientbut it had to be implemented insideclient.ccbecause it impacts theSSL_CTX. This may raise the eyebrows of some purists.Testing:
How is this change tested (unit tests, fuzz tests, etc.)? Are there any testing steps to be verified by the reviewer?
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.