tlsrp

A simple TLS reverse proxy
git clone git://nihaljere.xyz/tlsrp
Log | Files | Refs

commit 0f824bc336222b630e771e9ffc5b07ce8759dc46
parent 6d390600d3da9fc20d7be9261fe1e871072cf528
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Sun, 12 Jul 2020 20:30:00 -0500

added `tdie` for tls_error and `tcdie` for tls_config_error

Diffstat:
Mtlsrp.c | 20++++++++++----------
Mutil.c | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Mutil.h | 2++
3 files changed, 65 insertions(+), 10 deletions(-)

diff --git a/tlsrp.c b/tlsrp.c @@ -232,34 +232,34 @@ main(int argc, char* argv[]) usage(); if ((config = tls_config_new()) == NULL) - die("failed to get tls config:"); + tcdie("failed to get tls config:"); if (tls_config_set_protocols(config, protocols) == -1) - die("failed to set protocols:"); + tcdie("failed to set protocols:"); if (tls_config_set_ciphers(config, ciphers) == -1) - die("failed to set ciphers:"); + tcdie("failed to set ciphers:"); if (tls_config_set_dheparams(config, dheparams) == -1) - die("failed to set dheparams:"); + tcdie("failed to set dheparams:"); if (tls_config_set_ecdhecurves(config, ecdhecurves) == -1) - die("failed to set ecdhecurves:"); + tcdie("failed to set ecdhecurves:"); if (tls_config_set_ca_file(config, ca_path) == -1) - die("failed to load ca file:"); + tcdie("failed to load ca file:"); if (tls_config_set_cert_file(config, cert_path) == -1) - die("failed to load cert file:"); + tcdie("failed to load cert file:"); if (tls_config_set_key_file(config, key_path) == -1) - die("failed to load key file:"); + tcdie("failed to load key file:"); if ((tls_client = tls_server()) == NULL) - die("failed to create server context:"); + die("failed to create server context"); if ((tls_configure(tls_client, config)) == -1) - die("failed to configure server:"); + tdie("failed to configure server"); tls_config_free(config); diff --git a/util.c b/util.c @@ -3,6 +3,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <tls.h> #ifdef __OpenBSD__ #include <unistd.h> @@ -27,6 +28,34 @@ verr(const char *fmt, va_list ap) } } +static void +tls_conf_err(struct tls_config *config, const char *fmt, va_list ap) +{ + const char* errstring = tls_config_error(config); + vfprintf(stderr, fmt, ap); + + if (fmt[0] && fmt[strlen(fmt) - 1] == ':') { + fputc(' ', stderr); + fputs(errstring, stderr); + } else { + fputc('\n', stderr); + } +} + +static void +tls_err(struct tls *ctx, const char *fmt, va_list ap) +{ + const char* errstring = tls_error(ctx); + vfprintf(stderr, fmt, ap); + + if (fmt[0] && fmt[strlen(fmt) - 1] == ':') { + fputc(' ', stderr); + fputs(errstring, stderr); + } else { + fputc('\n', stderr); + } +} + void warn(const char *fmt, ...) { @@ -50,6 +79,30 @@ die(const char *fmt, ...) } void +tdie(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + verr(fmt, ap); + va_end(ap); + + exit(1); +} + +void +tcdie(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + verr(fmt, ap); + va_end(ap); + + exit(1); +} + +void epledge(const char *promises, const char *execpromises) { (void)promises; diff --git a/util.h b/util.h @@ -13,6 +13,8 @@ extern char *argv0; void warn(const char *, ...); void die(const char *, ...); +void tdie(const char *, ...); +void tcdie(const char *, ...); void epledge(const char *, const char *); void eunveil(const char *, const char *);