Create gh-pages for ktls-utils
Subsystems (2)
Chuck Lever
maintainercover Create gh-pages for ktls-utils
From: Chuck Lever <[email protected]>
Sorry for the size of this series.
The Doxygen comment style we started with was the kdoc style, which isn't suitable for user space projects. So the first step is to convert the comments to bog standard user-space Doxygen.
Patch 13/14 then adds the "create the Doxygen tree" build logic.
Patch 14/14 adds a GitHub action that can generate and deploy a set of gh-pages for ktls-utils. It includes the man pages, an example configuration file, and the generated Doxygen tree.
This isn't perfect, but it's something that can be built on over time.
Chuck Lever (14):
tlshd: Add kernel's quic.h
tlshd: Translate kernel-style Doxygen comments in src/tlshd/client.c
tlshd: Translate kernel-style Doxygen comments in src/tlshd/config.c
tlshd: Translate kernel-style Doxygen comments in
src/tlshd/handshake.c
tlshd: Translate kernel-style Doxygen comments in src/tlshd/keyring.c
tlshd: Translate kernel-style Doxygen comments in src/tlshd/ktls.c
tlshd: Translate kernel-style Doxygen comments in src/tlshd/log.c
tlshd: Translate kernel-style Doxygen comments in src/tlshd/main.c
tlshd: Translate kernel-style Doxygen comments in src/tlshd/netlink.c
tlshd: Translate kernel-style Doxygen comments in src/tlshd/quic.c
tlshd: Translate kernel-style Doxygen comments in src/tlshd/server.c
tlshd: Translate kernel-style Doxygen comments in src/tlshd/tlshd.h Build Doxygen web site
workflows: Generate gh-pages automatically
Xin Long (2):
tlshd: leave session_status as EIO on GnuTLS failure in QUIC session
setup
tlshd: set conn errcode to EACCES on GnuTLS failure in QUIC handshake
.github/workflows/documentation.yml | 154 ++
.gitignore | 1 +
Makefile.am | 3 +-
configure.ac | 13 +-
docs/Doxyfile.in | 2836 +++++++++++++++++++++++++++
{src => docs}/Makefile.am | 13 +-
src/Makefile.am | 2 +
src/mainpage.c | 20 +
src/tlshd/Makefile.am | 3 +-
src/tlshd/client.c | 200 +-
src/tlshd/config.c | 164 +-
src/tlshd/handshake.c | 32 +-
src/tlshd/keyring.c | 79 +-
src/tlshd/ktls.c | 118 +-
src/tlshd/log.c | 102 +-
src/tlshd/main.c | 42 +-
src/tlshd/netlink.c | 110 +-
src/tlshd/quic.c | 246 ++-
src/tlshd/quic.h | 236 +++
src/tlshd/server.c | 232 ++-
src/tlshd/tlshd.h | 87 +-
21 files changed, 4343 insertions(+), 350 deletions(-)
create mode 100644 .github/workflows/documentation.yml
create mode 100644 docs/Doxyfile.in
copy {src => docs}/Makefile.am (78%)
create mode 100644 src/mainpage.c
create mode 100644 src/tlshd/quic.hSignature · 1 line
2.51.0
Chuck Lever
maintainerPATCH 1/16 tlshd: Add kernel's quic.h
From: Chuck Lever <[email protected]>
Currently, QUIC support is disabled in tlshd unless the kernel's uapi/linux/quic.h file is present on the system. Since that work is not yet upstream, pretty much no build environment has this file.
Including this header now enables the oracle/ktls-utils testing workflows for the code in quic.c, and also enables development for tlshd code near the quic.c code -- ie, at least now building fails immediately if you've done something incompatible with what's in quic.c.
This copy of quic.h can be updated periodically or removed entirely when the kernel version of this file becomes reliably available.
I pulled the file from:
https://lore.kernel.org/netdev/[email protected]/T/#m377dc3b337c5bcfef79dc64400fec3a5e41cdbe0
--- configure.ac | 7 +- src/tlshd/Makefile.am | 3 +- src/tlshd/quic.h | 236 ++++++++++++++++++++++++++++++++++++++++++ src/tlshd/tlshd.h | 9 +- 4 files changed, 249 insertions(+), 6 deletions(-) create mode 100644 src/tlshd/quic.h
configure.ac +3 -4
@@ -64,10 +64,9 @@ PKG_CHECK_MODULES([LIBNL_GENL3], libnl-genl-3.0 >= 3.1) AC_SUBST([LIBNL_GENL3_CFLAGS]) AC_SUBST([LIBNL_GENL3_LIBS]) -AC_CHECK_HEADER([linux/quic.h], - [AC_CHECK_LIB([gnutls], [gnutls_handshake_set_secret_function], - [AC_DEFINE([HAVE_GNUTLS_QUIC], [1], [Define to 1 if QUIC is found.])])]) - +AC_CHECK_LIB([gnutls], [gnutls_handshake_set_secret_function], + [AC_DEFINE([HAVE_GNUTLS_QUIC], [1], + [Define to 1 if you have the gnutls_handshake_set_secret_function function.])]) AC_CHECK_LIB([gnutls], [gnutls_transport_is_ktls_enabled], [AC_DEFINE([HAVE_GNUTLS_TRANSPORT_IS_KTLS_ENABLED], [1], [Define to 1 if you have the gnutls_transport_is_ktls_enabled function.])])
src/tlshd/Makefile.am +2 -1
@@ -21,7 +21,8 @@ tlshd_CFLAGS = -Werror -Wall -Wextra $(LIBGNUTLS_CFLAGS) \ $(LIBKEYUTILS_CFLAGS) $(GLIB_CFLAGS) $(LIBNL3_CFLAGS) \ $(LIBNL_GENL3_CFLAGS) tlshd_SOURCES = client.c config.c handshake.c keyring.c ktls.c log.c \ - main.c netlink.c netlink.h server.c tlshd.h quic.c + main.c netlink.c netlink.h server.c tlshd.h quic.c \ + quic.h tlshd_LDADD = $(LIBGNUTLS_LIBS) $(LIBKEYUTILS_LIBS) $(GLIB_LIBS) \ $(LIBNL3_LIBS) $(LIBNL_GENL3_LIBS)
src/tlshd/quic.h new file +236 -0
236 lines not on this page · raw message
src/tlshd/tlshd.h +8 -1
@@ -122,7 +122,14 @@ extern void tlshd_tls13_serverhello_handshake(struct tlshd_handshake_parms *parmextern void tlshd_quic_serverhello_handshake (struct tlshd_handshake_parms *parms);#ifdef HAVE_GNUTLS_QUIC -#include <linux/quic.h> +#include "quic.h" + +#ifndef SOL_QUIC +#define SOL_QUIC 288 +#endif +#ifndef IPPROTO_QUIC +#define IPPROTO_QUIC 261 +#endif #define TLSHD_QUIC_MAX_DATA_LEN 4096#define TLSHD_QUIC_MAX_ALPNS_LEN 128
Signature · 1 line
2.51.0
Chuck Lever
maintainerPATCH 2/16 tlshd: leave session_status as EIO on GnuTLS failure in QUIC session setup
In reply to Chuck LeverFrom: Xin Long <[email protected]>
Align the QUIC session setup error handling with the TLS 1.3 code paths:
- tlshd_tls13_client_x509_handshake()
- tlshd_tls13_client_psk_handshake()
- tlshd_tls13_server_x509_handshake()
- tlshd_tls13_server_psk_handshake()
The QUIC session setup functions:
- tlshd_quic_client_set_x509_session()
- tlshd_quic_client_set_psk_session()
- tlshd_quic_server_set_x509_session()
- tlshd_quic_server_set_psk_session()
will no longer return an error directly. Instead, if a GnuTLS API call fails, session_status is left as EIO after logging the Gnutls errors.
--- src/tlshd/client.c | 42 ++++++++++++++++++++---------------------- src/tlshd/server.c | 29 +++++++++++++---------------- 2 files changed, 33 insertions(+), 38 deletions(-)
src/tlshd/client.c +20 -22
@@ -530,17 +530,17 @@ static int tlshd_quic_client_x509_verify_function(gnutls_session_t session)#define TLSHD_QUIC_NO_CERT_AUTH 3 -static int tlshd_quic_client_set_x509_session (struct tlshd_quic_conn *conn) +static void tlshd_quic_client_set_x509_session (struct tlshd_quic_conn *conn) {struct tlshd_handshake_parms *parms = conn->parms;gnutls_certificate_credentials_t cred;gnutls_session_t session; -int ret = -EINVAL ; +int ret;if (conn->cert_req !=TLSHD_QUIC_NO_CERT_AUTH ) {if (!tlshd_x509_client_get_certs (parms) || !tlshd_x509_client_get_privkey (parms)) { -tlshd_log_error ("cert/privkey get error %d" , -ret); -return ret; +tlshd_log_error ("Failed to get cert or privkey" ); +return ; } } ret =gnutls_certificate_allocate_credentials (&cred);
@@ -581,7 +581,8 @@ static int tlshd_quic_client_set_x509_session(struct tlshd_quic_conn *conn) goto err_session; } conn->session = session; -return 0 ; +return ; + err_session:gnutls_deinit (session); err_cred:
@@ -590,29 +591,28 @@ err:tlshd_x509_client_put_privkey ();tlshd_x509_client_put_certs ();tlshd_log_gnutls_error (ret); -return ret; } -static int tlshd_quic_client_set_anon_session (struct tlshd_quic_conn *conn) +static void tlshd_quic_client_set_anon_session (struct tlshd_quic_conn *conn) { conn->cert_req =TLSHD_QUIC_NO_CERT_AUTH ; -return tlshd_quic_client_set_x509_session (conn); +tlshd_quic_client_set_x509_session (conn); } -static int tlshd_quic_client_set_psk_session (struct tlshd_quic_conn *conn) +static void tlshd_quic_client_set_psk_session (struct tlshd_quic_conn *conn) {key_serial_t peerid =g_array_index (conn->parms->peerids, key_serial_t,0 );gnutls_psk_client_credentials_t cred;gnutls_session_t session;char *identity =NULL ;gnutls_datum_t key; -int ret = -EINVAL ; +int ret;if (!tlshd_keyring_get_psk_username (peerid, &identity) || !tlshd_keyring_get_psk_key (peerid, &key)) {free (identity); -tlshd_log_error ("identity/key get error %d" , -ret); -return ret; +tlshd_log_error ("Failed to get key identity or read key" ); +return ; } ret =gnutls_psk_allocate_client_credentials (&cred);
@@ -630,7 +630,8 @@ static int tlshd_quic_client_set_psk_session(struct tlshd_quic_conn *conn)if (ret) goto err_session; conn->session = session; -return 0 ; +return ; + err_session:gnutls_deinit (session); err_cred:
@@ -638,7 +639,6 @@ err_cred: err:free (identity);tlshd_log_gnutls_error (ret); -return ret; }/**
@@ -659,26 +659,24 @@ void tlshd_quic_clienthello_handshake(struct tlshd_handshake_parms *parms)switch (parms->auth_mode) {case HANDSHAKE_AUTH_UNAUTH : - ret =tlshd_quic_client_set_anon_session (conn); +tlshd_quic_client_set_anon_session (conn);break ;case HANDSHAKE_AUTH_X509 : - ret =tlshd_quic_client_set_x509_session (conn); +tlshd_quic_client_set_x509_session (conn);break ;case HANDSHAKE_AUTH_PSK : - ret =tlshd_quic_client_set_psk_session (conn); +tlshd_quic_client_set_psk_session (conn);break ;default : - ret = -EINVAL ;tlshd_log_debug ("Unrecognized auth mode (%d)" , parms->auth_mode); } -if (ret) { - conn->errcode = -ret; + +if (!conn->session) goto out; - }tlshd_quic_start_handshake (conn); -out: parms->session_status = conn->errcode; +out: tlshd_quic_conn_destroy(conn); }#else
src/tlshd/server.c +13 -16
@@ -562,17 +562,17 @@ found:return 0 ; } -static int tlshd_quic_server_set_x509_session (struct tlshd_quic_conn *conn) +static void tlshd_quic_server_set_x509_session (struct tlshd_quic_conn *conn) {struct tlshd_handshake_parms *parms = conn->parms;gnutls_certificate_credentials_t cred;gnutls_datum_t ticket_key;gnutls_session_t session; -int ret = -EINVAL ; +int ret;if (!tlshd_x509_server_get_certs (parms) || !tlshd_x509_server_get_privkey (parms)) { -tlshd_log_error ("cert/privkey get error %d" , -ret); -return ret; +tlshd_log_error ("Failed to get cert or privkey" ); +return ; } ret =gnutls_certificate_allocate_credentials (&cred);
@@ -619,7 +619,8 @@ static int tlshd_quic_server_set_x509_session(struct tlshd_quic_conn *conn) conn->is_serv =1 ; conn->session = session; -return 0 ; +return ; + err_session:gnutls_deinit (session); err_cred:
@@ -628,10 +629,9 @@ err:tlshd_x509_server_put_privkey ();tlshd_x509_server_put_certs ();tlshd_log_gnutls_error (ret); -return ret; } -static int tlshd_quic_server_set_psk_session (struct tlshd_quic_conn *conn) +static void tlshd_quic_server_set_psk_session (struct tlshd_quic_conn *conn) {gnutls_psk_server_credentials_t cred;gnutls_session_t session;
@@ -654,14 +654,14 @@ static int tlshd_quic_server_set_psk_session(struct tlshd_quic_conn *conn) conn->is_serv =1 ; conn->session = session; -return 0 ; +return ; + err_session:gnutls_deinit (session); err_cred:gnutls_psk_free_server_credentials (cred); err:tlshd_log_gnutls_error (ret); -return ret; }/**
@@ -682,23 +682,20 @@ void tlshd_quic_serverhello_handshake(struct tlshd_handshake_parms *parms)switch (parms->auth_mode) {case HANDSHAKE_AUTH_X509 : - ret =tlshd_quic_server_set_x509_session (conn); +tlshd_quic_server_set_x509_session (conn);break ;case HANDSHAKE_AUTH_PSK : - ret =tlshd_quic_server_set_psk_session (conn); +tlshd_quic_server_set_psk_session (conn);break ;default : - ret = -EINVAL ;tlshd_log_debug ("Unrecognized auth mode (%d)" , parms->auth_mode); } -if (ret) { - conn->errcode = -ret; +if (!conn->session) goto out; - }tlshd_quic_start_handshake (conn); -out: parms->session_status = conn->errcode; +out: tlshd_quic_conn_destroy(conn); }#else
Signature · 1 line
2.51.0
Chuck Lever
maintainerPATCH 3/16 tlshd: set conn errcode to EACCES on GnuTLS failure in QUIC handshake
In reply to Chuck LeverFrom: Xin Long <[email protected]>
Align QUIC handshake error handling with the TLS 1.3 path in tlshd_start_tls_handshake(). In tlshd_quic_start_handshake(), any error returned from the GnuTLS API is now logged and mapped to conn->errcode = EACCES (session_status).
Note: unlike TLS 1.3, the QUIC handshake manages its own packet send/recv. Timeouts are handled separately, with conn->errcode set to ETIMEDOUT by quic_timer_handler().
--- src/tlshd/quic.c | 66 +++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 29 deletions(-)
src/tlshd/quic.c +37 -29
@@ -188,7 +188,7 @@ static int quic_tp_send_func(gnutls_session_t session, gnutls_buffer_t extdata) ret =gnutls_buffer_append_data (extdata, buf, len);if (ret) {tlshd_log_gnutls_error (ret); -return ret; +return -1 ; }return 0 ;
@@ -230,6 +230,7 @@ static char quic_priority[] =static int quic_session_set_priority (gnutls_session_t session,uint32_t cipher) {char p[136 ] = {}; +int ret;memcpy (p, quic_priority,strlen (quic_priority));switch (cipher) {
@@ -249,14 +250,19 @@ static int quic_session_set_priority(gnutls_session_t session, uint32_t cipher)strcat (p,"AES-128-GCM:+AES-256-GCM:+AES-128-CCM:+CHACHA20-POLY1305" ); } -return gnutls_priority_set_direct (session, p,NULL ); + ret =gnutls_priority_set_direct (session, p,NULL ); +if (ret) { +tlshd_log_gnutls_error (ret); +return -1 ; + } +return 0 ; }static int quic_session_set_alpns (gnutls_session_t session,char *alpn_data) {gnutls_datum_t alpns[TLSHD_QUIC_MAX_ALPNS_LEN /2 ];char *alpn =strtok (alpn_data,"," ); -int count =0 ; +int count =0 , ret;while (alpn) {while (*alpn ==' ' )
@@ -267,7 +273,12 @@ static int quic_session_set_alpns(gnutls_session_t session, char *alpn_data) alpn =strtok (NULL ,"," ); } -return gnutls_alpn_set_protocols (session, alpns, count,GNUTLS_ALPN_MANDATORY ); + ret =gnutls_alpn_set_protocols (session, alpns, count,GNUTLS_ALPN_MANDATORY ); +if (ret) { +tlshd_log_gnutls_error (ret); +return -1 ; + } +return 0 ; }static gnutls_record_encryption_level_t quic_get_encryption_level (uint8_t level)
@@ -401,7 +412,7 @@ static int quic_handshake_crypto_data(const struct tlshd_quic_conn *conn, level =quic_get_encryption_level (level);if (datalen >0 ) { ret =gnutls_handshake_write (session, level, data, datalen); -if (ret !=0 ) { +if (ret) {if (!gnutls_error_is_fatal (ret))return 0 ; goto err;
@@ -418,7 +429,7 @@ static int quic_handshake_crypto_data(const struct tlshd_quic_conn *conn, err:gnutls_alert_send_appropriate (session, ret);tlshd_log_gnutls_error (ret); -return ret; +return -1 ; }/**
@@ -486,24 +497,25 @@ static int tlshd_quic_session_configure(struct tlshd_quic_conn *conn)gnutls_session_t session = conn->session;int ret; - ret =quic_session_set_priority (session, conn->cipher); -if (ret) -return ret; +if (quic_session_set_priority (session, conn->cipher)) +return -1 ; -if (conn->alpns[0 ]) { - ret =quic_session_set_alpns (session, conn->alpns); -if (ret) -return ret; - } +if (conn->alpns[0 ] &&quic_session_set_alpns (session, conn->alpns)) +return -1 ;gnutls_handshake_set_secret_function (session, quic_secret_func);gnutls_handshake_set_read_function (session, quic_read_func);gnutls_alert_set_read_function (session, quic_alert_read_func); -return gnutls_session_ext_register ( + ret =gnutls_session_ext_register ( session,"QUIC Transport Parameters" ,QUIC_TLSEXT_TP_PARAM ,GNUTLS_EXT_TLS , quic_tp_recv_func, quic_tp_send_func,NULL ,NULL ,NULL ,GNUTLS_EXT_FLAG_TLS |GNUTLS_EXT_FLAG_CLIENT_HELLO |GNUTLS_EXT_FLAG_EE ); +if (ret) { +tlshd_log_gnutls_error (ret); +return -1 ; + } +return 0 ; }static void tlshd_quic_recv_session_ticket (struct tlshd_quic_conn *conn)
@@ -532,16 +544,16 @@ static void tlshd_quic_recv_session_ticket(struct tlshd_quic_conn *conn)return ;/* process new session ticket msg and get the generated session data */ - ret =quic_handshake_crypto_data (conn,QUIC_CRYPTO_APP , conn->ticket, len); -if (ret) { - conn->errcode = -ret; +if (quic_handshake_crypto_data (conn,QUIC_CRYPTO_APP , conn->ticket, len)) { + conn->errcode =EACCES ;return ; } + size =sizeof (conn->ticket); ret =gnutls_session_get_data (session, conn->ticket, &size);if (ret) {tlshd_log_gnutls_error (ret); - conn->errcode = -ret; + conn->errcode =EACCES ;return ; }
@@ -569,17 +581,14 @@ void tlshd_quic_start_handshake(struct tlshd_quic_conn *conn)FD_ZERO (&readfds);FD_SET (sockfd, &readfds); - ret =tlshd_quic_session_configure (conn); -if (ret) { -tlshd_log_gnutls_error (ret); - conn->errcode = -ret; +if (tlshd_quic_session_configure (conn)) { + conn->errcode =EACCES ;return ; }if (!conn->is_serv) { - ret =quic_handshake_crypto_data (conn,QUIC_CRYPTO_INITIAL ,NULL ,0 ); -if (ret) { - conn->errcode = -ret; +if (quic_handshake_crypto_data (conn,QUIC_CRYPTO_INITIAL ,NULL ,0 )) { + conn->errcode =EACCES ;return ; }
@@ -614,9 +623,8 @@ void tlshd_quic_start_handshake(struct tlshd_quic_conn *conn)return tlshd_log_error ("socket recvmsg error %d" , errno); }tlshd_log_debug ("> Handshake RECV: %u %u" , msg->len, msg->level); - ret =quic_handshake_crypto_data (conn, msg->level, msg->data, msg->len); -if (ret) { - conn->errcode = -ret; +if (quic_handshake_crypto_data (conn, msg->level, msg->data, msg->len)) { + conn->errcode =EACCES ;return ; } }
Signature · 1 line
2.51.0
Chuck Lever
maintainerPATCH 4/16 tlshd: Translate kernel-style Doxygen comments in src/tlshd/client.c
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
I started the ktls-utils project using the Linux kernel flavor of Doxygen commenting which user-space Doxygen does not recognize by default.
Convert existing comments in client.c to what a normal user space Doxygen run expects to see. This will enable deployment of an automatically-generated documentation web site.
--- src/tlshd/client.c | 158 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 138 insertions(+), 20 deletions(-)
src/tlshd/client.c +138 -20
@@ -1,10 +1,14 @@ -/* -* Perform a TLSv1.3 handshake. +/** +* @file client.c +* @brief Perform a client-side TLS handshake * +* @copyright * Copyright (c) 2022 Oracle and/or its affiliates. * Copyright (c) 2022 SUSE LLC. * Copyright (c) 2024 Red Hat, Inc. -* +*/ + +/* * ktls-utils is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; version 2.
@@ -43,6 +47,13 @@#include "tlshd.h" #include "netlink.h" +/** +* @brief Initialize client side trust store +* @param[out] cred Trust store to initialize +* +* @returns a GnuTLS error code. Caller must release credentials +* using gnutls_certificate_free_credentials(3). +*/ static int tlshd_client_get_truststore (gnutls_certificate_credentials_t cred) {char *pathname;
@@ -74,6 +85,10 @@ static int tlshd_client_get_truststore(gnutls_certificate_credentials_t cred)return GNUTLS_E_SUCCESS ; } +/** +* @brief Initiate an x.509-based TLS handshake without a client certificate +* @param[in] parms Handshake parameters +*/ static void tlshd_tls13_client_anon_handshake (struct tlshd_handshake_parms *parms) {gnutls_certificate_credentials_t xcred;
@@ -134,13 +149,50 @@ out_free_creds:gnutls_certificate_free_credentials (xcred); } +/** +* @var gnutls_privkey_t tlshd_pq_privkey +* Client peer's post-quantum private key +*/ static gnutls_privkey_t tlshd_pq_privkey; + +/** +* @var gnutls_privkey_t tlshd_privkey +* Client peer's private key +*/ static gnutls_privkey_t tlshd_privkey; + +/** +* @var unsigned int tlshd_pq_certs_len +* Count of client peer's post-quantum certificates +*/ static unsigned int tlshd_pq_certs_len =TLSHD_MAX_CERTS ; + +/** +* @var unsigned int tlshd_certs_len +* Count of client peer's certificates +*/ static unsigned int tlshd_certs_len =TLSHD_MAX_CERTS ; + +/** +* @var gnutls_pcert_st tlshd_certs +* Client peer's certificates +*/ static gnutls_pcert_st tlshd_certs[TLSHD_MAX_CERTS ]; + +/** +* @var gnutls_pk_algorithm_t tlshd_pq_pkalg +* Client peer certificate's public key algorithms +*/ static gnutls_pk_algorithm_t tlshd_pq_pkalg =GNUTLS_PK_UNKNOWN ; +/** +* @brief Retrieve client certificates to be used for ClientHello +* @param[in] parms Handshake parameters +* +* @retval true Client certificates were found. Caller must release +* the certificates using tlshd_x509_client_put_certs. +* @retval false No usable client certificates were found +*/ static bool tlshd_x509_client_get_certs (struct tlshd_handshake_parms *parms) {if (parms->x509_cert !=TLS_NO_CERT )
@@ -151,6 +203,9 @@ static bool tlshd_x509_client_get_certs(struct tlshd_handshake_parms *parms) &tlshd_pq_pkalg); } +/** +* @brief Release client certificates that were used for ClientHello +*/ static void tlshd_x509_client_put_certs (void ) {unsigned int i;
@@ -159,6 +214,14 @@ static void tlshd_x509_client_put_certs(void)gnutls_pcert_deinit (&tlshd_certs[i]); } +/** +* @brief Retrieve the private key to be used for ClientHello +* @param[in] parms Handshake parameters +* +* @retval true Private key was found. Caller must release the +* private key using tlshd_x509_client_put_privkey. +* @retval false No usable private key was found +*/ static bool tlshd_x509_client_get_privkey (struct tlshd_handshake_parms *parms) {if (parms->x509_privkey !=TLS_NO_PRIVKEY )
@@ -168,12 +231,20 @@ static bool tlshd_x509_client_get_privkey(struct tlshd_handshake_parms *parms) &tlshd_privkey); } +/** +* @brief Release the private key that was used for ClientHello +*/ static void tlshd_x509_client_put_privkey (void ) {gnutls_privkey_deinit (tlshd_privkey);gnutls_privkey_deinit (tlshd_pq_privkey); } +/** +* @brief Audit trust chain of incoming server certificate +* @param[in] req_ca_rdn +* @param[in] nreqs +*/ static void tlshd_x509_log_issuers (const gnutls_datum_t *req_ca_rdn,int nreqs) {char issuer_dn[256 ];
@@ -196,7 +267,18 @@ static void tlshd_x509_log_issuers(const gnutls_datum_t *req_ca_rdn, int nreqs) }/** -* tlshd_x509_retrieve_key_cb - Initialize client's x.509 identity +* @brief Initialize the client peer's x.509 identity +* @param[in] session session in the midst of a handshake +* @param[in] req_ca_rdn +* @param[in] nreqs +* @param[in] pk_algos +* @param[in] pk_algos_length +* @param[out] pcert +* @param[out] pcert_length +* @param[out] privkey +* +* @retval 0 Success; output parameters are set accordingly +* @retval -1 Failure * * Callback function is of type gnutls_certificate_retrieve_function2 *
@@ -204,10 +286,6 @@ static void tlshd_x509_log_issuers(const gnutls_datum_t *req_ca_rdn, int nreqs)* gnutls/doc/examples/ex-cert-select.c. * * Sketched-in and untested. -* -* Return values: -* %0: Success; output parameters are set accordingly -* %-1: Failure */ static int tlshd_x509_retrieve_key_cb(gnutls_session_t session,
@@ -256,13 +334,12 @@ tlshd_x509_retrieve_key_cb(gnutls_session_t session, }/** -* tlshd_client_x509_verify_function - Verify remote's x.509 certificate -* @session: session in the midst of a handshake -* @parms: handshake parameters +* @brief Verify the remote peer's x.509 certificate +* @param[in] session session in the midst of a handshake +* @param[in] parms Handshake parameters * -* Return values: -* %GNUTLS_E_SUCCESS: Incoming certificate has been successfully verified -* %GNUTLS_E_CERTIFICATE_ERROR: certificate verification failed +* @retval GNUTLS_E_SUCCESS Certificate has been successfully verified +* @retval GNUTLS_E_CERTIFICATE_ERROR Certificate verification failed */ static int tlshd_client_x509_verify_function (gnutls_session_t session,struct tlshd_handshake_parms *parms)
@@ -313,6 +390,13 @@ static int tlshd_client_x509_verify_function(gnutls_session_t session,return GNUTLS_E_SUCCESS ; } +/** +* @brief Verify the remote peer's x.509 certificate (TLSv1.3) +* @param[in] session session in the midst of a handshake +* +* @retval GNUTLS_E_SUCCESS Certificate has been successfully verified +* @retval GNUTLS_E_CERTIFICATE_ERROR Certificate verification failed +*/ static int tlshd_tls13_client_x509_verify_function (gnutls_session_t session) {struct tlshd_handshake_parms *parms =gnutls_session_get_ptr (session);
@@ -320,6 +404,10 @@ static int tlshd_tls13_client_x509_verify_function(gnutls_session_t session)return tlshd_client_x509_verify_function (session, parms); } +/** +* @brief Initiate an x.509-based TLS handshake with a client certificate +* @param[in] parms Handshake parameters +*/ static void tlshd_tls13_client_x509_handshake (struct tlshd_handshake_parms *parms) {gnutls_certificate_credentials_t xcred;
@@ -384,6 +472,11 @@ out_free_creds:gnutls_certificate_free_credentials (xcred); } +/** +* @brief Initiate one PSK-based handshake +* @param[in] parms Handshake parameters +* @param[in] peerid Serial number of local peer ID to present +*/ static void tlshd_tls13_client_psk_handshake_one (struct tlshd_handshake_parms *parms,key_serial_t peerid) {
@@ -475,6 +568,10 @@ out_free_creds:free (identity); } +/** +* @brief Initiate an PSK-based TLS handshake +* @param[in] parms Handshake parameters +*/ static void tlshd_tls13_client_psk_handshake (struct tlshd_handshake_parms *parms) {key_serial_t peerid;
@@ -498,9 +595,8 @@ static void tlshd_tls13_client_psk_handshake(struct tlshd_handshake_parms *parms }/** -* tlshd_tls13_clienthello_handshake - send a TLSv1.3 ClientHello -* @parms: handshake parameters -* +* @brief Send a TLSv1.3 ClientHello +* @param[in] parms Handshake parameters */ void tlshd_tls13_clienthello_handshake (struct tlshd_handshake_parms *parms) {
@@ -521,6 +617,13 @@ void tlshd_tls13_clienthello_handshake(struct tlshd_handshake_parms *parms) }#ifdef HAVE_GNUTLS_QUIC +/** +* @brief Verify the remote peer's x.509 certificate (QUIC) +* @param[in] session session in the midst of a handshake +* +* @retval GNUTLS_E_SUCCESS Certificate has been successfully verified +* @retval GNUTLS_E_CERTIFICATE_ERROR Certificate verification failed +*/ static int tlshd_quic_client_x509_verify_function (gnutls_session_t session) {struct tlshd_quic_conn *conn =gnutls_session_get_ptr (session);
@@ -530,6 +633,10 @@ static int tlshd_quic_client_x509_verify_function(gnutls_session_t session)#define TLSHD_QUIC_NO_CERT_AUTH 3 +/** +* @brief Prepare a session for a QUIC client handshake using an x.509 cert +* @param[in] conn +*/ static void tlshd_quic_client_set_x509_session (struct tlshd_quic_conn *conn) {struct tlshd_handshake_parms *parms = conn->parms;
@@ -593,12 +700,20 @@ err:tlshd_log_gnutls_error (ret); } +/** +* @brief Prepare a session for a QUIC client handshake using no authentication +* @param[in] conn +*/ static void tlshd_quic_client_set_anon_session (struct tlshd_quic_conn *conn) { conn->cert_req =TLSHD_QUIC_NO_CERT_AUTH ;tlshd_quic_client_set_x509_session (conn); } +/** +* @brief Prepare a session for a QUIC client handshake using a pre-shared key +* @param[in] conn +*/ static void tlshd_quic_client_set_psk_session (struct tlshd_quic_conn *conn) {key_serial_t peerid =g_array_index (conn->parms->peerids, key_serial_t,0 );
@@ -642,9 +757,8 @@ err: }/** -* tlshd_quic_clienthello_handshake - send a QUIC Client Initial -* @parms: handshake parameters -* +* @brief Send a QUIC Client Initial +* @param[in] parms Handshake parameters */ void tlshd_quic_clienthello_handshake (struct tlshd_handshake_parms *parms) {
@@ -680,6 +794,10 @@ out: tlshd_quic_conn_destroy(conn); }#else +/** +* @brief Send a QUIC Client Initial +* @param[in] parms Handshake parameters +*/ void tlshd_quic_clienthello_handshake (struct tlshd_handshake_parms *parms) {tlshd_log_debug ("QUIC handshake is not enabled (%d)" , parms->auth_mode);
Signature · 1 line
2.51.0
Chuck Lever
maintainerPATCH 5/16 tlshd: Translate kernel-style Doxygen comments in src/tlshd/config.c
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
I started the ktls-utils project using the Linux kernel flavor of Doxygen commenting which user-space Doxygen does not recognize by default.
Convert existing comments in config.c to what a normal user space Doxygen run expects to see. This will enable deployment of an automatically-generated documentation web site.
--- src/tlshd/config.c | 152 ++++++++++++++++++++++++++------------------- 1 file changed, 88 insertions(+), 64 deletions(-)
src/tlshd/config.c +88 -64
@@ -1,6 +1,10 @@ +/** +* @file config.c +* @brief Parse tlshd's config file +*/ +/* -* Parse tlshd's config file. -* +* @copyright * Copyright (c) 2022 Oracle and/or its affiliates. * * ktls-utils is free software; you can redistribute it and/or
@@ -44,16 +48,20 @@#include "tlshd.h" +/** +* @var GKeyFile *tlshd_configuration +* In-memory parsed config file +*/ static GKeyFile *tlshd_configuration;/** -* tlshd_config_init - Read tlshd's config file -* @pathname: Pathname to config file -* @legacy: Don't generate an error if the config file doesn't exist +* @brief Parse tlshd's config file +* @param[in] pathname Pathname to config file +* @param[in] legacy Don't generate an error if the specified +* config file doesn't exist * -* Return values: -* %true: Config file read successfully -* %false: Unable to read config file +* @retval true Config file parsed successfully +* @retval false Unable to read config file */ bool tlshd_config_init (const gchar *pathname,bool legacy) {
@@ -111,26 +119,49 @@ bool tlshd_config_init(const gchar *pathname, bool legacy)return true; } +/** +* @brief Release parsed config file data +*/ void tlshd_config_shutdown (void ) {g_key_file_free (tlshd_configuration); }/** -* ALLPERMS exists in glibc, but not on musl, so we manually -* define TLSHD_ACCESSPERMS instead of using ALLPERMS. +* @def TLSHD_ACCESSPERMS +* @brief ALLPERMS exists in glibc, but not on musl, so we manually +* define TLSHD_ACCESSPERMS instead of using ALLPERMS. */ #define TLSHD_ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) -/* -* Expected file attributes +/** +* @def TLSHD_OWNER +* @brief Expected owner of certificate and private key files */ #define TLSHD_OWNER 0/* root */ + +/** +* @def TLSHD_CERT_MODE +* @brief Expected mode of certificate files +*/ #define TLSHD_CERT_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) + +/** +* @def TLSHD_PRIVKEY_MODE +* @brief Expected mode of private key files +*/ #define TLSHD_PRIVKEY_MODE (S_IRUSR|S_IWUSR) -/* -* On success, caller must release buffer returned in @data by calling free(3) +/** +* @brief Read one configuration file +* @param[in] pathname Pathname to file that is to be read +* @param[out] data Buffer containing all file content +* @param[in] owner Expected owner of file +* @param[in] mode Expected mode of file +* +* @retval true File content retrieved successfully. Caller must +* release "data->data" by calling free(3) +* @retval false File content not retrieved */ static bool tlshd_config_read_datum (const char *pathname,gnutls_datum_t *data,uid_t owner,mode_t mode)
@@ -189,13 +220,13 @@ out: }/** -* tlshd_config_get_truststore - Get truststore for {Client,Server}Hello from .conf -* @peer_type: IN: peer type -* @bundle: OUT: pathname to truststore +* @brief Get truststore to use for {Client,Server}Hello +* @param[in] peer_type peer type +* @param[out] bundle pathname to truststore * -* Return values: -* %false: pathname not retrieved -* %true: pathname retrieved successfully; caller must free @bundle using free(3) +* @retval true Trust store retrieved successfully. Caller must free +* "*bundle" using free(3) +* @retval false Trust store not retrieved */ bool tlshd_config_get_truststore (int peer_type,char **bundle) {
@@ -226,13 +257,13 @@ bool tlshd_config_get_truststore(int peer_type, char **bundle) }/** -* tlshd_config_get_crl - Get CRL for {Client,Server}Hello from .conf -* @peer_type: IN: peer type -* @result: OUT: pathname to CRL +* @brief Get CRL for {Client,Server}Hello from .conf +* @param[in] peer_type peer type +* @param[out] result pathname to CRL * -* Return values: -* %false: pathname not retrieved -* %true: pathname retrieved successfully; caller must free @result using free(3) +* @retval true CRL retrieved successfully. Caller must free +* "*result" using free(3) +* @retval false CRL not retrieved */ bool tlshd_config_get_crl (int peer_type,char **result) {
@@ -308,16 +339,14 @@ static bool tlshd_cert_check_pk_alg(__attribute__ ((unused)) gnutls_datum_t *dat#endif /* HAVE_GNUTLS_MLDSA */ /** -* __tlshd_config_get_certs - Helper for tlshd_config_get_certs() -* @peer_type: IN: peer type -* @certs: OUT: in-memory certificates -* @certs_len: IN: maximum number of certs to get, OUT: number of certs found -* @pkgalg: IN: if non-NULL, indicates we want to retrieve the PQ cert, -* OUT: if non-NULL, store the PQ public-key alg that was used in the PQ cert +* @brief Helper for tlshd_config_get_certs() +* @param[in] peer_type peer type +* @param[out] certs in-memory certificates +* @param[in,out] certs_len maximum number of certs to get, number of certs found +* @param[out] pkalg buffer for returning PQ algorithm * -* Return values: -* %true: certificate retrieved successfully -* %false: certificate not retrieved +* @retval true Certificate(s) retrieved successfully +* @retval false Certificate(s) not retrieved */ static bool __tlshd_config_get_certs(int peer_type, gnutls_pcert_st *certs, unsigned int *certs_len,
@@ -372,21 +401,20 @@ static bool __tlshd_config_get_certs(int peer_type, gnutls_pcert_st *certs, }/** -* tlshd_config_get_certs - Get certs for {Client,Server} Hello from .conf -* @peer_type: IN: peer type -* @certs: OUT: in-memory certificates -* @pq_certs_len: IN: maximum number of PQ certs to get, OUT: number of PQ certs found -* @certs_len: IN: maximum number of certs to get, OUT: number of certs found -* @pkgalg: OUT: the PQ public-key alg that was used in the PQ cert +* @brief Get certs for {Client,Server} Hello +* @param[in] peer_type peer type +* @param[out] certs in-memory certificates +* @param[in,out] pq_certs_len maximum number of PQ certs to get, number of PQ certs found +* @param[in,out] certs_len maximum number of certs to get, number of certs found +* @param[out] pkalg the PQ public-key alg that was used in the PQ cert * -* Retrieve the PQ cert(s) first, then the RSA cert(s). Both are stored in the -* same list. Note that @pq_certs_len is deducted from the available @certs_len -* and is also used to determine the offset to store the RSA cert(s) in the -* @certs array. +* Retrieve the PQ cert(s) first, then the RSA cert(s). Both are +* stored in the same list. Note that "pq_certs_len" is deducted +* from the available "certs_len" and is also used to determine +* the offset to store the RSA cert(s) in the "certs array". * -* Return values: -* %true: certificate retrieved successfully -* %false: certificate not retrieved +* @retval true Certificate(s) retrieved successfully +* @retval false Certificate(s) not retrieved */ bool tlshd_config_get_certs(int peer_type, gnutls_pcert_st *certs, unsigned int *pq_certs_len,
@@ -407,14 +435,13 @@ bool tlshd_config_get_certs(int peer_type, gnutls_pcert_st *certs, }/** -* __tlshd_config_get_privkey - Helper for tlshd_config_get_privkey() -* @peer_type: IN: peer type -* @privkey: OUT: in-memory private key -* @pq: IN: if true, retrieve the PQ private key +* @brief Helper for tlshd_config_get_privkey() +* @param[in] peer_type peer type +* @param[out] privkey in-memory private key +* @param[in] pq if true, retrieve the PQ private key * -* Return values: -* %true: private key retrieved successfully -* %false: private key not retrieved +* @retval true Private key retrieved successfully +* @retval false Private key not retrieved */ static bool __tlshd_config_get_privkey (int peer_type,gnutls_privkey_t *privkey,bool pq) {
@@ -463,16 +490,13 @@ static bool __tlshd_config_get_privkey(int peer_type, gnutls_privkey_t *privkey, }/** -* tlshd_config_get_privkey - Get private key for {Client,Server}Hello from .conf -* @peer_type: IN: peer type -* @pq_privkey: OUT: in-memory PQ private key -* @privkey: OUT: in-memory private key +* @brief Get private key for {Client,Server}Hello +* @param[in] peer_type peer type +* @param[out] pq_privkey in-memory PQ private key +* @param[out] privkey in-memory private key * -* Retrieve the PQ private key first, then the RSA private key. -* -* Return values: -* %true: private key retrieved successfully -* %false: private key not retrieved +* @retval true Private key retrieved successfully +* @retval false Private key not retrieved */ bool tlshd_config_get_privkey (int peer_type,gnutls_privkey_t *pq_privkey,gnutls_privkey_t *privkey)
Signature · 1 line
2.51.0
Chuck Lever
maintainerPATCH 6/16 tlshd: Translate kernel-style Doxygen comments in src/tlshd/handshake.c
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
I started the ktls-utils project using the Linux kernel flavor of Doxygen commenting which user-space Doxygen does not recognize by default.
Convert existing comments in handshake.c to what a normal user space Doxygen run expects to see. This will enable deployment of an automatically-generated documentation web site.
--- src/tlshd/handshake.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-)
src/tlshd/handshake.c +22 -10
@@ -1,9 +1,13 @@ -/* -* Service a request for a TLS handshake on behalf of an -* in-kernel TLS consumer. +/** +* @file handshake.c +* @brief Service a request for a TLS handshake on behalf of an +* in-kernel TLS consumer * +* @copyright * Copyright (c) 2022 Oracle and/or its affiliates. -* +*/ + +/* * ktls-utils is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; version 2.
@@ -43,6 +47,11 @@#include "tlshd.h" #include "netlink.h" +/** +* @brief Toggle the use of the Nagle algorithm +* @param[in] session TLS session to modify +* @param[in] val new setting +*/ static void tlshd_set_nagle (gnutls_session_t session,int val) {int ret;
@@ -53,6 +62,11 @@ static void tlshd_set_nagle(gnutls_session_t session, int val)tlshd_log_perror ("setsockopt (NODELAY)" ); } +/** +* @brief Retrieve the current Nagle algorithm setting +* @param[in] session TLS session to modify +* @param[out] saved where to save the current setting +*/ static void tlshd_save_nagle (gnutls_session_t session,int *saved) {socklen_t len;
@@ -72,10 +86,9 @@ static void tlshd_save_nagle(gnutls_session_t session, int *saved) }/** -* tlshd_start_tls_handshake - Drive the handshake interaction -* @session: TLS session to initialize -* @parms: handshake parameters -* +* @brief Kick off a handshake interaction +* @param[in] session TLS session to initialize +* @param[in] parms Handshake parameters */ void tlshd_start_tls_handshake (gnutls_session_t session,struct tlshd_handshake_parms *parms)
@@ -115,8 +128,7 @@ void tlshd_start_tls_handshake(gnutls_session_t session, }/** -* tlshd_service_socket - Service a kernel socket needing a key operation -* +* @brief Service a kernel socket needing a handshake operation */ void tlshd_service_socket (void ) {
Signature · 1 line
2.51.0
Chuck Lever
maintainerPATCH 7/16 tlshd: Translate kernel-style Doxygen comments in src/tlshd/keyring.c
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
I started the ktls-utils project using the Linux kernel flavor of Doxygen commenting which user-space Doxygen does not recognize by default.
Convert existing comments in keyring.c to what a normal user space Doxygen run expects to see. This will enable deployment of an automatically-generated documentation web site.
--- src/tlshd/keyring.c | 79 +++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 39 deletions(-)
src/tlshd/keyring.c +40 -39
@@ -1,8 +1,12 @@ -/* -* Scrape authentication information from kernel keyring. +/** +* @file keyring.c +* @brief Linux keyring management * +* @copyright * Copyright (c) 2022 Oracle and/or its affiliates. -* +*/ + +/* * ktls-utils is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; version 2.
@@ -40,15 +44,14 @@#include "tlshd.h" /** -* tlshd_keyring_get_psk_username - Retrieve username for PSK handshake -* @serial: Key serial number to look up -* @username: On success, filled in with NUL-terminated user name +* @brief Retrieve username for PSK handshake +* @param[in] serial Key serial number to look up +* @param[out] username Filled in with NUL-terminated user name * -* Caller must use gnutls_free() to free @username when finished. +* Caller must use gnutls_free() to free "username" when finished. * -* Return values: -* %true: Success; @username has been initialized -* %false: Failure +* @retval true Success; "username" has been initialized +* @retval false Failure */ bool tlshd_keyring_get_psk_username (key_serial_t serial,char **username) {
@@ -80,15 +83,14 @@ bool tlshd_keyring_get_psk_username(key_serial_t serial, char **username) }/** -* tlshd_keyring_get_psk_key - Retrieve pre-shared key for PSK handshake -* @serial: Key serial number to look up -* @key: On success, filled in with pre-shared key +* @brief Retrieve pre-shared key for PSK handshake +* @param[in] serial Key serial number to look up +* @param[out] key Filled in with pre-shared key * -* Caller must use free() to free @key->data when finished. +* Caller must use free() to free "key->data" when finished. * -* Return values: -* %true: Success; @key has been initialized -* %false: Failure +* @retval true Success; "key" has been initialized +* @retval false Failure */ bool tlshd_keyring_get_psk_key (key_serial_t serial,gnutls_datum_t *key) {
@@ -111,15 +113,14 @@ bool tlshd_keyring_get_psk_key(key_serial_t serial, gnutls_datum_t *key) }/** -* tlshd_keyring_get_privkey - Retrieve privkey for x.509 handshake -* @serial: Key serial number to look up -* @privkey: On success, filled in with a private key +* @brief Retrieve privkey for x.509 handshake +* @param[in] serial Key serial number to look up +* @param[out] privkey Filled in with a private key * -* Caller must use gnutls_privkey_deinit() to free @privkey when finished. +* Caller must use gnutls_privkey_deinit() to free "privkey" when finished. * -* Return values: -* %true: Success; @privkey has been initialized -* %false: Failure +* @retval true Success; "privkey" has been initialized +* @retval false Failure */ bool tlshd_keyring_get_privkey (key_serial_t serial,gnutls_privkey_t *privkey) {
@@ -157,16 +158,15 @@ bool tlshd_keyring_get_privkey(key_serial_t serial, gnutls_privkey_t *privkey) }/** -* tlshd_keyring_get_certs - Retrieve certs for x.509 handshake -* @serial: Key serial number to look up -* @certs: On success, filled in with certificates -* @certs_len: IN: maximum number of certs to get, OUT: number of certs found +* @brief Retrieve certs for x.509 handshake +* @param[in] serial Key serial number to look up +* @param[out] certs On success, filled in with certificates +* @param[in,out] certs_len Maximum number of certs to get, number of certs found * -* Caller must use gnutls_pcert_deinit() to free @cert when finished. +* Caller must use gnutls_pcert_deinit() to free "cert" when finished. * -* Return values: -* %true: Success; @cert has been initialized -* %false: Failure +* @retval true Success; "cert" has been initialized +* @retval false Failure */ bool tlshd_keyring_get_certs (key_serial_t serial,gnutls_pcert_st *certs,unsigned int *certs_len)
@@ -205,11 +205,11 @@ bool tlshd_keyring_get_certs(key_serial_t serial, gnutls_pcert_st *certs, }/** -* tlshd_keyring_create_cert - Create key containing peer's certificate -* @cert: Initialized x.509 certificate -* @peername: hostname of the remote peer +* @brief Create key containing peer's certificate +* @param[in] cert Initialized x.509 certificate +* @param[in] peername Hostname of the remote peer * -* Returns a positive key serial number on success; otherwise +* @returns a positive key serial number on success; otherwise * TLS_NO_PEERID. */ key_serial_t tlshd_keyring_create_cert(gnutls_x509_crt_t cert,
@@ -246,10 +246,11 @@ out: }/** -* tlshd_keyring_link_session - Link a keyring into the session keyring -* @keyring: keyring to be linked +* @brief Link a keyring into the session keyring +* @param[in] keyring keyring to be linked * -* Returns 0 on success and -1 on error. +* @retval 0 Success +* @retval -1 Failure */ int tlshd_keyring_link_session (const char *keyring) {
Signature · 1 line
2.51.0
Chuck Lever
maintainerPATCH 8/16 tlshd: Translate kernel-style Doxygen comments in src/tlshd/ktls.c
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
I started the ktls-utils project using the Linux kernel flavor of Doxygen commenting which user-space Doxygen does not recognize by default.
Convert existing comments in ktls.c to what a normal user space Doxygen run expects to see. This will enable deployment of an automatically-generated documentation web site.
--- src/tlshd/ktls.c | 118 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 102 insertions(+), 16 deletions(-)
src/tlshd/ktls.c +102 -16
@@ -1,9 +1,13 @@ -/* -* Initialize a kTLS socket. In some cases initialization might -* be handled by the TLS library. +/** +* @file ktls.c +* @brief Initialize a kTLS socket. In some cases initialization might +* be handled by the TLS library * +* @copyright * Copyright (c) 2022 Oracle and/or its affiliates. -* +*/ + +/* * ktls-utils is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; version 2.
@@ -42,6 +46,13 @@#include "tlshd.h" #include "netlink.h" +/** +* @brief Concatenate two NUL-terminated C strings +* @param[in] str1 left-hand string +* @param[in] str2 right-hand string +* +* @returns "str1" followed by "str2" +*/ static char *tlshd_string_concat (char *str1,const char *str2) {size_t len =0 ;
@@ -69,6 +80,14 @@ static char *tlshd_string_concat(char *str1, const char *str2) }#ifdef HAVE_GNUTLS_TRANSPORT_IS_KTLS_ENABLED +/** +* @brief Determine if a session is kTLS-enabled +* @param[in] session An established TLS session +* @param[in] read Which side of the duplex to check +* +* @retval true The session is prepared to use kTLS +* @retval false The session is not prepared to use kTLS +*/ static bool tlshd_is_ktls_enabled (gnutls_session_t session,unsigned read) {int ret;
@@ -90,6 +109,14 @@ static bool tlshd_is_ktls_enabled(gnutls_session_t session, unsigned read) }#else +/** +* @brief Determine if a session is kTLS-enabled +* @param[in] session An established TLS session +* @param[in] read Which side of the duplex to check +* +* @retval true The session is prepared to use kTLS +* @retval false The session is not prepared to use kTLS +*/ static bool tlshd_is_ktls_enabled (__attribute__ ((unused))gnutls_session_t session, __attribute__ ((unused))unsigned read) {
@@ -97,6 +124,16 @@ static bool tlshd_is_ktls_enabled(__attribute__ ((unused)) gnutls_session_t sess }#endif +/** +* @brief Call setsockopt(3), with error logging +* @param[in] sock An open socket descriptor +* @param[in] read Read or write side +* @param[in] info The value to set +* @param[in] infolen The size of "info", in bytes +* +* @retval true The option was set successfully +* @retval false The option was not set +*/ static bool tlshd_setsockopt (int sock,unsigned read,const void *info,socklen_t infolen) {
@@ -123,6 +160,15 @@ static bool tlshd_setsockopt(int sock, unsigned read, const void *info, }#if defined(TLS_CIPHER_AES_GCM_128 ) +/** +* @brief Configure TLS session for AES-GCM-128 encryption +* @param[in] session An established TLS session +* @param[in] sock An open socket descriptor +* @param[in] read Read or write side +* +* @retval true The session was configured successfully +* @retval false The session was not configured +*/ static bool tlshd_set_aes_gcm128_info (gnutls_session_t session,int sock,unsigned read) {
@@ -162,6 +208,15 @@ static bool tlshd_set_aes_gcm128_info(gnutls_session_t session, int sock,#endif #if defined(TLS_CIPHER_AES_GCM_256 ) +/** +* @brief Configure TLS session for AES-GCM-256 encryption +* @param[in] session An established TLS session +* @param[in] sock An open socket descriptor +* @param[in] read Read or write side +* +* @retval true The session was configured successfully +* @retval false The session was not configured +*/ static bool tlshd_set_aes_gcm256_info (gnutls_session_t session,int sock,unsigned read) {
@@ -201,6 +256,15 @@ static bool tlshd_set_aes_gcm256_info(gnutls_session_t session, int sock,#endif #if defined(TLS_CIPHER_AES_CCM_128 ) +/** +* @brief Configure TLS session for AES-CCM-128 encryption +* @param[in] session An established TLS session +* @param[in] sock An open socket descriptor +* @param[in] read Read or write side +* +* @retval true The session was configured successfully +* @retval false The session was not configured +*/ static bool tlshd_set_aes_ccm128_info (gnutls_session_t session,int sock,unsigned read) {
@@ -240,6 +304,15 @@ static bool tlshd_set_aes_ccm128_info(gnutls_session_t session, int sock,#endif #if defined(TLS_CIPHER_CHACHA20_POLY1305 ) +/** +* @brief Configure TLS session for ChaCha-Poly1305 encryption +* @param[in] session An established TLS session +* @param[in] sock An open socket descriptor +* @param[in] read Read or write side +* +* @retval true The session was configured successfully +* @retval false The session was not configured +*/ static bool tlshd_set_chacha20_poly1305_info (gnutls_session_t session,int sock,unsigned read) {
@@ -275,10 +348,10 @@ static bool tlshd_set_chacha20_poly1305_info(gnutls_session_t session, int sock,#endif /** -* tlshd_initialize_ktls - Initialize socket for use by kTLS -* @session: TLS session descriptor +* @brief Initialize a socket for use by kTLS +* @param[in] session TLS session descriptor * -* Returns zero on success, or a positive errno value. +* @returns zero on success, or a positive errno value. */ unsigned int tlshd_initialize_ktls (gnutls_session_t session) {
@@ -320,6 +393,13 @@ unsigned int tlshd_initialize_ktls(gnutls_session_t session)return EIO ; } +/** +* @brief Concatenate a cipher name to a string +* @param[in] pstring NUL-terminated C string +* @param[in] cipher GnuTLS cipher number +* +* @retval A NUL-terminated C string; caller must free the string with free(3) +*/ static char *tlshd_cipher_string_emit (char *pstring,unsigned int cipher) {switch (cipher) {
@@ -350,6 +430,13 @@ static gnutls_priority_t tlshd_gnutls_priority_psk;static gnutls_priority_t tlshd_gnutls_priority_psk_sha256;static gnutls_priority_t tlshd_gnutls_priority_psk_sha384; +/** +* @brief Initialize GnuTLS priority caches +* @param[in] ciphers Array of GnuTLS cipher numbers +* @param[in] cipher_count count of elements in "ciphers" +* +* @retval Zero on success; a negative errno if a failure occurred. +*/ static int tlshd_gnutls_priority_init_list (const unsigned int *ciphers,int cipher_count) {
@@ -498,9 +585,9 @@ static int tlshd_gnutls_priority_init_list(const unsigned int *ciphers, }/** -* tlshd_gnutls_priority_init - Initialize GnuTLS priority caches +* @brief Initialize GnuTLS priority caches * -* Returns zero on success, or a negative errno value if a failure +* @returns zero on success, or a negative errno value if a failure * occurred. */ int tlshd_gnutls_priority_init (void )
@@ -532,12 +619,12 @@ out: }/** -* tlshd_gnutls_priority_set - Initialize priorities per-session -* @session: session to initialize -* @parms: handshake parameters -* @psk_len: size of pre-shared key in bytes, or zero +* @brief Select GnuTLS priority cache to use for "session" +* @param[in] session Session to initialize +* @param[in] parms Handshake parameters +* @param[in] psk_len Size of pre-shared key in bytes, or zero * -* Returns GNUTLS_E_SUCCESS on success, otherwise an error code. +* @returns GNUTLS_E_SUCCESS on success, otherwise an error code. */ int tlshd_gnutls_priority_set(gnutls_session_t session, const struct tlshd_handshake_parms *parms,
@@ -558,8 +645,7 @@ int tlshd_gnutls_priority_set(gnutls_session_t session, }/** -* tlshd_gnutls_priority_deinit - Free GnuTLS priority caches -* +* @brief Free GnuTLS priority caches */ void tlshd_gnutls_priority_deinit (void ) {
Signature · 1 line
2.51.0
Chuck Lever
maintainerPATCH 9/16 tlshd: Translate kernel-style Doxygen comments in src/tlshd/log.c
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
I started the ktls-utils project using the Linux kernel flavor of Doxygen commenting which user-space Doxygen does not recognize by default.
Convert existing comments in log.c to what a normal user space Doxygen run expects to see. This will enable deployment of an automatically-generated documentation web site.
--- src/tlshd/log.c | 102 +++++++++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 49 deletions(-)
src/tlshd/log.c +53 -49
@@ -1,8 +1,12 @@ -/* -* Record audit and debugging information in the system log. +/** +* @file log.c +* @brief Record audit and debugging information in the system log * +* @copyright * Copyright (c) 2022 Oracle and/or its affiliates. -* +*/ + +/* * ktls-utils is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; version 2.
@@ -40,14 +44,27 @@#include "tlshd.h" +/** +* @var int tlshd_debug +* Global debug verbosity setting +*/ int tlshd_debug; + +/** +* @var int tlshd_tls_debug +* Global debug verbosity setting for TLS library calls +*/ int tlshd_tls_debug; + +/** +* @var int tlshd_stderr +* Global setting to output on stderr as well as syslog +*/ int tlshd_stderr;/** -* tlshd_log_completion - Emit completion notification -* @parms: handshake parameters -* +* @brief Emit completion notification +* @param[in] parms Handshake parameters */ void tlshd_log_completion (struct tlshd_handshake_parms *parms) {
@@ -69,9 +86,8 @@ void tlshd_log_completion(struct tlshd_handshake_parms *parms) }/** -* tlshd_log_debug - Emit a debugging notification -* @fmt - printf-style format string -* +* @brief Emit a debugging notification +* @param[in] fmt printf-style format string */ void tlshd_log_debug (const char *fmt, ...) {
@@ -86,9 +102,8 @@ void tlshd_log_debug(const char *fmt, ...) }/** -* tlshd_log_error - Emit a generic error notification -* @fmt - printf-style format string -* +* @brief Emit a generic error notification +* @param[in] fmt printf-style format string */ void tlshd_log_error (const char *fmt, ...) {
@@ -100,9 +115,8 @@ void tlshd_log_error(const char *fmt, ...) }/** -* tlshd_log_notice - Emit a generic warning -* @fmt - printf-style format string -* +* @brief Emit a generic warning +* @param[in] fmt printf-style format string */ void tlshd_log_notice (const char *fmt, ...) {
@@ -114,9 +128,8 @@ void tlshd_log_notice(const char *fmt, ...) }/** -* tlshd_log_perror - Emit "system call failed" notification -* @sap: remote address to log -* +* @brief Emit "system call failed" notification +* @param[in] prefix Identifier string */ void tlshd_log_perror (const char *prefix) {
@@ -124,9 +137,8 @@ void tlshd_log_perror(const char *prefix) }/** -* tlshd_log_gai_error - Emit "getaddr/nameinfo failed" notification -* @error: error code returned by getaddrinfo(3) or getnameinfo(3) -* +* @brief Emit "getaddr/nameinfo failed" notification +* @param[in] error error code returned by getaddrinfo(3) or getnameinfo(3) */ void tlshd_log_gai_error (int error) {
@@ -160,9 +172,8 @@ static const struct tlshd_cert_status_bit tlshd_cert_status_names[] = { };/** -* tlshd_log_cert_verification_error - Report a failed certificate verification -* @session: Session with a failed handshake -* +* @brief Report a failed certificate verification +* @param[in] session Session with a failed handshake */ void tlshd_log_cert_verification_error (gnutls_session_t session) {
@@ -178,9 +189,8 @@ void tlshd_log_cert_verification_error(gnutls_session_t session) }/** -* tlshd_log_gnutls_error - Emit "library call failed" notification -* @error: GnuTLS error code to log -* +* @brief Emit "library call failed" notification +* @param[in] error GnuTLS error code to log */ void tlshd_log_gnutls_error (int error) {
@@ -188,10 +198,9 @@ void tlshd_log_gnutls_error(int error) }/** -* tlshd_gnutls_log_func - Library callback function to log a message -* @level: log level -* @msg: message to log -* +* @brief Library callback function to log a message +* @param[in] level Log level +* @param[in] msg Message to log */ void tlshd_gnutls_log_func (int level,const char *msg) {
@@ -199,10 +208,9 @@ void tlshd_gnutls_log_func(int level, const char *msg) }/** -* tlshd_gnutls_audit_func - Library callback function to log an audit message -* @session: controlling GnuTLS session -* @msg: message to log -* +* @brief Library callback function to log an audit message +* @param[in] session Controlling GnuTLS session +* @param[in] msg Message to log */ void tlshd_gnutls_audit_func (__attribute__ ((unused))gnutls_session_t session,const char *msg)
@@ -211,10 +219,9 @@ void tlshd_gnutls_audit_func(__attribute__ ((unused)) gnutls_session_t session, }/** -* tlshd_log_gerror - Emit glib2 "library call failed" notification -* @msg: message to log -* @error: error information -* +* @brief Emit glib2 "library call failed" notification +* @param[in] msg Message to log +* @param[in] error Error information */ void tlshd_log_gerror (const char *msg,GError *error) {
@@ -222,10 +229,9 @@ void tlshd_log_gerror(const char *msg, GError *error) }/** -* tlshd_log_nl_error - Log a netlink error -* @msg: message to log -* @err: error number -* +* @brief Log a netlink error +* @param[in] msg Message to log +* @param[in] err Error number */ void tlshd_log_nl_error (const char *msg,int err) {
@@ -233,8 +239,8 @@ void tlshd_log_nl_error(const char *msg, int err) }/** -* tlshd_log_init - Initialize audit logging -* @progname: NUL-terminated string containing program name +* @brief Initialize audit logging +* @param[in] progname NUL-terminated string containing program name * */ void tlshd_log_init (const char *progname)
@@ -250,8 +256,7 @@ void tlshd_log_init(const char *progname) }/** -* tlshd_log_shutdown - Log a tlshd shutdown notice -* +* @brief Log a tlshd shutdown notice */ void tlshd_log_shutdown (void ) {
@@ -259,8 +264,7 @@ void tlshd_log_shutdown(void) }/** -* tlshd_log_close - Release audit logging resources -* +* @brief Release audit logging resources */ void tlshd_log_close (void ) {
Signature · 1 line
2.51.0
Chuck Lever
maintainerPATCH 10/16 tlshd: Translate kernel-style Doxygen comments in src/tlshd/main.c
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
I started the ktls-utils project using the Linux kernel flavor of Doxygen commenting which user-space Doxygen does not recognize by default.
Convert existing comments in main.c to what a normal user space Doxygen run expects to see. This will enable deployment of an automatically-generated documentation web site.
--- src/tlshd/main.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)
src/tlshd/main.c +21 -5
@@ -1,9 +1,13 @@ -/* -* Handle a request for a TLS handshake on behalf of an -* in-kernel TLS consumer. +/** +* @file main.c +* @brief Handle a request for a TLS handshake on behalf of an +* in-kernel TLS consumer * +* @copyright * Copyright (c) 2022 - 2023 Oracle and/or its affiliates. -* +*/ + +/* * ktls-utils is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; version 2.
@@ -56,11 +60,23 @@ static const struct option longopts[] = { { NULL, 0, NULL, 0 } }; -static void usage (const char *progname) +/** +* @brief Emit a program usage message on stderr +* @param[in] progname NUL-terminated C string containing program name +*/ +static void usage (char *progname) {fprintf (stderr,"usage: %s [-chsv]\n" , progname); } +/** +* @brief tlshd program entry point +* @param[in] argc Count of elements in "argv" +* @param[in] argv Command line parameters +* +* @retval EXIT_SUCCESS Program terminated normally +* @retval EXIT_FAILURE Program encountered an error +*/ int main (int argc,char **argv) {static gchar config_file[PATH_MAX +1 ];
Signature · 1 line
2.51.0
Chuck Lever
maintainerPATCH 11/16 tlshd: Translate kernel-style Doxygen comments in src/tlshd/netlink.c
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
I started the ktls-utils project using the Linux kernel flavor of Doxygen commenting which user-space Doxygen does not recognize by default.
Convert existing comments in netlink.c to what a normal user space Doxygen run expects to see. This will enable deployment of an automatically-generated documentation web site.
--- src/tlshd/netlink.c | 110 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 95 insertions(+), 15 deletions(-)
src/tlshd/netlink.c +95 -15
@@ -1,8 +1,12 @@ -/* -* Netlink operations for tlshd +/** +* @file netlink.c +* @brief Handle communication with the kernel via netlink * +* @copyright * Copyright (c) 2023 Oracle and/or its affiliates. -* +*/ + +/* * ktls-utils is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; version 2.
@@ -51,8 +55,20 @@#include "tlshd.h" #include "netlink.h" +/** +* @var unsigned int tlshd_delay_done +* Global number of seconds to delay each handshake completion +*/ unsigned int tlshd_delay_done; +/** +* @brief Open a netlink socket +* @param [out] sock A netlink socket descriptor +* +* @retval 0 Success; caller must close "sock" with tlshd_genl_sock_close +* @retval ENOMEM Failed to allocate the socket +* @retval ENOLINK Failed to connect to the netlink service +*/ static int tlshd_genl_sock_open (struct nl_sock **sock) {struct nl_sock *nls;
@@ -79,6 +95,10 @@ out:return ret; } +/** +* @brief Close a netlink socket +* @param[in] nls A netlink socket descriptor +*/ static void tlshd_genl_sock_close (struct nl_sock *nls) {if (!nls)
@@ -88,6 +108,10 @@ static void tlshd_genl_sock_close(struct nl_sock *nls)nl_socket_free (nls); } +/** +* @var struct nla_policy tlshd_accept_nl_policy +* Netlink policies for ACCEPT arguments +*/ #if LIBNL_VER_NUM >=LIBNL_VER (3 ,5 ) static const struct nla_policy#else
@@ -105,11 +129,33 @@ tlshd_accept_nl_policy[HANDSHAKE_A_ACCEPT_MAX + 1] = { [HANDSHAKE_A_ACCEPT_KEYRING] = { .type = NLA_U32, }, }; +/** +* @var struct nl_sock *tlshd_notification_nls +* Netlink socket on which notification events arrive +*/ static struct nl_sock *tlshd_notification_nls; +/** +* @var sigset_t tlshd_sig_poll_mask +* Daemon's signal poll mask +*/ static sigset_t tlshd_sig_poll_mask; + +/** +* @var int tlshd_sig_poll_fd +* Daemon's signal poll file descriptor +*/ static int tlshd_sig_poll_fd; +/** +* @brief Process one netlink notification event +* @param[in] msg A netlink event to be handled +* @param[in] arg Additional arguments +* +* @retval NL_OK Proceed with the next message +* @retval NL_SKIP Skip this message. +* @retval NL_STOP Stop and discard remaining messages. +*/ static int tlshd_genl_event_handler (struct nl_msg *msg, __attribute__ ((unused))void *arg) {
@@ -148,8 +194,7 @@ static int tlshd_genl_event_handler(struct nl_msg *msg, }/** -* tlshd_genl_dispatch - handle notification events -* +* @brief Handle notification events */ void tlshd_genl_dispatch (void ) {
@@ -231,6 +276,11 @@ out_close:tlshd_genl_sock_close (tlshd_notification_nls); } +/** +* @brief Extract the key serial number of the key with the remote peerid +* @param[in] parms Handshake parameters +* @param[in] head List of nlattrs to parse +*/ static void tlshd_parse_peer_identity (struct tlshd_handshake_parms *parms,struct nlattr *head) {
@@ -245,6 +295,10 @@ static void tlshd_parse_peer_identity(struct tlshd_handshake_parms *parms,g_array_append_val (parms->peerids, peerid); } +/** +* @var struct nla_policy tlshd_x509_nl_policy +* Netlink policies for x.509 key serial numbers +*/ #if LIBNL_VER_NUM >=LIBNL_VER (3 ,5 ) static const struct nla_policy#else
@@ -255,6 +309,11 @@ tlshd_x509_nl_policy[HANDSHAKE_A_X509_MAX + 1] = { [HANDSHAKE_A_X509_PRIVKEY] = { .type = NLA_U32, }, }; +/** +* @brief Extract the key serial number of the key with the cert / privkey +* @param[in] parms Handshake parameters +* @param[in] head List of nlattrs to parse +*/ static void tlshd_parse_certificate (struct tlshd_handshake_parms *parms,struct nlattr *head) {
@@ -277,6 +336,15 @@ static void tlshd_parse_certificate(struct tlshd_handshake_parms *parms, parms->x509_privkey =nla_get_s32 (tb[HANDSHAKE_A_X509_PRIVKEY ]); } +/** +* @brief Process an ACCESS argument +* @param[in] msg Message to be processed +* @param[out] arg Handshake parms to be filled in +* +* @retval NL_OK Proceed with the next message +* @retval NL_SKIP Skip this message. +* @retval NL_STOP Stop and discard remaining messages. +*/ static int tlshd_genl_valid_handler (struct nl_msg *msg,void *arg) {struct nlattr *tb[HANDSHAKE_A_ACCEPT_MAX +1 ];
@@ -363,6 +431,10 @@ static int tlshd_genl_valid_handler(struct nl_msg *msg, void *arg)return NL_SKIP ; } +/** +* @var struct tlshd_handshake_parms tlshd_default_handshake_parms +* Starting parameter values for each handshake +*/ static const struct tlshd_handshake_parms tlshd_default_handshake_parms = { .peername =NULL , .peeraddr =NULL ,
@@ -379,13 +451,15 @@ static const struct tlshd_handshake_parms tlshd_default_handshake_parms = { };/** -* tlshd_genl_get_handshake_parms - Retrieve handshake parameters -* @parms: buffer to fill in with parameters +* @brief Retrieve handshake parameters +* @param[in] parms Buffer to fill in with parameters * -* Returns 0 if handshake parameters were retrieved successfully. +* Caller must release handshake resources by calling +* tlshd_genl_put_handshake_parms when finished. * +* @returns 0 if handshake parameters were retrieved successfully. * Otherwise a positive errno is returned, and the content of -* @parms is indeterminant. +* "parms" is indeterminant. */ int tlshd_genl_get_handshake_parms (struct tlshd_handshake_parms *parms) {
@@ -460,9 +534,8 @@ out_close: }/** -* tlshd_genl_put_handshake_parms - Release handshake resources -* @parms: handshake parameters to be released -* +* @brief Release handshake resources +* @param[in] parms Handshake parameters to be released */ void tlshd_genl_put_handshake_parms (struct tlshd_handshake_parms *parms) {
@@ -474,6 +547,14 @@ void tlshd_genl_put_handshake_parms(struct tlshd_handshake_parms *parms)free (parms->peeraddr); } +/** +* @brief Format all remote peerid arguments +* @param[in] msg +* @param[in] parms Handshake parameters +* +* retval 0 Formatted all remote peerid arguments successfully +* retval -1 Failed to format +*/ static int tlshd_genl_put_remote_peerids (struct nl_msg *msg,struct tlshd_handshake_parms *parms) {
@@ -494,9 +575,8 @@ static int tlshd_genl_put_remote_peerids(struct nl_msg *msg, }/** -* tlshd_genl_done - Indicate handshake has completed successfully -* @parms: buffer filled in with parameters -* +* @brief Indicate handshake has completed successfully +* @param[in] parms Buffer filled in with parameters */ void tlshd_genl_done (struct tlshd_handshake_parms *parms) {
Signature · 1 line
2.51.0
Chuck Lever
maintainerPATCH 12/16 tlshd: Translate kernel-style Doxygen comments in src/tlshd/quic.c
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
I started the ktls-utils project using the Linux kernel flavor of Doxygen commenting which user-space Doxygen does not recognize by default.
Convert existing comments in quic.c to what a normal user space Doxygen run expects to see. This will enable deployment of an automatically-generated documentation web site.
--- src/tlshd/quic.c | 180 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 166 insertions(+), 14 deletions(-)
src/tlshd/quic.c +166 -14
@@ -1,8 +1,12 @@ -/* -* Perform a QUIC server or client side handshake. +/** +* @file quic.c +* @brief Utility functions for QUIC handshakes * +* @copyright * Copyright (c) 2024 Red Hat, Inc. -* +*/ + +/* * ktls-utils is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; version 2.
@@ -31,6 +35,10 @@#include "tlshd.h" #ifdef HAVE_GNUTLS_QUIC +/** +* @brief Callback to handle a timer expiry +* @param[in,out] arg user data +*/ static void quic_timer_handler (union sigval arg) {struct tlshd_quic_conn *conn = arg.sival_ptr;
@@ -39,6 +47,13 @@ static void quic_timer_handler(union sigval arg) conn->errcode =ETIMEDOUT ; } +/** +* @brief Set a handshake timer +* @param[in,out] conn QUIC handshake context +* +* @retval 0 Timer configured successfully +* @retval -1 Failed to configure timer +*/ static int quic_conn_setup_timer (struct tlshd_quic_conn *conn) {uint64_t msec = conn->parms->timeout_ms;
@@ -62,11 +77,21 @@ static int quic_conn_setup_timer(struct tlshd_quic_conn *conn)return 0 ; } +/** +* @brief Delete a handshake timer +* @param[in,out] conn QUIC handshake context +*/ static void quic_conn_delete_timer (struct tlshd_quic_conn *conn) {timer_delete (conn->timer); } +/** +* @brief Convert a GnuTLS cipher number to a kTLS cipher number +* @param[in] cipher kTLS cipher number to be converted +* +* @returns a kTLS cipher number. +*/ static uint32_t quic_get_tls_cipher_type (gnutls_cipher_algorithm_t cipher) {switch (cipher) {
@@ -84,6 +109,12 @@ static uint32_t quic_get_tls_cipher_type(gnutls_cipher_algorithm_t cipher) } } +/** +* @brief Convert a GnuTLS encryption level number +* @param[in] level GnuTLS encryption level +* +* @returns a QUIC encryption level number. +*/ static enum quic_crypto_level quic_get_crypto_level (gnutls_record_encryption_level_t level) {switch (level) {
@@ -101,6 +132,17 @@ static enum quic_crypto_level quic_get_crypto_level(gnutls_record_encryption_lev } } +/** +* @brief Callback to process a new traffic secret +* @param[in,out] session GnuTLS session +* @param[in] level GnuTLS encryption level +* @param[in] rx_secret Receive secret, or NULL +* @param[in] tx_secret Transmit secret, or NULL +* @param[in] secretlen Length of secrets, in bytes +* +* @retval 0 Callback completed successfully +* @retval -1 Callback failed +*/ static int quic_secret_func (gnutls_session_t session,gnutls_record_encryption_level_t level,const void *rx_secret,const void *tx_secret,size_t secretlen) {
@@ -150,6 +192,15 @@ static int quic_secret_func(gnutls_session_t session, gnutls_record_encryption_lreturn 0 ; } +/** +* @brief Callback to handle an outgoing alert +* @param[in,out] session GnuTLS session +* @param[in] level GnuTLS encryption level +* @param[in] alert_level TLS alert level number +* @param[in] alert_desc TLS alert description number +* +* @retval 0 Callback completed successfully +*/ static int quic_alert_read_func(gnutls_session_t session, gnutls_record_encryption_level_t gtls_level, gnutls_alert_level_t alert_level,
@@ -160,6 +211,15 @@ static int quic_alert_read_func(gnutls_session_t session,return 0 ; } +/** +* @brief Callback to receive handshake data +* @param[in,out] session GnuTLS session +* @param[in] buf Buffer containing received data +* @param[in] len Length of content in "buf", in bytes +* +* @retval 0 Callback completed successfully +* @retval -1 Callback failed +*/ static int quic_tp_recv_func (gnutls_session_t session,const uint8_t *buf,size_t len) {struct tlshd_quic_conn *conn =gnutls_session_get_ptr (session);
@@ -172,6 +232,14 @@ static int quic_tp_recv_func(gnutls_session_t session, const uint8_t *buf, size_return 0 ; } +/** +* @brief Callback to send handshake data +* @param[in,out] session GnuTLS session +* @param[in] buf Buffer to be filled in with data to send +* +* @retval 0 Callback completed successfully +* @retval -1 Callback failed +*/ static int quic_tp_send_func (gnutls_session_t session,gnutls_buffer_t extdata) {struct tlshd_quic_conn *conn =gnutls_session_get_ptr (session);
@@ -194,6 +262,17 @@ static int quic_tp_send_func(gnutls_session_t session, gnutls_buffer_t extdata)return 0 ; } +/** +* @brief Callback to handle an outgoing handshake message +* @param[in,out] session GnuTLS session +* @param[in] level GnuTLS encryption level +* @param[in] htype GnuTLS handshake description +* @param[in] data message to be processed +* @param[in] datalen length of "data" in bytes +* +* @retval 0 Callback completed successfully +* @retval -1 Callback failed +*/ static int quic_read_func (gnutls_session_t session,gnutls_record_encryption_level_t level,gnutls_handshake_description_t htype,const void *data,size_t datalen) {
@@ -224,9 +303,21 @@ static int quic_read_func(gnutls_session_t session, gnutls_record_encryption_levreturn 0 ; } +/** +* @var char quic_priority +* Default GnuTLS priority string for QUIC connections +*/ static char quic_priority[] ="%DISABLE_TLS13_COMPAT_MODE:NORMAL:-VERS-ALL:+VERS-TLS1.3:+PSK:-CIPHER-ALL:+" ; +/** +* @brief Set the GnuTLS priority string for a session +* @param[in,out] session GnuTLS session +* @param[in] cipher kTLS cipher number to set +* +* @retval 0 GnuTLS priority string set successfully +* @retval -1 Failed to set GnuTLS priority string +*/ static int quic_session_set_priority (gnutls_session_t session,uint32_t cipher) {char p[136 ] = {};
@@ -258,6 +349,14 @@ static int quic_session_set_priority(gnutls_session_t session, uint32_t cipher)return 0 ; } +/** +* @brief Set the ALPN information on a session +* @param[in,out] session GnuTLS session +* @param[in] alpn_data ALPN string to set +* +* @retval 0 ALPN string set successfully +* @retval -1 Failed to set ALPN string +*/ static int quic_session_set_alpns (gnutls_session_t session,char *alpn_data) {gnutls_datum_t alpns[TLSHD_QUIC_MAX_ALPNS_LEN /2 ];
@@ -281,6 +380,12 @@ static int quic_session_set_alpns(gnutls_session_t session, char *alpn_data)return 0 ; } +/** +* @brief Translate the encryption level value +* @param[in] level QUIC encryption level +* +* @returns an equivalent GNUTLS_ENCRYPTION value +*/ static gnutls_record_encryption_level_t quic_get_encryption_level (uint8_t level) {switch (level) {
@@ -298,6 +403,13 @@ static gnutls_record_encryption_level_t quic_get_encryption_level(uint8_t level) } } +/** +* @brief Retrieve QUIC connection configuration +* @param[in] conn QUIC handshake context +* +* @retval 0 Connection configuration retrieved successfully +* @retval -1 Failed to retrieve configuration +*/ static int quic_conn_get_config (struct tlshd_quic_conn *conn) {int sockfd = conn->parms->sockfd;
@@ -326,6 +438,13 @@ static int quic_conn_get_config(struct tlshd_quic_conn *conn)return 0 ; } +/** +* @brief Send one QUIC handshake message on a socket +* @param[in] sockfd Socket on which to send +* @param[in] msg Buffer containing message to send +* +* @returns the number of bytes sent, or -1 if an error occurred. +*/ static int quic_handshake_sendmsg (int sockfd,struct tlshd_quic_msg *msg) {char outcmsg[CMSG_SPACE (sizeof (struct quic_handshake_info ))];
@@ -359,6 +478,13 @@ static int quic_handshake_sendmsg(int sockfd, struct tlshd_quic_msg *msg)return sendmsg (sockfd, &outmsg, flags); } +/** +* @brief Receive one QUIC handshake message on a socket +* @param[in] sockfd Socket on which to receive +* @param[in,out] msg Buffer in which to receive a message +* +* @returns the number of bytes received, or -1 if an error occurred. +*/ static int quic_handshake_recvmsg (int sockfd,struct tlshd_quic_msg *msg) {char incmsg[CMSG_SPACE (sizeof (struct quic_handshake_info ))];
@@ -397,11 +523,28 @@ static int quic_handshake_recvmsg(int sockfd, struct tlshd_quic_msg *msg)return ret; } -static int quic_handshake_completed (const struct tlshd_quic_conn *conn) +/** +* @brief Predicate: Has the QUIC handshake completed +* @param[in] conn QUIC handshake context +* +* @retval true The handshake completed +* @retval false The handshake has not completed +*/ +static bool quic_handshake_completed (const struct tlshd_quic_conn *conn) {return conn->completed || conn->errcode; } +/** +* @brief Get the generated session data +* @param[in] conn QUIC handshake context +* @param[in] level Encryption level +* @param[in] data Ticket blob +* @param[in] datalen length of "data" in bytes +* +* @retval 0 Session data retrieved successfully +* @retval -1 Session data is not available +*/ static int quic_handshake_crypto_data (const struct tlshd_quic_conn *conn,uint8_t level,const uint8_t *data,size_t datalen)
@@ -433,11 +576,11 @@ err: }/** -* tlshd_quic_conn_create - Create a context for QUIC handshake -* @conn_p: pointer to accept the QUIC handshake context created -* @parms: handshake parameters +* @brief Create a context for QUIC handshake +* @param[out] conn_p Pointer to accept the QUIC handshake context created +* @param[in] parms Handshake parameters * -* Returns: %0 on success, or a negative error code +* @returns 0 on success, or a negative error code */ int tlshd_quic_conn_create (struct tlshd_quic_conn **conn_p,struct tlshd_handshake_parms *parms) {
@@ -471,9 +614,8 @@ err: }/** -* tlshd_quic_conn_destroy - Destroy a context for QUIC handshake -* @conn: QUIC handshake context to destroy -* +* @brief Destroy a context for QUIC handshake +* @param[in] conn QUIC handshake context to destroy */ void tlshd_quic_conn_destroy (struct tlshd_quic_conn *conn) {
@@ -492,6 +634,13 @@ void tlshd_quic_conn_destroy(struct tlshd_quic_conn *conn)#define QUIC_TLSEXT_TP_PARAM 0x39u +/** +* @brief Configure a tlshd_quic_conn +* @param[in,out] conn QUIC handshake context +* +* @retval 0 Connection configured successfully +* @retval -1 Failed to configure the connection +*/ static int tlshd_quic_session_configure (struct tlshd_quic_conn *conn) {gnutls_session_t session = conn->session;
@@ -518,6 +667,10 @@ static int tlshd_quic_session_configure(struct tlshd_quic_conn *conn)return 0 ; } +/** +* @brief Set up a QUIC receive session ticket +* @param[in,out] conn QUIC handshake context +*/ static void tlshd_quic_recv_session_ticket (struct tlshd_quic_conn *conn) {gnutls_session_t session = conn->session;
@@ -567,9 +720,8 @@ static void tlshd_quic_recv_session_ticket(struct tlshd_quic_conn *conn) }/** -* tlshd_quic_start_handshake - Drive the handshake interaction -* @conn: QUIC handshake context -* +* @brief Drive a QUIC handshake interaction +* @param[in,out] conn QUIC handshake context */ void tlshd_quic_start_handshake (struct tlshd_quic_conn *conn) {
Signature · 1 line
2.51.0
Chuck Lever
maintainerPATCH 13/16 tlshd: Translate kernel-style Doxygen comments in src/tlshd/server.c
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
I started the ktls-utils project using the Linux kernel flavor of Doxygen commenting which user-space Doxygen does not recognize by default.
Convert existing comments in server.c to what a normal user space Doxygen run expects to see. This will enable deployment of an automatically-generated documentation web site.
--- src/tlshd/server.c | 203 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 177 insertions(+), 26 deletions(-)
src/tlshd/server.c +177 -26
@@ -1,9 +1,13 @@ -/* -* Perform a TLSv1.3 server-side handshake. +/** +* @file server.c +* @brief Perform a TLSv1.3 server-side handshake * +* @copyright * Copyright (c) 2023 Oracle and/or its affiliates. * Copyright (c) 2024 Red Hat, Inc. -* +*/ + +/* * ktls-utils is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; version 2.
@@ -42,13 +46,50 @@#include "tlshd.h" #include "netlink.h" +/** +* @var gnutls_privkey_t tlshd_server_pq_privkey +* Server peer's post-quantum private key +*/ static gnutls_privkey_t tlshd_server_pq_privkey; + +/** +* @var gnutls_privkey_t tlshd_server_privkey +* Server peer's RSA private key +*/ static gnutls_privkey_t tlshd_server_privkey; + +/** +* @var unsigned int tlshd_server_pq_certs_len +* Count of server peer's PQ certificates +*/ static unsigned int tlshd_server_pq_certs_len =TLSHD_MAX_CERTS ; + +/** +* @var unsigned int tlshd_server_certs_len +* Count of server peer's certificates +*/ static unsigned int tlshd_server_certs_len =TLSHD_MAX_CERTS ; + +/** +* @var gnutls_pcert_st tlshd_server_certs +* Server peer's certificates +*/ static gnutls_pcert_st tlshd_server_certs[TLSHD_MAX_CERTS ]; + +/** +* @var gnutls_pk_algorithm_t tlshd_server_pq_pkalg +* Server peer certificate's public key algorithms +*/ static gnutls_pk_algorithm_t tlshd_server_pq_pkalg =GNUTLS_PK_UNKNOWN ; +/** +* @brief Retrieve server certificates to be used for ServerHello +* @param[in] parms Handshake parameters +* +* @retval true Server certificates were found. Caller must release +* the certificates using tlshd_x509_server_put_certs. +* @retval false No usable server certificates were found +*/ static bool tlshd_x509_server_get_certs (struct tlshd_handshake_parms *parms) {if (parms->x509_cert !=TLS_NO_CERT )
@@ -61,6 +102,9 @@ static bool tlshd_x509_server_get_certs(struct tlshd_handshake_parms *parms) &tlshd_server_pq_pkalg); } +/** +* @brief Release server certificates that were used for ServerHello +*/ static void tlshd_x509_server_put_certs (void ) {unsigned int i;
@@ -69,6 +113,14 @@ static void tlshd_x509_server_put_certs(void)gnutls_pcert_deinit (&tlshd_server_certs[i]); } +/** +* @brief Retrieve the private key to be used for ServerHello +* @param[in] parms Handshake parameters +* +* @retval true Private key was found. Caller must release the +* private key using tlshd_x509_server_put_privkey. +* @retval false No usable private key was found +*/ static bool tlshd_x509_server_get_privkey (struct tlshd_handshake_parms *parms) {if (parms->x509_privkey !=TLS_NO_PRIVKEY )
@@ -79,12 +131,20 @@ static bool tlshd_x509_server_get_privkey(struct tlshd_handshake_parms *parms) &tlshd_server_privkey); } +/** +* @brief Release the private key that was used for ServerHello +*/ static void tlshd_x509_server_put_privkey (void ) {gnutls_privkey_deinit (tlshd_server_pq_privkey);gnutls_privkey_deinit (tlshd_server_privkey); } +/** +* @brief Audit trust chain of incoming client certificate +* @param[in] req_ca_rdn +* @param[in] nreqs +*/ static void tlshd_x509_log_issuers (const gnutls_datum_t *req_ca_rdn,int nreqs) {char issuer_dn[256 ];
@@ -107,7 +167,18 @@ static void tlshd_x509_log_issuers(const gnutls_datum_t *req_ca_rdn, int nreqs) }/** -* tlshd_x509_retrieve_key_cb - Initialize client's x.509 identity +* @brief Initialize the server peer's x.509 identity +* @param[in] session session in the midst of a handshake +* @param[in] req_ca_rdn +* @param[in] nreqs +* @param[in] pk_algos +* @param[in] pk_algos_length +* @param[out] pcert +* @param[out] pcert_length +* @param[out] privkey +* +* @retval 0 Success; output parameters are set accordingly +* @retval -1 Failure * * Callback function is of type gnutls_certificate_retrieve_function2 *
@@ -115,10 +186,6 @@ static void tlshd_x509_log_issuers(const gnutls_datum_t *req_ca_rdn, int nreqs)* gnutls/doc/examples/ex-cert-select.c. * * Sketched-in and untested. -* -* Return values: -* %0: Success; output parameters are set accordingly -* %-1: Failure */ static int tlshd_x509_retrieve_key_cb(gnutls_session_t session,
@@ -197,6 +264,13 @@ tlshd_x509_retrieve_key_cb(gnutls_session_t session,return 0 ; } +/** +* @brief Initialize server-side trust store +* @param[out] cred Trust store to initialize +* +* @returns a GnuTLS error code. Caller must release credentials +* using gnutls_certificate_free_credentials(3). +*/ static int tlshd_server_get_truststore (gnutls_certificate_credentials_t cred) {char *pathname;
@@ -227,9 +301,9 @@ static int tlshd_server_get_truststore(gnutls_certificate_credentials_t cred) }/** -* tlshd_server_x509_verify_function - Verify remote's x.509 certificate -* @session: session in the midst of a handshake -* @parms: handshake parameters +* @brief Verify remote's x.509 certificate +* @param[in] session Session in the midst of a handshake +* @param[in] parms Handshake parameters * * A return value of %GNUTLS_E_SUCCESS indicates that the TLS session * has been allowed to continue. tlshd either sets the peerid array if
@@ -299,6 +373,13 @@ certificate_error:return GNUTLS_E_CERTIFICATE_ERROR ; } +/** +* @brief Verify a remote peer's x.509 certificate (TLSv1.3) +* @param[in] session session in the midst of a handshake +* +* @retval GNUTLS_E_SUCCESS Certificate has been successfully verified +* @retval GNUTLS_E_CERTIFICATE_ERROR Certificate verification failed +*/ static int tlshd_tls13_server_x509_verify_function (gnutls_session_t session) {struct tlshd_handshake_parms *parms =gnutls_session_get_ptr (session);
@@ -306,6 +387,10 @@ static int tlshd_tls13_server_x509_verify_function(gnutls_session_t session)return tlshd_server_x509_verify_function (session, parms); } +/** +* @brief Process an x.509-based TLS handshake with a server certificate +* @param[in] parms Handshake parameters +*/ static void tlshd_tls13_server_x509_handshake (struct tlshd_handshake_parms *parms) {gnutls_certificate_credentials_t xcred;
@@ -386,17 +471,16 @@ out_free_creds: }/** -* tlshd_server_psk_cb - Validate remote's username -* @session: session in the midst of a handshake -* @username: remote's username -* @key: PSK matching @username +* @brief Validate the remote peer's username +* @param[in] session Session in the midst of a handshake +* @param[in] username Remote peer's username +* @param[in] key PSK matching "username" * -* Searches for a key with description @username in the session -* keyring, and stores the PSK data in @key if found. +* Searches for a key with description "username" in the session +* keyring, and stores the PSK data in "key" if found. * -* Return values: -* %0: Matching key has been stored in @key -* %-1: Error during lookup, @key is not updated +* @retval 0 Matching key has been stored in "key" +* @retval -1 Error during lookup, "key" is not updated */ static int tlshd_server_psk_cb (gnutls_session_t session,const char *username,gnutls_datum_t *key)
@@ -426,6 +510,10 @@ static int tlshd_server_psk_cb(gnutls_session_t session,return 0 ; } +/** +* @brief Process an PSK-based TLS handshake (TLSv1.3) +* @param[in] parms Handshake parameters +*/ static void tlshd_tls13_server_psk_handshake (struct tlshd_handshake_parms *parms) {gnutls_psk_server_credentials_t psk_cred;
@@ -471,9 +559,8 @@ out_free_creds: }/** -* tlshd_tls13_serverhello_handshake - send a TLSv1.3 ServerHello -* @parms: handshake parameters -* +* @brief Send a TLSv1.3 ServerHello +* @param[in] parms Handshake parameters */ void tlshd_tls13_serverhello_handshake (struct tlshd_handshake_parms *parms) {
@@ -491,6 +578,17 @@ void tlshd_tls13_serverhello_handshake(struct tlshd_handshake_parms *parms) }#ifdef HAVE_GNUTLS_QUIC +/** +* @brief Verify the ALPNs presented by a remote peer +* @param[in] session +* @param[in] htype +* @param[in] when +* @param[in] incoming +* @param[in] msg +* +* @retval 0 ALPN verification was successful +* @retval -1 ALPN verification failed +*/ static int tlshd_quic_server_alpn_verify (gnutls_session_t session,unsigned int htype,unsigned int when,unsigned int incoming,const gnutls_datum_t *msg)
@@ -515,6 +613,25 @@ static int tlshd_quic_server_alpn_verify(gnutls_session_t session, unsigned intreturn 0 ; } +/** +* @brief Anti-reply protection +* @param[in] dbf +* @param[in] exp_time +* @param[in] key +* @param[in] data +* +* Currently, tlshd handles each handshake request in a new process +* rather than a thread. As a result, it cannot share the +* gnutls_anti_replay_t object across processes. This causes 0-RTT +* data to be automatically disabled, since +* _gnutls_anti_replay_check() fails validation in the absence of a +* shared anti-replay context. +* +* To properly support 0-RTT data, we need to enable sharing of the +* gnutls_anti_replay_t object across processes in some way. +* +* @retval 0 Not a replay +*/ static int tlshd_quic_server_anti_replay_db_add_func (void *dbf,time_t exp_time,const gnutls_datum_t *key,const gnutls_datum_t *data)
@@ -523,8 +640,19 @@ static int tlshd_quic_server_anti_replay_db_add_func(void *dbf, time_t exp_time,return 0 ; } +/** +* @var gnutls_anti_replay_t tlshd_quic_server_anti_replay +* Shared anti-replay context +*/ static gnutls_anti_replay_t tlshd_quic_server_anti_replay; +/** +* @brief Verify a remote peer's x.509 certificate (QUIC) +* @param[in] session session in the midst of a handshake +* +* @retval GNUTLS_E_SUCCESS Certificate has been successfully verified +* @retval GNUTLS_E_CERTIFICATE_ERROR Certificate verification failed +*/ static int tlshd_quic_server_x509_verify_function (gnutls_session_t session) {struct tlshd_quic_conn *conn =gnutls_session_get_ptr (session);
@@ -532,6 +660,18 @@ static int tlshd_quic_server_x509_verify_function(gnutls_session_t session)return tlshd_server_x509_verify_function (session, conn->parms); } +/** +* @brief Validate the remote peer's username +* @param[in] session Session in the midst of a handshake +* @param[in] username Remote peer's username +* @param[in] key PSK matching "username" +* +* Searches for a key with description "username" in the session +* keyring, and stores the PSK data in "key" if found. +* +* @retval 0 Matching key has been stored in "key" +* @retval -1 Error during lookup, "key" is not updated +*/ static int tlshd_quic_server_psk_cb (gnutls_session_t session,const char *username,gnutls_datum_t *key) {
@@ -562,6 +702,10 @@ found:return 0 ; } +/** +* @brief Prepare a session for a QUIC server handshake using an x.509 cert +* @param[in] conn +*/ static void tlshd_quic_server_set_x509_session (struct tlshd_quic_conn *conn) {struct tlshd_handshake_parms *parms = conn->parms;
@@ -631,6 +775,10 @@ err:tlshd_log_gnutls_error (ret); } +/** +* @brief Prepare a session for a QUIC client handshake using a pre-shared key +* @param[in] conn +*/ static void tlshd_quic_server_set_psk_session (struct tlshd_quic_conn *conn) {gnutls_psk_server_credentials_t cred;
@@ -665,9 +813,8 @@ err: }/** -* tlshd_quic_serverhello_handshake - send a QUIC Server Initial -* @parms: handshake parameters -* +* @brief Send a QUIC Server Initial +* @param[in] parms Handshake parameters */ void tlshd_quic_serverhello_handshake (struct tlshd_handshake_parms *parms) {
@@ -699,6 +846,10 @@ out: tlshd_quic_conn_destroy(conn); }#else +/** +* @brief Send a QUIC Server Initial +* @param[in] parms Handshake parameters +*/ void tlshd_quic_serverhello_handshake (struct tlshd_handshake_parms *parms) {tlshd_log_debug ("QUIC handshake is not enabled (%d)" , parms->auth_mode);
Signature · 1 line
2.51.0
Chuck Lever
maintainerPATCH 14/16 tlshd: Translate kernel-style Doxygen comments in src/tlshd/tlshd.h
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
I started the ktls-utils project using the Linux kernel flavor of Doxygen commenting which user-space Doxygen does not recognize by default.
Convert existing comments in tlshd.h to what a normal user space Doxygen run expects to see. This will enable deployment of an automatically-generated documentation web site.
--- src/tlshd/tlshd.h | 78 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 17 deletions(-)
src/tlshd/tlshd.h +61 -17
@@ -1,6 +1,9 @@ +/** +* @file tlshd.h +* @brief Generic definitions and forward declarations for tlshd +*/ +/* -* Generic definitions and forward declarations for tlshd. -* * ktls-utils is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; version 2.
@@ -18,6 +21,10 @@#include <linux/netlink.h> +/** +* @def ARRAY_SIZE +* @brief Generate the number of elements in an array +*/ #define ARRAY_SIZE (a) (sizeof(a) / sizeof((a)[0]))extern int tlshd_debug;
@@ -27,21 +34,27 @@ extern int tlshd_stderr;struct nl_sock ; +/** +* @struct tlshd_handshake_parms +* @brief Handshake parameters (global) +*/ struct tlshd_handshake_parms { -char *peername; -char *peeraddr; -int sockfd; -int ip_proto; -uint32_t handshake_type; -unsigned int timeout_ms; -uint32_t auth_mode; -key_serial_t keyring; -key_serial_t x509_cert; -key_serial_t x509_privkey; -GArray *peerids; -GArray *remote_peerids; +/*@{*/ +char *peername;/**< Remote's DNS label */ +char *peeraddr;/**< Remote's IP address */ +int sockfd;/**< Socket on which to perform the handshake */ +int ip_proto;/**< Transport protocol number */ +uint32_t handshake_type;/**< Handshake interaction to perform */ +unsigned int timeout_ms;/**< How long to wait for completion */ +uint32_t auth_mode;/**< x.509, PSK, etc. */ +key_serial_t keyring;/**< Keyring containing auth material */ +key_serial_t x509_cert;/**< Key serial of our x.509 cert */ +key_serial_t x509_privkey;/**< Key serial of our x.509 private key */ +GArray *peerids;/**< Peer identities to present to servers */ +GArray *remote_peerids;/**< Peer identities presented by clients */ -unsigned int session_status; +unsigned int session_status;/**< Handshake completion status */ +/*@}*/ };enum peer_type {
@@ -134,6 +147,10 @@ extern void tlshd_quic_serverhello_handshake(struct tlshd_handshake_parms *parms#define TLSHD_QUIC_MAX_DATA_LEN 4096#define TLSHD_QUIC_MAX_ALPNS_LEN 128 +/** +* @struct tlshd_quic_msg +* @brief QUIC message format +*/ struct tlshd_quic_msg {struct tlshd_quic_msg *next;uint8_t data[TLSHD_QUIC_MAX_DATA_LEN ];
@@ -141,6 +158,10 @@ struct tlshd_quic_msg {uint8_t level; }; +/** +* @struct tlshd_quic_conn +* @brief QUIC connection object +*/ struct tlshd_quic_conn {struct tlshd_handshake_parms *parms;char alpns[TLSHD_QUIC_MAX_ALPNS_LEN ];
@@ -161,16 +182,39 @@ struct tlshd_quic_conn { struct tlshd_quic_msg recv_msg; }; -/* quic.c */ extern int tlshd_quic_conn_create (struct tlshd_quic_conn **conn_p,struct tlshd_handshake_parms *parms);extern void tlshd_quic_conn_destroy (struct tlshd_quic_conn *conn);extern void tlshd_quic_start_handshake (struct tlshd_quic_conn *conn); +#endif +/** +* @def TLS_DEFAULT_PSK_TYPE +* @brief Default type of pre-shared key +*/ #define TLS_DEFAULT_PSK_TYPE "psk" + +/** +* @def TLS_NO_PEERID +* @brief No peer ID provided via keyring +*/ #define TLS_NO_PEERID (0) + +/** +* @def TLS_NO_CERT +* @brief No certificate provided via keyring +*/ #define TLS_NO_CERT (0) + +/** +* @def TLS_NO_PRIVKEY +* @brief No private key provided via keyring +*/ #define TLS_NO_PRIVKEY (0) -/* Max number of (chained) certs to load */ + +/** +* @def TLSHD_MAX_CERTS +* @brief Maximum number of (chained) certs to load +*/ #define TLSHD_MAX_CERTS 10
Signature · 1 line
2.51.0
Chuck Lever
maintainerPATCH 15/16 Build Doxygen web site
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
Make use of the nice documenting comments I've added over the years to build some developer documentation.
The generated pages are not installed (but could be if there is demand).
---
.gitignore | 1 +
Makefile.am | 3 +-
configure.ac | 8 +
docs/Doxyfile.in | 2836 +++++++++++++++++++++++++++++++++++++
{src => docs}/Makefile.am | 13 +-
src/Makefile.am | 2 +
src/mainpage.c | 20 +
src/tlshd/config.c | 12 +
src/tlshd/main.c | 16 +
9 files changed, 2908 insertions(+), 3 deletions(-)
create mode 100644 docs/Doxyfile.in
copy {src => docs}/Makefile.am (78%)
create mode 100644 src/mainpage.c.gitignore +1 -0
@@ -5,6 +5,7 @@ configure.ac~ configure configure~ cscope.* +docs/doxygen/ Makefile Makefile.in .deps/
Makefile.am +2 -1
@@ -20,5 +20,6 @@ AUTOMAKE_OPTIONS = foreign EXTRA_DIST = autogen.sh CONTRIBUTING.md LICENSE.txt \ README.md SECURITY.md -SUBDIRS = etc man src systemd +SUBDIRS = docs etc man src systemd + MAINTAINERCLEANFILES = Makefile.in cscope.* ktls-utils*.tar.gz
configure.ac +8 -0
@@ -64,6 +64,12 @@ PKG_CHECK_MODULES([LIBNL_GENL3], libnl-genl-3.0 >= 3.1) AC_SUBST([LIBNL_GENL3_CFLAGS]) AC_SUBST([LIBNL_GENL3_LIBS]) +AC_CHECK_PROG(DOXYGEN, doxygen, doxygen, false) +if test "$DOXYGEN" = false; then + AC_MSG_WARN([Doxygen not found - documentation will not be built]) +fi +AM_CONDITIONAL([HAVE_DOXYGEN], [test "$DOXYGEN" != "false"]) + AC_CHECK_LIB([gnutls], [gnutls_handshake_set_secret_function], [AC_DEFINE([HAVE_GNUTLS_QUIC], [1], [Define to 1 if you have the gnutls_handshake_set_secret_function function.])])
@@ -94,6 +100,8 @@ fi AC_SUBST([AM_CPPFLAGS]) AC_CONFIG_FILES([Makefile \ + docs/Doxyfile \ + docs/Makefile \ etc/Makefile \ etc/tlshd/Makefile \ man/Makefile \
docs/Doxyfile.in new file +2836 -0
2,836 lines not on this page · raw message
docs/Makefile.am renamed from src/Makefile.am +11 -2
@@ -1,5 +1,5 @@ # -# Copyright (c) 2022 Oracle and/or its affiliates. +# Copyright (c) 2025 Oracle and/or its affiliates. # # ktls-utils is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as
@@ -16,5 +16,14 @@ # 02110-1301, USA. # -SUBDIRS = tlshd +EXTRA_DIST = Doxyfile.in + +if HAVE_DOXYGEN +doxygen: Doxyfile + $(DOXYGEN) Doxyfile +endif + +clean-local: + -rm -rf doxygen/ latex/ man/ + MAINTAINERCLEANFILES = Makefile.in
src/Makefile.am +2 -0
@@ -16,5 +16,7 @@ # 02110-1301, USA. # +EXTRA_DIST = mainpage.c + SUBDIRS = tlshd MAINTAINERCLEANFILES = Makefile.in
src/mainpage.c new file +20 -0
@@ -0,0 +1,20 @@ +/** +* @cond skip +* vim:syntax=doxygen +* @endcond + +@mainpage + +@section main_intro Introduction + +In-kernel TLS consumers need a mechanism to perform TLS handshakes +on a connected socket to negotiate TLS session parameters that can +then be programmed into the kernel's TLS record protocol engine. + +This package of software provides a TLS handshake user agent that +listens for kernel requests and then materializes a user space +socket endpoint on which to perform these handshakes. The resulting +negotiated session parameters are passed back to the kernel via +standard kTLS socket options. + +*/
src/tlshd/config.c +12 -0
@@ -48,6 +48,18 @@#include "tlshd.h" +/** +* @page config Configuration +* +* @section man5 Man pages +* @subsection tlshd_conf_5 tlshd.conf.5 +* @htmlinclude tlshd.conf.5.html +* +* @section examples Configuration examples +* @subsection tlshd_conf /etc/tlshd/config +* @verbinclude config +*/ +/** * @var GKeyFile *tlshd_configuration * In-memory parsed config file
src/tlshd/main.c +16 -0
@@ -51,6 +51,22 @@#include "tlshd.h" +/** +* @page tlshd TLS handshake daemon +* +* The tlshd daemon is a user agent that services TLS handshake +* requests on behalf of kernel TLS consumers. It materializes kernel +* socket endpoints in user space in order to perform TLS handshakes +* using a standard TLS library. After each handshake completes, tlshd +* plants the TLS session key into the socket to enable the use of +* kTLS to secure subsequent communication on that socket. The socket +* is then passed back to the kernel. +* +* @section man8 Man pages +* @subsection tlshd_8 tlshd.8 +* @htmlinclude tlshd.8.html +*/ +static const char *optstring ="c:hsv" ;static const struct option longopts[] = { {"config" , required_argument,NULL ,'c' },
Signature · 1 line
2.51.0
Chuck Lever
maintainerPATCH 16/16 workflows: Generate gh-pages automatically
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
Add a GitHub Action that compiles the Doxygen comments and the man pages in the tlshd source code and builds a .io web site. This is a small step towards improving the published upstream documentation for ktls-utils.
--- .github/workflows/documentation.yml | 154 ++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 .github/workflows/documentation.yml
.github/workflows/documentation.yml new file +154 -0
@@ -0,0 +1,154 @@ +--- +name: Generate public documentation + +on: + release: + types: [published] + workflow_dispatch: + +jobs: + generate-docs: + runs-on: ubuntu-latest + permissions: + contents: read + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + steps: + - uses: actions/checkout@v4 + + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: | + /var/cache/apt + ~/.cache + key: ${{ runner.os }}-docs-${{ hashFiles('.github/workflows/documentation.yml') }} + restore-keys: | + ${{ runner.os }}-docs- + + - name: Install build dependencies + run: | + sudo apt-get update + sudo apt-get -y install \ + build-essential \ + autoconf \ + automake \ + gnutls-dev \ + libkeyutils-dev \ + libnl-3-dev \ + libnl-genl-3-dev \ + libglib2.0-dev + + - name: Install documentation tools + run: | + sudo apt-get update + sudo apt-get install -y \ + doxygen \ + graphviz \ + man2html + + - name: Configure + run: | + ./autogen.sh + ./configure --with-systemd + + - name: Generate HTML man pages + run: | + mkdir -p docs/man/html + if ! ls man/man* >/dev/null 2>&1; then + echo "No man page directories found, skipping HTML generation" + exit 0 + fi + for section_dir in man/man* + do + if [ ! -d "$section_dir" ]; then + continue + fi + section_num=$(basename "$section_dir" | sed 's/man//') + echo "Processing section $section_num pages..." + find "$section_dir" -name "*.$section_num" -print0 | while IFS= read -r -d '' manpage; do + basename_file=$(basename "$manpage") + section=${basename_file##*.} + name=${basename_file%.*} + if ! man2html "$manpage" > "docs/man/html/${name}.${section}.html"; then + echo "Failed to convert $manpage" + exit 1 + fi + done + done + ls -lR docs/man + + - name: Generate Doxygen documentation + run: | + (cd docs && doxygen Doxyfile) + + - name: Assemble final site + run: | + echo "::group::Assembling Documentation Site" + + # Copy Doxygen HTML output + if [ -d docs/doxygen/html ]; then + cp -r docs/doxygen/html _site/ + echo "✓ Doxygen HTML documentation copied" + else + echo "✗ No Doxygen HTML documentation found" + exit 1 + fi + + # Copy man page HTML and index + if [ -d docs/man/html ]; then + cp -r docs/man/html _site/ + echo "✓ Manual page documentation copied" + else + echo "ℹ️ No manual pages to copy" + # Create empty man directory with placeholder + mkdir -p _site/man + cat > _site/man/index.html <<EOF + <!DOCTYPE html> + <html><head><title>Manual Pages</title></head> + <body> + <h1>Manual Pages</h1> + <p><a href="../index.html">← Back to Documentation Home</a></p> + <p><em>No manual pages available yet.</em></p> + </body></html> + EOF + fi + + # Copy configuration examples + if [ -d docs/examples ]; then + cp -r docs/examples _site/ + echo "✓ Configuration examples copied" + else + echo "ℹ️ No configuration examples to copy" + fi + + # Add .nojekyll to disable Jekyll processing + touch _site/.nojekyll + + # Create sitemap + find _site -name "*.html" | sed 's|_site/||' | while read file; do + echo "https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/$file" + done > _site/sitemap.txt + + echo "Documentation site assembled successfully" + echo "Total files: $(find _site -type f | wc -l)" + echo "Site size: $(du -sh _site | cut -f1)" + + echo "::endgroup::" + + - name: Setup Pages + uses: actions/configure-pages@v4 + + - name: Upload Pages artifact + uses: actions/upload-pages-artifact@v3 + with: + path: _site + + - name: Deploy to GitHub Pages + if: github.ref == 'refs/heads/main' + id: deployment + uses: actions/deploy-pages@v4
Signature · 1 line
2.51.0