diff --git a/src/messages_server.c b/src/messages_server.c index 168bb023..84442032 100644 --- a/src/messages_server.c +++ b/src/messages_server.c @@ -30,8 +30,6 @@ #include "messages_server.h" #include "netconf.h" -extern struct nc_server_opts server_opts; - API struct nc_server_reply * nc_server_reply_ok(void) { diff --git a/src/server_config.c b/src/server_config.c index 8bce71f3..158d84d7 100644 --- a/src/server_config.c +++ b/src/server_config.c @@ -33,8 +33,6 @@ #include "server_config_p.h" #include "session_p.h" -extern struct nc_server_opts server_opts; - /* returns a parent node of 'node' that matches the name 'name' */ static const struct lyd_node * nc_server_config_get_parent(const struct lyd_node *node, const char *name) diff --git a/src/server_config_ks.c b/src/server_config_ks.c index b12e2f39..0194c70b 100644 --- a/src/server_config_ks.c +++ b/src/server_config_ks.c @@ -27,8 +27,6 @@ #include "server_config_p.h" #include "session_p.h" -extern struct nc_server_opts server_opts; - /** * @brief Get the pointer to an asymmetric key structure based on node's location in the YANG data. * diff --git a/src/server_config_ts.c b/src/server_config_ts.c index b76feef1..62528d75 100644 --- a/src/server_config_ts.c +++ b/src/server_config_ts.c @@ -27,8 +27,6 @@ #include "server_config_p.h" #include "session_p.h" -extern struct nc_server_opts server_opts; - /** * @brief Get the pointer to a certificate bag structure based on node's location in the YANG data. * diff --git a/src/session.c b/src/session.c index 155aafca..4b7cfd69 100644 --- a/src/session.c +++ b/src/session.c @@ -50,8 +50,6 @@ /* in milliseconds */ #define NC_CLOSE_REPLY_TIMEOUT 200 -extern struct nc_server_opts server_opts; - void nc_timeouttime_get(struct timespec *ts, uint32_t add_ms) { diff --git a/src/session_mbedtls.c b/src/session_mbedtls.c index e0947b8f..560d85f3 100644 --- a/src/session_mbedtls.c +++ b/src/session_mbedtls.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -1923,3 +1924,91 @@ nc_tls_get_cert_exp_time_wrap(void *cert) return timegm(&t); } + +/** + * @brief Convert the MbedTLS key export type to a label for the keylog file. + * + * @param[in] type MbedTLS key export type. + * @return Label for the keylog file or NULL if the type is not supported. + */ +static const char * +nc_tls_keylog_type2label(mbedtls_ssl_key_export_type type) +{ + switch (type) { + case MBEDTLS_SSL_KEY_EXPORT_TLS12_MASTER_SECRET: + return "CLIENT_RANDOM"; +#ifdef MBEDTLS_SSL_PROTO_TLS1_3 + case MBEDTLS_SSL_KEY_EXPORT_TLS1_3_CLIENT_HANDSHAKE_TRAFFIC_SECRET: + return "CLIENT_HANDSHAKE_TRAFFIC_SECRET"; + case MBEDTLS_SSL_KEY_EXPORT_TLS1_3_SERVER_HANDSHAKE_TRAFFIC_SECRET: + return "SERVER_HANDSHAKE_TRAFFIC_SECRET"; + case MBEDTLS_SSL_KEY_EXPORT_TLS1_3_CLIENT_APPLICATION_TRAFFIC_SECRET: + return "CLIENT_TRAFFIC_SECRET_0"; + case MBEDTLS_SSL_KEY_EXPORT_TLS1_3_SERVER_APPLICATION_TRAFFIC_SECRET: + return "SERVER_TRAFFIC_SECRET_0"; +#endif + default: + return NULL; + } +} + +/** + * @brief Callback for writing a line in the keylog file. + */ +static void +nc_tls_keylog_write_line(void *UNUSED(p_expkey), mbedtls_ssl_key_export_type type, const unsigned char *secret, + size_t secret_len, const unsigned char client_random[32], + const unsigned char UNUSED(server_random[32]), mbedtls_tls_prf_types UNUSED(tls_prf_type)) +{ + size_t linelen, len = 0, i, client_random_len; + char buf[256]; + const char *label; + + if (!server_opts.tls_keylog_file) { + return; + } + + label = nc_tls_keylog_type2label(type); + if (!label) { + /* type not supported */ + return; + } + + /*