Skip to content

Commit 7af8cc7

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 7af8cc7

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,14 @@ 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;
349+
#ifdef HAVE_GNUTLS_PSK_ALLOCATE_CREDENTIALS2
350+
int version, type, hash;
351+
#endif
346352
gnutls_datum_t key;
347353
unsigned int flags;
348354
char *identity;
@@ -359,7 +365,27 @@ static void tlshd_tls13_client_psk_handshake_one(struct tlshd_handshake_parms *p
359365
return;
360366
}
361367

368+
#ifdef HAVE_GNUTLS_PSK_ALLOCATE_CREDENTIALS2
369+
if (sscanf(identity, "NVMe%01d%c%02d %*s",
370+
&version, &type, &hash) == 3) {
371+
switch (hash) {
372+
case 1:
373+
mac = GNUTLS_MAC_SHA256;
374+
break;
375+
case 2:
376+
mac = GNUTLS_MAC_SHA384;
377+
break;
378+
default:
379+
tlshd_log_error("invalid key identity");
380+
free(identity);
381+
return;
382+
}
383+
}
384+
385+
ret = gnutls_psk_allocate_client_credentials2(&psk_cred, mac);
386+
#else
362387
ret = gnutls_psk_allocate_client_credentials(&psk_cred);
388+
#endif
363389
if (ret != GNUTLS_E_SUCCESS) {
364390
tlshd_log_gnutls_error(ret);
365391
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)