mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 06:48:31 +00:00
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:
parent
1beeb7a829
commit
cc1920749e
1032 changed files with 152673 additions and 69310 deletions
|
@ -23,27 +23,70 @@
|
|||
/**
|
||||
* Formats internet address to string.
|
||||
*
|
||||
* @param af can be AF_INET
|
||||
* @param af can be AF_INET or AF_INET6
|
||||
* @param src is the binary-encoded address, e.g. &addr->sin_addr
|
||||
* @param dst is the output string buffer
|
||||
* @param size is bytes in dst, which needs 16+ for IPv4
|
||||
* @param size needs to be 16+ for IPv4 and 72+ for IPv6
|
||||
* @return dst on success or NULL w/ errno
|
||||
*/
|
||||
const char *inet_ntop(int af, const void *src, char *dst, uint32_t size) {
|
||||
char *p;
|
||||
unsigned char *ip4;
|
||||
if (src) {
|
||||
unsigned char *ip;
|
||||
int i, t, a, b, c, d;
|
||||
p = dst;
|
||||
if ((ip = src)) {
|
||||
if (af == AF_INET) {
|
||||
if (size >= 16) {
|
||||
p = dst;
|
||||
ip4 = src;
|
||||
p += uint64toarray_radix10(ip4[0], p);
|
||||
p += uint64toarray_radix10(ip[0], p);
|
||||
*p++ = '.';
|
||||
p += uint64toarray_radix10(ip4[1], p);
|
||||
p += uint64toarray_radix10(ip[1], p);
|
||||
*p++ = '.';
|
||||
p += uint64toarray_radix10(ip4[2], p);
|
||||
p += uint64toarray_radix10(ip[2], p);
|
||||
*p++ = '.';
|
||||
p += uint64toarray_radix10(ip4[3], p);
|
||||
p += uint64toarray_radix10(ip[3], p);
|
||||
*p = '\0';
|
||||
return dst;
|
||||
} else {
|
||||
enospc();
|
||||
}
|
||||
} else if (af == AF_INET6) {
|
||||
if (size >= 16 * 4 + 8) {
|
||||
t = 0;
|
||||
i = 0;
|
||||
for (i = 0; i < 16; i += 2) {
|
||||
switch (t) {
|
||||
case 0:
|
||||
if (!ip[i] && !ip[i + 1]) {
|
||||
t = 1;
|
||||
*p++ = ':';
|
||||
*p++ = ':';
|
||||
continue;
|
||||
} else if (i) {
|
||||
*p++ = ':';
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (!ip[i] && !ip[i + 1]) {
|
||||
continue;
|
||||
} else {
|
||||
t = 2;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
*p++ = ':';
|
||||
break;
|
||||
default:
|
||||
unreachable;
|
||||
}
|
||||
a = (ip[i + 0] & 0xF0) >> 4;
|
||||
b = (ip[i + 0] & 0x0F) >> 0;
|
||||
c = (ip[i + 1] & 0xF0) >> 4;
|
||||
d = (ip[i + 1] & 0x0F) >> 0;
|
||||
if (a) *p++ = "0123456789abcdef"[a];
|
||||
if (a || b) *p++ = "0123456789abcdef"[b];
|
||||
if (a || b || c) *p++ = "0123456789abcdef"[c];
|
||||
*p++ = "0123456789abcdef"[d];
|
||||
}
|
||||
*p = '\0';
|
||||
return dst;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue