From: Scott Mayhew <smayhew@redhat.com>
To: chuck.lever@oracle.com
Cc: kernel-tls-handshake@lists.linux.dev
Subject: [PATCH 3/5] tlshd: Make sure x509.pq.certificate is using a PQ public-key alg
Date: Thu, 28 Aug 2025 18:23:46 -0400 [thread overview]
Message-ID: <20250828222348.601924-4-smayhew@redhat.com> (raw)
In-Reply-To: <20250828222348.601924-1-smayhew@redhat.com>
Ensure that the PQ certificate is using a post-quantum public-key
algorithm (ML-DSA-44, ML-DSA-65, or ML-DSA-87).
Link: https://github.com/oracle/ktls-utils/issues/113
Signed-off-by: Scott Mayhew <smayhew@redhat.com>
---
src/tlshd/config.c | 53 +++++++++++++++++++++++++++++++++++++++-
src/tlshd/server.c | 6 +++--
src/tlshd/tlshd.conf.man | 2 ++
src/tlshd/tlshd.h | 3 ++-
4 files changed, 60 insertions(+), 4 deletions(-)
diff --git a/src/tlshd/config.c b/src/tlshd/config.c
index 20634dd..6adacc0 100644
--- a/src/tlshd/config.c
+++ b/src/tlshd/config.c
@@ -401,11 +401,47 @@ bool tlshd_config_get_server_crl(char **result)
return true;
}
+#ifdef HAVE_GNUTLS_MLDSA
+static bool tlshd_cert_check_pk_alg(gnutls_datum_t *data)
+{
+ gnutls_x509_crt_t cert;
+ gnutls_pk_algorithm_t pk_alg;
+ int ret;
+
+ ret = gnutls_x509_crt_init(&cert);
+ if (ret < 0)
+ return false;
+
+ ret = gnutls_x509_crt_import(cert, data, GNUTLS_X509_FMT_PEM);
+ if (ret < 0) {
+ gnutls_x509_crt_deinit(cert);
+ return false;
+ }
+
+ pk_alg = gnutls_x509_crt_get_pk_algorithm(cert, NULL);
+ tlshd_log_debug("%s: certificate pk algorithm %s", __func__,
+ gnutls_pk_algorithm_get_name(pk_alg));
+ switch (pk_alg) {
+ case GNUTLS_PK_MLDSA44:
+ case GNUTLS_PK_MLDSA65:
+ case GNUTLS_PK_MLDSA87:
+ break;
+ default:
+ gnutls_x509_crt_deinit(cert);
+ return false;
+ }
+
+ gnutls_x509_crt_deinit(cert);
+ return true;
+}
+#endif /* HAVE_GNUTLS_MLDSA */
+
/**
* tlshd_config_get_server_certs - Get certs for ServerHello from .conf
* @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
*
* Return values:
* %true: certificate retrieved successfully
@@ -413,8 +449,12 @@ 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)
+ unsigned int *certs_len,
+ bool check_pq)
{
+#ifndef HAVE_GNUTLS_MLSDA
+ (void)check_pq;
+#endif /* HAVE_GNUTLS_MLDSA */
gnutls_datum_t data;
gchar *pathname;
int ret;
@@ -430,6 +470,17 @@ bool tlshd_config_get_server_certs(const gchar *key,
return false;
}
+#ifdef HAVE_GNUTLS_MLDSA
+ if (check_pq && !tlshd_cert_check_pk_alg(&data)) {
+ tlshd_log_debug("%s: %s certificate not using a PQ public-key algorithm",
+ __func__, key);
+ free(data.data);
+ g_free(pathname);
+ *certs_len = 0;
+ return false;
+ }
+#endif /* HAVE_GNUTLS_MLDSA */
+
/* Config file supports only PEM-encoded certificates */
ret = gnutls_pcert_list_import_x509_raw(certs, certs_len, &data,
GNUTLS_X509_FMT_PEM, 0);
diff --git a/src/tlshd/server.c b/src/tlshd/server.c
index 96b1b88..210a09e 100644
--- a/src/tlshd/server.c
+++ b/src/tlshd/server.c
@@ -61,11 +61,13 @@ static bool tlshd_x509_server_get_certs(struct tlshd_handshake_parms *parms)
#ifdef HAVE_GNUTLS_MLDSA
tlshd_config_get_server_certs("x509.pq.certificate",
tlshd_server_pq_certs,
- &tlshd_server_pq_certs_len);
+ &tlshd_server_pq_certs_len,
+ true);
#endif /* HAVE_GNUTLS_MLDSA */
return tlshd_config_get_server_certs("x509.certificate",
tlshd_server_certs,
- &tlshd_server_certs_len);
+ &tlshd_server_certs_len,
+ false);
}
static void tlshd_x509_server_put_certs(void)
diff --git a/src/tlshd/tlshd.conf.man b/src/tlshd/tlshd.conf.man
index ed545e4..575d88b 100644
--- a/src/tlshd/tlshd.conf.man
+++ b/src/tlshd/tlshd.conf.man
@@ -130,6 +130,8 @@ a PEM-encoded private key associated with the above certificate.
This option specifies the pathname of a file containing
a PEM-encoded x.509 certificate that is to be presented during
a handshake request if the peer supports post-quantum cryptography.
+This certificate must be using a post-quantum public-key algorithm
+(ML-DSA-44, ML-DSA-65, or ML-DSA-87).
If the peer does not support post-quantum cryptography, the
certificate configured in the
.I x509.certificate
diff --git a/src/tlshd/tlshd.h b/src/tlshd/tlshd.h
index d9b68ed..6bd55c7 100644
--- a/src/tlshd/tlshd.h
+++ b/src/tlshd/tlshd.h
@@ -61,7 +61,8 @@ bool tlshd_config_get_server_truststore(char **bundle);
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);
+ unsigned int *certs_len,
+ bool check_pq);
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 ` Scott Mayhew [this message]
2025-08-28 22:23 ` [PATCH 4/5] tlshd: Make sure the client supports the PQ pk alg used by the server cert Scott Mayhew
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-4-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.