refs: HTTP权威指南 第14章 安全HTTP

SSL:

  1. 交换协议版本号
  2. 选择两端都了解的密码
  3. 通过证书签名对两端的身份进行认证(主要是客户端认证服务端)
  4. 生成临时的会话密码

流程:

客户端发送支持的密码协议,请求证书

服务端选择密码,返回证书

客户端用证书中的服务端公钥非对称加密密钥,客户端与服务端生成密钥

客户端和服务端用临时生成的密钥,通过对称加密通信。

如何认证证书有效

客户端必须有信任的权威CA机构。权威CA机构的私钥是要经过仪式生成的。(http://www.digi-sign.com/digi-ca/buyer/key+ceremony

"A Key Ceremony is only required when your organisation wishes to achieve your own independent root, or intermediate, Certificate Authority. This typically occurs where an organisation wants to create and own its own Root CA for reasons relating to compliance to specific standards (e.g. ISO 27001, WebTrust, EU Qualified Certificates, etc). A Root Key Ceremony is a procedure where a unique pair of Public and Private Root Keys is generated. Depending on your requirements and specifications, the generation of the Root Keys may require notarisation, legal representation, witnesses and "Key Holders" to be present"

CA机构可以为一些服务的合法性背书,具体做法就是签发证书。

证书信息包含服务端公钥,为该网络服务背书的CA机构,证书生效时间和失效时间。可以按照一定规则为这些信息生成摘要。CA机构会用私钥为证书信息生成一段摘要签名,即签发证书。

客户端保存着权威CA机构的公钥,收到服务端的证书后,客户端会同样为证书按照与服务端同样的规则生成一段摘要,同时用证书注明的CA的公钥解密摘要签名,如果解密出来的摘要与证书的摘要相同,则证书是合法的。

除此之外,客户端还会验证证书的有效时间,站点身份。

为什么服务端不需要验证客户端身份

https保证通信内容不被第三方监听,任何人都可以与服务端通信,但是获取服务端资源依然需要Cookie等机制验证身份。