1. Problem Raising
The widely used HTTP protocol uses a plaintext transmission mode, so it is very insecure to transmit data between communication parties on the network.
2 Solution
One simple solution is to encrypt the transmitted data.
There are two popular encryption methods: symmetric encryption and asymmetric encryption.
2.1 Symmetric Encryption
Symmetric encryption is discussed first.
Symmetric encryption means that the communication parties use the same set of keys to encrypt and decrypt data.
Symmetric encryption means that both sides of the communication must know the key in order to complete the encryption and decryption operation.
A typical scenario is that the client sends a key to the server. The server accepts the key, and all subsequent data transfers are encrypted and decrypted using the key.
Although this method can solve the problem of plaintext transmission, it has hidden danger. In the key negotiation phase, the client needs to send the key to the server. If the attacker detects the key, he can use the key to decrypt all subsequent data. In this case, the data transmission after symmetric encryption becomes plaintext transmission.
Therefore, how to ensure the security of the key in symmetric encryption is the most important problem.
2.2 Asymmetric encryption
Next we discuss asymmetric encryption. Asymmetric encryption includes public key and private key. Data encrypted with the public key can be decrypted only by the private key, and data encrypted with the private key can be decrypted only by the public key.
So is asymmetric encryption of transmitted data safe?
Asymmetric encryption A typical scenario is that the server generates a public key and a private key and sends the public key to the client. Then all data between the server and client is encrypted using the public key and private key.
Let’s analyze this scenario. From the client to accept to the server public key, and then use the public key to encrypt data, according to the principle of asymmetric encryption, we know only the server to use the private key can decrypt the encrypted data, so any attacker intercepted this information could not be completed, so any data sent by the client to the server are safe.
However, in the initial stage, the server needs to send the public key to the client. During this process, the attacker may obtain the public key, which means that the attacker can also decrypt all the data encrypted by the private key sent by the server to the client.
In conclusion, asymmetric encryption can only ensure the security of client-to-server data, but not the security of server-to-client data. Therefore, it is only a one-way secure encryption method.
2.3 Mixed encryption
Next we explore the use of symmetric encryption + asymmetric encryption mixed encryption.
According to the analysis in 2.1 Symmetric encryption mode, we know that the biggest problem in this mode lies in the security of the key. Once the key is obtained by an attacker, the transmission will be plaintext transmission. 2.2 Asymmetric Encryption We know that asymmetric encryption is only one-way secure data transmission, that is, only client-server transmission is secure.
Combining the characteristics of the two, we propose that all the data transmission of communication parties adopts symmetric encryption mode, and the key transmission adopts asymmetric encryption mode.
A typical scenario is:
- The server generates public and private keys and sends the public key to the client.
- The client generates a symmetric encryption key, encrypts the key with the public key, and sends the key to the server. All subsequent data transmission is encrypted with the key.
- After receiving the data encrypted with the public key from the client, the server decrypts it using the private key to obtain the key of the client. Then, all the data from the client is decrypted using the key.
This hybrid method of encryption can improve the security of data transmission to some extent, but is it necessarily secure? If the proxy server forges the public key from the real server and sends it to the client, then all subsequent transmission will also be plaintext transmission.
Therefore, the core problem with hybrid encryption is that there is no way to confirm that the public key is from a real server, rather than a proxy server.
2.4 the certificate
In hybrid encryption, the client requests the public key directly from the server, and the public key may be forged. Let’s improve this by introducing the concept of certificates.
A certificate contains three parts of information:
Plaintext information such as the public key of the server;
In this paper.
Digital signature;
Digest = hash(plaintext information);
Digital signature = Encryption (digest) of the certificate’s issuing authority private key;
A typical scenario is:
The client requests a certificate from the server.
Find the certificate authority’s certificate, get the public key, and decrypt the digital signature to get digest A;
Hash (plaintext) = digest B;
Compare A and B to verify the validity of the certificate.
Does this verify that the certificate was indeed issued by a certificate authority, but that authority is necessarily legitimate? So it needs to be validated again.
The same method is used to verify the validity of the authority, one layer at a time, until the client browser is pre-installed with the certificate of a globally trusted CA, which we call the root certificate.
Therefore, each server certificate is authenticated by the certificate authority at the highest level. If the certificate is authenticated by the root certificate, the certificate is valid.
Future blogs will explore the details of HTTPS implementation, but stay tuned if you’re interested.
reference
[1]. Tencent Bugly all came HTTPS. [EB/OL]. [2016-12-09]. Segmentfault.com/a/119000000…
The appendix
Common hash algorithm is MD5SHA1 SHA256
Common symmetric encryption algorithm: DES 3DES TDEA Blowfish RC5 IDEA
Common asymmetric encryption algorithm: RSA ECC Elgamal