Using CheapSSLs certificates with stunnel
CheapSSLs website sells cheapest mainstream SSL certificates currently. Apparently they are part of NameCheap group and also run ssls.com website. Prices are really low, and running SSL is not really that expensive anymore.
In my setup, I'm mostly using stunnel in front of HAProxy, which then does load-balancing to a bunch of nginx, Apache and node.js servers. Configuring each of those for SSL would be PITA, so I'm simply using stunnel. The only drawback was getting IP addresses of connected web clients. This can be solved with proxy protocol using HAProxy 1.5, but I also use websockets and json-polling and xhr-polling with node.js and socket.io I cannot use the proxy protocol. So I patched stunnel 5.0 with 4.x patch you can find on the net, to give me additional HTTP headers.
When you apply for SSL cert at cheapssls, they ask for the type of web server and even though there are 20+ options, stunnel is not one of them. So I picked "other". I got three files:
- mydomain.csr
- AddTrustExternalCARoot.crt
- PositiveSSLCA2.crt
BTW, to create the certificate request, I used the same procedure as with GoDaddy.
I tried to set it up using intuition and previous experience with GoDaddy, but it just would not work. I would get this error:
[!] SSL_CTX_use_PrivateKey_file: B080074: error:0B080074:x509 certificate routines:X509_check_private_key:key values mismatch [!] Service [domain]: Failed to initialize SSL context
So I tried to use the CAfile setting, copy/paste certificates again, and stunnel just would not start. If I removed intermediate certificates it would work, but then it would not support all the browsers out there.
Finally, after a lot of trial and error and trying out various howtos on the net, I got it working. Here's how to do it. First, create a file containing your certificate, intermediate certificate and root certificate, in that exact order. This is important, because it would not work otherwise:
cat yourdomain.crt PositiveSSLCA2.crt AddTrustExternalCARoot.crt > all.pemNext, set up a stunnel.conf file like this:
cert=/full/path/to/all.pem key=/full/path/to/yourdomain.key
Do not use the CAFile setting at all. And that's it. It's really simple once you get it working.
Tweet to @mbabuskov Tweet Milan Babuškov, 2014-03-26