| 792 | |
| 793 | |
| 794 | std::size_t CNetworkServer::RecvRSAFinalize(std::shared_ptr<CNetworkPeer> peer, const void* data, std::size_t maxlength) |
| 795 | { |
| 796 | NETWORK_LOG(LL_SYS, "Peer: %p-%p %s(%d) Data: %p Max length: %p Packet size: %p", |
| 797 | peer, peer.get(), peer->GetIP().c_str(), peer->GetId(), data, maxlength, TPacketRsaKeyFinalize::size()); |
| 798 | |
| 799 | if (maxlength < TPacketRsaKeyFinalize::size()) |
| 800 | return 0; |
| 801 | |
| 802 | if (maxlength != TPacketRsaKeyFinalize::size()) |
| 803 | { |
| 804 | NETWORK_LOG(LL_CRI, "Packet size mismatch it can be combined packet!"); |
| 805 | return TPacketRsaKeyFinalize::size(); |
| 806 | } |
| 807 | |
| 808 | auto packet = reinterpret_cast<const TPacketRsaKeyFinalize*>(data); |
| 809 | |
| 810 | auto szCorrectSum = g_nmApp->NetworkMgrInstance()->CreateChecksum(data, maxlength - (NET_CHECKSUM_LENGTH /* hash */ + NET_CHECKSUM_LENGTH /* sum */)); |
| 811 | if (szCorrectSum != packet->ulChecksum) |
| 812 | { |
| 813 | NETWORK_LOG(LL_CRI, "Packet checksum mismatch! Current: %p Correct: %p Connection closed!", packet->ulChecksum, szCorrectSum); |
| 814 | return TPacketRsaKeyFinalize::size(); |
| 815 | } |
| 816 | |
| 817 | NETWORK_LOG(LL_SYS, "Got RSA finalize packet!"); |
| 818 | |
| 819 | auto szCorrectKeyHash = g_nmApp->DirFunctionsInstance()->GetSHA256(peer->GetRSACtx().get_data(), peer->GetRSACtx().get_size()); |
| 820 | auto szCurrentKeyHash = packet->rsaKeyHash; |
| 821 | auto bKeysIsEqual = (!strcmp(szCorrectKeyHash.c_str(), szCurrentKeyHash)); |
| 822 | |
| 823 | NETWORK_LOG(LL_SYS, "Client key hash: %s Server key hash: %s Eq: %d", szCurrentKeyHash, szCorrectKeyHash, bKeysIsEqual); |
| 824 | |
| 825 | // Check rsa key |
| 826 | if (bKeysIsEqual == false) |
| 827 | { |
| 828 | NETWORK_LOG(LL_CRI, "RSA key hash mismatch with clientside!"); // TODO: Mark as failed, If client still try send request reject requests |
| 829 | peer->DelayedDisconnect(5000); |
| 830 | } |
| 831 | |
| 832 | // Send notification to client |
| 833 | peer->SendRSACompleteNotification(bKeysIsEqual); |
| 834 | |
| 835 | // Set key data |
| 836 | peer->SetRSAKey(peer->GetRSACtx().get_data()); |
| 837 | NETWORK_LOG(LL_SYS, "Server RSA key succesfully created! Size: %u", peer->GetRSACtx().get_size()); |
| 838 | |
| 839 | return TPacketRsaKeyFinalize::size(); |
| 840 | } |
| 841 | |
| 842 | std::size_t CNetworkServer::RecvEnterRequest(std::shared_ptr<CNetworkPeer> peer, const void* data, std::size_t maxlength) |
| 843 | { |
nothing calls this directly
no test coverage detected