summaryrefslogtreecommitdiff
path: root/src/stls/stls_handshake.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2021-01-13 11:36:16 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2021-01-13 11:36:16 +0000
commitcc7dccb1858e73176814c3a8457ff6f94ff45662 (patch)
tree746a462d3a58b4dc19c240bcbf9f224e593e23e7 /src/stls/stls_handshake.c
parent23f7b20aeac1d337587d4f59779df94c82dc06b7 (diff)
downloads6-networking-cc7dccb1858e73176814c3a8457ff6f94ff45662.tar.xz
Implement handshake timeout for libtls backend
Diffstat (limited to 'src/stls/stls_handshake.c')
-rw-r--r--src/stls/stls_handshake.c30
1 files changed, 30 insertions, 0 deletions
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 <signal.h>
+#include <unistd.h>
+
+#include <tls.h>
+
+#include <skalibs/alarm.h>
+#include <skalibs/strerr2.h>
+
+#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) ;
+}