tlshd: Allow the use of post-quantum cryptography
v2 cover tlshd: Allow the use of post-quantum cryptography
These patches allow tlshd to use post-quantum cryptography. The first patch does a bit of refactoring to reduce some code duplication. The second fixes the priority string and allows the PQ algorithms to be used. The other two implement dual certificate support. Dual certificates are necessary to enable a smooth transition period, allowing servers to work with both clients that are PQ-enabled and clients that are not. The server will prefer the ML-DSA certificate but will fall back to the traditional certificate for clients that do not support ML-DSA.
Changes since v1:
- Refactoring to allow the client and server code to use the same tlshd_config_get_* functions
- Removed a lot of "#ifdef HAVE_GNUTLS_MLDSA" statements (I'm pretty sure the handful that are left are necessary)
- Store both the PQ and RSA certs in the same array. The PQ certs (if present) will be first, followed by the RSA certs. Note that I didn't increase TLSHD_MAX_CERTS though.
For those who prefer a web UI, these patches are also available in this branch:
https://github.com/scottmayhew/ktls-utils/tree/pqc
To use these patches, you need a recent version of gnutls as well as crypto-policies (if used by your distro). These commands will help you determine if your gnutls has the necessary stuff:
$ gnutls-cli -l | grep ML-DSA $ gnutls-cli -l | grep MLKEM
You'll need to generate a cert using ML-DSA-44/ML-DSA-65/ML-DSA-87. For example, here's how I generate a self-signed cert using ML-DSA-65:
$ openssl req -new -x509 -newkey mldsa65 -days 365 \ -keyout /etc/pki/tls/private/rhel10.smayhew.test.mldsa65.key \ -out /etc/pki/tls/certs/rhel10.smayhew.test.mldsa65.pem \ -subj "/CN=rhel10.smayhew.test" \ -addext "subjectAltName=DNS:rhel10.smayhew.test,IP:192.168.124.69" \ -noenc -quiet
Obviously if you're using openssl to generate your certs, you'll need a recent openssl too. Or you can use certtool if you prefer the gnutls utilities.
You'll need to add the cert and key to the relevant sections of tlshd.conf and you should be good to go.
If you have debug logging turned on, you should see this if you perform a handshake with a PQ-enabled peer you should see something like this:
Aug 28 17:58:25 rhel10.smayhew.test tlshd[3291]: Session description: (TLS1.3)-(HYBRID-X25519-MLKEM768)-(ML-DSA-65)-(AES-256-GCM)
and if you perform a handshake with a non-PQ-enabled peer:
Aug 28 18:04:21 rhel10.smayhew.test tlshd[3352]: Session description: (TLS1.3)-(ECDHE-X25519)-(RSA-PSS-RSAE-SHA256)-(AES-256-GCM)
-Scott
Scott Mayhew (4):
tlshd: deduplicate client and server config functions
tlshd: Fix priority string to allow PQC
tlshd: Server-side dual certificate support
tlshd: Client-side dual certificate support
configure.ac | 12 ++ src/tlshd/client.c | 48 +++++-- src/tlshd/config.c | 281 +++++++++++++++++++-------------------- src/tlshd/ktls.c | 2 +- src/tlshd/server.c | 74 ++++++++++- src/tlshd/tlshd.conf | 4 + src/tlshd/tlshd.conf.man | 15 +++ src/tlshd/tlshd.h | 23 ++-- 8 files changed, 286 insertions(+), 173 deletions(-)
Signature · 1 line
2.50.1
PATCH v2 1/4 tlshd: deduplicate client and server config functions
The client and server variants of tlshd_config_get_* are identical except for
1) the stanza they're looking at in the config file, and
2) whether the word "client" or "server" gets written in a log message
Add new parameter 'peer_type' to each of these functions so we can use the same function for both the client and server code.
--- src/tlshd/client.c | 9 +- src/tlshd/config.c | 213 +++++++++------------------------------------ src/tlshd/server.c | 11 +-- src/tlshd/tlshd.h | 20 ++--- 4 files changed, 62 insertions(+), 191 deletions(-)
src/tlshd/client.c +5 -4
@@ -48,7 +48,7 @@ static int tlshd_client_get_truststore(gnutls_certificate_credentials_t cred)char *pathname;int ret; -if (tlshd_config_get_client_truststore (&pathname)) { +if (tlshd_config_get_truststore (PEER_TYPE_CLIENT , &pathname)) { ret =gnutls_certificate_set_x509_trust_file (cred, pathname,GNUTLS_X509_FMT_PEM );free (pathname);
@@ -60,7 +60,7 @@ static int tlshd_client_get_truststore(gnutls_certificate_credentials_t cred) }tlshd_log_debug ("System trust: Loaded %d certificate(s)." , ret); -if (tlshd_config_get_client_crl (&pathname)) { +if (tlshd_config_get_crl (PEER_TYPE_CLIENT , &pathname)) { ret =gnutls_certificate_set_x509_crl_file (cred, pathname,GNUTLS_X509_FMT_PEM );free (pathname);
@@ -143,7 +143,8 @@ static bool tlshd_x509_client_get_certs(struct tlshd_handshake_parms *parms)if (parms->x509_cert !=TLS_NO_CERT )return tlshd_keyring_get_certs (parms->x509_cert, tlshd_certs, &tlshd_certs_len); -return tlshd_config_get_client_certs (tlshd_certs, &tlshd_certs_len); +return tlshd_config_get_certs (PEER_TYPE_CLIENT , tlshd_certs, + &tlshd_certs_len); }static void tlshd_x509_client_put_certs (void )
@@ -159,7 +160,7 @@ static bool tlshd_x509_client_get_privkey(struct tlshd_handshake_parms *parms)if (parms->x509_privkey !=TLS_NO_PRIVKEY )return tlshd_keyring_get_privkey (parms->x509_privkey, &tlshd_privkey); -return tlshd_config_get_client_privkey (&tlshd_privkey); +return tlshd_config_get_privkey (PEER_TYPE_CLIENT , &tlshd_privkey); }static void tlshd_x509_client_put_privkey (void )
src/tlshd/config.c +41 -172
290 lines not on this page · raw message
src/tlshd/server.c +6 -5
@@ -52,8 +52,8 @@ static bool tlshd_x509_server_get_certs(struct tlshd_handshake_parms *parms)return tlshd_keyring_get_certs (parms->x509_cert, tlshd_server_certs, &tlshd_server_certs_len); -return tlshd_config_get_server_certs (tlshd_server_certs, - &tlshd_server_certs_len); +return tlshd_config_get_certs (PEER_TYPE_SERVER , tlshd_server_certs, + &tlshd_server_certs_len); }static void tlshd_x509_server_put_certs (void )
@@ -69,7 +69,8 @@ static bool tlshd_x509_server_get_privkey(struct tlshd_handshake_parms *parms)if (parms->x509_privkey !=TLS_NO_PRIVKEY )return tlshd_keyring_get_privkey (parms->x509_privkey, &tlshd_server_privkey); -return tlshd_config_get_server_privkey (&tlshd_server_privkey); +return tlshd_config_get_privkey (PEER_TYPE_SERVER , + &tlshd_server_privkey); }static void tlshd_x509_server_put_privkey (void )
@@ -140,7 +141,7 @@ static int tlshd_server_get_truststore(gnutls_certificate_credentials_t cred)char *pathname;int ret; -if (tlshd_config_get_server_truststore (&pathname)) { +if (tlshd_config_get_truststore (PEER_TYPE_SERVER , &pathname)) { ret =gnutls_certificate_set_x509_trust_file (cred, pathname,GNUTLS_X509_FMT_PEM );free (pathname);
@@ -150,7 +151,7 @@ static int tlshd_server_get_truststore(gnutls_certificate_credentials_t cred)return ret;tlshd_log_debug ("System trust: Loaded %d certificate(s)." , ret); -if (tlshd_config_get_server_crl (&pathname)) { +if (tlshd_config_get_crl (PEER_TYPE_SERVER , &pathname)) { ret =gnutls_certificate_set_x509_crl_file (cred, pathname,GNUTLS_X509_FMT_PEM );free (pathname);
src/tlshd/tlshd.h +10 -10
@@ -45,6 +45,11 @@ struct tlshd_handshake_parms {unsigned int session_status; }; +enum peer_type { +PEER_TYPE_CLIENT , +PEER_TYPE_SERVER , +}; +/* client.c */ extern void tlshd_tls13_clienthello_handshake (struct tlshd_handshake_parms *parms);extern void tlshd_quic_clienthello_handshake (struct tlshd_handshake_parms *parms);
@@ -52,16 +57,11 @@ extern void tlshd_quic_clienthello_handshake(struct tlshd_handshake_parms *parms/* config.c */ bool tlshd_config_init (const gchar *pathname);void tlshd_config_shutdown (void ); -bool tlshd_config_get_client_truststore (char **bundle); -bool tlshd_config_get_client_crl (char **result); -bool tlshd_config_get_client_certs (gnutls_pcert_st *certs, -unsigned int *certs_len); -bool tlshd_config_get_client_privkey (gnutls_privkey_t *privkey); -bool tlshd_config_get_server_truststore (char **bundle); -bool tlshd_config_get_server_crl (char **result); -bool tlshd_config_get_server_certs (gnutls_pcert_st *certs, -unsigned int *certs_len); -bool tlshd_config_get_server_privkey (gnutls_privkey_t *privkey); +bool tlshd_config_get_truststore (int peer_type,char **bundle); +bool tlshd_config_get_crl (int peer_type,char **result); +bool tlshd_config_get_certs (int peer_type,gnutls_pcert_st *certs, +unsigned int *certs_len); +bool tlshd_config_get_privkey (int peer_type,gnutls_privkey_t *privkey);/* handshake.c */ extern void tlshd_start_tls_handshake(gnutls_session_t session,
Signature · 1 line
2.50.1
PATCH v2 2/4 tlshd: Fix priority string to allow PQC
In reply to Scott MayhewSpecifying either of the SECURE256 or SECURE128 keywords in the priority string results in the ML-DSA algorithms being disabled because the post-quantum algorithms do not map nicely to the security classifications based on "bits of security" used for traditional algorithms [1].
Use @SYSTEM instead, which will allow PQC on systems with newer versions of GnuTLS. It will also allow users to disable PQC via a policy module (on systems with the crypto-policies package).
--- src/tlshd/ktls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/tlshd/ktls.c +1 -1
@@ -357,7 +357,7 @@ static int tlshd_gnutls_priority_init_list(const unsigned int *ciphers,const char *errpos;int ret, i; - pstring =strdup ("SECURE256:+SECURE128:-COMP-ALL" ); + pstring =strdup ("@SYSTEM:-COMP-ALL" );if (!pstring)return -ENOMEM ;
Signature · 1 line
2.50.1
Re: [PATCH v2 2/4] tlshd: Fix priority string to allow PQC
Quoted 23 lines · Scott Mayhew
Specifying either of the SECURE256 or SECURE128 keywords in the priority string results in the ML-DSA algorithms being disabled because the post-quantum algorithms do not map nicely to the security classifications based on "bits of security" used for traditional algorithms [1].
Use @SYSTEM instead, which will allow PQC on systems with newer versions of GnuTLS. It will also allow users to disable PQC via a policy module (on systems with the crypto-policies package).
---
src/tlshd/ktls.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)src/tlshd/ktls.c +0
-0
src/tlshd/ktls.c static int tlshd_gnutls_priority_init_list(const unsigned int *ciphers, · line 360
Quoted 5 lines
src/tlshd/ktls.c +1
-1@@ -357,7 +357,7 @@ static int tlshd_gnutls_priority_init_list(const unsigned int *ciphers,const char *errpos;int ret, i; - pstring =strdup ("SECURE256:+SECURE128:-COMP-ALL" ); + pstring =strdup ("@SYSTEM:-COMP-ALL" );
This change is breaking traditional handshakes for me as _gnutls_resolve_priorities() fails to resolve a priority.
I'm not sure if it's a system config issue though, is anyone else seeing this?
Alistair
Quoted 8 lines
src/tlshd/ktls.c +0
-0if (!pstring)return -ENOMEM ;Signature · 1 line
2.50.1
Re: [PATCH v2 2/4] tlshd: Fix priority string to allow PQC
Quoted 27 lines · Alistair
Quoted 26 lines · Scott Mayhew
Specifying either of the SECURE256 or SECURE128 keywords in the priority string results in the ML-DSA algorithms being disabled because the post-quantum algorithms do not map nicely to the security classifications based on "bits of security" used for traditional algorithms [1].
Use @SYSTEM instead, which will allow PQC on systems with newer versions of GnuTLS. It will also allow users to disable PQC via a policy module (on systems with the crypto-policies package).
---
src/tlshd/ktls.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)src/tlshd/ktls.c +0
-0@@ -357,7 +357,7 @@ static int tlshd_gnutls_priority_init_list(const unsigned int *ciphers,const char *errpos;int ret, i;
Quoted 6 lines
src/tlshd/ktls.c static int tlshd_gnutls_priority_init_list(const unsigned int *ciphers, · line 360
Quoted 2 lines
src/tlshd/ktls.c +1
-1- pstring =strdup ("SECURE256:+SECURE128:-COMP-ALL" ); + pstring =strdup ("@SYSTEM:-COMP-ALL" );This change is breaking traditional handshakes for me as
_gnutls_resolve_priorities()fails to resolve a priority.I'm not sure if it's a system config issue though, is anyone else seeing this?
What output do you get when you run these commands?
gnutls-cli --priority @SYSTEM -l
gnutls-cli --list-config
-Scott
Quoted 12 lines
Alistair
Quoted 8 lines
src/tlshd/ktls.c +0
-0if (!pstring)return -ENOMEM ;Signature · 1 line
2.50.1
PATCH 1/1 tlshd: fix priority cache initialization
In reply to AlistairCommit 9253f9d added the use of the @SYSTEM keyword as the initial keyword in the priority string used by tlshd. Unfortunately @SYSTEM doesn't appear to work on systems that do not have a system-wide library configuration set up.
Instead of trying to pick an initial keyword that will work on all systems, let's instead use gnutls_priority_init2() with the GNUTLS_PRIORITY_INIT_DEF_APPEND flag instead. That will *append* our priority string to the default options.
---
Alistair, can you try this patch and see if it fixes your issue?
src/tlshd/ktls.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
src/tlshd/ktls.c +11 -7
@@ -357,7 +357,7 @@ static int tlshd_gnutls_priority_init_list(const unsigned int *ciphers,const char *errpos;int ret, i; - pstring =strdup ("@SYSTEM:-COMP-ALL" ); + pstring =strdup ("-COMP-ALL" );if (!pstring)return -ENOMEM ;
@@ -425,7 +425,8 @@ static int tlshd_gnutls_priority_init_list(const unsigned int *ciphers, }tlshd_log_debug ("x.509 priority string: %s\n" , pstring); - ret =gnutls_priority_init (&tlshd_gnutls_priority_x509, pstring, &errpos); + ret =gnutls_priority_init2 (&tlshd_gnutls_priority_x509, pstring, &errpos, +GNUTLS_PRIORITY_INIT_DEF_APPEND );if (ret !=GNUTLS_E_SUCCESS ) {free (pstring_sha256);free (pstring_sha384);
@@ -442,7 +443,8 @@ static int tlshd_gnutls_priority_init_list(const unsigned int *ciphers, }tlshd_log_debug ("PSK priority string: %s\n" , pstring); - ret =gnutls_priority_init (&tlshd_gnutls_priority_psk, pstring, &errpos); + ret =gnutls_priority_init2 (&tlshd_gnutls_priority_psk, pstring, &errpos, +GNUTLS_PRIORITY_INIT_DEF_APPEND );if (ret !=GNUTLS_E_SUCCESS ) {free (pstring_sha256);free (pstring_sha384);
@@ -461,8 +463,9 @@ static int tlshd_gnutls_priority_init_list(const unsigned int *ciphers, }tlshd_log_debug ("PSK SHA256 priority string: %s\n" , pstring); - ret =gnutls_priority_init (&tlshd_gnutls_priority_psk_sha256, - pstring, &errpos); + ret =gnutls_priority_init2 (&tlshd_gnutls_priority_psk_sha256, + pstring, &errpos, +GNUTLS_PRIORITY_INIT_DEF_APPEND );if (ret !=GNUTLS_E_SUCCESS ) {free (pstring);free (pstring_sha384);
@@ -482,8 +485,9 @@ static int tlshd_gnutls_priority_init_list(const unsigned int *ciphers, }tlshd_log_debug ("PSK SHA384 priority string: %s\n" , pstring); - ret =gnutls_priority_init (&tlshd_gnutls_priority_psk_sha384, - pstring, &errpos); + ret =gnutls_priority_init2 (&tlshd_gnutls_priority_psk_sha384, + pstring, &errpos, +GNUTLS_PRIORITY_INIT_DEF_APPEND );if (ret !=GNUTLS_E_SUCCESS ) {free (pstring);gnutls_priority_deinit (tlshd_gnutls_priority_psk_sha256);
Signature · 1 line
2.51.0
Re: [PATCH] tlshd: fix priority cache initialization
Quoted 6 lines · Scott Mayhew
Commit 9253f9d added the use of the @SYSTEM keyword as the initial keyword in the priority string used by tlshd. Unfortunately @SYSTEM doesn't appear to work on systems that do not have a system-wide library configuration set up.
Quoted 7 lines
Instead of trying to pick an initial keyword that will work on all systems, let's instead use
gnutls_priority_init2()with theGNUTLS_PRIORITY_INIT_DEF_APPENDflag instead. That will *append* our priority string to the default options.Fixes 9253f9d ("tlshd: Fix priority string to allow PQC")Signed-off-by Scott Mayhew <[email protected]>
Awesome! Thanks for fixing this
Quoted 3 lines
---
Alistair, can you try this patch and see if it fixes your issue?
Yep, fixes my issue
Alistair
Quoted 65 lines
src/tlshd/ktls.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)src/tlshd/ktls.c +11
-8@@ -357,7 +357,7 @@ static int tlshd_gnutls_priority_init_list(const unsigned int *ciphers,const char *errpos;int ret, i; - pstring =strdup ("@SYSTEM:-COMP-ALL" ); + pstring =strdup ("-COMP-ALL" );if (!pstring)return -ENOMEM ;@@ -425,7 +425,8 @@ static int tlshd_gnutls_priority_init_list(const unsigned int *ciphers, }tlshd_log_debug ("x.509 priority string: %s\n" , pstring); - ret =gnutls_priority_init (&tlshd_gnutls_priority_x509, pstring, &errpos); + ret =gnutls_priority_init2 (&tlshd_gnutls_priority_x509, pstring, &errpos, +GNUTLS_PRIORITY_INIT_DEF_APPEND );if (ret !=GNUTLS_E_SUCCESS ) {free (pstring_sha256);free (pstring_sha384);@@ -442,7 +443,8 @@ static int tlshd_gnutls_priority_init_list(const unsigned int *ciphers, }tlshd_log_debug ("PSK priority string: %s\n" , pstring); - ret =gnutls_priority_init (&tlshd_gnutls_priority_psk, pstring, &errpos); + ret =gnutls_priority_init2 (&tlshd_gnutls_priority_psk, pstring, &errpos, +GNUTLS_PRIORITY_INIT_DEF_APPEND );if (ret !=GNUTLS_E_SUCCESS ) {free (pstring_sha256);free (pstring_sha384);@@ -461,8 +463,9 @@ static int tlshd_gnutls_priority_init_list(const unsigned int *ciphers, }tlshd_log_debug ("PSK SHA256 priority string: %s\n" , pstring); - ret =gnutls_priority_init (&tlshd_gnutls_priority_psk_sha256, - pstring, &errpos); + ret =gnutls_priority_init2 (&tlshd_gnutls_priority_psk_sha256, + pstring, &errpos, +GNUTLS_PRIORITY_INIT_DEF_APPEND );if (ret !=GNUTLS_E_SUCCESS ) {free (pstring);free (pstring_sha384);@@ -482,8 +485,9 @@ static int tlshd_gnutls_priority_init_list(const unsigned int *ciphers, }tlshd_log_debug ("PSK SHA384 priority string: %s\n" , pstring); - ret =gnutls_priority_init (&tlshd_gnutls_priority_psk_sha384, - pstring, &errpos); + ret =gnutls_priority_init2 (&tlshd_gnutls_priority_psk_sha384, + pstring, &errpos, +GNUTLS_PRIORITY_INIT_DEF_APPEND );if (ret !=GNUTLS_E_SUCCESS ) {free (pstring);gnutls_priority_deinit (tlshd_gnutls_priority_psk_sha256); --2.51.0
Re: [PATCH] tlshd: fix priority cache initialization
In reply to Scott MayhewQuoted 10 lines · Scott Mayhew
Commit 9253f9d added the use of the @SYSTEM keyword as the initial keyword in the priority string used by tlshd. Unfortunately @SYSTEM doesn't appear to work on systems that do not have a system-wide library configuration set up.
Instead of trying to pick an initial keyword that will work on all systems, let's instead use
gnutls_priority_init2()with theGNUTLS_PRIORITY_INIT_DEF_APPENDflag instead. That will *append* our priority string to the default options.
Quoted 9 lines
Fixes 9253f9d ("tlshd: Fix priority string to allow PQC")Signed-off-by Scott Mayhew <[email protected]>---
Alistair, can you try this patch and see if it fixes your issue?
src/tlshd/ktls.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
Thanks for doing this. Figuring out the init strings had been a major pain, so I wasn't that happy with the initial patch.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Re: [PATCH] tlshd: fix priority cache initialization
Quoted 17 lines · Hannes Reinecke
Quoted 16 lines · Scott Mayhew
Commit 9253f9d added the use of the @SYSTEM keyword as the initial keyword in the priority string used by tlshd. Unfortunately @SYSTEM doesn't appear to work on systems that do not have a system-wide library configuration set up.
Instead of trying to pick an initial keyword that will work on all systems, let's instead use
gnutls_priority_init2()with theGNUTLS_PRIORITY_INIT_DEF_APPENDflag instead. That will *append* our priority string to the default options.Fixes 9253f9d ("tlshd: Fix priority string to allow PQC")Signed-off-by Scott Mayhew <[email protected]>---
Alistair, can you try this patch and see if it fixes your issue?
Quoted 7 lines
Quoted 3 lines
src/tlshd/ktls.c| 18 +++++++++++-------1 file changed, 11 insertions(+), 7 deletions(-)Thanks for doing this. Figuring out the init strings had been a major pain, so I wasn't that happy with the initial patch.
Reviewed-by Hannes Reinecke <[email protected]>
Thanks, folks. I will try to get this merged this afternoon.
Signature · 1 line
Chuck Lever
PATCH v2 3/4 tlshd: Server-side dual certificate support
In reply to Scott MayhewAdd two new config options, "x509.pq.certificate" and "x509.pq.private_key" to configure tlshd to use an ML-DSA certificate. If the cert callback determines that the client supports ML-DSA, it will select this certificate. Otherwise, it will fall back to the traditional certficate (i.e. the certificate configured via "x509.certificate" and "x509.private_key").
Note that we check to ensure that the PQ certificate is using a post-quantum public-key algorithm (ML-DSA-44, ML-DSA-65, or ML-DSA-87), and we store the algorithm value so we can later compare it to the list of signing algorithms supported by the client in the cert callback.
--- configure.ac | 12 ++++ src/tlshd/client.c | 6 +- src/tlshd/config.c | 132 ++++++++++++++++++++++++++++++++++++--- src/tlshd/server.c | 65 ++++++++++++++++++- src/tlshd/tlshd.conf | 2 + src/tlshd/tlshd.conf.man | 15 +++++ src/tlshd/tlshd.h | 7 ++- 7 files changed, 225 insertions(+), 14 deletions(-)
configure.ac +12 -0
@@ -79,6 +79,18 @@ AC_CHECK_LIB([gnutls], [gnutls_get_system_config_file], AC_CHECK_LIB([gnutls], [gnutls_psk_allocate_client_credentials2], [AC_DEFINE([HAVE_GNUTLS_PSK_ALLOCATE_CREDENTIALS2], [1], [Define to 1 if you have the gnutls_psk_allocate_client_credentials2 function.])]) + +AC_MSG_CHECKING(for ML-DSA support in gnutls) +AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[ #include <gnutls/gnutls.h> ]], + [[ (void) GNUTLS_SIGN_MLDSA65; ]])], + [ have_mldsa=yes ], + [ have_mldsa=no ]) +AC_MSG_RESULT([$have_mldsa]) +if test "x$have_mldsa" = xyes ; then + AC_DEFINE([HAVE_GNUTLS_MLDSA], [1], [Define to 1 if gnutls supports ML-DSA]) +fi + AC_SUBST([AM_CPPFLAGS]) AC_CONFIG_FILES([Makefile src/Makefile src/tlshd/Makefile systemd/Makefile])
src/tlshd/client.c +3 -3
@@ -143,8 +143,8 @@ static bool tlshd_x509_client_get_certs(struct tlshd_handshake_parms *parms)if (parms->x509_cert !=TLS_NO_CERT )return tlshd_keyring_get_certs (parms->x509_cert, tlshd_certs, &tlshd_certs_len); -return tlshd_config_get_certs (PEER_TYPE_CLIENT , tlshd_certs, - &tlshd_certs_len); +return tlshd_config_get_certs (PEER_TYPE_CLIENT , tlshd_certs,NULL , + &tlshd_certs_len,NULL ); }static void tlshd_x509_client_put_certs (void )
@@ -160,7 +160,7 @@ static bool tlshd_x509_client_get_privkey(struct tlshd_handshake_parms *parms)if (parms->x509_privkey !=TLS_NO_PRIVKEY )return tlshd_keyring_get_privkey (parms->x509_privkey, &tlshd_privkey); -return tlshd_config_get_privkey (PEER_TYPE_CLIENT , &tlshd_privkey); +return tlshd_config_get_privkey (PEER_TYPE_CLIENT ,NULL , &tlshd_privkey); }static void tlshd_x509_client_put_privkey (void )
src/tlshd/config.c +125 -7
181 lines not on this page · raw message
src/tlshd/server.c +63 -2
112 lines not on this page · raw message
src/tlshd/tlshd.conf +2 -0
@@ -39,3 +39,5 @@ nl=0 #x509.crl= <pathname> #x509.certificate= <pathname> #x509.private_key= <pathname> +#x509.pq.certificate= <pathname> +#x509.pq.private_key= <pathname>
src/tlshd/tlshd.conf.man +15 -0
@@ -125,6 +125,21 @@ a handshake request when no other certificate is available. .B x509.private_key This option specifies the pathname of a file containing a PEM-encoded private key associated with the above certificate. +.TP +.B x509.pq.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 +option will be presented instead. +.TP +.B x509.pq.private_key +This option specifies the pathname of a file containing +a PEM-encoded private key associated with the above certificate. .SH SEE ALSO .BR tlshd (8) .SH AUTHOR
src/tlshd/tlshd.h +5 -2
@@ -60,8 +60,11 @@ void tlshd_config_shutdown(void);bool tlshd_config_get_truststore (int peer_type,char **bundle);bool tlshd_config_get_crl (int peer_type,char **result);bool tlshd_config_get_certs (int peer_type,gnutls_pcert_st *certs, -unsigned int *certs_len); -bool tlshd_config_get_privkey (int peer_type,gnutls_privkey_t *privkey); +unsigned int *pq_certs_len, +unsigned int *certs_len, +gnutls_pk_algorithm_t *pkalg); +bool tlshd_config_get_privkey (int peer_type,gnutls_privkey_t *pq_privkey, +gnutls_privkey_t *privkey);/* handshake.c */ extern void tlshd_start_tls_handshake(gnutls_session_t session,
Signature · 1 line
2.50.1
PATCH v2 4/4 tlshd: Client-side dual certificate support
In reply to Scott MayhewAdd two new config options "x509.pq.certificate" and "x509.pq.private_key", this time to the "[authenticate.client]" stanza of tlshd.conf. This is for client-side handling of the server's certificate request when the client is mounting with "xprtsec=mtls".
This commit also makes sure the client-side x509.pq.certificate is using a post-quantum public-key algorithm, and we make sure that the server supports that algorithm before returning that cert in the cert callback (unlike the server-side cert callback, the pk_algos list is populated, so this check is more straightforward than on the server-side).
--- src/tlshd/client.c | 45 ++++++++++++++++++++++++++++++++++++-------- src/tlshd/tlshd.conf | 2 ++ 2 files changed, 39 insertions(+), 8 deletions(-)
src/tlshd/client.c +37 -8
@@ -134,17 +134,21 @@ out_free_creds:gnutls_certificate_free_credentials (xcred); } +static gnutls_privkey_t tlshd_pq_privkey;static gnutls_privkey_t tlshd_privkey; +static unsigned int tlshd_pq_certs_len =TLSHD_MAX_CERTS ;static unsigned int tlshd_certs_len =TLSHD_MAX_CERTS ;static gnutls_pcert_st tlshd_certs[TLSHD_MAX_CERTS ]; +static gnutls_pk_algorithm_t tlshd_pq_pkalg =GNUTLS_PK_UNKNOWN ;static bool tlshd_x509_client_get_certs (struct tlshd_handshake_parms *parms) {if (parms->x509_cert !=TLS_NO_CERT )return tlshd_keyring_get_certs (parms->x509_cert, tlshd_certs, &tlshd_certs_len); -return tlshd_config_get_certs (PEER_TYPE_CLIENT , tlshd_certs,NULL , - &tlshd_certs_len,NULL ); +return tlshd_config_get_certs (PEER_TYPE_CLIENT , tlshd_certs, + &tlshd_pq_certs_len, &tlshd_certs_len, + &tlshd_pq_pkalg); }static void tlshd_x509_client_put_certs (void )
@@ -160,12 +164,14 @@ static bool tlshd_x509_client_get_privkey(struct tlshd_handshake_parms *parms)if (parms->x509_privkey !=TLS_NO_PRIVKEY )return tlshd_keyring_get_privkey (parms->x509_privkey, &tlshd_privkey); -return tlshd_config_get_privkey (PEER_TYPE_CLIENT ,NULL , &tlshd_privkey); +return tlshd_config_get_privkey (PEER_TYPE_CLIENT , &tlshd_pq_privkey, + &tlshd_privkey); }static void tlshd_x509_client_put_privkey (void ) {gnutls_privkey_deinit (tlshd_privkey); +gnutls_privkey_deinit (tlshd_pq_privkey); }static void tlshd_x509_log_issuers (const gnutls_datum_t *req_ca_rdn,int nreqs)
@@ -206,13 +212,15 @@ static void tlshd_x509_log_issuers(const gnutls_datum_t *req_ca_rdn, int nreqs)static int tlshd_x509_retrieve_key_cb (gnutls_session_t session,const gnutls_datum_t *req_ca_rdn,int nreqs, - __attribute__ ((unused))const gnutls_pk_algorithm_t *pk_algos, - __attribute__ ((unused))int pk_algos_length, +const gnutls_pk_algorithm_t *pk_algos, +int pk_algos_length,gnutls_pcert_st **pcert,unsigned int *pcert_length,gnutls_privkey_t *privkey) {gnutls_certificate_type_t type; +bool use_pq_cert = false; +int i;tlshd_x509_log_issuers (req_ca_rdn, nreqs);
@@ -220,9 +228,30 @@ tlshd_x509_retrieve_key_cb(gnutls_session_t session,if (type !=GNUTLS_CRT_X509 )return -1 ; - *pcert_length = tlshd_certs_len; - *pcert = tlshd_certs; - *privkey = tlshd_privkey; +if (tlshd_pq_pkalg !=GNUTLS_PK_UNKNOWN ) { +for (i =0 ; i < pk_algos_length; i++) { +if (pk_algos[i] == tlshd_pq_pkalg) { + use_pq_cert = true; +break ; + } + } +if (use_pq_cert == true) { +tlshd_log_debug ("%s: Server supports %s" , __func__, +gnutls_pk_algorithm_get_name (pk_algos[i])); + } + } + +if (use_pq_cert == true) { +tlshd_log_debug ("%s: Selecting x509.pq.certificate from conf file" , __func__); + *pcert_length = tlshd_pq_certs_len; + *pcert = tlshd_certs; + *privkey = tlshd_pq_privkey; + }else { +tlshd_log_debug ("%s: Selecting x509.certificate from conf file" , __func__); + *pcert_length = tlshd_certs_len; + *pcert = tlshd_certs + tlshd_pq_certs_len; + *privkey = tlshd_privkey; + }return 0 ; }
src/tlshd/tlshd.conf +2 -0
@@ -33,6 +33,8 @@ nl=0 #x509.crl= <pathname> #x509.certificate= <pathname> #x509.private_key= <pathname> +#x509.pq.certificate= <pathname> +#x509.pq.private_key= <pathname> [authenticate.server] #x509.truststore= <pathname>
Signature · 1 line
2.50.1
Quoted 19 lines · Scott Mayhew
These patches allow tlshd to use post-quantum cryptography. The first patch does a bit of refactoring to reduce some code duplication. The second fixes the priority string and allows the PQ algorithms to be used. The other two implement dual certificate support. Dual certificates are necessary to enable a smooth transition period, allowing servers to work with both clients that are PQ-enabled and clients that are not. The server will prefer the ML-DSA certificate but will fall back to the traditional certificate for clients that do not support ML-DSA.
Changes since v1:
- Refactoring to allow the client and server code to use the same tlshd_config_get_* functions
- Removed a lot of "#ifdefHAVE_GNUTLS_MLDSA" statements (I'm pretty sure the handful that are left are necessary)
- Store both the PQ and RSA certs in the same array. The PQ certs (if present) will be first, followed by the RSA certs. Note that I didn't increaseTLSHD_MAX_CERTSthough.
Quoted 3 lines
For those who prefer a web UI, these patches are also available in this branch:
https://github.com/scottmayhew/ktls-utils/tree/pqc
Hi Scott, these look close enough to merge IMO. Please open a pull request against oracle/ktls-utils.
Quoted 51 lines
To use these patches, you need a recent version of gnutls as well as crypto-policies (if used by your distro). These commands will help you determine if your gnutls has the necessary stuff:
$ gnutls-cli -l | grep ML-DSA $ gnutls-cli -l | grep MLKEMYou'll need to generate a cert using ML-DSA-44/ML-DSA-65/ML-DSA-87. For example, here's how I generate a self-signed cert using ML-DSA-65:
$ openssl req -new -x509 -newkey mldsa65 -days 365 \ -keyout /etc/pki/tls/private/rhel10.smayhew.test.mldsa65.key \ -out /etc/pki/tls/certs/rhel10.smayhew.test.mldsa65.pem \ -subj "/CN=rhel10.smayhew.test" \ -addext "subjectAltName=DNS:rhel10.smayhew.test,IP:192.168.124.69" \ -noenc -quietObviously if you're using openssl to generate your certs, you'll need a recent openssl too. Or you can use certtool if you prefer the gnutls utilities.
You'll need to add the cert and key to the relevant sections of tlshd.conf and you should be good to go.
If you have debug logging turned on, you should see this if you perform a handshake with a PQ-enabled peer you should see something like this:
Aug 28 17:58:25 rhel10.smayhew.test tlshd[3291]: Session description: (TLS1.3)-(HYBRID-X25519-MLKEM768)-(ML-DSA-65)-(AES-256-GCM)and if you perform a handshake with a non-PQ-enabled peer:
Aug 28 18:04:21 rhel10.smayhew.test tlshd[3352]: Session description: (TLS1.3)-(ECDHE-X25519)-(RSA-PSS-RSAE-SHA256)-(AES-256-GCM)-Scott
Scott Mayhew (4):
tlshd: deduplicate client and server config functions
tlshd: Fix priority string to allow PQC
tlshd: Server-side dual certificate support
tlshd: Client-side dual certificate supportconfigure.ac | 12 ++ src/tlshd/client.c | 48 +++++-- src/tlshd/config.c | 281 +++++++++++++++++++-------------------- src/tlshd/ktls.c | 2 +- src/tlshd/server.c | 74 ++++++++++- src/tlshd/tlshd.conf | 4 + src/tlshd/tlshd.conf.man | 15 +++ src/tlshd/tlshd.h | 23 ++-- 8 files changed, 286 insertions(+), 173 deletions(-)
Signature · 1 line
Chuck Lever