Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Where do we go after Http 1.1 - Http2 by Mihail Stoynov

Riga Dev Day
March 13, 2016
35

Where do we go after Http 1.1 - Http2 by Mihail Stoynov

Riga Dev Day

March 13, 2016
Tweet

More Decks by Riga Dev Day

Transcript

  1. Agenda • Who am I? • What is the problem?

    • HTTP/2 • Enabled websites • Analyzing HTTP/2 • How do we know a site is using HTTP/2 • Chrome internals • Tools to analyze HTTP/2 • How can we start using HTTP/2?
  2. Who am I? @mihailstoynov • Day job: sty.bz • Java

    • Security audits, web pen testing, sec tools • Training, travelling, • Hobby: jug.bg • Java evangelism -> organizing events • Java patches, writing manuals, early adoption • Hobby2 • Writing books, university courses….
  3. What is the problem with current http? • The CNN

    homepage has 157 resources: • HTTP/1.0 – allows only one connection per request • This means 157 connections have to be created • HTTP/1.1 has keep-alive • Allows reusing of connections, but it is serial • If one request is slow, others wait • Optimizations: image sprites, domain sharding, concatenating js/css, inlining css/js • Headers are repeated for every request (and sometimes they are as big as 1kb)
  4. HTTP/2 • HTTP/2 is a binary protocol designed for low

    latency transport of content • One of the goals is: there should be no change for web developers • Key features: • One connection per domain • Multiplexing – multiple Streams over the same connection. • Header compression – reuse previous headers • Server push – the server pushes stuff before the client even requests it • Prioritization – some resources can be more important than others
  5. HTTP history • You have used HTTP/2 since 2009 if

    you used Chrome • HTTP/2 began as SPDY • Developed by Google and silently used since 2009/2010 • Became a standard on February 17, 2015 (HTTP/1.1 was born 1997) • 18 YEARS after HTTP/1.1 • Currently used by • Gmail, google.com • twitter, facebook • wikipedia (still uses spdy) • And of course our community site: https://jprime.io
  6. Streams and Frames • HTTP/2 defines streams (bidirectional sequence of

    data) • One TCP connection can have multiple streams • Streams are not raw, they are typed • The structure inside a stream is called a frame • Frame types: HEADERS, DATA, SETTINGS, PUSH_PROMISE • A request/response in http2 is HEADERS/DATA
  7. How do we know a site is on HTTP/2? •

    Browsers don't tell • Developer tools are somewhat helpful • Headers can be a hint
  8. How do we know a site is on HTTP/2? •

    Browser plugins • Yeah, you can install it right now and follow the demos
  9. Tools to help analyze http2 traffic • Burp Suite –

    NO • ZAP – NO • cURL – NO (you have to build it yourself, I tried and gave up) • Wireshark • Wireshark can't mitm ssl, can only read ssl with a private key • Browsers support only strong crypto with http2 • Perfect Forward Secrecy • (if you have the private key, you cannot decrypt old data) • https://en.wikipedia.org/wiki/Forward_secrecy • Diffie-Hellman key exchange (DHE-RSA, DHE-DSS) • Wireshark is useless in this scenario
  10. How can I start using HTTP/2? • https://github.com/http2/http2-spec/wiki/Implementations • Java

    apps • Tomcat – NO • Undertow - Limited • Jetty - extensive support • Nginx 1.9.5 has an "experimental" http2 module • Nginx Plus supports PUSH • Apache after 2.4.17 (my hosting provider is not using it, so no luck yet)
  11. https://jprime.io • Supports HTTP/2 • You can test it •

    Real SSL certificate • Supported protocol IDs: h2 • Negotiation: ALPN, NPN, direct • No upgrade supported
  12. h2 vs h2c (protocol identifiers) • h2 denotes HTTP/2 over

    TLS with ALPN for negotiation • h2c denotes cleartext HTTP/2 with direct negotiation • h2-14, h2c-14 – stands for draft 14 • h2-15, h2c-15 – stands for draft 15 • h2-16, h2c-16 – stands for draft 16 • h2-17, h2c-17 – stands for draft 17 • h2, h2c – the official spec impl • SPDY/3.1: Google's first version of the HTTP/2 spec, formed the basis of HTTP/2
  13. ALPN • Application-Layer Protocol Negotiation is a TLS extension for

    protocol resolution • This is how the servers/clients discover http2 (only for ssl) • Example from Chrome (doesn't support h2c):
  14. https://jprime.io:8443 (bad cypher) • Supports HTTP/2 • You can test

    it • Real SSL certificate • Supports protocol ids: h2 • Negotiation: ALPN, NPN, direct • No upgrade • Bad cyphers in this example • ssl_ciphers AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;
  15. TLS 1.2 Cypher Suites • A deployment of HTTP/2 over

    TLS 1.2 SHOULD NOT use any of the cipher suites that are listed in the cipher suite black list • https://http2.github.io/http2-spec/#BadCipherSuites
  16. http://jprime.io:81 (h2c) • Try it – it fails • The

    browsers refuse http/2 without ssl (h2c) • Firefox shows garbage result • Chrome downloads a binary file
  17. The h2c client • Jetty supports h2c and can act

    as a client • we can write a small client app • And sniff the data with wireshark
  18. Direct or Upgrade • When no TLS, HTTP/2 is discovered:

    • Upgrade header from client • Server switches to http2 in the same connection (note the h2c)
  19. Direct or Upgrade • Direct (we "know" there is http2)

    • Then we directly do the HTTP/2 Connection Preface • Final confirmation of the protocol in use and to establish the initial settings for the HTTP/2 connection • The purpose of the connection preface is to stop http/1.1 servers from sending data in case of error
  20. A typical request/response • Client: MAGIC (connection preface), SETTINGS •

    Client: HEADERS http1: req.headers • Server: SETTINGS, WINDOW_UPDATE • Client: SETTINGS • Server: HEADERS http1: res.headers • Server: DATA http1: res.body • Server: DATA • Server: DATA • Server: DATA • Client: GOAWAY
  21. Jetty • Jetty • java -jar $JETTY_HOME/start.jar --add-to-startd=http,https,deploy • java

    -jar $JETTY_HOME/start.jar --add-to-startd=http2,http2c • java -jar $JETTY_HOME/start.jar
  22. NSS Keylogging – tell the browser to decrypt • There

    is a way to tell the browser to export the pre secret key • We can use this technique to any site • without the site's private key • without changing anything (no MITM) $ export SSLKEYLOGFILE=$PWD/http2/firefox.sslkeylogfile.txt $ /Applications/Firefox.app/Contents/MacOS/firefox • Then we give this key to wireshark and wireshark can decrypt • Wireshark -> Preferences -> Protocols -> SSL -> (Pre)-Master-Secret log filename • Then we can decode the SSL and then read the HTTP2
  23. Speed – is HTTP/2 faster? • An example of the

    speed difference • https://http2.akamai.com/demo • For us (nginx in front of tomcat) it means • Less connections • No push yet, unfortunately • Faster delivery of resources • If we have time, we'll move to jetty, but that's a change for DEVs • Now they don't know anything about