diff --git a/.vscode/settings.json b/.vscode/settings.json index 6c0c0fa81a..63ae2ca943 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -240,7 +240,9 @@ "xutility": "cpp", "string.h": "c", "zutil.h": "c", - "gzguts.h": "c" + "gzguts.h": "c", + "stdatomic.h": "c", + "root_certs.h": "c" }, "C_Cpp.errorSquiggles": "enabled", "eslint.workingDirectories": ["packages/bun-types"], diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ac8a08043..87a19e8022 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,7 +163,6 @@ endif() # --- Dependencies --- if(NOT WIN32) - message(STATUS "not window") # WebKit if(NOT WEBKIT_DIR) # TODO: allow this to point to the actual webkit cmake file to allow easier rebuilds @@ -454,6 +453,12 @@ add_custom_command( USES_TERMINAL ) +set(BUN_EXTRA_SOURCES "") +if(WIN32) + set(BUN_EXTRA_SOURCES "${BUN_SRC}/bun.js/bindings/windows/musl-memmem.c") + include_directories("${BUN_SRC}/bun.js/bindings/windows") +endif() + # -- The Buntime™️ --- add_executable( ${bun} @@ -465,6 +470,7 @@ add_executable( "${BUN_WORKDIR}/codegen/ZigGeneratedClasses.cpp" "${BUN_WORKDIR}/codegen/WebCoreJSBuiltins.cpp" "${BUN_ZIG_OBJ}" + "${BUN_EXTRA_SOURCES}" ) set_target_properties(${bun} PROPERTIES CXX_STANDARD 20 @@ -828,8 +834,8 @@ if(NOT MSVC) target_link_libraries(${bun} PRIVATE "${WEBKIT_DIR}/lib/libJavaScriptCore.a") target_link_libraries(${bun} PRIVATE "${WEBKIT_DIR}/lib/libbmalloc.a") else() - target_link_libraries(${bun} PRIVATE "${WEBKIT_LIB_DIR}/lib/WTF.lib") - target_link_libraries(${bun} PRIVATE "${WEBKIT_LIB_DIR}/lib/JavaScriptCore.lib") + target_link_libraries(${bun} PRIVATE "${WEBKIT_LIB_DIR}/WTF.lib") + target_link_libraries(${bun} PRIVATE "${WEBKIT_LIB_DIR}/JavaScriptCore.lib") if (WIN32) string (APPEND CMAKE_CXX_FLAGS @@ -849,11 +855,16 @@ else() # include_directories(C:/Users/windo/Build/WebKit/WebKitBuild/WTF/Headers) file(COPY C:/Users/windo/Code/WebKit/WebKitBuild/cmakeconfig.h DESTINATION ${BUN_SRC}/bun.js/bindings) - include_directories(C:/Users/windo/Code/WebKit/WebKitLibraries/win/include) - link_directories(C:/Users/windo/Code/WebKit/WebKitLibraries/win/lib64) - target_link_directories(${bun} PUBLIC ${ICU_LIBRARY}) - + target_include_directories(${bun} PUBLIC C:/Users/windo/Code/WebKit/WebKitLibraries/win/include) + target_link_directories(${bun} PUBLIC C:/Users/windo/Code/WebKit/WebKitLibraries/win/lib64) + target_link_directories(${bun} PUBLIC C:/Users/windo/Code/lib64) + # icudt.lib + # icuin.lib + # icuio.lib + # icutest.lib + # icutu.lib + # icuuc.lib target_link_libraries(${bun} PUBLIC icuuc icudt icutu icuio icuin icutest) target_link_libraries(${bun} PUBLIC winmm ws2_32 bcrypt ntdll kernel32 shell32 shlwapi advapi32 vcruntime ucrt legacy_stdio_definitions) endif() diff --git a/packages/bun-usockets/src/crypto/openssl.c b/packages/bun-usockets/src/crypto/openssl.c index a4c5a5c8ef..9819c90d42 100644 --- a/packages/bun-usockets/src/crypto/openssl.c +++ b/packages/bun-usockets/src/crypto/openssl.c @@ -18,37 +18,37 @@ #if (defined(LIBUS_USE_OPENSSL) || defined(LIBUS_USE_WOLFSSL)) /* These are in sni_tree.cpp */ -void *sni_new(); -void sni_free(void *sni, void(*cb)(void *)); -int sni_add(void *sni, const char *hostname, void *user); -void *sni_remove(void *sni, const char *hostname); -void *sni_find(void *sni, const char *hostname); +void* sni_new(); +void sni_free(void* sni, void (*cb)(void*)); +int sni_add(void* sni, const char* hostname, void* user); +void* sni_remove(void* sni, const char* hostname); +void* sni_find(void* sni, const char* hostname); -#include "libusockets.h" #include "internal/internal.h" +#include "libusockets.h" #include /* This module contains the entire OpenSSL implementation * of the SSL socket and socket context interfaces. */ #ifdef LIBUS_USE_OPENSSL -#include #include -#include #include +#include +#include #elif LIBUS_USE_WOLFSSL -#include -#include #include -#include #include +#include +#include +#include #endif #include "./root_certs.h" -#include +// #include static const size_t root_certs_size = sizeof(root_certs) / sizeof(root_certs[0]); -static X509* root_cert_instances[root_certs_size] = {NULL}; -static atomic_flag root_cert_instances_lock = ATOMIC_FLAG_INIT; -static atomic_bool root_cert_instances_initialized = 0; +static X509* root_cert_instances[1] = { NULL }; +// static atomic_flag root_cert_instances_lock = ATOMIC_FLAG_INIT; +// static atomic_bool root_cert_instances_initialized = 0; /* These are in root_certs.cpp */ extern X509_STORE* us_get_default_ca_store(); @@ -58,14 +58,14 @@ struct loop_ssl_data { unsigned int ssl_read_input_length; unsigned int ssl_read_input_offset; - struct us_socket_t *ssl_socket; + struct us_socket_t* ssl_socket; int last_write_was_msg_more; int msg_more; - BIO *shared_rbio; - BIO *shared_wbio; - BIO_METHOD *shared_biom; + BIO* shared_rbio; + BIO* shared_wbio; + BIO_METHOD* shared_biom; }; struct us_internal_ssl_socket_context_t { @@ -74,20 +74,20 @@ struct us_internal_ssl_socket_context_t { // this thing can be shared with other socket contexts via socket transfer! // maybe instead of holding once you hold many, a vector or set // when a socket that belongs to another socket context transfers to a new socket context - SSL_CTX *ssl_context; + SSL_CTX* ssl_context; int is_parent; /* These decorate the base implementation */ - struct us_internal_ssl_socket_t *(*on_open)(struct us_internal_ssl_socket_t *, int is_client, char *ip, int ip_length); - struct us_internal_ssl_socket_t *(*on_data)(struct us_internal_ssl_socket_t *, char *data, int length); - struct us_internal_ssl_socket_t *(*on_writable)(struct us_internal_ssl_socket_t *); - struct us_internal_ssl_socket_t *(*on_close)(struct us_internal_ssl_socket_t *, int code, void *reason); + struct us_internal_ssl_socket_t* (*on_open)(struct us_internal_ssl_socket_t*, int is_client, char* ip, int ip_length); + struct us_internal_ssl_socket_t* (*on_data)(struct us_internal_ssl_socket_t*, char* data, int length); + struct us_internal_ssl_socket_t* (*on_writable)(struct us_internal_ssl_socket_t*); + struct us_internal_ssl_socket_t* (*on_close)(struct us_internal_ssl_socket_t*, int code, void* reason); /* Called for missing SNI hostnames, if not NULL */ - void (*on_server_name)(struct us_internal_ssl_socket_context_t *, const char *hostname); + void (*on_server_name)(struct us_internal_ssl_socket_context_t*, const char* hostname); /* Pointer to sni tree, created when the context is created and freed likewise when freed */ - void *sni; + void* sni; us_internal_on_handshake_t on_handshake; void* handshake_data; @@ -96,27 +96,30 @@ struct us_internal_ssl_socket_context_t { // same here, should or shouldn't it contain s? struct us_internal_ssl_socket_t { struct us_socket_t s; - SSL *ssl; + SSL* ssl; int ssl_write_wants_read; // we use this for now int ssl_read_wants_write; int pending_handshake; }; -int passphrase_cb(char *buf, int size, int rwflag, void *u) { - const char *passphrase = (const char *) u; +int passphrase_cb(char* buf, int size, int rwflag, void* u) +{ + const char* passphrase = (const char*)u; size_t passphrase_length = strlen(passphrase); memcpy(buf, passphrase, passphrase_length); // put null at end? no? - return (int) passphrase_length; + return (int)passphrase_length; } -int BIO_s_custom_create(BIO *bio) { +int BIO_s_custom_create(BIO* bio) +{ BIO_set_init(bio, 1); return 1; } -long BIO_s_custom_ctrl(BIO *bio, int cmd, long num, void *user) { - switch(cmd) { +long BIO_s_custom_ctrl(BIO* bio, int cmd, long num, void* user) +{ + switch (cmd) { case BIO_CTRL_FLUSH: return 1; default: @@ -124,10 +127,9 @@ long BIO_s_custom_ctrl(BIO *bio, int cmd, long num, void *user) { } } - - -int BIO_s_custom_write(BIO *bio, const char *data, int length) { - struct loop_ssl_data *loop_ssl_data = (struct loop_ssl_data *) BIO_get_data(bio); +int BIO_s_custom_write(BIO* bio, const char* data, int length) +{ + struct loop_ssl_data* loop_ssl_data = (struct loop_ssl_data*)BIO_get_data(bio); loop_ssl_data->last_write_was_msg_more = loop_ssl_data->msg_more || length == 16413; int written = us_socket_write(0, loop_ssl_data->ssl_socket, data, length, loop_ssl_data->last_write_was_msg_more); @@ -142,17 +144,18 @@ int BIO_s_custom_write(BIO *bio, const char *data, int length) { return written; } -int BIO_s_custom_read(BIO *bio, char *dst, int length) { - struct loop_ssl_data *loop_ssl_data = (struct loop_ssl_data *) BIO_get_data(bio); +int BIO_s_custom_read(BIO* bio, char* dst, int length) +{ + struct loop_ssl_data* loop_ssl_data = (struct loop_ssl_data*)BIO_get_data(bio); - //printf("BIO_s_custom_read\n"); + // printf("BIO_s_custom_read\n"); if (!loop_ssl_data->ssl_read_input_length) { BIO_set_flags(bio, BIO_FLAGS_SHOULD_RETRY | BIO_FLAGS_READ); return -1; } - if ((unsigned int) length > loop_ssl_data->ssl_read_input_length) { + if ((unsigned int)length > loop_ssl_data->ssl_read_input_length) { length = loop_ssl_data->ssl_read_input_length; } @@ -163,14 +166,13 @@ int BIO_s_custom_read(BIO *bio, char *dst, int length) { return length; } +struct us_internal_ssl_socket_t* ssl_on_open(struct us_internal_ssl_socket_t* s, int is_client, char* ip, int ip_length) +{ -struct us_internal_ssl_socket_t *ssl_on_open(struct us_internal_ssl_socket_t *s, int is_client, char *ip, int ip_length) { + struct us_internal_ssl_socket_context_t* context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); - struct us_internal_ssl_socket_context_t *context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); - - - struct us_loop_t *loop = us_socket_context_loop(0, &context->sc); - struct loop_ssl_data *loop_ssl_data = (struct loop_ssl_data *) loop->data.ssl_data; + struct us_loop_t* loop = us_socket_context_loop(0, &context->sc); + struct loop_ssl_data* loop_ssl_data = (struct loop_ssl_data*)loop->data.ssl_data; s->ssl = SSL_new(context->ssl_context); s->ssl_write_wants_read = 0; @@ -187,52 +189,52 @@ struct us_internal_ssl_socket_t *ssl_on_open(struct us_internal_ssl_socket_t *s, SSL_set_accept_state(s->ssl); } - struct us_internal_ssl_socket_t * result = (struct us_internal_ssl_socket_t *) context->on_open(s, is_client, ip, ip_length); + struct us_internal_ssl_socket_t* result = (struct us_internal_ssl_socket_t*)context->on_open(s, is_client, ip, ip_length); // Hello Message! // always handshake after open if on_handshake is set - if(context->on_handshake || s->pending_handshake) { + if (context->on_handshake || s->pending_handshake) { s->pending_handshake = 1; us_internal_ssl_handshake(s, context->on_handshake, context->handshake_data); } - + return result; } - -void us_internal_on_ssl_handshake(struct us_internal_ssl_socket_context_t * context, void (*on_handshake)(struct us_internal_ssl_socket_t *, int success, struct us_bun_verify_error_t verify_error, void* custom_data), void* custom_data) { +void us_internal_on_ssl_handshake(struct us_internal_ssl_socket_context_t* context, void (*on_handshake)(struct us_internal_ssl_socket_t*, int success, struct us_bun_verify_error_t verify_error, void* custom_data), void* custom_data) +{ context->on_handshake = on_handshake; context->handshake_data = custom_data; } -void us_internal_ssl_handshake(struct us_internal_ssl_socket_t *s, us_internal_on_handshake_t on_handshake, void* custom_data) { - struct us_internal_ssl_socket_context_t *context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); - +void us_internal_ssl_handshake(struct us_internal_ssl_socket_t* s, us_internal_on_handshake_t on_handshake, void* custom_data) +{ + struct us_internal_ssl_socket_context_t* context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); + // will start on_open, on_writable or on_data - if(!s->ssl) { - + if (!s->ssl) { + s->pending_handshake = 1; context->on_handshake = on_handshake; context->handshake_data = custom_data; return; } - struct us_loop_t *loop = us_socket_context_loop(0, &context->sc); - struct loop_ssl_data *loop_ssl_data = (struct loop_ssl_data *) loop->data.ssl_data; + struct us_loop_t* loop = us_socket_context_loop(0, &context->sc); + struct loop_ssl_data* loop_ssl_data = (struct loop_ssl_data*)loop->data.ssl_data; loop_ssl_data->ssl_socket = &s->s; - if (us_socket_is_closed(0, &s->s) || us_internal_ssl_socket_is_shut_down(s)) { + if (us_socket_is_closed(0, &s->s) || us_internal_ssl_socket_is_shut_down(s)) { s->pending_handshake = 0; - + struct us_bun_verify_error_t verify_error = (struct us_bun_verify_error_t) { .error = 0, .code = NULL, .reason = NULL }; - if(on_handshake != NULL) { + if (on_handshake != NULL) { on_handshake(s, 0, verify_error, custom_data); } return; } - int result = SSL_do_handshake(s->ssl); if (result <= 0) { @@ -240,7 +242,7 @@ void us_internal_ssl_handshake(struct us_internal_ssl_socket_t *s, us_internal_o // as far as I know these are the only errors we want to handle if (err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE) { s->pending_handshake = 0; - + struct us_bun_verify_error_t verify_error = us_internal_verify_error(s); // clear per thread error queue if it may contain something if (err == SSL_ERROR_SSL || err == SSL_ERROR_SYSCALL) { @@ -248,7 +250,7 @@ void us_internal_ssl_handshake(struct us_internal_ssl_socket_t *s, us_internal_o } // error - if(on_handshake != NULL) { + if (on_handshake != NULL) { on_handshake(s, 0, verify_error, custom_data); } return; @@ -260,14 +262,13 @@ void us_internal_ssl_handshake(struct us_internal_ssl_socket_t *s, us_internal_o if (!us_socket_is_closed(0, &s->s) && !us_internal_ssl_socket_is_shut_down(s)) { us_socket_write(1, loop_ssl_data->ssl_socket, "\0", 0, 0); } - } } else { s->pending_handshake = 0; struct us_bun_verify_error_t verify_error = us_internal_verify_error(s); // success - if(on_handshake != NULL) { + if (on_handshake != NULL) { on_handshake(s, 1, verify_error, custom_data); } // Ensure that we'll cycle through internal openssl's state @@ -275,20 +276,20 @@ void us_internal_ssl_handshake(struct us_internal_ssl_socket_t *s, us_internal_o us_socket_write(1, loop_ssl_data->ssl_socket, "\0", 0, 0); } } - } - -struct us_internal_ssl_socket_t *us_internal_ssl_socket_close(struct us_internal_ssl_socket_t *s, int code, void *reason) { - struct us_internal_ssl_socket_context_t *context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); +struct us_internal_ssl_socket_t* us_internal_ssl_socket_close(struct us_internal_ssl_socket_t* s, int code, void* reason) +{ + struct us_internal_ssl_socket_context_t* context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); if (s->pending_handshake) { s->pending_handshake = 0; } - return (struct us_internal_ssl_socket_t *) us_socket_close(0, (struct us_socket_t *) s, code, reason); + return (struct us_internal_ssl_socket_t*)us_socket_close(0, (struct us_socket_t*)s, code, reason); } -struct us_internal_ssl_socket_t *ssl_on_close(struct us_internal_ssl_socket_t *s, int code, void *reason) { - struct us_internal_ssl_socket_context_t *context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); +struct us_internal_ssl_socket_t* ssl_on_close(struct us_internal_ssl_socket_t* s, int code, void* reason) +{ + struct us_internal_ssl_socket_context_t* context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); if (s->pending_handshake) { s->pending_handshake = 0; } @@ -297,7 +298,8 @@ struct us_internal_ssl_socket_t *ssl_on_close(struct us_internal_ssl_socket_t *s return context->on_close(s, code, reason); } -struct us_internal_ssl_socket_t *ssl_on_end(struct us_internal_ssl_socket_t *s) { +struct us_internal_ssl_socket_t* ssl_on_end(struct us_internal_ssl_socket_t* s) +{ if (s && s->pending_handshake) { s->pending_handshake = 0; } @@ -308,20 +310,20 @@ struct us_internal_ssl_socket_t *ssl_on_end(struct us_internal_ssl_socket_t *s) } // this whole function needs a complete clean-up -struct us_internal_ssl_socket_t *ssl_on_data(struct us_internal_ssl_socket_t *s, void *data, int length) { +struct us_internal_ssl_socket_t* ssl_on_data(struct us_internal_ssl_socket_t* s, void* data, int length) +{ // note: this context can change when we adopt the socket! - struct us_internal_ssl_socket_context_t *context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); + struct us_internal_ssl_socket_context_t* context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); + struct us_loop_t* loop = us_socket_context_loop(0, &context->sc); + struct loop_ssl_data* loop_ssl_data = (struct loop_ssl_data*)loop->data.ssl_data; - struct us_loop_t *loop = us_socket_context_loop(0, &context->sc); - struct loop_ssl_data *loop_ssl_data = (struct loop_ssl_data *) loop->data.ssl_data; - - if(s->pending_handshake) { + if (s->pending_handshake) { us_internal_ssl_handshake(s, context->on_handshake, context->handshake_data); } - // note: if we put data here we should never really clear it (not in write either, it still should be available for SSL_write to read from!) + // note: if we put data here we should never really clear it (not in write either, it still should be available for SSL_write to read from!) loop_ssl_data->ssl_read_input = data; loop_ssl_data->ssl_read_input_length = length; loop_ssl_data->ssl_read_input_offset = 0; @@ -333,12 +335,11 @@ struct us_internal_ssl_socket_t *ssl_on_data(struct us_internal_ssl_socket_t *s, } if (us_internal_ssl_socket_is_shut_down(s)) { - int ret = 0; if ((ret = SSL_shutdown(s->ssl)) == 1) { // two phase shutdown is complete here - //printf("Two step SSL shutdown complete\n"); + // printf("Two step SSL shutdown complete\n"); /* Todo: this should also report some kind of clean shutdown */ return us_internal_ssl_socket_close(s, 0, NULL); @@ -350,7 +351,6 @@ struct us_internal_ssl_socket_t *ssl_on_data(struct us_internal_ssl_socket_t *s, // we need to clear the error queue in case these added to the thread local queue ERR_clear_error(); } - } // no further processing of data when in shutdown state @@ -359,7 +359,7 @@ struct us_internal_ssl_socket_t *ssl_on_data(struct us_internal_ssl_socket_t *s, // bug checking: this loop needs a lot of attention and clean-ups and check-ups int read = 0; - restart: +restart: while (1) { int just_read = SSL_read(s->ssl, loop_ssl_data->ssl_read_output + LIBUS_RECV_BUFFER_PADDING + read, LIBUS_RECV_BUFFER_LENGTH - read); @@ -372,7 +372,7 @@ struct us_internal_ssl_socket_t *ssl_on_data(struct us_internal_ssl_socket_t *s, if (err == SSL_ERROR_ZERO_RETURN) { // zero return can be EOF/FIN, if we have data just signal on_data and close if (read) { - context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); + context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); s = context->on_data(s, loop_ssl_data->ssl_read_output + LIBUS_RECV_BUFFER_PADDING, read); if (us_socket_is_closed(0, &s->s)) { @@ -382,10 +382,10 @@ struct us_internal_ssl_socket_t *ssl_on_data(struct us_internal_ssl_socket_t *s, // terminate connection here return us_internal_ssl_socket_close(s, 0, NULL); } - + if (err == SSL_ERROR_SSL || err == SSL_ERROR_SYSCALL) { // clear per thread error queue if it may contain something - + ERR_clear_error(); } @@ -409,7 +409,7 @@ struct us_internal_ssl_socket_t *ssl_on_data(struct us_internal_ssl_socket_t *s, break; } - context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); + context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); s = context->on_data(s, loop_ssl_data->ssl_read_output + LIBUS_RECV_BUFFER_PADDING, read); if (us_socket_is_closed(0, &s->s)) { @@ -418,7 +418,6 @@ struct us_internal_ssl_socket_t *ssl_on_data(struct us_internal_ssl_socket_t *s, break; } - } read += just_read; @@ -426,7 +425,7 @@ struct us_internal_ssl_socket_t *ssl_on_data(struct us_internal_ssl_socket_t *s, // at this point we might be full and need to emit the data to application and start over if (read == LIBUS_RECV_BUFFER_LENGTH) { - context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); + context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); // emit data and restart s = context->on_data(s, loop_ssl_data->ssl_read_output + LIBUS_RECV_BUFFER_PADDING, read); @@ -444,9 +443,9 @@ struct us_internal_ssl_socket_t *ssl_on_data(struct us_internal_ssl_socket_t *s, s->ssl_write_wants_read = 0; // make sure to update context before we call (context can change if the user adopts the socket!) - context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); + context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); - s = (struct us_internal_ssl_socket_t *) context->sc.on_writable(&s->s); // cast here! + s = (struct us_internal_ssl_socket_t*)context->sc.on_writable(&s->s); // cast here! // if we are closed here, then exit if (us_socket_is_closed(0, &s->s)) { return s; @@ -455,36 +454,37 @@ struct us_internal_ssl_socket_t *ssl_on_data(struct us_internal_ssl_socket_t *s, // check this then? if (SSL_get_shutdown(s->ssl) & SSL_RECEIVED_SHUTDOWN) { - //printf("SSL_RECEIVED_SHUTDOWN\n"); + // printf("SSL_RECEIVED_SHUTDOWN\n"); - //exit(-2); + // exit(-2); // not correct anyways! s = us_internal_ssl_socket_close(s, 0, NULL); - //us_ + // us_ } return s; } -struct us_internal_ssl_socket_t *ssl_on_writable(struct us_internal_ssl_socket_t *s) { +struct us_internal_ssl_socket_t* ssl_on_writable(struct us_internal_ssl_socket_t* s) +{ - struct us_internal_ssl_socket_context_t *context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); + struct us_internal_ssl_socket_context_t* context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); - if(s->pending_handshake) { + if (s->pending_handshake) { us_internal_ssl_handshake(s, context->on_handshake, context->handshake_data); } // todo: cork here so that we efficiently output both from reading and from writing? if (s->ssl_read_wants_write) { s->ssl_read_wants_write = 0; - + // make sure to update context before we call (context can change if the user adopts the socket!) - context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); + context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); // if this one fails to write data, it sets ssl_read_wants_write again - s = (struct us_internal_ssl_socket_t *) context->sc.on_data(&s->s, 0, 0); // cast here! + s = (struct us_internal_ssl_socket_t*)context->sc.on_data(&s->s, 0, 0); // cast here! } // should this one come before we have read? should it come always? spurious on_writable is okay @@ -494,9 +494,10 @@ struct us_internal_ssl_socket_t *ssl_on_writable(struct us_internal_ssl_socket_t } /* Lazily inits loop ssl data first time */ -void us_internal_init_loop_ssl_data(struct us_loop_t *loop) { +void us_internal_init_loop_ssl_data(struct us_loop_t* loop) +{ if (!loop->data.ssl_data) { - struct loop_ssl_data *loop_ssl_data = us_malloc(sizeof(struct loop_ssl_data)); + struct loop_ssl_data* loop_ssl_data = us_malloc(sizeof(struct loop_ssl_data)); loop_ssl_data->ssl_read_input_length = 0; loop_ssl_data->ssl_read_input_offset = 0; loop_ssl_data->last_write_was_msg_more = 0; @@ -522,8 +523,9 @@ void us_internal_init_loop_ssl_data(struct us_loop_t *loop) { } /* Called by loop free, clears any loop ssl data */ -void us_internal_free_loop_ssl_data(struct us_loop_t *loop) { - struct loop_ssl_data *loop_ssl_data = (struct loop_ssl_data *) loop->data.ssl_data; +void us_internal_free_loop_ssl_data(struct us_loop_t* loop) +{ + struct loop_ssl_data* loop_ssl_data = (struct loop_ssl_data*)loop->data.ssl_data; if (loop_ssl_data) { us_free(loop_ssl_data->ssl_read_output); @@ -539,7 +541,8 @@ void us_internal_free_loop_ssl_data(struct us_loop_t *loop) { // we throttle reading data for ssl sockets that are in init state. here we actually use // the kernel buffering to our advantage -int ssl_is_low_prio(struct us_internal_ssl_socket_t *s) { +int ssl_is_low_prio(struct us_internal_ssl_socket_t* s) +{ /* We use SSL_in_before() instead of SSL_in_init(), because only the first step is CPU intensive, and we want to * speed up the rest of connection establishing if the CPU intensive work is already done, so fully established * connections increase lineary over time under high load */ @@ -547,14 +550,16 @@ int ssl_is_low_prio(struct us_internal_ssl_socket_t *s) { } /* Per-context functions */ -void *us_internal_ssl_socket_context_get_native_handle(struct us_internal_ssl_socket_context_t *context) { +void* us_internal_ssl_socket_context_get_native_handle(struct us_internal_ssl_socket_context_t* context) +{ return context->ssl_context; } -struct us_internal_ssl_socket_context_t *us_internal_create_child_ssl_socket_context(struct us_internal_ssl_socket_context_t *context, int context_ext_size) { +struct us_internal_ssl_socket_context_t* us_internal_create_child_ssl_socket_context(struct us_internal_ssl_socket_context_t* context, int context_ext_size) +{ /* Create a new non-SSL context */ - struct us_socket_context_options_t options = {0}; - struct us_internal_ssl_socket_context_t *child_context = (struct us_internal_ssl_socket_context_t *) us_create_socket_context(0, context->sc.loop, sizeof(struct us_internal_ssl_socket_context_t) + context_ext_size, options); + struct us_socket_context_options_t options = { 0 }; + struct us_internal_ssl_socket_context_t* child_context = (struct us_internal_ssl_socket_context_t*)us_create_socket_context(0, context->sc.loop, sizeof(struct us_internal_ssl_socket_context_t) + context_ext_size, options); /* The only thing we share is SSL_CTX */ child_context->ssl_context = context->ssl_context; @@ -565,13 +570,14 @@ struct us_internal_ssl_socket_context_t *us_internal_create_child_ssl_socket_con /* Common function for creating a context from options. * We must NOT free a SSL_CTX with only SSL_CTX_free! Also free any password */ -void free_ssl_context(SSL_CTX *ssl_context) { +void free_ssl_context(SSL_CTX* ssl_context) +{ if (!ssl_context) { return; } /* If we have set a password string, free it here */ - void *password = SSL_CTX_get_default_passwd_cb_userdata(ssl_context); + void* password = SSL_CTX_get_default_passwd_cb_userdata(ssl_context); /* OpenSSL returns NULL if we have no set password */ us_free(password); @@ -580,9 +586,10 @@ void free_ssl_context(SSL_CTX *ssl_context) { /* This function should take any options and return SSL_CTX - which has to be free'd with * our destructor function - free_ssl_context() */ -SSL_CTX *create_ssl_context_from_options(struct us_socket_context_options_t options) { +SSL_CTX* create_ssl_context_from_options(struct us_socket_context_options_t options) +{ /* Create the context */ - SSL_CTX *ssl_context = SSL_CTX_new(TLS_method()); + SSL_CTX* ssl_context = SSL_CTX_new(TLS_method()); /* Default options we rely on - changing these will break our logic */ SSL_CTX_set_read_ahead(ssl_context, 1); @@ -595,13 +602,13 @@ SSL_CTX *create_ssl_context_from_options(struct us_socket_context_options_t opti /* Important option for lowering memory usage, but lowers performance slightly */ if (options.ssl_prefer_low_memory_usage) { - SSL_CTX_set_mode(ssl_context, SSL_MODE_RELEASE_BUFFERS); + SSL_CTX_set_mode(ssl_context, SSL_MODE_RELEASE_BUFFERS); } if (options.passphrase) { /* When freeing the CTX we need to check SSL_CTX_get_default_passwd_cb_userdata and * free it if set */ - SSL_CTX_set_default_passwd_cb_userdata(ssl_context, (void *) strdup(options.passphrase)); + SSL_CTX_set_default_passwd_cb_userdata(ssl_context, (void*)strdup(options.passphrase)); SSL_CTX_set_default_passwd_cb(ssl_context, passphrase_cb); } @@ -622,9 +629,9 @@ SSL_CTX *create_ssl_context_from_options(struct us_socket_context_options_t opti } if (options.ca_file_name) { - STACK_OF(X509_NAME) *ca_list; + STACK_OF(X509_NAME) * ca_list; ca_list = SSL_load_client_CA_file(options.ca_file_name); - if(ca_list == NULL) { + if (ca_list == NULL) { free_ssl_context(ssl_context); return NULL; } @@ -638,8 +645,8 @@ SSL_CTX *create_ssl_context_from_options(struct us_socket_context_options_t opti if (options.dh_params_file_name) { /* Set up ephemeral DH parameters. */ - DH *dh_2048 = NULL; - FILE *paramfile; + DH* dh_2048 = NULL; + FILE* paramfile; paramfile = fopen(options.dh_params_file_name, "r"); if (paramfile) { @@ -681,239 +688,244 @@ SSL_CTX *create_ssl_context_from_options(struct us_socket_context_options_t opti return ssl_context; } - - -int us_ssl_ctx_use_privatekey_content(SSL_CTX *ctx, const char *content, int type) { - int reason_code, ret = 0; - BIO *in; - EVP_PKEY *pkey = NULL; - in = BIO_new_mem_buf(content, strlen(content)); - if (in == NULL) { - OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB); - goto end; - } - - if (type == SSL_FILETYPE_PEM) { - reason_code = ERR_R_PEM_LIB; - pkey = PEM_read_bio_PrivateKey(in, NULL, SSL_CTX_get_default_passwd_cb(ctx), - SSL_CTX_get_default_passwd_cb_userdata(ctx)); - } else if (type == SSL_FILETYPE_ASN1) { - reason_code = ERR_R_ASN1_LIB; - pkey = d2i_PrivateKey_bio(in, NULL); - } else { - OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_SSL_FILETYPE); - goto end; - } - - if (pkey == NULL) { - OPENSSL_PUT_ERROR(SSL, reason_code); - goto end; - } - ret = SSL_CTX_use_PrivateKey(ctx, pkey); - EVP_PKEY_free(pkey); - -end: - BIO_free(in); - return ret; -} - -X509 * us_ssl_ctx_get_X509_from(SSL_CTX *ctx, const char *content) { - X509 *x = NULL; - BIO *in; - - ERR_clear_error(); // clear error stack for SSL_CTX_use_certificate() - - in = BIO_new_mem_buf(content, strlen(content)); - if (in == NULL) { - OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB); - goto end; - } - - x = PEM_read_bio_X509(in, NULL, SSL_CTX_get_default_passwd_cb(ctx), - SSL_CTX_get_default_passwd_cb_userdata(ctx)); - if (x == NULL) { - OPENSSL_PUT_ERROR(SSL, ERR_R_PEM_LIB); - goto end; - } - - return x; - -end: - X509_free(x); - BIO_free(in); - return NULL; -} - -int us_ssl_ctx_use_certificate_chain(SSL_CTX *ctx, const char *content) { - BIO *in; - int ret = 0; - X509 *x = NULL; - - ERR_clear_error(); // clear error stack for SSL_CTX_use_certificate() - - in = BIO_new_mem_buf(content, strlen(content)); - if (in == NULL) { - OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB); - goto end; - } - - x = PEM_read_bio_X509_AUX(in, NULL, SSL_CTX_get_default_passwd_cb(ctx), - SSL_CTX_get_default_passwd_cb_userdata(ctx)); - if (x == NULL) { - OPENSSL_PUT_ERROR(SSL, ERR_R_PEM_LIB); - goto end; - } - - ret = SSL_CTX_use_certificate(ctx, x); - - if (ERR_peek_error() != 0) { - ret = 0; // Key/certificate mismatch doesn't imply ret==0 ... - } - - if (ret) { - // If we could set up our certificate, now proceed to the CA - // certificates. - X509 *ca; - int r; - uint32_t err; - - SSL_CTX_clear_chain_certs(ctx); - - while ((ca = PEM_read_bio_X509(in, NULL, SSL_CTX_get_default_passwd_cb(ctx), - SSL_CTX_get_default_passwd_cb_userdata(ctx))) != - NULL) { - r = SSL_CTX_add0_chain_cert(ctx, ca); - if (!r) { - X509_free(ca); - ret = 0; +int us_ssl_ctx_use_privatekey_content(SSL_CTX* ctx, const char* content, int type) +{ + int reason_code, ret = 0; + BIO* in; + EVP_PKEY* pkey = NULL; + in = BIO_new_mem_buf(content, strlen(content)); + if (in == NULL) { + OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB); goto end; - } - // Note that we must not free r if it was successfully added to the chain - // (while we must free the main certificate, since its reference count is - // increased by SSL_CTX_use_certificate). } - // When the while loop ends, it's usually just EOF. - err = ERR_peek_last_error(); - if (ERR_GET_LIB(err) == ERR_LIB_PEM && - ERR_GET_REASON(err) == PEM_R_NO_START_LINE) { - ERR_clear_error(); + if (type == SSL_FILETYPE_PEM) { + reason_code = ERR_R_PEM_LIB; + pkey = PEM_read_bio_PrivateKey(in, NULL, SSL_CTX_get_default_passwd_cb(ctx), + SSL_CTX_get_default_passwd_cb_userdata(ctx)); + } else if (type == SSL_FILETYPE_ASN1) { + reason_code = ERR_R_ASN1_LIB; + pkey = d2i_PrivateKey_bio(in, NULL); } else { - ret = 0; // some real error + OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_SSL_FILETYPE); + goto end; } - } + + if (pkey == NULL) { + OPENSSL_PUT_ERROR(SSL, reason_code); + goto end; + } + ret = SSL_CTX_use_PrivateKey(ctx, pkey); + EVP_PKEY_free(pkey); end: - X509_free(x); - BIO_free(in); - return ret; + BIO_free(in); + return ret; } -const char* us_X509_error_code(long err) { // NOLINT(runtime/int) - const char* code = "UNSPECIFIED"; -#define CASE_X509_ERR(CODE) case X509_V_ERR_##CODE: code = #CODE; break; - switch (err) { - // if you modify anything in here, *please* update the respective section in - // doc/api/tls.md as well - CASE_X509_ERR(UNABLE_TO_GET_ISSUER_CERT) - CASE_X509_ERR(UNABLE_TO_GET_CRL) - CASE_X509_ERR(UNABLE_TO_DECRYPT_CERT_SIGNATURE) - CASE_X509_ERR(UNABLE_TO_DECRYPT_CRL_SIGNATURE) - CASE_X509_ERR(UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY) - CASE_X509_ERR(CERT_SIGNATURE_FAILURE) - CASE_X509_ERR(CRL_SIGNATURE_FAILURE) - CASE_X509_ERR(CERT_NOT_YET_VALID) - CASE_X509_ERR(CERT_HAS_EXPIRED) - CASE_X509_ERR(CRL_NOT_YET_VALID) - CASE_X509_ERR(CRL_HAS_EXPIRED) - CASE_X509_ERR(ERROR_IN_CERT_NOT_BEFORE_FIELD) - CASE_X509_ERR(ERROR_IN_CERT_NOT_AFTER_FIELD) - CASE_X509_ERR(ERROR_IN_CRL_LAST_UPDATE_FIELD) - CASE_X509_ERR(ERROR_IN_CRL_NEXT_UPDATE_FIELD) - CASE_X509_ERR(OUT_OF_MEM) - CASE_X509_ERR(DEPTH_ZERO_SELF_SIGNED_CERT) - CASE_X509_ERR(SELF_SIGNED_CERT_IN_CHAIN) - CASE_X509_ERR(UNABLE_TO_GET_ISSUER_CERT_LOCALLY) - CASE_X509_ERR(UNABLE_TO_VERIFY_LEAF_SIGNATURE) - CASE_X509_ERR(CERT_CHAIN_TOO_LONG) - CASE_X509_ERR(CERT_REVOKED) - CASE_X509_ERR(INVALID_CA) - CASE_X509_ERR(PATH_LENGTH_EXCEEDED) - CASE_X509_ERR(INVALID_PURPOSE) - CASE_X509_ERR(CERT_UNTRUSTED) - CASE_X509_ERR(CERT_REJECTED) - CASE_X509_ERR(HOSTNAME_MISMATCH) - } -#undef CASE_X509_ERR - return code; -} +X509* us_ssl_ctx_get_X509_from(SSL_CTX* ctx, const char* content) +{ + X509* x = NULL; + BIO* in; -long us_internal_verify_peer_certificate( // NOLINT(runtime/int) - const SSL* ssl, - long def) { // NOLINT(runtime/int) - long err = def; // NOLINT(runtime/int) - X509* peer_cert = SSL_get_peer_certificate(ssl); - if (peer_cert) { - X509_free(peer_cert); - err = SSL_get_verify_result(ssl); - } else { - const SSL_CIPHER* curr_cipher = SSL_get_current_cipher(ssl); + ERR_clear_error(); // clear error stack for SSL_CTX_use_certificate() - const SSL_SESSION* sess = SSL_get_session(ssl); - // Allow no-cert for PSK authentication in TLS1.2 and lower. - // In TLS1.3 check that session was reused because TLS1.3 PSK - // looks like session resumption. - if ((curr_cipher && SSL_CIPHER_get_auth_nid(curr_cipher) == NID_auth_psk) || - (sess && SSL_SESSION_get_protocol_version(sess) == TLS1_3_VERSION && - SSL_session_reused(ssl))) { - return X509_V_OK; + in = BIO_new_mem_buf(content, strlen(content)); + if (in == NULL) { + OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB); + goto end; } - } - return err; + + x = PEM_read_bio_X509(in, NULL, SSL_CTX_get_default_passwd_cb(ctx), + SSL_CTX_get_default_passwd_cb_userdata(ctx)); + if (x == NULL) { + OPENSSL_PUT_ERROR(SSL, ERR_R_PEM_LIB); + goto end; + } + + return x; + +end: + X509_free(x); + BIO_free(in); + return NULL; } +int us_ssl_ctx_use_certificate_chain(SSL_CTX* ctx, const char* content) +{ + BIO* in; + int ret = 0; + X509* x = NULL; -struct us_bun_verify_error_t us_internal_verify_error(struct us_internal_ssl_socket_t *s) { + ERR_clear_error(); // clear error stack for SSL_CTX_use_certificate() + + in = BIO_new_mem_buf(content, strlen(content)); + if (in == NULL) { + OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB); + goto end; + } + + x = PEM_read_bio_X509_AUX(in, NULL, SSL_CTX_get_default_passwd_cb(ctx), + SSL_CTX_get_default_passwd_cb_userdata(ctx)); + if (x == NULL) { + OPENSSL_PUT_ERROR(SSL, ERR_R_PEM_LIB); + goto end; + } + + ret = SSL_CTX_use_certificate(ctx, x); + + if (ERR_peek_error() != 0) { + ret = 0; // Key/certificate mismatch doesn't imply ret==0 ... + } + + if (ret) { + // If we could set up our certificate, now proceed to the CA + // certificates. + X509* ca; + int r; + uint32_t err; + + SSL_CTX_clear_chain_certs(ctx); + + while ((ca = PEM_read_bio_X509(in, NULL, SSL_CTX_get_default_passwd_cb(ctx), + SSL_CTX_get_default_passwd_cb_userdata(ctx))) + != NULL) { + r = SSL_CTX_add0_chain_cert(ctx, ca); + if (!r) { + X509_free(ca); + ret = 0; + goto end; + } + // Note that we must not free r if it was successfully added to the chain + // (while we must free the main certificate, since its reference count is + // increased by SSL_CTX_use_certificate). + } + + // When the while loop ends, it's usually just EOF. + err = ERR_peek_last_error(); + if (ERR_GET_LIB(err) == ERR_LIB_PEM && ERR_GET_REASON(err) == PEM_R_NO_START_LINE) { + ERR_clear_error(); + } else { + ret = 0; // some real error + } + } + +end: + X509_free(x); + BIO_free(in); + return ret; +} + +const char* us_X509_error_code(long err) +{ // NOLINT(runtime/int) + const char* code = "UNSPECIFIED"; +#define CASE_X509_ERR(CODE) \ + case X509_V_ERR_##CODE: \ + code = #CODE; \ + break; + switch (err) { + // if you modify anything in here, *please* update the respective section in + // doc/api/tls.md as well + CASE_X509_ERR(UNABLE_TO_GET_ISSUER_CERT) + CASE_X509_ERR(UNABLE_TO_GET_CRL) + CASE_X509_ERR(UNABLE_TO_DECRYPT_CERT_SIGNATURE) + CASE_X509_ERR(UNABLE_TO_DECRYPT_CRL_SIGNATURE) + CASE_X509_ERR(UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY) + CASE_X509_ERR(CERT_SIGNATURE_FAILURE) + CASE_X509_ERR(CRL_SIGNATURE_FAILURE) + CASE_X509_ERR(CERT_NOT_YET_VALID) + CASE_X509_ERR(CERT_HAS_EXPIRED) + CASE_X509_ERR(CRL_NOT_YET_VALID) + CASE_X509_ERR(CRL_HAS_EXPIRED) + CASE_X509_ERR(ERROR_IN_CERT_NOT_BEFORE_FIELD) + CASE_X509_ERR(ERROR_IN_CERT_NOT_AFTER_FIELD) + CASE_X509_ERR(ERROR_IN_CRL_LAST_UPDATE_FIELD) + CASE_X509_ERR(ERROR_IN_CRL_NEXT_UPDATE_FIELD) + CASE_X509_ERR(OUT_OF_MEM) + CASE_X509_ERR(DEPTH_ZERO_SELF_SIGNED_CERT) + CASE_X509_ERR(SELF_SIGNED_CERT_IN_CHAIN) + CASE_X509_ERR(UNABLE_TO_GET_ISSUER_CERT_LOCALLY) + CASE_X509_ERR(UNABLE_TO_VERIFY_LEAF_SIGNATURE) + CASE_X509_ERR(CERT_CHAIN_TOO_LONG) + CASE_X509_ERR(CERT_REVOKED) + CASE_X509_ERR(INVALID_CA) + CASE_X509_ERR(PATH_LENGTH_EXCEEDED) + CASE_X509_ERR(INVALID_PURPOSE) + CASE_X509_ERR(CERT_UNTRUSTED) + CASE_X509_ERR(CERT_REJECTED) + CASE_X509_ERR(HOSTNAME_MISMATCH) + } +#undef CASE_X509_ERR + return code; +} + +long us_internal_verify_peer_certificate( // NOLINT(runtime/int) + const SSL* ssl, + long def) +{ // NOLINT(runtime/int) + long err = def; // NOLINT(runtime/int) + X509* peer_cert = SSL_get_peer_certificate(ssl); + if (peer_cert) { + X509_free(peer_cert); + err = SSL_get_verify_result(ssl); + } else { + const SSL_CIPHER* curr_cipher = SSL_get_current_cipher(ssl); + + const SSL_SESSION* sess = SSL_get_session(ssl); + // Allow no-cert for PSK authentication in TLS1.2 and lower. + // In TLS1.3 check that session was reused because TLS1.3 PSK + // looks like session resumption. + if ((curr_cipher && SSL_CIPHER_get_auth_nid(curr_cipher) == NID_auth_psk) || (sess && SSL_SESSION_get_protocol_version(sess) == TLS1_3_VERSION && SSL_session_reused(ssl))) { + return X509_V_OK; + } + } + return err; +} + +struct us_bun_verify_error_t us_internal_verify_error(struct us_internal_ssl_socket_t* s) +{ if (us_socket_is_closed(0, &s->s) || us_internal_ssl_socket_is_shut_down(s)) { return (struct us_bun_verify_error_t) { .error = 0, .code = NULL, .reason = NULL }; } SSL* ssl = s->ssl; - long x509_verify_error = // NOLINT(runtime/int) + long x509_verify_error = // NOLINT(runtime/int) us_internal_verify_peer_certificate( ssl, X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT); if (x509_verify_error == X509_V_OK) return (struct us_bun_verify_error_t) { .error = x509_verify_error, .code = NULL, .reason = NULL }; - + const char* reason = X509_verify_cert_error_string(x509_verify_error); const char* code = us_X509_error_code(x509_verify_error); return (struct us_bun_verify_error_t) { .error = x509_verify_error, .code = code, .reason = reason }; } -int us_verify_callback(int preverify_ok, X509_STORE_CTX* ctx) { - // From https://www.openssl.org/docs/man1.1.1/man3/SSL_verify_cb: - // - // If VerifyCallback returns 1, the verification process is continued. If - // VerifyCallback always returns 1, the TLS/SSL handshake will not be - // terminated with respect to verification failures and the connection will - // be established. The calling process can however retrieve the error code - // of the last verification error using SSL_get_verify_result(3) or by - // maintaining its own error storage managed by VerifyCallback. - // - // Since we cannot perform I/O quickly enough with X509_STORE_CTX_ APIs in - // this callback, we ignore all preverify_ok errors and let the handshake - // continue. It is imperative that the user use Connection::VerifyError after - // the 'secure' callback has been made. - return 1; +int us_verify_callback(int preverify_ok, X509_STORE_CTX* ctx) +{ + // From https://www.openssl.org/docs/man1.1.1/man3/SSL_verify_cb: + // + // If VerifyCallback returns 1, the verification process is continued. If + // VerifyCallback always returns 1, the TLS/SSL handshake will not be + // terminated with respect to verification failures and the connection will + // be established. The calling process can however retrieve the error code + // of the last verification error using SSL_get_verify_result(3) or by + // maintaining its own error storage managed by VerifyCallback. + // + // Since we cannot perform I/O quickly enough with X509_STORE_CTX_ APIs in + // this callback, we ignore all preverify_ok errors and let the handshake + // continue. It is imperative that the user use Connection::VerifyError after + // the 'secure' callback has been made. + return 1; } -SSL_CTX *create_ssl_context_from_bun_options(struct us_bun_socket_context_options_t options) { +SSL_CTX* create_ssl_context_from_bun_options(struct us_bun_socket_context_options_t options) +{ /* Create the context */ - SSL_CTX *ssl_context = SSL_CTX_new(TLS_method()); + SSL_CTX* ssl_context = SSL_CTX_new(TLS_method()); /* Default options we rely on - changing these will break our logic */ SSL_CTX_set_read_ahead(ssl_context, 1); @@ -926,14 +938,13 @@ SSL_CTX *create_ssl_context_from_bun_options(struct us_bun_socket_context_option /* Important option for lowering memory usage, but lowers performance slightly */ if (options.ssl_prefer_low_memory_usage) { - SSL_CTX_set_mode(ssl_context, SSL_MODE_RELEASE_BUFFERS); + SSL_CTX_set_mode(ssl_context, SSL_MODE_RELEASE_BUFFERS); } - if (options.passphrase) { /* When freeing the CTX we need to check SSL_CTX_get_default_passwd_cb_userdata and * free it if set */ - SSL_CTX_set_default_passwd_cb_userdata(ssl_context, (void *) strdup(options.passphrase)); + SSL_CTX_set_default_passwd_cb_userdata(ssl_context, (void*)strdup(options.passphrase)); SSL_CTX_set_default_passwd_cb(ssl_context, passphrase_cb); } @@ -944,7 +955,7 @@ SSL_CTX *create_ssl_context_from_bun_options(struct us_bun_socket_context_option return NULL; } } else if (options.cert && options.cert_count > 0) { - for(unsigned int i = 0; i < options.cert_count; i++) { + for (unsigned int i = 0; i < options.cert_count; i++) { if (us_ssl_ctx_use_certificate_chain(ssl_context, options.cert[i]) != 1) { free_ssl_context(ssl_context); return NULL; @@ -959,7 +970,7 @@ SSL_CTX *create_ssl_context_from_bun_options(struct us_bun_socket_context_option return NULL; } } else if (options.key && options.key_count > 0) { - for(unsigned int i = 0; i < options.key_count; i++){ + for (unsigned int i = 0; i < options.key_count; i++) { if (us_ssl_ctx_use_privatekey_content(ssl_context, options.key[i], SSL_FILETYPE_PEM) != 1) { free_ssl_context(ssl_context); return NULL; @@ -970,31 +981,31 @@ SSL_CTX *create_ssl_context_from_bun_options(struct us_bun_socket_context_option if (options.ca_file_name) { SSL_CTX_set_cert_store(ssl_context, us_get_default_ca_store()); - STACK_OF(X509_NAME) *ca_list; + STACK_OF(X509_NAME) * ca_list; ca_list = SSL_load_client_CA_file(options.ca_file_name); - if(ca_list == NULL) { + if (ca_list == NULL) { free_ssl_context(ssl_context); return NULL; } - + SSL_CTX_set_client_CA_list(ssl_context, ca_list); if (SSL_CTX_load_verify_locations(ssl_context, options.ca_file_name, NULL) != 1) { free_ssl_context(ssl_context); return NULL; } - - if(options.reject_unauthorized) { + + if (options.reject_unauthorized) { SSL_CTX_set_verify(ssl_context, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, us_verify_callback); } else { SSL_CTX_set_verify(ssl_context, SSL_VERIFY_PEER, us_verify_callback); } - }else if (options.ca && options.ca_count > 0) { + } else if (options.ca && options.ca_count > 0) { X509_STORE* cert_store = NULL; - - for(unsigned int i = 0; i < options.ca_count; i++){ + + for (unsigned int i = 0; i < options.ca_count; i++) { X509* ca_cert = us_ssl_ctx_get_X509_from(ssl_context, options.ca[i]); - if (ca_cert == NULL){ + if (ca_cert == NULL) { free_ssl_context(ssl_context); return NULL; } @@ -1003,23 +1014,23 @@ SSL_CTX *create_ssl_context_from_bun_options(struct us_bun_socket_context_option cert_store = us_get_default_ca_store(); SSL_CTX_set_cert_store(ssl_context, cert_store); } - + X509_STORE_add_cert(cert_store, ca_cert); - if(!SSL_CTX_add_client_CA(ssl_context, ca_cert)){ + if (!SSL_CTX_add_client_CA(ssl_context, ca_cert)) { free_ssl_context(ssl_context); return NULL; } - if(options.reject_unauthorized) { + if (options.reject_unauthorized) { SSL_CTX_set_verify(ssl_context, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, us_verify_callback); } else { SSL_CTX_set_verify(ssl_context, SSL_VERIFY_PEER, us_verify_callback); } } } else { - if(options.request_cert) { + if (options.request_cert) { SSL_CTX_set_cert_store(ssl_context, us_get_default_ca_store()); - - if(options.reject_unauthorized) { + + if (options.reject_unauthorized) { SSL_CTX_set_verify(ssl_context, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, us_verify_callback); } else { SSL_CTX_set_verify(ssl_context, SSL_VERIFY_PEER, us_verify_callback); @@ -1028,8 +1039,8 @@ SSL_CTX *create_ssl_context_from_bun_options(struct us_bun_socket_context_option } if (options.dh_params_file_name) { /* Set up ephemeral DH parameters. */ - DH *dh_2048 = NULL; - FILE *paramfile; + DH* dh_2048 = NULL; + FILE* paramfile; paramfile = fopen(options.dh_params_file_name, "r"); if (paramfile) { @@ -1076,11 +1087,12 @@ SSL_CTX *create_ssl_context_from_bun_options(struct us_bun_socket_context_option } /* Returns a servername's userdata if any */ -void *us_internal_ssl_socket_context_find_server_name_userdata(struct us_internal_ssl_socket_context_t *context, const char *hostname_pattern) { - +void* us_internal_ssl_socket_context_find_server_name_userdata(struct us_internal_ssl_socket_context_t* context, const char* hostname_pattern) +{ + /* We can use sni_find because looking up a "wildcard pattern" will match the exact literal "wildcard pattern" first, * before it matches by the very wildcard itself, so it works fine (exact match is the only thing we care for here) */ - SSL_CTX *ssl_context = sni_find(context->sni, hostname_pattern); + SSL_CTX* ssl_context = sni_find(context->sni, hostname_pattern); if (ssl_context) { return SSL_CTX_get_ex_data(ssl_context, 0); @@ -1090,15 +1102,17 @@ void *us_internal_ssl_socket_context_find_server_name_userdata(struct us_interna } /* Returns either nullptr or the previously set user data attached to this SSL's selected SNI context */ -void *us_internal_ssl_socket_get_sni_userdata(struct us_internal_ssl_socket_t *s) { +void* us_internal_ssl_socket_get_sni_userdata(struct us_internal_ssl_socket_t* s) +{ return SSL_CTX_get_ex_data(SSL_get_SSL_CTX(s->ssl), 0); } /* Todo: return error on failure? */ -void us_internal_ssl_socket_context_add_server_name(struct us_internal_ssl_socket_context_t *context, const char *hostname_pattern, struct us_socket_context_options_t options, void *user) { +void us_internal_ssl_socket_context_add_server_name(struct us_internal_ssl_socket_context_t* context, const char* hostname_pattern, struct us_socket_context_options_t options, void* user) +{ /* Try and construct an SSL_CTX from options */ - SSL_CTX *ssl_context = create_ssl_context_from_options(options); + SSL_CTX* ssl_context = create_ssl_context_from_options(options); /* Attach the user data to this context */ if (1 != SSL_CTX_set_ex_data(ssl_context, 0, user)) { @@ -1114,10 +1128,11 @@ void us_internal_ssl_socket_context_add_server_name(struct us_internal_ssl_socke } } -void us_bun_internal_ssl_socket_context_add_server_name(struct us_internal_ssl_socket_context_t *context, const char *hostname_pattern, struct us_bun_socket_context_options_t options, void *user) { +void us_bun_internal_ssl_socket_context_add_server_name(struct us_internal_ssl_socket_context_t* context, const char* hostname_pattern, struct us_bun_socket_context_options_t options, void* user) +{ /* Try and construct an SSL_CTX from options */ - SSL_CTX *ssl_context = create_ssl_context_from_bun_options(options); + SSL_CTX* ssl_context = create_ssl_context_from_bun_options(options); /* Attach the user data to this context */ if (1 != SSL_CTX_set_ex_data(ssl_context, 0, user)) { @@ -1133,22 +1148,25 @@ void us_bun_internal_ssl_socket_context_add_server_name(struct us_internal_ssl_s } } -void us_internal_ssl_socket_context_on_server_name(struct us_internal_ssl_socket_context_t *context, void (*cb)(struct us_internal_ssl_socket_context_t *, const char *hostname)) { +void us_internal_ssl_socket_context_on_server_name(struct us_internal_ssl_socket_context_t* context, void (*cb)(struct us_internal_ssl_socket_context_t*, const char* hostname)) +{ context->on_server_name = cb; } -void us_internal_ssl_socket_context_remove_server_name(struct us_internal_ssl_socket_context_t *context, const char *hostname_pattern) { +void us_internal_ssl_socket_context_remove_server_name(struct us_internal_ssl_socket_context_t* context, const char* hostname_pattern) +{ /* The same thing must happen for sni_free, that's why we have a callback */ - SSL_CTX *sni_node_ssl_context = (SSL_CTX *) sni_remove(context->sni, hostname_pattern); + SSL_CTX* sni_node_ssl_context = (SSL_CTX*)sni_remove(context->sni, hostname_pattern); free_ssl_context(sni_node_ssl_context); } /* Returns NULL or SSL_CTX. May call missing server name callback */ -SSL_CTX *resolve_context(struct us_internal_ssl_socket_context_t *context, const char *hostname) { +SSL_CTX* resolve_context(struct us_internal_ssl_socket_context_t* context, const char* hostname) +{ /* Try once first */ - void *user = sni_find(context->sni, hostname); + void* user = sni_find(context->sni, hostname); if (!user) { /* Emit missing hostname then try again */ if (!context->on_server_name) { @@ -1166,20 +1184,20 @@ SSL_CTX *resolve_context(struct us_internal_ssl_socket_context_t *context, const } // arg is context -int sni_cb(SSL *ssl, int *al, void *arg) { +int sni_cb(SSL* ssl, int* al, void* arg) +{ if (ssl) { - const char *hostname = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); + const char* hostname = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); if (hostname && hostname[0]) { /* Try and resolve (match) required hostname with what we have registered */ - SSL_CTX *resolved_ssl_context = resolve_context((struct us_internal_ssl_socket_context_t *) arg, hostname); + SSL_CTX* resolved_ssl_context = resolve_context((struct us_internal_ssl_socket_context_t*)arg, hostname); if (resolved_ssl_context) { - //printf("Did find matching SNI context for hostname: <%s>!\n", hostname); + // printf("Did find matching SNI context for hostname: <%s>!\n", hostname); SSL_set_SSL_CTX(ssl, resolved_ssl_context); } else { /* Call a blocking callback notifying of missing context */ } - } return SSL_TLSEXT_ERR_OK; @@ -1189,33 +1207,34 @@ int sni_cb(SSL *ssl, int *al, void *arg) { return SSL_TLSEXT_ERR_NOACK; } -struct us_internal_ssl_socket_context_t *us_internal_create_ssl_socket_context(struct us_loop_t *loop, int context_ext_size, struct us_socket_context_options_t options) { +struct us_internal_ssl_socket_context_t* us_internal_create_ssl_socket_context(struct us_loop_t* loop, int context_ext_size, struct us_socket_context_options_t options) +{ /* If we haven't initialized the loop data yet, do so . * This is needed because loop data holds shared OpenSSL data and * the function is also responsible for initializing OpenSSL */ us_internal_init_loop_ssl_data(loop); /* First of all we try and create the SSL context from options */ - SSL_CTX *ssl_context = create_ssl_context_from_options(options); + SSL_CTX* ssl_context = create_ssl_context_from_options(options); if (!ssl_context) { /* We simply fail early if we cannot even create the OpenSSL context */ return NULL; } /* Otherwise ee continue by creating a non-SSL context, but with larger ext to hold our SSL stuff */ - struct us_internal_ssl_socket_context_t *context = (struct us_internal_ssl_socket_context_t *) us_create_socket_context(0, loop, sizeof(struct us_internal_ssl_socket_context_t) + context_ext_size, options); + struct us_internal_ssl_socket_context_t* context = (struct us_internal_ssl_socket_context_t*)us_create_socket_context(0, loop, sizeof(struct us_internal_ssl_socket_context_t) + context_ext_size, options); /* I guess this is the only optional callback */ context->on_server_name = NULL; /* Then we extend its SSL parts */ - context->ssl_context = ssl_context;//create_ssl_context_from_options(options); + context->ssl_context = ssl_context; // create_ssl_context_from_options(options); context->is_parent = 1; context->on_handshake = NULL; context->handshake_data = NULL; /* We, as parent context, may ignore data */ - context->sc.is_low_prio = (int (*)(struct us_socket_t *)) ssl_is_low_prio; + context->sc.is_low_prio = (int (*)(struct us_socket_t*))ssl_is_low_prio; /* Parent contexts may use SNI */ SSL_CTX_set_tlsext_servername_callback(context->ssl_context, sni_cb); @@ -1226,33 +1245,34 @@ struct us_internal_ssl_socket_context_t *us_internal_create_ssl_socket_context(s return context; } -struct us_internal_ssl_socket_context_t *us_internal_bun_create_ssl_socket_context(struct us_loop_t *loop, int context_ext_size, struct us_bun_socket_context_options_t options) { +struct us_internal_ssl_socket_context_t* us_internal_bun_create_ssl_socket_context(struct us_loop_t* loop, int context_ext_size, struct us_bun_socket_context_options_t options) +{ /* If we haven't initialized the loop data yet, do so . * This is needed because loop data holds shared OpenSSL data and * the function is also responsible for initializing OpenSSL */ us_internal_init_loop_ssl_data(loop); /* First of all we try and create the SSL context from options */ - SSL_CTX *ssl_context = create_ssl_context_from_bun_options(options); + SSL_CTX* ssl_context = create_ssl_context_from_bun_options(options); if (!ssl_context) { /* We simply fail early if we cannot even create the OpenSSL context */ return NULL; } /* Otherwise ee continue by creating a non-SSL context, but with larger ext to hold our SSL stuff */ - struct us_internal_ssl_socket_context_t *context = (struct us_internal_ssl_socket_context_t *) us_create_bun_socket_context(0, loop, sizeof(struct us_internal_ssl_socket_context_t) + context_ext_size, options); + struct us_internal_ssl_socket_context_t* context = (struct us_internal_ssl_socket_context_t*)us_create_bun_socket_context(0, loop, sizeof(struct us_internal_ssl_socket_context_t) + context_ext_size, options); /* I guess this is the only optional callback */ context->on_server_name = NULL; /* Then we extend its SSL parts */ - context->ssl_context = ssl_context;//create_ssl_context_from_options(options); + context->ssl_context = ssl_context; // create_ssl_context_from_options(options); context->is_parent = 1; - + context->on_handshake = NULL; context->handshake_data = NULL; /* We, as parent context, may ignore data */ - context->sc.is_low_prio = (int (*)(struct us_socket_t *)) ssl_is_low_prio; + context->sc.is_low_prio = (int (*)(struct us_socket_t*))ssl_is_low_prio; /* Parent contexts may use SNI */ SSL_CTX_set_tlsext_servername_callback(context->ssl_context, sni_cb); @@ -1265,12 +1285,14 @@ struct us_internal_ssl_socket_context_t *us_internal_bun_create_ssl_socket_conte } /* Our destructor for hostnames, used below */ -void sni_hostname_destructor(void *user) { +void sni_hostname_destructor(void* user) +{ /* Some nodes hold null, so this one must ignore this case */ - free_ssl_context((SSL_CTX *) user); + free_ssl_context((SSL_CTX*)user); } -void us_internal_ssl_socket_context_free(struct us_internal_ssl_socket_context_t *context) { +void us_internal_ssl_socket_context_free(struct us_internal_ssl_socket_context_t* context) +{ /* If we are parent then we need to free our OpenSSL context */ if (context->is_parent) { free_ssl_context(context->ssl_context); @@ -1283,103 +1305,115 @@ void us_internal_ssl_socket_context_free(struct us_internal_ssl_socket_context_t us_socket_context_free(0, &context->sc); } -struct us_listen_socket_t *us_internal_ssl_socket_context_listen(struct us_internal_ssl_socket_context_t *context, const char *host, int port, int options, int socket_ext_size) { +struct us_listen_socket_t* us_internal_ssl_socket_context_listen(struct us_internal_ssl_socket_context_t* context, const char* host, int port, int options, int socket_ext_size) +{ return us_socket_context_listen(0, &context->sc, host, port, options, sizeof(struct us_internal_ssl_socket_t) - sizeof(struct us_socket_t) + socket_ext_size); } -struct us_listen_socket_t *us_internal_ssl_socket_context_listen_unix(struct us_internal_ssl_socket_context_t *context, const char *path, int options, int socket_ext_size) { +struct us_listen_socket_t* us_internal_ssl_socket_context_listen_unix(struct us_internal_ssl_socket_context_t* context, const char* path, int options, int socket_ext_size) +{ return us_socket_context_listen_unix(0, &context->sc, path, options, sizeof(struct us_internal_ssl_socket_t) - sizeof(struct us_socket_t) + socket_ext_size); } -struct us_internal_ssl_socket_t *us_internal_ssl_socket_context_connect(struct us_internal_ssl_socket_context_t *context, const char *host, int port, const char *source_host, int options, int socket_ext_size) { - return (struct us_internal_ssl_socket_t *) us_socket_context_connect(0, &context->sc, host, port, source_host, options, sizeof(struct us_internal_ssl_socket_t) - sizeof(struct us_socket_t) + socket_ext_size); +struct us_internal_ssl_socket_t* us_internal_ssl_socket_context_connect(struct us_internal_ssl_socket_context_t* context, const char* host, int port, const char* source_host, int options, int socket_ext_size) +{ + return (struct us_internal_ssl_socket_t*)us_socket_context_connect(0, &context->sc, host, port, source_host, options, sizeof(struct us_internal_ssl_socket_t) - sizeof(struct us_socket_t) + socket_ext_size); } -struct us_internal_ssl_socket_t *us_internal_ssl_socket_context_connect_unix(struct us_internal_ssl_socket_context_t *context, const char *server_path, int options, int socket_ext_size) { - return (struct us_internal_ssl_socket_t *) us_socket_context_connect_unix(0, &context->sc, server_path, options, sizeof(struct us_internal_ssl_socket_t) - sizeof(struct us_socket_t) + socket_ext_size); +struct us_internal_ssl_socket_t* us_internal_ssl_socket_context_connect_unix(struct us_internal_ssl_socket_context_t* context, const char* server_path, int options, int socket_ext_size) +{ + return (struct us_internal_ssl_socket_t*)us_socket_context_connect_unix(0, &context->sc, server_path, options, sizeof(struct us_internal_ssl_socket_t) - sizeof(struct us_socket_t) + socket_ext_size); } -void us_internal_ssl_socket_context_on_open(struct us_internal_ssl_socket_context_t *context, struct us_internal_ssl_socket_t *(*on_open)(struct us_internal_ssl_socket_t *s, int is_client, char *ip, int ip_length)) { - us_socket_context_on_open(0, &context->sc, (struct us_socket_t *(*)(struct us_socket_t *, int, char *, int)) ssl_on_open); +void us_internal_ssl_socket_context_on_open(struct us_internal_ssl_socket_context_t* context, struct us_internal_ssl_socket_t* (*on_open)(struct us_internal_ssl_socket_t* s, int is_client, char* ip, int ip_length)) +{ + us_socket_context_on_open(0, &context->sc, (struct us_socket_t * (*)(struct us_socket_t*, int, char*, int)) ssl_on_open); context->on_open = on_open; } -void us_internal_ssl_socket_context_on_close(struct us_internal_ssl_socket_context_t *context, struct us_internal_ssl_socket_t *(*on_close)(struct us_internal_ssl_socket_t *s, int code, void *reason)) { - us_socket_context_on_close(0, (struct us_socket_context_t *) context, (struct us_socket_t *(*)(struct us_socket_t *, int, void *)) ssl_on_close); +void us_internal_ssl_socket_context_on_close(struct us_internal_ssl_socket_context_t* context, struct us_internal_ssl_socket_t* (*on_close)(struct us_internal_ssl_socket_t* s, int code, void* reason)) +{ + us_socket_context_on_close(0, (struct us_socket_context_t*)context, (struct us_socket_t * (*)(struct us_socket_t*, int, void*)) ssl_on_close); context->on_close = on_close; } -void us_internal_ssl_socket_context_on_data(struct us_internal_ssl_socket_context_t *context, struct us_internal_ssl_socket_t *(*on_data)(struct us_internal_ssl_socket_t *s, char *data, int length)) { - us_socket_context_on_data(0, (struct us_socket_context_t *) context, (struct us_socket_t *(*)(struct us_socket_t *, char *, int)) ssl_on_data); +void us_internal_ssl_socket_context_on_data(struct us_internal_ssl_socket_context_t* context, struct us_internal_ssl_socket_t* (*on_data)(struct us_internal_ssl_socket_t* s, char* data, int length)) +{ + us_socket_context_on_data(0, (struct us_socket_context_t*)context, (struct us_socket_t * (*)(struct us_socket_t*, char*, int)) ssl_on_data); context->on_data = on_data; } -void us_internal_ssl_socket_context_on_writable(struct us_internal_ssl_socket_context_t *context, struct us_internal_ssl_socket_t *(*on_writable)(struct us_internal_ssl_socket_t *s)) { - us_socket_context_on_writable(0, (struct us_socket_context_t *) context, (struct us_socket_t *(*)(struct us_socket_t *)) ssl_on_writable); +void us_internal_ssl_socket_context_on_writable(struct us_internal_ssl_socket_context_t* context, struct us_internal_ssl_socket_t* (*on_writable)(struct us_internal_ssl_socket_t* s)) +{ + us_socket_context_on_writable(0, (struct us_socket_context_t*)context, (struct us_socket_t * (*)(struct us_socket_t*)) ssl_on_writable); context->on_writable = on_writable; } -void us_internal_ssl_socket_context_on_timeout(struct us_internal_ssl_socket_context_t *context, struct us_internal_ssl_socket_t *(*on_timeout)(struct us_internal_ssl_socket_t *s)) { - us_socket_context_on_timeout(0, (struct us_socket_context_t *) context, (struct us_socket_t *(*)(struct us_socket_t *)) on_timeout); +void us_internal_ssl_socket_context_on_timeout(struct us_internal_ssl_socket_context_t* context, struct us_internal_ssl_socket_t* (*on_timeout)(struct us_internal_ssl_socket_t* s)) +{ + us_socket_context_on_timeout(0, (struct us_socket_context_t*)context, (struct us_socket_t * (*)(struct us_socket_t*)) on_timeout); } -void us_internal_ssl_socket_context_on_long_timeout(struct us_internal_ssl_socket_context_t *context, struct us_internal_ssl_socket_t *(*on_long_timeout)(struct us_internal_ssl_socket_t *s)) { - us_socket_context_on_long_timeout(0, (struct us_socket_context_t *) context, (struct us_socket_t *(*)(struct us_socket_t *)) on_long_timeout); +void us_internal_ssl_socket_context_on_long_timeout(struct us_internal_ssl_socket_context_t* context, struct us_internal_ssl_socket_t* (*on_long_timeout)(struct us_internal_ssl_socket_t* s)) +{ + us_socket_context_on_long_timeout(0, (struct us_socket_context_t*)context, (struct us_socket_t * (*)(struct us_socket_t*)) on_long_timeout); } /* We do not really listen to passed FIN-handler, we entirely override it with our handler since SSL doesn't really have support for half-closed sockets */ -void us_internal_ssl_socket_context_on_end(struct us_internal_ssl_socket_context_t *context, struct us_internal_ssl_socket_t *(*on_end)(struct us_internal_ssl_socket_t *)) { - us_socket_context_on_end(0, (struct us_socket_context_t *) context, (struct us_socket_t *(*)(struct us_socket_t *)) ssl_on_end); +void us_internal_ssl_socket_context_on_end(struct us_internal_ssl_socket_context_t* context, struct us_internal_ssl_socket_t* (*on_end)(struct us_internal_ssl_socket_t*)) +{ + us_socket_context_on_end(0, (struct us_socket_context_t*)context, (struct us_socket_t * (*)(struct us_socket_t*)) ssl_on_end); } -void us_internal_ssl_socket_context_on_connect_error(struct us_internal_ssl_socket_context_t *context, struct us_internal_ssl_socket_t *(*on_connect_error)(struct us_internal_ssl_socket_t *, int code)) { - us_socket_context_on_connect_error(0, (struct us_socket_context_t *) context, (struct us_socket_t *(*)(struct us_socket_t *, int)) on_connect_error); +void us_internal_ssl_socket_context_on_connect_error(struct us_internal_ssl_socket_context_t* context, struct us_internal_ssl_socket_t* (*on_connect_error)(struct us_internal_ssl_socket_t*, int code)) +{ + us_socket_context_on_connect_error(0, (struct us_socket_context_t*)context, (struct us_socket_t * (*)(struct us_socket_t*, int)) on_connect_error); } -void *us_internal_ssl_socket_context_ext(struct us_internal_ssl_socket_context_t *context) { +void* us_internal_ssl_socket_context_ext(struct us_internal_ssl_socket_context_t* context) +{ return context + 1; } /* Per socket functions */ -void *us_internal_ssl_socket_get_native_handle(struct us_internal_ssl_socket_t *s) { +void* us_internal_ssl_socket_get_native_handle(struct us_internal_ssl_socket_t* s) +{ return s->ssl; } -int us_internal_ssl_socket_raw_write(struct us_internal_ssl_socket_t *s, const char *data, int length, int msg_more) { - +int us_internal_ssl_socket_raw_write(struct us_internal_ssl_socket_t* s, const char* data, int length, int msg_more) +{ + if (us_socket_is_closed(0, &s->s) || us_internal_ssl_socket_is_shut_down(s)) { return 0; } return us_socket_write(0, &s->s, data, length, msg_more); } -int us_internal_ssl_socket_write(struct us_internal_ssl_socket_t *s, const char *data, int length, int msg_more) { - +int us_internal_ssl_socket_write(struct us_internal_ssl_socket_t* s, const char* data, int length, int msg_more) +{ if (us_socket_is_closed(0, &s->s) || us_internal_ssl_socket_is_shut_down(s)) { return 0; } - struct us_internal_ssl_socket_context_t *context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); + struct us_internal_ssl_socket_context_t* context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); - struct us_loop_t *loop = us_socket_context_loop(0, &context->sc); - struct loop_ssl_data *loop_ssl_data = (struct loop_ssl_data *) loop->data.ssl_data; + struct us_loop_t* loop = us_socket_context_loop(0, &context->sc); + struct loop_ssl_data* loop_ssl_data = (struct loop_ssl_data*)loop->data.ssl_data; // it makes literally no sense to touch this here! it should start at 0 and ONLY be set and reset by the on_data function! // the way is is now, triggering a write from a read will essentially delete all input data! // what we need to do is to check if this ever is non-zero and print a warning - - loop_ssl_data->ssl_read_input_length = 0; - loop_ssl_data->ssl_socket = &s->s; loop_ssl_data->msg_more = msg_more; loop_ssl_data->last_write_was_msg_more = 0; - //printf("Calling SSL_write\n"); + // printf("Calling SSL_write\n"); int written = SSL_write(s->ssl, data, length); - //printf("Returning from SSL_write\n"); + // printf("Returning from SSL_write\n"); loop_ssl_data->msg_more = 0; if (loop_ssl_data->last_write_was_msg_more && !msg_more) { @@ -1404,32 +1438,33 @@ int us_internal_ssl_socket_write(struct us_internal_ssl_socket_t *s, const char } } -void *us_internal_ssl_socket_ext(struct us_internal_ssl_socket_t *s) { +void* us_internal_ssl_socket_ext(struct us_internal_ssl_socket_t* s) +{ return s + 1; } -int us_internal_ssl_socket_is_shut_down(struct us_internal_ssl_socket_t *s) { - return us_socket_is_shut_down(0, &s->s) || SSL_get_shutdown(s->ssl) & SSL_SENT_SHUTDOWN; +int us_internal_ssl_socket_is_shut_down(struct us_internal_ssl_socket_t* s) +{ + return us_socket_is_shut_down(0, &s->s) || SSL_get_shutdown(s->ssl) & SSL_SENT_SHUTDOWN; } -void us_internal_ssl_socket_shutdown(struct us_internal_ssl_socket_t *s) { +void us_internal_ssl_socket_shutdown(struct us_internal_ssl_socket_t* s) +{ if (!us_socket_is_closed(0, &s->s) && !us_internal_ssl_socket_is_shut_down(s)) { - struct us_internal_ssl_socket_context_t *context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); - struct us_loop_t *loop = us_socket_context_loop(0, &context->sc); - struct loop_ssl_data *loop_ssl_data = (struct loop_ssl_data *) loop->data.ssl_data; + struct us_internal_ssl_socket_context_t* context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); + struct us_loop_t* loop = us_socket_context_loop(0, &context->sc); + struct loop_ssl_data* loop_ssl_data = (struct loop_ssl_data*)loop->data.ssl_data; // also makes no sense to touch this here! // however the idea is that if THIS socket is not the same as ssl_socket then this data is not for me // but this is not correct as it is currently anyways, any data available should be properly reset loop_ssl_data->ssl_read_input_length = 0; - // essentially we need two of these: one for CURRENT CALL and one for CURRENT SOCKET WITH DATA // if those match in the BIO function then you may read, if not then you may not read // we need ssl_read_socket to be set in on_data and checked in the BIO loop_ssl_data->ssl_socket = &s->s; - loop_ssl_data->msg_more = 0; // sets SSL_SENT_SHUTDOWN no matter what (not actually true if error!) @@ -1452,16 +1487,16 @@ void us_internal_ssl_socket_shutdown(struct us_internal_ssl_socket_t *s) { } } -struct us_internal_ssl_socket_t *us_internal_ssl_socket_context_adopt_socket(struct us_internal_ssl_socket_context_t *context, struct us_internal_ssl_socket_t *s, int ext_size) { +struct us_internal_ssl_socket_t* us_internal_ssl_socket_context_adopt_socket(struct us_internal_ssl_socket_context_t* context, struct us_internal_ssl_socket_t* s, int ext_size) +{ // todo: this is completely untested - return (struct us_internal_ssl_socket_t *) us_socket_context_adopt_socket(0, &context->sc, &s->s, sizeof(struct us_internal_ssl_socket_t) - sizeof(struct us_socket_t) + ext_size); + return (struct us_internal_ssl_socket_t*)us_socket_context_adopt_socket(0, &context->sc, &s->s, sizeof(struct us_internal_ssl_socket_t) - sizeof(struct us_socket_t) + ext_size); } - - -struct us_internal_ssl_socket_t * ssl_wrapped_context_on_close(struct us_internal_ssl_socket_t *s, int code, void *reason) { - struct us_internal_ssl_socket_context_t *context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); - struct us_wrapped_socket_context_t* wrapped_context = (struct us_wrapped_socket_context_t *)us_internal_ssl_socket_context_ext(context); +struct us_internal_ssl_socket_t* ssl_wrapped_context_on_close(struct us_internal_ssl_socket_t* s, int code, void* reason) +{ + struct us_internal_ssl_socket_context_t* context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); + struct us_wrapped_socket_context_t* wrapped_context = (struct us_wrapped_socket_context_t*)us_internal_ssl_socket_context_ext(context); if (wrapped_context->events.on_close) { wrapped_context->events.on_close((struct us_socket_t*)s, code, reason); @@ -1475,10 +1510,10 @@ struct us_internal_ssl_socket_t * ssl_wrapped_context_on_close(struct us_interna return s; } - -struct us_internal_ssl_socket_t * ssl_wrapped_context_on_writable(struct us_internal_ssl_socket_t *s) { - struct us_internal_ssl_socket_context_t *context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); - struct us_wrapped_socket_context_t* wrapped_context = (struct us_wrapped_socket_context_t *)us_internal_ssl_socket_context_ext(context); +struct us_internal_ssl_socket_t* ssl_wrapped_context_on_writable(struct us_internal_ssl_socket_t* s) +{ + struct us_internal_ssl_socket_context_t* context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); + struct us_wrapped_socket_context_t* wrapped_context = (struct us_wrapped_socket_context_t*)us_internal_ssl_socket_context_ext(context); if (wrapped_context->events.on_writable) { wrapped_context->events.on_writable((struct us_socket_t*)s); @@ -1492,10 +1527,10 @@ struct us_internal_ssl_socket_t * ssl_wrapped_context_on_writable(struct us_inte return s; } - -struct us_internal_ssl_socket_t * ssl_wrapped_context_on_data(struct us_internal_ssl_socket_t *s, char *data, int length) { - struct us_internal_ssl_socket_context_t *context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); - struct us_wrapped_socket_context_t* wrapped_context = (struct us_wrapped_socket_context_t *)us_internal_ssl_socket_context_ext(context); +struct us_internal_ssl_socket_t* ssl_wrapped_context_on_data(struct us_internal_ssl_socket_t* s, char* data, int length) +{ + struct us_internal_ssl_socket_context_t* context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); + struct us_wrapped_socket_context_t* wrapped_context = (struct us_wrapped_socket_context_t*)us_internal_ssl_socket_context_ext(context); // raw data if needed if (wrapped_context->old_events.on_data) { wrapped_context->old_events.on_data((struct us_socket_t*)s, data, length); @@ -1504,9 +1539,10 @@ struct us_internal_ssl_socket_t * ssl_wrapped_context_on_data(struct us_internal return ssl_on_data(s, data, length); } -struct us_internal_ssl_socket_t * ssl_wrapped_context_on_timeout(struct us_internal_ssl_socket_t * s) { - struct us_internal_ssl_socket_context_t *context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); - struct us_wrapped_socket_context_t* wrapped_context = (struct us_wrapped_socket_context_t *)us_internal_ssl_socket_context_ext(context); +struct us_internal_ssl_socket_t* ssl_wrapped_context_on_timeout(struct us_internal_ssl_socket_t* s) +{ + struct us_internal_ssl_socket_context_t* context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); + struct us_wrapped_socket_context_t* wrapped_context = (struct us_wrapped_socket_context_t*)us_internal_ssl_socket_context_ext(context); if (wrapped_context->events.on_timeout) { wrapped_context->events.on_timeout((struct us_socket_t*)s); @@ -1519,9 +1555,10 @@ struct us_internal_ssl_socket_t * ssl_wrapped_context_on_timeout(struct us_inter return s; } -struct us_internal_ssl_socket_t * ssl_wrapped_context_on_long_timeout(struct us_internal_ssl_socket_t * s) { - struct us_internal_ssl_socket_context_t *context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); - struct us_wrapped_socket_context_t* wrapped_context = (struct us_wrapped_socket_context_t *)us_internal_ssl_socket_context_ext(context); +struct us_internal_ssl_socket_t* ssl_wrapped_context_on_long_timeout(struct us_internal_ssl_socket_t* s) +{ + struct us_internal_ssl_socket_context_t* context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); + struct us_wrapped_socket_context_t* wrapped_context = (struct us_wrapped_socket_context_t*)us_internal_ssl_socket_context_ext(context); if (wrapped_context->events.on_long_timeout) { wrapped_context->events.on_long_timeout((struct us_socket_t*)s); @@ -1534,9 +1571,10 @@ struct us_internal_ssl_socket_t * ssl_wrapped_context_on_long_timeout(struct us return s; } -struct us_internal_ssl_socket_t * ssl_wrapped_context_on_end(struct us_internal_ssl_socket_t * s) { - struct us_internal_ssl_socket_context_t *context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); - struct us_wrapped_socket_context_t* wrapped_context = (struct us_wrapped_socket_context_t *)us_internal_ssl_socket_context_ext(context); +struct us_internal_ssl_socket_t* ssl_wrapped_context_on_end(struct us_internal_ssl_socket_t* s) +{ + struct us_internal_ssl_socket_context_t* context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); + struct us_wrapped_socket_context_t* wrapped_context = (struct us_wrapped_socket_context_t*)us_internal_ssl_socket_context_ext(context); if (wrapped_context->events.on_end) { wrapped_context->events.on_end((struct us_socket_t*)s); @@ -1548,9 +1586,10 @@ struct us_internal_ssl_socket_t * ssl_wrapped_context_on_end(struct us_internal return s; } -struct us_internal_ssl_socket_t * ssl_wrapped_on_connect_error(struct us_internal_ssl_socket_t * s, int code) { - struct us_internal_ssl_socket_context_t *context = (struct us_internal_ssl_socket_context_t *) us_socket_context(0, &s->s); - struct us_wrapped_socket_context_t* wrapped_context = (struct us_wrapped_socket_context_t *)us_internal_ssl_socket_context_ext(context); +struct us_internal_ssl_socket_t* ssl_wrapped_on_connect_error(struct us_internal_ssl_socket_t* s, int code) +{ + struct us_internal_ssl_socket_context_t* context = (struct us_internal_ssl_socket_context_t*)us_socket_context(0, &s->s); + struct us_wrapped_socket_context_t* wrapped_context = (struct us_wrapped_socket_context_t*)us_internal_ssl_socket_context_ext(context); if (wrapped_context->events.on_connect_error) { wrapped_context->events.on_connect_error((struct us_socket_t*)s, code); @@ -1562,30 +1601,33 @@ struct us_internal_ssl_socket_t * ssl_wrapped_on_connect_error(struct us_interna return s; } -struct us_internal_ssl_socket_t* us_internal_ssl_socket_open(struct us_internal_ssl_socket_t * s, int is_client, char* ip, int ip_length) { +struct us_internal_ssl_socket_t* us_internal_ssl_socket_open(struct us_internal_ssl_socket_t* s, int is_client, char* ip, int ip_length) +{ // closed if (us_socket_is_closed(0, &s->s)) { return s; } // already opened - if (s->ssl) return s; + if (s->ssl) + return s; // start SSL open return ssl_on_open(s, is_client, ip, ip_length); } -struct us_internal_ssl_socket_t *us_internal_ssl_socket_wrap_with_tls(struct us_socket_t *s, struct us_bun_socket_context_options_t options, struct us_socket_events_t events, int socket_ext_size) { +struct us_internal_ssl_socket_t* us_internal_ssl_socket_wrap_with_tls(struct us_socket_t* s, struct us_bun_socket_context_options_t options, struct us_socket_events_t events, int socket_ext_size) +{ /* Cannot wrap a closed socket */ if (us_socket_is_closed(0, s)) { return NULL; } - struct us_socket_context_t * old_context = us_socket_context(0, s); - - struct us_socket_context_t * context = us_create_bun_socket_context(1, old_context->loop, sizeof(struct us_wrapped_socket_context_t), options); - struct us_internal_ssl_socket_context_t *tls_context = (struct us_internal_ssl_socket_context_t *) context; + struct us_socket_context_t* old_context = us_socket_context(0, s); - struct us_wrapped_socket_context_t* wrapped_context = (struct us_wrapped_socket_context_t *)us_internal_ssl_socket_context_ext(tls_context); + struct us_socket_context_t* context = us_create_bun_socket_context(1, old_context->loop, sizeof(struct us_wrapped_socket_context_t), options); + struct us_internal_ssl_socket_context_t* tls_context = (struct us_internal_ssl_socket_context_t*)context; + + struct us_wrapped_socket_context_t* wrapped_context = (struct us_wrapped_socket_context_t*)us_internal_ssl_socket_context_ext(tls_context); // we need to fire this events on the old context struct us_socket_events_t old_events = (struct us_socket_events_t) { .on_close = old_context->on_close, @@ -1599,41 +1641,40 @@ struct us_internal_ssl_socket_t *us_internal_ssl_socket_wrap_with_tls(struct us_ wrapped_context->old_events = old_events; wrapped_context->events = events; - // no need to wrap open because socket is already open (only new context will be called so we can configure hostname and ssl stuff normally here before handshake) - tls_context->on_open = (struct us_internal_ssl_socket_t *(*)(struct us_internal_ssl_socket_t *, int, char *, int))events.on_open; - + tls_context->on_open = (struct us_internal_ssl_socket_t * (*)(struct us_internal_ssl_socket_t*, int, char*, int)) events.on_open; + // on handshake is not available on the old context so we just add this - if(events.on_handshake){ - us_internal_on_ssl_handshake(tls_context, (void (*)(struct us_internal_ssl_socket_t *, int, struct us_bun_verify_error_t, void*))events.on_handshake, NULL); + if (events.on_handshake) { + us_internal_on_ssl_handshake(tls_context, (void (*)(struct us_internal_ssl_socket_t*, int, struct us_bun_verify_error_t, void*))events.on_handshake, NULL); } // we need to wrap these events because we need to call the old context events as well - us_socket_context_on_connect_error(0, context, (struct us_socket_t *(*)(struct us_socket_t *, int)) ssl_wrapped_on_connect_error); - us_socket_context_on_end(0, context, (struct us_socket_t *(*)(struct us_socket_t *)) ssl_wrapped_context_on_end); - us_socket_context_on_long_timeout(0, context, (struct us_socket_t *(*)(struct us_socket_t *)) ssl_wrapped_context_on_long_timeout); - us_socket_context_on_timeout(0, context, (struct us_socket_t *(*)(struct us_socket_t *)) ssl_wrapped_context_on_timeout); - + us_socket_context_on_connect_error(0, context, (struct us_socket_t * (*)(struct us_socket_t*, int)) ssl_wrapped_on_connect_error); + us_socket_context_on_end(0, context, (struct us_socket_t * (*)(struct us_socket_t*)) ssl_wrapped_context_on_end); + us_socket_context_on_long_timeout(0, context, (struct us_socket_t * (*)(struct us_socket_t*)) ssl_wrapped_context_on_long_timeout); + us_socket_context_on_timeout(0, context, (struct us_socket_t * (*)(struct us_socket_t*)) ssl_wrapped_context_on_timeout); + // special case this will be called after ssl things are done // called from ssl_on_data handler is called inside ssl_wrapped_context_on_data - tls_context->on_data = (struct us_internal_ssl_socket_t *(*)(struct us_internal_ssl_socket_t *, char *, int))events.on_data; - us_socket_context_on_data(0, context, (struct us_socket_t *(*)(struct us_socket_t *, char *, int)) ssl_wrapped_context_on_data); - + tls_context->on_data = (struct us_internal_ssl_socket_t * (*)(struct us_internal_ssl_socket_t*, char*, int)) events.on_data; + us_socket_context_on_data(0, context, (struct us_socket_t * (*)(struct us_socket_t*, char*, int)) ssl_wrapped_context_on_data); + // here is the inverse of the above ssl_on_writable will call ssl_wrapped_context_on_writable tls_context->on_writable = ssl_wrapped_context_on_writable; - us_socket_context_on_writable(0, context, (struct us_socket_t *(*)(struct us_socket_t *)) ssl_on_writable); + us_socket_context_on_writable(0, context, (struct us_socket_t * (*)(struct us_socket_t*)) ssl_on_writable); tls_context->on_close = ssl_wrapped_context_on_close; - us_socket_context_on_close(0, context, (struct us_socket_t *(*)(struct us_socket_t *, int, void *)) ssl_on_close); - + us_socket_context_on_close(0, context, (struct us_socket_t * (*)(struct us_socket_t*, int, void*)) ssl_on_close); + // will resize to tls + ext size - struct us_internal_ssl_socket_t * socket = (struct us_internal_ssl_socket_t *) us_socket_context_adopt_socket(0, context, s, sizeof(struct us_internal_ssl_socket_t) - sizeof(struct us_socket_t) + socket_ext_size); + struct us_internal_ssl_socket_t* socket = (struct us_internal_ssl_socket_t*)us_socket_context_adopt_socket(0, context, s, sizeof(struct us_internal_ssl_socket_t) - sizeof(struct us_socket_t) + socket_ext_size); socket->ssl = NULL; socket->ssl_write_wants_read = 0; socket->ssl_read_wants_write = 0; return socket; -} +} #endif diff --git a/packages/bun-usockets/src/socket.c b/packages/bun-usockets/src/socket.c index 03f774aa4b..9c3fa0d56c 100644 --- a/packages/bun-usockets/src/socket.c +++ b/packages/bun-usockets/src/socket.c @@ -204,21 +204,22 @@ struct us_socket_t *us_socket_attach(int ssl, LIBUS_SOCKET_DESCRIPTOR client_fd, } struct us_socket_t *us_socket_pair(struct us_socket_context_t *ctx, int socket_ext_size, LIBUS_SOCKET_DESCRIPTOR* fds) { -#ifdef LIBUS_USE_LIBUV +#if defined(LIBUS_USE_LIBUV) || defined(WIN32) return 0; -#endif +#else if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) != 0) { return 0; } return us_socket_from_fd(ctx, socket_ext_size, fds[0]); +#endif } struct us_socket_t *us_socket_from_fd(struct us_socket_context_t *ctx, int socket_ext_size, LIBUS_SOCKET_DESCRIPTOR fd) { -#ifdef LIBUS_USE_LIBUV +#if defined(LIBUS_USE_LIBUV) || defined(WIN32) return 0; -#endif +#else struct us_poll_t *p1 = us_create_poll(ctx->loop, 0, sizeof(struct us_socket_t) + socket_ext_size); us_poll_init(p1, fd, POLL_TYPE_SOCKET); us_poll_start(p1, ctx->loop, LIBUS_SOCKET_READABLE | LIBUS_SOCKET_WRITABLE); @@ -239,6 +240,7 @@ struct us_socket_t *us_socket_from_fd(struct us_socket_context_t *ctx, int socke } return s; +#endif } diff --git a/src/bun.js/WebKit b/src/bun.js/WebKit index 1a49a1f94b..a780bdf025 160000 --- a/src/bun.js/WebKit +++ b/src/bun.js/WebKit @@ -1 +1 @@ -Subproject commit 1a49a1f94bf42ab4f8c6b11d7bbbb21e491d2d62 +Subproject commit a780bdf0255ae1a7ed15e4b3f31c14af705facae diff --git a/src/bun.js/bindings/JSDOMFile.cpp b/src/bun.js/bindings/JSDOMFile.cpp index b0d5a33e47..4e0e4bf482 100644 --- a/src/bun.js/bindings/JSDOMFile.cpp +++ b/src/bun.js/bindings/JSDOMFile.cpp @@ -97,6 +97,7 @@ public: { auto scope = DECLARE_THROW_SCOPE(lexicalGlobalObject->vm()); throwTypeError(lexicalGlobalObject, scope, "Class constructor File cannot be invoked without 'new"_s); + return {}; } }; diff --git a/src/bun.js/bindings/KeyObject.cpp b/src/bun.js/bindings/KeyObject.cpp index 301d36afc6..d770c67a5b 100644 --- a/src/bun.js/bindings/KeyObject.cpp +++ b/src/bun.js/bindings/KeyObject.cpp @@ -145,7 +145,7 @@ AsymmetricKeyValueWithDER KeyObject__ParsePublicKeyPEM(const char* key_pem, size_t key_pem_len) { auto bp = BIOPtr(BIO_new_mem_buf(const_cast(key_pem), key_pem_len)); - auto result = (AsymmetricKeyValueWithDER) { .key = nullptr, .der_data = nullptr, .der_len = 0 }; + auto result = AsymmetricKeyValueWithDER { .key = nullptr, .der_data = nullptr, .der_len = 0 }; if (!bp) { ERR_clear_error(); @@ -2188,7 +2188,9 @@ JSC::EncodedJSValue KeyObject__generateKeySync(JSC::JSGlobalObject* lexicalGloba throwException(lexicalGlobalObject, scope, createTypeError(lexicalGlobalObject, "Invalid length"_s)); return JSValue::encode(JSC::jsUndefined()); } - return JSC::JSValue::encode(JSCryptoKey::create(structure, zigGlobalObject, WTFMove(result.releaseNonNull()))); + // TODO(@paperdave 2023-10-19): i removed WTFMove from result.releaseNonNull() as per MSVC compiler error. + // We need to evaluate if that is the proper fix here. + return JSC::JSValue::encode(JSCryptoKey::create(structure, zigGlobalObject, (result.releaseNonNull()))); } else if (type_str == "aes"_s) { Zig::GlobalObject* zigGlobalObject = reinterpret_cast(lexicalGlobalObject); auto* structure = zigGlobalObject->JSCryptoKeyStructure(); @@ -2207,7 +2209,9 @@ JSC::EncodedJSValue KeyObject__generateKeySync(JSC::JSGlobalObject* lexicalGloba throwException(lexicalGlobalObject, scope, createTypeError(lexicalGlobalObject, "Invalid length"_s)); return JSValue::encode(JSC::jsUndefined()); } - return JSC::JSValue::encode(JSCryptoKey::create(structure, zigGlobalObject, WTFMove(result.releaseNonNull()))); + // TODO(@paperdave 2023-10-19): i removed WTFMove from result.releaseNonNull() as per MSVC compiler error. + // We need to evaluate if that is the proper fix here. + return JSC::JSValue::encode(JSCryptoKey::create(structure, zigGlobalObject, (result.releaseNonNull()))); } else { throwException(lexicalGlobalObject, scope, createTypeError(lexicalGlobalObject, "algorithm should be 'aes' or 'hmac'"_s)); return JSValue::encode(JSC::jsUndefined()); @@ -2279,23 +2283,23 @@ static AsymmetricKeyValue GetInternalAsymmetricKey(WebCore::CryptoKey& key) case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5: case CryptoAlgorithmIdentifier::RSA_OAEP: case CryptoAlgorithmIdentifier::RSA_PSS: - return (AsymmetricKeyValue) { .key = downcast(key).platformKey(), .owned = false }; + return AsymmetricKeyValue { .key = downcast(key).platformKey(), .owned = false }; case CryptoAlgorithmIdentifier::ECDSA: case CryptoAlgorithmIdentifier::ECDH: - return (AsymmetricKeyValue) { .key = downcast(key).platformKey(), .owned = false }; + return AsymmetricKeyValue { .key = downcast(key).platformKey(), .owned = false }; case CryptoAlgorithmIdentifier::Ed25519: { const auto& okpKey = downcast(key); auto keyData = okpKey.exportKey(); if (okpKey.type() == CryptoKeyType::Private) { auto* evp_key = EVP_PKEY_new_raw_private_key(okpKey.namedCurve() == CryptoKeyOKP::NamedCurve::X25519 ? EVP_PKEY_X25519 : EVP_PKEY_ED25519, nullptr, keyData.data(), keyData.size()); - return (AsymmetricKeyValue) { .key = evp_key, .owned = true }; + return AsymmetricKeyValue { .key = evp_key, .owned = true }; } else { auto* evp_key = EVP_PKEY_new_raw_public_key(okpKey.namedCurve() == CryptoKeyOKP::NamedCurve::X25519 ? EVP_PKEY_X25519 : EVP_PKEY_ED25519, nullptr, keyData.data(), keyData.size()); - return (AsymmetricKeyValue) { .key = evp_key, .owned = true }; + return AsymmetricKeyValue { .key = evp_key, .owned = true }; } } default: - return (AsymmetricKeyValue) { .key = NULL, .owned = false }; + return AsymmetricKeyValue { .key = NULL, .owned = false }; } } diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 711a3ae1ad..cee1cd0be5 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -448,7 +448,11 @@ static String computeErrorInfoWithPrepareStackTrace(JSC::VM& vm, Zig::GlobalObje // We need to sourcemap it if it's a GlobalObject. if (globalObject == lexicalGlobalObject) { size_t framesCount = stackTrace.size(); +#if OS(WINDOWS) // MSVC workaround + ZigStackFrame* remappedFrames = new ZigStackFrame[framesCount]; +#else ZigStackFrame remappedFrames[framesCount]; +#endif for (int i = 0; i < framesCount; i++) { memset(remappedFrames + i, 0, sizeof(ZigStackFrame)); remappedFrames[i].source_url = Bun::toString(lexicalGlobalObject, stackTrace.at(i).sourceURL()); @@ -476,6 +480,9 @@ static String computeErrorInfoWithPrepareStackTrace(JSC::VM& vm, Zig::GlobalObje callSite->setLineNumber(lineNumber); } } +#if OS(WINDOWS) // MSVC workaround + delete remappedFrames; +#endif } globalObject->formatStackTrace(vm, lexicalGlobalObject, errorObject, callSites, prepareStackTrace); @@ -3540,12 +3547,12 @@ JSC_DEFINE_CUSTOM_GETTER(getConsoleStdout, (JSGlobalObject * globalObject, Encod auto global = jsCast(globalObject); // instead of calling the constructor builtin, go through the process.stdout getter to ensure it's only created once. - auto stdout = global->processObject()->get(globalObject, Identifier::fromString(vm, "stdout"_s)); - if (!stdout) + auto stdoutValue = global->processObject()->get(globalObject, Identifier::fromString(vm, "stdout"_s)); + if (!stdoutValue) return JSValue::encode({}); - console->putDirect(vm, property, stdout, PropertyAttribute::DontEnum | 0); - return JSValue::encode(stdout); + console->putDirect(vm, property, stdoutValue, PropertyAttribute::DontEnum | 0); + return JSValue::encode(stdoutValue); } // `console._stderr` is equal to `process.stderr` @@ -3556,12 +3563,12 @@ JSC_DEFINE_CUSTOM_GETTER(getConsoleStderr, (JSGlobalObject * globalObject, Encod auto global = jsCast(globalObject); // instead of calling the constructor builtin, go through the process.stdout getter to ensure it's only created once. - auto stdout = global->processObject()->get(globalObject, Identifier::fromString(vm, "stderr"_s)); - if (!stdout) + auto stderrValue = global->processObject()->get(globalObject, Identifier::fromString(vm, "stderr"_s)); + if (!stderrValue) return JSValue::encode({}); - console->putDirect(vm, property, stdout, PropertyAttribute::DontEnum | 0); - return JSValue::encode(stdout); + console->putDirect(vm, property, stderrValue, PropertyAttribute::DontEnum | 0); + return JSValue::encode(stderrValue); } JSC_DEFINE_CUSTOM_SETTER(EventSource_setter, diff --git a/src/bun.js/bindings/c-bindings.cpp b/src/bun.js/bindings/c-bindings.cpp index a8f8efdd26..4edcad6dfa 100644 --- a/src/bun.js/bindings/c-bindings.cpp +++ b/src/bun.js/bindings/c-bindings.cpp @@ -1,8 +1,6 @@ // when we don't want to use @cInclude, we can just stick wrapper functions here #include "root.h" -#include #include -#include "root.h" #if !OS(WINDOWS) #include @@ -10,14 +8,13 @@ #include #include #include +#include +#include #else #include #endif // !OS(WINDOWS) -#if CPU(X86_64) -#include -#include - +#if CPU(X86_64) && !OS(WINDOWS) extern "C" void bun_warn_avx_missing(const char* url) { __builtin_cpu_init(); diff --git a/src/bun.js/bindings/cmakeconfig.h b/src/bun.js/bindings/cmakeconfig.h new file mode 100644 index 0000000000..b73452d767 --- /dev/null +++ b/src/bun.js/bindings/cmakeconfig.h @@ -0,0 +1,887 @@ +#ifndef CMAKECONFIG_H +#define CMAKECONFIG_H + +#define ALLOW_LINE_AND_COLUMN_NUMBER_IN_BUILTINS 1 +#define ENABLE_3D_TRANSFORMS 1 +#define ENABLE_3D_TRANSFORMS 1 +#define ENABLE_3D_TRANSFORMS 1 +#define ENABLE_3D_TRANSFORMS 1 +#define ENABLE_3D_TRANSFORMS 1 +#define ENABLE_3D_TRANSFORMS 1 +#define ENABLE_ACCESSIBILITY 1 +#define ENABLE_ACCESSIBILITY 1 +#define ENABLE_ACCESSIBILITY 1 +#define ENABLE_ACCESSIBILITY 1 +#define ENABLE_ACCESSIBILITY 1 +#define ENABLE_ACCESSIBILITY 1 +#define ENABLE_ACCESSIBILITY_ISOLATED_TREE 0 +#define ENABLE_ACCESSIBILITY_ISOLATED_TREE 0 +#define ENABLE_ACCESSIBILITY_ISOLATED_TREE 0 +#define ENABLE_ACCESSIBILITY_ISOLATED_TREE 0 +#define ENABLE_ACCESSIBILITY_ISOLATED_TREE 0 +#define ENABLE_ACCESSIBILITY_ISOLATED_TREE 0 +#define ENABLE_API_TESTS 0 +#define ENABLE_API_TESTS 0 +#define ENABLE_API_TESTS 0 +#define ENABLE_API_TESTS 0 +#define ENABLE_API_TESTS 0 +#define ENABLE_API_TESTS 0 +#define ENABLE_APPLE_PAY 0 +#define ENABLE_APPLE_PAY 0 +#define ENABLE_APPLE_PAY 0 +#define ENABLE_APPLE_PAY 0 +#define ENABLE_APPLE_PAY 0 +#define ENABLE_APPLE_PAY 0 +#define ENABLE_APPLICATION_MANIFEST 0 +#define ENABLE_APPLICATION_MANIFEST 0 +#define ENABLE_APPLICATION_MANIFEST 0 +#define ENABLE_APPLICATION_MANIFEST 0 +#define ENABLE_APPLICATION_MANIFEST 0 +#define ENABLE_APPLICATION_MANIFEST 0 +#define ENABLE_ASYNC_SCROLLING 0 +#define ENABLE_ASYNC_SCROLLING 0 +#define ENABLE_ASYNC_SCROLLING 0 +#define ENABLE_ASYNC_SCROLLING 0 +#define ENABLE_ASYNC_SCROLLING 0 +#define ENABLE_ASYNC_SCROLLING 0 +#define ENABLE_ATTACHMENT_ELEMENT 0 +#define ENABLE_ATTACHMENT_ELEMENT 0 +#define ENABLE_ATTACHMENT_ELEMENT 0 +#define ENABLE_ATTACHMENT_ELEMENT 0 +#define ENABLE_ATTACHMENT_ELEMENT 0 +#define ENABLE_ATTACHMENT_ELEMENT 0 +#define ENABLE_AUTOCAPITALIZE 0 +#define ENABLE_AUTOCAPITALIZE 0 +#define ENABLE_AUTOCAPITALIZE 0 +#define ENABLE_AUTOCAPITALIZE 0 +#define ENABLE_AUTOCAPITALIZE 0 +#define ENABLE_AUTOCAPITALIZE 0 +#define ENABLE_AVF_CAPTIONS 0 +#define ENABLE_AVF_CAPTIONS 0 +#define ENABLE_AVF_CAPTIONS 0 +#define ENABLE_AVF_CAPTIONS 0 +#define ENABLE_AVF_CAPTIONS 0 +#define ENABLE_AVF_CAPTIONS 0 +#define ENABLE_BREAKPAD 0 +#define ENABLE_BREAKPAD 0 +#define ENABLE_BREAKPAD 0 +#define ENABLE_BREAKPAD 0 +#define ENABLE_BREAKPAD 0 +#define ENABLE_BREAKPAD 0 +#define ENABLE_BUBBLEWRAP_SANDBOX 0 +#define ENABLE_BUBBLEWRAP_SANDBOX 0 +#define ENABLE_BUBBLEWRAP_SANDBOX 0 +#define ENABLE_BUBBLEWRAP_SANDBOX 0 +#define ENABLE_BUBBLEWRAP_SANDBOX 0 +#define ENABLE_BUBBLEWRAP_SANDBOX 0 +#define ENABLE_BUN_SKIP_FAILING_ASSERTIONS 0 +#define ENABLE_CACHE_PARTITIONING 0 +#define ENABLE_CACHE_PARTITIONING 0 +#define ENABLE_CACHE_PARTITIONING 0 +#define ENABLE_CACHE_PARTITIONING 0 +#define ENABLE_CACHE_PARTITIONING 0 +#define ENABLE_CACHE_PARTITIONING 0 +#define ENABLE_CHANNEL_MESSAGING 1 +#define ENABLE_CHANNEL_MESSAGING 1 +#define ENABLE_CHANNEL_MESSAGING 1 +#define ENABLE_CHANNEL_MESSAGING 1 +#define ENABLE_CHANNEL_MESSAGING 1 +#define ENABLE_CHANNEL_MESSAGING 1 +#define ENABLE_COG 0 +#define ENABLE_COG 0 +#define ENABLE_COG 0 +#define ENABLE_COG 0 +#define ENABLE_COG 0 +#define ENABLE_COG 0 +#define ENABLE_CONTENT_EXTENSIONS 0 +#define ENABLE_CONTENT_EXTENSIONS 0 +#define ENABLE_CONTENT_EXTENSIONS 0 +#define ENABLE_CONTENT_EXTENSIONS 0 +#define ENABLE_CONTENT_EXTENSIONS 0 +#define ENABLE_CONTENT_EXTENSIONS 0 +#define ENABLE_CONTENT_FILTERING 0 +#define ENABLE_CONTENT_FILTERING 0 +#define ENABLE_CONTENT_FILTERING 0 +#define ENABLE_CONTENT_FILTERING 0 +#define ENABLE_CONTENT_FILTERING 0 +#define ENABLE_CONTENT_FILTERING 0 +#define ENABLE_CONTEXT_MENUS 1 +#define ENABLE_CONTEXT_MENUS 1 +#define ENABLE_CONTEXT_MENUS 1 +#define ENABLE_CONTEXT_MENUS 1 +#define ENABLE_CONTEXT_MENUS 1 +#define ENABLE_CONTEXT_MENUS 1 +#define ENABLE_CORE_IMAGE_ACCELERATED_FILTER_RENDER 0 +#define ENABLE_CORE_IMAGE_ACCELERATED_FILTER_RENDER 0 +#define ENABLE_CORE_IMAGE_ACCELERATED_FILTER_RENDER 0 +#define ENABLE_CORE_IMAGE_ACCELERATED_FILTER_RENDER 0 +#define ENABLE_CORE_IMAGE_ACCELERATED_FILTER_RENDER 0 +#define ENABLE_CORE_IMAGE_ACCELERATED_FILTER_RENDER 0 +#define ENABLE_CSS_BOX_DECORATION_BREAK 1 +#define ENABLE_CSS_BOX_DECORATION_BREAK 1 +#define ENABLE_CSS_BOX_DECORATION_BREAK 1 +#define ENABLE_CSS_BOX_DECORATION_BREAK 1 +#define ENABLE_CSS_BOX_DECORATION_BREAK 1 +#define ENABLE_CSS_BOX_DECORATION_BREAK 1 +#define ENABLE_CSS_COMPOSITING 1 +#define ENABLE_CSS_COMPOSITING 1 +#define ENABLE_CSS_COMPOSITING 1 +#define ENABLE_CSS_COMPOSITING 1 +#define ENABLE_CSS_COMPOSITING 1 +#define ENABLE_CSS_COMPOSITING 1 +#define ENABLE_CSS_CONIC_GRADIENTS 0 +#define ENABLE_CSS_CONIC_GRADIENTS 0 +#define ENABLE_CSS_CONIC_GRADIENTS 0 +#define ENABLE_CSS_CONIC_GRADIENTS 0 +#define ENABLE_CSS_CONIC_GRADIENTS 0 +#define ENABLE_CSS_CONIC_GRADIENTS 0 +#define ENABLE_CSS_PAINTING_API 0 +#define ENABLE_CSS_PAINTING_API 0 +#define ENABLE_CSS_PAINTING_API 0 +#define ENABLE_CSS_PAINTING_API 0 +#define ENABLE_CSS_PAINTING_API 0 +#define ENABLE_CSS_PAINTING_API 0 +#define ENABLE_CURSOR_VISIBILITY 0 +#define ENABLE_CURSOR_VISIBILITY 0 +#define ENABLE_CURSOR_VISIBILITY 0 +#define ENABLE_CURSOR_VISIBILITY 0 +#define ENABLE_CURSOR_VISIBILITY 0 +#define ENABLE_CURSOR_VISIBILITY 0 +#define ENABLE_C_LOOP 0 +#define ENABLE_C_LOOP 0 +#define ENABLE_C_LOOP 0 +#define ENABLE_C_LOOP 0 +#define ENABLE_C_LOOP 0 +#define ENABLE_C_LOOP 0 +#define ENABLE_DARK_MODE_CSS 0 +#define ENABLE_DARK_MODE_CSS 0 +#define ENABLE_DARK_MODE_CSS 0 +#define ENABLE_DARK_MODE_CSS 0 +#define ENABLE_DARK_MODE_CSS 0 +#define ENABLE_DARK_MODE_CSS 0 +#define ENABLE_DATACUE_VALUE 0 +#define ENABLE_DATACUE_VALUE 0 +#define ENABLE_DATACUE_VALUE 0 +#define ENABLE_DATACUE_VALUE 0 +#define ENABLE_DATACUE_VALUE 0 +#define ENABLE_DATACUE_VALUE 0 +#define ENABLE_DATALIST_ELEMENT 0 +#define ENABLE_DATALIST_ELEMENT 0 +#define ENABLE_DATALIST_ELEMENT 0 +#define ENABLE_DATALIST_ELEMENT 0 +#define ENABLE_DATALIST_ELEMENT 0 +#define ENABLE_DATALIST_ELEMENT 0 +#define ENABLE_DEVICE_ORIENTATION 0 +#define ENABLE_DEVICE_ORIENTATION 0 +#define ENABLE_DEVICE_ORIENTATION 0 +#define ENABLE_DEVICE_ORIENTATION 0 +#define ENABLE_DEVICE_ORIENTATION 0 +#define ENABLE_DEVICE_ORIENTATION 0 +#define ENABLE_DFG_JIT 1 +#define ENABLE_DFG_JIT 1 +#define ENABLE_DFG_JIT 1 +#define ENABLE_DFG_JIT 1 +#define ENABLE_DFG_JIT 1 +#define ENABLE_DFG_JIT 1 +#define ENABLE_DOWNLOAD_ATTRIBUTE 0 +#define ENABLE_DOWNLOAD_ATTRIBUTE 0 +#define ENABLE_DOWNLOAD_ATTRIBUTE 0 +#define ENABLE_DOWNLOAD_ATTRIBUTE 0 +#define ENABLE_DOWNLOAD_ATTRIBUTE 0 +#define ENABLE_DOWNLOAD_ATTRIBUTE 0 +#define ENABLE_DRAG_SUPPORT 0 +#define ENABLE_DRAG_SUPPORT 0 +#define ENABLE_DRAG_SUPPORT 0 +#define ENABLE_DRAG_SUPPORT 0 +#define ENABLE_DRAG_SUPPORT 0 +#define ENABLE_DRAG_SUPPORT 0 +#define ENABLE_ENCRYPTED_MEDIA 0 +#define ENABLE_ENCRYPTED_MEDIA 0 +#define ENABLE_ENCRYPTED_MEDIA 0 +#define ENABLE_ENCRYPTED_MEDIA 0 +#define ENABLE_ENCRYPTED_MEDIA 0 +#define ENABLE_ENCRYPTED_MEDIA 0 +#define ENABLE_EXPERIMENTAL_FEATURES 0 +#define ENABLE_EXPERIMENTAL_FEATURES 0 +#define ENABLE_EXPERIMENTAL_FEATURES 0 +#define ENABLE_EXPERIMENTAL_FEATURES 0 +#define ENABLE_EXPERIMENTAL_FEATURES 0 +#define ENABLE_EXPERIMENTAL_FEATURES 0 +#define ENABLE_EXPERIMENTAL_FEATURES 0 +#define ENABLE_FILTERS_LEVEL_2 0 +#define ENABLE_FILTERS_LEVEL_2 0 +#define ENABLE_FILTERS_LEVEL_2 0 +#define ENABLE_FILTERS_LEVEL_2 0 +#define ENABLE_FILTERS_LEVEL_2 0 +#define ENABLE_FILTERS_LEVEL_2 0 +#define ENABLE_FTL_JIT 0 +#define ENABLE_FTL_JIT 0 +#define ENABLE_FTL_JIT 0 +#define ENABLE_FTL_JIT 0 +#define ENABLE_FTL_JIT 0 +#define ENABLE_FTL_JIT 0 +#define ENABLE_FTPDIR 1 +#define ENABLE_FTPDIR 1 +#define ENABLE_FTPDIR 1 +#define ENABLE_FTPDIR 1 +#define ENABLE_FTPDIR 1 +#define ENABLE_FTPDIR 1 +#define ENABLE_FULLSCREEN_API 1 +#define ENABLE_FULLSCREEN_API 1 +#define ENABLE_FULLSCREEN_API 1 +#define ENABLE_FULLSCREEN_API 1 +#define ENABLE_FULLSCREEN_API 1 +#define ENABLE_FULLSCREEN_API 1 +#define ENABLE_GAMEPAD 0 +#define ENABLE_GAMEPAD 0 +#define ENABLE_GAMEPAD 0 +#define ENABLE_GAMEPAD 0 +#define ENABLE_GAMEPAD 0 +#define ENABLE_GAMEPAD 0 +#define ENABLE_GEOLOCATION 1 +#define ENABLE_GEOLOCATION 1 +#define ENABLE_GEOLOCATION 1 +#define ENABLE_GEOLOCATION 1 +#define ENABLE_GEOLOCATION 1 +#define ENABLE_GEOLOCATION 1 +#define ENABLE_GPU_PROCESS 0 +#define ENABLE_GPU_PROCESS 0 +#define ENABLE_GPU_PROCESS 0 +#define ENABLE_GPU_PROCESS 0 +#define ENABLE_GPU_PROCESS 0 +#define ENABLE_GPU_PROCESS 0 +#define ENABLE_IMAGE_DIFF 1 +#define ENABLE_IMAGE_DIFF 1 +#define ENABLE_IMAGE_DIFF 1 +#define ENABLE_IMAGE_DIFF 1 +#define ENABLE_IMAGE_DIFF 1 +#define ENABLE_IMAGE_DIFF 1 +#define ENABLE_INPUT_TYPE_COLOR 0 +#define ENABLE_INPUT_TYPE_COLOR 0 +#define ENABLE_INPUT_TYPE_COLOR 0 +#define ENABLE_INPUT_TYPE_COLOR 0 +#define ENABLE_INPUT_TYPE_COLOR 0 +#define ENABLE_INPUT_TYPE_COLOR 0 +#define ENABLE_INPUT_TYPE_DATE 0 +#define ENABLE_INPUT_TYPE_DATE 0 +#define ENABLE_INPUT_TYPE_DATE 0 +#define ENABLE_INPUT_TYPE_DATE 0 +#define ENABLE_INPUT_TYPE_DATE 0 +#define ENABLE_INPUT_TYPE_DATE 0 +#define ENABLE_INPUT_TYPE_DATETIMELOCAL 0 +#define ENABLE_INPUT_TYPE_DATETIMELOCAL 0 +#define ENABLE_INPUT_TYPE_DATETIMELOCAL 0 +#define ENABLE_INPUT_TYPE_DATETIMELOCAL 0 +#define ENABLE_INPUT_TYPE_DATETIMELOCAL 0 +#define ENABLE_INPUT_TYPE_DATETIMELOCAL 0 +#define ENABLE_INPUT_TYPE_MONTH 0 +#define ENABLE_INPUT_TYPE_MONTH 0 +#define ENABLE_INPUT_TYPE_MONTH 0 +#define ENABLE_INPUT_TYPE_MONTH 0 +#define ENABLE_INPUT_TYPE_MONTH 0 +#define ENABLE_INPUT_TYPE_MONTH 0 +#define ENABLE_INPUT_TYPE_TIME 0 +#define ENABLE_INPUT_TYPE_TIME 0 +#define ENABLE_INPUT_TYPE_TIME 0 +#define ENABLE_INPUT_TYPE_TIME 0 +#define ENABLE_INPUT_TYPE_TIME 0 +#define ENABLE_INPUT_TYPE_TIME 0 +#define ENABLE_INPUT_TYPE_WEEK 0 +#define ENABLE_INPUT_TYPE_WEEK 0 +#define ENABLE_INPUT_TYPE_WEEK 0 +#define ENABLE_INPUT_TYPE_WEEK 0 +#define ENABLE_INPUT_TYPE_WEEK 0 +#define ENABLE_INPUT_TYPE_WEEK 0 +#define ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS 1 +#define ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS 1 +#define ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS 1 +#define ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS 1 +#define ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS 1 +#define ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS 1 +#define ENABLE_INSPECTOR_EXTENSIONS 0 +#define ENABLE_INSPECTOR_EXTENSIONS 0 +#define ENABLE_INSPECTOR_EXTENSIONS 0 +#define ENABLE_INSPECTOR_EXTENSIONS 0 +#define ENABLE_INSPECTOR_EXTENSIONS 0 +#define ENABLE_INSPECTOR_EXTENSIONS 0 +#define ENABLE_INSPECTOR_TELEMETRY 0 +#define ENABLE_INSPECTOR_TELEMETRY 0 +#define ENABLE_INSPECTOR_TELEMETRY 0 +#define ENABLE_INSPECTOR_TELEMETRY 0 +#define ENABLE_INSPECTOR_TELEMETRY 0 +#define ENABLE_INSPECTOR_TELEMETRY 0 +#define ENABLE_IOS_GESTURE_EVENTS 0 +#define ENABLE_IOS_GESTURE_EVENTS 0 +#define ENABLE_IOS_GESTURE_EVENTS 0 +#define ENABLE_IOS_GESTURE_EVENTS 0 +#define ENABLE_IOS_GESTURE_EVENTS 0 +#define ENABLE_IOS_GESTURE_EVENTS 0 +#define ENABLE_IOS_TOUCH_EVENTS 0 +#define ENABLE_IOS_TOUCH_EVENTS 0 +#define ENABLE_IOS_TOUCH_EVENTS 0 +#define ENABLE_IOS_TOUCH_EVENTS 0 +#define ENABLE_IOS_TOUCH_EVENTS 0 +#define ENABLE_IOS_TOUCH_EVENTS 0 +#define ENABLE_JIT 1 +#define ENABLE_JIT 1 +#define ENABLE_JIT 1 +#define ENABLE_JIT 1 +#define ENABLE_JIT 1 +#define ENABLE_JIT 1 +#define ENABLE_LAYER_BASED_SVG_ENGINE 0 +#define ENABLE_LAYER_BASED_SVG_ENGINE 0 +#define ENABLE_LAYER_BASED_SVG_ENGINE 0 +#define ENABLE_LAYER_BASED_SVG_ENGINE 0 +#define ENABLE_LAYER_BASED_SVG_ENGINE 0 +#define ENABLE_LAYER_BASED_SVG_ENGINE 0 +#define ENABLE_LAYOUT_TESTS 0 +#define ENABLE_LAYOUT_TESTS 0 +#define ENABLE_LAYOUT_TESTS 0 +#define ENABLE_LAYOUT_TESTS 0 +#define ENABLE_LAYOUT_TESTS 0 +#define ENABLE_LAYOUT_TESTS 0 +#define ENABLE_LEGACY_CUSTOM_PROTOCOL_MANAGER 0 +#define ENABLE_LEGACY_CUSTOM_PROTOCOL_MANAGER 0 +#define ENABLE_LEGACY_CUSTOM_PROTOCOL_MANAGER 0 +#define ENABLE_LEGACY_CUSTOM_PROTOCOL_MANAGER 0 +#define ENABLE_LEGACY_CUSTOM_PROTOCOL_MANAGER 0 +#define ENABLE_LEGACY_CUSTOM_PROTOCOL_MANAGER 0 +#define ENABLE_LEGACY_ENCRYPTED_MEDIA 0 +#define ENABLE_LEGACY_ENCRYPTED_MEDIA 0 +#define ENABLE_LEGACY_ENCRYPTED_MEDIA 0 +#define ENABLE_LEGACY_ENCRYPTED_MEDIA 0 +#define ENABLE_LEGACY_ENCRYPTED_MEDIA 0 +#define ENABLE_LEGACY_ENCRYPTED_MEDIA 0 +#define ENABLE_LETTERPRESS 0 +#define ENABLE_LETTERPRESS 0 +#define ENABLE_LETTERPRESS 0 +#define ENABLE_LETTERPRESS 0 +#define ENABLE_LETTERPRESS 0 +#define ENABLE_LETTERPRESS 0 +#define ENABLE_LLVM_PROFILE_GENERATION 0 +#define ENABLE_LLVM_PROFILE_GENERATION 0 +#define ENABLE_LLVM_PROFILE_GENERATION 0 +#define ENABLE_LLVM_PROFILE_GENERATION 0 +#define ENABLE_LLVM_PROFILE_GENERATION 0 +#define ENABLE_LLVM_PROFILE_GENERATION 0 +#define ENABLE_MANAGED_MEDIA_SOURCE 0 +#define ENABLE_MANAGED_MEDIA_SOURCE 0 +#define ENABLE_MANAGED_MEDIA_SOURCE 0 +#define ENABLE_MANAGED_MEDIA_SOURCE 0 +#define ENABLE_MANAGED_MEDIA_SOURCE 0 +#define ENABLE_MANAGED_MEDIA_SOURCE 0 +#define ENABLE_MATHML 1 +#define ENABLE_MATHML 1 +#define ENABLE_MATHML 1 +#define ENABLE_MATHML 1 +#define ENABLE_MATHML 1 +#define ENABLE_MATHML 1 +#define ENABLE_MEDIA_CAPTURE 0 +#define ENABLE_MEDIA_CAPTURE 0 +#define ENABLE_MEDIA_CAPTURE 0 +#define ENABLE_MEDIA_CAPTURE 0 +#define ENABLE_MEDIA_CAPTURE 0 +#define ENABLE_MEDIA_CAPTURE 0 +#define ENABLE_MEDIA_CONTROLS_CONTEXT_MENUS 0 +#define ENABLE_MEDIA_CONTROLS_CONTEXT_MENUS 0 +#define ENABLE_MEDIA_CONTROLS_CONTEXT_MENUS 0 +#define ENABLE_MEDIA_CONTROLS_CONTEXT_MENUS 0 +#define ENABLE_MEDIA_CONTROLS_CONTEXT_MENUS 0 +#define ENABLE_MEDIA_CONTROLS_CONTEXT_MENUS 0 +#define ENABLE_MEDIA_CONTROLS_SCRIPT 1 +#define ENABLE_MEDIA_CONTROLS_SCRIPT 1 +#define ENABLE_MEDIA_CONTROLS_SCRIPT 1 +#define ENABLE_MEDIA_CONTROLS_SCRIPT 1 +#define ENABLE_MEDIA_CONTROLS_SCRIPT 1 +#define ENABLE_MEDIA_CONTROLS_SCRIPT 1 +#define ENABLE_MEDIA_RECORDER 0 +#define ENABLE_MEDIA_RECORDER 0 +#define ENABLE_MEDIA_RECORDER 0 +#define ENABLE_MEDIA_RECORDER 0 +#define ENABLE_MEDIA_RECORDER 0 +#define ENABLE_MEDIA_RECORDER 0 +#define ENABLE_MEDIA_SESSION 0 +#define ENABLE_MEDIA_SESSION 0 +#define ENABLE_MEDIA_SESSION 0 +#define ENABLE_MEDIA_SESSION 0 +#define ENABLE_MEDIA_SESSION 0 +#define ENABLE_MEDIA_SESSION 0 +#define ENABLE_MEDIA_SESSION_COORDINATOR 0 +#define ENABLE_MEDIA_SESSION_COORDINATOR 0 +#define ENABLE_MEDIA_SESSION_COORDINATOR 0 +#define ENABLE_MEDIA_SESSION_COORDINATOR 0 +#define ENABLE_MEDIA_SESSION_COORDINATOR 0 +#define ENABLE_MEDIA_SESSION_COORDINATOR 0 +#define ENABLE_MEDIA_SESSION_PLAYLIST 0 +#define ENABLE_MEDIA_SESSION_PLAYLIST 0 +#define ENABLE_MEDIA_SESSION_PLAYLIST 0 +#define ENABLE_MEDIA_SESSION_PLAYLIST 0 +#define ENABLE_MEDIA_SESSION_PLAYLIST 0 +#define ENABLE_MEDIA_SESSION_PLAYLIST 0 +#define ENABLE_MEDIA_SOURCE 0 +#define ENABLE_MEDIA_SOURCE 0 +#define ENABLE_MEDIA_SOURCE 0 +#define ENABLE_MEDIA_SOURCE 0 +#define ENABLE_MEDIA_SOURCE 0 +#define ENABLE_MEDIA_SOURCE 0 +#define ENABLE_MEDIA_STATISTICS 0 +#define ENABLE_MEDIA_STATISTICS 0 +#define ENABLE_MEDIA_STATISTICS 0 +#define ENABLE_MEDIA_STATISTICS 0 +#define ENABLE_MEDIA_STATISTICS 0 +#define ENABLE_MEDIA_STATISTICS 0 +#define ENABLE_MEDIA_STREAM 0 +#define ENABLE_MEDIA_STREAM 0 +#define ENABLE_MEDIA_STREAM 0 +#define ENABLE_MEDIA_STREAM 0 +#define ENABLE_MEDIA_STREAM 0 +#define ENABLE_MEDIA_STREAM 0 +#define ENABLE_MEMORY_SAMPLER 0 +#define ENABLE_MEMORY_SAMPLER 0 +#define ENABLE_MEMORY_SAMPLER 0 +#define ENABLE_MEMORY_SAMPLER 0 +#define ENABLE_MEMORY_SAMPLER 0 +#define ENABLE_MEMORY_SAMPLER 0 +#define ENABLE_MHTML 0 +#define ENABLE_MHTML 0 +#define ENABLE_MHTML 0 +#define ENABLE_MHTML 0 +#define ENABLE_MHTML 0 +#define ENABLE_MHTML 0 +#define ENABLE_MINIBROWSER 0 +#define ENABLE_MINIBROWSER 0 +#define ENABLE_MINIBROWSER 0 +#define ENABLE_MINIBROWSER 0 +#define ENABLE_MINIBROWSER 0 +#define ENABLE_MINIBROWSER 0 +#define ENABLE_MODERN_MEDIA_CONTROLS 0 +#define ENABLE_MODERN_MEDIA_CONTROLS 0 +#define ENABLE_MODERN_MEDIA_CONTROLS 0 +#define ENABLE_MODERN_MEDIA_CONTROLS 0 +#define ENABLE_MODERN_MEDIA_CONTROLS 0 +#define ENABLE_MODERN_MEDIA_CONTROLS 0 +#define ENABLE_MOUSE_CURSOR_SCALE 0 +#define ENABLE_MOUSE_CURSOR_SCALE 0 +#define ENABLE_MOUSE_CURSOR_SCALE 0 +#define ENABLE_MOUSE_CURSOR_SCALE 0 +#define ENABLE_MOUSE_CURSOR_SCALE 0 +#define ENABLE_MOUSE_CURSOR_SCALE 0 +#define ENABLE_NAVIGATOR_STANDALONE 0 +#define ENABLE_NAVIGATOR_STANDALONE 0 +#define ENABLE_NAVIGATOR_STANDALONE 0 +#define ENABLE_NAVIGATOR_STANDALONE 0 +#define ENABLE_NAVIGATOR_STANDALONE 0 +#define ENABLE_NAVIGATOR_STANDALONE 0 +#define ENABLE_NETSCAPE_PLUGIN_API 1 +#define ENABLE_NETSCAPE_PLUGIN_API 1 +#define ENABLE_NETSCAPE_PLUGIN_API 1 +#define ENABLE_NETSCAPE_PLUGIN_API 1 +#define ENABLE_NETSCAPE_PLUGIN_API 1 +#define ENABLE_NETSCAPE_PLUGIN_API 1 +#define ENABLE_NETWORK_CACHE_SPECULATIVE_REVALIDATION 0 +#define ENABLE_NETWORK_CACHE_SPECULATIVE_REVALIDATION 0 +#define ENABLE_NETWORK_CACHE_SPECULATIVE_REVALIDATION 0 +#define ENABLE_NETWORK_CACHE_SPECULATIVE_REVALIDATION 0 +#define ENABLE_NETWORK_CACHE_SPECULATIVE_REVALIDATION 0 +#define ENABLE_NETWORK_CACHE_SPECULATIVE_REVALIDATION 0 +#define ENABLE_NETWORK_CACHE_STALE_WHILE_REVALIDATE 0 +#define ENABLE_NETWORK_CACHE_STALE_WHILE_REVALIDATE 0 +#define ENABLE_NETWORK_CACHE_STALE_WHILE_REVALIDATE 0 +#define ENABLE_NETWORK_CACHE_STALE_WHILE_REVALIDATE 0 +#define ENABLE_NETWORK_CACHE_STALE_WHILE_REVALIDATE 0 +#define ENABLE_NETWORK_CACHE_STALE_WHILE_REVALIDATE 0 +#define ENABLE_NOTIFICATIONS 1 +#define ENABLE_NOTIFICATIONS 1 +#define ENABLE_NOTIFICATIONS 1 +#define ENABLE_NOTIFICATIONS 1 +#define ENABLE_NOTIFICATIONS 1 +#define ENABLE_NOTIFICATIONS 1 +#define ENABLE_OFFSCREEN_CANVAS 0 +#define ENABLE_OFFSCREEN_CANVAS 0 +#define ENABLE_OFFSCREEN_CANVAS 0 +#define ENABLE_OFFSCREEN_CANVAS 0 +#define ENABLE_OFFSCREEN_CANVAS 0 +#define ENABLE_OFFSCREEN_CANVAS 0 +#define ENABLE_OFFSCREEN_CANVAS_IN_WORKERS 0 +#define ENABLE_OFFSCREEN_CANVAS_IN_WORKERS 0 +#define ENABLE_OFFSCREEN_CANVAS_IN_WORKERS 0 +#define ENABLE_OFFSCREEN_CANVAS_IN_WORKERS 0 +#define ENABLE_OFFSCREEN_CANVAS_IN_WORKERS 0 +#define ENABLE_OFFSCREEN_CANVAS_IN_WORKERS 0 +#define ENABLE_ORIENTATION_EVENTS 0 +#define ENABLE_ORIENTATION_EVENTS 0 +#define ENABLE_ORIENTATION_EVENTS 0 +#define ENABLE_ORIENTATION_EVENTS 0 +#define ENABLE_ORIENTATION_EVENTS 0 +#define ENABLE_ORIENTATION_EVENTS 0 +#define ENABLE_OVERFLOW_SCROLLING_TOUCH 0 +#define ENABLE_OVERFLOW_SCROLLING_TOUCH 0 +#define ENABLE_OVERFLOW_SCROLLING_TOUCH 0 +#define ENABLE_OVERFLOW_SCROLLING_TOUCH 0 +#define ENABLE_OVERFLOW_SCROLLING_TOUCH 0 +#define ENABLE_OVERFLOW_SCROLLING_TOUCH 0 +#define ENABLE_PAYMENT_REQUEST 0 +#define ENABLE_PAYMENT_REQUEST 0 +#define ENABLE_PAYMENT_REQUEST 0 +#define ENABLE_PAYMENT_REQUEST 0 +#define ENABLE_PAYMENT_REQUEST 0 +#define ENABLE_PAYMENT_REQUEST 0 +#define ENABLE_PDFJS 0 +#define ENABLE_PDFJS 0 +#define ENABLE_PDFJS 0 +#define ENABLE_PDFJS 0 +#define ENABLE_PDFJS 0 +#define ENABLE_PDFJS 0 +#define ENABLE_PDFKIT_PLUGIN 0 +#define ENABLE_PDFKIT_PLUGIN 0 +#define ENABLE_PDFKIT_PLUGIN 0 +#define ENABLE_PDFKIT_PLUGIN 0 +#define ENABLE_PDFKIT_PLUGIN 0 +#define ENABLE_PDFKIT_PLUGIN 0 +#define ENABLE_PERIODIC_MEMORY_MONITOR 0 +#define ENABLE_PERIODIC_MEMORY_MONITOR 0 +#define ENABLE_PERIODIC_MEMORY_MONITOR 0 +#define ENABLE_PERIODIC_MEMORY_MONITOR 0 +#define ENABLE_PERIODIC_MEMORY_MONITOR 0 +#define ENABLE_PERIODIC_MEMORY_MONITOR 0 +#define ENABLE_PICTURE_IN_PICTURE_API 0 +#define ENABLE_PICTURE_IN_PICTURE_API 0 +#define ENABLE_PICTURE_IN_PICTURE_API 0 +#define ENABLE_PICTURE_IN_PICTURE_API 0 +#define ENABLE_PICTURE_IN_PICTURE_API 0 +#define ENABLE_PICTURE_IN_PICTURE_API 0 +#define ENABLE_POINTER_LOCK 0 +#define ENABLE_POINTER_LOCK 0 +#define ENABLE_POINTER_LOCK 0 +#define ENABLE_POINTER_LOCK 0 +#define ENABLE_POINTER_LOCK 0 +#define ENABLE_POINTER_LOCK 0 +#define ENABLE_PUBLIC_SUFFIX_LIST 1 +#define ENABLE_PUBLIC_SUFFIX_LIST 1 +#define ENABLE_PUBLIC_SUFFIX_LIST 1 +#define ENABLE_PUBLIC_SUFFIX_LIST 1 +#define ENABLE_PUBLIC_SUFFIX_LIST 1 +#define ENABLE_PUBLIC_SUFFIX_LIST 1 +#define ENABLE_RELEASE_LOG 0 +#define ENABLE_RELEASE_LOG 0 +#define ENABLE_RELEASE_LOG 0 +#define ENABLE_RELEASE_LOG 0 +#define ENABLE_RELEASE_LOG 0 +#define ENABLE_RELEASE_LOG 0 +#define ENABLE_REMOTE_INSPECTOR 1 +#define ENABLE_REMOTE_INSPECTOR 1 +#define ENABLE_REMOTE_INSPECTOR 1 +#define ENABLE_REMOTE_INSPECTOR 1 +#define ENABLE_REMOTE_INSPECTOR 1 +#define ENABLE_REMOTE_INSPECTOR 1 +#define ENABLE_REMOTE_INSPECTOR 1 +#define ENABLE_RESOURCE_USAGE 1 +#define ENABLE_RESOURCE_USAGE 1 +#define ENABLE_RESOURCE_USAGE 1 +#define ENABLE_RESOURCE_USAGE 1 +#define ENABLE_RESOURCE_USAGE 1 +#define ENABLE_RESOURCE_USAGE 1 +#define ENABLE_RESOURCE_USAGE 1 +#define ENABLE_RUBBER_BANDING 0 +#define ENABLE_RUBBER_BANDING 0 +#define ENABLE_RUBBER_BANDING 0 +#define ENABLE_RUBBER_BANDING 0 +#define ENABLE_RUBBER_BANDING 0 +#define ENABLE_RUBBER_BANDING 0 +#define ENABLE_SAMPLING_PROFILER 1 +#define ENABLE_SAMPLING_PROFILER 1 +#define ENABLE_SAMPLING_PROFILER 1 +#define ENABLE_SAMPLING_PROFILER 1 +#define ENABLE_SAMPLING_PROFILER 1 +#define ENABLE_SAMPLING_PROFILER 1 +#define ENABLE_SANDBOX_EXTENSIONS 0 +#define ENABLE_SANDBOX_EXTENSIONS 0 +#define ENABLE_SANDBOX_EXTENSIONS 0 +#define ENABLE_SANDBOX_EXTENSIONS 0 +#define ENABLE_SANDBOX_EXTENSIONS 0 +#define ENABLE_SANDBOX_EXTENSIONS 0 +#define ENABLE_SERVER_PRECONNECT 0 +#define ENABLE_SERVER_PRECONNECT 0 +#define ENABLE_SERVER_PRECONNECT 0 +#define ENABLE_SERVER_PRECONNECT 0 +#define ENABLE_SERVER_PRECONNECT 0 +#define ENABLE_SERVER_PRECONNECT 0 +#define ENABLE_SERVICE_CONTROLS 0 +#define ENABLE_SERVICE_CONTROLS 0 +#define ENABLE_SERVICE_CONTROLS 0 +#define ENABLE_SERVICE_CONTROLS 0 +#define ENABLE_SERVICE_CONTROLS 0 +#define ENABLE_SERVICE_CONTROLS 0 +#define ENABLE_SERVICE_WORKER 0 +#define ENABLE_SERVICE_WORKER 0 +#define ENABLE_SERVICE_WORKER 0 +#define ENABLE_SERVICE_WORKER 0 +#define ENABLE_SERVICE_WORKER 0 +#define ENABLE_SERVICE_WORKER 0 +#define ENABLE_SHAREABLE_RESOURCE 0 +#define ENABLE_SHAREABLE_RESOURCE 0 +#define ENABLE_SHAREABLE_RESOURCE 0 +#define ENABLE_SHAREABLE_RESOURCE 0 +#define ENABLE_SHAREABLE_RESOURCE 0 +#define ENABLE_SHAREABLE_RESOURCE 0 +#define ENABLE_SINGLE_THREADED_VM_ENTRY_SCOPE 1 +#define ENABLE_SINGLE_THREADED_VM_ENTRY_SCOPE 1 +#define ENABLE_SMOOTH_SCROLLING 1 +#define ENABLE_SMOOTH_SCROLLING 1 +#define ENABLE_SMOOTH_SCROLLING 1 +#define ENABLE_SMOOTH_SCROLLING 1 +#define ENABLE_SMOOTH_SCROLLING 1 +#define ENABLE_SMOOTH_SCROLLING 1 +#define ENABLE_SPEECH_SYNTHESIS 0 +#define ENABLE_SPEECH_SYNTHESIS 0 +#define ENABLE_SPEECH_SYNTHESIS 0 +#define ENABLE_SPEECH_SYNTHESIS 0 +#define ENABLE_SPEECH_SYNTHESIS 0 +#define ENABLE_SPEECH_SYNTHESIS 0 +#define ENABLE_SPELLCHECK 0 +#define ENABLE_SPELLCHECK 0 +#define ENABLE_SPELLCHECK 0 +#define ENABLE_SPELLCHECK 0 +#define ENABLE_SPELLCHECK 0 +#define ENABLE_SPELLCHECK 0 +#define ENABLE_STATIC_JSC 1 +#define ENABLE_TELEPHONE_NUMBER_DETECTION 0 +#define ENABLE_TELEPHONE_NUMBER_DETECTION 0 +#define ENABLE_TELEPHONE_NUMBER_DETECTION 0 +#define ENABLE_TELEPHONE_NUMBER_DETECTION 0 +#define ENABLE_TELEPHONE_NUMBER_DETECTION 0 +#define ENABLE_TELEPHONE_NUMBER_DETECTION 0 +#define ENABLE_TEXT_AUTOSIZING 0 +#define ENABLE_TEXT_AUTOSIZING 0 +#define ENABLE_TEXT_AUTOSIZING 0 +#define ENABLE_TEXT_AUTOSIZING 0 +#define ENABLE_TEXT_AUTOSIZING 0 +#define ENABLE_TEXT_AUTOSIZING 0 +#define ENABLE_THUNDER 0 +#define ENABLE_THUNDER 0 +#define ENABLE_THUNDER 0 +#define ENABLE_THUNDER 0 +#define ENABLE_THUNDER 0 +#define ENABLE_THUNDER 0 +#define ENABLE_TOUCH_EVENTS 0 +#define ENABLE_TOUCH_EVENTS 0 +#define ENABLE_TOUCH_EVENTS 0 +#define ENABLE_TOUCH_EVENTS 0 +#define ENABLE_TOUCH_EVENTS 0 +#define ENABLE_TOUCH_EVENTS 0 +#define ENABLE_TRACKING_PREVENTION 0 +#define ENABLE_TRACKING_PREVENTION 0 +#define ENABLE_TRACKING_PREVENTION 0 +#define ENABLE_TRACKING_PREVENTION 0 +#define ENABLE_TRACKING_PREVENTION 0 +#define ENABLE_TRACKING_PREVENTION 0 +#define ENABLE_UNIFIED_BUILDS 1 +#define ENABLE_UNIFIED_BUILDS 1 +#define ENABLE_UNIFIED_BUILDS 1 +#define ENABLE_UNIFIED_BUILDS 1 +#define ENABLE_UNIFIED_BUILDS 1 +#define ENABLE_UNIFIED_BUILDS 1 +#define ENABLE_USER_MESSAGE_HANDLERS 1 +#define ENABLE_USER_MESSAGE_HANDLERS 1 +#define ENABLE_USER_MESSAGE_HANDLERS 1 +#define ENABLE_USER_MESSAGE_HANDLERS 1 +#define ENABLE_USER_MESSAGE_HANDLERS 1 +#define ENABLE_USER_MESSAGE_HANDLERS 1 +#define ENABLE_VARIATION_FONTS 0 +#define ENABLE_VARIATION_FONTS 0 +#define ENABLE_VARIATION_FONTS 0 +#define ENABLE_VARIATION_FONTS 0 +#define ENABLE_VARIATION_FONTS 0 +#define ENABLE_VARIATION_FONTS 0 +#define ENABLE_VIDEO 1 +#define ENABLE_VIDEO 1 +#define ENABLE_VIDEO 1 +#define ENABLE_VIDEO 1 +#define ENABLE_VIDEO 1 +#define ENABLE_VIDEO 1 +#define ENABLE_VIDEO_PRESENTATION_MODE 0 +#define ENABLE_VIDEO_PRESENTATION_MODE 0 +#define ENABLE_VIDEO_PRESENTATION_MODE 0 +#define ENABLE_VIDEO_PRESENTATION_MODE 0 +#define ENABLE_VIDEO_PRESENTATION_MODE 0 +#define ENABLE_VIDEO_PRESENTATION_MODE 0 +#define ENABLE_VIDEO_USES_ELEMENT_FULLSCREEN 1 +#define ENABLE_VIDEO_USES_ELEMENT_FULLSCREEN 1 +#define ENABLE_VIDEO_USES_ELEMENT_FULLSCREEN 1 +#define ENABLE_VIDEO_USES_ELEMENT_FULLSCREEN 1 +#define ENABLE_VIDEO_USES_ELEMENT_FULLSCREEN 1 +#define ENABLE_VIDEO_USES_ELEMENT_FULLSCREEN 1 +#define ENABLE_WEBASSEMBLY 0 +#define ENABLE_WEBASSEMBLY 0 +#define ENABLE_WEBASSEMBLY 0 +#define ENABLE_WEBASSEMBLY 0 +#define ENABLE_WEBASSEMBLY 0 +#define ENABLE_WEBASSEMBLY 0 +#define ENABLE_WEBASSEMBLY_BBQJIT 0 +#define ENABLE_WEBASSEMBLY_BBQJIT 0 +#define ENABLE_WEBASSEMBLY_BBQJIT 0 +#define ENABLE_WEBASSEMBLY_BBQJIT 0 +#define ENABLE_WEBASSEMBLY_BBQJIT 0 +#define ENABLE_WEBASSEMBLY_BBQJIT 0 +#define ENABLE_WEBASSEMBLY_OMGJIT 0 +#define ENABLE_WEBASSEMBLY_OMGJIT 0 +#define ENABLE_WEBASSEMBLY_OMGJIT 0 +#define ENABLE_WEBASSEMBLY_OMGJIT 0 +#define ENABLE_WEBASSEMBLY_OMGJIT 0 +#define ENABLE_WEBASSEMBLY_OMGJIT 0 +#define ENABLE_WEBDRIVER 0 +#define ENABLE_WEBDRIVER 0 +#define ENABLE_WEBDRIVER 0 +#define ENABLE_WEBDRIVER 0 +#define ENABLE_WEBDRIVER 0 +#define ENABLE_WEBDRIVER 0 +#define ENABLE_WEBDRIVER_KEYBOARD_GRAPHEME_CLUSTERS 0 +#define ENABLE_WEBDRIVER_KEYBOARD_GRAPHEME_CLUSTERS 0 +#define ENABLE_WEBDRIVER_KEYBOARD_GRAPHEME_CLUSTERS 0 +#define ENABLE_WEBDRIVER_KEYBOARD_GRAPHEME_CLUSTERS 0 +#define ENABLE_WEBDRIVER_KEYBOARD_GRAPHEME_CLUSTERS 0 +#define ENABLE_WEBDRIVER_KEYBOARD_GRAPHEME_CLUSTERS 0 +#define ENABLE_WEBDRIVER_KEYBOARD_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_KEYBOARD_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_KEYBOARD_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_KEYBOARD_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_KEYBOARD_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_KEYBOARD_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_MOUSE_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_MOUSE_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_MOUSE_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_MOUSE_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_MOUSE_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_MOUSE_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_TOUCH_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_TOUCH_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_TOUCH_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_TOUCH_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_TOUCH_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_TOUCH_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_WHEEL_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_WHEEL_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_WHEEL_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_WHEEL_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_WHEEL_INTERACTIONS 0 +#define ENABLE_WEBDRIVER_WHEEL_INTERACTIONS 0 +#define ENABLE_WEBGL 0 +#define ENABLE_WEBGL 0 +#define ENABLE_WEBGL 0 +#define ENABLE_WEBGL 0 +#define ENABLE_WEBGL 0 +#define ENABLE_WEBGL 0 +#define ENABLE_WEBXR 0 +#define ENABLE_WEBXR 0 +#define ENABLE_WEBXR 0 +#define ENABLE_WEBXR 0 +#define ENABLE_WEBXR 0 +#define ENABLE_WEBXR 0 +#define ENABLE_WEB_API_STATISTICS 0 +#define ENABLE_WEB_API_STATISTICS 0 +#define ENABLE_WEB_API_STATISTICS 0 +#define ENABLE_WEB_API_STATISTICS 0 +#define ENABLE_WEB_API_STATISTICS 0 +#define ENABLE_WEB_API_STATISTICS 0 +#define ENABLE_WEB_AUDIO 1 +#define ENABLE_WEB_AUDIO 1 +#define ENABLE_WEB_AUDIO 1 +#define ENABLE_WEB_AUDIO 1 +#define ENABLE_WEB_AUDIO 1 +#define ENABLE_WEB_AUDIO 1 +#define ENABLE_WEB_AUTHN 0 +#define ENABLE_WEB_AUTHN 0 +#define ENABLE_WEB_AUTHN 0 +#define ENABLE_WEB_AUTHN 0 +#define ENABLE_WEB_AUTHN 0 +#define ENABLE_WEB_AUTHN 0 +#define ENABLE_WEB_CODECS 0 +#define ENABLE_WEB_CODECS 0 +#define ENABLE_WEB_CODECS 0 +#define ENABLE_WEB_CODECS 0 +#define ENABLE_WEB_CODECS 0 +#define ENABLE_WEB_CODECS 0 +#define ENABLE_WEB_CRYPTO 1 +#define ENABLE_WEB_CRYPTO 1 +#define ENABLE_WEB_CRYPTO 1 +#define ENABLE_WEB_CRYPTO 1 +#define ENABLE_WEB_CRYPTO 1 +#define ENABLE_WEB_CRYPTO 1 +#define ENABLE_WEB_RTC 0 +#define ENABLE_WEB_RTC 0 +#define ENABLE_WEB_RTC 0 +#define ENABLE_WEB_RTC 0 +#define ENABLE_WEB_RTC 0 +#define ENABLE_WEB_RTC 0 +#define ENABLE_WIRELESS_PLAYBACK_TARGET 0 +#define ENABLE_WIRELESS_PLAYBACK_TARGET 0 +#define ENABLE_WIRELESS_PLAYBACK_TARGET 0 +#define ENABLE_WIRELESS_PLAYBACK_TARGET 0 +#define ENABLE_WIRELESS_PLAYBACK_TARGET 0 +#define ENABLE_WIRELESS_PLAYBACK_TARGET 0 +#define ENABLE_XSLT 1 +#define ENABLE_XSLT 1 +#define ENABLE_XSLT 1 +#define ENABLE_XSLT 1 +#define ENABLE_XSLT 1 +#define ENABLE_XSLT 1 +#define HAVE_ALIGNED_MALLOC 1 +#define HAVE_ERRNO_H 1 +#define HAVE_FEATURES_H 0 +#define HAVE_LANGINFO_H 0 +#define HAVE_LINUX_MEMFD_H 0 +#define HAVE_LOCALTIME_R 0 +#define HAVE_MALLOC_TRIM 0 +#define HAVE_MAP_ALIGNED 0 +#define HAVE_MMAP 0 +#define HAVE_PTHREAD_MAIN_NP 0 +#define HAVE_PTHREAD_NP_H 0 +#define HAVE_REGEX_H 0 +#define HAVE_SHM_ANON 0 +#define HAVE_SIGNAL_H 0 +#define HAVE_STATX 0 +#define HAVE_STAT_BIRTHTIME 0 +#define HAVE_STRNSTR 0 +#define HAVE_SYS_PARAM_H 0 +#define HAVE_SYS_TIMEB_H 1 +#define HAVE_SYS_TIME_H 0 +#define HAVE_TIMEGM 0 +#define HAVE_TIMINGSAFE_BCMP 0 +#define HAVE_TM_GMTOFF 0 +#define HAVE_TM_ZONE 0 +#define HAVE_VASPRINTF 0 +#define JS_NO_EXPORT 1 +#define USE_64KB_PAGE_BLOCK 0 +#define USE_ALLOW_LINE_AND_COLUMN_NUMBER_IN_BUILTINS 1 +#define USE_AVIF 1 +#define USE_AVIF 1 +#define USE_AVIF 1 +#define USE_AVIF 1 +#define USE_AVIF 1 +#define USE_AVIF 1 +#define USE_BUN_JSC_ADDITIONS 1 +#define USE_BUN_JSC_ADDITIONS 1 +#define USE_GENERIC_EVENT_LOOP 1 +#define USE_INSPECTOR_SOCKET_SERVER 1 +#define USE_ISO_MALLOC 1 +#define USE_ISO_MALLOC 1 +#define USE_ISO_MALLOC 1 +#define USE_ISO_MALLOC 1 +#define USE_ISO_MALLOC 1 +#define USE_ISO_MALLOC 1 +#define USE_JPEGXL 1 +#define USE_JPEGXL 1 +#define USE_JPEGXL 1 +#define USE_JPEGXL 1 +#define USE_JPEGXL 1 +#define USE_JPEGXL 1 +#define USE_SYSTEM_MALLOC 1 +#define USE_SYSTEM_MALLOC 1 +#define USE_SYSTEM_MALLOC 1 +#define USE_SYSTEM_MALLOC 1 +#define USE_SYSTEM_MALLOC 1 +#define USE_SYSTEM_MALLOC 1 +#define USE_UNIX_DOMAIN_SOCKETS 1 +#define WTF_DEFAULT_EVENT_LOOP 0 + +#endif /* CMAKECONFIG_H */ diff --git a/src/bun.js/bindings/webcrypto/CryptoKeyOKPOpenSSL.cpp b/src/bun.js/bindings/webcrypto/CryptoKeyOKPOpenSSL.cpp index 68505bec94..796ebb772b 100644 --- a/src/bun.js/bindings/webcrypto/CryptoKeyOKPOpenSSL.cpp +++ b/src/bun.js/bindings/webcrypto/CryptoKeyOKPOpenSSL.cpp @@ -339,10 +339,13 @@ String CryptoKeyOKP::generateJwkX() const ASSERT(type() == CryptoKeyType::Private); if (namedCurve() == NamedCurve::Ed25519) - return Bun::base64URLEncodeToString(WTFMove(ed25519PublicFromPrivate(const_cast(m_data)))); + // TODO(@paperdave 2023-10-19): i removed WTFMove from ed25519PublicFromPrivate() as per MSVC compiler error. + // We need to evaluate if that is the proper fix here. + return Bun::base64URLEncodeToString(ed25519PublicFromPrivate(const_cast(m_data))); ASSERT(namedCurve() == NamedCurve::X25519); - return Bun::base64URLEncodeToString(WTFMove(x25519PublicFromPrivate(const_cast(m_data)))); + // TODO(@paperdave 2023-10-19): see above + return Bun::base64URLEncodeToString(x25519PublicFromPrivate(const_cast(m_data))); } CryptoKeyOKP::KeyMaterial CryptoKeyOKP::platformExportRaw() const diff --git a/src/bun.js/bindings/musl-memmem.c b/src/bun.js/bindings/windows/musl-memmem.c similarity index 60% rename from src/bun.js/bindings/musl-memmem.c rename to src/bun.js/bindings/windows/musl-memmem.c index a7b866bc08..115b99c91e 100644 --- a/src/bun.js/bindings/musl-memmem.c +++ b/src/bun.js/bindings/windows/musl-memmem.c @@ -1,8 +1,8 @@ // musl as a whole is licensed under the following standard MIT license: -// +// // ---------------------------------------------------------------------- // Copyright © 2005-2020 Rich Felker, et al. -// +// // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including @@ -10,10 +10,10 @@ // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: -// +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. @@ -22,9 +22,9 @@ // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ---------------------------------------------------------------------- -// +// // Authors/contributors include: -// +// // A. Wilcox // Ada Worcester // Alex Dowad @@ -107,16 +107,16 @@ // Will Dietz // William Haddon // William Pitcock -// +// // Portions of this software are derived from third-party works licensed // under terms compatible with the above MIT license: -// +// // The TRE regular expression implementation (src/regex/reg* and // src/regex/tre*) is Copyright © 2001-2008 Ville Laurikari and licensed // under a 2-clause BSD license (license text in the source files). The // included version has been heavily modified by Rich Felker in 2012, in // the interests of size, simplicity, and namespace cleanliness. -// +// // Much of the math library code (src/math/* and src/complex/*) is // Copyright © 1993,2004 Sun Microsystems or // Copyright © 2003-2011 David Schultz or @@ -126,40 +126,40 @@ // Copyright © 2017-2018 Arm Limited // and labelled as such in comments in the individual source files. All // have been licensed under extremely permissive terms. -// +// // The ARM memcpy code (src/string/arm/memcpy.S) is Copyright © 2008 // The Android Open Source Project and is licensed under a two-clause BSD // license. It was taken from Bionic libc, used on Android. -// +// // The AArch64 memcpy and memset code (src/string/aarch64/*) are // Copyright © 1999-2019, Arm Limited. -// +// // The implementation of DES for crypt (src/crypt/crypt_des.c) is // Copyright © 1994 David Burren. It is licensed under a BSD license. -// +// // The implementation of blowfish crypt (src/crypt/crypt_blowfish.c) was // originally written by Solar Designer and placed into the public // domain. The code also comes with a fallback permissive license for use // in jurisdictions that may not recognize the public domain. -// +// // The smoothsort implementation (src/stdlib/qsort.c) is Copyright © 2011 // Valentin Ochs and is licensed under an MIT-style license. -// +// // The x86_64 port was written by Nicholas J. Kain and is licensed under // the standard MIT terms. -// +// // The mips and microblaze ports were originally written by Richard // Pennington for use in the ellcc project. The original code was adapted // by Rich Felker for build system and code conventions during upstream // integration. It is licensed under the standard MIT terms. -// +// // The mips64 port was contributed by Imagination Technologies and is // licensed under the standard MIT terms. -// +// // The powerpc port was also originally written by Richard Pennington, // and later supplemented and integrated by John Spencer. It is licensed // under the standard MIT terms. -// +// // All other files which have no copyright comments are original works // produced specifically for use as part of this library, written either // by Rich Felker, the main author of the library, or by one or more @@ -167,14 +167,14 @@ // can be found in the git version control history of the project. The // omission of copyright and license comments in each file is in the // interest of source tree size. -// +// // In addition, permission is hereby granted for all public header files // (include/* and arch/*/bits/*) and crt files intended to be linked into // applications (crt/*, ldso/dlstart.c, and arch/*/crt_arch.h) to omit // the copyright notice and permission notice otherwise required by the // license, and to use these files without any requirement of // attribution. These files include substantial contributions from: -// +// // Bobby Bingham // John Spencer // Nicholas J. Kain @@ -182,9 +182,9 @@ // Richard Pennington // Stefan Kristiansson // Szabolcs Nagy -// +// // all of whom have explicitly granted such permission. -// +// // This file previously contained text expressing a belief that most of // the files covered by the above exception were sufficiently trivial not // to be subject to copyright, resulting in confusion over whether it @@ -195,149 +195,173 @@ #include #include -static char *twobyte_memmem(const unsigned char *h, size_t k, const unsigned char *n) +static char* twobyte_memmem(const unsigned char* h, size_t k, const unsigned char* n) { - uint16_t nw = n[0]<<8 | n[1], hw = h[0]<<8 | h[1]; - for (h+=2, k-=2; k; k--, hw = hw<<8 | *h++) - if (hw == nw) return (char *)h-2; - return hw == nw ? (char *)h-2 : 0; + uint16_t nw = n[0] << 8 | n[1], hw = h[0] << 8 | h[1]; + for (h += 2, k -= 2; k; k--, hw = hw << 8 | *h++) + if (hw == nw) + return (char*)h - 2; + return hw == nw ? (char*)h - 2 : 0; } -static char *threebyte_memmem(const unsigned char *h, size_t k, const unsigned char *n) +static char* threebyte_memmem(const unsigned char* h, size_t k, const unsigned char* n) { - uint32_t nw = (uint32_t)n[0]<<24 | n[1]<<16 | n[2]<<8; - uint32_t hw = (uint32_t)h[0]<<24 | h[1]<<16 | h[2]<<8; - for (h+=3, k-=3; k; k--, hw = (hw|*h++)<<8) - if (hw == nw) return (char *)h-3; - return hw == nw ? (char *)h-3 : 0; + uint32_t nw = (uint32_t)n[0] << 24 | n[1] << 16 | n[2] << 8; + uint32_t hw = (uint32_t)h[0] << 24 | h[1] << 16 | h[2] << 8; + for (h += 3, k -= 3; k; k--, hw = (hw | *h++) << 8) + if (hw == nw) + return (char*)h - 3; + return hw == nw ? (char*)h - 3 : 0; } -static char *fourbyte_memmem(const unsigned char *h, size_t k, const unsigned char *n) +static char* fourbyte_memmem(const unsigned char* h, size_t k, const unsigned char* n) { - uint32_t nw = (uint32_t)n[0]<<24 | n[1]<<16 | n[2]<<8 | n[3]; - uint32_t hw = (uint32_t)h[0]<<24 | h[1]<<16 | h[2]<<8 | h[3]; - for (h+=4, k-=4; k; k--, hw = hw<<8 | *h++) - if (hw == nw) return (char *)h-4; - return hw == nw ? (char *)h-4 : 0; + uint32_t nw = (uint32_t)n[0] << 24 | n[1] << 16 | n[2] << 8 | n[3]; + uint32_t hw = (uint32_t)h[0] << 24 | h[1] << 16 | h[2] << 8 | h[3]; + for (h += 4, k -= 4; k; k--, hw = hw << 8 | *h++) + if (hw == nw) + return (char*)h - 4; + return hw == nw ? (char*)h - 4 : 0; } -#define MAX(a,b) ((a)>(b)?(a):(b)) -#define MIN(a,b) ((a)<(b)?(a):(b)) +#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#define BITOP(a,b,op) \ - ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) +#define BITOP(a, b, op) \ + ((a)[(size_t)(b) / (8 * sizeof *(a))] op(size_t) 1 << ((size_t)(b) % (8 * sizeof *(a)))) -static char *twoway_memmem(const unsigned char *h, const unsigned char *z, const unsigned char *n, size_t l) +static char* twoway_memmem(const unsigned char* h, const unsigned char* z, const unsigned char* n, size_t l) { - size_t i, ip, jp, k, p, ms, p0, mem, mem0; - size_t byteset[32 / sizeof(size_t)] = { 0 }; - size_t shift[256]; + size_t i, ip, jp, k, p, ms, p0, mem, mem0; + size_t byteset[32 / sizeof(size_t)] = { 0 }; + size_t shift[256]; - /* Computing length of needle and fill shift table */ - for (i=0; i n[jp+k]) { - jp += k; - k = 1; - p = jp - ip; - } else { - ip = jp++; - k = p = 1; - } - } - ms = ip; - p0 = p; + /* Compute maximal suffix */ + ip = -1; + jp = 0; + k = p = 1; + while (jp + k < l) { + if (n[ip + k] == n[jp + k]) { + if (k == p) { + jp += p; + k = 1; + } else + k++; + } else if (n[ip + k] > n[jp + k]) { + jp += k; + k = 1; + p = jp - ip; + } else { + ip = jp++; + k = p = 1; + } + } + ms = ip; + p0 = p; - /* And with the opposite comparison */ - ip = -1; jp = 0; k = p = 1; - while (jp+k ms+1) ms = ip; - else p = p0; + /* And with the opposite comparison */ + ip = -1; + jp = 0; + k = p = 1; + while (jp + k < l) { + if (n[ip + k] == n[jp + k]) { + if (k == p) { + jp += p; + k = 1; + } else + k++; + } else if (n[ip + k] < n[jp + k]) { + jp += k; + k = 1; + p = jp - ip; + } else { + ip = jp++; + k = p = 1; + } + } + if (ip + 1 > ms + 1) + ms = ip; + else + p = p0; - /* Periodic needle? */ - if (memcmp(n, n+p, ms+1)) { - mem0 = 0; - p = MAX(ms, l-ms-1) + 1; - } else mem0 = l-p; - mem = 0; + /* Periodic needle? */ + if (memcmp(n, n + p, ms + 1)) { + mem0 = 0; + p = MAX(ms, l - ms - 1) + 1; + } else + mem0 = l - p; + mem = 0; - /* Search loop */ - for (;;) { - /* If remainder of haystack is shorter than needle, done */ - if (z-h < l) return 0; + /* Search loop */ + for (;;) { + /* If remainder of haystack is shorter than needle, done */ + if (z - h < l) + return 0; - /* Check last byte first; advance by shift on mismatch */ - if (BITOP(byteset, h[l-1], &)) { - k = l-shift[h[l-1]]; - if (k) { - if (k < mem) k = mem; - h += k; - mem = 0; - continue; - } - } else { - h += l; - mem = 0; - continue; - } + /* Check last byte first; advance by shift on mismatch */ + if (BITOP(byteset, h[l - 1], &)) { + k = l - shift[h[l - 1]]; + if (k) { + if (k < mem) + k = mem; + h += k; + mem = 0; + continue; + } + } else { + h += l; + mem = 0; + continue; + } - /* Compare right half */ - for (k=MAX(ms+1,mem); kmem && n[k-1] == h[k-1]; k--); - if (k <= mem) return (char *)h; - h += p; - mem = mem0; - } + /* Compare right half */ + for (k = MAX(ms + 1, mem); k < l && n[k] == h[k]; k++) + ; + if (k < l) { + h += k - ms; + mem = 0; + continue; + } + /* Compare left half */ + for (k = ms + 1; k > mem && n[k - 1] == h[k - 1]; k--) + ; + if (k <= mem) + return (char*)h; + h += p; + mem = mem0; + } } -extern void *memmem(const void *h0, size_t k, const void *n0, size_t l) +extern void* memmem(const void* h0, size_t k, const void* n0, size_t l) { - const unsigned char *h = h0, *n = n0; + const unsigned char *h = h0, *n = n0; - /* Return immediately on empty needle */ - if (!l) return (void *)h; + /* Return immediately on empty needle */ + if (!l) + return (void*)h; - /* Return immediately when needle is longer than haystack */ - if (k