// moonbitlang/async loads OpenSSL with dlopen/dlsym, which a static musl binary // can't do. These definitions replace musl's stubs (nothing else in Orbit uses // them) and hand out the statically linked OpenSSL functions instead. // // openssl_symbols.h is generated by scripts/build-musl.sh from async's own // import list, so a function OpenSSL lacks fails the link, not the first request. #include #include #include #include #include #include #include #include #include #include #include // SSL_CTX_set_default_verify_paths only checks the OPENSSLDIR chosen at build // time (/etc/ssl). Also load the CA bundle from where other distros keep it, // unless the user picked their own with SSL_CERT_FILE or SSL_CERT_DIR. static int set_default_verify_paths(SSL_CTX *ctx) { static const char *const bundles[] = { "/etc/ssl/certs/ca-certificates.crt", // Debian, Arch, Alpine, Nix "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem", // Fedora, RHEL "/etc/pki/tls/certs/ca-bundle.crt", // older Fedora, RHEL "/etc/ssl/ca-bundle.pem", // openSUSE "/etc/ssl/cert.pem", // Alpine, Void }; if (!SSL_CTX_set_default_verify_paths(ctx)) return 0; if (getenv("SSL_CERT_FILE") || getenv("SSL_CERT_DIR")) return 1; for (size_t i = 0; i < sizeof(bundles) / sizeof(bundles[0]); ++i) { if (access(bundles[i], R_OK) == 0 && SSL_CTX_load_verify_file(ctx, bundles[i])) { break; } } return 1; } static const struct { const char *name; void *address; } symbols[] = { { "OpenSSL_version_num", (void *)OpenSSL_version_num }, #define ORBIT_SYMBOL(name) { #name, (void *)name }, #include "openssl_symbols.h" #undef ORBIT_SYMBOL }; void *dlopen(const char *file, int mode) { (void)mode; return file && strncmp(file, "libssl.so", 9) == 0 ? (void *)symbols : NULL; } void *dlsym(void *handle, const char *name) { if (handle != (void *)symbols) return NULL; if (strcmp(name, "SSL_CTX_set_default_verify_paths") == 0) { return (void *)set_default_verify_paths; } for (size_t i = 0; i < sizeof(symbols) / sizeof(symbols[0]); ++i) { if (strcmp(name, symbols[i].name) == 0) return symbols[i].address; } return NULL; }