Https one-way authentication and two-way authentication

Original text from:

http://blog.csdn.net/duanbokan/article/details/50847612

 

一、Http

HyperText Transfer Protocol, the hypertext transfer protocol, is the most widely used protocol on the Internet, and all WWW files must follow the standard. The data transmitted by the HTTP protocol is unencrypted, that is, in clear text, so it is very insecure to use the HTTP protocol to transmit private information.

Use TCP port as: 80

2. Https

Hyper Text Transfer Protocol over Secure Socket Layer, a secure hypertext transfer protocol, Netscape formula designed the SSL (Secure Sockets Layer) protocol to encrypt the data transmitted by the Http protocol to ensure the security during the session.

Use TCP port default is 443

3. SSL protocol encryption method

The SSL protocol uses both symmetric encryption and asymmetric encryption (public key encryption). When establishing a transmission link, SSL first performs asymmetric encryption on the symmetric encryption key using the public key. The transmitted content uses symmetric encryption.

  1. Symmetric encryption 
    has high speed and can encrypt larger content, and is used to encrypt messages during a session

  2. Public key encryption 
    encryption is slower, but can provide better authentication technology, used to encrypt the key of symmetric encryption

Four, one-way authentication

Before Https establishes a Socket connection, a handshake needs to be performed. The specific process is as follows:



 

 

  1. The client sends the SSL protocol version number, encryption algorithm type, random number and other information to the server.
  2. The server returns the SSL protocol version number, encryption algorithm type, random number and other information to the client, and also returns the server's certificate, that is, the public key certificate
  3. The client uses the information returned by the server to verify the legitimacy of the server, including:

    • Whether the certificate has expired
    • Is the CA that issued the server certificate reliable?
    • Whether the returned public key can correctly decrypt the digital signature in the returned certificate
    • Does the domain name on the server certificate match the actual domain name of the server?

    After the verification is passed, the communication will continue, otherwise, the communication will be terminated

  4. The client sends the symmetric encryption scheme that it can support to the server for the server to choose
  5. The server selects the encryption method with the highest degree of encryption among the encryption schemes provided by the client.
  6. 服务器将选择好的加密方案通过明文方式返回给客户端
  7. 客户端接收到服务端返回的加密方式后,使用该加密方式生成产生随机码,用作通信过程中对称加密的密钥,使用服务端返回的公钥进行加密,将加密后的随机码发送至服务器
  8. 服务器收到客户端返回的加密信息后,使用自己的私钥进行解密,获取对称加密密钥。 
    在接下来的会话中,服务器和客户端将会使用该密码进行对称加密,保证通信过程中信息的安全。

五、双向认证

双向认证和单向认证原理基本差不多,只是除了客户端需要认证服务端以外,增加了服务端对客户端的认证,具体过程如下:



 

  1. 客户端向服务端发送SSL协议版本号、加密算法种类、随机数等信息。
  2. 服务端给客户端返回SSL协议版本号、加密算法种类、随机数等信息,同时也返回服务器端的证书,即公钥证书
  3. 客户端使用服务端返回的信息验证服务器的合法性,包括:

    • 证书是否过期
    • 颁发服务器证书的CA是否可靠
    • 返回的公钥是否能正确解开返回证书中的数字签名
    • 服务器证书上的域名是否和服务器的实际域名相匹配

    验证通过后,将继续进行通信,否则,终止通信

  4. 服务端要求客户端发送客户端的证书,客户端会将自己的证书发送至服务端
  5. 验证客户端的证书,通过验证后,会获得客户端的公钥
  6. 客户端向服务端发送自己所能支持的对称加密方案,供服务器端进行选择
  7. 服务器端在客户端提供的加密方案中选择加密程度最高的加密方式
  8. 将加密方案通过使用之前获取到的客户端公钥进行加密,返回给客户端
  9. 客户端收到服务端返回的加密方案密文后,使用自己的私钥进行解密,获取具体加密方式,而后,产生该加密方式的随机码,用作加密过程中的密钥,使用之前从服务端证书中获取到的公钥进行加密后,发送给服务端
  10. 服务端收到客户端发送的消息后,使用自己的私钥进行解密,获取对称加密的密钥,在接下来的会话中,服务器和客户端将会使用该密码进行对称加密,保证通信过程中信息的安全。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326219100&siteId=291194637