基本概念
引用自维基百科
HTTP:
The Hypertext Transfer Protocol (HTTP) is an application protocol (应用层协议)for distributed, collaborative, hypermedia information systems.[1] HTTP is the foundation of data communication for the World Wide Web, where hypertext documents include hyperlinks to other resources that the user can easily access, for example by a mouse click or by tapping the screen in a web browser. HTTP was developed to facilitate hypertext and the World Wide Web.
HTTPS:
Hypertext Transfer Protocol Secure (HTTPS) is an extension of the Hypertext Transfer Protocol (HTTP). It is used for secure communication over a computer network, and is widely used on the Internet.[1][2] In HTTPS, the communication protocol is encrypted using Transport Layer Security(TLS), or, formerly, its predecessor, Secure Sockets Layer (SSL). The protocol is therefore also often referred to as HTTP over TLS,[3] or HTTP over SSL.
HTTPS
目的
为了解决HTTP明文传输带来的信息安全问题。
基本原理
采用非对称加密。
客户端:向服务端请求公钥,然后用公钥将信息加密后传输给服务端。
服务端:服务端用私钥将信息解密。
但是会产生以下几个问题:
Q1:如何防止中间人攻击?即客服端获取了伪造的公钥,攻击人截获客户端向服务端发送的信息,用自己的私钥解密信息。
A1:数字证书有效解决了公钥的信任问题。
Q2:如何解决非对称加密性能问题?
A2:解决方法:每一次对话(session),客户端和服务器端都生成一个"对话密钥"(session key),用它来加密信息。由于"对话密钥"是对称加密,所以运算速度非常快,而服务器公钥只用于加密"对话密钥"本身,这样就减少了加密运算的消耗时间。
PS:这就是常见的为了解决非对称加密性能不好的方案,采用对称加密加密正文,非对称仅用于加密 对称加密密钥。实现用对称密钥加密文本,用非对称加密传输密钥。既保证性能也保证安全性。
如何处理这一系列问题使得协议进一步复杂化。这里有几个重要的概念。
-
数字签名
数字签名是为了保证文本不被篡改。
其运作流程如下:
- 首先,A将撰写的文本利用hash函数压缩,成为摘要(digest)。
- A利用私钥将摘要加密产生数字签名。并将数字签名与明文文本一同传输给B。
- B将明文文本hash产生h1,将数字签名用公钥解密产生h2,比对两者hash值,从而确定文本是否被篡改。
-
数字证书是为了保证客户端获取到可信的公钥。
将网站的相关信息与公钥发送到证书中心"(certificate authority,简称CA),CA会核实身份(验证你对域名的所有权),成功后将网站的相关信息与网站服务端生成的公钥加上用CA的私钥产生的***数字签名***作为证书发给申请者。
数字证书的依赖关系:
The roles of root certificate, intermediate certificate and end-entity certificate as in the chain of trust.
证书的基本结构: