Can now control SSL cert verfication from in-engine

This commit is contained in:
2022-03-18 16:25:20 -04:00
parent 2e7b793110
commit 2e3bef79b3
8 changed files with 392 additions and 204 deletions

View File

@@ -41,7 +41,7 @@ struct termios orig_termios;
static std::string strerror_str(int err) {
char errbuf[256];
return strerror_r(errno, errbuf, 256);
return strerror_r(err, errbuf, 256);
}
void set_nonblocking(int fd) {
@@ -69,7 +69,7 @@ static void enable_tty_raw() {
assert(status >= 0);
}
static SOCKET open_connection(std::string_view target, std::string &err) {
static SOCKET open_connection(const char *host, const char *port, std::string &err) {
struct addrinfo *addrs = nullptr;
struct addrinfo *goodaddr = nullptr;
struct addrinfo hints;
@@ -82,9 +82,7 @@ static SOCKET open_connection(std::string_view target, std::string &err) {
hints.ai_flags = AI_NUMERICSERV;
err.clear();
std::string host, port;
drv::split_host_port(target, host, port);
int status = getaddrinfo(host.c_str(), port.c_str(), &hints, &addrs);
int status = getaddrinfo(host, port, &hints, &addrs);
if (status != 0) {
err = gai_strerror(status);
goto error_general;
@@ -228,6 +226,25 @@ static int console_read(char *bytes, int nbytes) {
return read(0, bytes, nbytes);
}
static void ssl_ctx_use_dummycert(SSL_CTX *ctx);
static SSL_CTX *new_ssl_server_context() {
SSL_CTX *ctx = SSL_CTX_new(TLS_method());
SSL_CTX_set_mode(ctx, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
SSL_CTX_set_mode(ctx, SSL_MODE_ENABLE_PARTIAL_WRITE);
SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, nullptr);
ssl_ctx_use_dummycert(ctx);
return ctx;
}
static SSL_CTX *new_ssl_client_context(int verify) {
SSL_CTX *ctx = SSL_CTX_new(TLS_method());
SSL_CTX_set_mode(ctx, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
SSL_CTX_set_mode(ctx, SSL_MODE_ENABLE_PARTIAL_WRITE);
SSL_CTX_set_default_verify_paths(ctx);
SSL_CTX_set_verify(ctx, verify, nullptr);
return ctx;
}
static void disable_randomization(int argc, char *argv[]) {
const int old_personality = personality(ADDR_NO_RANDOMIZE);