In the https era, do you still know nothing about him?
The author of this article: Qieguo, focuses on the field of front-end development. For more articles, please pay attention to the Zhihu column "Front-end Little Things"
Now open the major well-known websites, have you found the address? A small green lock has been added to the column?
Yes, this is https, this is the era of https.
However, do you understand https?
Simply put, https is http wrapped in SSL/TLS, which is secure http. What is safety? A secure network communication environment needs to solve three problems:
Confidentiality of communication content
True identity of both communicating parties
Complete communication content
And https was born to solve these three major problems (to be precise, it should be ssl). Let’s take a look at these three separately. solution to the problem.
Confidentiality of communication content
Confidentiality of communication content needs to be achieved through encryption. Our Internet environment is very transparent, and communications need to go through many transits before reaching the recipient. This situation is a bit like handing a note to Xiaohong in the first row during class. On the note, you would definitely not directly write "see you at the playground at midnight tonight", but cleverly write "see you at the same place." Only you and Xiaohong know about this old place, so even if Xiaoming and Xiaoli see the note, they don't know whether the old place is the library or the English corner. This is encryption, and the old place is the so-called key.
Of course, this example is not very accurate. To put it simply, encryption and decryption is a function , and the key is the parameter of this function. For example, we define a simple encryption function, f(x)=x+b, x is the input plaintext, and b is the key; the decryption function is the inverse function of the encryption function, that is, g(x )=x-b. When you don't know b, you can't guess the real content even if you see the ciphertext, so encryption is achieved. This kind of encryption and decryption uses the same key, which is called symmetric encryption.
But there is a problem here. How is parameter b here negotiated?
You and Xiaohong can spend time and money to make an appointment, but in a real network environment, there is no possibility for you and Xiaohong to communicate directly. All communication must rely on Xiaoming and Xiaoli to pass the paper. If so, what can you do to avoid them? Here you need to use an asymmetric encryption algorithm. This algorithm has a pair of public keys and private keys. The public key is a key that everyone can obtain, and the private key is kept privately by the service server. key. In the asymmetric encryption algorithm, the content encrypted by the public key can only be decrypted by the private key, and the content encrypted by the private key can only be decrypted by the public key. So when you use Xiaohong's public key to encrypt your note, Xiaoming, Xiaoli and others who help you deliver the note will not be able to read the content when they see the note. Only Xiaohong who has the private key can read your information. .
The symmetric encryption algorithm uses the same secret key for encryption and decryption; the asymmetric encryption algorithm requires two keys for encryption and decryption, and these two secret keys are public keys. (public key, referred to as public key) and private key (private key, referred to as private key). You may be curious about the principles of asymmetric encryption algorithms, but I will not go into details about the algorithm here. Interested students can search by themselves.
Then the question is, what should I do if Xiaohong also wants to encrypt the response to you?
If Xiaohong uses her private key to encrypt, everyone in the class knows the public key, and the public key can decrypt the private key, which also means that everyone can decrypt Xiaohong’s Respond to messages. If you are smart, you must have thought of the solution: Use the asymmetric encryption algorithm to encrypt a symmetric key to Xiaohong. Xiaohong uses her private key to read the symmetric key, and then you use this symmetric key to do it. Symmetric encryption, and then you can happily date.
Of course, https does the same thing.
The true identity of the communicating parties
After encryption, the communication process seems to be perfect? Wait a minute, how does Xiaohong’s public key become known to the world?
You must know that all information interaction in the network environment is carried out by passing notes, and Xiaohong's public key is no exception. What if it is switched when it passes through Xiaoming's hands? How to ensure that the Xiaohong public key in your hand is the real Xiaohong public key? Seeing that the notes about the crazy men and women in the class were being exchanged in various ways, Sister Feng, the entertainment committee member, decided to come forward. Sister Feng came up with a way to carry a certificate with her in all encrypted communications to prove her identity. This certificate was specially made by Sister Feng for all the singles in the class. The public key is placed in the certificate and returned to the sender of the note. In addition to the public key, the certificate also contains various information such as student number, name, and even zodiac sign, height and measurements. . There is a large identification seal stamped on the certificate. This is Sister Feng's unique seal, which means that the authenticity of the information on the certificate is guaranteed by Sister Feng. When you see this seal, you can think that the other party is a real single.
Through this information, you can know whether the other party is Xiaohong or Ruhua. This is the certificate mechanism.
Obviously you will suspect that Sister Feng’s official seal on the certificate may have been forged, and your suspicion is justified! Therefore, the official seal on the certificate is also asymmetrically encrypted. The encryption method is just the opposite of what is mentioned above: encrypted with Sister Feng’s private key, and decrypted with Sister Feng’s public key, so that the authenticity of the certificate can be verified. This official seal is the digital signature of the certificate. Specifically, it is the process of first extracting the summary of the certificate using a hash algorithm, and then encrypting the summary. In addition, you can also go directly to Sister Feng with the certificate, and Sister Feng will help you verify the validity of the certificate. (Certificates have an expiration date, so even real certificates may expire, so you need to pay attention)
This mechanism seems to be quite complete, but we have to build a security mechanism with a skeptical attitude, something that Sister Feng guarantees It's trustworthy.
But, is Sister Feng really Sister Feng? ? ?
Therefore, Sister Feng herself must also be guaranteed by a certificate. Sister Feng’s certificate is issued by the class teacher, and the class teacher’s certificate is issued by the principal... This chain goes all the way to the end Several authoritative institutions are the so-called root CAs in the https system. Roots are unquestionable authorities, they bring salt to themselves and prove themselves to be who they are. In the https certificate system, the root certificate comes with the operating system/browser. We can trust the certificates certified by these organizations, and then derive them layer by layer to the level of Fengjie.
In addition, because the certificate is actually very easy to obtain, it costs 10 yuan per copy at the subway entrance, and it costs 10 yuan for both Harvard and Stanford! Therefore, some companies will make their own certificates without going to the root CA organization at all, such as the famous 12306. You can also make your own certificate and put it online for users to download and import into their browsers, but because you don’t have Sister Feng’s influence, no one will believe you. Of course, some people don’t even believe Sister Feng...
The communication content is complete
The password has also been added, and Sister Feng’s official seal has also been stamped. Is this mechanism perfect?
NoNoNo, think about it, Xiao Ming, who has a crush on you, will definitely feel unhappy when he sees you sending a note to Xiao Hong. Although he can’t understand it, he can still change the cipher text. Originally, you were going to ask Xiaohong to meet on the playground at midnight, but Xiaoming deleted the first half of the cipher text, and after decryption it happened to be "Meet on the playground." Then Xiaohong ran to the playground immediately after class, but you ran back to the dormitory to take a good shower. A bath. . . Then, Xiaohong ran away with Xiaoming~~
I believe everyone has a deep understanding of this scenario of tampering with communication content. When we visit some sites, advertisements from operators appear for no reason. This is all It was added by the operator! ! Therefore, the integrity of the content also needs to be guaranteed. This is relatively simple: first use a hash algorithm to extract the content summary, and then encrypt the summary to generate a digital signature. By verifying the digital signature, you can determine the integrity of the communication content.
The above is a simplified version of the technology used in https. An http communication process is as follows:
General steps:
The client sends a Client Hello message to start SSL communication. The message contains the SSL version, available algorithm list, key length, etc.
When the server supports SSL communication, it will respond with a Server Hello message. The message also includes the SSL version and encryption algorithm configuration, which is the negotiated encryption and decryption algorithm.
Then the server will send the Certificate message, which means sending the certificate to the client.
The client sends a Client Key Exchange message, uses the certificate public key in 3 to encrypt the Pre-master secret random password string, and subsequently uses this password for symmetric encryption for communication.
After the server successfully decrypts using the private key, it returns a response indicating that the SSL communication environment has been set up.
Then there is regular http c/s communication.
As mentioned above, digest and signature algorithms will be used in steps 3 and 6 to ensure that the passed certificate and communication content are not tampered with. It can be seen from this process that the core of https lies in encryption, especially the asymmetric encryption algorithm that is used many times to transmit key information.
After understanding encryption, recognizing the transparency of the network, and being skeptical of everything, it becomes easier to understand the https system.
Conclusion
Recently I have been systematically reviewing http-related things. This article first introduces the basic principles of https. I have little knowledge and knowledge. If there is anything inappropriate, please correct me! Later, we will introduce the actual application, static server configuration, etc.~
Appendix
How to avoid man-in-the-middle hijacking of https?
If someone hijacks your DNS server and resolves wwe.icbc.com to his illegal website, or the proxy server directs you to his illegal website, this is a man-in-the-middle attack. If there is no https, then the attack occurs. So how does https avoid such attacks?
The answer is through certificate authentication.
When applying for a certificate, the CA will perform control certification on the domain name to be applied for, so it is impossible for you to use Lao Wang’s website next door to apply for a certificate. Even if you hack his site, Lao Wang can find out as long as he applies for a certificate.
If you forge a certificate that is not issued by an authoritative CA, then the browser will alert you when checking that the certificate is illegal. Of course, users can still continue to operate, such as grabbing train tickets or something. .
If you download the certificate of the real site, the domain name on the certificate remains unchanged, and you just replace the public key, then the browser will be able to find the correctness when comparing the digital signature of the certificate. If you can't get on, call the police without saying a word.
If the middleman directly uses the real certificate of www.icbc.com, then although he can receive the client's message, he cannot decrypt it, so he cannot respond to the client's request, and the attack is invalid!
Certificate’s Digital Signature
I didn’t know much about hash algorithms and digital signatures before. After understanding them, I found that the principle is actually quite simple. The hash algorithm can convert a large amount of data into a fixed-length summary, and the summary corresponds to the input. The summary will also change when the input changes. Therefore, a hash algorithm is applied to the data to obtain a summary. By comparing the summary, you can determine whether the data has been tampered with. The certificate uses the private key to encrypt the digest, and then the client can use the public key to decrypt it to obtain the digest. By comparing the digest calculated by the hash algorithm, it can determine whether the certificate has been tampered with. On the other hand, because the public and private keys are in pairs, although the digest of the tampered certificate can be obtained, the signature cannot be encrypted, so the combination of digest and encryption can ensure the authenticity of the certificate. The private key here is the private key of the issuing authority of the certificate, that is, the CA on the CA chain encrypts the user server certificate, and the superior CA encrypts the certificate of the subordinate CA, thus forming a trust ring.
The author of this article: Qieguo, focuses on the field of front-end development. For more articles, please pay attention to the Zhihu column "Front-end Little Things"
The above is the detailed content of In the https era, do you still know nothing about him?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use NginxProxyManager to implement reverse proxy under HTTPS protocol. In recent years, with the popularity of the Internet and the diversification of application scenarios, the access methods of websites and applications have become more and more complex. In order to improve website access efficiency and security, many websites have begun to use reverse proxies to handle user requests. The reverse proxy for the HTTPS protocol plays an important role in protecting user privacy and ensuring communication security. This article will introduce how to use NginxProxy

How to use NginxProxyManager to implement automatic jump from HTTP to HTTPS. With the development of the Internet, more and more websites are beginning to use the HTTPS protocol to encrypt data transmission to improve data security and user privacy protection. Since the HTTPS protocol requires the support of an SSL certificate, certain technical support is required when deploying the HTTPS protocol. Nginx is a powerful and commonly used HTTP server and reverse proxy server, and NginxProxy

Nginx is a high-performance web server software and a powerful reverse proxy server and load balancer. With the rapid development of the Internet, more and more websites are beginning to use the SSL protocol to protect sensitive user data, and Nginx also provides powerful SSL support, making the security performance of the web server even further. This article will introduce how to configure Nginx to support the SSL protocol and protect the security performance of the web server. What is SSL protocol? SSL (SecureSocket

The https workflow includes steps such as client-initiated request, server response, SSL/TLS handshake, data transmission, and client-side rendering. Through these steps, the security and integrity of data during transmission can be ensured.

The reason for the error is that the ProxySchemeUnknown(proxy.scheme) error of urllib3 is usually caused by the use of an unsupported proxy protocol. In this case, urllib3 does not recognize the proxy server's protocol type and therefore cannot use the proxy for network connections. To resolve this issue, you need to ensure that you are using a supported proxy protocol, such as HTTP or https. How to resolve To resolve this issue, you need to ensure that you are using a supported proxy protocol, such as HTTP or HTTPS. You can solve this problem by setting the proxy parameters of urllib3. If you are using an http proxy, the code example is as follows: importurllib3http

Configuration steps: 1. Obtain the SSL certificate; 2. Configure the SSL certificate; 3. Edit the Tomcat configuration file; 4. Restart Tomcat. Detailed introduction: 1. You need to obtain an SSL certificate, either a self-signed certificate or a valid SSL certificate from a certification agency (such as Let's Encrypt); 2. Place the obtained SSL certificate and private key files on the server and ensure that these files Located in a safe location, only users with sufficient permissions can access; 3. Edit Tomcat configuration files, etc.

In today's Internet era, secure communication has become an indispensable part. Especially in HTTPS communication, how to ensure its security is particularly important. As a popular web server and reverse proxy server, Nginx's firewall can also play an important role in ensuring HTTPS secure communication. This article will discuss the Nginx firewall from the following aspects. TLS/SSL encryption The security of HTTPS communication is mainly based on TLS/SSL encryption technology, which can prevent data from being transmitted during transmission.

The difference between one-way verification and two-way verification: One-way verification: refers to the client verifying the server-side certificate, and the server does not need to verify the client certificate. Two-way verification: refers to the client verifying the server-side certificate, and the server also needs to verify the client certificate through the CA's public key certificate. Detailed handshake process: One-way authentication The browser sends a connection request to the security server. 1. The server sends its own certificate and certificate-related information to the client browser. 2. The client browser checks whether the certificate sent by the server is issued by the CA center it trusts. If it is, continue to execute the agreement; if not, the client's browser will give the client a warning message: warning the client that this certificate is not trustworthy and asking the client if it needs to continue. 3. Pick up customers
