+ All Categories
Home > Documents > Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 ·...

Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 ·...

Date post: 04-Aug-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
40
WebRTC Is TLS Fast Yet? It can be. Making TLS fast(er)... the nuts and bolts. TLS all the tubes! +Ilya Grigorik @igrigorik
Transcript
Page 1: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

WebRTCIs TLS Fast Yet?It can be. Making TLS fast(er)... the nuts and bolts.

TLS all the tubes!

+Ilya Grigorik@igrigorik

Page 2: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

All communication should be secure, always, and by default! HTTPS everywhere!

Page 3: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

IPTCPTLS

HTTP

Transport Layer Security

... Authenticationam I talking to who they claim to be?

Data integrityhas anyone tampered with the data?

Encryptioncan anyone see my conversation?

Page 4: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

1. Doesn’t TLS have high computational overhead?a. Extra servers, extra ops costs, and so on?

2. Doesn’t TLS incur latency overhead? a. Extra roundtrips translate to slower sites, right?

That’s great, but...

Page 5: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

TLS has exactly one performance problem: it is not used widely enough.

Everything else can be optimized

Page 6: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

CPU + Memorylet’s take a peek under the hood...

Page 7: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

Computational costsAsymmetric crypto (public key) is expensive (relatively speaking)● O(1 ms) per handshake

Symmetric crypto can easily saturate your NIC● 100Mbps+ per core with sha256 and 1024 byte blocks

# upgrade to latest

$> openssl version

# run benchmarks

$> openssl speed sha

$> openssl speed ecdh

Page 8: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

“We have deployed TLS at a large scale using both hardware and software load balancers. We have found that modern software-based TLS implementations running on commodity CPUs are fast enough to handle heavy HTTPS traffic load without needing to resort to dedicated cryptographic hardware.”

Doug Beaver, Facebook.

Page 9: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

“On our production frontend machines, SSL/TLS accounts for less than 1% of the CPU load, less than 10 KB of memory per connection and less than 2% of network overhead. Many people believe that SSL/TLS takes a lot of CPU time and we hope the preceding numbers will help to dispel that.”

Adam Langley, Google.

Page 10: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

Rough memory usage numbers…

TLS compression on ~1MB / connection

TLS compression off ~100KB / connection

Google servers ~10KB / connection

1. Disable TLS compression (security and perf)2. We need to improve open source libraries...

Page 11: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

BoringSSL is exciting!Google’s fork of OpenSSL, will be used in Chrome, Android, …● Internal cleanup patches, reduced resource usage, and so on.

Hot off the press!

Page 12: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

“In practical deployment, we found that enabling and prioritizing ECDHE cipher suites actually caused negligible increase in CPU usage. HTTP keepalives and session resumption mean that most requests do not require a full handshake, so handshake operations do not dominate our CPU usage.”

Jacob Hoffman-Andrews, Twitter.

Elliptic Curve Ephemeral Diffie-Hellman… enables Forward Secrecy.

Page 13: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

TLS resumption 101

Re-use negotiated parameters for the symmetric cipher

● Eliminates asymmetric crypto on the server via reuse of previously used parameters● Eliminates full roundtrip, allowing 1-RTT connection establishment

Page 14: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

TLS resumption

Session identifiers● Server assigns session ID● Server caches parameters● Client sends session ID● Session is “resumed”

Session tickets● Server encrypts parameters● Server sets opaque ticket● Client sends opaque ticket● Server decrypts ticket and resumes session

Shared state is on the server

Shared state is on the client

Page 15: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

TLS handshake with session resumption... $> openssl s_client -connect example.com:443 -tls1 -tlsextdebug -status

SSL-Session: Protocol : TLSv1 Cipher : RC4-SHA Session-ID: 8BE63F4825DDE238E0FE7574D7637080D1278537ECD783512872BFD6FDFB861E Session-ID-ctx: Master-Key: 2FA185F11A791EFB5BA24847FA448B7A0CE73F2D095191F949A35F68CE40FD4EC389E025CCD75 Key-Arg : None TLS session ticket lifetime hint: 600 (seconds) TLS session ticket: 0000 - e4 34 51 9b 4c 13 9d ec-1f 1a 5a ea 89 c6 1f a7 .4Q.L.....Z..... 0010 - b7 d5 25 4e 20 56 b6 00-c2 8d ce 6c 06 8b c9 ff ..%N V.....l.... (snip)

Session Identifier

Session Ticket

● You can enable both: older clients may not support session tickets● Most servers support both, check the docs for configuration options

Page 16: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

A few things to think about…1. Session identifiers

a. Require a shared cache between servers for best resultsb. Sessions must be expired and rotated in a secure manner

2. Session ticketsa. Require a shared ticket encryption keyb. Shared encryption key must be rotated in a secure manner

3. Perfect Forward Secrecy (PFS)“Session ticket keys have to be distributed to all the frontend machines, without being written to any kind of persistent storage, and frequently rotated.”

https://www.imperialviolet.org/2011/11/22/forwardsecret.html

Page 17: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

Latencywhat about those extra roundtrips?

Page 18: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

TLS handshake 101

Certificate verification(asymmetric crypto)

Symmetric key negotiation

encrypted app data

2 RTTs

Page 19: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

CDNs are not just for static content.

Edge termination can significantly reduce TCP and TLS handshake costs!

Terminate TLS at the CDN edge...

RTT with origin

RTT with CDN edge

*Before you hand over the keys to your kingdom, make your your CDN has their TLS stack optimized! You may be surprised...

Page 20: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

Online Certificate Status Protocol (OCSP)

Stop the world and query the OCSP server● DNS lookup● TCP connect● Wait for server response

What if the OCSP check times out, gets blocked, etc? See “Revocation still doesn’t work.”

Has this certificate been revoked?

Page 21: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

● Chrome blocks on EV certs only● Other browsers may block on all (FF)

Eliminating OCSP latency

OCSP endpoint

Use OCSP stapling!1. Server retrieves the OCSP response2. Server “staples” response to certificate3. Client verifies stapled response

Page 22: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

TLS handshake with stapled OCSP response... $> openssl s_client -connect example.com:443 -tls1 -tlsextdebug -status

OCSP Response Data: OCSP Response Status: successful (0x0) Response Type: Basic OCSP Response Version: 1 (0x0) Responder Id: C = IL, O = StartCom Ltd., CN = StartCom Class 1 Server OCSP Signer Produced At: Feb 18 17:53:53 2014 GMT Responses: Certificate ID: Hash Algorithm: sha1 Issuer Name Hash: 6568874F40750F016A3475625E1F5C93E5A26D58 Issuer Key Hash: EB4234D098B0AB9FF41B6B08F7CC642EEF0E2C45 Serial Number: 0B60D5 Cert Status: good

Stapled OCSP means no blocking!

OCSP stapling increases certificate size! Is this a problem for your site? Better check.

Page 23: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

How many RTTs does your certificate incur?

● Average certificate chain depth: 2-3 certificates● Average certificate size: ~1~1.5KB● Plus OCSP response…

● Many cert chains overflow the old TCP (4 packet) CWND● Upgrade your servers to use IW10!

3+ RTT TLS handshake due to 2 RTT cert?

Page 24: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

Check your server, you may be surprised...

● Capture a tcpdump of your handshake and check the exchange

● Some servers will pause on “large certificates” until they get an ACK for the first 4KB of the certificate (doh!)

nginx <1.5.6, HAProxy <1.5-dev22 incur extra RTT, even w/ IW10!

Page 25: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

1-RTT non-resumed handshake with TLS False Start

Client sends application data immediately after “Finished”.

● Eliminates 1RTT● No protocol changes...● Only timing is affected

In practice…● Some servers break (ugh)● Hence, opt-in behavior...

Page 26: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

Deploying False Start...● Chrome and FirefoxChrome and Firefox● NPN/ALPN advertisement - e.g. “http/1.1”● Forward secrecy ciphersuite - e.g. ECDHE

Safari● Forward secrecy ciphersuite

Internet Explorer● Blacklist + timeout● If handshake fails, retry without False Start

TL;DR: enable NPN advertisement and forward secrecy to get 1RTT handshakes.

Page 27: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

Ingredients for a 1-RTT TLS experience…1. False Start = 1-RTT handshake for new visitors

a. New users have to perform public-key crypto handshake

2. Session resumption = 1-RTT handshake for returning visitorsa. Plus, we can skip public-key crypto by reusing previous parameters

3. OCSP Staplinga. No OCSP blocking to verify certificate status

4. False Start + Session Resumption + OCSP staplinga. 1-RTT handshake for new and returning visitorsb. Returning visitors can skip the public-key crypto

Page 28: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

What’s wrong with this picture?

300ms RTT, 1.5Mbps...

● It’s a 2-RTT time to first byte!○ Large records are buffered, which delays processing!

● It’s a 2-RTT handshake… we know better!○ At least there is no OSCP overhead!

Page 29: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

TLS record size + latency gotchas...

This record is split across 8 TCP packets

TLS allows up to 16KB of application per record● New connection + 16KB record = CWND overflow and an extra RTT● Lost or delayed packet delays processing of entire record

Page 30: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

Optimizing record size…1. Google servers implement dynamic record sizing

a. New connections start with 1400 byte records (aka, single MTU)b. After ~1MB is sent, switch to 16K recordsc. After ~1s of inactivity, reset to 1400 byte records

2. Most servers don’t optimize this case at all...a. HAProxy recently landed dynamic sizing patch - yay!b. Nginx recently landed ssl_buffer_size: static override - better, but meh...

TL;DR: there is no “perfect record size”. Adjust dynamically.

Page 31: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

Quick sanity check... theory is great, but does this all work in practice?

Page 32: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

Tuning Nginx TLS Time To First Byte (TTTFB)

● Pre 1.5.7: bug for 4KB+ certs, resulting in 3RTT+ handshakes● 1.7.1 added ssl_buffer_size: 4KB record size remove an RTT● 1.7.1 with NPN and forward secrecy → 1RTT handshake

https://www.igvita.com/2013/12/16/optimizing-nginx-tls-time-to-first-byte/

Page 33: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

● “Out of the box” TLS performance is poor… we need to fix this.● No server is perfect, plenty of work to be done to improve perf.

Page 34: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

There is way too much red here… Bug your CDN about fixing this!

Page 35: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

isTLSfastyet.com

Page 36: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

Getting ready for HTTP/2(SPDY, same thing)... better perf and lower ops costs!

Page 37: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

HTTP/2 and SPDY

● In practice, you need TLS to deploy SPDY & HTTP/2● HTTP/2 uses a single connection to mux all requests to same origin

Google News Google Sites Google Drive Google Maps

Median 43% 27% 23% 24%

95th percentile 44% 33% 36% 28%

Page load time improvement with SPDY enabled...

Improvement over HTTP/1.1 + TLS

Page 38: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

“SPDY also has advantages on the server:

SPDY requests consume less resources on the serverSPDY requests consume less memory but a bit more CPU SPDY requires fewer Apache worker threads”

Hervé Servy, Neotys.

s/SPDY/HTTP2/g … same results.

Fewer connections means that...

Page 39: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

Deliver 1-RTT handshake 100% of the time1. TLS False Start for new visitors2. TLS resumption for returning visitors3. Ensure that server is able to send full cert chain without blocking4. OCSP stapling to avoid blocking

Optimize data delivery1. Optimize record size to avoid unnecessary buffering delays2. Leverage SPDY / HTTP/2 to further reduce latency and ops costs

a. Leverage HTTP/2 optimizations: unshard, un-concat, etc

An optimized TLS deployment should...

Page 40: Is TLS Fast Yet? WebRTCseoblog.giorgiotave.it/files/2014/07/Making-TLS-Faster.pdf · 2014-07-25 · Protocol : TLSv1 Cipher : RC4-SHA Session-ID: ... No protocol changes... Only timing

Thanks! Questions?

+Ilya Grigorik@igrigorik

Slidesbit.ly/fastTLS

Learn moreisTLSfastyet.com


Recommended