What is the TCP three-way handshake?
There are three blocks here, corresponding to three IP packets. This is the “TCP three-way handshake”. The goal of this process is to establish a connection.
Connection establishment is like a legal contract. Each party must agree to the contract, and have a copy of the other party’s agreement to the contract. The contract content could be thought of as
127.0.0.2shall transmit two byte streams between each other.
127.0.0.1shall send a byte stream from port
127.0.0.2shall send a byte stream from port
The first packet is the client requesting a connection. But the connection contract can’t be achieved with a single “open connection” packet. TCP works over IP, where there is no guaranteed delivery; thus the client cannot know that the server received the “open connection” packet. Also, the server might choose to deny the connection even if it receives the request!
The client wishes to know whether the the server has accepted the connection. This acceptance is called “acknowledgement” in TCP, and this is the second packet in the handshake: the server acknowledges the connection.
Doesn’t it seem like two packets are enough to establish the connection? A legal contract could work this way. But two packets are not enough, because the “connection contract” actually consists of a couple more facts:
The first byte in the byte stream from
127.0.0.1:56742shall have number
3112279261. The first byte in the byte stream from
127.0.0.2:12345shall have number
3504942089 are “initial sequence numbers”.
You can see them in the
An initial sequence number is chosen at random by its source host,
3112279261 at random
3504942089 at random.
Thus the full contract is not written by the client;
it is only known after the server responds.
This means the server now wants a response from the client,
acknowledging the server’s initial sequence number.
This is the third packet in the three-way handshake.
(Why do we have these random initial sequence numbers? I’ll cover that some other time.)
More by Jim
- Your syntax highlighter is wrong
- Granddad died today
- The Three Ts of Time, Thought and Typing: measuring cost on the web
- I hate telephones
- The sorry state of OpenSSL usability
- The dots do matter: how to scam a Gmail user
- My parents are Flat-Earthers
- How Hacker News stays interesting
- Project C-43: the lost origins of asymmetric crypto
- The hacker hype cycle
- The inception bar: a new phishing method
- Time is running out to catch COVID-19
- A probabilistic pub quiz for nerds
- Smear phishing: a new Android vulnerability
Tagged . All content copyright James Fisher 2018. This post is not associated with my employer. Found an error? Edit this page.