diff options
Diffstat (limited to 'src/Protocol')
-rw-r--r-- | src/Protocol/Authenticator.cpp | 2 | ||||
-rw-r--r-- | src/Protocol/MojangAPI.cpp | 44 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_8.cpp | 30 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_8.h | 4 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_9.cpp | 30 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_9.h | 4 |
6 files changed, 74 insertions, 40 deletions
diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp index d46127d34..445a3dff5 100644 --- a/src/Protocol/Authenticator.cpp +++ b/src/Protocol/Authenticator.cpp @@ -11,7 +11,7 @@ #include "../IniFile.h" #include "json/json.h" -#include "PolarSSL++/BlockingSslClientSocket.h" +#include "mbedTLS++/BlockingSslClientSocket.h" diff --git a/src/Protocol/MojangAPI.cpp b/src/Protocol/MojangAPI.cpp index 5a11356c1..0b14d1cac 100644 --- a/src/Protocol/MojangAPI.cpp +++ b/src/Protocol/MojangAPI.cpp @@ -1,4 +1,4 @@ - + // MojangAPI.cpp // Implements the cMojangAPI class representing the various API points provided by Mojang's webservices, and a cache for their results @@ -9,7 +9,8 @@ #include "SQLiteCpp/Statement.h" #include "../IniFile.h" #include "json/json.h" -#include "PolarSSL++/BlockingSslClientSocket.h" +#include "mbedTLS++/BlockingSslClientSocket.h" +#include "mbedTLS++/SslConfig.h" #include "../RankManager.h" #include "../OSSupport/IsThread.h" #include "../Root.h" @@ -39,9 +40,9 @@ const int MAX_PER_QUERY = 100; /** Returns the CA certificates that should be trusted for Mojang-related connections. */ -static const AString & GetCACerts(void) +static cX509CertPtr GetCACerts(void) { - static const AString Cert( + static const char CertString[] = // GeoTrust root CA cert // Currently used for signing *.mojang.com's cert // Exported from Mozilla Firefox's built-in CA repository @@ -140,9 +141,33 @@ static const AString & GetCACerts(void) "VSJYACPq4xJDKVtHCN2MQWplBqjlIapBtJUhlbl90TSrE9atvNziPTnNvT51cKEY\n" "WQPJIrSPnNVeKtelttQKbfi3QBFGmh95DmK/D5fs4C8fF5Q=\n" "-----END CERTIFICATE-----\n" - ); + ; + + static auto X509Cert = [&]() + { + auto Cert = std::make_shared<cX509Cert>(); + VERIFY(0 == Cert->Parse(CertString, sizeof(CertString))); + return Cert; + }(); + + return X509Cert; +} - return Cert; + + + + +/** Returns the config to be used for secure requests. */ +static std::shared_ptr<const cSslConfig> GetSslConfig() +{ + static const std::shared_ptr<const cSslConfig> Config = []() + { + auto Conf = cSslConfig::MakeDefaultConfig(true); + Conf->SetCACerts(GetCACerts()); + Conf->SetAuthMode(eSslAuthMode::Required); + return Conf; + }(); + return Config; } @@ -432,7 +457,8 @@ bool cMojangAPI::SecureRequest(const AString & a_ServerName, const AString & a_R { // Connect the socket: cBlockingSslClientSocket Socket; - Socket.SetTrustedRootCertsFromString(GetCACerts(), a_ServerName); + Socket.SetSslConfig(GetSslConfig()); + Socket.SetExpectedPeerName(a_ServerName); if (!Socket.Connect(a_ServerName, 443)) { LOGWARNING("%s: Can't connect to %s: %s", __FUNCTION__, a_ServerName.c_str(), Socket.GetLastErrorText().c_str()); @@ -452,13 +478,13 @@ bool cMojangAPI::SecureRequest(const AString & a_ServerName, const AString & a_R { int ret = Socket.Receive(buf, sizeof(buf)); - if ((ret == POLARSSL_ERR_NET_WANT_READ) || (ret == POLARSSL_ERR_NET_WANT_WRITE)) + if ((ret == MBEDTLS_ERR_SSL_WANT_READ) || (ret == MBEDTLS_ERR_SSL_WANT_WRITE)) { // This value should never be returned, it is handled internally by cBlockingSslClientSocket LOGWARNING("%s: SSL reading failed internally", __FUNCTION__); return false; } - if (ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) + if (ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) { break; } diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp index a0afe8c15..053aa75e5 100644 --- a/src/Protocol/Protocol_1_8.cpp +++ b/src/Protocol/Protocol_1_8.cpp @@ -11,7 +11,7 @@ Implements the 1.8 protocol classes: #include "json/json.h" #include "Protocol_1_8.h" #include "ChunkDataSerializer.h" -#include "PolarSSL++/Sha1Checksum.h" +#include "mbedTLS++/Sha1Checksum.h" #include "Packetizer.h" #include "../ClientHandle.h" @@ -1077,9 +1077,10 @@ void cProtocol_1_8_0::SendPlayerSpawn(const cPlayer & a_Player) cPacketizer Pkt(*this, 0x0c); // Spawn Player packet Pkt.WriteVarInt32(a_Player.GetUniqueID()); Pkt.WriteUUID(a_Player.GetUUID()); - Pkt.WriteFPInt(a_Player.GetPosX()); - Pkt.WriteFPInt(a_Player.GetPosY() + 0.001); // The "+ 0.001" is there because otherwise the player falls through the block they were standing on. - Pkt.WriteFPInt(a_Player.GetPosZ()); + Vector3d LastSentPos = a_Player.GetLastSentPos(); + Pkt.WriteFPInt(LastSentPos.x); + Pkt.WriteFPInt(LastSentPos.y + 0.001); // The "+ 0.001" is there because otherwise the player falls through the block they were standing on. + Pkt.WriteFPInt(LastSentPos.z); Pkt.WriteByteAngle(a_Player.GetYaw()); Pkt.WriteByteAngle(a_Player.GetPitch()); short ItemType = a_Player.GetEquippedItem().IsEmpty() ? 0 : a_Player.GetEquippedItem().m_ItemType; @@ -1314,9 +1315,10 @@ void cProtocol_1_8_0::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock cPacketizer Pkt(*this, 0x0e); // Spawn Object packet Pkt.WriteVarInt32(a_FallingBlock.GetUniqueID()); Pkt.WriteBEUInt8(70); // Falling block - Pkt.WriteFPInt(a_FallingBlock.GetPosX()); - Pkt.WriteFPInt(a_FallingBlock.GetPosY()); - Pkt.WriteFPInt(a_FallingBlock.GetPosZ()); + Vector3d LastSentPos = a_FallingBlock.GetLastSentPos(); + Pkt.WriteFPInt(LastSentPos.x); + Pkt.WriteFPInt(LastSentPos.y); + Pkt.WriteFPInt(LastSentPos.z); Pkt.WriteByteAngle(a_FallingBlock.GetYaw()); Pkt.WriteByteAngle(a_FallingBlock.GetPitch()); Pkt.WriteBEInt32(static_cast<Int32>(a_FallingBlock.GetBlockType()) | (static_cast<Int32>(a_FallingBlock.GetBlockMeta()) << 12)); @@ -1336,9 +1338,10 @@ void cProtocol_1_8_0::SendSpawnMob(const cMonster & a_Mob) cPacketizer Pkt(*this, 0x0f); // Spawn Mob packet Pkt.WriteVarInt32(a_Mob.GetUniqueID()); Pkt.WriteBEUInt8(static_cast<Byte>(a_Mob.GetMobType())); - Pkt.WriteFPInt(a_Mob.GetPosX()); - Pkt.WriteFPInt(a_Mob.GetPosY()); - Pkt.WriteFPInt(a_Mob.GetPosZ()); + Vector3d LastSentPos = a_Mob.GetLastSentPos(); + Pkt.WriteFPInt(LastSentPos.x); + Pkt.WriteFPInt(LastSentPos.y); + Pkt.WriteFPInt(LastSentPos.z); Pkt.WriteByteAngle(a_Mob.GetPitch()); Pkt.WriteByteAngle(a_Mob.GetHeadYaw()); Pkt.WriteByteAngle(a_Mob.GetYaw()); @@ -1392,9 +1395,10 @@ void cProtocol_1_8_0::SendSpawnVehicle(const cEntity & a_Vehicle, char a_Vehicle cPacketizer Pkt(*this, 0xe); // Spawn Object packet Pkt.WriteVarInt32(a_Vehicle.GetUniqueID()); Pkt.WriteBEUInt8(static_cast<UInt8>(a_VehicleType)); - Pkt.WriteFPInt(a_Vehicle.GetPosX()); - Pkt.WriteFPInt(a_Vehicle.GetPosY()); - Pkt.WriteFPInt(a_Vehicle.GetPosZ()); + Vector3d LastSentPos = a_Vehicle.GetLastSentPos(); + Pkt.WriteFPInt(LastSentPos.x); + Pkt.WriteFPInt(LastSentPos.y); + Pkt.WriteFPInt(LastSentPos.z); Pkt.WriteByteAngle(a_Vehicle.GetPitch()); Pkt.WriteByteAngle(a_Vehicle.GetYaw()); Pkt.WriteBEInt32(a_VehicleSubType); diff --git a/src/Protocol/Protocol_1_8.h b/src/Protocol/Protocol_1_8.h index b04e5c5f0..d3d0daf0a 100644 --- a/src/Protocol/Protocol_1_8.h +++ b/src/Protocol/Protocol_1_8.h @@ -29,8 +29,8 @@ Declares the 1.8 protocol classes: #pragma warning(pop) #endif -#include "PolarSSL++/AesCfb128Decryptor.h" -#include "PolarSSL++/AesCfb128Encryptor.h" +#include "mbedTLS++/AesCfb128Decryptor.h" +#include "mbedTLS++/AesCfb128Encryptor.h" diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index 7eeba06b4..5267c7a8a 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -17,7 +17,7 @@ Implements the 1.9 protocol classes: #include "json/json.h" #include "Protocol_1_9.h" #include "ChunkDataSerializer.h" -#include "PolarSSL++/Sha1Checksum.h" +#include "mbedTLS++/Sha1Checksum.h" #include "Packetizer.h" #include "../ClientHandle.h" @@ -1124,9 +1124,10 @@ void cProtocol_1_9_0::SendPlayerSpawn(const cPlayer & a_Player) cPacketizer Pkt(*this, 0x05); // Spawn Player packet Pkt.WriteVarInt32(a_Player.GetUniqueID()); Pkt.WriteUUID(a_Player.GetUUID()); - Pkt.WriteBEDouble(a_Player.GetPosX()); - Pkt.WriteBEDouble(a_Player.GetPosY() + 0.001); // The "+ 0.001" is there because otherwise the player falls through the block they were standing on. - Pkt.WriteBEDouble(a_Player.GetPosZ()); + Vector3d LastSentPos = a_Player.GetLastSentPos(); + Pkt.WriteBEDouble(LastSentPos.x); + Pkt.WriteBEDouble(LastSentPos.y + 0.001); // The "+ 0.001" is there because otherwise the player falls through the block they were standing on. + Pkt.WriteBEDouble(LastSentPos.z); Pkt.WriteByteAngle(a_Player.GetYaw()); Pkt.WriteByteAngle(a_Player.GetPitch()); WriteEntityMetadata(Pkt, a_Player); @@ -1359,9 +1360,10 @@ void cProtocol_1_9_0::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock Pkt.WriteBEUInt64(0); Pkt.WriteBEUInt64(a_FallingBlock.GetUniqueID()); Pkt.WriteBEUInt8(70); // Falling block - Pkt.WriteBEDouble(a_FallingBlock.GetPosX()); - Pkt.WriteBEDouble(a_FallingBlock.GetPosY()); - Pkt.WriteBEDouble(a_FallingBlock.GetPosZ()); + Vector3d LastSentPos = a_FallingBlock.GetLastSentPos(); + Pkt.WriteBEDouble(LastSentPos.x); + Pkt.WriteBEDouble(LastSentPos.y); + Pkt.WriteBEDouble(LastSentPos.z); Pkt.WriteByteAngle(a_FallingBlock.GetYaw()); Pkt.WriteByteAngle(a_FallingBlock.GetPitch()); Pkt.WriteBEInt32(static_cast<Int32>(a_FallingBlock.GetBlockType()) | (static_cast<Int32>(a_FallingBlock.GetBlockMeta()) << 12)); @@ -1384,9 +1386,10 @@ void cProtocol_1_9_0::SendSpawnMob(const cMonster & a_Mob) Pkt.WriteBEUInt64(0); Pkt.WriteBEUInt64(a_Mob.GetUniqueID()); Pkt.WriteBEUInt8(static_cast<Byte>(a_Mob.GetMobType())); - Pkt.WriteBEDouble(a_Mob.GetPosX()); - Pkt.WriteBEDouble(a_Mob.GetPosY()); - Pkt.WriteBEDouble(a_Mob.GetPosZ()); + Vector3d LastSentPos = a_Mob.GetLastSentPos(); + Pkt.WriteBEDouble(LastSentPos.x); + Pkt.WriteBEDouble(LastSentPos.y); + Pkt.WriteBEDouble(LastSentPos.z); Pkt.WriteByteAngle(a_Mob.GetPitch()); Pkt.WriteByteAngle(a_Mob.GetHeadYaw()); Pkt.WriteByteAngle(a_Mob.GetYaw()); @@ -1443,9 +1446,10 @@ void cProtocol_1_9_0::SendSpawnVehicle(const cEntity & a_Vehicle, char a_Vehicle Pkt.WriteBEUInt64(0); Pkt.WriteBEUInt64(a_Vehicle.GetUniqueID()); Pkt.WriteBEUInt8(static_cast<UInt8>(a_VehicleType)); - Pkt.WriteBEDouble(a_Vehicle.GetPosX()); - Pkt.WriteBEDouble(a_Vehicle.GetPosY()); - Pkt.WriteBEDouble(a_Vehicle.GetPosZ()); + Vector3d LastSentPos = a_Vehicle.GetLastSentPos(); + Pkt.WriteBEDouble(LastSentPos.x); + Pkt.WriteBEDouble(LastSentPos.y); + Pkt.WriteBEDouble(LastSentPos.z); Pkt.WriteByteAngle(a_Vehicle.GetPitch()); Pkt.WriteByteAngle(a_Vehicle.GetYaw()); Pkt.WriteBEInt32(a_VehicleSubType); diff --git a/src/Protocol/Protocol_1_9.h b/src/Protocol/Protocol_1_9.h index b4fdc7f67..3fbbe86da 100644 --- a/src/Protocol/Protocol_1_9.h +++ b/src/Protocol/Protocol_1_9.h @@ -35,8 +35,8 @@ Declares the 1.9 protocol classes: #pragma warning(pop) #endif -#include "PolarSSL++/AesCfb128Decryptor.h" -#include "PolarSSL++/AesCfb128Encryptor.h" +#include "mbedTLS++/AesCfb128Decryptor.h" +#include "mbedTLS++/AesCfb128Encryptor.h" |