MCPcopy Create free account
hub / github.com/cuberite/cuberite / HandleEncryptionKeyResponse

Method HandleEncryptionKeyResponse

src/Protocol/Protocol132.cpp:816–863  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

814
815
816void cProtocol132::HandleEncryptionKeyResponse(const AString & a_EncKey, const AString & a_EncNonce)
817{
818 // Decrypt EncNonce using privkey
819 cRSAPrivateKey & rsaDecryptor = cRoot::Get()->GetServer()->GetPrivateKey();
820
821 Int32 DecryptedNonce[MAX_ENC_LEN / sizeof(Int32)];
822 int res = rsaDecryptor.Decrypt((const Byte *)a_EncNonce.data(), a_EncNonce.size(), (Byte *)DecryptedNonce, sizeof(DecryptedNonce));
823 if (res != 4)
824 {
825 LOGD("Bad nonce length");
826 m_Client->Kick("Hacked client");
827 return;
828 }
829 if (ntohl(DecryptedNonce[0]) != (unsigned)(uintptr_t)this)
830 {
831 LOGD("Bad nonce value");
832 m_Client->Kick("Hacked client");
833 return;
834 }
835
836 // Decrypt the symmetric encryption key using privkey:
837 Byte DecryptedKey[MAX_ENC_LEN];
838 res = rsaDecryptor.Decrypt((const Byte *)a_EncKey.data(), a_EncKey.size(), DecryptedKey, sizeof(DecryptedKey));
839 if (res != 16)
840 {
841 LOGD("Bad key length");
842 m_Client->Kick("Hacked client");
843 return;
844 }
845
846 {
847 // Send encryption key response:
848 cCSLock Lock(m_CSPacket);
849 WriteByte(0xfc);
850 WriteShort(0);
851 WriteShort(0);
852 Flush();
853 }
854
855 #ifdef _DEBUG
856 AString DecryptedKeyHex;
857 CreateHexDump(DecryptedKeyHex, DecryptedKey, res, 16);
858 LOGD("Received encryption key, %d bytes:\n%s", res, DecryptedKeyHex.c_str());
859 #endif
860
861 StartEncryption(DecryptedKey);
862 return;
863}
864
865
866

Callers

nothing calls this directly

Calls 5

GetServerMethod · 0.80
DecryptMethod · 0.80
sizeMethod · 0.80
KickMethod · 0.80
c_strMethod · 0.80

Tested by

no test coverage detected