Google recently announced that it is going to start prioritising websites that offer HTTPS by default in its search engine results. At first, the positive effect will be small to give webmasters time to switch to HTTPS, but it will gradually become more of a significant signal. This is a good thing for the internet: SSL doesn't cost much for webhosts, and it makes it more difficult to spy on everyone all the time! The Electronic Frontier Foundation praised the decision calling it a "bold and welcome move to protect users".
I wanted to start offering some of the services I run on my server to other friends and family, and I couldn't easily install the CAcert root on all of their devices, so this seemed like a good time to purchase a cert. The following describes how I configured the various services (Apache, Postfix, Dovecot) to use the new certificate from COMODO.
Differences to CAcert certificate
Until now, I have used a certificate signed by CAcert for the site and used Apache's mod_rewrite to redirect unauthenticated users (everyone except me) back to http. I chose to do this because unless the CAcert root was installed on the client machine, the users would get a browser error; I also didn't want Google crawling the HTTPS site and penalising me for having duplicate content (http and https).
Configuring Apache and the other services to use the cert signed by CAcert was easy because it was signed directly by the CAcert root: I just had to give Apache a path to the new certificate file, it sent the cert to clients when they made a connection, and it was accepted because it was signed by a trusted root certificate. However, commercial certificate authorities generally don't use their root certificates to validate domains because having the root key in constant use increases the likelihood that the key could be compromised. Instead, they use the root key to sign an intermediate certificate, and then use the intermediate key to validate domains. If they didn't do this and the root key was compromised, every operating system would have to push an update to remove the compromised root certificate from the trusted certificate store on users' machines; this way, if the intermediate key is compromised the certificate authority can revoke the intermediate cert and generate a new one without the root certificate being affected.
The small downside of this is that Apache now needs to send a string of certs to each client containing every certificate between yours and the root cert, or the client will just check to see if your cert was signed directly by a root CA in its trusted certificate store, and reject it if it wasn't. The string of certs forms a chain of trust, i.e. "the samhobbs.co.uk_cert was signed by intermediate_cert which was signed by root_ca". So, the first thing I had to do was concatenate the certificate files to make one jumbo certificate file.
Creating a certificate bundle
Comodo sent me a .zip archive
samhobbs_co_uk.zip containing the following files:
To unzip the archive use the
mkdir ~/certs mv samhobbs_co_uk.zip ~/certs/samhobbs_co_uk.zip cd ~/certs unzip samhobbs_co_uk.zip
The order of the certs in the concatenated file is important: you want your certificate at the top of the file, the one that signed your cert (intermediate1) below that, and the one that signed that one (intermediate2) below that. The root certificate should be left off the file: each client will already have a copy of this file in its trusted certificate store... and if they don't then sending them it won't help, the cert will still be rejected! Actually, the RFC for TLS says that you MAY include the anchor (root cert), which means it will work either way... but the QUALYS SSL Labs test, which we will be using later, will flag it up as an anomaly if you do.
So... which file is which? You can get information about certs in a human readable format by using this command:
openssl x509 -text -in /path/to/your/cert.crt
Certificate: Data: Version: 3 (0x2) Serial Number: 96:3b:4e:d8:b9:2c:7a:6c:1d:08:4f:fd:e1:c0:3f:3a Signature Algorithm: sha256WithRSAEncryption Issuer: C=GB, ST=Greater Manchester, L=Salford, O=COMODO CA Limited, CN=COMODO RSA Domain Validation Secure Server CA Validity Not Before: Aug 15 00:00:00 2014 GMT Not After : Aug 14 23:59:59 2019 GMT Subject: OU=Domain Control Validated, OU=PositiveSSL, CN=samhobbs.co.uk Subject Public Key Info: Public Key Algorithm: rsaEncryption Public-Key: (2048 bit) Modulus: 00:d3:a3:1a:49:1f:02:6e:a5:38:75:0f:32:2f:89: fc:a0:b3:e5:51:0f:25:c4:17:5c:3c:82:1a:ea:df: a5:ad:03:f0:e3:76:8d:b7:7a:80:8c:41:88:8f:34: 26:01:a3:b2:49:60:d1:7c:39:ac:ed:31:5f:30:6a: b7:54:2a:f4:ee:a3:a7:c2:1b:5b:14:17:94:b2:9a: 16:87:04:43:d7:12:25:8e:ef:2a:ac:5e:24:3f:73: 12:c0:27:ff:26:f5:3a:8b:64:89:01:32:d8:db:f6: f6:19:7b:b4:4e:82:14:6a:a2:de:db:dc:c3:b6:76: 08:47:48:a0:30:7a:31:b2:7c:38:b1:c1:2f:b4:bc: 7c:61:3e:76:ea:c1:97:47:29:d7:5c:cb:77:4d:a6: 68:5f:34:57:dc:36:ec:27:c3:b8:98:9a:8c:d3:15: c4:7d:bd:5c:f0:9d:49:27:d2:6e:a9:f7:51:b3:16: 58:4f:b0:36:45:33:93:81:7c:8d:93:16:ca:dd:20: 21:84:c6:e1:a4:ce:72:b3:1f:6f:84:f2:89:65:4e: ce:1e:b8:ef:f3:06:4a:4a:44:a7:99:20:06:72:c8: 50:9f:37:e2:39:be:ea:1f:75:5c:0a:69:6f:e2:4e: 99:88:89:18:8e:16:51:b3:35:1b:52:29:1a:77:9b: 82:79 Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Authority Key Identifier: keyid:90:AF:6A:3A:94:5A:0B:D8:90:EA:12:56:73:DF:43:B4:3A:28:DA:E7 X509v3 Subject Key Identifier: 81:6A:52:BA:72:60:2F:A3:F1:9F:00:20:36:0A:E9:14:BC:37:BC:C3 X509v3 Key Usage: critical Digital Signature, Key Encipherment X509v3 Basic Constraints: critical CA:FALSE X509v3 Extended Key Usage: TLS Web Server Authentication, TLS Web Client Authentication X509v3 Certificate Policies: Policy: 188.8.131.52.4.1.64184.108.40.206.3.4 CPS: https://secure.comodo.net/CPS Policy: 220.127.116.11.2.1 X509v3 CRL Distribution Points: Full Name: URI:http://crl.comodoca.com/COMODORSADomainValidationSecureServerCA.crl Authority Information Access: CA Issuers - URI:http://crt.comodoca.com/COMODORSADomainValidationSecureServerCA.crt OCSP - URI:http://ocsp.comodoca.com X509v3 Subject Alternative Name: DNS:samhobbs.co.uk, DNS:www.samhobbs.co.uk Signature Algorithm: sha256WithRSAEncryption 0c:29:6b:2a:18:d4:25:54:9c:88:6a:3d:1c:8b:2f:99:0f:88: 10:4f:11:56:cd:28:cc:67:6f:d3:de:c6:f1:54:f8:b5:1a:b7: 6b:94:9c:74:7c:e2:41:49:46:ed:a7:c2:49:c6:5b:c2:02:c9: 08:c8:26:fd:f2:15:1d:28:c8:24:ca:aa:6a:e2:1e:74:96:9c: d1:f9:78:58:3a:f2:8c:bf:e7:f9:37:3b:eb:ac:c5:09:3f:23: fc:63:4a:aa:d9:64:38:78:5b:83:69:81:b2:a6:3e:83:a6:bd: 9a:2a:82:4e:3d:ee:ec:15:2f:53:a7:b2:00:89:e2:97:d2:ee: 6a:75:38:9a:7c:8b:c6:67:fe:be:7f:0f:ee:24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Xdbir65FW1sHuBUZ6zy1I58Ms= -----END CERTIFICATE-----
And if you just want to know who issued the cert (who signed it) then use this command:
openssl x509 -noout -in samhobbs_co_uk.crt -issuer
issuer= /C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Domain Validation Secure Server CA
So we can see that my cert was signed by
COMODORSADomainValidationSecureServerCA.crt. Using the same command on the other certs reveals that the order, from root to my cert, is:
- AddTrustExternalCARoot.crt (ROOT)
So, to combine all of these files into one we can use the
cat command, listing them in reverse order and omitting the root cert:
cat samhobbs_co_uk.crt COMODORSADomainValidationSecureServerCA.crt COMODORSAAddTrustCA.crt > samhobbs.co.uk-new.ca-bundle
So, now that we have a combined certificate file, let's configure Apache2, Dovecot and Postfix to use it:
In the following examples, I'm using these paths as an example:
- The certificate (on its own) is located at
- The certificate bundle is located at
- The key file is located at
In your postfix configuration file
/etc/postfix/main.cf, find these two parameters and edit them to match these lines:
As you can see, Postfix only needs the certificate bundle and the key file; the certificate file on its own is not used.
The SSL configuration for Dovecot is found at
/etc/dovecot/conf.d/10-ssl.conf, and needs the key file and the certificate bundle, similar to Postfix:
ssl_cert = </etc/ssl/certs/samhobbs.co.uk-new.ca-bundle ssl_key = </etc/ssl/private/samhobbs.co.uk-new.key
< isn't a mistake, don't leave it out!
Apache2 is the odd one out here, because it requires three parameters in versions before 2.4.8, like so:
SSLCertificateFile /etc/ssl/certs/samhobbs.co.uk-new.crt SSLCertificateChainFile /etc/ssl/certs/samhobbs.co.uk-new.ca-bundle SSLCertificateKeyFile /etc/ssl/private/samhobbs.co.uk-new.key
I.e. the cert on its own, the certificate bundle and the key file.
In new versions (greater than 2.4.8) things have improved:
SSLCertificateChainFile is depreciated;
SSLCertificateFile was extended so that you can pass it a certificate bundle... so now Apache just needs two parameters:
SSLCertificateFile /etc/ssl/certs/samhobbs.co.uk-new.ca-bundle SSLCertificateKeyFile /etc/ssl/private/samhobbs.co.uk-new.key
If you're not sure which version of Apache you're running, you can check with this command:
At the time of writing (01 Sep 2014), the version of Apache2 in the Ubuntu 14.04 repositories is 2.4.7 and the version in the Raspbian/Debian stable repos is 2.2.22; both of these packages use the "old way" but Ubuntu will soon get the new version.
HTTP Strict Transport Security (HSTS)
If your site is HTTPS only, you can make use of a technology called HTTP Strict Transport Security (HSTS), where Apache sends a header to the client's browser that tells it to always connect with HTTPS. This site is using HSTS now: if you have visited before and you type http://samhobbs.co.uk in your browser it will rewrite to https://samhobbs.co.uk before it sends a request to my server.
This is different to rewriting HTTP to HTTPS on the server because the rewrite is done client side, and can help prevent certain kinds of Man In The Middle (MITM) attacks.
Note that you still need to have a HTTP virtualhost that rewrites to HTTPS because this only works when someone has visited to the site before: new users will need a server-side rewrite before their browser has stored the header.
Setting up HSTS is really simple: all you need to do is add this to your HTTPS virtualhost:
Header add Strict-Transport-Security "max-age=15768000"
And then reload Apache:
sudo service apache2 reload
Obviously, don't do this for sites where you actually want to have separate HTTP and HTTPS sites on the same domain name, or you won't be able to access the HTTP site without clearing your cache to remove the header.
Perfect Forward Secrecy
While we are talking about SSL, I thought I'd mention Perfect Forward Secrecy (PFS). This is technology that helps protect users by ensuring that if a SSL key is decrypted in the future it couldn't be used to decrypt past sessions that were captured (by security services or your ISP, for example).
Or in other words (from the EFF article below):
When an encrypted connection uses perfect forward secrecy, that means that the session keys the server generates are truly ephemeral, and even somebody with access to the secret key can't later derive the relevant session key that would allow her to decrypt any particular HTTPS session. So intercepted encrypted data is protected from prying eyes long into the future, even if the website's secret key is later compromised.
I don't have any special knowledge of the various ciphers used in SSL/TLS, so the configuration below was taken from the Mozilla wiki, using the backward compatible ciphersuite. The order of the list prioritises strong ciphers that support forward secrecy.
First, you need Apache 2.3.3 or higher (see earlier in this article for how to check your version).
Next, put this inside your SSL virtualhost:
SSLProtocol all -SSLv2 SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128:AES256:AES:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK SSLHonorCipherOrder on SSLCompression off
Now test your configuration with the Qualys SSL Labs test!
You can read some more about VirtualHost files on Apache2 in this tutorial of mine.