六. TLS协定给咱们的启发 — 古代加密通信协议设计

在看了这么多的剖析和案例之后,咱们曾经能够演绎出加密通信协议设计的广泛问题,和常见设计决策,

设计决策点:

  1. 四类根底算法 加密/MAC/签名/密钥替换 如何抉择?
    对称加密目前毫无疑问应该间接用aead,最佳抉择就是 aes-128-gcm/aes-256-gcm/chacha20-poly1305了
    数字签名/验证计划,如果是挪动互联网,应该思考间接放弃 RSA,思考 P-256 的 ECDSA 公钥证书,或者更进一步的 ed25519 公钥证书。
    密钥替换算法,目前最佳抉择就是 curve25519,或者 P-256。
  2. 对称加密算法+认证算法,如何抉择?或者间接用aead?
  3. 签名算法如何抉择?RSA or ECDSA or Ed25519?
  4. 思考未来的算法调整,要加版本号机制吗?
    倡议是加上,起码在密钥协商的步骤,要加上版本号。便于未来更新算法。
  5. RSA用作密钥替换是一个好的抉择吗?思考PFS
    倡议间接放弃RSA,RSA服务器端性能比ECDSA更差,签名更大费流量,而且没有前向安全性,给私钥保存带来更大危险。
  6. 自建PKI,是个好的抉择吗?crl如何解决?
    自建PKI能够做到更平安,比方简略的客户端内置数字签名公钥。可是当须要紧急撤消一个证书的时候,只能通过紧急公布新版客户端来解决。
  7. 必须用蹩脚的openssl吗?or something better?crypto++,botan, nacl/libsodium, polarssl?libsodium: ed25519+curve2519+chacha20+poly1305
  8. 重放攻打如何解决?某种seq?或者nonce如何生成?
  9. 握手过程被中间人篡改的问题怎么解决?
  10. 性能:私钥运算的cpu耗费能够接受吗?加上某种cache?
    要解决私钥运算的高cpu耗费,必然就须要 session ticket/session id 这种cache机制。显然session ticket 更好
  11. 提早:密钥协商须要几个rtt?起码多少?加上cache后?和tcp比照如何
  12. TLS的性能(次要指服务器cpu耗费)还有空间能够压迫吗?我能设计一个性能更牛逼的吗?

七. 附录:密码学根底概念

本文曾经很长了,根底概念的内容更多,再开展介绍就太长了,上面就列一下点,贴一下参考资料,就先这样,当前再说吧。

当然,最好的材料是上面列的书。

1. 块加密算法 block cipher

AES 等

《AES后分组明码的钻研现状 及发展趋势》
http://www.ccf.org.cn/resourc...

aead的介绍(作者是大神)
https://www.imperialviolet.or...

3种组合形式之争
http://www.thoughtcrime.org/b...

CBC模式+MAC-then-encrypt的padding oracle 攻打, tls POODLE 破绽
http://drops.wooyun.org/paper...
https://defuse.ca/blog/recove...

128 bit 和 256 bit key size之争
https://www.schneier.com/blog...

nist 对 aes gcm 的技术标准,官网权威文档:
http://csrc.nist.gov/groups/S...

一个gcm的调用范例
https://github.com/facebook/c...

DES
1天之内破解DES(2008年)
http://www.sciengines.com/com...

iPhone 5S开始,A7芯片也有了aes硬件指令 (ARMv8 指令集),有825%的性能晋升:
http://www.anandtech.com/show...

2. 流加密算法 stream cipher

RC4,ChaCha20 等

序列密码倒退现状
http://www.ccf.org.cn/resourc...

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

[RC4加密已不再平安,破解效率极高(含视频)] http://www.freebuf.com/news/7...

3. Hash函数 hash funtion

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

MD5被碰撞:
http://natmchugh.blogspot.com...

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

4. 音讯验证码函数 message authentication code

HMAC-sha256,AEAD 等

为什么要用MAC
http://www.happybearsoftware....

Flickr的破绽案例:
http://netifera.com/research/...

http://www.ietf.org/rfc/rfc21...

5. 密钥替换 key exchange

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

https://blog.cloudflare.com/a...

对于 前向安全性( Perfect Forward Secrecy )
http://vincent.bernat.im/en/b...

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

google对openssl外面的椭圆曲线的优化:
http://static.googleuserconte...

http://www.math.brown.edu/~jh...

ripple从nistp256k1曲线迁徙到ed25519
https://ripple.com/uncategori...

openssh 6.5 开始反对 ed25519, curve25519, chacha20-poly1305
http://www.openssh.org/txt/re...

6. 公钥加密 public-key encryption

RSA,rabin-williams 等

RSA入门必读(斯坦福,普渡的课件):
http://crypto.stanford.edu/~d...
https://engineering.purdue.ed...

PKCS1 规范,利用RSA必读:
https://www.ietf.org/rfc/rfc3447

RSA 的公钥为什么比AES的key长?
http://crypto.stackexchange.c...

http://cryptofails.blogspot.c...

应用什么padding? OAEP,为什么不要用PKCS V1.5

http://stackoverflow.com/ques...

http://crypto.stackexchange.c...
http://en.wikipedia.org/wiki/...

PKCS #1 — #15标准协议官方网站:
http://www.emc.com/emc-plus/r...
http://arxiv.org/pdf/1207.544...

blinding 一种实现上的技术,用来解决 timing 侧通道攻打的问题
https://en.wikipedia.org/wiki...(cryptography)
http://crypto.stanford.edu/~d...

Twenty Years of Attacks on the RSA Cryptosystem:
http://crypto.stanford.edu/~d...

电子信封(digital envelope)
http://www.emc.com/emc-plus/r...

在openssl的evp接口中有间接反对:
https://wiki.openssl.org/inde...

7. 数字签名算法 signature algorithm

RSA,DSA,ECDSA (secp256r1 , ed25519) 等

三大公钥体制:RSA,DSA,ECDSA
RSA目前是支流,占据绝大多数市场份额
DSA曾经被废除
ECDSA是将来的趋势,例如bitcoin就用ECDSA
https://blog.cloudflare.com/e...
https://blog.cloudflare.com/a...

8. 明码衍生函数 key derivation function

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

hkdf: http://tools.ietf.org/html/rf...
https://cryptography.io/en/la...

9. 随机数生成器 random number generators

/dev/urandom 等

[古代密码学实际指南[2015年]] https://blog.helong.info/blog...

八. 参考文献:

TLS/SSL 相干RFC及规范

  • [TLS 1.2] 链接 https://tools.ietf.org/html/r...
  • [TLS 1.3 draft specification] 链接 https://github.com/tlswg/tls1...
  • [AES GCM for TLS] 链接 https://tools.ietf.org/html/r...
  • [ECC cipher suites for TLS] 链接 https://tools.ietf.org/html/r...
  • [TLS extensions] 链接 https://tools.ietf.org/html/r...
  • [Application-Layer Protocol Negotiation Extension] 链接 https://tools.ietf.org/html/r...
  • [X.509 PKI] 链接 https://tools.ietf.org/html/r...
  • [X.509 PKI and CRLs] 链接 https://tools.ietf.org/html/r...
  • [美国国家标准局NIST 的密码学规范] 链接 http://csrc.nist.gov/groups/S...
  • [NIST SP 800-90A ] 链接 http://csrc.nist.gov/publicat...
  • [nsa 的 SuiteB 密码学规范] 链接 https://www.nsa.gov/ia/progra...
  • [TLS on wikipedia] 链接 https://en.wikipedia.org/wiki...

协定剖析文章

  • http://www.root.org/talks/TLS...
  • [20 Years of SSL/TLS Research An Analysis of the Internet’s Security Foundation] 链接 http://www-brs.ub.ruhr-uni-bo...
  • https://www.slideshare.net/ya...
  • http://security.stackexchange...
  • [SSL/TLS in Detail] 链接 https://technet.microsoft.com...(v=ws.10).aspx
  • [SSL/TLS] 链接 http://www.spiegel.de/media/m...
  • [The Sorry State Of SSL] 链接 https://hynek.me/talks/tls/
  • [What’s the matter with TLS?] 链接 http://hyperelliptic.org/inte...
  • http://blog.csdn.net/CaesarZo...
  • )
  • [X.509 PKI and CRLs] 链接 https://tools.ietf.org/html/r...
  • [Layman’s Guide to ASN.1] 链接 http://luca.ntop.org/Teaching...

理论部署调优相干

  • https://bit.ly/gottls
  • https://istlsfastyet.com/
  • https://www.imperialviolet.org/
  • https://letsencrypt.org/
  • http://chimera.labs.oreilly.c...
  • [RSA Conference 2015 : New Trends In Cryptographic Algorithm Suites Used For TLS Communications] 链接 http://www.rsaconference.com/...

密码学相干

  • [Stanford Cryptography open course] 链接 https://www.coursera.org/cour...
  • [crypto101,一本很棒的开源电子书] 链接 http://crypto101.io
  • [古代密码学实践与实际] 链接 https://book.douban.com/subje... - 毛文波
  • [古代密码学:原理与协定] 链接 http://book.douban.com/subjec... - Katz and Lindell
  • [“Modern Crypto: 15 Years of Advancement in Cryptography” — 2015 defcon 大会Steve Weis 演讲] 链接 http://saweis.net/pdfs/weis-m...
  • 强烈建议不要看90年代的书,广泛重大过期,比方《利用密码学:协定、算法与C源程序(原书第2版)》
  • [DJBs crypto page] 链接 http://cr.yp.to/crypto.html
  • [DJBs entropy attacks] 链接 http://blog.cr.yp.to/20140205...
  • [Cryptographic Right Answers] 链接 https://gist.github.com/tqbf/...
  • http://www.slideshare.net/yas...
  • [Schneier 对于密码学2010年现状的评述] 链接 <https://www.schneier.com/blog...
  • http://security.stackexchange...
  • http://chargen.matasano.com/c...
  • http://kodu.ut.ee/~swen/publi...
  • https://www.enisa.europa.eu/a...
  • https://github.com/sweis/cryp...
  • [Cryptographic Best Practices in the Post-Snowden Era] 链接 http://pages.uoregon.edu/joe/...
  • [Crypto War] 链接 http://en.wikipedia.org/wiki/...
  • [52 Things People Should Know To Do Cryptography] 链接 http://www.cs.bris.ac.uk/Rese...
  • http://bristolcrypto.blogspot...
  • https://www.schneier.com/
  • https://www.imperialviolet.or...
  • https://crypto.stanford.edu/~...
  • http://saweis.net/pdfs/weis-m...

相干开源我的项目

  • [GoTLS] 链接 http://golang.org/pkg/crypto/... - go语言本人搞的 TLS 协定实现
  • [OpenSSL] 链接 https://www.openssl.org/ - 事实上的规范
  • [LibreSSL] 链接 http://www.libressl.org/ - OpenBSD搞的OpenSSL的分支,代码可读性大大提高
  • [BoringSSL] 链接 https://boringssl.googlesourc... - Google Security team 保护的OpenSSL分支
  • [NSS] 链接 https://developer.mozilla.org... - 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...
  • [NaCL] 链接 http://nacl.cr.yp.to/ and [libsodium] 链接 https://github.com/jedisct1/l...
  • [spiped] 链接 http://www.tarsnap.com/spiped...

本文转自微信后盾团队,如有进犯,请分割咱们立刻删除

OpenIMgithub开源地址:

https://github.com/OpenIMSDK/...

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

OpenIM官方论坛: https://forum.rentsoft.cn/

更多技术文章:

开源OpenIM:高性能、可伸缩、易扩大的即时通讯架构
https://forum.rentsoft.cn/thr...

【OpenIM原创】简略轻松入门 一文解说WebRTC实现1对1音视频通信原理
https://forum.rentsoft.cn/thr...

【OpenIM原创】开源OpenIM:轻量、高效、实时、牢靠、低成本的音讯模型
https://forum.rentsoft.cn/thr...