From: Scott Mayhew <smayhew@redhat.com>
To: chuck.lever@oracle.com
Cc: kernel-tls-handshake@lists.linux.dev
Subject: [PATCH 4/5] tlshd: Make sure the client supports the PQ pk alg used by the server cert
Date: Thu, 28 Aug 2025 18:23:47 -0400 [thread overview]
Message-ID: <20250828222348.601924-5-smayhew@redhat.com> (raw)
In-Reply-To: <20250828222348.601924-1-smayhew@redhat.com>
Store the public-key algorithm used by the server cert so we can later
compare it to the list of signing algorithms supported by the client in
the cert callback.
Link: https://github.com/oracle/ktls-utils/issues/113
Signed-off-by: Scott Mayhew <smayhew@redhat.com>
---
src/tlshd/config.c | 12 +++++++-----
src/tlshd/server.c | 49 ++++++++++++++++++++++++++++++++++------------
src/tlshd/tlshd.h | 2 +-
3 files changed, 44 insertions(+), 19 deletions(-)
diff --git a/src/tlshd/config.c b/src/tlshd/config.c
index 6adacc0..735d24a 100644
--- a/src/tlshd/config.c
+++ b/src/tlshd/config.c
@@ -402,7 +402,8 @@ bool tlshd_config_get_server_crl(char **result)
}
#ifdef HAVE_GNUTLS_MLDSA
-static bool tlshd_cert_check_pk_alg(gnutls_datum_t *data)
+static bool tlshd_cert_check_pk_alg(gnutls_datum_t *data,
+ gnutls_pk_algorithm_t *pkalg)
{
gnutls_x509_crt_t cert;
gnutls_pk_algorithm_t pk_alg;
@@ -425,6 +426,7 @@ static bool tlshd_cert_check_pk_alg(gnutls_datum_t *data)
case GNUTLS_PK_MLDSA44:
case GNUTLS_PK_MLDSA65:
case GNUTLS_PK_MLDSA87:
+ *pkalg = pk_alg;
break;
default:
gnutls_x509_crt_deinit(cert);
@@ -441,7 +443,7 @@ static bool tlshd_cert_check_pk_alg(gnutls_datum_t *data)
* @key: IN: the key field name from .conf
* @certs: OUT: in-memory certificates
* @certs_len: IN: maximum number of certs to get, OUT: number of certs found
- * @check_pq: IN: verify that the cert is using a PQ public-key alg
+ * @pkgalg: OUT: the PQ public-key alg that was used in the cert
*
* Return values:
* %true: certificate retrieved successfully
@@ -450,10 +452,10 @@ static bool tlshd_cert_check_pk_alg(gnutls_datum_t *data)
bool tlshd_config_get_server_certs(const gchar *key,
gnutls_pcert_st *certs,
unsigned int *certs_len,
- bool check_pq)
+ gnutls_pk_algorithm_t *pkalg)
{
#ifndef HAVE_GNUTLS_MLSDA
- (void)check_pq;
+ (void)pkalg;
#endif /* HAVE_GNUTLS_MLDSA */
gnutls_datum_t data;
gchar *pathname;
@@ -471,7 +473,7 @@ bool tlshd_config_get_server_certs(const gchar *key,
}
#ifdef HAVE_GNUTLS_MLDSA
- if (check_pq && !tlshd_cert_check_pk_alg(&data)) {
+ if (pkalg && !tlshd_cert_check_pk_alg(&data, pkalg)) {
tlshd_log_debug("%s: %s certificate not using a PQ public-key algorithm",
__func__, key);
free(data.data);
diff --git a/src/tlshd/server.c b/src/tlshd/server.c
index 210a09e..7a0ce24 100644
--- a/src/tlshd/server.c
+++ b/src/tlshd/server.c
@@ -50,6 +50,7 @@ static gnutls_pcert_st tlshd_server_certs[TLSHD_MAX_CERTS];
static gnutls_privkey_t tlshd_server_pq_privkey;
static unsigned int tlshd_server_pq_certs_len = TLSHD_MAX_CERTS;
static gnutls_pcert_st tlshd_server_pq_certs[TLSHD_MAX_CERTS];
+static gnutls_pk_algorithm_t tlshd_server_pq_pkalg = GNUTLS_PK_UNKNOWN;
#endif /* HAVE_GNUTLS_MLDSA */
static bool tlshd_x509_server_get_certs(struct tlshd_handshake_parms *parms)
@@ -62,12 +63,12 @@ static bool tlshd_x509_server_get_certs(struct tlshd_handshake_parms *parms)
tlshd_config_get_server_certs("x509.pq.certificate",
tlshd_server_pq_certs,
&tlshd_server_pq_certs_len,
- true);
+ &tlshd_server_pq_pkalg);
#endif /* HAVE_GNUTLS_MLDSA */
return tlshd_config_get_server_certs("x509.certificate",
tlshd_server_certs,
&tlshd_server_certs_len,
- false);
+ NULL);
}
static void tlshd_x509_server_put_certs(void)
@@ -158,20 +159,42 @@ tlshd_x509_retrieve_key_cb(gnutls_session_t session,
return -1;
#ifdef HAVE_GNUTLS_MLDSA
- for (i = 0; ; i++) {
- ret = gnutls_sign_algorithm_get_requested(session, i, &client_alg);
- if (ret != GNUTLS_E_SUCCESS)
- break;
- if (client_alg == GNUTLS_SIGN_MLDSA44
- || client_alg == GNUTLS_SIGN_MLDSA65
- || client_alg == GNUTLS_SIGN_MLDSA87) {
- tlshd_log_debug("%s: Client supports ML-DSA", __func__);
- use_pq_cert = true;
- break;
+ /*
+ * NB: Unfortunately when the callback function is invoked server-side,
+ * pk_algos is NULL and pk_algos_length is 0. So we check the signature
+ * algorithms the client supports and try to match one of them to the
+ * public-key algorithm used by the server cert.
+ */
+ if (tlshd_server_pq_pkalg != GNUTLS_PK_UNKNOWN) {
+ for (i = 0; ; i++) {
+ ret = gnutls_sign_algorithm_get_requested(session, i, &client_alg);
+ if (ret != GNUTLS_E_SUCCESS)
+ break;
+ switch (client_alg) {
+ case GNUTLS_SIGN_MLDSA44:
+ if (tlshd_server_pq_pkalg == GNUTLS_PK_MLDSA44)
+ use_pq_cert = true;
+ break;
+ case GNUTLS_SIGN_MLDSA65:
+ if (tlshd_server_pq_pkalg == GNUTLS_PK_MLDSA65)
+ use_pq_cert = true;
+ break;
+ case GNUTLS_SIGN_MLDSA87:
+ if (tlshd_server_pq_pkalg == GNUTLS_PK_MLDSA87)
+ use_pq_cert = true;
+ break;
+ default:
+ break;
+ }
+ if (use_pq_cert == true) {
+ tlshd_log_debug("%s: Client supports %s", __func__,
+ gnutls_sign_get_name(client_alg));
+ break;
+ }
}
}
- if (use_pq_cert == true && tlshd_server_pq_certs_len > 0) {
+ if (use_pq_cert == true) {
tlshd_log_debug("%s: Selecting x509.pq.certificate from conf file", __func__);
*pcert_length = tlshd_server_pq_certs_len;
*pcert = tlshd_server_pq_certs;
diff --git a/src/tlshd/tlshd.h b/src/tlshd/tlshd.h
index 6bd55c7..ca84d8f 100644
--- a/src/tlshd/tlshd.h
+++ b/src/tlshd/tlshd.h
@@ -62,7 +62,7 @@ bool tlshd_config_get_server_crl(char **result);
bool tlshd_config_get_server_certs(const gchar *key,
gnutls_pcert_st *certs,
unsigned int *certs_len,
- bool check_pq);
+ gnutls_pk_algorithm_t *pkalg);
bool tlshd_config_get_server_privkey(const gchar *key,
gnutls_privkey_t *privkey);
--
2.50.1
next prev parent reply other threads:[~2025-08-28 22:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-28 22:23 [PATCH 0/5] tlshd: Allow the use of post-quantum cryptography Scott Mayhew
2025-08-28 22:23 ` [PATCH 1/5] tlshd: Fix priority string to allow PQC Scott Mayhew
2025-08-29 16:47 ` Chuck Lever
2025-08-28 22:23 ` [PATCH 2/5] tlshd: Server-side dual certificate support Scott Mayhew
2025-08-29 16:59 ` Chuck Lever
2025-09-03 13:28 ` Scott Mayhew
2025-09-03 14:17 ` Chuck Lever
2025-09-03 15:03 ` Chuck Lever
2025-08-28 22:23 ` [PATCH 3/5] tlshd: Make sure x509.pq.certificate is using a PQ public-key alg Scott Mayhew
2025-08-28 22:23 ` Scott Mayhew [this message]
2025-08-28 22:23 ` [PATCH 5/5] tlshd: Client-side dual certificate support Scott Mayhew
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250828222348.601924-5-smayhew@redhat.com \
--to=smayhew@redhat.com \
--cc=chuck.lever@oracle.com \
--cc=kernel-tls-handshake@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.