During the period of unemployment, I have nothing to do. I read the book “how to connect the Internet” and two books
On the one hand to supplement professional knowledge, on the other hand is to prepare for job hopping interview.
To avoid forgetting, I drew one
There are too many problems worthy of further study. Let’s talk about them first
WebSeveral handshakes in English
1. More than one handshake
In the early days of network transmission, there were many problems
TCPThe protocol needs a handshake process, but the early protocol has a defect: the communication can only be initiated by the client, and the server can not push information to the client.
WebSocketThe agreement was born in 2008 and became an international standard in 2011. All browsers already support it.
SSL/TLSThe Security version of network protocol has existed for a long time
HTTPSIt is also a burst of development.
In the end, the handshake in the front-end field is divided into three parts
TCPThree handshakes, return
TLSShake hands, return
WebSocketHandshake, based on
TCPProtocol, it works.
TCPThe ultimate significance of three handshakes
In my previous article: “Zhenxiang warning” revisits TCP / IP protocol and three handshakes
I’ve also talked about it in detail
TCPI shook hands three times, but I didn’t realize what it meant.
Just like everyone else, I will only remember before the interview and forget afterwards.
Until I saw a passage in how the Internet connects:
**In the actual communication, the serial number does not start from 1, but needs to calculate an initial value with a random number
If the serial numbers start from 1, the communication process will be very easy to predict, and someone will use this to launch an attack.<br/><br/>But if the initial value is random, then the other party can’t figure out what the sequence number is from
Therefore, it is necessary to inform the communication object of the initial value before sending and receiving data. **
You taste, you taste. Isn’t shaking hands three times to test each other’s Secret signals to determine whether they are the right person?
2.1 knowledge supplement: the maximum length of a network packet
Calculate the data length that each network packet can hold, and the protocol stack will calculate the data length according to a
MTURepresents the maximum length of a network packet. In Ethernet, it is generally the maximum length
MTUIs the total length that contains the head, so you need to
MTUSubtracting the length of the header, the length obtained is the maximum data length that a network packet can hold. This length is called
As can be seen from the above two figures,
MSSThe value is
TCPThe longest head can reach
HTTPSThe core of
HTTPSIt’s actually a very simple agreement,
RFCThe document is very small, only seven pages long, which specifies the new protocol name“
https”The default port number is 443. As for other request response modes, message structures, request methods
URI, header fields, connection management and so on are all fully used
HTTPNothing new. —-Perspective
If you are interested, you can have a look herehttps://tools.ietf.org/html/r…
TLS/SSLWhat is it?
A lot of people see it
TLS/SSLThis pair of words began to be encircled. In fact, these two things are the same thing:
1999Name changed in
SSL 3 === TLS 1.0
What is the most widely used at present
TLSIt consists of several sub protocols, such as record protocol, handshake protocol, warning protocol, change password specification protocol, extension protocol, etc.
TLS/SSLThe protocol is located between the application layer and the transport layer TCP protocol.
TLSThe rough division can be divided into two layers
- Handshake protocol close to application layer
TLS Handshaking Protocols
- Record layer protocol close to TCP
TLS Record Protocol
It’s too much to write in this space. Let’s take care of it first
TLS handshakeDetailed explanation
When does TLS handshake occur? ：
- Every time a user passes
HTTPSWhen you navigate to a web site and the browser first begins to query the site’s original server, this is done
- Whenever any other communication is used
HTTPSThis also happens when you query the DNS on the
- Occurs when a TCP connection is opened by a TCP handshake
What happens during the TLS handshake?
TLSDuring the handshake, the client and the server perform the following operations together:
- Specify the TLS version to be used (TLS 1.0, 1.2, 1.3, etc.)
- Determine which encryption suites will be used.
- The identity of the server is verified by the public key of the server and the digital signature of the SSL certification authority
- After the handshake, a session key is generated to use symmetric encryption
The encryption suite determines the handshake mode:：
Excerpt from: detailed explanation of SSL handshake process in the chapter of HTTPS
TLSThere are two main types of handshakes: one based on
Diffie-Hellman. The main difference between the two handshakes lies in key exchange and authentication.
|Secret key exchange||Authentication|
The mainstream handshake types are basically based on
RSASo the following explanation is based on
The whole process is as follows:
Specific process description:
hello: the client initiates a handshake by sending a “hello” message to the server. The message will include the TLS version supported by the client, the encryption suite supported, and a random byte string called “client random.”.
- The server
hello: for reply client
helloMessage, the server sends a message containing the server’s
SSLCertificate, the encryption suite selected by the server and “server random number”, another random byte string generated by the server.
- The client sends the pre master key of public key encryption.
The server decrypts the encrypted pre master key with its own private key.
finished: the client sends a finish message, which is encrypted with the session key.
- The server
finished: the server sends a finish message encrypted with the session key.
- The handshake is completed, and then the master key is used to encrypt and decrypt.
There is only encryption suite, and the explanation needs to be based on packet capture. Another day, another day I will talk about…
WebSocketThe protocol is relatively simple to implement. It uses
HTTPThe protocol makes an initial handshake. After a successful handshake, the connection is established,
WebSocketBasically, raw TCP is used to read / write data.
HTTP》The pictures in this book are quite clear:
The specific steps are as follows:
- Client request:
GET /chat HTTP/1.1 Host: server.example.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw== Sec-WebSocket-Protocol: chat, superchat Sec-WebSocket-Version: 13 Origin: http://example.com
- Server response:
HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk= Sec-WebSocket-Protocol: chat
WebsocketFull duplex communication
WebsocketThe protocol solves the problem of full duplex communication between server and client.
What is simplex, half duplex, full duplex communication?
|Simplex||One way transmission of information|
|Half duplex||Information can be transmitted in both directions, but not at the same time|
|full duplex||Information can be transmitted in both directions at the same time|
SocketWhat’s the relationship,
SocketThat’s what it’s about.
HTTPThe relationship between
- It’s all the same
TCPAll of them are reliable transport protocols.
- They are all application layer protocols.
WebSocketIs a two-way communication protocol, simulation
SocketProtocol, which can send or receive information in both directions.
WebSocketA handshake is needed to establish a connection.
SocketWhat is it?
SocketIs the application layer and
TCP/IPThe intermediate software abstraction layer of protocol family communication is a set of interfaces.
In design patterns,
SocketIn fact, it’s a facade model, which integrates complex
TCP/IPProtocol family hidden in
SocketAfter the interface, for the user, a simple set of interfaces is the whole
SocketTo organize data to meet specified protocols.
4.1 expand knowledge:
Socket.IOSeven layers of demotion
Java SpringAnd so on,
websocketThere is a set of implementation
Socket.IOIt consists of two parts
- A server is used to integrate (or mount) to
Node.JS HTTPThe server:
- A client loaded into the browser:
Many people think that
Socket.ioThere are many transmission mechanisms:
1. WebSockets 2. FlashSocket 3. XHR long polling 4. XHR partial flow: multipart / form data 5. XHR polling 6. Jsonp polling 7. iframe
Thanks to so many transmission mechanisms,
Socket.ioDon’t worry about compatibility at all.
SocketWhat is it?One thing I forgot to say:
HTTPThe core difference lies in two points
HTTPThe underlying transport protocol consists of
TCP/IPIt was replaced by
- Sending and receiving messages are no longer used
Socket APIInstead of calling a dedicated security interface.
HTTPSThe agreement needs to be completed
CAApply for certificate, general free certificate is very few, need to pay.
HTTPIt’s hypertext transfer protocol, and information is transmitted in plaintext,
HTTPSIs a secure SSL encryption transmission protocol.
httpsIt uses completely different connection methods and different ports. The former is the same
80The latter is
HTTPThe connection is simple and stateless.
HTTPSThe agreement is made by
SSL+HTTPThe network protocol constructed by the protocol can carry out encrypted transmission and identity authentication
Postscript and quotation
This article quotes a lot of materials and columns
1.Detailed explanation of SSL handshake process in HTTPS
2. [how is the network connected? — Hu genqin] ()
3. [diagram HTTP – Ueno publicity] ()
4. [perspective HTTP protocol — Luo Jianfeng] ()
5.《What Happens in a TLS Handshake?》
In my brain map, I summarized eight kinds of
HTTPThe core issue.
As the front end of a career change, understand these
HTTPIt’s a painful and interesting process. If you want to scan the brain map, you can add the code to me or the official account reply:
❤️ After three things
If you think this article is enlightening to you, I’d like to invite you to do me three small favors:
- Like, so that more people can see this content (collection is not like, are playing hooligans-_ -）
- Pay attention to “front end persuasion” and share original knowledge from time to time.
- Also look at other articles
You can come to me, too
GitHubTake the source files of all the articles in the blog:
Front end persuasion Guide：https://github.com/roger-hiro…
Play together. ~