I. in the session creation phase of the handshake, the IDs of the received packet packages are all 0. The main process of this phase is to send the hello data block to the server by the client. Then, the server will also create a rhello data block to respond to the client. rhello contains the cookie created by the server and the certificate. The specific process is as follows:
2. process the received packet as follows:
The structure of the received packet is as follows (this figure is provided by netizens ):
1. uint8 marker = packet. read8 (); // read marker
Uint16 time = packet. read16 (); // read timesent
Uint8 id = packet. read8 (); // read typeid
Uint16 size = packet. read16 (); // read size
Note: (a) In the hello data block sent by the client, the read marker value is marker = 0x0b, written in binary format as marker = 00001011,
The last two values determine the packet type, as shown below:
0: indicates the prohibited value.
1: indicates the sender flag.
2: Indicate the responder sign
3: Create a session Startup Type
Therefore, the preceding marker shows that the packet type is the session Startup type.
(B) The read ID is 0x30, which indicates a hello data block.
2. Continue to read packet data as follows:
Request. read8 (); // skip unknown
Uint8 epdlen = request. read8 ()-1; // read EPD Length
Uint8 type = request. read8 (); // read type
String EPD;
Request. readraw (epdlen, EPD); // read EPD
String tag;
Request. readraw (16, tag); // read the tag
Response. writestring8 (TAG); // write the tag to response, which is required by the Protocol
The structure of the hello data block is as follows:
3. Response Processing:
The structure of response is as follows:
1. As mentioned above, the tag has been written into response.
2. Create a cookie and write the response as follows:
Cookie * pcookie = attempt. pcookie;
Writer. write8 (cookie_size );
Writer. writeraw (pcookie-> value, cookie_size );
3. Write the certificate into response as follows:
Memcpy (_ certificat, "\ x01 \ x0a \ x41 \ x0e", 4 );
Randominputstream (). Read (char *) & _ Certificat [4], 64 );
Memcpy (& _ Certificat [68], "\ x02 \ x15 \ x02 \ x02 \ x15 \ x05 \ x02 \ x15 \ x0e", 9 );
Response. writeraw (_ certificat, sizeof (_ Certificat ));
4. Write the typeid to response, as shown below:
Response. write8 (0x70 );
5. Write the size to response as follows:
Response. write16 (response. Length ()-response. Position ()-2 );
Finally sent to the client, the first handshake ends.
The structure of the rhello data block is as follows:
Not complete to be continued ~~
Reprinted please indicate the source: zhujian blog, http://blog.csdn.net/linyanwen99/article/details/8664626