Setting up HTTPS using Let's Encrypt

From EPrints Documentation
Revision as of 08:39, 1 September 2017 by Drn@ecs.soton.ac.uk (talk | contribs) (Drn@ecs.soton.ac.uk moved page Setting up HTTPS using Lets's Encrypt to Setting up HTTPS using Let's Encrypt without leaving a redirect: typo)
Jump to: navigation, search

By default EPrints does not come setup to use HTTPS. This is because you need to generate an SSL certificate and if this is not signed by a known Certificate Authority a user web browser is likely to complain vigourously. In the past it has typically costed a fair amount of money to obtain an SSL certificate from your hosting provider. However, now there is Let's Encrypt it is possible to get a certificate for free. This is not to say you should use Let's Encrypt in all cases. UK academic institutions should continue to obtain their SSL certificates through Jisc and other institutions/organisations may already have similar arrangements for obtaining SSL certificates.

As well as being free, Let's Encrypt has an automated way for renewing certificates. However, it should be noted that the length of its certificates is a lot shorter than usually at 3 months. As the renewal process is automatic this time period is more appropriate to maximise security. Let's Encrypt's certificate generation requires your EPrints repository to be publicly accessible. Beneath are instructions on how to setup EPrints to enable HTTPS with a Let's Encrypt certificate.

1. Go to the https://certbot.eff.org/ and follow the instructions for your web server and operating system (the former will almost always be Apache) and follow the instructions provided.


2. When you get to the point of running the certbot command you want the certificate only so should type as the root user:

certbot --apache certonly

3. Take a note of the path to were your certificate, key and CA chain have been saved. This will probably be something like

/etc/letsencrypt/live/example.eprints.org/

4. If you have not already done so create an directory called ssl inside your archive's directory. E.g.

mkdir /opt/eprints3/archives/example/ssl/

5. Create a file inside the new ssl directory called securevhost.conf and include the following contents, amending the ServerName, SSLCertificateFile, SSLCertificateKeyFile SSLCertificateChainFile and Include as appropriate. You will note that this configuration also enables HTTP Strict Transport Security (HSTS) for additional security. This ensures that after the first time you visit HTTPS for a particular site in your web browser, all future HTTP requests for this hostname will automatically be converted by your browser to HTTPS.

<VirtualHost *:443>

    ServerName example.eprints.org:443

    # Enable HSTS
    Header always set Strict-Transport-Security "max-age=63072000;"

    SSLEngine on
    SSLProtocol all -SSLv2 -SSLv3
    SSLHonorCipherOrder on
    SSLCipherSuite HIGH:!aNULL:!eNULL:!kECDH:!aDH:!RC4:!3DES:!CAMELLIA:!MD5:!PSK:!SRP:!KRB5:@STRENGTH

    SSLCertificateFile /etc/letsencrypt/live/example.eprints.org/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.eprints.org/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/example.eprints.org/chain.pem

    SetEnvIf User-Agent ".*MSIE.*" \
        nokeepalive ssl-unclean-shutdown \
        downgrade-1.0 force-response-1.0

    LogLevel warn
    ErrorLog logs/ssl_error_log    
    TransferLog logs/ssl_access_log
    CustomLog logs/ssl_request_log \
        "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

    Include /opt/eprints3/cfg/apache_ssl/test.conf

    PerlTransHandler +EPrints::Apache::Rewrite

</VirtualHost>

6. Now you will need to regenerate the rest of your Apache configuration for EPrints will the following command run as the EPrints user. (Substitute the path as appropriate):

/opt/eprints3/bin/generate_apacheconf --system --replace

7. Apache will not yet have been setup to include the Apache configuration file you create in step 5. To include this you will need to edit the file in your Apache configuration directory (/etc/httpd/ on RHEL/CentOS/Fedora and /etc/apache2/ on Debian/Ubuntu) and find the file that contains the line cfg/apache.conf. E.g.

cd /etc/httpd/
grep "cfg/apache.conf" *

8. Once you have found it you will need to edit it and add the following line, changing the path as appropriate:

Include /opt/eprints3/archives/example/ssl/securevhost.conf

9. Now test that the Apache configuration is correct and fix any issues if necessary:

apachectl configtest

10. Restart Apache and check whether you can access your EPrints repository using HTTPS in a web browser:

apachectl restart

11. If the guide on cerbot.eff.org you used in step 1 tells you to to setup a cron job then follow those instructions. The easiest way to do this is probably to run 'crontab -e as root and add the following cron job, substituting the minute (43) and hours (6,18) for you own choice maintaining a 12 hour gap between the hours:

43 6,18 * * * certbot renew