mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-29 18:27:29 +02:00
Added new WOLFSSL_SSLKEYLOGFILE
define to output master secret used by Wireshark logging to file. Defaults to sslkeylog.log
, but can be overridden using WOLFSSL_SSLKEYLOGFILE_OUTPUT
.
This commit is contained in:
47
src/tls.c
47
src/tls.c
@ -99,6 +99,12 @@ static int TLSX_PopulateSupportedGroups(WOLFSSL* ssl, TLSX** extensions);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Optional Pre-Master-Secret logging for Wireshark */
|
||||
#if !defined(NO_FILESYSTEM) && defined(WOLFSSL_SSLKEYLOGFILE)
|
||||
#ifndef WOLFSSL_SSLKEYLOGFILE_OUTPUT
|
||||
#define WOLFSSL_SSLKEYLOGFILE_OUTPUT "sslkeylog.log"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef WOLFSSL_NO_TLS12
|
||||
|
||||
@ -704,13 +710,44 @@ int MakeTlsMasterSecret(WOLFSSL* ssl)
|
||||
}
|
||||
if (ret == 0) {
|
||||
#ifdef SHOW_SECRETS
|
||||
int i;
|
||||
/* Wireshark Pre-Master-Secret Format:
|
||||
* CLIENT_RANDOM <clientrandom> <mastersecret>
|
||||
*/
|
||||
const char* CLIENT_RANDOM_LABEL = "CLIENT_RANDOM";
|
||||
int i, pmsPos = 0;
|
||||
char pmsBuf[13 + 1 + 64 + 1 + 96 + 1 + 1];
|
||||
|
||||
printf("master secret: ");
|
||||
for (i = 0; i < SECRET_LEN; i++)
|
||||
printf("%02x", ssl->arrays->masterSecret[i]);
|
||||
printf("\n");
|
||||
XSNPRINTF(&pmsBuf[pmsPos], sizeof(pmsBuf) - pmsPos, "%s ",
|
||||
CLIENT_RANDOM_LABEL);
|
||||
pmsPos += XSTRLEN(CLIENT_RANDOM_LABEL) + 1;
|
||||
for (i = 0; i < RAN_LEN; i++) {
|
||||
XSNPRINTF(&pmsBuf[pmsPos], sizeof(pmsBuf) - pmsPos, "%02x",
|
||||
ssl->arrays->clientRandom[i]);
|
||||
pmsPos += 2;
|
||||
}
|
||||
XSNPRINTF(&pmsBuf[pmsPos], sizeof(pmsBuf) - pmsPos, " ");
|
||||
pmsPos += 1;
|
||||
for (i = 0; i < SECRET_LEN; i++) {
|
||||
XSNPRINTF(&pmsBuf[pmsPos], sizeof(pmsBuf) - pmsPos, "%02x",
|
||||
ssl->arrays->masterSecret[i]);
|
||||
pmsPos += 2;
|
||||
}
|
||||
XSNPRINTF(&pmsBuf[pmsPos], sizeof(pmsBuf) - pmsPos, "\n");
|
||||
pmsPos += 1;
|
||||
|
||||
/* print master secret */
|
||||
puts(pmsBuf);
|
||||
|
||||
#if !defined(NO_FILESYSTEM) && defined(WOLFSSL_SSLKEYLOGFILE)
|
||||
{
|
||||
FILE* f = XFOPEN(WOLFSSL_SSLKEYLOGFILE_OUTPUT, "a");
|
||||
if (f != XBADFILE) {
|
||||
XFWRITE(pmsBuf, 1, pmsPos, f);
|
||||
XFCLOSE(f);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* SHOW_SECRETS */
|
||||
|
||||
ret = DeriveTlsKeys(ssl);
|
||||
}
|
||||
|
Reference in New Issue
Block a user