Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ AC_CHECK_LIB([gnutls], [gnutls_protocol_set_enabled],
AC_CHECK_LIB([gnutls], [gnutls_get_system_config_file],
[AC_DEFINE([HAVE_GNUTLS_GET_SYSTEM_CONFIG_FILE], [1],
[Define to 1 if you have the gnutls_get_system_config_file function.])])
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_SUBST([AM_CPPFLAGS])

AC_CONFIG_FILES([Makefile src/Makefile src/tlshd/Makefile systemd/Makefile])
Expand Down
26 changes: 26 additions & 0 deletions src/tlshd/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,14 @@ static void tlshd_tls13_client_x509_handshake(struct tlshd_handshake_parms *parm
static void tlshd_tls13_client_psk_handshake_one(struct tlshd_handshake_parms *parms,
key_serial_t peerid)
{
#ifdef HAVE_GNUTLS_PSK_ALLOCATE_CREDENTIALS2
gnutls_mac_algorithm_t mac = GNUTLS_MAC_SHA256;
#endif
gnutls_psk_client_credentials_t psk_cred;
gnutls_session_t session;
#ifdef HAVE_GNUTLS_PSK_ALLOCATE_CREDENTIALS2
int version, type, hash;
#endif
gnutls_datum_t key;
unsigned int flags;
char *identity;
Expand All @@ -359,7 +365,27 @@ static void tlshd_tls13_client_psk_handshake_one(struct tlshd_handshake_parms *p
return;
}

#ifdef HAVE_GNUTLS_PSK_ALLOCATE_CREDENTIALS2
if (sscanf(identity, "NVMe%01d%c%02d %*s",
&version, &type, &hash) == 3) {
switch (hash) {
case 1:
mac = GNUTLS_MAC_SHA256;
break;
case 2:
mac = GNUTLS_MAC_SHA384;
break;
default:
tlshd_log_error("invalid key identity");
free(identity);
return;
}
}

ret = gnutls_psk_allocate_client_credentials2(&psk_cred, mac);
#else
ret = gnutls_psk_allocate_client_credentials(&psk_cred);
#endif
if (ret != GNUTLS_E_SUCCESS) {
tlshd_log_gnutls_error(ret);
free(identity);
Expand Down
5 changes: 5 additions & 0 deletions src/tlshd/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,12 @@ static void tlshd_tls13_server_psk_handshake(struct tlshd_handshake_parms *parms
gnutls_session_t session;
int ret;

#ifdef HAVE_GNUTLS_PSK_ALLOCATE_CREDENTIALS2
ret = gnutls_psk_allocate_server_credentials2(&psk_cred,
GNUTLS_MAC_NONE);
#else
ret = gnutls_psk_allocate_server_credentials(&psk_cred);
#endif
if (ret != GNUTLS_E_SUCCESS) {
tlshd_log_gnutls_error(ret);
return;
Expand Down