Saturday, April 11, 2015

Enabling Opportunistic Encryption in Nginx

The week of March 31th Mozilla released Firefox 37 with support of Opportunistic Encryption (OE) - a mechanism which allows to encrypt traffic over HTTP connection with a self-signed certificate which bypasses validation.

Be adviced that this feature was disabled in Firefox 37.0.1 due to bug which allowed to bypass certificate validation over HTTPS connection (https://www.mozilla.org/en-US/security/advisories/mfsa2015-44/).

In order to enable OE you need to have HTTP/2 or SPDY enabled server and send Alt-Svc HTTP header on unencrypted HTTP-connection, e.g.: Alt-Svc: h2=":443 or Alt-Svc spdy/3.1=":443" if you use SPDY.

Below you can see example of Nginx configuration:

http {
    server {
        listen       80;
        server_name  example.com,*.example.com;
        add_header   Alt-Svc spdy/3.1=":443";
    }

    server {
        listen       443 ssl spdy;
        server_name  example.com,*.example.com;
    }
}