Be sure to check whether your domain name is HTTPS before doing something wrong, otherwise

Time:2021-4-21

Be sure to check whether your domain name is HTTPS before doing something wrong, otherwise

1、 HTTP protocol

Before we talk about the HTTPS protocol, let’s review the concept of HTTP protocol.

1.1 introduction to HTTP protocol

HTTP is a text-based transport protocol, which is located in the application layer of OSI network model.

Be sure to check whether your domain name is HTTPS before doing something wrong, otherwise

HTTP protocol communicates through the request response of client and server. At present, the protocol is divided into six separate protocol descriptions (RFC 7230, RFC 7231, RFC 7232, RFC 7233, RFC 7234, RFC 7235) from RFC 2616. The communication message is as follows:

request

POST http://www.baidu.com HTTP/1.1
Host: www.baidu.com
Connection: keep-alive
Content-Length: 7
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36

wd=HTTP

response

HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/html;charset=utf-8
Date: Thu, 14 Feb 2019 07:23:49 GMT
Transfer-Encoding: chunked

<html>...</html>

1.2 HTTP man in the middle attack

HTTP protocol is very convenient to use, but it has a fatal disadvantage: insecurity.

We know that the message in HTTP protocol is transmitted in plaintext without any encryption. What problems will this cause? Here’s an example:

Xiaoming posted in the Java post bar, the content is I love Java:

Be sure to check whether your domain name is HTTPS before doing something wrong, otherwise

Attacked by middleman, the content is changed to I love PHP

Be sure to check whether your domain name is HTTPS before doing something wrong, otherwise

Xiao Ming is ridiculed by the crowd
We can see that in the process of HTTP transmission, the middleman can see and modify all the requests and responses in HTTP communication, so it is very unsafe to use HTTP.

1.3 prevention of man in the middle attack

At this time, some people may think that since the content is plaintext, I use symmetric encryption to encrypt the message, so that the middleman can’t see the plaintext, so the transformation is as follows:

Both parties agree on the encryption method

Be sure to check whether your domain name is HTTPS before doing something wrong, otherwise

Encrypt message with AES

Be sure to check whether your domain name is HTTPS before doing something wrong, otherwise

In this way, it seems that the middleman can’t get the plaintext information, but in fact, the encryption method and secret key will be exposed in plaintext in the communication process. If the first communication is intercepted, the secret key will be leaked to the middleman, and the middleman can still decrypt the subsequent communication

Be sure to check whether your domain name is HTTPS before doing something wrong, otherwise

Then, in this case, we will certainly consider whether we can encrypt the secret key to prevent the middleman from seeing it? The answer is yes. Using asymmetric encryption, we can implement it through RSA algorithm. The actual operation of this step is relatively simple. You can view the video of setting up the HTTPS service by replying to the HTTPS in the background of coder’s subscription number.

When the encryption mode is agreed, the server generates a pair of public and private keys, the server returns the public key to the client, and the client generates a set of AES locally_ Key) is used for symmetric encryption and is encrypted by the public key sent by the server_ KEY_ After that, it returns to the server, which sends the AES sent by the client through the private key_ KEY_ Secret decrypts to get AEK_ Finally, the client and server through AEK_ Key carries out encrypted communication of message, and the transformation is as follows:

Be sure to check whether your domain name is HTTPS before doing something wrong, otherwise

It can be seen that in this case, the man in the middle can not steal the secret key used for AES encryption, so it is definitely impossible to decrypt the subsequent communication, so is it absolutely safe to do so?

In order to deal with this encryption method, the middleman has come up with a new solution, since he can’t get AES_ Key, then I simulate myself as a combination of client and server. In the process of user man in the middle, the man in the middle simulates the behavior of the server, so that I can get the plaintext requested by the user. In the process of man in the middle, the man in the middle simulates the behavior of the client, so that I can get the plaintext responded by the server, so as to carry out man in the middle attack

Be sure to check whether your domain name is HTTPS before doing something wrong, otherwise

This time, the communication is intercepted by the middleman again. The middleman forges a pair of public and private keys and sends the public key to the user to steal the AES generated by the client_ Key, get the AES_ After the key can be easily decrypted.

If middlemen do what they want, there is no way to punish them. Of course, there is. Next, let’s see how HTTPS solves the problem of communication security.

2、 HTTPS protocol

2.1 introduction to HTTPS

In fact, HTTPS is the abbreviation of SSL + http. Of course, SSL has been basically replaced by TLS, but next we will take SSL as the abbreviation. SSL protocol is not only applied to HTTP protocol, but also applied to various application layer protocols, such as FTP and websocket.

In fact, SSL protocol is roughly the same as the asymmetric encryption in the previous section. In the handshake process, the main purpose is to exchange secret keys, and then use symmetric encryption for communication in the communication process. The general process is as follows:

Be sure to check whether your domain name is HTTPS before doing something wrong, otherwise

I just drew a schematic diagram here. In fact, the real SSL handshake will be much more complex than this one, but its nature is still similar. What we need to pay attention to here is how to prevent man in the middle attacks by HTTPS.

It can be observed from the above figure that the server transmits the public key through SSL certificate, and the client will verify the SSL certificate. The certificate authentication system is the key to ensure the security of SSL. Next, let’s explain the CA authentication system and see how it can prevent man in the middle attack.

2.2 CA certification system

In the previous section, we saw that the client needs to verify the SSL certificate returned by the server, so how does the client verify the security of the server’s SSL certificate.

Authoritative certification body

In CA authentication system, all certificates are issued by authoritative institutions, and Ca certificates of authoritative institutions are built-in in the operating system. We call these certificates CA root certificates

Be sure to check whether your domain name is HTTPS before doing something wrong, otherwise

grant a certificate

If our application server wants to use SSL The CA certificate needs to be issued by an authoritative certification authority. We will send the public key and site related information generated by the server to the CA issuing authority, and then the CA issuing authority will countersign the relevant information sent by the server with the CA issuing authority, so as to get the certificate of our application server. The certificate will generate the signature of the content of the certificate, and use the CA to sign the signature The private key of the organization is encrypted to get the certificate fingerprint, and the relationship chain is generated with the superior certificate.

Here we download Baidu’s certificate

Be sure to check whether your domain name is HTTPS before doing something wrong, otherwise

We can see that Baidu is trusted by globalsign G2, and the same globalsign G2 is trusted by globalsign R1. When the client (browser) does certificate verification, it will check up level by level until the final root certificate. If there is no problem, the server certificate can be trusted.

How to verify the server certificate

So how does the client (browser) verify the server certificate? First, it will find the superior certificate through the hierarchical relationship, decrypt the certificate fingerprint of the server through the public key in the superior certificate to get the signature (sign1), and then calculate the signature (sign2) of the server certificate through the signature algorithm. By comparing sign1 and sign2, if they are equal, it means that the certificate has not been usurped It’s not fake.

Be sure to check whether your domain name is HTTPS before doing something wrong, otherwise

What’s interesting here is that RSA used for certificate verification cleverly verifies the validity of certificates by encrypting certificate signature with private key and decrypting with public key.

In this way, through the certificate authentication system, we can avoid the middleman stealing AES_ Key to initiate the interception and modification of HTTP communication messages.

summary

First of all, we can understand why HTTP is not secure through HTTP man in the middle attack, and then we can summarize the principle of HTTPS from the evolution of security attack and defense technology, hoping to give you a deeper understanding of HTTPS.

Write at the end

Welcome to my official account.Calm as a yard】, massive Java related articles and learning materials will be updated in it, and the sorted materials will also be put in it.

If you think the writing is good, just like it and pay attention to it! Focus, don’t get lost, keep updating!!!

Recommended Today

Review of SQL Sever basic command

catalogue preface Installation of virtual machine Commands and operations Basic command syntax Case sensitive SQL keyword and function name Column and Index Names alias Too long to see? Space Database connection Connection of SSMS Connection of command line Database operation establish delete constraint integrity constraint Common constraints NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY DEFAULT […]