public void DecryptedPacketToByteBufferCheck() { bool isValid; DaedalusGlobal.ReturnCodes returnCode; int packetStart; int packetLength; DecryptedDaedalusPacket packet; // <STX><packetLength><packetIndex><cmd><cmdVer> <cmdLen> <cmdPay><hash> <act> <ETX> <CRC> <EOT> // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 byte[] testPacket = { 0x02, 0x1C, 0x00, 0x01, 0x00, 0x20, 0x01, 0x15, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x3A, 0x1f, 0x04 }; isValid = DecryptedDaedalusPacket.IsValidPacket(testPacket, out returnCode, out packetStart, out packetLength); Assert.AreEqual(isValid, true); Assert.AreEqual(returnCode, DaedalusGlobal.ReturnCodes.Valid); packet = new DecryptedDaedalusPacket(testPacket, 0, testPacket.Length, out returnCode); Assert.AreEqual(returnCode, DaedalusGlobal.ReturnCodes.Valid); Assert.IsNotNull(packet); Assert.IsTrue(packet.getTotalPacketLength() == testPacket.Length); Assert.IsTrue(packet.payload.Count == 2); Assert.IsTrue(packet.payload.ContainsKey("hash")); Assert.IsTrue(packet.payload.ContainsKey("actionTaken")); byte[] bufferBackOut = packet.toByteBuffer(); Assert.IsTrue(bufferBackOut.SequenceEqual(testPacket)); }
internal EncryptedDaedalusPacket(DecryptedDaedalusPacket inPacket, string AESKey) { encryptionKey = AESKey; // Not at all like that //// The decrypted packet's entire size is the payload of the encrypted packet, so the <encryptedPacketLength> is that + size of ETX //encryptedPacketLength = inPacket.getTotalPacketLength() + elementETX.ElementSize; // Copy the decrypted packet into the local byte buffer decryptedPayload = new byte[inPacket.getTotalPacketLength()]; Array.Copy(inPacket.toByteBuffer(), decryptedPayload, inPacket.getTotalPacketLength()); // Force accessor to perform encryption operation and synch payloads //byte[] temp = encryptedPayload; // Packet length field is payload length plus length of ETX encryptedPacketLengthFieldValue = encryptedPayload.Length + elementETX.ElementSize; }
public DaedalusGlobal.ReturnCodes processAction(DecryptedDaedalusPacket packet, frmMain mainForm, IPEndPoint source) { // So this isn't exactly ideal, but I didn't want to write custom mutators for each control. // So sue me. mainForm.BeginInvoke((Action)(() => mainForm.lstTraffic.Items.Add( packet.packetIndex + ":" + source.ToString() + ": " + BitConverter.ToString(packet.toByteBuffer()) ))); return(DaedalusGlobal.ReturnCodes.Valid); }