From 7cd3f4d63f7c947c289ce5484db78a7e2d71ea10 Mon Sep 17 00:00:00 2001 From: "Jason_DiDonato@yahoo.com" Date: Wed, 24 Mar 2021 14:09:55 -0400 Subject: [PATCH] transforming payload of ResetSequence into flags, sequence, and remainder, along with a test decryption --- .../psforever/actors/net/MiddlewareActor.scala | 2 +- .../scala/net/psforever/packet/PSPacket.scala | 3 +++ .../net/psforever/packet/PacketCoding.scala | 16 +++++++++++----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/scala/net/psforever/actors/net/MiddlewareActor.scala b/src/main/scala/net/psforever/actors/net/MiddlewareActor.scala index 52346a9b..174c6de8 100644 --- a/src/main/scala/net/psforever/actors/net/MiddlewareActor.scala +++ b/src/main/scala/net/psforever/actors/net/MiddlewareActor.scala @@ -417,7 +417,7 @@ class MiddlewareActor( case Successful((packet, None)) => in(packet) case Failure(e) => - log.error(s"Could not decode packet: $e") + log.error(s"Could not decode $connectionId's packet: $e") } Behaviors.same diff --git a/src/main/scala/net/psforever/packet/PSPacket.scala b/src/main/scala/net/psforever/packet/PSPacket.scala index 36e116e0..acf2e4ae 100644 --- a/src/main/scala/net/psforever/packet/PSPacket.scala +++ b/src/main/scala/net/psforever/packet/PSPacket.scala @@ -39,6 +39,9 @@ trait PlanetSideCryptoPacket extends PlanetSidePacket { def opcode: CryptoPacketOpcode.Type } +/** PlanetSide ResetSequence packets: self-contained? */ +trait PlanetSideResetSequencePacket extends PlanetSidePacket { } + /** PlanetSide packet type. Used in more complicated packet headers * * ResetSequence - Not sure what this is used for or if the name matches what it actually does diff --git a/src/main/scala/net/psforever/packet/PacketCoding.scala b/src/main/scala/net/psforever/packet/PacketCoding.scala index dcb2536b..84d1d35e 100644 --- a/src/main/scala/net/psforever/packet/PacketCoding.scala +++ b/src/main/scala/net/psforever/packet/PacketCoding.scala @@ -174,10 +174,12 @@ object PacketCoding { } case PacketType.Crypto => if (flags.secured && crypto.isEmpty) { - return Failure(Err("Unsupported packet type: crypto packets must be unencrypted")) + return Failure(Err("Unsupported packet type: secured crypto packets must be unencrypted")) } case PacketType.ResetSequence => - return Failure(Err(s"Caught a wild ResetSequence when cryptoState is ${crypto.nonEmpty}: $msg -> $flags and $remainder")) + if (!flags.secured || crypto.isEmpty) { + return Failure(Err("Unsupported packet type: reset sequence packets must be encrypted")) + } case _ => return Failure(Err(s"Unsupported packet type: ${flags.packetType.toString}")) } @@ -187,7 +189,7 @@ object PacketCoding { case Successful(DecodeResult(value, _remainder)) => (value, _remainder.toByteVector) case Failure(e) => - return Failure(Err(s"Failed to parse packet sequence number: ${e.message}")) + return Failure(Err(s"Failed to parse ${flags.packetType} packet sequence number: ${e.message}")) } (flags.packetType, crypto) match { @@ -201,9 +203,13 @@ object PacketCoding { case (PacketType.Normal, None) if !flags.secured => decodePacket(payload).map(p => (p, sequence)) case (PacketType.Normal, None) => - Failure(Err(s"Cannot unmarshal encrypted packet without CryptoCoding")) + Failure(Err("Cannot unmarshal encrypted packet without a cipher")) + case (PacketType.ResetSequence, Some(_crypto)) => + val test = _crypto.decrypt(payload.drop(1)) + Failure(Err(s"ResetSequence not completely supported, but: $flags, $sequence, and $payload; decrypt: $test")) + case (ptype, _) => + Failure(Err(s"Cannot unmarshal $ptype packet at all")) } - } /**