Mongoose doesn't pick up traffic on localhost:443 when SSL enabled

I’m building an HTTP server in C++ using the Cesanta Mongoose c++ networking library. Essentially I’m trying to redirect traffic from my web browser to a proxy on the localhost. I recently added support for HTTPS by purchasing a certificate and domain and following the instructions to enable ssl with mongoose (https://cesanta.com/docs/http/ssl.html). The server is now listening on port 443, and it runs fine. I’ve configured my web browser to direct HTTPS requests to localhost:443, but it doesn’t appear to be triggering the HTTP server. When my server is listening on port 8080 and the web browser is configured to send requests to localhost:8080, it triggers the web browser, but it doesn’t support https. Is there something wrong with configuring the web browser to send requests to localhost:443? I will say that when I have SSL enabled, it also does not pick up requests when listening on localhost:8080 and the proxy is set to localhost:8080, nor does it work with 8443. I tried nmap to see if 443 was blocked but it isn’t blocked, just closed. Here is my server code for reference. Essentially what happens when I run the code is that the program will run fine, but the event handler function is not triggered, i.e. it doesn’t print anything out.

#include <string.h>
#include <string>
#include <iostream>
#include <iterator>
#include <sstream>
#include <vector>
#include "mongoose.h"

static const char *s_http_port = "443";
static int exit_flag = 0;
struct mg_mgr mgr;
static const char *s_ssl_cert = "cert.pem";
static const char *s_ssl_key = "server.key";
const char *err;



static void ev_handler(struct mg_connection *c, int ev, void *p) {
  if (ev == MG_EV_HTTP_REQUEST) {
      std::cout << "Received request" << std::endl;
    struct http_message *hm = (struct http_message *) p;
    mg_send_head(c, 200, hm->message.len, "Content-Type: text/plain");
  }
  
}


int main(void) {
  
  struct mg_connection *listen;
  struct mg_bind_opts bind_opts;
  mg_mgr_init(&mgr, NULL);
  
  memset(&bind_opts, 0, sizeof(bind_opts));
  

  bind_opts.ssl_cert = s_ssl_cert;
  bind_opts.ssl_key = s_ssl_key;
  bind_opts.error_string = &err;
  

  listen = mg_bind_opt(&mgr, s_http_port, ev_handler, bind_opts);
  
  if (listen == NULL) {
    printf("Failed to create listener: %s\n", err);
    return 1;
  }
  mg_set_protocol_http_websocket(listen);
  

  for (;;) {
    mg_mgr_poll(&mgr, 1000);
  }
  while (exit_flag == 0) {
    mg_mgr_poll(&mgr, 1000);
  }
  mg_mgr_free(&mgr);

  return 0;
}

Could you point out why this is a Mongoose library problem?

With all due respect, it’s not clear to me where the confusion lies. I’ve implemented an HTTPS server using the Mongoose networking library, and it’s not responding to traffic directed at the listening connection. It works with HTTP, but not with HTTPS enabled. I’ve tried telling the computer to allow the certificate I have, I’ve verified the validity of the certificates, etc. The event handler function is simply not called in my code which was implemented using the Mongoose Networking Library.

Beware ports below 1024 need admin privileges.

1 Like

hay lắm, phát huy nhé bạn