1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:07:34 +00:00

LibTLS+RequestServer: Add an option to dump TLS keys to a log file

This file allows us to decrypt TLS messages in wireshark, which can help
immensely in debugging network stuff :^)
This commit is contained in:
Ali Mohammad Pur 2022-02-09 23:12:56 +03:30 committed by Andreas Kling
parent a796207b9f
commit cb7becb067
4 changed files with 28 additions and 2 deletions

View file

@ -5,6 +5,7 @@
*/
#include <AK/Debug.h>
#include <AK/Hex.h>
#include <AK/Random.h>
#include <LibCrypto/ASN1/DER.h>
#include <LibCrypto/BigInt/UnsignedBigInteger.h>
@ -136,6 +137,16 @@ bool TLSv12::compute_master_secret_from_pre_master_secret(size_t length)
dbgln("master key:");
print_buffer(m_context.master_key);
}
if constexpr (TLS_SSL_KEYLOG_DEBUG) {
auto file = MUST(Core::Stream::File::open("/home/anon/ssl_keylog", Core::Stream::OpenMode::Append | Core::Stream::OpenMode::Write));
VERIFY(file->write_or_error("CLIENT_RANDOM "sv.bytes()));
VERIFY(file->write_or_error(encode_hex({ m_context.local_random, 32 }).bytes()));
VERIFY(file->write_or_error(" "sv.bytes()));
VERIFY(file->write_or_error(encode_hex(m_context.master_key).bytes()));
VERIFY(file->write_or_error("\n"sv.bytes()));
}
expand_key();
return true;
}