GoAhead Web Server comes with internal SSL support. it's disabled by default, and I haven't seen a tutorial around this topic on the web. so here is the my adventure of enabling it.
Difficulties with goahead
According to the goahead's feature page, SSL is fully supported. but it's not so convienent to enable it. the downloaded source package doesn' t include the source code of the SSL library that it depends It. even the distribution package (header file and library file) isn' t there.
If we trun the macro webs_ssl_support definition on, what we get eventually is compilcation error. You may see the error of Type SSL isn' t defined.
Then we can see there is a mocana project file, so we guess go ahead is using mocana library. And now problem comes, mocana is a comerical product and it's not freely available.
Use OpenSSL instead
Luckily, we found there was a macro named OpenSSL. It's a symbol of OpenSSL can be an alternative option here.
Looking deeply inside the code, we can see that goahead provides a abstract layer above the underlying SSL library. So that we can change the implementaion easily. See? It's a typical usage of adapter design pattern.
We downloaded the OpenSSL source, compile a Linux version binary set. the OpenSSL is a powerful SSL tool set. in addition to the SSL library itself, it also contains several utility tools. within those tools, OpenSSL is a useful terminal tool. it can act as a SSL server, ssl client, and certificate file generator.
What's specifically useful is we can generate and sign certificate file with it and use them to test our server. This page tells how to generate and sign certificates.
In goahead's code, it uses three certificate files.
Privkey. pem: the private key
Cacert. pem: The certificate
Server. pem: a combination of private key and cacert. the first part of its content is privkey. PEM and the second part is cacert. pem.
Having got those files, we changed the makefile to define webs_ssl_support and OpenSSL macro to enable SSL. Compiled again and run.
How to visit
The GoAhead Web server listens on a differnt port for incoming secure connection. the port is defined as ssl_port macro N in websssl. c with default value 433. to test, open the browser and visit https: // address: ssl_port.
Since we used a self signed certificates, the Firefox won't allow access to it. we have to add our site to Firefox exception list from "tools-advanced-encryption-view certificates-add exception ".