Ejemplo n.º 1
0
        private bool VerifyEncryptedCRC(CryptoSystem fq, out string keyOffsetForLogging)
        {
            var verifiedKey = new Tuple <int, uint>(0, 0);

            uint receivedKey = (Header.Checksum - headerChecksum) ^ payloadChecksum;

            Func <Tuple <int, uint>, bool> cbSearch = new Func <Tuple <int, uint>, bool>((pair) =>
            {
                if (receivedKey == pair.Item2)
                {
                    verifiedKey = pair;
                    return(true);
                }

                return(false);
            });

            if (fq.Search(cbSearch))
            {
                keyOffsetForLogging = verifiedKey.Item1.ToString();
                return(true);
            }

            keyOffsetForLogging = "???";
            return(false);
        }
Ejemplo n.º 2
0
        public bool VerifyCRC(CryptoSystem fq)
        {
            if (Header.HasFlag(PacketHeaderFlags.EncryptedChecksum))
            {
                var key = ((Header.Checksum - headerChecksum) ^ payloadChecksum);
                if (fq.Search(key))
                {
                    fq.ConsumeKey(key);
                    return(true);
                }
            }
            else
            {
                if (headerChecksum + payloadChecksum == Header.Checksum)
                {
                    packetLog.DebugFormat("{0}", this);
                    return(true);
                }

                packetLog.DebugFormat("{0}, Checksum Failed", this);
            }

            NetworkStatistics.C2S_CRCErrors_Aggregate_Increment();

            return(false);
        }
Ejemplo n.º 3
0
        public static bool readMaterialsFromSAP(out List <Material> mats)
        {
            mats = new List <Material>();
            var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);

            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            binding.MaxReceivedMessageSize = 5000000;

            var address = new EndpointAddress(CommonData.webServiceEndPoint);

            ZStandalonePackingClient  client = new ZStandalonePackingClient(binding, address);
            ZGetFinishedGoodMaterials toSAP  = new ZGetFinishedGoodMaterials();

            toSAP.Device = CommonData.sapSettings.device;

            client.ClientCredentials.UserName.UserName = CommonData.sapSettings.user;
            client.ClientCredentials.UserName.Password = CryptoSystem.Decrypt(CommonData.sapSettings.password);
            ZGetFinishedGoodMaterialsResponse fromSAP;

            try
            {
                fromSAP = client.ZGetFinishedGoodMaterials(toSAP);
            }
            catch (CommunicationException ex)
            {
                MessageLogger.Add("Error reading materials from SAP", MessageLogger.MsgLevel.error);
                MessageLogger.Add(ex.ToString(), MessageLogger.MsgLevel.additional);
                return(false);
            }

            foreach (ZsapaFinGoodMat finGood in fromSAP.FinGoods)
            {
                Material newMat = new Material(finGood.MatNumber);
                newMat.description     = finGood.Description;
                newMat.labelLine1      = finGood.LabelLine1;
                newMat.labelLine2      = finGood.LabelLine2;
                newMat.labelLine3      = finGood.LabelLine3;
                newMat.labelLine4      = finGood.LabelLine4;
                newMat.maxWeight       = limitWeight(finGood.MaxWeight);
                newMat.minWeight       = limitWeight(finGood.MinWeight);
                newMat.nomWeight       = limitWeight(finGood.NomWeight);
                newMat.baseUom         = finGood.BaseUom;
                newMat.parallelUom     = finGood.ParallelUom;
                newMat.overdelPerc     = finGood.OverdelPerc;
                newMat.Ean             = finGood.Ean;
                newMat.labelFile       = finGood.LabelFile;
                newMat.shelfLife       = finGood.ShelfLife;
                newMat.madeToOrd       = finGood.MadeToOrd.Equals("X");
                newMat.fixedWeight     = finGood.FixedWeight.Equals("X");
                newMat.unlimOverdel    = finGood.UnlimOverdel.Equals("X");
                newMat.custMatNumber   = finGood.CustMatNum;
                newMat.oldMatNumber    = finGood.OldMatNum;
                newMat.targetMatNumber = finGood.TargetMatNum;
                newMat.woolGrp         = finGood.WoolGrp;

                mats.Add(newMat);
            }
            return(true);
        }
Ejemplo n.º 4
0
        private bool VerifyEncryptedCRCAndLogResult(CryptoSystem fq, bool rangeAdvance)
        {
            bool result = VerifyEncryptedCRC(fq, out string key, rangeAdvance);

            key = (key == "") ? $"" : $" Key: {key}";
            packetLog.Debug($"{fq} {this}{key}");
            return(result);
        }
Ejemplo n.º 5
0
        private bool VerifyEncryptedCRCAndLogResult(CryptoSystem fq)
        {
            bool result = VerifyEncryptedCRC(fq, out string key);

            key = (key == "") ? "" : $" Key: {key}";
            packetLog.DebugFormat("{0} {1}{2}", fq, this, key);

            return(result);
        }
Ejemplo n.º 6
0
        public static List <User> ReadUsersFromDB()
        {
            var users = new List <User>();

            DBOperations.OpenDBConnection();
            MySqlCommand cmd = DBOperations.myConn.CreateCommand();

            cmd.CommandText = "SELECT * FROM user";

            try
            {
                MySqlDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    var user = new User(rdr);
                    users.Add(user);
                }
                rdr.Close();
            }
            catch (MySqlException ex)
            {
                MessageLogger.Add("Error reading users from DB " + ex.ToString(), MessageLogger.MsgLevel.critical);
                return(null);
            }
            if (users.Count == 0)
            {
                var user = new User("001");
                user.name            = "Administrator";
                user.password        = CryptoSystem.Encrypt("12345");
                user.accessUserAdmin = true;
                users.Add(user);

                user                  = new User("002");
                user.name             = "Packer 1";
                user.password         = CryptoSystem.Encrypt("1234");
                user.accessPackCarton = true;
                users.Add(user);
            }
            return(users);
        }
Ejemplo n.º 7
0
        public SessionConnectionData()
        {
            // since the network processor is single threaded this can instantiate the .NET Core System.Random class without locking
            Random rand = new Random();

            // the client and server seeds determine where on the 32 bit wheel the stream cipher begins
            // by picking a random initialization vector it makes it more difficult for an adversary to forge packets
            ClientSeed = new byte[4];
            ServerSeed = new byte[4];

            rand.NextBytes(ClientSeed);
            rand.NextBytes(ServerSeed);

            CryptoClient = new CryptoSystem(ClientSeed);
            IssacServer  = new ISAAC(ServerSeed);

            byte[] bytes = new byte[8];
            rand.NextBytes(bytes);
            ConnectionCookie = BitConverter.ToUInt64(bytes, 0);

            PacketSequence = new UIntSequence(false);
        }
Ejemplo n.º 8
0
 public bool VerifyCRC(CryptoSystem fq, bool rangeAdvance)
 {
     if (Header.HasFlag(PacketHeaderFlags.EncryptedChecksum))
     {
         if (VerifyEncryptedCRCAndLogResult(fq, rangeAdvance))
         {
             CRCVerified = true;
             return(true);
         }
     }
     else
     {
         if (Header.HasFlag(PacketHeaderFlags.RequestRetransmit))
         {
             // discard retransmission request with cleartext CRC
             // client sends one encrypted version and one non encrypted version of each retransmission request
             // honoring these causes client to drop because it's only expecting one of the two retransmission requests to be honored
             // and it's more secure to only accept the trusted version
             return(false);
         }
         else
         {
             if (VerifyChecksum(0))
             {
                 packetLog.Debug($"{this}");
                 return(true);
             }
             else
             {
                 packetLog.Debug($"{this}, Checksum Failed");
             }
         }
     }
     NetworkStatistics.C2S_CRCErrors_Aggregate_Increment();
     return(false);
 }
Ejemplo n.º 9
0
        private bool VerifyEncryptedCRC(CryptoSystem fq, out string keyOffsetForLogging, bool rangeAdvance)
        {
            var verifiedKey = new Tuple <int, uint>(0, 0);
            Func <Tuple <int, uint>, bool> cbSearch = new Func <Tuple <int, uint>, bool>((pair) =>
            {
                if (VerifyChecksum(pair.Item2))
                {
                    verifiedKey = pair;
                    return(true);
                }
                else
                {
                    return(false);
                }
            });

            if (fq.Search(cbSearch, rangeAdvance))
            {
                keyOffsetForLogging = verifiedKey.Item1.ToString();
                return(true);
            }
            keyOffsetForLogging = "???";
            return(false);
        }
Ejemplo n.º 10
0
        public bool VerifyCRC(CryptoSystem fq)
        {
            if (Header.HasFlag(PacketHeaderFlags.EncryptedChecksum))
            {
                if (VerifyEncryptedCRCAndLogResult(fq))
                {
                    return(true);
                }
            }
            else
            {
                if (VerifyChecksum())
                {
                    packetLog.DebugFormat("{0}", this);
                    return(true);
                }

                packetLog.DebugFormat("{0}, Checksum Failed", this);
            }

            NetworkStatistics.C2S_CRCErrors_Aggregate_Increment();

            return(false);
        }
Ejemplo n.º 11
0
        public static bool SendPacks()
        {
            DBOperations.BeginTransaction();

            var packs = ReadUnsentPacks();

            if (packs.Count == 0)
            {
                DBOperations.CommitTransaction();
                return(true);  //Okay - no cartons need to be sent
            }

            var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);

            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            binding.MaxReceivedMessageSize = 1000000;
            var address = new EndpointAddress(CommonData.webServiceEndPoint);
            ZStandalonePackingClient client = new ZStandalonePackingClient(binding, address);

            var toSAP = new ZReceiptCartons();

            toSAP.Cartons = new ZsapaCarton[packs.Count];

            int i = 0;

            foreach (var p in packs)
            {
                toSAP.Cartons[i] = new ZsapaCarton();

                toSAP.Cartons[i].Serial         = p.serial.ToString();
                toSAP.Cartons[i].MaterialNum    = p.materialNum;
                toSAP.Cartons[i].Batch          = p.batch;
                toSAP.Cartons[i].OrderNum       = p.orderNum;
                toSAP.Cartons[i].Plant          = p.plant;
                toSAP.Cartons[i].StorageLctn    = p.storage_lctn;
                toSAP.Cartons[i].PackedQty      = p.qty;
                toSAP.Cartons[i].PackedUom      = p.uom;
                toSAP.Cartons[i].Weight         = p.netWeight;
                toSAP.Cartons[i].PlannedWeight  = p.plannedWeight;
                toSAP.Cartons[i].ActualWeight   = p.actualWeight;
                toSAP.Cartons[i].TareWeight     = p.tareWeight;
                toSAP.Cartons[i].PackedOn       = p.packedOn.ToString("yyyy-MM-dd");
                toSAP.Cartons[i].PackedAt       = p.packedOn.ToString("HHmmss");
                toSAP.Cartons[i].ManuDate       = p.manuDate.ToString("yyyy-MM-dd");
                toSAP.Cartons[i].ExpiryDate     = p.expiryDate.ToString("yyyy-MM-dd");
                toSAP.Cartons[i].SlaughterDates = p.slaughterDates;
                toSAP.Cartons[i].Device         = p.terminal;
                toSAP.Cartons[i].UseFreezer     = p.useFreezer ? "X" : "";
                toSAP.Cartons[i].DgaUser        = p.user;
                toSAP.Cartons[i].GrReversal     = p.cancelled ? "X" : "";
                i++;
            }

            client.ClientCredentials.UserName.UserName = CommonData.sapSettings.user;
            client.ClientCredentials.UserName.Password = CryptoSystem.Decrypt(CommonData.sapSettings.password);

            ZReceiptCartonsResponse fromSAP;

            try
            {
                fromSAP = client.ZReceiptCartons(toSAP);
            }
            catch (Exception e)
            {
                MessageLogger.Add("Error sending packs to SAP " + e.ToString(), MessageLogger.MsgLevel.error);
                DBOperations.RollbackTransaction();
                return(false);
            }

            foreach (var c in fromSAP.ReturnMsgs)
            {
                MessageLogger.Add("Flagging carton " + c.Serial + " " + c.Msg, MessageLogger.MsgLevel.info);

                FlagAsSent(ulong.Parse(c.Serial), c.Msg);
            }
            DBOperations.CommitTransaction();
            return(true);
        }
Ejemplo n.º 12
0
        public static bool ReadOrdersFromSAP(out List <Order> normalOrders, out List <Order> reworkOrders, out List <Order.PackedOn> slDates)
        {
            normalOrders = new List <Order>();
            reworkOrders = new List <Order>();
            slDates      = new List <PackedOn>();

            var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);

            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            binding.MaxReceivedMessageSize = 1000000;

            var address = new EndpointAddress(CommonData.webServiceEndPoint);
            var client  = new ZStandalonePackingClient(binding, address);
            var toSAP   = new ZGetProductionOrders();

            toSAP.Device = CommonData.sapSettings.device;

            client.ClientCredentials.UserName.UserName = CommonData.sapSettings.user;
            client.ClientCredentials.UserName.Password = CryptoSystem.Decrypt(CommonData.sapSettings.password);
            ZGetProductionOrdersResponse fromSAP;

            try
            {
                fromSAP = client.ZGetProductionOrders(toSAP);
            }
            catch (CommunicationException ex)
            {
                MessageLogger.Add("Error reading orders from SAP", MessageLogger.MsgLevel.error);
                MessageLogger.Add(ex.ToString(), MessageLogger.MsgLevel.additional);
                return(false);
            }
            string prevMatNumber = "~";

            Order normalOrder         = null;
            Order reworkOrder         = null;
            bool  missingMaterialData = false;

            foreach (ZsapaProdOrder sapOrd in fromSAP.Orders)
            {
                var  newIncOrd = new IncOrder(sapOrd);
                bool rework    = sapOrd.OrderType.Equals("YREW");

                if (!sapOrd.MaterialNum.Equals(prevMatNumber))
                {
                    normalOrder         = reworkOrder = null;
                    missingMaterialData = false;

                    var ord = new Order(newIncOrd);
                    if (ord.material == null)
                    {
                        missingMaterialData = true;
                        MessageLogger.Add("No master data for material " + ord.materialNum, MessageLogger.MsgLevel.warning);
                    }
                    else if (rework)
                    {
                        reworkOrder = ord;
                        reworkOrders.Add(ord);
                    }
                    else
                    {
                        normalOrder = ord;
                        normalOrders.Add(ord);
                    }
                }
                if (missingMaterialData)
                {
                    continue;
                }

                if (rework)
                {
                    if (reworkOrder == null)
                    {
                        reworkOrder = new Order(newIncOrd);
                        reworkOrders.Add(reworkOrder);
                    }
                    reworkOrder.AddIncOrder(newIncOrd);
                }
                else
                {
                    if (normalOrder == null)
                    {
                        normalOrder = new Order(newIncOrd);
                        normalOrders.Add(normalOrder);
                    }
                    normalOrder.AddIncOrder(newIncOrd);
                }
                prevMatNumber = sapOrd.MaterialNum;
            }
            foreach (var sl in fromSAP.ProdDates)
            {
                slDates.Add(new Order.PackedOn(sl));
            }
            return(true);
        }
Ejemplo n.º 13
0
 public void SetSeeds(uint recv, uint send)
 {
     Flags        |= ServerFlags.ChecksumSeeds;
     RecvGenerator = new CryptoSystem(recv);
     SendGenerator = new CryptoSystem(send);
 }
Ejemplo n.º 14
0
 public User(string _userId, string _userName, string _password)
 {
     userId   = _userId;
     name     = _userName;
     password = CryptoSystem.Encrypt(_password);
 }
Ejemplo n.º 15
0
 public bool CheckPassword(string passwordEntered)
 {
     return(password.Equals(CryptoSystem.Encrypt(passwordEntered)));
 }
Ejemplo n.º 16
0
 public bool UpdatePassword(string newPassword)
 {
     password = CryptoSystem.Encrypt(newPassword);
     return(UpdateOnDB());
 }