Add SSL to redbean

Your redbean can now interoperate with clients that require TLS crypto.
This is accomplished using a protocol polyglot that lets us distinguish
between HTTP and HTTPS regardless of the port number. Certificates will
be generated automatically, if none are supplied by the user. Footprint
increases by only a few hundred kb so redbean in MODY=tiny is now 1.0mb

- Add lseek() polyfills for ZIP executable
- Automatically polyfill /tmp/FOO paths on NT
- Fix readdir() / ftw() / nftw() bugs on Windows
- Introduce -B flag for slower SSL that's stronger
- Remove mbedtls features Cosmopolitan doesn't need
- Have base64 decoder support the uri-safe alternative
- Remove Truncated HMAC because it's forbidden by the IETF
- Add all the mbedtls test suites and make them go 3x faster
- Support opendir() / readdir() / closedir() on ZIP executable
- Use Everest for ECDHE-ECDSA because it's so good it's so good
- Add tinier implementation of sha1 since it's not worth the rom
- Add chi-square monte-carlo mean correlation tests for getrandom()
- Source entropy on Windows from the proper interface everyone uses

We're continuing to outperform NGINX and other servers on raw message
throughput. Using SSL means that instead of 1,000,000 qps you can get
around 300,000 qps. However redbean isn't as fast as NGINX yet at SSL
handshakes, since redbean can do 2,627 per second and NGINX does 4.3k

Right now, the SSL UX story works best if you give your redbean a key
signing key since that can be easily generated by openssl using a one
liner then redbean will do all the things that are impossibly hard to
do like signing ecdsa and rsa certificates that'll work in chrome. We
should integrate the let's encrypt acme protocol in the future.

Live Demo: https://redbean.justine.lol/
Root Cert: https://redbean.justine.lol/redbean1.crt
This commit is contained in:
Justine Tunney 2021-06-24 12:31:26 -07:00
parent 1beeb7a829
commit cc1920749e
1032 changed files with 152673 additions and 69310 deletions

View file

@ -1,2 +1,2 @@
.include "o/libc/sysv/macros.internal.inc"
.scall sys_getrandom,0x05b00723321f413e,globl,hidden
.scall sys_getrandom,0xfff00723321f413e,globl,hidden

View file

@ -151,6 +151,7 @@ syscon sig SIGIO 29 23 23 23 23 29 # bsd consensus
syscon sig SIGSYS 31 12 12 12 12 31 # wut; bsd consensus
syscon sig SIGRTMAX 0 0 126 0 63 0
syscon sig SIGRTMIN 0 0 65 0 33 0
syscon sig SIGEMT 0 7 7 7 7 0 # not implemented in most community editions of system five; consider doing this using SIGUSR1 or SIGUSR2 instead
syscon compat SIGPOLL 29 23 23 23 23 29 # same as SIGIO
syscon compat SIGIOT 6 6 6 6 6 6 # PDP-11 feature; same as SIGABRT
syscon compat SIGPWR 30 30 30 30 32 30 # not implemented in most community editions of system five; consider doing this using SIGUSR1 or SIGUSR2 instead
@ -170,7 +171,7 @@ syscon open O_APPEND 0x00000400 8 8 8 8 0x00000004 # bsd consensus
syscon open O_CREAT 0x00000040 0x00000200 0x00000200 0x00000200 0x00000200 0x00000040 # bsd consensus & NT faked as Linux
syscon open O_EXCL 0x00000080 0x00000800 0x00000800 0x00000800 0x00000800 0x00000080 # bsd consensus & NT faked as Linux
syscon open O_TRUNC 0x00000200 0x00000400 0x00000400 0x00000400 0x00000400 0x00000200 # bsd consensus & NT faked as Linux
syscon open O_DIRECTORY 0x00010000 0x00100000 0x00020000 0x00020000 0x00200000 0x02000000 # kNtFileFlagBackupSemantics
syscon open O_DIRECTORY 0x00010000 0x00100000 0x00020000 0x00020000 0x00200000 0x02000000 # useful hint on UNIX, but required on NT (see kNtFileFlagBackupSemantics)
syscon open O_DIRECT 0x00004000 0 0x00010000 0 0x00080000 0x00200000 # kNtFileFlagNoBuffering>>8
syscon open O_CLOEXEC 0x00080000 0x01000000 0x00100000 0x00010000 0x00400000 0x00080000 # NT faked as Linux
syscon open O_TMPFILE 0x00410000 0 0 0 0 0x04000100 # Linux 3.11+ (c. 2013) & kNtFileAttributeTemporary|kNtFileFlagDeleteOnClose

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon sig,SIGEMT,0,7,7,7,7,0

View file

@ -2,7 +2,9 @@
#define COSMOPOLITAN_LIBC_SYSV_CONSTS_GRND_H_
#include "libc/runtime/symbolic.h"
#define GRND_NONBLOCK LITERALLY(1)
#define GRND_RANDOM LITERALLY(2)
#define GRND_NONBLOCK 1
#define GRND_RANDOM 2
#define GRND_NORDRND 64
#define GRND_NOSYSTEM 128
#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_GRND_H_ */

View file

@ -41,6 +41,7 @@ extern const long SIGVTALRM;
extern const long SIGWINCH;
extern const long SIGXCPU;
extern const long SIGXFSZ;
extern const long SIGEMT;
extern const long SIG_ATOMIC_MIN;
extern const long SIG_BLOCK;
@ -50,47 +51,48 @@ extern const long SIG_UNBLOCK;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#define SIGABRT LITERALLY(6)
#define SIGALRM LITERALLY(14)
#define SIGBUS SYMBOLIC(SIGBUS)
#define SIGCHLD SYMBOLIC(SIGCHLD)
#define SIGCONT SYMBOLIC(SIGCONT)
#define SIGFPE LITERALLY(8)
#define SIGHUP LITERALLY(1)
#define SIGILL LITERALLY(4)
#define SIGINT LITERALLY(2)
#define SIGIO SYMBOLIC(SIGIO)
#define SIGIOT LITERALLY(6)
#define SIGKILL LITERALLY(9)
#define SIGPIPE LITERALLY(13)
#define SIGPOLL SYMBOLIC(SIGPOLL)
#define SIGPROF LITERALLY(27)
#define SIGPWR SYMBOLIC(SIGPWR)
#define SIGQUIT LITERALLY(3)
#define SIGRTMAX SYMBOLIC(SIGRTMAX)
#define SIGRTMIN SYMBOLIC(SIGRTMIN)
#define SIGSEGV LITERALLY(11)
#define SIGABRT LITERALLY(6)
#define SIGALRM LITERALLY(14)
#define SIGBUS SYMBOLIC(SIGBUS)
#define SIGCHLD SYMBOLIC(SIGCHLD)
#define SIGCONT SYMBOLIC(SIGCONT)
#define SIGFPE LITERALLY(8)
#define SIGHUP LITERALLY(1)
#define SIGILL LITERALLY(4)
#define SIGINT LITERALLY(2)
#define SIGIO SYMBOLIC(SIGIO)
#define SIGIOT LITERALLY(6)
#define SIGKILL LITERALLY(9)
#define SIGPIPE LITERALLY(13)
#define SIGPOLL SYMBOLIC(SIGPOLL)
#define SIGPROF LITERALLY(27)
#define SIGPWR SYMBOLIC(SIGPWR)
#define SIGQUIT LITERALLY(3)
#define SIGRTMAX SYMBOLIC(SIGRTMAX)
#define SIGRTMIN SYMBOLIC(SIGRTMIN)
#define SIGSEGV LITERALLY(11)
#define SIGSTKFLT SYMBOLIC(SIGSTKFLT)
#define SIGSTKSZ SYMBOLIC(SIGSTKSZ)
#define SIGSTOP SYMBOLIC(SIGSTOP)
#define SIGSYS SYMBOLIC(SIGSYS)
#define SIGTERM LITERALLY(15)
#define SIGTRAP LITERALLY(5)
#define SIGTSTP SYMBOLIC(SIGTSTP)
#define SIGTTIN LITERALLY(21)
#define SIGTTOU LITERALLY(22)
#define SIGSTKSZ SYMBOLIC(SIGSTKSZ)
#define SIGSTOP SYMBOLIC(SIGSTOP)
#define SIGSYS SYMBOLIC(SIGSYS)
#define SIGTERM LITERALLY(15)
#define SIGTRAP LITERALLY(5)
#define SIGTSTP SYMBOLIC(SIGTSTP)
#define SIGTTIN LITERALLY(21)
#define SIGTTOU LITERALLY(22)
#define SIGUNUSED SYMBOLIC(SIGUNUSED)
#define SIGURG SYMBOLIC(SIGURG)
#define SIGUSR1 SYMBOLIC(SIGUSR1)
#define SIGUSR2 SYMBOLIC(SIGUSR2)
#define SIGURG SYMBOLIC(SIGURG)
#define SIGUSR1 SYMBOLIC(SIGUSR1)
#define SIGUSR2 SYMBOLIC(SIGUSR2)
#define SIGVTALRM LITERALLY(26)
#define SIGWINCH LITERALLY(28)
#define SIGXCPU LITERALLY(24)
#define SIGXFSZ LITERALLY(25)
#define SIGWINCH LITERALLY(28)
#define SIGXCPU LITERALLY(24)
#define SIGXFSZ LITERALLY(25)
#define SIGEMT SYMBOLIC(SIGEMT)
#define SIG_ATOMIC_MIN SYMBOLIC(SIG_ATOMIC_MIN)
#define SIG_BLOCK SYMBOLIC(SIG_BLOCK)
#define SIG_SETMASK SYMBOLIC(SIG_SETMASK)
#define SIG_UNBLOCK SYMBOLIC(SIG_UNBLOCK)
#define SIG_BLOCK SYMBOLIC(SIG_BLOCK)
#define SIG_SETMASK SYMBOLIC(SIG_SETMASK)
#define SIG_UNBLOCK SYMBOLIC(SIG_UNBLOCK)
#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_SIG_H_ */

View file

@ -349,7 +349,7 @@ scall sched_setattr 0xfffffffffffff13a globl # ├─ desktop replaced with ta
scall sched_getattr 0xfffffffffffff13b globl # ├─ karen sandler requires systemd init and boot for tablet gui
scall renameat2 0xfffffffffffff13c globl # └─ debian founder ian murdock found strangled with vacuum cord
scall seccomp 0xfffffffffffff13d globl
scall sys_getrandom 0x05b00723321f413e globl hidden # Linux 3.17+ and getentropy() on XNU/OpenBSD
scall sys_getrandom 0xfff00723321f413e globl hidden # Linux 3.17+ and getentropy() on XNU/OpenBSD, coming to NetBSD in 9.2
scall memfd_create 0xfffffffffffff13f globl # wut
scall kexec_file_load 0xfffffffffffff140 globl
scall bpf 0xfffffffffffff141 globl