Skip to content

Commit 9a6929b

Browse files
committed
tlshd: use gnutls_psk_allocate_{client,server}_credentials2
There is a merge request to gnutls (#11939) to implement gnutls_psk_allocate_client_credentials2() and gnutls_psk_allocate_server_credentials2(). These new functions allow to specify the binder algorithm, to overcome the defect in gnutls to always use SHA256 when calculating the binder value. So update the code to use these functions if available. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent b010190 commit 9a6929b

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

configure.ac

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ AC_CHECK_LIB([gnutls], [gnutls_protocol_set_enabled],
7676
AC_CHECK_LIB([gnutls], [gnutls_get_system_config_file],
7777
[AC_DEFINE([HAVE_GNUTLS_GET_SYSTEM_CONFIG_FILE], [1],
7878
[Define to 1 if you have the gnutls_get_system_config_file function.])])
79+
AC_CHECK_LIB([gnutls], [gnutls_psk_allocate_client_credentials2],
80+
[AC_DEFINE([HAVE_GNUTLS_PSK_ALLOCATE_CREDENTIALS2], [1],
81+
[Define to 1 if you have the gnutls_psk_allocate_client_credentials2 function.])])
7982
AC_SUBST([AM_CPPFLAGS])
8083

8184
AC_CONFIG_FILES([Makefile src/Makefile src/tlshd/Makefile systemd/Makefile])

src/tlshd/client.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ static void tlshd_tls13_client_x509_handshake(struct tlshd_handshake_parms *parm
341341
static void tlshd_tls13_client_psk_handshake_one(struct tlshd_handshake_parms *parms,
342342
key_serial_t peerid)
343343
{
344+
#ifdef HAVE_GNUTLS_PSK_ALLOCATE_CREDENTIALS2
345+
gnutls_mac_algorithm_t mac = GNUTLS_MAC_SHA256;
346+
#endif
344347
gnutls_psk_client_credentials_t psk_cred;
345348
gnutls_session_t session;
346349
gnutls_datum_t key;
@@ -359,7 +362,14 @@ static void tlshd_tls13_client_psk_handshake_one(struct tlshd_handshake_parms *p
359362
return;
360363
}
361364

365+
#ifdef HAVE_GNUTLS_PSK_ALLOCATE_CREDENTIALS2
366+
if (key.size == SHA384_DIGEST_SIZE)
367+
mac = GNUTLS_MAC_SHA384;
368+
369+
ret = gnutls_psk_allocate_client_credentials2(&psk_cred, mac);
370+
#else
362371
ret = gnutls_psk_allocate_client_credentials(&psk_cred);
372+
#endif
363373
if (ret != GNUTLS_E_SUCCESS) {
364374
tlshd_log_gnutls_error(ret);
365375
free(identity);

src/tlshd/server.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,12 @@ static void tlshd_tls13_server_psk_handshake(struct tlshd_handshake_parms *parms
327327
gnutls_session_t session;
328328
int ret;
329329

330+
#ifdef HAVE_GNUTLS_PSK_ALLOCATE_CREDENTIALS2
331+
ret = gnutls_psk_allocate_server_credentials2(&psk_cred,
332+
GNUTLS_MAC_NONE);
333+
#else
330334
ret = gnutls_psk_allocate_server_credentials(&psk_cred);
335+
#endif
331336
if (ret != GNUTLS_E_SUCCESS) {
332337
tlshd_log_gnutls_error(ret);
333338
return;

0 commit comments

Comments
 (0)