Today I summarized what is the HTTP three-way handshake, the process of the HTTPS handshake and why HTTPS is secure.
Premise
When describing these two handshakes, there are some things that need to be explained in advance.
What is the difference between HTTP and TCP/IP?
TPC/IP protocol is a transport layer protocol, which mainly solves how to transmit data in the network, while HTTP is an application layer protocol, which mainly solves how to package data. WEB uses HTTP protocol as the application layer protocol to encapsulate HTTP text information, and then uses TCP/IP as the transport layer protocol to send it to the network.
The following diagram attempts to show the position of different TCP/IP and other protocols in the original OSI (Open System Interconnect) model:
PS: The form comes from online information
#What is the CA certificate?
CA (Certificate Authority) is a third-party authority responsible for managing and issuing certificates. It is trusted and recognized by all industries and the public.
CA certificate is a certificate issued by a CA. It can be used to verify whether a website is trustworthy (for HTTPS), to verify whether a file is trustworthy (whether it has been tampered with), etc. One certificate can also be used to prove another certificate. It is authentic and trustworthy, and the top-level certificate is called the root certificate. Except for the root certificate (which proves itself to be reliable), other certificates must rely on the higher-level certificate to prove themselves.
HTTP three-way handshake
HTTP (HyperText Transfer Protocol) Hypertext Transfer Protocol is the most widely used on the Internet A network protocol. Since the information is transmitted in clear text, it is considered insecure. As for the three-way handshake of HTTP, it actually uses the three-way TCP handshake to confirm the establishment of an HTTP connection.
As shown in the figure below, SYN (synchronous) is the handshake signal, Sequence number, and Acknowledge number used when TCP/IP establishes a connection. The three arrows pointing to it represent a three-way handshake. After the three-way handshake is completed, the client and server start transmitting data.
PS: The picture comes from online information
The first handshake: the client sends a syn packet (syn=j) to the server and enters the SYN_SEND state. Waiting for server confirmation;
Second handshake: The server receives the syn packet and must confirm the client's SYN (ack=j+1), and at the same time it also sends a SYN packet (syn=k), that is, SYN+ ACK packet, at this time the server enters the SYN_RECV state;
The third handshake: the client receives the SYN+ACK packet from the server and sends a confirmation packet ACK (ack=k+1) to the server. After the packet is sent, the client The client and server enter the ESTABLISHED state and complete the three-way handshake.
HTTPS handshake process
HTTPS adds the SSL protocol based on HTTP. SSL relies on certificates to verify the server. identity and encrypt communications between the browser and server. Specifically, how to perform encryption, decryption, and verification is shown in the figure below. The following is called a handshake.
PS: The following description of the picture is taken from: http://zhuqil.cnblogs.com
1. Client Initiating an HTTPS request
2. Server configuration
The server using the HTTPS protocol must have a set of digital certificates. You can make it yourself or use a CA certificate. The difference is that the certificate issued by yourself needs to be verified by the client before you can continue to access, while using the CA certificate will not pop up the prompt page. This set of certificates is actually a pair of public and private keys. The public key is used for encryption by others, and the private key is used for decryption by yourself.
3. Transfer the certificate
This certificate is actually a public key, but it contains a lot of information, such as the issuing authority of the certificate, expiration time, etc. .
4. Client parsing certificate
#This part of the work is completed by the client's TLS. First, it will verify whether the public key is valid. For example, the issuing authority, expiration time, etc. If an abnormality is found, a warning box will pop up indicating that there is a problem with the certificate. If there is no problem with the certificate, then a random value is generated and then the random value is encrypted with the certificate.
5. Transmitting encrypted information
#This part transmits a random value encrypted with a certificate. The purpose is to let the server get this random value. value, future communication between the client and the server can be encrypted and decrypted through this random value.
6. Service segment decryption information
After the server decrypts with the private key, it obtains the random value (private key) passed by the client, and then symmetrically encrypts the content using this value. The so-called symmetric encryption is to mix information and private keys through a certain algorithm, so that unless the private key is known, the content cannot be obtained, and both the client and the server know the private key, so as long as the encryption algorithm is strong enough, The private key is complex enough and the data is secure enough.
7. Transmitting encrypted information
This part of the information is the information encrypted by the private key in the service segment, which can be used on the client. reduction.
8. The client decrypts the information
#The client uses the previously generated private key to decrypt the information passed by the service segment, and then obtains the decryption the following content.
PS: Even if the third party monitors the data during the entire handshake process, it is helpless.
Summary
Why is HTTPS secure?
In the fourth step of the HTTPS handshake, if the site's certificate is not trusted, the following confirmation interface will be displayed to confirm the authenticity of the website. In addition, steps six and eight use the client's private key to encrypt and decrypt, ensuring the security of data transmission.
The difference between HTTPS and HTTP
1. The https protocol requires applying for a certificate from ca or a self-made certificate .
2. http information is transmitted in clear text, while https uses secure SSL encryption.
3. http transmits data directly with TCP, while https passes through a layer of SSL (OSI presentation layer) and uses different ports. The former is 80 (requires domestic filing) and the latter is 443. .
4. The http connection is very simple and stateless; the HTTPS protocol is a network protocol built from the SSL+HTTP protocol that can perform encrypted transmission and identity authentication, and is more secure than the http protocol.
Note that https encryption is completed at the transport layer
The https message is encrypted when it is packaged into a tcp message, whether it is Both the header domain and the body domain of https will be encrypted.
When using tcp layer tools such as tcpdump or wireshark to capture packets, the encrypted content is obtained, and if the application layer is used to capture Package, use Charels(Mac), Fildder(Windows) packet capture tool, then of course you will see it in clear text.
PS: HTTPS itself is for network transmission security.
Example, use wireshark to capture the packet:
http, you can see that the capture is in plain text:
https, you can see The one caught is ciphertext:
Appendix
The encryption and HASH algorithms generally used by HTTPS are as follows :
Asymmetric encryption algorithm: RSA, DSA/DSS
Symmetric encryption algorithm: AES, RC4, 3DES
HASH algorithm: MD5, SHA1, SHA256
The above is the detailed content of What is the HTTP vs HTTPS handshake. For more information, please follow other related articles on the PHP Chinese website!

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor