From cc7dccb1858e73176814c3a8457ff6f94ff45662 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Wed, 13 Jan 2021 11:36:16 +0000 Subject: Implement handshake timeout for libtls backend --- src/stls/stls_handshake.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/stls/stls_handshake.c (limited to 'src/stls/stls_handshake.c') diff --git a/src/stls/stls_handshake.c b/src/stls/stls_handshake.c new file mode 100644 index 0000000..989a167 --- /dev/null +++ b/src/stls/stls_handshake.c @@ -0,0 +1,30 @@ +/* ISC license. */ + +#include +#include + +#include + +#include +#include + +#include "stls-internal.h" + +#define diectx(e, ctx, s) strerr_diefu3x(e, (s), ": ", tls_error(ctx)) + +static void alrm_handler (int sig) +{ + strerr_dief1x(98, "handshake timed out") ; +} + +void stls_handshake (struct tls *ctx, tain_t const *tto) +{ + struct sigaction saold ; + struct sigaction sanew = { .sa_handler = &alrm_handler, .sa_flags = SA_RESTART, .sa_sigaction = 0 } ; + sigfillset(&sanew.sa_mask) ; + if (sigaction(SIGALRM, &sanew, &saold) < 0) strerr_diefu1sys(111, "sigaction") ; + if (!alarm_timeout(tto)) strerr_diefu1sys(111, "set an alarm") ; + if (tls_handshake(ctx) < 0) diectx(97, ctx, "tls_handshake") ; + alarm_disable() ; + sigaction(SIGALRM, &saold, 0) ; +} -- cgit v1.3.1