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

Cache + TLS

Thierry
September 17, 2013

Cache + TLS

Sujet présenté lors du sfPot parisien du 17 septembre 2013 à la Pépinière 27

Thierry

September 17, 2013
Tweet

More Decks by Thierry

Other Decks in Programming

Transcript

  1. Objectifs à atteindre 1. Mettre en cache du contenu dont

    la génération est coûteuse 2. Protéger les utilisateurs ayant accès aux ressources cachées Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 2
  2. Pourquoi une mise en cache des contenus ? • HTTP

    1.1 et son « Accélération » [RFC 2616] • Plus grande capacité d'accueil des visites • Meilleure tolérance aux pannes (relative) • Réponses retournées plus rapidement Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 3
  3. Pourquoi sécurise-t-on le trafic ? • Écoutes sur le réseau

    (MITM) • Usurpation d'identité • Altération des données échangées Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 4
  4. Comment se prémunir des risques ? • Par le chiffrement

    des communications • => Confidentialité des échanges • => Authentification des interlocuteurs • => Intégrité des données échangées Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 6
  5. Protocoles sécurisant HTTP • SSL v1.0, SSL v2.0, SSL v3.0

    • TLS v1.0 [RFC 2246] • TLS v1.1 [RFC 4346] • TLS v1.2 [RFC 5246] Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 7
  6. Performances avec SSL ? In January this year (2010), Gmail

    switched to using HTTPS for everything by default. [...] In order to do this we had to deploy no additional machines and no special hardware. [...] SSL/TLS is not computationally expensive any more. Adam Langley “ Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 8
  7. • Client • valeur pseudo-aléatoire • id de session •

    liste de chiffrements • Serveur • valeur pseudo-aléatoire • id de session • certificat • liste de chiffrements Handshaking Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 9
  8. Chiffrement par bloc (CBC) • Découpage des données • Chiffrement

    des blocs • Exemple: AES, Blowfish Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 10
  9. Chiffrement par flot • Un générateur de nombres pseudo-aléatoires •

    XOR entre bit de la sortie du génerateur et un bit de la donnée • Aucune contrainte sur la longueur des données • Exemple: • RC4 • Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 11
  10. Vulnérabilités 1/4 • CRIME (Compression Ratio Info-leak Made Easy) •

    Détournement de session • Désactiver la compression SSL/TLS Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 12
  11. Vulnérabilités 2/4 • BEAST (Browser Exploit Against SSL/TLS) • Récupération

    du cookie de session • Utiliser RC4 comme chiffrement avec SSL v3.0 et TLS v1.0 • Is BEAST Still a Threat? Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 13
  12. Vulnérabilités 3/4 • BREACH (Browser Reconnaissance & Exfiltration via Adaptive

    Compression of Hypertext) • Prolongement de l'attaque CRIME • Désactiver la compression HTTP pour diminuer les risques (solution la plus drastique) Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 14
  13. Vulnérabilités 4/4 • StripSSL / CSRF / XSS • =>

    HSTS (HTTP Strict Transport Security) Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 15
  14. Vulnérabilités 4/4 # N g i n x a d

    d _ h e a d e r S t r i c t - T r a n s p o r t - S e c u r i t y m a x - a g e = 6 3 0 7 2 0 0 0 ; # L i g h t t p d s e r v e r . m o d u l e s + = ( " m o d _ s e t e n v " ) $ H T T P [ " s c h e m e " ] = = " h t t p s " { s e t e n v . a d d - r e s p o n s e - h e a d e r = ( " S t r i c t - T r a n s p o r t - S e c u r i t y " = > " m a x - a g e = 6 3 0 7 2 0 0 0 " ) } # A p a c h e # O p t i o n a l l y l o a d t h e h e a d e r s m o d u l e : L o a d M o d u l e h e a d e r s _ m o d u l e m o d u l e s / m o d _ h e a d e r s . s o H e a d e r a l w a y s s e t S t r i c t - T r a n s p o r t - S e c u r i t y " m a x - a g e = 6 3 0 7 2 0 0 0 ; i n c l u d e S u b D o m a i n s " 0 1 . 0 2 . 0 3 . 0 4 . 0 5 . 0 6 . 0 7 . 0 8 . 0 9 . 1 0 . 1 1 . 1 2 . 1 3 . 1 4 . 1 5 . Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 16
  15. Gnothi seauton (Know Thyself) 1. SSL Server Test (by SSL

    Labs) 2. Extension navigateur proposée par Netcraft Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 17
  16. Preuve de concept 1. Backend - Apache (2.2.22) + PHP

    (5.5) + Symfony (2.3) 2. Reverse proxy cache - Varnish (3.0.2) 3. SSL proxy - Nginx (1.4.2) 4. Nginx <--> Varnish <--> Apache Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 18
  17. Backend Server (Apache) 1/3 < V i r t u

    a l H o s t 1 2 7 . 0 . 0 . 1 : 8 0 > S e r v e r A d m i n h o s t @ e d - b y . m e S e r v e r N a m e 1 2 7 . 0 . 0 . 1 D o c u m e n t R o o t / v a r / w w w / s y m f o n y < D i r e c t o r y / > A l l o w O v e r r i d e N o n e < / D i r e c t o r y > E r r o r L o g $ { A P A C H E _ L O G _ D I R } / e r r o r . s y m f o n y 2 . l o g C u s t o m L o g $ { A P A C H E _ L O G _ D I R } / a c c e s s . s y m f o n y 2 . l o g c o m b i n e d # P r é p a r e r v o u s a u p i r e e t à c r e u s e r # P o s s i b l e v a l u e s i n c l u d e : d e b u g , i n f o , n o t i c e , w a r n , e r r o r , c r i t , # a l e r t , e m e r g . # h t t p d 2 . 4 . 6 # L o g L e v e l d e b u g # L o g l e v e l a l e r t r e w r i t e : t r a c e 8 # h t t p d 2 . 2 # R e w r i t e L o g " / u s r / l o c a l / v a r / a p a c h e / l o g s / r e w r i t e . l o g " # R e w r i t e L o g L e v e l 9 < / V i r t u a l H o s t > 0 1 . 0 2 . 0 3 . 0 4 . 0 5 . 0 6 . 0 7 . 0 8 . 0 9 . 1 0 . 1 1 . 1 2 . 1 3 . 1 4 . 1 5 . 1 6 . 1 7 . 1 8 . 1 9 . 2 0 . Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 19
  18. Backend Server (Apache) 2/3 < D i r e c

    t o r y / v a r / w w w / s y m f o n y 2 > A d d C h a r s e t u t f - 8 . * O r d e r a l l o w , d e n y # [ 2 ] A l l o w a c c e s s f r o m l o c a l h o s t o n l y A l l o w f r o m 1 2 7 . 0 . 0 . 1 < I f M o d u l e m o d _ r e w r i t e . c > R e w r i t e E n g i n e o n R e w r i t e C o n d % { R E Q U E S T _ U R I } : : $ 1 ^ ( / . + ) / ( . * ) : : \ 2 $ R e w r i t e R u l e ^ ( . * ) - [ E = B A S E : % 1 ] R e w r i t e C o n d % { E N V : R E D I R E C T _ S T A T U S } ^ $ R e w r i t e R u l e ^ a p p \ . p h p ( / ( . * ) | $ ) % { E N V : B A S E } / $ 2 [ R = 3 0 1 , L ] R e w r i t e C o n d % { R E Q U E S T _ F I L E N A M E } - f R e w r i t e R u l e . ? - [ L ] R e w r i t e R u l e . ? % { E N V : B A S E } / a p p . p h p [ L ] < / I f M o d u l e > < / D i r e c t o r y > 0 1 . 0 2 . 0 3 . 0 4 . 0 5 . 0 6 . 0 7 . 0 8 . 0 9 . 1 0 . 1 1 . 1 2 . 1 3 . 1 4 . 1 5 . 1 6 . 1 7 . Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 20
  19. Backend Server (Apache) 3/3 # [ 1 ] R e

    d i r e c t s t o s e c u r e d - f r o n t - s e r v e r . n e t : 4 4 3 # N g i n x e t A p a c h e n e p e u v e n t p a s é c o u t e r s u r l e m ê m e p o r t < V i r t u a l H o s t * : 8 0 > S e r v e r A d m i n h o s t @ e d - b y . m e S e r v e r N a m e s s l - t e r m i n a t i o n . n e t < I f M o d u l e m o d _ r e w r i t e . c > R e w r i t e E n g i n e o n R e w r i t e R u l e ^ / ( . * ) h t t p s : / / % { S E R V E R _ N A M E } / $ 1 [ L ] < / I f M o d u l e > < / V i r t u a l H o s t > 0 1 . 0 2 . 0 3 . 0 4 . 0 5 . 0 6 . 0 7 . 0 8 . 0 9 . 1 0 . 1 1 . Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 21
  20. Entêtes proxy SSL 1/2 • Trusting Proxies (doc Symfony2) <

    ? p h p / / / w e b / a p p . p h p / / [ . . . ] R e q u e s t : : s e t T r u s t e d P r o x i e s ( a r r a y ( ' 1 2 7 . 0 . 0 . 1 ' ) ) ; / / [ . . . ] $ r e q u e s t - > s e t T r u s t e d H e a d e r N a m e ( R e q u e s t : : H E A D E R _ C L I E N T _ P R O T O , ' X - P r o x y - P r o t o ' ) ; $ r e q u e s t - > s e t T r u s t e d H e a d e r N a m e ( R e q u e s t : : H E A D E R _ C L I E N T _ I P , ' X - P r o x y - F o r ' ) ; $ r e q u e s t - > s e t T r u s t e d H e a d e r N a m e ( R e q u e s t : : H E A D E R _ C L I E N T _ H O S T , ' X - P r o x y - H o s t ' ) ; 0 1 . 0 2 . 0 3 . 0 4 . 0 5 . 0 6 . 0 7 . 0 8 . 0 9 . 1 0 . 1 1 . Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 22
  21. Entêtes proxy SSL 2/2 l o c a t i

    o n / { a d d _ h e a d e r F r o n t - E n d - H t t p s o n ; p r o x y _ p a s s h t t p : / / 1 2 7 . 0 . 0 . 1 : 8 0 8 0 ; p r o x y _ n e x t _ u p s t r e a m e r r o r t i m e o u t i n v a l i d _ h e a d e r h t t p _ 5 0 0 h t t p _ 5 0 2 h t t p _ 5 0 3 h t t p _ 5 0 4 ; p r o x y _ s e t _ h e a d e r A c c e p t - E n c o d i n g " " ; p r o x y _ s e t _ h e a d e r H o s t $ h o s t ; p r o x y _ s e t _ h e a d e r X - R e a l - I P $ r e m o t e _ a d d r ; p r o x y _ s e t _ h e a d e r X - F o r w a r d e d - F o r $ p r o x y _ a d d _ x _ f o r w a r d e d _ f o r ; p r o x y _ s e t _ h e a d e r X - F o r w a r d e d - H o s t $ h o s t ; p r o x y _ s e t _ h e a d e r X - F o r w a r d e d - P r o t o $ s c h e m e ; p r o x y _ h i d e _ h e a d e r X - V a r n i s h ; p r o x y _ h i d e _ h e a d e r X - P o w e r e d - B y ; p r o x y _ h i d e _ h e a d e r V i a ; p r o x y _ r e d i r e c t o f f ; } 0 1 . 0 2 . 0 3 . 0 4 . 0 5 . 0 6 . 0 7 . 0 8 . 0 9 . 1 0 . 1 1 . 1 2 . 1 3 . 1 4 . 1 5 . 1 6 . 1 7 . 1 8 . 1 9 . 2 0 . Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 23
  22. Forcer HTTPS avec Symfony2 # s e c u r

    i t y . y m l # h t t p : / / s y m f o n y . c o m / d o c / c u r r e n t / c o o k b o o k / s e c u r i t y / f o r c e _ h t t p s . h t m l a c c e s s _ c o n t r o l : - p a t h : ^ / l o g i n r o l e s : I S _ A U T H E N T I C A T E D _ A N O N Y M O U S L Y r e q u i r e s _ c h a n n e l : h t t p s # r o u t i n g . y m l # h t t p : / / s y m f o n y . c o m / d o c / c u r r e n t / b o o k / r o u t i n g . h t m l s e c u r e : p a t t e r n : / s e c u r e d e f a u l t s : { _ c o n t r o l l e r : A c m e D e m o B u n d l e : M a i n : s e c u r e } r e q u i r e m e n t s : _ s c h e m e : h t t p s 0 1 . 0 2 . 0 3 . 0 4 . 0 5 . 0 6 . 0 7 . 0 8 . 0 9 . 1 0 . 1 1 . 1 2 . 1 3 . 1 4 . Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 24
  23. Forcer HTTPS avec Symfony2 ou pas • Risques de boucles

    de redirection sous certaines conditions • Varnish est seul à communiquer avec le backend sur 127.0.0.1:80 Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 25
  24. SSL Proxy (Nginx) s e r v e r {

    l i s t e n 4 4 3 ; s s l o n ; s e r v e r _ n a m e s s l - t e r m i n a t i o n . n e t ; # [ . . . ] s s l _ c e r t i f i c a t e / e t c / s s l / p r i v a t e / s i g n e d - c e r t i f i c a t e . c r t ; s s l _ c e r t i f i c a t e _ k e y / e t c / s s l / p r i v a t e / p r i v a t e . k e y ; # r é d u c t i o n d e s v e r s i o n s d e S S L / T L S p r o p o s é e s p a r l e s e r v e u r s s l _ p r o t o c o l s T L S v 1 T L S v 1 . 1 T L S v 1 . 2 ; # r é d u c t i o n d e l a l i s t e a l g o r i t h m e s d e c h i f f r e m e n t s p r o p o s é s p a r l e s e r v e u r s s l _ c i p h e r s A L L : ! E X P : ! L O W : ! D S S : ! 3 D E S : ! P S K : ! a N U L L : ! e N U L L : ! R C 4 : H I G H : ! a N U L L : ! M D 5 ; s s l _ p r e f e r _ s e r v e r _ c i p h e r s o n ; s s l _ d h p a r a m / e t c / s s l / p r i v a t e / d h 4 0 9 6 . p e m ; k e e p a l i v e _ t i m e o u t 6 0 ; s s l _ s e s s i o n _ c a c h e s h a r e d : S S L : 1 0 m ; s s l _ s e s s i o n _ t i m e o u t 1 0 m ; a d d _ h e a d e r S t r i c t - T r a n s p o r t - S e c u r i t y m a x - a g e = 6 3 0 7 2 0 0 0 ; # [ . . . ] } 0 1 . 0 2 . 0 3 . 0 4 . 0 5 . 0 6 . 0 7 . 0 8 . 0 9 . 1 0 . 1 1 . 1 2 . 1 3 . 1 4 . 1 5 . 1 6 . 1 7 . 1 8 . 1 9 . 2 0 . Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 26
  25. Compression déléguée au proxy SSL s e r v e

    r { / / [ . . . ] g z i p o n ; g z i p _ d i s a b l e " m s i e 6 " ; # P l e a s e , l e t i t r e s t i n p e a c e g z i p _ m i n _ l e n g t h 2 0 ; g z i p _ v a r y o n ; g z i p _ p r o x i e d a n y ; g z i p _ c o m p _ l e v e l 6 ; g z i p _ b u f f e r s 1 6 8 k ; g z i p _ h t t p _ v e r s i o n 1 . 1 ; g z i p _ t y p e s t e x t / p l a i n t e x t / c s s a p p l i c a t i o n / j s o n a p p l i c a t i o n / j a v a s c r i p t a p p l i c a t i o n / x - j a v a s c r i p t \ t e x t / x m l a p p l i c a t i o n / x m l a p p l i c a t i o n / x m l + r s s t e x t / j a v a s c r i p t ; / / [ . . . ] } 0 1 . 0 2 . 0 3 . 0 4 . 0 5 . 0 6 . 0 7 . 0 8 . 0 9 . 1 0 . 1 1 . 1 2 . 1 3 . 1 4 . Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 27
  26. Compression déléguée au Backend # S e e a l

    s o h t t p : / / s y m f o n y . c o m / d o c / c u r r e n t / c o o k b o o k / c a c h e / v a r n i s h . h t m l s u b v c l _ r e c v { i f ( r e q . h t t p . A c c e p t - E n c o d i n g ) { i f ( r e q . u r l ~ " \ . ( j p g | p n g | g i f | g z | t g z | b z 2 | t b z | m p 3 | o g g ) $ " ) { # N o p o i n t i n c o m p r e s s i n g t h e s e r e m o v e r e q . h t t p . A c c e p t - E n c o d i n g ; } e l s i f ( r e q . h t t p . A c c e p t - E n c o d i n g ~ " g z i p " ) { s e t r e q . h t t p . A c c e p t - E n c o d i n g = " g z i p " ; } e l s i f ( r e q . h t t p . A c c e p t - E n c o d i n g ~ " d e f l a t e " & & r e q . h t t p . u s e r - a g e n t ! ~ " M S I E " ) { s e t r e q . h t t p . A c c e p t - E n c o d i n g = " d e f l a t e " ; } e l s e { # u n k o w n a l g o r i t h m r e m o v e r e q . h t t p . A c c e p t - E n c o d i n g ; } } # [ . . . ] } 0 1 . 0 3 . 0 4 . 0 5 . 0 6 . 0 7 . 0 8 . 0 9 . 1 0 . 1 1 . 1 2 . 1 3 . 1 4 . 1 5 . 1 6 . 1 7 . 1 8 . 1 9 . 2 0 . Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 28
  27. ...ou au Reverse-Cache Proxy s u b v c l

    _ f e t c h { i f ( r e q . u r l ~ " \ . ( c s s | j s | m i n | ) $ " ) { s e t b e r e s p . d o _ g z i p = t r u e ; } # E S I i f ( b e r e s p . h t t p . S u r r o g a t e - C o n t r o l ~ " E S I / 1 . 0 " ) { u n s e t b e r e s p . h t t p . S u r r o g a t e - C o n t r o l ; s e t b e r e s p . d o _ e s i = t r u e ; } } 0 1 . 0 2 . 0 3 . 0 4 . 0 5 . 0 6 . 0 7 . 0 8 . 0 9 . 1 0 . 1 1 . Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 29
  28. Conclusion 1/2 • Le monde (de la sécurité) n'est pas

    figé • ImperialViolet • GRC (Gibson Research Corporation) • TechSNAP • « Il était une fois SSL/TLS » par Benjamin Sonntag (co-fondateur de La Quadrature du Net) à la Cantine le 20 Septembre 2013 Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 30
  29. Conclusion 2/2 • Rien ne vaut l'expérimentation ! • Extensions

    PHP • CryptoJS • PyCrypto Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 31
  30. Une journée ne compte que 24h (approximativement)... • Benchmarks (JMeter)

    • Autres solutions de mise en cache nginx HttpProxyModule • Autres solutions de chiffrement SSL/TLS stunnel Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 32
  31. Merci pour votre attention ! • Et merci à •

    L'AFSY • Yoopies • Theodo • @paulgreg & @michaelc Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 33
  32. Sources • https://www.trustworthyinternet.org/ssl-pulse/ • https://www.grc.com • http://www.codinghorror.com/blog/2012/02/should-all-web-traffic-be-encrypted.html • http://www.theregister.co.uk/2011/09/19/beast_exploits_paypal_ssl/ •

    http://www.moserware.com/2009/06/first-few-milliseconds-of-https.html • http://vincent.bernat.im/en/blog/2011-ssl-benchmark.html • http://breachattack.com/ • http://news.netcraft.com/archives/2013/06/25/ssl-intercepted-today-decrypted-tomorrow.html • https://raymii.org/s/tutorials/HTTP_Strict_Transport_Security_for_Apache_NGINX_and_Lighttpd.html • https://github.com/nealharris/BREACH • http://xkcd.com/221/ • http://www.wired.com/threatlevel/2012/03/ff_nsadatacenter/all/ • http://en.wikipedia.org/wiki/Certificate_authority • http://en.wikipedia.org/wiki/Secure_Sockets_Layer • http://en.wikipedia.org/wiki/Message_authentication_code • http://en.wikipedia.org/wiki/Stream_cipher • http://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security • https://speakerdeck.com/yassl/tls • http://takingnote.blogs.nytimes.com/2013/07/18/yes-we-can-to-yes-we-scan/ Creative Commons Attribution-ShareAlike 3.0 Unported License (@thierrymarianne | thierrym@theodo[point]fr) 35