Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool cConnection::HandleServerLoginEncryptionKeyRequest(void)
- {
- // Read the packet from the server:
- HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, ServerID);
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, PublicKeyLength);
- AString PublicKey;
- if (!m_ServerBuffer.ReadString(PublicKey, PublicKeyLength))
- {
- return false;
- }
- HANDLE_SERVER_PACKET_READ(ReadBEShort, short, NonceLength);
- AString Nonce;
- if (!m_ServerBuffer.ReadString(Nonce, NonceLength))
- {
- return false;
- }
- Log("Got PACKET_ENCRYPTION_KEY_REQUEST from the SERVER:");
- Log(" ServerID = %s", ServerID.c_str());
- DataLog(PublicKey.data(), PublicKey.size(), " Public key (%u bytes)", (unsigned)PublicKey.size());
- m_ServerBuffer.CommitRead();
- // Save the public key
- AString NewPublicKey = m_Server.GetPublicKeyDER();
- m_ServerPublicKey = PublicKey;
- // Send packet to client with our own public key
- cByteBuffer Packet(1024);
- Packet.WriteVarInt(0x01);
- Packet.WriteVarUTF8String(ServerID);
- Packet.WriteBEShort(NewPublicKey.size());
- Packet.WriteBuf(NewPublicKey.data(), NewPublicKey.size());
- Packet.WriteBEShort(NonceLength);
- Packet.WriteBuf(Nonce.data(), NonceLength);
- AString Pkt;
- Packet.ReadAll(Pkt);
- cByteBuffer ToClient(1024);
- ToClient.WriteVarUTF8String(Pkt);
- CLIENTSEND(ToClient);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement