summaryrefslogtreecommitdiff
path: root/src/sbearssl
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2020-11-21 02:22:09 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2020-11-21 02:22:09 +0000
commit5c2880becc94141b8035b3488b6bd60696011308 (patch)
tree51e177122b50e248075dae441e4a76d68fd33081 /src/sbearssl
parent5715c21a077ee1c2fe8957cb4adcea14fd2eda6b (diff)
downloads6-networking-5c2880becc94141b8035b3488b6bd60696011308.tar.xz
Privs can only be dropped after reading key files.
Diffstat (limited to 'src/sbearssl')
-rw-r--r--src/sbearssl/deps-lib/sbearssl1
-rw-r--r--src/sbearssl/sbearssl-internal.h1
-rw-r--r--src/sbearssl/sbearssl_client_init_and_run.c2
-rw-r--r--src/sbearssl/sbearssl_drop.c24
-rw-r--r--src/sbearssl/sbearssl_server_init_and_run.c2
5 files changed, 30 insertions, 0 deletions
diff --git a/src/sbearssl/deps-lib/sbearssl b/src/sbearssl/deps-lib/sbearssl
index 55729f6..13df389 100644
--- a/src/sbearssl/deps-lib/sbearssl
+++ b/src/sbearssl/deps-lib/sbearssl
@@ -3,6 +3,7 @@ sbearssl_cert_from.o
sbearssl_cert_readbigpem.o
sbearssl_cert_readfile.o
sbearssl_cert_to.o
+sbearssl_drop.o
sbearssl_ec_issuer_keytype.o
sbearssl_ec_pkey_from.o
sbearssl_ec_pkey_to.o
diff --git a/src/sbearssl/sbearssl-internal.h b/src/sbearssl/sbearssl-internal.h
index 25f6468..2d98680 100644
--- a/src/sbearssl/sbearssl-internal.h
+++ b/src/sbearssl/sbearssl-internal.h
@@ -17,6 +17,7 @@ struct sbearssl_strallocerr_s
int err ;
} ;
+extern void sbearssl_drop (void) ;
extern void sbearssl_append (void *, void const *, size_t) ;
extern int sbearssl_pem_push (br_pem_decoder_context *, char const *, size_t, sbearssl_pemobject *, genalloc *, sbearssl_strallocerr *, int *) ;
diff --git a/src/sbearssl/sbearssl_client_init_and_run.c b/src/sbearssl/sbearssl_client_init_and_run.c
index a95e9e1..a6e7aca 100644
--- a/src/sbearssl/sbearssl_client_init_and_run.c
+++ b/src/sbearssl/sbearssl_client_init_and_run.c
@@ -44,6 +44,8 @@ void sbearssl_client_init_and_run (int *fds, tain_t const *tto, uint32_t preopti
strerr_dief2x(96, "no trust anchor found in ", x) ;
}
+ sbearssl_drop() ;
+
{
sbearssl_handshake_cb_context_t cbarg = { .notif = notif } ;
unsigned char buf[BR_SSL_BUFSIZE_BIDI] ;
diff --git a/src/sbearssl/sbearssl_drop.c b/src/sbearssl/sbearssl_drop.c
new file mode 100644
index 0000000..2d826af
--- /dev/null
+++ b/src/sbearssl/sbearssl_drop.c
@@ -0,0 +1,24 @@
+/* ISC license. */
+
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <skalibs/strerr2.h>
+#include <skalibs/types.h>
+
+#include "sbearssl-internal.h"
+
+void sbearssl_drop (void)
+{
+ if (!getuid())
+ {
+ uid_t uid ;
+ gid_t gid ;
+ char const *x = getenv("TLS_UID") ;
+ if (x && !uid0_scan(x, &uid)) strerr_dieinvalid(100, "TLS_UID") ;
+ x = getenv("TLS_GID") ;
+ if (x && !gid0_scan(x, &gid)) strerr_dieinvalid(100, "TLS_GID") ;
+ if (gid && setgid(gid) < 0) strerr_diefu1sys(111, "setgid") ;
+ if (uid && setuid(uid) < 0) strerr_diefu1sys(111, "setuid") ;
+ }
+}
diff --git a/src/sbearssl/sbearssl_server_init_and_run.c b/src/sbearssl/sbearssl_server_init_and_run.c
index 778fdbd..629fafb 100644
--- a/src/sbearssl/sbearssl_server_init_and_run.c
+++ b/src/sbearssl/sbearssl_server_init_and_run.c
@@ -45,6 +45,8 @@ void sbearssl_server_init_and_run (int *fds, tain_t const *tto, uint32_t preopti
strerr_diefu2x(96, "find a certificate in ", x) ;
}
+ sbearssl_drop() ;
+
{
sbearssl_handshake_cb_context_t cbarg = { .notif = notif } ;
unsigned char buf[BR_SSL_BUFSIZE_BIDI] ;