To keep this practical, we will not go into the theory of ECC or RSA certificates. Let’s just mention that ECC certificates can provide as much security as RSA with a much lower key size, meaning much lower computation requirements on the server side. Sadly, many clients do not support ciphers based on ECC, so to maintain compatibility as well as provide good performance we need to be able to detect which type of certificate is supported by the client to be able to serve it correctly.

The above is usually achieved by analyzing the cipher suites sent by the client in the ClientHello message at the start of the SSL handshake, but we’ve opted for a much simpler approach that works very well with all modern browsers (clients).

Prerequisites

First, you will need to obtain both RSA and ECC certificates for your website. Depending on the registrar you are using, check their documentation. After you have been issued with the certificates, make sure you download the appropriate intermediate certificates and create the bundle files for HAProxy to read.

To be able to use the sample fetch required, you will need at least HAProxy 1.6-dev3 (not yet released as of writing) or you can clone the latest HAProxy from the git repository. The feature was introduced in commit 5fc7d7e.

Configuration

We will use chaining in order to achieve the desired functionality. You can use abstract sockets on Linux to get even more performance, but note the drawbacks that can be found in HAProxy documentation.

 frontend ssl-relay
 mode tcp
 bind 0.0.0.0:443
 tcp-request inspect-delay 5s
 # Ensure we wait for the existence or lack of the extension
 tcp-request content accept if { req.ssl_ec_ext 0 }
 # Make routing decision
 use_backend ssl-ecc if { req.ssl_ec_ext 1 }
 default_backend ssl-rsa

 backend ssl-ecc
 mode tcp
 server ecc unix@/var/run/haproxy_ssl_ecc.sock send-proxy-v2

 backend ssl-rsa
 mode tcp
 server rsa unix@/var/run/haproxy_ssl_rsa.sock send-proxy-v2

 listen all-ssl
 bind unix@/var/run/haproxy_ssl_ecc.sock accept-proxy ssl crt /usr/local/haproxy/ecc.www.foo.com.pem user nobody
 bind unix@/var/run/haproxy_ssl_rsa.sock accept-proxy ssl crt /usr/local/haproxy/www.foo.com.pem user nobody
 mode http
 server backend_1 192.168.1.1:8000 check

The whole configuration revolves around the newly implemented sample fetch: req.ssl_ec_ext. What this fetch does is that it detects the presence of Supported Elliptic Curves Extension inside the ClientHello message. This extension is defined in RFC4492 and according to it, it SHOULD be sent with every ClientHello message by the client supporting ECC. We have observed that all modern clients send it correctly.

If the extension is detected, the client is sent through a unix socket to the frontend that will serve an ECC certificate. If not, a regular RSA certificate will be served.

Benchmark

We will provide full HAProxy benchmarks in the near future, but for the sake of comparison, let us view the difference present on an E5-2680v3 CPU and OpenSSL 1.0.2.

256bit ECDSA:
sign verify sign/s verify/s
0.0000s 0.0001s 24453.3 9866.9

2048bit RSA:
sign verify sign/s verify/s
0.000682s 0.000028s 1466.4 35225.1

As you can see, looking at the sign/s we are getting over 15 times the performance with ECDSA256 compared to RSA2048.

UPDATE 2018

The above is only required if you are using HAProxy 1.6 or you are using any OpenSSL version before 1.0.2. If you are using an up-to-date version of HAProxy and OpenSSL, you can use the native ECC/RSA switching by naming your certificates with a. rsa, .dsa or .ecdsa suffix. More information can be found in the official documentation: https://www.haproxy.com/documentation/hapee/1-8r1/onepage/#5.1-crt

Subscribe to our blog. Get the latest release updates, tutorials, and deep-dives from HAProxy experts.