Loading...

Cette présentation est un site en HTML5

Appuyez sur pour avancer.

Contrôles :

  • et pour vous déplacer.
  • Ctrl/Command et + ou - pour zoomer.
  • T pour changer le thème.
  • H pour changer le surlignage de la syntaxe.

HTTP

Hypertext Transfer Protocol

Grégory Paul - paulgreg.me

valtech_

Sommaire

  1. Vue d’ensemble
  2. La petite histoire...
  3. Versions 0.9, 1.0. 1.1
  4. URI, URL, URN
  5. Verbes
  6. Codes de retour
  7. Cookies
  8. Négociation de contenu
  9. Plage de réponse et réponse partielle
  10. Cache
  11. Authentification
  12. SSL/TLS
  13. Extensions (WebDAV,...)
  14. SPDY et HTTP 2.0
  15. Outils

Vue d’ensemble

Modèle OSI

Couches réseau

Illustration

Diagramme réseau HTTP

HTTP à la main

➜  ~  ping www.google.fr
PING www.google.fr (74.125.230.247) 56(84) bytes of data.
...
^C
➜  ~  telnet 74.125.230.247 80 
Trying 74.125.230.247...
Connected to 74.125.230.247.
Escape character is '^]'.
GET / HTTP/1.1
Host: www.google.fr

HTTP/1.1 200 OK
Date: Fri, 02 Dec 2011 15:03:11 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Content-Length: 4386
Set-Cookie: ... 
Server: gws

<!doctype html><html><head>...

Avec des outils : Live HTTP Headers ou HttpFox

LiveHTTPHeaders

Séquence

Diagramme requête HTTP

La petite histoire...

La petite histoire...

(URI / URL / URN)

URI / URL / URN

URN / URL / URI

Une URI identifie.

Une URL identifie et localise.

une URN identifie et nomme.

URLs :

  • mailto:someone@example.com
  • http://www.damnhandy.com/
  • file:///home/someuser/somefile.txt

URNs :

  • urn:mpeg:mpeg7:schema:2001urn:isbn:0451450523
  • urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C
  • urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66

HTTP 0.9, 1.0 et 1.1

HTTP 0.9

  • n’est pas un standard
  • n’est pas figé, constantes évolutions
  • en cours de développement dans les années 91~95
  • un seul verbe : GET
  • port 80 par défaut
  • introduit le concept d’URI
  • introduit le code de retour (status code)
  • puis l’entête content-type
  • sans état...
  • mais les cookies apparaissent par Lou Montulli en 94 pour une boutique d’ecommerce

HTTP 1.0

  • en 1996, RFC 1945
  • verbe GET, POST, HEAD mais aussi PUT, DELETE, LINK, UNLINK
  • standardisation des entêtes, du formatage des réponses, des codes d’erreurs
  • cache côté client via les en‐têtes Last-modified, Pragma, Expires et la compression

HTTP 1.1

  • En 1997, RFC 2068 : HTTP/1.1
  • OPTIONS, CONNECT et TRACE (LINK, UNLINK)
  • en-tête Host obligatoire (permettant plusieurs sites web depuis une même IP)
  • négociation de contenu et de langage (Accept, Accept-Language, Accept-Charset), un pas en avant vers REST
  • HTTP PipeliningConnection: keep-alive permettant le pipelining
  • découpe de la réponse en plusieurs morceaux via Transfer-Encoding: chunked (un exemple est l’usage "temps réel" tel que les premiers chats)
  • 19 révisions entre 2007 et 2012 et des ajouts divers tels que Content Security Policy

Verbes

Verbes

  • GET : récupération d’une ressource
  • HEAD : seulement les entêtes
  • POST : soumission d’un formulaire / modification d’une ressource
  • PUT : création d’une ressource
  • DELETE : suppression d’une ressource
  • TRACE : echo de la requête
  • OPTIONS : Capacités du serveur
  • CONNECT : SSL/TLS pour les proxies
  • PATCH : modification partielle (RFC 5789, mai 2010)

Code de retour (status code)

Codes de retour

  • 1xx Informational (3)
    • 100 Continue
    • 101 Switching Protocols
    • 102 Processing (WebDAV; RFC 2518)
  • 2xx Success (10)
    • 200 OK
    • 201 Created
    • 202 Accepted
    • 203 Non-Authoritative Information (since HTTP/1.1)
    • 204 No Content
    • 205 Reset Content
    • 206 Partial Content
    • 207 Multi-Status (WebDAV; RFC 4918)
    • 208 Already Reported (WebDAV; RFC 5842)
    • 226 IM Used (RFC 3229)
  • 3xx Redirection (9)
    • 300 Multiple Choices
    • 301 Moved Permanently
    • 302 Found
    • 303 See Other (since HTTP/1.1)
    • 304 Not Modified
    • 305 Use Proxy (since HTTP/1.1)
    • 306 Switch Proxy
    • 307 Temporary Redirect (since HTTP/1.1)
    • 308 Permanent Redirect (approved as experimental)
  • 4xx Client Error (38)
    • 400 Bad Request
    • 401 Unauthorized
    • 402 Payment Required
    • 403 Forbidden
    • 404 Not Found
    • 405 Method Not Allowed
    • 406 Not Acceptable
    • 407 Proxy Authentication Required
    • 408 Request Timeout
    • 409 Conflict
    • 410 Gone
    • 411 Length Required
    • 412 Precondition Failed
    • 413 Request Entity Too Large
    • 414 Request-URI Too Long
    • 415 Unsupported Media Type
    • 416 Requested Range Not Satisfiable
    • 417 Expectation Failed
    • 418 I'm a teapot (RFC 2324)
    • 420 Enhance Your Calm (Twitter)
    • 422 Unprocessable Entity (WebDAV; RFC 4918)
    • 423 Locked (WebDAV; RFC 4918)
    • 424 Failed Dependency (WebDAV; RFC 4918)
    • 424 Method Failure (WebDAV)
    • 425 Unordered Collection (Internet draft)
    • 426 Upgrade Required (RFC 2817)
    • 428 Precondition Required (RFC 6585)
    • 429 Too Many Requests (RFC 6585)
    • 431 Request Header Fields Too Large (RFC 6585)
    • 444 No Response (Nginx)
    • 449 Retry With (Microsoft)
    • 450 Blocked by Windows Parental Controls (Microsoft)
    • 451 Unavailable For Legal Reasons (Internet draft)
    • 494 Request Header Too Large (Nginx)
    • 495 Cert Error (Nginx)
    • 496 No Cert (Nginx)
    • 497 HTTP to HTTPS (Nginx)
    • 499 Client Closed Request (Nginx)
  • 5xx Server Error (14)
    • 500 Internal Server Error
    • 501 Not Implemented
    • 502 Bad Gateway
    • 503 Service Unavailable
    • 504 Gateway Timeout
    • 505 HTTP Version Not Supported
    • 506 Variant Also Negotiates (RFC 2295)
    • 507 Insufficient Storage (WebDAV; RFC 4918)
    • 508 Loop Detected (WebDAV; RFC 5842)
    • 509 Bandwidth Limit Exceeded (Apache bw/limited extension)
    • 510 Not Extended (RFC 2774)
    • 511 Network Authentication Required (RFC 6585)
    • 598 Network read timeout error (Unknown)
    • 599 Network connect timeout error (Unknown)

Négociation de contenu

Négociation de contenu

Navigateur demandant une page web

GET / HTTP/1.1
Host: www.exemple.org
Accept: text/html; q=1.0, text/*; q=0.8, image/gif; q=0.6, image/jpeg; q=0.6, image/*; q=0.5, */*; q=0.1
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding: gzip,deflate
Accept-Language: fr-FR; q=1.0, en; q=0.5
... 
HTTP/1.1 200 OK
Content-Encoding: gzip
Content-Length: 25719
Content-type: text/html; charset=UTF-8
Content-Language: en-US
...

Négociation de contenu

Client d’API REST

GET /shops/all/address HTTP/1.1
Host: www.exemple.org
Accept: application/json; q=1.0, text/xml; q=0.8
Accept-Charset: ISO-8859-1,utf-8; q=0.7, *; q=0.3
Accept-Encoding: gzip,deflate
Accept-Language: fr-FR; q=1.0, en; q=0.5
... 
HTTP/1.1 200 OK
Content-Encoding: gzip
Content-Length: 25719
Content-type: application/json; charset=utf-8
Content-Language: en-US
 ...

Requête et réponse partielle

Requête et réponse partielle

HEAD /2390/2253727548_a413c88ab3_s.jpg HTTP/1.1
Host: farm3.static.flickr.com
HTTP/1.0 200 OK
Date: Mon, 05 May 2008 00:33:14 GMT
Server: Apache/2.0.52 (Red Hat)
Accept-Ranges: bytes
Content-Length: 3980
Content-Type: image/jpeg
GET /2390/2253727548_a413c88ab3_s.jpg HTTP/1.1
Host: farm3.static.flickr.com
Range: bytes=0-999
HTTP/1.0 206 Partial Content
Date: Mon, 05 May 2008 00:36:57 GMT
Server: Apache/2.0.52 (Red Hat)
Accept-Ranges: bytes
Content-Length: 1000
Content-Range: bytes 0-999/3980
Content-Type: image/jpeg
...

Cache

Cache : En Action

Chargement initial, sans cache :

First twitter load

Rechargement de la même page :

Second twitter load

Cache : Introduction

Qui ?

  • Navigateur / Client
  • Proxy (squid, équipement réseau/"network appliance")
  • Reverse-proxy (squid, varnish, etc)
  • CDN (Akamai, Amazon Cloud Front, ...)

2 types :

  • Cache privé
  • Cache public

Définitions :

  • Revalidation
  • Cache hit
  • Cache miss

Cache : Date et Expires

Date:Tue, 04 Sep 2012 09:24:26 GMT
Expires: Thu, 01 Dec 1994 16:00:00 GMT
  • Date obligatoire !
  • Expires > now() : caché jusqu’à la date indiquée puis revalidation
  • Expires == now() : caché mais revalidation à la prochaine requête
  • Expires < now() || Expires == -1 : pas de cache

Cache : Cache-Control

  • Cache-Control: private : Cache client
  • Cache-Control: public : Cache client et proxy
  • Cache-Control: no-cache : Cache client et proxy mais revalidation
  • Cache-Control: no-cache=Set-Cookie : Ne pas cacher cet entête
  • Cache-Control: no-store : Cache client ou proxy interdit
  • Cache-Control: must-revalidate : Revalidation après expiration
  • Cache-Control: proxy-revalidate : Idem mais pour les proxies
  • Cache-Control: max-age=xxx : Temps relatif, en secondes
  • Cache-Control: s-maxage=xxx : Idem mais que pour les proxies
  • Cache-Control: no-transform : Les proxies ne doivent pas transformer la ressource

Cache : Last-Modified et requête conditionnelle

GET /logo.png HTTP/1.1
...
HTTP/1.1 200 OK
Date: Mon, 03 Sep 2012 15:05:20 GMT
Expires: Mon, 03 Sep 2012 15:05:20 GMT
Last-Modified: Mon, 02 Apr 2012 02:13:37 GMT
...
GET /logo.png HTTP/1.1
If-Modified-Since: Mon, 02 Apr 2012 02:13:37 GMT
...
HTTP/1.1 304 Not Modified
Date: Mon, 03 Sep 2012 15:07:07 GMT
Expires: Mon, 03 Sep 2012 15:07:07 GMT
...

Cache : Entity Tag et requête conditionnelle

GET /logo.png HTTP/1.1
...
HTTP/1.1 200 OK
Date: Mon, 03 Sep 2012 15:05:20 GMT
ETag: "8eca4-205f-17b94c"
...
GET /logo.png HTTP/1.1
If-None-Match "8eca4-205f-17b94c"
...
HTTP/1.1 304 Not Modified
Date: Mon, 03 Sep 2012 15:07:07 GMT
ETag: "8eca4-205f-17b94c"
...

Cache : Vary

Exemple sur la compression :

GET /file.js HTTP/1.1
Accept-Encoding: gzip, deflate
...
HTTP/1.1 200 OK
Content-Encoding:gzip
Date:Thu, 06 Sep 2012 13:56:47 GMT
Expires:Thu, 13 Sep 2012 13:56:47 GMT
ETag:M0-0eb75f26
Vary:Accept-Encoding
...

Exemple sur la négociation de contenu :

GET /shops/all/address HTTP/1.1
Host: www.exemple.org
Accept: application/json
Accept-Language: fr-FR; q=1.0, en; q=0.5
... 
HTTP/1.1 200 OK
Content-type: application/json; charset=utf-8
Content-Language: en-US
Vary: Accept,Accept-Language
 ...

Cache : Recommandations

  • Utilisez soit Expires, soit Cache-Control: max-age
  • avec soit Last-Modified, soit ETag pour permettre les requêtes conditionnelles
  • Idéalement, cachez pour un mois ou un an (mais pas plus !) et utiliser l’url fingerprinting
  • SSL/TLS : Cache control: public (sinon, pas de cache sous FF)
  • Attention aux paramètres dans les URL (proxies)
  • Limitez les cookies aux ressources qui ont en besoin (html)
  • Rappel : ressources statiques sur un autre sous-domaine
  • Attention de bien configurer Vary en fonction du Content-Encoding, Content-Type ou encore sur les champs Accept (Négociation de contenu)

Authenfication

Authenfication basique

GET /private/index.html HTTP/1.1
Host: www.exemple.org
...
HTTP/1.1 401 Authorization Required
Content-type: text/html
WWW-Authenticate: Basic realm="Secure Area"
...
GET /private/index.html HTTP/1.1
Host: www.exemple.org
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

Encodage/décodage base 64

> echo -n "Aladdin:open sesame" | base64 - > QWxhZGRpbjpvcGVuIHNlc2FtZQ== > echo -n QWxhZGRpbjpvcGVuIHNlc2FtZQ== | base64 -d > Aladdin:open sesame

Authenfication Digest

HTTP/1.1 401 Authorization Required
Content-type: text/html
WWW-Authenticate: Digest realm="testrealm@host.com",
qop="auth, auth-int",
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
opaque="5ccc069c403ebaf9f0171e9517f40e41"
...
GET /private/index.html HTTP/1.1
Host: www.exemple.org
GET /dir/index.html HTTP/1.0
Host: localhost
Authorization: Digest username="gpaul",
realm="testrealm@host.com",
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
uri="/private/index.html",
qop=auth,
nc=00000001,
cnonce="0a4f113b",
response="6629fae49393a05397450978507c4ef1",
opaque="5ccc069c403ebaf9f0171e9517f40e41"

SSL/TLS

SSL/TLS : Introduction

  • SSL 1.0 (jamais publique), 2.0 en 1995, 3.0 en 1996 (RFC 6101),
  • TLS 1.0 en 1999 (RFC 2246)
  • TLS 1.1 en 2006 (RFC 4346)
  • TLS 1.2 en 2008 (RFC 5246)
  • Mise à jour sur TLS 1.2 en 2011 (RFC 6176)
  • TLS utilisé sur HTTP, FTP, SMTP, NNTP et XMPP
  • HTTPS sur le port 443

5 principes

  • l'authentification du serveur,
  • la confidentialité des données échangées,
  • l'intégrité des données échangées,
  • la spontanéité,
  • de manière optionnelle, l'authentification du client avec un certificat,
  • la transparence (HTTP over TLS).

Quelques rappels cryptographiques

  • Chiffrement symétrique (DES, 3DES, AES, BlowFish,...)
  • Chiffrement asymétrique (RSA)
  • Fonction de hashage (MD5, SHA1, SHA256,...)
  • Signature
  • Certificats (x509)
  • Autorité de certification
  • Chaînes de confiance

Création d’une signature

var hash = sha1(certificat.info)
return encrypt(ca.privatekey, hash)

Vérification d’une signature

var hash = sha1(certificat.info)
var uncryptedSignature = decrypt(ca.publickey, signature)
return hash == uncryptedSignature

SSL/TLS : Handshake

SSL/TLS handshake
  • 1. Client hello : chiffrements supportés ordonnés
  • 2. Server hello : chiffrement utilisé et certificat (le client vérifie le certificat et la chaîne de confiance)
  • 3. Pré-clé chiffrée avec la clé publique du serveur
  • 4. Négociation terminée, calcul de la clé secrête symétrique
  • 5. Échanges HTTP chiffrés avec la clé symétrique

Algorithmes d’encryption

Version, chiffrement asymétrique, chiffrement symétrique, négociation des clés, signature

  • SSL2-RC4-128-with-MD5
  • SSL2-RC2-128-CBC-with-MD5
  • SSL2-DES-168-EDE3-CBC-with-MD5
  • SSL2-DES-56-CBC-with-MD5
  • SSL2-RC4-128-EXPORT40-with-MD5
  • SSL2-RC2-128-CBC-EXPORT40-with-MD5
  • SSL3-FORTEZZA-DMS-with-FORTEZZA-CBC-SHA
  • SSL3-FORTEZZA-DMS-with-RC4-128-SHA
  • SSL3-RSA-with-RC4-128-MD5
  • SSL3-RSA-with-3DES-EDE-CBC-SHA
  • SSL3-RSA-with-DES-CBC-SHA
  • SSL3-RSA-with-RC4-40-MD5
  • SSL3-RSA-with-RC2-CBC-40-MD5
  • SSL3-FORTEZZA-DMS-with-null-SHA
  • SSL3-RSA-with-null-MD5
  • SSL3-RSA-FIPS-with-3DES-EDE--CBC-SHA
  • SSL3-RSA-FIPS-with-DES-CBC-SHA
  • SSL3-DHE-RSA-with-3DES-EDE-CBC-SHA
  • SSL3-DHE-DSS-with-3DES-EDE-CBC-SHA
  • SSL3-DHE-RSA-with-DES-CBC-SHA
  • SSL3-DHE-DSS-with-DES-CBC-SHA
  • TLS-RSA-1024-with-RC4-56-SHA
  • TLS-RSA-1024-with-DES-CBC-SHA
  • TLS-RSA-with-RC4-128-MD5
  • SSL_RSA_WITH_RC4_128_SHA or TLS_RSA_WITH_RC4_128_SHA
  • TLS-RSA-with-3DES-EDE-CBC-SHA
  • TLS-RSA-with-DES-CBC-SHA
  • TLS-RSA-with-AES-256-CBC-SHA
  • TLS-RSA-with-AES-128-CBC-SHA
  • TLS-RSA-with-RC4-40-MD5
  • TLS-RSA-with-RC2-CBC-40-MD5
  • TLS-RSA-with-null-MD5
  • TLS-DHE-RSA-with-AES-256-CBC-SHA
  • TLS-DHE-RSA-with-AES-128-CBC-SHA
  • TLS-DHE-DSS-with-AES-256-CBC-SHA
  • TLS-DHE-DSS-with-AES-128-CBC-SHA
  • TLS-DHE-DSS-with-RC4-128-SHA
  • TLS-ECDH-ECDSA-with-RC4-128-SHA
  • TLS-ECDH-RSA-with-RC4-128-SHA
  • TLS-ECDHE-ECDSA-with-RC4-128-SHA
  • TLS-ECDHE-RSA-with-RC4-128-SHA
  • TLS-ECDH-ECDSA-with-3DES-EDE-CBC-SHA
  • TLS-ECDH-RSA-with-3DES-EDE-CBC-SHA
  • TLS-ECDHE-ECDSA-with-3DES-EDE-CBC-SHA
  • TLS-ECDHE-RSA-with-3DES-EDE-CBC-SHA
  • TLS-ECDH-ECDSA-with-AES-128-CBC-SHA
  • TLS-ECDH-RSA-with-AES-128-CBC-SHA
  • TLS-ECDHE-ECDSA-with-AES-128-CBC-SHA
  • TLS-ECDHE-RSA-with-AES-128-CBC-SHA
  • TLS-ECDH-ECDSA-with-AES-256-CBC-SHA
  • TLS-ECDH-RSA-with-AES-256-CBC-SHA
  • TLS-ECDHE-ECDSA-with-AES-256-CBC-SHA
  • TLS-ECDHE-RSA-with-AES-256-CBC-SHA

SSL/TLS : Diffie-Hellman

SSL/TLS & Perfect Forward Secrecy, DHE-RSA-AES128-SHA, ECDHE-RSA-AES128-SHA

Algorithme de Diffie Hellman

SSL/TLS : Securité

HSTS

Strict-Transport-Security: max-age=16070400; includeSubDomains

Attaques connues

En 2011, Thai Duong et Juliano Rizzo démontrent BEAST, une attaque contre TLS/1.0.

En 2012, ils présentent CRIME, se basant sur la compression : TLS et SPDY sont vulnérables.

Extension

Extension : WebDAV

  • permet de récupérer, déposer, synchroniser et publier des fichiers/dossiers,
  • gestion des droits d’accès, vérrouillage des fichiers,
  • Nouvelles méthodes, entêtes et codes de retour (RFC 4918) :
COPY /~fielding/index.html HTTP/1.1 
Host: www.example.com 
Destination: http://www.example.com/users/f/fielding/index.html 
If: <http://www.example.com/users/f/fielding/index.html> (<urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6>)
HTTP/1.1 204 No Content
DELETE /locked/member HTTP/1.1
Host: example.com
HTTP/1.1 423 Locked
Content-Type: application/xml; charset="utf-8"
Content-Length: xxxx

<?xml version="1.0" encoding="utf-8" ?>
<D:error xmlns:D="DAV:">
<D:lock-token-submitted>
<D:href>/locked/</D:href>
</D:lock-token-submitted>
</D:error>

SPDY / HTTP 2.0

SPDY

  • standard de facto, standardisation en cours (draft-mbelshe-httpbis-spdy-00)
  • implémenté dans Google Chrome (chrome://net-internals/#spdy) et Firefox 11 (annonce), actif par défaut dans Firefox 13 (network.http.spdy.enabled, cf about:config) et Amazon Silk,
  • utilisé sur presque tous les services Google, ainsi que twitter,
  • Speedy stack ne remplace pas HTTP mais change la façon dont les données sont envoyées,
  • suppression des entêtes redondants (user-agent, accept, etc),
  • compression des entêtes,
  • multiplexage (plusieurs streams) au sein d’une requête TCP,
  • HTTP Pipelining,
  • priorise les ressources,
  • "push" des resources liées (images, css, js) avant que le navigateur ne les demande,
  • TLS/SSL obligatoire.

HTTP 2.0

  • en cours de réflexion par le groupe Hypertext Transfer Protocol Bis (httpbis),
  • buts : multiplexage, compression des entête, pipelining,
  • rétro-compatibilité complète,
  • SPDY candidat pour HTTP/2.0,
  • Microsoft propose HTTP Speed+Mobility (basé sur SPDY).

Outils et resources