Example #1
0
        private bool EncryptionRegisterFromWire(Peer toPassTo, PacketBase packet)
        {
            EncryptionRequest eq = packet as EncryptionRequest;

            if (eq == null)
            {
                ClassLogger.LogError("Recieved encryption request with null packet.");
                return(false);
            }

            if (!EncryptionFactory.ContainsKey(eq.EncryptionByteType))
            {
                ClassLogger.LogError("Failed to establish encryption from Peer ID: "
                                     + toPassTo.UniqueConnectionId + " with EncryptionByte: " + eq.EncryptionByteType);
                return(false);
            }

            EncryptionBase newEncryptionObj = EncryptionFactory[eq.EncryptionByteType]();

            toPassTo.EncryptionRegister.Register(newEncryptionObj, eq.EncryptionByteType);

            bool result = toPassTo.EncryptionRegister[eq.EncryptionByteType]
                          .SetNetworkInitRequiredData(eq.EncryptionInitInfo);

            if (result)
            {
                EncryptionRequest encryptionResponse =
                    new EncryptionRequest(eq.EncryptionByteType, newEncryptionObj.NetworkInitRequiredData());

                toPassTo.SendMessage(Packet.OperationType.Response, encryptionResponse, (byte)InternalPacketCode.EncryptionRequest,
                                     Packet.DeliveryMethod.ReliableUnordered, 0, 0, true);
            }

            return(false);
        }
Example #2
0
 private bool DecryptIncomingPacket(IEncryptable packet, EncryptionBase decrypter)
 {
     if (packet.isEncrypted)
     {
         if (decrypter.EncryptionTypeByte == packet.EncryptionMethodByte)
         {
             return(packet.Decrypt(decrypter));
         }
         else
         {
             throw new LoggableException("Failed to decrypt byte[] blob due to decryptor object being of byte: " + decrypter.EncryptionTypeByte.ToString() +
                                         " and lidgren packet encryption byte being: " + packet.EncryptionMethodByte, null, LogType.Error);
         }
     }
     else
     {
         return(false);
     }
 }
Example #3
0
        public virtual void Encrypt(EncryptionBase encryptionObject)
        {
            if (InternalByteRepresentation != null)
            {
                //Sets the encryption method used via  byte so remote recievers will know how to handle the
                //encrypted byte[]
                this.EncryptionMethodByte = encryptionObject.EncryptionTypeByte;

                try
                {
                    this.InternalByteRepresentation = encryptionObject.Encrypt(InternalByteRepresentation,
                                                                               out _EncryptionAdditionalBlob);
                }
                catch (CryptographicException e)
                {
                    throw new LoggableException("Failed to encrypt LidgrenPacket: " + this.ToString(), e, LogType.Error);
                }
            }
        }
Example #4
0
        public virtual bool Decrypt(EncryptionBase encryptionObject)
        {
            if (InternalByteRepresentation != null && EncryptionMethodByte != EncryptionBase.NoEncryptionByte)
            {
                try
                {
                    this.InternalByteRepresentation = encryptionObject.Decrypt(InternalByteRepresentation,
                                                                               _EncryptionAdditionalBlob);

                    decrypted = true;

                    return(this.InternalByteRepresentation != null);
                }
                catch (CryptographicException e)
                {
                    throw new LoggableException("Failed to decrypt LidgrenPacket: " + this.ToString(), e, LogType.Error);
                }
            }
            else
            {
                return(false);
            }
        }
Example #5
0
 NetworkPackage IConverter <IEncryptablePackage, SerializerBase, EncryptionBase, NetworkPackage> .Convert(IEncryptablePackage obj1, SerializerBase obj2, EncryptionBase obj3)
 {
     return(this.Convert <NetworkPackage>(obj1, obj2, obj3));
 }
Example #6
0
        public NetworkPackageType Convert <NetworkPackageType>(IEncryptablePackage package, SerializerBase serializer, EncryptionBase decryptor)
            where NetworkPackageType : NetworkPackage, new()
        {
            if (decryptor != null)
            {
                this.DecryptIncomingPacket(package, decryptor);
            }

            NetworkPackageType dispatchPackage = GenerateFromPacket <NetworkPackageType>(package, serializer);

            return(dispatchPackage);
        }
Example #7
0
        //(No longer internal due to Unity3D Requirements) This is internal because we don't want child classes having access to it but we need some derived classes to have access.
        protected PackageType GeneratePackage <PackageType>(IEncryptablePackage packet, EncryptionBase decrypter)
            where PackageType : NetworkPackage, new()
        {
            if (SerializerRegister.GetValue(packet.SerializerKey) == null)
            {
                throw new LoggableException("Packet serializer not found with get.", null, LogType.Error);
            }

            return(Converter.Convert <PackageType>(packet, SerializerRegister[packet.SerializerKey], decrypter));
        }