2

I try to add SSL to my web server implemented with mongoose, but I don't manage to make it work. I have openssl installed and I try to follow the documentation there https://github.com/cesanta/mongoose/blob/master/docs/SSL.md

I have SSL enable:

#define NS_ENABLE_SSL

This is my main function:

int main(int argc, char *argv[]) {
  struct mg_server *server;
  char port[10] = "8000";
  const char * _port;

  if (argc > 1) {
    strcpy(port, argv[1]);
  }

  // Create and configure the server
  server = mg_create_server(NULL, ev_handler);

  mg_set_option(server, "listening_port", port);
  _port = mg_get_option(server, "listening_port");
  if (strlen(_port)) {
    printf("Starting on port %s\n", _port);
    for (;;) {
      mg_poll_server(server, 1000);
    }
  }
  else {
    printf("Cannot start on port %s\n", port);
  }

  // Cleanup, and free server instance
  mg_destroy_server(&server);

  return 0;
}

And I have case MG_AUTH: return MG_TRUE; in ev_handler function.

I run my server with:

sudo ./hihttpd 80,ssl://443:ssl.pem

ssl.pem is in the same folder as hihttpd.

https://127.0.0.1/ return me SSL connection error :-/

You can checkout everything on githut https://github.com/apiel/hihttpd/blob/master/hihttpd.c

mpromonet
  • 11,326
  • 43
  • 62
  • 91
Alexandre
  • 3,088
  • 3
  • 34
  • 53

1 Answers1

0

Did you add the option to set the certificate path?

mg_set_option(server,"ssl_certificate", "../ssl.pem");
mpromonet
  • 11,326
  • 43
  • 62
  • 91
Aditya Gupta
  • 896
  • 1
  • 7
  • 9