tlshd: Allow the use of post-quantum cryptography
cover tlshd: Allow the use of post-quantum cryptography
These patches allow tlshd to use post-quantum cryptography. The first patch fixes the priority string and allows the PQ algorithms to be used. The remaining patches 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.
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 Mayhew (5):
tlshd: Fix priority string to allow PQC
tlshd: Server-side dual certificate support
tlshd: Make sure x509.pq.certificate is using a PQ public-key alg
tlshd: Make sure the client supports the PQ pk alg used by the server
cert
tlshd: Client-side dual certificate support
configure.ac | 12 +++++ src/tlshd/client.c | 66 +++++++++++++++++++++++++-- src/tlshd/config.c | 97 +++++++++++++++++++++++++++++++++++----- src/tlshd/ktls.c | 2 +- src/tlshd/server.c | 86 +++++++++++++++++++++++++++++++++-- src/tlshd/tlshd.conf | 4 ++ src/tlshd/tlshd.conf.man | 15 +++++++ src/tlshd/tlshd.h | 18 +++++--- 8 files changed, 276 insertions(+), 24 deletions(-)
Signature · 1 line
2.50.1
PATCH 1/5 tlshd: Fix priority string to allow PQC
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 +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 1/5] 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 363
Quoted 8 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" );if (!pstring)return -ENOMEM ;
If I can get a R-b from Hannes, this can get merged right now.
Signature · 1 line
Chuck Lever
PATCH 2/5 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").
--- configure.ac | 12 ++++++++ src/tlshd/config.c | 12 +++++--- src/tlshd/server.c | 59 ++++++++++++++++++++++++++++++++++++++-- src/tlshd/tlshd.conf | 2 ++ src/tlshd/tlshd.conf.man | 13 +++++++++ src/tlshd/tlshd.h | 6 ++-- 6 files changed, 96 insertions(+), 8 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/config.c +8 -4
@@ -403,6 +403,7 @@ bool tlshd_config_get_server_crl(char **result)/** * 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 *
@@ -410,7 +411,8 @@ bool tlshd_config_get_server_crl(char **result)* %true: certificate retrieved successfully * %false: certificate not retrieved */ -bool tlshd_config_get_server_certs (gnutls_pcert_st *certs, +bool tlshd_config_get_server_certs (const gchar *key, +gnutls_pcert_st *certs,unsigned int *certs_len) {gnutls_datum_t data;
@@ -418,7 +420,7 @@ bool tlshd_config_get_server_certs(gnutls_pcert_st *certs,int ret; pathname =g_key_file_get_string (tlshd_configuration,"authenticate.server" , -"x509.certificate" ,NULL ); + key,NULL );if (!pathname)return false;
@@ -446,20 +448,22 @@ bool tlshd_config_get_server_certs(gnutls_pcert_st *certs,/** * tlshd_config_get_server_privkey - Get private key for ServerHello from .conf +* @key: IN: the key field name from .conf * @privkey: OUT: in-memory private key * * Return values: * %true: private key retrieved successfully * %false: private key not retrieved */ -bool tlshd_config_get_server_privkey (gnutls_privkey_t *privkey) +bool tlshd_config_get_server_privkey (const gchar *key, +gnutls_privkey_t *privkey) {gnutls_datum_t data;gchar *pathname;int ret; pathname =g_key_file_get_string (tlshd_configuration,"authenticate.server" , -"x509.private_key" ,NULL ); + key,NULL );if (!pathname)return false;
src/tlshd/server.c +57 -2
103 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 +13 -0
@@ -125,6 +125,19 @@ 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. +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 +4 -2
@@ -59,9 +59,11 @@ bool tlshd_config_get_client_certs(gnutls_pcert_st *certs,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, +bool tlshd_config_get_server_certs (const gchar *key, +gnutls_pcert_st *certs,unsigned int *certs_len); -bool tlshd_config_get_server_privkey (gnutls_privkey_t *privkey); +bool tlshd_config_get_server_privkey (const gchar *key, +gnutls_privkey_t *privkey);/* handshake.c */ extern void tlshd_start_tls_handshake(gnutls_session_t session,
Signature · 1 line
2.50.1
Re: [PATCH 2/5] tlshd: Server-side dual certificate support
Quoted 31 lines · Scott Mayhew
Add 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").
--- configure.ac | 12 ++++++++ src/tlshd/config.c | 12 +++++--- src/tlshd/server.c | 59 ++++++++++++++++++++++++++++++++++++++-- src/tlshd/tlshd.conf | 2 ++ src/tlshd/tlshd.conf.man | 13 +++++++++ src/tlshd/tlshd.h | 6 ++-- 6 files changed, 96 insertions(+), 8 deletions(-)configure.ac +5
-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; ]])],
configure.ac AC_CHECK_LIB([gnutls], [gnutls_get_system_config_file], · line 96
Quoted 10 lines
configure.ac +7
-0+ [ 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])
Nice.
src/tlshd/config.c bool tlshd_config_get_server_crl(char **result) · line 406
Quoted 9 lines
src/tlshd/config.c +1
-0@@ -403,6 +403,7 @@ bool tlshd_config_get_server_crl(char **result)/** * tlshd_config_get_server_certs - Get certs for ServerHello from .conf +* @key: IN: the key field name from .conf
ETOOMANYTHINGSCALLEDKEY :-)
Can you find a less overloaded name for the new function parameter, here and below?
But see below... perhaps the additional parameter isn't needed if all the configured certificates and private keys can be retrieved using the same functions.
Quoted 52 lines
src/tlshd/config.c +7
-4* @certs: OUT: in-memory certificates * @certs_len: IN: maximum number of certs to get, OUT: number of certs found * @@ -410,7 +411,8 @@ bool tlshd_config_get_server_crl(char **result)* %true: certificate retrieved successfully * %false: certificate not retrieved */ -bool tlshd_config_get_server_certs (gnutls_pcert_st *certs, +bool tlshd_config_get_server_certs (const gchar *key, +gnutls_pcert_st *certs,unsigned int *certs_len) {gnutls_datum_t data;@@ -418,7 +420,7 @@ bool tlshd_config_get_server_certs(gnutls_pcert_st *certs,int ret; pathname =g_key_file_get_string (tlshd_configuration,"authenticate.server" , -"x509.certificate" ,NULL ); + key,NULL );if (!pathname)return false;@@ -446,20 +448,22 @@ bool tlshd_config_get_server_certs(gnutls_pcert_st *certs,/** * tlshd_config_get_server_privkey - Get private key for ServerHello from .conf +* @key: IN: the key field name from .conf * @privkey: OUT: in-memory private key * * Return values: * %true: private key retrieved successfully * %false: private key not retrieved */ -bool tlshd_config_get_server_privkey (gnutls_privkey_t *privkey) +bool tlshd_config_get_server_privkey (const gchar *key, +gnutls_privkey_t *privkey) {gnutls_datum_t data;gchar *pathname;int ret; pathname =g_key_file_get_string (tlshd_configuration,"authenticate.server" , -"x509.private_key" ,NULL ); + key,NULL );if (!pathname)return false;src/tlshd/server.c +0
-0
src/tlshd/server.c static gnutls_privkey_t tlshd_server_privkey; · line 54
Quoted 9 lines
src/tlshd/server.c +6
-0@@ -46,13 +46,25 @@ static gnutls_privkey_t tlshd_server_privkey;static unsigned int tlshd_server_certs_len =TLSHD_MAX_CERTS ;static gnutls_pcert_st tlshd_server_certs[TLSHD_MAX_CERTS ]; +#ifdef HAVE_GNUTLS_MLDSA +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 ]; +#endif /* HAVE_GNUTLS_MLDSA */ +
Two architectural thoughts when seeing this:
1. Generally, I'd rather see fewer "#ifdef HAVE_GNUTLS_MLDSA" throughout and just leave things enabled all the time where it makes sense. That makes for less clutter and better test coverage.
2. Does it make sense for tlshd_config_get_server_certs to retrieve both types of certificates in the same array? Or, more generally speaking, where it's sensible, try not to duplicate the logic, but combine it.
Similar comments in the client parts of the series. Overall the series looks like a reasonable direction.
Quoted 150 lines
src/tlshd/server.c +51
-2static bool tlshd_x509_server_get_certs (struct tlshd_handshake_parms *parms) {if (parms->x509_cert !=TLS_NO_CERT )return tlshd_keyring_get_certs (parms->x509_cert, tlshd_server_certs, &tlshd_server_certs_len); -return tlshd_config_get_server_certs (tlshd_server_certs, +#ifdef HAVE_GNUTLS_MLDSA +tlshd_config_get_server_certs ("x509.pq.certificate" , + tlshd_server_pq_certs, + &tlshd_server_pq_certs_len); +#endif /* HAVE_GNUTLS_MLDSA */ +return tlshd_config_get_server_certs ("x509.certificate" , + tlshd_server_certs, &tlshd_server_certs_len); }@@ -62,6 +74,11 @@ static void tlshd_x509_server_put_certs(void)for (i =0 ; i < tlshd_server_certs_len; i++)gnutls_pcert_deinit (&tlshd_server_certs[i]); + +#ifdef HAVE_GNUTLS_MLDSA +for (i =0 ; i < tlshd_server_pq_certs_len; i++) +gnutls_pcert_deinit (&tlshd_server_pq_certs[i]); +#endif /* HAVE_GNUTLS_MLDSA */ }static bool tlshd_x509_server_get_privkey (struct tlshd_handshake_parms *parms)@@ -69,12 +86,18 @@ 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); +#ifdef HAVE_GNUTLS_MLDSA +tlshd_config_get_server_privkey ("x509.pq.private_key" , &tlshd_server_pq_privkey); +#endif /* HAVE_GNUTLS_MLDSA */ +return tlshd_config_get_server_privkey ("x509.private_key" , &tlshd_server_privkey); }static void tlshd_x509_server_put_privkey (void ) {gnutls_privkey_deinit (tlshd_server_privkey); +#ifdef HAVE_GNUTLS_MLDSA +gnutls_privkey_deinit (tlshd_server_pq_privkey); +#endif /* HAVE_GNUTLS_MLDSA */ }static void tlshd_x509_log_issuers (const gnutls_datum_t *req_ca_rdn,int nreqs)@@ -120,6 +143,11 @@ tlshd_x509_retrieve_key_cb(gnutls_session_t session, gnutls_privkey_t *privkey) {gnutls_certificate_type_t type; +#ifdef HAVE_GNUTLS_MLDSA +gnutls_sign_algorithm_t client_alg; +bool use_pq_cert = false; +int i, ret; +#endif /* HAVE_GNUTLS_MLDSA */ tlshd_x509_log_issuers (req_ca_rdn, nreqs);@@ -127,9 +155,36 @@ tlshd_x509_retrieve_key_cb(gnutls_session_t session,if (type !=GNUTLS_CRT_X509 )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 ; + } + } + +if (use_pq_cert == true && tlshd_server_pq_certs_len >0 ) { +tlshd_log_debug ("%s: Selecting x509.pq.certificate from conf file" , __func__); + *pcert_length = tlshd_server_pq_certs_len; + *pcert = tlshd_server_pq_certs; + *privkey = tlshd_server_pq_privkey; + }else { +tlshd_log_debug ("%s: Selecting x509.certificate from conf file" , __func__); + *pcert_length = tlshd_server_certs_len; + *pcert = tlshd_server_certs; + *privkey = tlshd_server_privkey; + } +#else *pcert_length = tlshd_server_certs_len; *pcert = tlshd_server_certs; *privkey = tlshd_server_privkey; +#endif /* HAVE_GNUTLS_MLDSA */ return 0 ; }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 +13
-0@@ -125,6 +125,19 @@ 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. +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 AUTHORsrc/tlshd/tlshd.h +4
-2@@ -59,9 +59,11 @@ bool tlshd_config_get_client_certs(gnutls_pcert_st *certs,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, +bool tlshd_config_get_server_certs (const gchar *key, +gnutls_pcert_st *certs,unsigned int *certs_len); -bool tlshd_config_get_server_privkey (gnutls_privkey_t *privkey); +bool tlshd_config_get_server_privkey (const gchar *key, +gnutls_privkey_t *privkey);/* handshake.c */ extern void tlshd_start_tls_handshake(gnutls_session_t session,
Signature · 1 line
Chuck Lever
Re: [PATCH 2/5] tlshd: Server-side dual certificate support
Quoted 52 lines · Chuck Lever
Quoted 31 lines · Scott Mayhew
Add 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").
--- configure.ac | 12 ++++++++ src/tlshd/config.c | 12 +++++--- src/tlshd/server.c | 59 ++++++++++++++++++++++++++++++++++++++-- src/tlshd/tlshd.conf | 2 ++ src/tlshd/tlshd.conf.man | 13 +++++++++ src/tlshd/tlshd.h | 6 ++-- 6 files changed, 96 insertions(+), 8 deletions(-)configure.ac +5
-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; ]])],configure.ac AC_CHECK_LIB([gnutls], [gnutls_get_system_config_file], · line 96
Quoted 10 lines
configure.ac +7
-0+ [ 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])Nice.
Quoted 6 lines
src/tlshd/config.c +0
-0@@ -403,6 +403,7 @@ bool tlshd_config_get_server_crl(char **result)
Quoted 8 lines
src/tlshd/config.c bool tlshd_config_get_server_crl(char **result) · line 406
Quoted 3 lines
src/tlshd/config.c +1
-0/** * tlshd_config_get_server_certs - Get certs for ServerHello from .conf +* @key: IN: the key field name from .conf ETOOMANYTHINGSCALLEDKEY :-)
Can you find a less overloaded name for the new function parameter, here and below?
Yeah, I called it 'key' because that's what it's referred to in
https://docs.gtk.org/glib/method.KeyFile.get_string.html
I'm open to suggestions (gkey? gfile_key? option?)
Quoted 70 lines
But see below... perhaps the additional parameter isn't needed if all the configured certificates and private keys can be retrieved using the same functions.
Quoted 52 lines
src/tlshd/config.c +7
-4* @certs: OUT: in-memory certificates * @certs_len: IN: maximum number of certs to get, OUT: number of certs found * @@ -410,7 +411,8 @@ bool tlshd_config_get_server_crl(char **result)* %true: certificate retrieved successfully * %false: certificate not retrieved */ -bool tlshd_config_get_server_certs (gnutls_pcert_st *certs, +bool tlshd_config_get_server_certs (const gchar *key, +gnutls_pcert_st *certs,unsigned int *certs_len) {gnutls_datum_t data;@@ -418,7 +420,7 @@ bool tlshd_config_get_server_certs(gnutls_pcert_st *certs,int ret; pathname =g_key_file_get_string (tlshd_configuration,"authenticate.server" , -"x509.certificate" ,NULL ); + key,NULL );if (!pathname)return false;@@ -446,20 +448,22 @@ bool tlshd_config_get_server_certs(gnutls_pcert_st *certs,/** * tlshd_config_get_server_privkey - Get private key for ServerHello from .conf +* @key: IN: the key field name from .conf * @privkey: OUT: in-memory private key * * Return values: * %true: private key retrieved successfully * %false: private key not retrieved */ -bool tlshd_config_get_server_privkey (gnutls_privkey_t *privkey) +bool tlshd_config_get_server_privkey (const gchar *key, +gnutls_privkey_t *privkey) {gnutls_datum_t data;gchar *pathname;int ret; pathname =g_key_file_get_string (tlshd_configuration,"authenticate.server" , -"x509.private_key" ,NULL ); + key,NULL );if (!pathname)return false;src/tlshd/server.c +0
-0src/tlshd/server.c static gnutls_privkey_t tlshd_server_privkey; · line 54
Quoted 9 lines
src/tlshd/server.c +6
-0@@ -46,13 +46,25 @@ static gnutls_privkey_t tlshd_server_privkey;static unsigned int tlshd_server_certs_len =TLSHD_MAX_CERTS ;static gnutls_pcert_st tlshd_server_certs[TLSHD_MAX_CERTS ]; +#ifdef HAVE_GNUTLS_MLDSA +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 ]; +#endif /* HAVE_GNUTLS_MLDSA */ +Two architectural thoughts when seeing this:
Quoted 3 lines
1. Generally, I'd rather see fewer "#ifdef
HAVE_GNUTLS_MLDSA" throughout and just leave things enabled all the time where it makes sense. That makes for less clutter and better test coverage.
I should've sent v1 before I did any refactoring :/ There's much less IFDEFery going on in this version.
Quoted 4 lines
2. Does it make sense for
tlshd_config_get_server_certsto retrieve both types of certificates in the same array? Or, more generally speaking, where it's sensible, try not to duplicate the logic, but combine it.
Yeah, when I did the last patch I noticed that each of the client & server variants of the tlshd_config_get_* are pretty much identical except for 1) which stanza/group_name of the config they're looking at and 2) whether they have the word "client" or "server" in the log message.
I was thinking of adding the group_name to the arg list, which would at least allow us to use the same functions for the client and the server side of things... or just adding a flag field to specify whether we're looking for the configuration for client/server and post-quantum/traditional.
I'm not sure if I could use a single list or not. I guess I'd need to either store the index of the PQ cert or I'd need to walk the list each time in the cert callback each time to find it. I thought it was more straightforward this way.
But looking at the gnutls-serv program I'm wondering why we even need to use a list at all. gnutls-serv just pulls the cert and key directly into the credentials structure (gnutls_certificate_credentials_t) using the higher level gnutls_certificate_set_x509_key_file() API. When you run it with multiple certs it picks the right one, without any cert callback. Is there a reason tlshd needs to use the lower level functions gnutls_pcert_list_import_x509_raw and gnutls_privkey_import_x509_raw (at least for the server-side stuff)? Also, why does tlshd parse the config and set up the credentials structure every time we do a handshake instead of just doing it once at startup and reusing it for each session?
-Scott
Quoted 160 lines
Similar comments in the client parts of the series. Overall the series looks like a reasonable direction.
Quoted 150 lines
src/tlshd/server.c +51
-2static bool tlshd_x509_server_get_certs (struct tlshd_handshake_parms *parms) {if (parms->x509_cert !=TLS_NO_CERT )return tlshd_keyring_get_certs (parms->x509_cert, tlshd_server_certs, &tlshd_server_certs_len); -return tlshd_config_get_server_certs (tlshd_server_certs, +#ifdef HAVE_GNUTLS_MLDSA +tlshd_config_get_server_certs ("x509.pq.certificate" , + tlshd_server_pq_certs, + &tlshd_server_pq_certs_len); +#endif /* HAVE_GNUTLS_MLDSA */ +return tlshd_config_get_server_certs ("x509.certificate" , + tlshd_server_certs, &tlshd_server_certs_len); }@@ -62,6 +74,11 @@ static void tlshd_x509_server_put_certs(void)for (i =0 ; i < tlshd_server_certs_len; i++)gnutls_pcert_deinit (&tlshd_server_certs[i]); + +#ifdef HAVE_GNUTLS_MLDSA +for (i =0 ; i < tlshd_server_pq_certs_len; i++) +gnutls_pcert_deinit (&tlshd_server_pq_certs[i]); +#endif /* HAVE_GNUTLS_MLDSA */ }static bool tlshd_x509_server_get_privkey (struct tlshd_handshake_parms *parms)@@ -69,12 +86,18 @@ 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); +#ifdef HAVE_GNUTLS_MLDSA +tlshd_config_get_server_privkey ("x509.pq.private_key" , &tlshd_server_pq_privkey); +#endif /* HAVE_GNUTLS_MLDSA */ +return tlshd_config_get_server_privkey ("x509.private_key" , &tlshd_server_privkey); }static void tlshd_x509_server_put_privkey (void ) {gnutls_privkey_deinit (tlshd_server_privkey); +#ifdef HAVE_GNUTLS_MLDSA +gnutls_privkey_deinit (tlshd_server_pq_privkey); +#endif /* HAVE_GNUTLS_MLDSA */ }static void tlshd_x509_log_issuers (const gnutls_datum_t *req_ca_rdn,int nreqs)@@ -120,6 +143,11 @@ tlshd_x509_retrieve_key_cb(gnutls_session_t session, gnutls_privkey_t *privkey) {gnutls_certificate_type_t type; +#ifdef HAVE_GNUTLS_MLDSA +gnutls_sign_algorithm_t client_alg; +bool use_pq_cert = false; +int i, ret; +#endif /* HAVE_GNUTLS_MLDSA */ tlshd_x509_log_issuers (req_ca_rdn, nreqs);@@ -127,9 +155,36 @@ tlshd_x509_retrieve_key_cb(gnutls_session_t session,if (type !=GNUTLS_CRT_X509 )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 ; + } + } + +if (use_pq_cert == true && tlshd_server_pq_certs_len >0 ) { +tlshd_log_debug ("%s: Selecting x509.pq.certificate from conf file" , __func__); + *pcert_length = tlshd_server_pq_certs_len; + *pcert = tlshd_server_pq_certs; + *privkey = tlshd_server_pq_privkey; + }else { +tlshd_log_debug ("%s: Selecting x509.certificate from conf file" , __func__); + *pcert_length = tlshd_server_certs_len; + *pcert = tlshd_server_certs; + *privkey = tlshd_server_privkey; + } +#else *pcert_length = tlshd_server_certs_len; *pcert = tlshd_server_certs; *privkey = tlshd_server_privkey; +#endif /* HAVE_GNUTLS_MLDSA */ return 0 ; }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 +13
-0@@ -125,6 +125,19 @@ 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. +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 AUTHORsrc/tlshd/tlshd.h +4
-2@@ -59,9 +59,11 @@ bool tlshd_config_get_client_certs(gnutls_pcert_st *certs,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, +bool tlshd_config_get_server_certs (const gchar *key, +gnutls_pcert_st *certs,unsigned int *certs_len); -bool tlshd_config_get_server_privkey (gnutls_privkey_t *privkey); +bool tlshd_config_get_server_privkey (const gchar *key, +gnutls_privkey_t *privkey);/* handshake.c */ extern void tlshd_start_tls_handshake(gnutls_session_t session,Signature · 1 line
Chuck Lever
Re: [PATCH 2/5] tlshd: Server-side dual certificate support
Quoted 155 lines · Scott Mayhew
Quoted 52 lines · Chuck Lever
Quoted 31 lines · Scott Mayhew
Add 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").
--- configure.ac | 12 ++++++++ src/tlshd/config.c | 12 +++++--- src/tlshd/server.c | 59 ++++++++++++++++++++++++++++++++++++++-- src/tlshd/tlshd.conf | 2 ++ src/tlshd/tlshd.conf.man | 13 +++++++++ src/tlshd/tlshd.h | 6 ++-- 6 files changed, 96 insertions(+), 8 deletions(-)configure.ac +5
-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; ]])],configure.ac AC_CHECK_LIB([gnutls], [gnutls_get_system_config_file], · line 96
Quoted 10 lines
configure.ac +7
-0+ [ 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])Nice.
Quoted 6 lines
src/tlshd/config.c +0
-0@@ -403,6 +403,7 @@ bool tlshd_config_get_server_crl(char **result)Quoted 8 lines
src/tlshd/config.c bool tlshd_config_get_server_crl(char **result) · line 406
Quoted 3 lines
src/tlshd/config.c +1
-0/** * tlshd_config_get_server_certs - Get certs for ServerHello from .conf +* @key: IN: the key field name from .conf ETOOMANYTHINGSCALLEDKEY :-)
Can you find a less overloaded name for the new function parameter, here and below?
Yeah, I called it 'key' because that's what it's referred to in
https://docs.gtk.org/glib/method.KeyFile.get_string.html
I'm open to suggestions (gkey?gfile_key? option?)Quoted 70 lines
But see below... perhaps the additional parameter isn't needed if all the configured certificates and private keys can be retrieved using the same functions.
Quoted 52 lines
src/tlshd/config.c +7
-4* @certs: OUT: in-memory certificates * @certs_len: IN: maximum number of certs to get, OUT: number of certs found * @@ -410,7 +411,8 @@ bool tlshd_config_get_server_crl(char **result)* %true: certificate retrieved successfully * %false: certificate not retrieved */ -bool tlshd_config_get_server_certs (gnutls_pcert_st *certs, +bool tlshd_config_get_server_certs (const gchar *key, +gnutls_pcert_st *certs,unsigned int *certs_len) {gnutls_datum_t data;@@ -418,7 +420,7 @@ bool tlshd_config_get_server_certs(gnutls_pcert_st *certs,int ret; pathname =g_key_file_get_string (tlshd_configuration,"authenticate.server" , -"x509.certificate" ,NULL ); + key,NULL );if (!pathname)return false;@@ -446,20 +448,22 @@ bool tlshd_config_get_server_certs(gnutls_pcert_st *certs,/** * tlshd_config_get_server_privkey - Get private key for ServerHello from .conf +* @key: IN: the key field name from .conf * @privkey: OUT: in-memory private key * * Return values: * %true: private key retrieved successfully * %false: private key not retrieved */ -bool tlshd_config_get_server_privkey (gnutls_privkey_t *privkey) +bool tlshd_config_get_server_privkey (const gchar *key, +gnutls_privkey_t *privkey) {gnutls_datum_t data;gchar *pathname;int ret; pathname =g_key_file_get_string (tlshd_configuration,"authenticate.server" , -"x509.private_key" ,NULL ); + key,NULL );if (!pathname)return false;src/tlshd/server.c +0
-0src/tlshd/server.c static gnutls_privkey_t tlshd_server_privkey; · line 54
Quoted 9 lines
src/tlshd/server.c +6
-0@@ -46,13 +46,25 @@ static gnutls_privkey_t tlshd_server_privkey;static unsigned int tlshd_server_certs_len =TLSHD_MAX_CERTS ;static gnutls_pcert_st tlshd_server_certs[TLSHD_MAX_CERTS ]; +#ifdef HAVE_GNUTLS_MLDSA +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 ]; +#endif /* HAVE_GNUTLS_MLDSA */ +Two architectural thoughts when seeing this:
Quoted 3 lines
1. Generally, I'd rather see fewer "#ifdef
HAVE_GNUTLS_MLDSA" throughout and just leave things enabled all the time where it makes sense. That makes for less clutter and better test coverage.I should've sent v1 before I did any refactoring :/ There's much less IFDEFery going on in this version.
Quoted 4 lines
2. Does it make sense for
tlshd_config_get_server_certsto retrieve both types of certificates in the same array? Or, more generally speaking, where it's sensible, try not to duplicate the logic, but combine it.Yeah, when I did the last patch I noticed that each of the client & server variants of the tlshd_config_get_* are pretty much identical except for 1) which stanza/group_name of the config they're looking at and 2) whether they have the word "client" or "server" in the log message.
Quoted 5 lines
I was thinking of adding the
group_nameto the arg list, which would at least allow us to use the same functions for the client and the server side of things... or just adding a flag field to specify whether we're looking for the configuration for client/server and post-quantum/traditional.
Careful, you might be mixing local knowlege from two subsystems. I'd like to keep the config-related details in config.c and the x.509 related details in x509.c -- at least as much as is practical.
Quoted 5 lines
I'm not sure if I could use a single list or not. I guess I'd need to either store the index of the PQ cert or I'd need to walk the list each time in the cert callback each time to find it. I thought it was more straightforward this way.
Quoted 8 lines
But looking at the gnutls-serv program I'm wondering why we even need to use a list at all. gnutls-serv just pulls the cert and key directly into the credentials structure (
gnutls_certificate_credentials_t) using the higher levelgnutls_certificate_set_x509_key_file()API. When you run it with multiple certs it picks the right one, without any cert callback. Is there a reason tlshd needs to use the lower level functionsgnutls_pcert_list_import_x509_rawandgnutls_privkey_import_x509_raw(at least for the server-side stuff)?
I don't remember, unfortunately.
Quoted 3 lines
Also, why does tlshd parse the config
and set up the credentials structure every time we do a handshake instead of just doing it once at startup and reusing it for each session?
Is it parsing the config, or simply walking the already-parsed tlshd_configuration data structure?
Quoted 160 lines
Quoted 159 lines
Similar comments in the client parts of the series. Overall the series looks like a reasonable direction.
Quoted 150 lines
src/tlshd/server.c +51
-2static bool tlshd_x509_server_get_certs (struct tlshd_handshake_parms *parms) {if (parms->x509_cert !=TLS_NO_CERT )return tlshd_keyring_get_certs (parms->x509_cert, tlshd_server_certs, &tlshd_server_certs_len); -return tlshd_config_get_server_certs (tlshd_server_certs, +#ifdef HAVE_GNUTLS_MLDSA +tlshd_config_get_server_certs ("x509.pq.certificate" , + tlshd_server_pq_certs, + &tlshd_server_pq_certs_len); +#endif /* HAVE_GNUTLS_MLDSA */ +return tlshd_config_get_server_certs ("x509.certificate" , + tlshd_server_certs, &tlshd_server_certs_len); }@@ -62,6 +74,11 @@ static void tlshd_x509_server_put_certs(void)for (i =0 ; i < tlshd_server_certs_len; i++)gnutls_pcert_deinit (&tlshd_server_certs[i]); + +#ifdef HAVE_GNUTLS_MLDSA +for (i =0 ; i < tlshd_server_pq_certs_len; i++) +gnutls_pcert_deinit (&tlshd_server_pq_certs[i]); +#endif /* HAVE_GNUTLS_MLDSA */ }static bool tlshd_x509_server_get_privkey (struct tlshd_handshake_parms *parms)@@ -69,12 +86,18 @@ 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); +#ifdef HAVE_GNUTLS_MLDSA +tlshd_config_get_server_privkey ("x509.pq.private_key" , &tlshd_server_pq_privkey); +#endif /* HAVE_GNUTLS_MLDSA */ +return tlshd_config_get_server_privkey ("x509.private_key" , &tlshd_server_privkey); }static void tlshd_x509_server_put_privkey (void ) {gnutls_privkey_deinit (tlshd_server_privkey); +#ifdef HAVE_GNUTLS_MLDSA +gnutls_privkey_deinit (tlshd_server_pq_privkey); +#endif /* HAVE_GNUTLS_MLDSA */ }static void tlshd_x509_log_issuers (const gnutls_datum_t *req_ca_rdn,int nreqs)@@ -120,6 +143,11 @@ tlshd_x509_retrieve_key_cb(gnutls_session_t session, gnutls_privkey_t *privkey) {gnutls_certificate_type_t type; +#ifdef HAVE_GNUTLS_MLDSA +gnutls_sign_algorithm_t client_alg; +bool use_pq_cert = false; +int i, ret; +#endif /* HAVE_GNUTLS_MLDSA */ tlshd_x509_log_issuers (req_ca_rdn, nreqs);@@ -127,9 +155,36 @@ tlshd_x509_retrieve_key_cb(gnutls_session_t session,if (type !=GNUTLS_CRT_X509 )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 ; + } + } + +if (use_pq_cert == true && tlshd_server_pq_certs_len >0 ) { +tlshd_log_debug ("%s: Selecting x509.pq.certificate from conf file" , __func__); + *pcert_length = tlshd_server_pq_certs_len; + *pcert = tlshd_server_pq_certs; + *privkey = tlshd_server_pq_privkey; + }else { +tlshd_log_debug ("%s: Selecting x509.certificate from conf file" , __func__); + *pcert_length = tlshd_server_certs_len; + *pcert = tlshd_server_certs; + *privkey = tlshd_server_privkey; + } +#else *pcert_length = tlshd_server_certs_len; *pcert = tlshd_server_certs; *privkey = tlshd_server_privkey; +#endif /* HAVE_GNUTLS_MLDSA */ return 0 ; }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 +13
-0@@ -125,6 +125,19 @@ 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. +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 AUTHORsrc/tlshd/tlshd.h +4
-2@@ -59,9 +59,11 @@ bool tlshd_config_get_client_certs(gnutls_pcert_st *certs,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, +bool tlshd_config_get_server_certs (const gchar *key, +gnutls_pcert_st *certs,unsigned int *certs_len); -bool tlshd_config_get_server_privkey (gnutls_privkey_t *privkey); +bool tlshd_config_get_server_privkey (const gchar *key, +gnutls_privkey_t *privkey);/* handshake.c */ extern void tlshd_start_tls_handshake(gnutls_session_t session,Signature · 1 line
Chuck Lever
Signature · 1 line
Chuck Lever
Re: [PATCH 2/5] tlshd: Server-side dual certificate support
In reply to Scott MayhewQuoted 60 lines · Scott Mayhew
Quoted 58 lines · Chuck Lever
Quoted 31 lines · Scott Mayhew
Add 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").
--- configure.ac | 12 ++++++++ src/tlshd/config.c | 12 +++++--- src/tlshd/server.c | 59 ++++++++++++++++++++++++++++++++++++++-- src/tlshd/tlshd.conf | 2 ++ src/tlshd/tlshd.conf.man | 13 +++++++++ src/tlshd/tlshd.h | 6 ++-- 6 files changed, 96 insertions(+), 8 deletions(-)configure.ac +5
-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; ]])],configure.ac AC_CHECK_LIB([gnutls], [gnutls_get_system_config_file], · line 96
Quoted 10 lines
configure.ac +7
-0+ [ 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])Nice.
src/tlshd/config.c bool tlshd_config_get_server_crl(char **result) · line 406
Quoted 9 lines
src/tlshd/config.c +1
-0@@ -403,6 +403,7 @@ bool tlshd_config_get_server_crl(char **result)/** * tlshd_config_get_server_certs - Get certs for ServerHello from .conf +* @key: IN: the key field name from .conf ETOOMANYTHINGSCALLEDKEY :-)
Quoted 6 lines
Quoted 2 lines
Can you find a less overloaded name for the new function parameter, here and below?
Yeah, I called it 'key' because that's what it's referred to in
https://docs.gtk.org/glib/method.KeyFile.get_string.html
I'm open to suggestions (gkey?gfile_key? option?)
How about @cert_type ?
If you need to keep this parameter, I would make it an enumerated integer. Keep the knowledge about the config option name internal to config.c.
Signature · 1 line
Chuck Lever
PATCH 3/5 tlshd: Make sure x509.pq.certificate is using a PQ public-key alg
In reply to Scott MayhewEnsure that the PQ certificate is using a post-quantum public-key algorithm (ML-DSA-44, ML-DSA-65, or ML-DSA-87).
--- 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(-)
src/tlshd/config.c +52 -1
@@ -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 );
src/tlshd/server.c +4 -2
@@ -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 )
src/tlshd/tlshd.conf.man +2 -0
@@ -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
src/tlshd/tlshd.h +2 -1
@@ -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);
Signature · 1 line
2.50.1
PATCH 4/5 tlshd: Make sure the client supports the PQ pk alg used by the server cert
In reply to Scott MayhewStore 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.
--- src/tlshd/config.c | 12 +++++++----- src/tlshd/server.c | 49 ++++++++++++++++++++++++++++++++++------------ src/tlshd/tlshd.h | 2 +- 3 files changed, 44 insertions(+), 19 deletions(-)
src/tlshd/config.c +7 -5
@@ -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);
src/tlshd/server.c +36 -13
74 lines not on this page · raw message
src/tlshd/tlshd.h +1 -1
@@ -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);
Signature · 1 line
2.50.1
PATCH 5/5 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 | 66 +++++++++++++++++++++++++-- src/tlshd/config.c | 104 ++++++++++++++++++++++++++----------------- src/tlshd/tlshd.conf | 2 + src/tlshd/tlshd.h | 9 ++-- 4 files changed, 132 insertions(+), 49 deletions(-)
src/tlshd/client.c +62 -4
@@ -138,12 +138,24 @@ static gnutls_privkey_t tlshd_privkey;static unsigned int tlshd_certs_len =TLSHD_MAX_CERTS ;static gnutls_pcert_st tlshd_certs[TLSHD_MAX_CERTS ]; +#ifdef HAVE_GNUTLS_MLDSA +static gnutls_privkey_t tlshd_pq_privkey; +static unsigned int tlshd_pq_certs_len =TLSHD_MAX_CERTS ; +static gnutls_pcert_st tlshd_pq_certs[TLSHD_MAX_CERTS ]; +static gnutls_pk_algorithm_t tlshd_pq_pkalg =GNUTLS_PK_UNKNOWN ; +#endif /* HAVE_GNUTLS_MLDSA */ +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); +#ifdef HAVE_GNUTLS_MLDSA +tlshd_config_get_client_certs ("x509.pq.certificate" , tlshd_pq_certs, + &tlshd_pq_certs_len, &tlshd_pq_pkalg); +#endif /* HAVE_GNUTLS_MLDSA */ +return tlshd_config_get_client_certs ("x509.certificate" , tlshd_certs, + &tlshd_certs_len,NULL ); }static void tlshd_x509_client_put_certs (void )
@@ -152,6 +164,11 @@ static void tlshd_x509_client_put_certs(void)for (i =0 ; i < tlshd_certs_len; i++)gnutls_pcert_deinit (&tlshd_certs[i]); + +#ifdef HAVE_GNUTLS_MLDSA +for (i =0 ; i < tlshd_pq_certs_len; i++) +gnutls_pcert_deinit (&tlshd_pq_certs[i]); +#endif /* HAVE_GNUTLS_MLDSA */ }static bool tlshd_x509_client_get_privkey (struct tlshd_handshake_parms *parms)
@@ -159,12 +176,18 @@ 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); +#ifdef HAVE_GNUTLS_MLDSA +tlshd_config_get_client_privkey ("x509.pq.private_key" , &tlshd_pq_privkey); +#endif /* HAVE_GNUTLS_MLDSA */ +return tlshd_config_get_client_privkey ("x509.private_key" , &tlshd_privkey); }static void tlshd_x509_client_put_privkey (void ) {gnutls_privkey_deinit (tlshd_privkey); +#ifdef HAVE_GNUTLS_MLDSA +gnutls_privkey_deinit (tlshd_pq_privkey); +#endif /* HAVE_GNUTLS_MLDSA */ }static void tlshd_x509_log_issuers (const gnutls_datum_t *req_ca_rdn,int nreqs)
@@ -203,13 +226,21 @@ 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) { +#ifndef HAVE_GNUTLS_MLDSA + (void )pk_algos; + (void )pk_algos_length; +#endif /* HAVE_GNUTLS_MLDSA */ gnutls_certificate_type_t type; +#ifdef HAVE_GNUTLS_MLDSA +bool use_pq_cert = false; +int i; +#endif /* HAVE_GNUTLS_MLDSA */ tlshd_x509_log_issuers (req_ca_rdn, nreqs);
@@ -217,9 +248,36 @@ tlshd_x509_retrieve_key_cb(gnutls_session_t session,if (type !=GNUTLS_CRT_X509 )return -1 ; +#ifdef HAVE_GNUTLS_MLDSA +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_pq_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; + *privkey = tlshd_privkey; + } +#else *pcert_length = tlshd_certs_len; *pcert = tlshd_certs; *privkey = tlshd_privkey; +#endif /* HAVE_GNUTLS_MLDSA */ return 0 ; }
src/tlshd/config.c +62 -42
155 lines not on this page · raw message
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>
src/tlshd/tlshd.h +6 -3
@@ -54,9 +54,12 @@ 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_client_certs (const gchar *key, +gnutls_pcert_st *certs, +unsigned int *certs_len, +gnutls_pk_algorithm_t *pkalg); +bool tlshd_config_get_client_privkey (const gchar *key, +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(const gchar *key,
Signature · 1 line
2.50.1