TLS協議分析 (九) 現代加密通信協議設計

六.? TLS協議給我們的啟發 — 現代加密通信協議設計

在看了這么多的分析和案例之后,我們已經可以歸納出加密通信協議設計的普遍問題,和常見設計決策,

設計決策點:

四類基礎算法 加密/MAC/簽名/密鑰交換 如何選擇?對稱加密目前毫無疑問應該直接用aead,最佳選擇就是 aes-128-gcm/aes-256-gcm/chacha20-poly1305了數字簽名/驗證方案,如果是移動互聯網,應該考慮直接放棄 RSA,考慮 P-256 的 ECDSA 公鑰證書,或者更進一步的 ed25519 公鑰證書。密鑰交換算法,目前最佳選擇就是 curve25519,或者 P-256。

對稱加密算法+認證算法,如何選擇?或者直接用aead?

簽名算法如何選擇?RSA or ECDSA or Ed25519?

考慮將來的算法調整,要加版本號機制嗎?建議是加上,起碼在密鑰協商的步驟,要加上版本號。便于將來更新算法。

RSA用作密鑰交換是一個好的選擇嗎?考慮PFS建議直接放棄RSA,RSA服務器端性能比ECDSA更差,簽名更大費流量,而且沒有前向安全性,給私鑰保管帶來更大風險。

自建PKI,是個好的選擇嗎?crl如何解決?自建PKI可以做到更安全,比如簡單的客戶端內置數字簽名公鑰??墒钱斝枰o急吊銷一個證書的時候,只能通過緊急發布新版客戶端來解決。

必須用糟糕的openssl嗎?or something better?crypto++,botan, nacl/libsodium, polarssl?libsodium: ed25519+curve2519+chacha20+poly1305

重放攻擊如何解決?某種seq?或者nonce如何生成?

握手過程被中間人篡改的問題怎么解決?

性能:私鑰運算的cpu消耗可以承受嗎?加上某種cache?要解決私鑰運算的高cpu消耗,必然就需要 session ticket/session id 這種cache機制。顯然session ticket 更好

延遲:密鑰協商需要幾個rtt?最少多少?加上cache后?和tcp對比如何

TLS的性能(主要指服務器cpu消耗)還有空間可以壓榨嗎?我能設計一個性能更牛逼的嗎?

七. 附錄:密碼學基礎概念

本文已經很長了,基礎概念的內容更多,再展開介紹就太長了,下面就列一下點,貼一下參考資料,就先這樣,以后再說吧。

當然,最好的資料是下面列的書。

1. 塊加密算法 block cipher

AES 等

《AES后分組密碼的研究現狀 及發展趨勢》http://www.ccf.org.cn/resources/1190201776262/2010/04/15/019026.pdf

aead的介紹(作者是大神)https://www.imperialviolet.org/2015/05/16/aeads.html

3種組合方式之爭http://www.thoughtcrime.org/blog/the-cryptographic-doom-principle/

CBC模式+MAC-then-encrypt的padding oracle 攻擊, tls POODLE 漏洞http://drops.wooyun.org/papers/3194https://defuse.ca/blog/recovering-cbc-mode-iv-chosen-ciphertext.html

128 bit 和 256 bit key size之爭https://www.schneier.com/blog/archives/2009/07/another_new_aes.html

nist 對 aes gcm 的技術標準,官方權威文檔:http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-spec.pdf

一個gcm的調用范例https://github.com/facebook/conceal/blob/master/native/crypto/gcm_util.c

DES1天之內破解DES(2008年)http://www.sciengines.com/company/news-a-events/74-des-in-1-day.html

iPhone 5S開始,A7芯片也有了aes硬件指令 (ARMv8 指令集),有825%的性能提升:http://www.anandtech.com/show/7335/the-iphone-5s-review/4

2. 流加密算法 stream cipher

RC4,ChaCha20 等

序列密碼發展現狀http://www.ccf.org.cn/resources/1190201776262/2010/04/15/019018.pdf

rc4 : http://www.rc4nomore.com/

[RC4加密已不再安全,破解效率極高(含視頻)]? http://www.freebuf.com/news/72622.html

3. Hash函數 hash funtion

MD5,sha1,sha256,sha512 , ripemd 160,poly1305 等

MD5被碰撞:http://natmchugh.blogspot.com/2014/10/how-i-created-two-images-with-same-md5.html

http://blog.avira.com/md5-the-broken-algorithm/

4. 消息驗證碼函數 message authentication code

HMAC-sha256,AEAD 等

為什么要用MAChttp://www.happybearsoftware.com/you-are-dangerously-bad-at-cryptography.html

Flickr的漏洞案例:http://netifera.com/research/flickr_api_signature_forgery.pdf

http://www.ietf.org/rfc/rfc2104.txt

5. 密鑰交換 key exchange

DH,ECDH,RSA,PFS方式的(DHE,ECDHE)等

https://blog.cloudflare.com/a-relatively-easy-to-understand-primer-on-elliptic-curve-cryptography/

關于 前向安全性( Perfect Forward Secrecy )http://vincent.bernat.im/en/blog/2011-ssl-perfect-forward-secrecy.html

http://www.cryptopp.com/wiki/Elliptic_Curve_Cryptography

google對openssl里面的橢圓曲線的優化:http://static.googleusercontent.com/media/research.google.com/en//pubs/archive/37376.pdf

http://www.math.brown.edu/~jhs/Presentations/WyomingEllipticCurve.pdf

ripple從nistp256k1曲線遷移到ed25519https://ripple.com/uncategorized/curves-with-a-twist/

openssh 6.5 開始支持 ed25519, curve25519, chacha20-poly1305http://www.openssh.org/txt/release-6.5

6. 公鑰加密 public-key encryption

RSA,rabin-williams 等

RSA入門必讀(斯坦福,普渡的課件):http://crypto.stanford.edu/~dabo/courses/cs255_winter07/rsa.ppthttps://engineering.purdue.edu/kak/compsec/NewLectures/Lecture12.pdf

PKCS1 標準,應用RSA必讀:https://www.ietf.org/rfc/rfc3447

RSA 的公鑰為什么比AES的key長?http://crypto.stackexchange.com/questions/8687/security-strength-of-rsa-in-relation-with-the-modulus-size

http://cryptofails.blogspot.ca/2013/07/saltstack-rsa-e-d-1.html

使用什么padding? OAEP,為什么不要用PKCS V1.5

http://stackoverflow.com/questions/2991603/pkcs1-v2-0-encryption-is-usually-called-oaep-encryption-where-can-i-confirm-i

http://crypto.stackexchange.com/questions/12688/can-you-explain-bleichenbachers-cca-attack-on-pkcs1-v1-5http://en.wikipedia.org/wiki/Adaptive_chosen-ciphertext_attack

PKCS #1 — #15標準協議官方網站:http://www.emc.com/emc-plus/rsa-labs/standards-initiatives/public-key-cryptography-standards.htmhttp://arxiv.org/pdf/1207.5446v1.pdf

blinding 一種實現上的技術,用來解決 timing 側通道攻擊的問題https://en.wikipedia.org/wiki/Blinding_(cryptography)http://crypto.stanford.edu/~dabo/papers/ssl-timing.pdf

Twenty Years of Attacks on the RSA Cryptosystem:http://crypto.stanford.edu/~dabo/papers/RSA-survey.pdf

電子信封(digital envelope)http://www.emc.com/emc-plus/rsa-labs/standards-initiatives/what-is-a-digital-envelope.htm

在openssl的evp接口中有直接支持:https://wiki.openssl.org/index.php/EVP_Asymmetric_Encryption_and_Decryption_of_an_Envelope

7. 數字簽名算法 signature algorithm

RSA,DSA,ECDSA (secp256r1 , ed25519) 等

三大公鑰體制:RSA,DSA,ECDSARSA目前是主流,占據絕大多數市場份額DSA已經被廢棄ECDSA是未來的趨勢,例如bitcoin就用ECDSAhttps://blog.cloudflare.com/ecdsa-the-digital-signature-algorithm-of-a-better-internet/https://blog.cloudflare.com/a-relatively-easy-to-understand-primer-on-elliptic-curve-cryptography/

8. 密碼衍生函數 key derivation function

TLS-12-PRF(SHA-256) , bcrypto,scrypto,pbkdf2 等

hkdf:? ? http://tools.ietf.org/html/rfc5869https://cryptography.io/en/latest/hazmat/primitives/key-derivation-functions/

9. 隨機數生成器 random number generators

/dev/urandom 等

[現代密碼學實踐指南[2015年]]? https://blog.helong.info/blog/2015/06/05/modern-crypto/

八. 參考文獻:

TLS/SSL 相關RFC及標準

[TLS 1.2] 鏈接 https://tools.ietf.org/html/rfc5246

[TLS 1.3 draft specification] 鏈接 https://github.com/tlswg/tls13-spec

[AES GCM for TLS] 鏈接 https://tools.ietf.org/html/rfc5288

[ECC cipher suites for TLS] 鏈接 https://tools.ietf.org/html/rfc4492

[TLS extensions] 鏈接 https://tools.ietf.org/html/rfc6066

[Application-Layer Protocol Negotiation Extension] 鏈接 https://tools.ietf.org/html/rfc7301

[X.509 PKI] 鏈接 https://tools.ietf.org/html/rfc4210

[X.509 PKI and CRLs] 鏈接 https://tools.ietf.org/html/rfc5280

[美國國家標準局NIST 的密碼學標準] 鏈接 http://csrc.nist.gov/groups/ST/toolkit/index.html

[NIST SP 800-90A ] 鏈接 http://csrc.nist.gov/publications/nistpubs/800-90A/SP800-90A.pdf

[nsa 的 SuiteB 密碼學標準] 鏈接 https://www.nsa.gov/ia/programs/suiteb_cryptography/

[TLS on wikipedia] 鏈接 https://en.wikipedia.org/wiki/Transport_Layer_Security

協議分析文章

http://www.root.org/talks/TLS_Design20071129_2.pdf

[20 Years of SSL/TLS Research An Analysis of the Internet’s Security Foundation] 鏈接 http://www-brs.ub.ruhr-uni-bochum.de/netahtml/HSS/Diss/MeyerChristopher/diss.pdf

https://www.slideshare.net/yassl/securing-data-in-transit

http://security.stackexchange.com/questions/20803/how-does-ssl-tls-work

[SSL/TLS in Detail] 鏈接 https://technet.microsoft.com/en-us/library/cc785811(v=ws.10).aspx

[SSL/TLS] 鏈接 http://www.spiegel.de/media/media-35511.pdf

[The Sorry State Of SSL] 鏈接 https://hynek.me/talks/tls/

[What’s the matter with TLS?] 鏈接 http://hyperelliptic.org/internetcrypto/OpenSSLPresentation.pdf

http://blog.csdn.net/CaesarZou/article/details/9331993

)

[X.509 PKI and CRLs] 鏈接 https://tools.ietf.org/html/rfc5280

[Layman’s Guide to ASN.1] 鏈接 http://luca.ntop.org/Teaching/Appunti/asn1.html

實際部署調優相關

https://bit.ly/gottls

https://istlsfastyet.com/

https://www.imperialviolet.org/

https://letsencrypt.org/

http://chimera.labs.oreilly.com/books/1230000000545/ch04.to/crypto.html

[RSA Conference 2015 : New Trends In Cryptographic Algorithm Suites Used For TLS Communications] 鏈接 http://www.rsaconference.com/writable/presentations/file_upload/dsp-f03-new-trends-in-cryptographic-algorithm-suites-used-for-tls-communications.pdf

密碼學相關

[Stanford Cryptography open course] 鏈接 https://www.coursera.org/course/crypto

[crypto101,一本很棒的開源電子書] 鏈接 http://crypto101.io

[現代密碼學理論與實踐] 鏈接 https://book.douban.com/subject/1172109/ - 毛文波

[現代密碼學:原理與協議] 鏈接 http://book.douban.com/subject/5954556/ - Katz and Lindell

[“Modern Crypto: 15 Years of Advancement in Cryptography”? — 2015 defcon 大會Steve Weis 演講] 鏈接 http://saweis.net/pdfs/weis-modern-crypto-defcon-2015.pdf

強烈建議不要看90年代的書,普遍嚴重過時,比如《應用密碼學:協議、算法與C源程序(原書第2版)》

[DJBs crypto page] 鏈接 http://cr.yp.to/crypto.html

[DJBs entropy attacks] 鏈接 http://blog.cr.yp.to/20140205-entropy.html

[Cryptographic Right Answers] 鏈接 https://gist.github.com/tqbf/be58d2d39690c3b366ad

http://www.slideshare.net/yassl/securing-data-in-transit

[Schneier 關于密碼學2010年現狀的評述] 鏈接 <https://www.schneier.com/blog/archives/2013/07/is_cryptography.html

http://security.stackexchange.com/questions/2202/lessons-learned-and-misconceptions-regarding-encryption-and-cryptology

http://chargen.matasano.com/chargen/2009/7/22/if-youre-typing-the-letters-a-e-s-into-your-code-youre-doing.html

http://kodu.ut.ee/~swen/publications/articles/laur-thesis-binded.pdf

https://www.enisa.europa.eu/activities/identity-and-trust/library/deliverables/study-on-cryptographic-protocols

https://github.com/sweis/crypto-might-not-suck

[Cryptographic Best Practices in the Post-Snowden Era] 鏈接 http://pages.uoregon.edu/joe/crypto-bcp/crypto-bcp.pdf

[Crypto War] 鏈接 http://en.wikipedia.org/wiki/Crypto_Wars

[52 Things People Should Know To Do Cryptography] 鏈接 http://www.cs.bris.ac.uk/Research/CryptographySecurity/knowledge.html

http://bristolcrypto.blogspot.com/

https://www.schneier.com/

https://www.imperialviolet.org/2015/05/16/aeads.html

https://crypto.stanford.edu/~dabo/cryptobook/draft_0_2.pdf

http://saweis.net/pdfs/weis-modern-crypto-defcon-2015.pdf

相關開源項目

[GoTLS] 鏈接 http://golang.org/pkg/crypto/tls/ - go語言自己搞的 TLS 協議實現

[OpenSSL] 鏈接 https://www.openssl.org/ - 事實上的標準

[LibreSSL] 鏈接 http://www.libressl.org/ - OpenBSD搞的OpenSSL的分支,代碼可讀性大大提高

[BoringSSL] 鏈接 https://boringssl.googlesource.com/boringssl/ - Google Security team 維護的OpenSSL分支

[NSS] 鏈接 https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS - Mozilla 維護的TLS協議實現

[s2n] 鏈接 https://github.com/awslabs/s2n/ - Amazon搞的tls協議實現

[MiTLS] 鏈接 http://www.mitls.org/wsgi/home ,? [TLS Attacks] 鏈接 http://www.mitls.org/wsgi/tls-attacks

[NaCL] 鏈接 http://nacl.cr.yp.to/ and [libsodium] 鏈接 https://github.com/jedisct1/libsodium

[spiped] 鏈接 http://www.tarsnap.com/spiped.html

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 本文轉自微信后臺團隊,如有侵犯,請聯系我們立即刪除

OpenIMgithub開源地址:

https://github.com/OpenIMSDK/Open-IM-Server

OpenIM官網 : https://www.rentsoft.cn

OpenIM官方論壇: https://forum.rentsoft.cn/

更多技術文章:

開源OpenIM:高性能、可伸縮、易擴展的即時通訊架構https://forum.rentsoft.cn/thread/3

【OpenIM原創】簡單輕松入門 一文講解WebRTC實現1對1音視頻通信原理https://forum.rentsoft.cn/thread/4

【OpenIM原創】開源OpenIM:輕量、高效、實時、可靠、低成本的消息模型https://forum.rentsoft.cn/thread/1

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 230,431評論 6 544
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,637評論 3 429
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事?!?“怎么了?”我有些...
    開封第一講書人閱讀 178,555評論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,900評論 1 318
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,629評論 6 412
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,976評論 1 328
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,976評論 3 448
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 43,139評論 0 290
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,686評論 1 336
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,411評論 3 358
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,641評論 1 374
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,129評論 5 364
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,820評論 3 350
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,233評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,567評論 1 295
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,362評論 3 400
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,604評論 2 380

推薦閱讀更多精彩內容