Add SNI support to redbean and improve SSL perf

This change makes SSL virtual hosting possible. You can now load
multiple certificates for multiple domains and redbean will just
figure out which one to use, even if you only have 1 ip address.
You can also use a jumbo certificate that lists all your domains
in the the subject alternative names.

This change also makes performance improvements to MbedTLS. Here
are some benchmarks vs. cc1920749e

                                   BEFORE    AFTER   (microsecs)
suite_ssl.com                     2512881   191738 13.11x faster
suite_pkparse.com                   36291     3295 11.01x faster
suite_x509parse.com                854669   120293  7.10x faster
suite_pkwrite.com                    6549     1265  5.18x faster
suite_ecdsa.com                     53347    18778  2.84x faster
suite_pk.com                        49051    18717  2.62x faster
suite_ecdh.com                      19535     9502  2.06x faster
suite_shax.com                      15848     7965  1.99x faster
suite_rsa.com                      353257   184828  1.91x faster
suite_x509write.com                162646    85733  1.90x faster
suite_ecp.com                       20503    11050  1.86x faster
suite_hmac_drbg.no_reseed.com       19528    11417  1.71x faster
suite_hmac_drbg.nopr.com            12460     8010  1.56x faster
suite_mpi.com                      687124   442661  1.55x faster
suite_hmac_drbg.pr.com              11890     7752  1.53x faster

There aren't any special tricks to the performance imporvements.
It's mostly due to code cleanup, assembly and intel instructions
like mulx, adox, and adcx.
This commit is contained in:
Justine Tunney 2021-07-19 14:55:20 -07:00
parent f3e28aa192
commit 398f0c16fb
190 changed files with 14367 additions and 8928 deletions

View file

@ -0,0 +1,72 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2021 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/testlib/testlib.h"
#include "third_party/mbedtls/config.h"
#include "third_party/mbedtls/ssl_ciphersuites.h"
int GetCipherId(const char *s) {
const mbedtls_ssl_ciphersuite_t *c;
if ((c = GetCipherSuite(s))) {
return c->id;
} else {
return -1;
}
}
#ifdef MBEDTLS_CIPHER_MODE_CBC
TEST(GetCipherSuite, theOlde) {
EXPECT_EQ(0x002F, GetCipherId("RSA-AES128-CBC-SHA")); // Cosmo
EXPECT_EQ(0x002F, GetCipherId("TLS_RSA_AES_128_CBC_SHA1")); // GnuTLS
EXPECT_EQ(0x002F, GetCipherId("TLS_RSA_WITH_AES_128_CBC_SHA")); // IANA
// EXPECT_EQ(0x002F, GetCipherId("AES128-SHA")); // OpenSSL
}
#endif
#ifdef MBEDTLS_DES_C
TEST(GetCipherSuite, theAncient) {
EXPECT_EQ(0x000A, GetCipherId("RSA-3DES-EDE-CBC-SHA")); // Cosmo
EXPECT_EQ(0x000A, GetCipherId("TLS_RSA_3DES_EDE_CBC_SHA1")); // GnuTLS
EXPECT_EQ(0x000A, GetCipherId("TLS_RSA_WITH_3DES_EDE_CBC_SHA")); // IANA
// EXPECT_EQ(0x000A, GetCipherId("DES-CBC3-SHA"));
}
#endif
#ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
TEST(GetCipherSuite, theUltimo) {
EXPECT_EQ(0xC02C, GetCipherId("ECDHE-ECDSA-AES256-GCM-SHA384"));
EXPECT_EQ(0xC02C, GetCipherId("ECDHE-ECDSA-WITH-AES-256-GCM-SHA384"));
EXPECT_EQ(0xC02C, GetCipherId("TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384"));
EXPECT_EQ(0xC02C, GetCipherId("TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"));
}
#endif
#ifdef MBEDTLS_CHACHAPOLY_C
TEST(GetCipherSuite, arcfourReborn) {
EXPECT_EQ(0xCCA8, GetCipherId("ECDHE-RSA-CHACHA20-POLY1305-SHA256"));
EXPECT_EQ(0xCCA8, GetCipherId("TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256"));
// EXPECT_EQ(0xCCA8, GetCipherId("TLS_ECDHE_RSA_CHACHA20_POLY1305"));
// EXPECT_EQ(0xCCA8, GetCipherId("ECDHE-RSA-CHACHA20-POLY1305"));
}
#endif
TEST(GetCipherSuite, forTheeNotForMe) {
EXPECT_EQ(0x0004, GetCipherId("RSA-RC4-128-MD5")); // Cosmo
EXPECT_EQ(0x0004, GetCipherId("TLS_RSA_WITH_RC4_128_MD5")); // IANA
// EXPECT_EQ(0x0004, GetCipherId("TLS_RSA_ARCFOUR_128_MD5"));
}

File diff suppressed because it is too large Load diff

46
test/net/https/test.mk Normal file
View file

@ -0,0 +1,46 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
PKGS += TEST_NET_HTTPS
TEST_NET_HTTPS_SRCS := $(wildcard test/net/https/*.c)
TEST_NET_HTTPS_SRCS_TEST = $(filter %_test.c,$(TEST_NET_HTTPS_SRCS))
TEST_NET_HTTPS_BINS = $(TEST_NET_HTTPS_COMS) $(TEST_NET_HTTPS_COMS:%=%.dbg)
TEST_NET_HTTPS_OBJS = \
$(TEST_NET_HTTPS_SRCS:%.c=o/$(MODE)/%.o)
TEST_NET_HTTPS_COMS = \
$(TEST_NET_HTTPS_SRCS:%.c=o/$(MODE)/%.com)
TEST_NET_HTTPS_TESTS = \
$(TEST_NET_HTTPS_SRCS_TEST:%.c=o/$(MODE)/%.com.ok)
TEST_NET_HTTPS_CHECKS = \
$(TEST_NET_HTTPS_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
TEST_NET_HTTPS_DIRECTDEPS = \
NET_HTTPS \
LIBC_LOG \
LIBC_TESTLIB \
THIRD_PARTY_MBEDTLS
TEST_NET_HTTPS_DEPS := \
$(call uniq,$(foreach x,$(TEST_NET_HTTPS_DIRECTDEPS),$($(x))))
o/$(MODE)/test/net/https/https.pkg: \
$(TEST_NET_HTTPS_OBJS) \
$(foreach x,$(TEST_NET_HTTPS_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/test/net/https/%.com.dbg: \
$(TEST_NET_HTTPS_DEPS) \
o/$(MODE)/test/net/https/%.o \
$(LIBC_TESTMAIN) \
$(CRT) \
$(APE)
@$(APELINK)
.PHONY: o/$(MODE)/test/net/https
o/$(MODE)/test/net/https: \
$(TEST_NET_HTTPS_BINS) \
$(TEST_NET_HTTPS_CHECKS)