-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Keylog file with env variable SSLKEYLOGFILE (for openssl)
- Loading branch information
Gael COLIN
committed
Nov 4, 2024
1 parent
53c97bc
commit 81bf39b
Showing
7 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* @file keylog.h | ||
* @author Gael COLIN <gael.colin@nokia.com> | ||
* @brief libnetconf2 - log functions | ||
* | ||
* @copyright | ||
* Copyright (c) 2015 - 2021 CESNET, z.s.p.o. | ||
* Copyright (c) 1996 - 2024, Daniel Stenberg, daniel@haxx.se, and many contributors, see the THANKS file. | ||
* | ||
* This source code is licensed under BSD 3-Clause License (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* | ||
* This software is licensed as described in the file COPYING, which | ||
* you should have received as part of this distribution. The terms | ||
* are also available at https://curl.se/docs/copyright.html. | ||
* | ||
* SPDX-License-Identifier: curl | ||
*/ | ||
#include <stdlib.h> | ||
#include "keylog.h" | ||
|
||
#define KEYLOG_LABEL_MAXLEN (sizeof("CLIENT_HANDSHAKE_TRAFFIC_SECRET") - 1) | ||
|
||
#define CLIENT_RANDOM_SIZE 32 | ||
|
||
/* | ||
* The master secret in TLS 1.2 and before is always 48 bytes. In TLS 1.3, the | ||
* secret size depends on the cipher suite's hash function which is 32 bytes | ||
* for SHA-256 and 48 bytes for SHA-384. | ||
*/ | ||
#define SECRET_MAXLEN 48 | ||
|
||
/* The fp for the open SSLKEYLOGFILE, or NULL if not open */ | ||
FILE *keylog_file_fp = NULL; | ||
|
||
void | ||
tls_keylog_open(void) | ||
{ | ||
char *keylog_file_name; | ||
|
||
if (!keylog_file_fp) { | ||
keylog_file_name = getenv("SSLKEYLOGFILE"); | ||
if (keylog_file_name) { | ||
keylog_file_fp = fopen(keylog_file_name, "a"); | ||
if (keylog_file_fp) { | ||
if (setvbuf(keylog_file_fp, NULL, _IOLBF, 4096)) { | ||
fclose(keylog_file_fp); | ||
keylog_file_fp = NULL; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
void | ||
tls_keylog_close(void) | ||
{ | ||
if (keylog_file_fp) { | ||
fclose(keylog_file_fp); | ||
keylog_file_fp = NULL; | ||
} | ||
} | ||
|
||
bool | ||
tls_keylog_enabled(void) | ||
{ | ||
return keylog_file_fp != NULL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @file keylog.h | ||
* @author Gael COLIN <gael.colin@nokia.com> | ||
* @brief libnetconf2 - log functions | ||
* | ||
* @copyright | ||
* Copyright (c) 2015 - 2021 CESNET, z.s.p.o. | ||
* Copyright (c) 1996 - 2024, Daniel Stenberg, daniel@haxx.se, and many contributors, see the THANKS file. | ||
* | ||
* This source code is licensed under BSD 3-Clause License (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* | ||
* This software is licensed as described in the file COPYING, which | ||
* you should have received as part of this distribution. The terms | ||
* are also available at https://curl.se/docs/copyright.html. | ||
* | ||
* SPDX-License-Identifier: curl | ||
*/ | ||
#include <stdio.h> | ||
#include "stdbool.h" | ||
#include "stddef.h" | ||
|
||
extern FILE *keylog_file_fp; | ||
|
||
/* | ||
* Opens the TLS key log file if requested by the user. The SSLKEYLOGFILE | ||
* environment variable specifies the output file. | ||
*/ | ||
void tls_keylog_open(void); | ||
|
||
/* | ||
* Closes the TLS key log file if not already. | ||
*/ | ||
void tls_keylog_close(void); | ||
|
||
/* | ||
* Returns true if the user successfully enabled the TLS key log file. | ||
*/ | ||
bool tls_keylog_enabled(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters