aboutsummaryrefslogtreecommitdiffstats
path: root/src/tls
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2026-04-13 03:32:51 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2026-04-13 03:32:51 +0000
commit030078b7bf67a4307623f1a5c58284561ff64a56 (patch)
tree908d840523cf84fad55753a1dc16cee31a1a0d65 /src/tls
parentc2ffcd960ba55570fb701de2b9f4e2ad6e1d628d (diff)
downloads6-networking-030078b7bf67a4307623f1a5c58284561ff64a56.tar.gz
Implement --no-verify-cert for s6-tlsc and s6-tlsc-io
Diffstat (limited to 'src/tls')
-rw-r--r--src/tls/s6-tlsc-io.c91
-rw-r--r--src/tls/s6-tlsc.c115
-rw-r--r--src/tls/s6-ucspitlsc.c118
-rw-r--r--src/tls/s6tls_prep_tlscio.c5
4 files changed, 205 insertions, 124 deletions
diff --git a/src/tls/s6-tlsc-io.c b/src/tls/s6-tlsc-io.c
index 25347b7..9098fdc 100644
--- a/src/tls/s6-tlsc-io.c
+++ b/src/tls/s6-tlsc-io.c
@@ -3,10 +3,10 @@
#include <stdint.h>
#include <signal.h>
+#include <skalibs/uint64.h>
#include <skalibs/gccattributes.h>
#include <skalibs/types.h>
-#include <skalibs/sgetopt.h>
-#include <skalibs/strerr.h>
+#include <skalibs/envexec.h>
#include <skalibs/tai.h>
#include <skalibs/sig.h>
#include <skalibs/djbunix.h>
@@ -16,6 +16,23 @@
#define USAGE "s6-tlsc-io [ -v verbosity ] [ -d notif ] [ -S | -s ] [ -J | -j ] [ -Y | -y ] [ -K timeout ] [ -k servername ] fdr fdw"
#define dieusage() strerr_dieusage(100, USAGE)
+enum golb_e
+{
+ GOLB_CLOSENOTIFY = 0x01,
+ GOLB_STRICTCN = 0x02,
+ GOLB_CLIENTCERT = 0x10,
+ GOLB_NOVERIFY = 0x20,
+} ;
+
+enum gola_e
+{
+ GOLA_VERBOSITY,
+ GOLA_KIMEOUT,
+ GOLA_SERVERNAME,
+ GOLA_NOTIF,
+ GOLA_N
+} ;
+
static inline void doit (int *, tain const *tto, uint32_t, uint32_t, unsigned int, char const *, unsigned int) gccattr_noreturn ;
#ifdef S6_NETWORKING_USE_TLS
@@ -67,41 +84,51 @@ static inline void doit (int *fds, tain const *tto, uint32_t preoptions, uint32_
int main (int argc, char const *const *argv, char const *const *envp)
{
- char const *servername = 0 ;
- tain tto ;
+ static gol_bool const rgolb[] =
+ {
+ { .so = 's', .lo = "no-close-notify", .clear = GOLB_CLOSENOTIFY, .set = 0 },
+ { .so = 'S', .lo = "close-notify", .clear = 0, .set = GOLB_CLOSENOTIFY },
+ { .so = 'j', .lo = "no-enforce-close-notify", .clear = GOLB_STRICTCN, .set = 0 },
+ { .so = 'J', .lo = "enforce-close-notify", .clear = 0, .set = GOLB_STRICTCN },
+ { .so = 'Y', .lo = "no-client-cert", .clear = GOLB_CLIENTCERT, .set = 0 },
+ { .so = 'y', .lo = "client-cert", .clear = 0, .set = GOLB_CLIENTCERT },
+ { .so = 0, .lo = "verify-cert", .clear = GOLB_NOVERIFY, .set = 0 },
+ { .so = 0, .lo = "no-verify-cert", .clear = 0, .set = GOLB_NOVERIFY },
+ } ;
+ static gol_arg const rgola[] =
+ {
+ { .so = 'v', .lo = "verbosity", .i = GOLA_VERBOSITY },
+ { .so = 'K', .lo = "kimeout", .i = GOLA_KIMEOUT },
+ { .so = 'k', .lo = "servername", .i = GOLA_SERVERNAME },
+ { .so = 'd', .lo = "notification-fd", .i = GOLA_NOTIF },
+ } ;
int fds[4] = { 0, 1 } ;
+ tain tto = TAIN_INFINITE_RELATIVE ;
unsigned int verbosity = 1 ;
unsigned int notif = 0 ;
- uint32_t preoptions = 0 ;
- uint32_t options = 0 ;
-
+ uint64_t wgolb = 0 ;
+ char const *wgola[GOLA_N] = { 0 } ;
+ unsigned int golc ;
PROG = "s6-tlsc-io" ;
+
+ golc = GOL_main(argc, argv, rgolb, rgola, &wgolb, wgola) ;
+ argc -= golc ; argv += golc ;
+ if (argc < 2) dieusage() ;
+
+ if (wgola[GOLA_VERBOSITY])
+ if (!uint0_scan(wgola[GOLA_VERBOSITY], &verbosity))
+ strerr_dief2x(100, "verbosity", " must be an unsigned integer") ;
+ if (wgola[GOLA_KIMEOUT])
{
- subgetopt l = SUBGETOPT_ZERO ;
- unsigned int t = 0 ;
- for (;;)
- {
- int opt = subgetopt_r(argc, argv, "d:SsJjYyv:K:k:", &l) ;
- if (opt == -1) break ;
- switch (opt)
- {
- case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ;
- case 'd' : if (!uint0_scan(l.arg, &notif)) dieusage() ; break ;
- case 'S' : options |= 1 ; break ;
- case 's' : options &= ~1 ; break ;
- case 'J' : options |= 2 ; break ;
- case 'j' : options &= ~2 ; break ;
- case 'y' : preoptions |= 1 ; break ;
- case 'Y' : preoptions &= ~1 ; break ;
- case 'K' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ;
- case 'k' : servername = l.arg ; break ;
- default : dieusage() ;
- }
- }
- argc -= l.ind ; argv += l.ind ;
- if (t) tain_from_millisecs(&tto, t) ; else tto = tain_infinite_relative ;
+ unsigned int kimeout ;
+ if (!uint0_scan(wgola[GOLA_KIMEOUT], &kimeout))
+ strerr_dief2x(100, "kimeout", " must be an unsigned integer") ;
+ if (kimeout) tain_from_millisecs(&tto, kimeout) ;
}
- if (argc < 2) dieusage() ;
+ if (wgola[GOLA_NOTIF])
+ if (!uint0_scan(wgola[GOLA_NOTIF], &notif))
+ strerr_dief2x(100, "notification-fd", " must be an unsigned integer") ;
+
{
unsigned int u ;
if (!uint0_scan(argv[0], &u)) dieusage() ;
@@ -112,5 +139,5 @@ int main (int argc, char const *const *argv, char const *const *envp)
if (!sig_ignore(SIGPIPE)) strerr_diefu1sys(111, "ignore SIGPIPE") ;
tain_now_set_stopwatch_g() ;
- doit(fds, &tto, preoptions, options, verbosity, servername, notif) ;
+ doit(fds, &tto, wgolb >> 4, wgolb & 0xf, verbosity, wgola[GOLA_SERVERNAME], notif) ;
}
diff --git a/src/tls/s6-tlsc.c b/src/tls/s6-tlsc.c
index ebea264..2308a52 100644
--- a/src/tls/s6-tlsc.c
+++ b/src/tls/s6-tlsc.c
@@ -5,8 +5,7 @@
#include <fcntl.h>
#include <skalibs/types.h>
-#include <skalibs/sgetopt.h>
-#include <skalibs/strerr.h>
+#include <skalibs/envexec.h>
#include <skalibs/djbunix.h>
#include "s6tls-internal.h"
@@ -14,64 +13,92 @@
#define USAGE "s6-tlsc [ -S | -s ] [ -J | -j ] [ -Y | -y ] [ -v verbosity ] [ -K timeout ] [ -k servername ] [ -Z | -z ] [ -6 fdr ] [ -7 fdw ] prog..."
#define dieusage() strerr_dieusage(100, USAGE)
+enum golb_e
+{
+ GOLB_CLOSENOTIFY = 0x01,
+ GOLB_STRICTCN = 0x02,
+ GOLB_CLIENTCERT = 0x04,
+ GOLB_NOVERIFY = 0x08,
+ GOLB_KEEP = 0x10,
+} ;
+
+enum gola_e
+{
+ GOLA_VERBOSITY,
+ GOLA_KIMEOUT,
+ GOLA_SERVERNAME,
+ GOLA_RFD,
+ GOLA_WFD,
+ GOLA_N
+} ;
+
int main (int argc, char const *const *argv)
{
+ static gol_bool const rgolb[] =
+ {
+ { .so = 's', .lo = "no-close-notify", .clear = GOLB_CLOSENOTIFY, .set = 0 },
+ { .so = 'S', .lo = "close-notify", .clear = 0, .set = GOLB_CLOSENOTIFY },
+ { .so = 'j', .lo = "no-enforce-close-notify", .clear = GOLB_STRICTCN, .set = 0 },
+ { .so = 'J', .lo = "enforce-close-notify", .clear = 0, .set = GOLB_STRICTCN },
+ { .so = 'Y', .lo = "no-client-cert", .clear = GOLB_CLIENTCERT, .set = 0 },
+ { .so = 'y', .lo = "client-cert", .clear = 0, .set = GOLB_CLIENTCERT },
+ { .so = 'z', .lo = "no-keep", .clear = GOLB_KEEP, .set = 0 },
+ { .so = 'Z', .lo = "keep", .clear = 0, .set = GOLB_KEEP },
+ { .so = 0, .lo = "verify-cert", .clear = GOLB_NOVERIFY, .set = 0 },
+ { .so = 0, .lo = "no-verify-cert", .clear = 0, .set = GOLB_NOVERIFY },
+ } ;
+ static gol_arg const rgola[] =
+ {
+ { .so = 'v', .lo = "verbosity", .i = GOLA_VERBOSITY },
+ { .so = 'K', .lo = "kimeout", .i = GOLA_KIMEOUT },
+ { .so = 'k', .lo = "servername", .i = GOLA_SERVERNAME },
+ { .so = '6', .lo = "read-fd", .i = GOLA_RFD },
+ { .so = '7', .lo = "write-fd", .i = GOLA_WFD },
+ } ;
unsigned int verbosity = 1 ;
unsigned int kimeout = 0 ;
int p[8] = { [6] = 6, [7] = 7 } ;
- uint32_t coptions = 0 ;
- uint32_t poptions = 1 ;
pid_t pid ;
- char const *servername = 0 ;
+ uint64_t wgolb = 0 ;
+ char const *wgola[GOLA_N] = { 0 } ;
+ unsigned int golc ;
char const *newargv[S6TLS_PREP_IO_ARGC] ;
char buf[S6TLS_PREP_IO_BUFLEN] ;
+
PROG = "s6-tlsc" ;
+ golc = GOL_main(argc, argv, rgolb, rgola, &wgolb, wgola) ;
+ argc -= golc ; argv += golc ;
+ if (!argc) dieusage() ;
+
+ if (wgola[GOLA_VERBOSITY])
+ if (!uint0_scan(wgola[GOLA_VERBOSITY], &verbosity))
+ strerr_dief2x(100, "verbosity", " must be an unsigned integer") ;
+ if (wgola[GOLA_KIMEOUT])
+ if (!uint0_scan(wgola[GOLA_KIMEOUT], &kimeout))
+ strerr_dief2x(100, "kimeout", " must be an unsigned integer") ;
+ if (wgola[GOLA_RFD])
{
- subgetopt l = SUBGETOPT_ZERO ;
- for (;;)
- {
- int opt = subgetopt_r(argc, argv, "SsJjyYv:K:k:Zz6:7:", &l) ;
- if (opt == -1) break ;
- switch (opt)
- {
- case 'S' : coptions |= 4 ; break ;
- case 's' : coptions &= ~4 ; break ;
- case 'J' : coptions |= 2 ; break ;
- case 'j' : coptions &= ~2 ; break ;
- case 'y' : coptions |= 1 ; break ;
- case 'Y' : coptions &= ~1 ; break ;
- case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ;
- case 'K' : if (!uint0_scan(l.arg, &kimeout)) dieusage() ; break ;
- case 'k' : servername = l.arg ; break ;
- case 'Z' : poptions &= ~1 ; break ;
- case 'z' : poptions |= 1 ; break ;
- case '6' :
- {
- unsigned int fd ;
- if (!uint0_scan(l.arg, &fd) || fd < 3) dieusage() ;
- p[6] = fd ;
- break ;
- }
- case '7' :
- {
- unsigned int fd ;
- if (!uint0_scan(l.arg, &fd) || fd < 3) dieusage() ;
- p[7] = fd ;
- break ;
- }
- default : dieusage() ;
- }
- }
- argc -= l.ind ; argv += l.ind ;
+ unsigned int fd ;
+ if (!uint0_scan(wgola[GOLA_RFD], &fd) || fd < 3)
+ strerr_dief3x(100, "read-fd", " must be an unsigned integer", " (3 or more)") ;
+ p[6] = fd ;
}
- if (!argc || p[6] == p[7]) dieusage() ;
+ if (wgola[GOLA_WFD])
+ {
+ unsigned int fd ;
+ if (!uint0_scan(wgola[GOLA_WFD], &fd) || fd < 3)
+ strerr_dief3x(100, "write-fd", " must be an unsigned integer", " (3 or more)") ;
+ p[7] = fd ;
+ }
+ if (p[6] == p[7]) strerr_dief1x(100, "read-fd and write-fd must be different") ;
+
fd_sanitize() ;
if (fcntl(p[6], F_GETFD) == -1 || fcntl(p[7], F_GETFD) == -1)
strerr_diefu1sys(111, "check network fds") ;
if (pipe(p) == -1 || pipe(p+2) == -1 || pipe(p+4) == -1)
strerr_diefu1sys(111, "pipe") ;
- s6tls_prep_tlscio(newargv, buf, p, coptions, verbosity, kimeout, servername) ;
+ s6tls_prep_tlscio(newargv, buf, p, wgolb & 0xf, verbosity, kimeout, wgola[GOLA_SERVERNAME]) ;
pid = s6tls_io_spawn(newargv, p, 1) ;
if (!pid) strerr_diefu2sys(111, "spawn ", newargv[0]) ;
- s6tls_sync_and_exec_app(argv, p, pid, poptions) ;
+ s6tls_sync_and_exec_app(argv, p, pid, wgolb >> 4) ;
}
diff --git a/src/tls/s6-ucspitlsc.c b/src/tls/s6-ucspitlsc.c
index cd29324..60f76de 100644
--- a/src/tls/s6-ucspitlsc.c
+++ b/src/tls/s6-ucspitlsc.c
@@ -4,13 +4,12 @@
#include <stdint.h>
#include <unistd.h>
+#include <skalibs/uint64.h>
#include <skalibs/gccattributes.h>
#include <skalibs/types.h>
-#include <skalibs/sgetopt.h>
-#include <skalibs/strerr.h>
#include <skalibs/djbunix.h>
#include <skalibs/socket.h>
-#include <skalibs/exec.h>
+#include <skalibs/envexec.h>
#include <s6-networking/config.h>
#include "s6tls-internal.h"
@@ -18,6 +17,25 @@
#define USAGE "s6-ucspitlsc [ -S | -s ] [ -J | -j ] [ -Y | -y ] [ -v verbosity ] [ -K timeout ] [ -Z | -z ] [ -k servername ] [ -6 fdr ] [ -7 fdw ] prog..."
#define dieusage() strerr_dieusage(100, USAGE)
+enum golb_e
+{
+ GOLB_CLOSENOTIFY = 0x01,
+ GOLB_STRICTCN = 0x02,
+ GOLB_CLIENTCERT = 0x04,
+ GOLB_NOVERIFY = 0x08,
+ GOLB_KEEP = 0x10,
+} ;
+
+enum gola_e
+{
+ GOLA_VERBOSITY,
+ GOLA_KIMEOUT,
+ GOLA_SERVERNAME,
+ GOLA_RFD,
+ GOLA_WFD,
+ GOLA_N
+} ;
+
static inline void child (int *, uint32_t, unsigned int, unsigned int, char const *, pid_t) gccattr_noreturn ;
static inline void child (int *p, uint32_t options, unsigned int verbosity, unsigned int kimeout, char const *servername, pid_t pid)
{
@@ -67,58 +85,66 @@ static inline void child (int *p, uint32_t options, unsigned int verbosity, unsi
int main (int argc, char const *const *argv, char const *const *envp)
{
+ static gol_bool const rgolb[] =
+ {
+ { .so = 's', .lo = "no-close-notify", .clear = GOLB_CLOSENOTIFY, .set = 0 },
+ { .so = 'S', .lo = "close-notify", .clear = 0, .set = GOLB_CLOSENOTIFY },
+ { .so = 'j', .lo = "no-enforce-close-notify", .clear = GOLB_STRICTCN, .set = 0 },
+ { .so = 'J', .lo = "enforce-close-notify", .clear = 0, .set = GOLB_STRICTCN },
+ { .so = 'Y', .lo = "no-client-cert", .clear = GOLB_CLIENTCERT, .set = 0 },
+ { .so = 'y', .lo = "client-cert", .clear = 0, .set = GOLB_CLIENTCERT },
+ { .so = 'z', .lo = "no-keep", .clear = GOLB_KEEP, .set = 0 },
+ { .so = 'Z', .lo = "keep", .clear = 0, .set = GOLB_KEEP },
+ { .so = 0, .lo = "verify-cert", .clear = GOLB_NOVERIFY, .set = 0 },
+ { .so = 0, .lo = "no-verify-cert", .clear = 0, .set = GOLB_NOVERIFY },
+ } ;
+ static gol_arg const rgola[] =
+ {
+ { .so = 'v', .lo = "verbosity", .i = GOLA_VERBOSITY },
+ { .so = 'K', .lo = "kimeout", .i = GOLA_KIMEOUT },
+ { .so = 'k', .lo = "servername", .i = GOLA_SERVERNAME },
+ { .so = '6', .lo = "read-fd", .i = GOLA_RFD },
+ { .so = '7', .lo = "write-fd", .i = GOLA_WFD },
+ } ;
+
unsigned int verbosity = 1 ;
unsigned int kimeout = 0 ;
- uint32_t coptions = 0 ;
int p[8] = { [6] = 6, [7] = 7 } ;
- uint32_t poptions = 1 ;
pid_t pid ;
- char const *servername = 0 ;
+ uint64_t wgolb = 0 ;
+ char const *wgola[GOLA_N] = { 0 } ;
+ unsigned int golc ;
PROG = "s6-ucspitlsc (parent)" ;
+ golc = GOL_main(argc, argv, rgolb, rgola, &wgolb, wgola) ;
+ argc -= golc ; argv += golc ;
+ if (!argc) dieusage() ;
+
+ if (wgola[GOLA_VERBOSITY])
+ if (!uint0_scan(wgola[GOLA_VERBOSITY], &verbosity))
+ strerr_dief2x(100, "verbosity", " must be an unsigned integer") ;
+ if (wgola[GOLA_KIMEOUT])
+ if (!uint0_scan(wgola[GOLA_KIMEOUT], &kimeout))
+ strerr_dief2x(100, "kimeout", " must be an unsigned integer") ;
+ if (wgola[GOLA_RFD])
{
- subgetopt l = SUBGETOPT_ZERO ;
- for (;;)
- {
- int opt = subgetopt_r(argc, argv, "SsJjyYv:K:Zzk:6:7:", &l) ;
- if (opt == -1) break ;
- switch (opt)
- {
- case 'S' : coptions |= 4 ; break ;
- case 's' : coptions &= ~4 ; break ;
- case 'J' : coptions |= 2 ; break ;
- case 'j' : coptions &= ~2 ; break ;
- case 'y' : coptions |= 1 ; break ;
- case 'Y' : coptions &= ~1 ; break ;
- case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ;
- case 'K' : if (!uint0_scan(l.arg, &kimeout)) dieusage() ; break ;
- case 'Z' : poptions &= ~1 ; break ;
- case 'z' : poptions |= 1 ; break ;
- case 'k' : servername = l.arg ; break ;
- case '6' :
- {
- unsigned int fd ;
- if (!uint0_scan(l.arg, &fd)) dieusage() ;
- p[6] = fd ;
- break ;
- }
- case '7' :
- {
- unsigned int fd ;
- if (!uint0_scan(l.arg, &fd)) dieusage() ;
- p[7] = fd ;
- break ;
- }
- default : dieusage() ;
- }
- }
- argc -= l.ind ; argv += l.ind ;
+ unsigned int fd ;
+ if (!uint0_scan(wgola[GOLA_RFD], &fd) || fd < 3)
+ strerr_dief3x(100, "read-fd", " must be an unsigned integer", " (3 or more)") ;
+ p[6] = fd ;
}
- if (!argc || p[6] == p[7]) dieusage() ;
+ if (wgola[GOLA_WFD])
+ {
+ unsigned int fd ;
+ if (!uint0_scan(wgola[GOLA_WFD], &fd) || fd < 3)
+ strerr_dief3x(100, "write-fd", " must be an unsigned integer", " (3 or more)") ;
+ p[7] = fd ;
+ }
+ if (p[6] == p[7]) strerr_dief1x(100, "read-fd and write-fd must be different") ;
+
fd_sanitize() ;
if (fcntl(p[6], F_GETFD) == -1 || fcntl(p[7], F_GETFD) == -1)
strerr_diefu1sys(111, "check network fds") ;
-
if (pipe(p) == -1 || pipe(p+2) == -1) strerr_diefu1sys(111, "pipe") ;
if (ipc_pair_b(p+4) == -1) strerr_diefu1sys(111, "ipc_pair") ;
pid = getpid() ;
@@ -126,8 +152,8 @@ int main (int argc, char const *const *argv, char const *const *envp)
switch (fork())
{
case -1 : strerr_diefu1sys(111, "fork") ;
- case 0 : child(p, coptions, verbosity, kimeout, servername, pid) ;
+ case 0 : child(p, wgolb & 0xf, verbosity, kimeout, wgola[GOLA_SERVERNAME], pid) ;
default : break ;
}
- s6tls_ucspi_exec_app(argv, p, poptions) ;
+ s6tls_ucspi_exec_app(argv, p, wgolb >> 4) ;
}
diff --git a/src/tls/s6tls_prep_tlscio.c b/src/tls/s6tls_prep_tlscio.c
index f56106f..d6b00fc 100644
--- a/src/tls/s6tls_prep_tlscio.c
+++ b/src/tls/s6tls_prep_tlscio.c
@@ -25,9 +25,10 @@ void s6tls_prep_tlscio (char const **argv, char *buf, int const *p, uint32_t opt
n += uint_fmt(buf + n, p[5]) ;
buf[n++] = 0 ;
}
- if (options & 4) argv[m++] = "-S" ;
+ if (options & 1) argv[m++] = "-S" ;
if (options & 2) argv[m++] = "-J" ;
- if (options & 1) argv[m++] = "-y" ;
+ if (options & 4) argv[m++] = "-y" ;
+ if (options & 8) argv[m++] = "--no-verify-cert" ;
if (kimeout)
{
argv[m++] = "-K" ;