diff --git a/examples/web_server/Makefile b/examples/web_server/Makefile index ba3a2084..ee9bc1b0 100644 --- a/examples/web_server/Makefile +++ b/examples/web_server/Makefile @@ -4,9 +4,25 @@ PROG = web_server CFLAGS = -W -Wall -I../.. -pthread -g -O0 -DMONGOOSE_ENABLE_THREADS $(CFLAGS_EXTRA) SOURCES = $(PROG).c ../../mongoose.c +OPENSSL_FLAGS = -DNS_ENABLE_SSL -lssl + +# PolarSSL paths and flags +POLARSSL_PATH = /usr/local +POLARSSLCOMPAT_PATH = ./../../../polar +SOURCES_POLAR = $(SOURCES) $(POLARSSLCOMPAT_PATH)/polarssl_compat.c +INCDIR_POLAR = -I$(POLARSSLCOMPAT_PATH) -I$(POLARSSL_PATH)/include +LDFLAGS_POLAR = -L$(POLARSSL_PATH)/lib -lmbedtls +CFLAGS_POLAR = $(CFLAGS) $(INCDIR_POLAR) -DNS_ENABLE_SSL +# $(PROG): $(SOURCES) $(CC) -o $(PROG) $(SOURCES) $(CFLAGS) +openssl: + $(CC) -o $(PROG) $(SOURCES) $(CFLAGS) $(OPENSSL_FLAGS) + +polarssl: + $(CC) -o $(PROG) $(SOURCES_POLAR) $(LDFLAGS_POLAR) $(CFLAGS_POLAR) + clean: rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib diff --git a/examples/web_server/certs/cert.pem b/examples/web_server/certs/cert.pem new file mode 100644 index 00000000..f191e3c1 --- /dev/null +++ b/examples/web_server/certs/cert.pem @@ -0,0 +1,46 @@ +-----BEGIN CERTIFICATE----- +MIIC+zCCAeOgAwIBAgIJAPhB8jbL+G82MA0GCSqGSIb3DQEBCwUAMBQxEjAQBgNV +BAMMCTEyNy4wLjAuMTAeFw0xNTAzMDYxMjQzMzNaFw0yNTAzMDMxMjQzMzNaMBQx +EjAQBgNVBAMMCTEyNy4wLjAuMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC +ggEBALi3b3daMgzUEROKob1Caf68i+//cTRkPdBJv2cOBak21CdQzY0N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zlR3p1CimWehLmCopHXorr1iocMIdP0535L+ZU258y3N +vaA0HpFTW9PsYgaMwLMJ7uAY3lVkIzx84e849i2HqHMgLkl0dbW+WFXL2xblxylv +yU2wuNNED/EB4lTawcpycAvTKYvrBXt4lVE4S9exAoGAGl6vZV3zyw4jpIw4uDfk +LTPYUrghFDDGKExyeOnC/W9pqR2veqzfBz02C3jqwhewoqgAcnNc2sg0rJmM+6Oz +Z2mmGZTHO9xR++7+W7e8AkQBbS6TB8a+7yNcM4USLP+b9sX5N+8gFhFs9tG7j/no +G44qLsJ/yve7/QsOA37uEMs= +-----END PRIVATE KEY----- diff --git a/examples/web_server/web_server.c b/examples/web_server/web_server.c index 8f8567af..07fda84e 100644 --- a/examples/web_server/web_server.c +++ b/examples/web_server/web_server.c @@ -71,7 +71,12 @@ static char server_name[50]; // Set by init_server_name() static char s_config_file[PATH_MAX]; // Set by process_command_line_arguments static struct mg_server *server; // Set by start_mongoose() static const char *s_default_document_root = "."; +#ifndef NS_ENABLE_SSL static const char *s_default_listening_port = "8080"; +#else +static const char *s_default_listening_port = "ssl://8443:certs/cert.pem"; +#endif + static char **s_argv = { NULL }; static void set_options(char *argv[]);