2013年6月9日 星期日

High Performance Browser Networking ch4 Transport Layer Security (TLS) 筆記

原文: http://chimera.labs.oreilly.com/books/1230000000545/ch04.html

  • TLS 1.0 相當於 SSL 3.0, 兩者沒有顯著的差異。由於 SSL 屬於 Netscape 的協定, IETF 另定了 TLS。現在我們用的 "SSL" 其實是指 TLS
  • TLS 屬於 session layer 的協定, 在 application (例如 HTTP) 之下, transport (例如 TCP) 之上
  • TLS 三個要點:
    • Encryption: 加密資料, 其他人無法竊聽
    • Authentication: 認證對方身份, 傳錯人的話, 加密也沒用了
    • Integrity: 確保資料沒有被修改。中間人無法得知資料內容, 但有可能竄改內容。多了 checksum 可以避免使用被改過的資料
  • TLS handshake: 連 TCP handshake 在內要三次 round trip time (RTT)。若一次 RTT 要個 170ms, 這表示 0.5s 後才會開始傳第一筆資料。
  • TLS 多加的兩個 RTT 是:
    • -> ClientHello
    • <- ServerHello, Certificate, ServerHelloDone
    • -> ClientKeyExChange, ChangeCipherSpec, Finished
    • <- ChangeCipherSpec, Finished
  • TLS 的主要缺點是較高的 latency, CPU、記憶體和傳輸資料量到是沒差 (後述)。
  • TLS 主要的計算量在用 public/private key 加解密 symmetric key。整體的 CPU、記憶體和網路負擔都很小。
    • 依 2010 Google 使用 Gmail 的發言:
      "... we had to deploy no additional machines and no special hardware. 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. "
    • Facebook 也有類似的發言:
      "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. We serve all of our HTTPS traffic using software running on commodity hardware."
  • 若 server 想在同一個 IP 上使用多個不同 domain name 的 TLS certificate, client 可透過 server name indication (SNI), 指定要取得那份 certificate
  • TLS 有機會減少最後一個 RTT, 其中一個方法是使用 Session Ticket:
    • server 在 handshake 最後一步時, 用額外的 secret key 加密 symmetric key 回傳給 client。
    • client 存下加密後的 symmetric key
    • 下次要建立連線時, 在 ClientHello 裡帶上加密後的 symmetric key, 由於只有 server 知道解密的 secret key, 可保證由同一個 server 取回 symmetric key
    • 這個作法的好處是: server 不用 cache 大量 session ticket, 不過要在多台 server 上部署同一個 secret key。還有免不了的維護 secret key 的生命週期, 定期換 secret key 增加安全性。
  • 傳 certificate 給 client 時, server 最好傳給 client 所有需要的 intermediate certificate, 避免 client 額外花時間去取得它們。另外沒有必要傳 root certificate, client 一定要有 root certificate, 沒有的話也不會相信剩下的 intermediate certificate 了。
  • 若 TLS record size > TCP packet size, 會造成一筆 TLS record 拆成多個 TCP packets 傳, 導致 client 要收完全部 TCP packets 才能解開這筆 TLC record。最好設定 TLC record size <= TCP packet size
  • 不要開啟 TLS compression。
  • 文末有提到用 Qualys SSL Server Test 和 command line 的 openssl 測試是否有設好 TLS。

沒有留言:

張貼留言

在 Fedora 下裝 id-utils

Fedora 似乎因為執行檔撞名,而沒有提供 id-utils 的套件 ,但這是使用 gj 的必要套件,只好自己編。從官網抓好 tarball ,解開來編譯 (./configure && make)就是了。 但編譯後會遇到錯誤: ./stdio.h:10...