Exemplo n.º 1
0
        public SafeResponse Post_CardVirtual([FromBody] SafeData safeData)
        {
            try {
                Review_HttpRequest(Request);
                Decrypt_Data(ref apiRequest, ref safeData);

                Tool.ValidatePhoneNumber(apiRequest.Phone_No);
                apiRequest.Exp_Date  = Tool.ValidateExpirationDate(apiRequest.Exp_Date);
                apiRequest.Informing = apiRequest.Informing.ToUpper();
                Tool.Validate_Status(apiRequest.Informing, "Informing");

                VirtualCard vcard = new VirtualCard(ref apiRequest);

                VirtualCardOut data = DA.Create_VirtualCard(ref apiRequest, ref vcard);

                SafeData sd = Encrypt_Data(data);
                apiResponse = new SafeResponse(sd, CodeStatus.Ok);
            } catch (ApiException ae) {
                apiResponse.Status = ae.Status;
                Print(ae, Tool.GetCurrentMethod());
            } catch (Exception e) {
                apiResponse.Status = new ResponseStatus(CodeStatus.Unhandled_Exception);
                Print(e, Tool.GetCurrentMethod(), false);
            } finally {
                Task.Run(() => Save_Response());
                chainLogger.Finish(apiResponse.Status.Detail);
            }

            return(apiResponse);
        }
Exemplo n.º 2
0
        public SafeResponse Get_TopTransactions([FromBody] SafeData safeData)
        {
            try {
                Review_HttpRequest(Request);
                Decrypt_Data(ref apiRequest, ref safeData);

                if ((apiRequest.Top < 1) || ((apiRequest.Top > 99)))
                {
                    throw new ApiException("Invalid Top number. Must be from 1 to 99");
                }

                using (AutoDisposeList <Transaction> data = DA.Get_Transactions(ref apiRequest).Transactions) {
                    chainLogger.Database_Request();
                    using (SafeData sd = Encrypt_Data(data)) {
                        apiResponse = new SafeResponse(sd, CodeStatus.Ok);
                    }
                }
            } catch (ApiException ae) {
                apiResponse.Status = ae.Status;
                Print(ae, Tool.GetCurrentMethod());
            } catch (Exception e) {
                apiResponse.Status = new ResponseStatus(CodeStatus.Unhandled_Exception);
                Print(e, Tool.GetCurrentMethod());
            } finally {
                chainLogger.Finish(apiResponse.Status.Detail);
            }

            return(apiResponse);
        }
Exemplo n.º 3
0
        public SafeResponse Check([FromBody] SimpleData simpleData)
        {
            try {
                DA.Check();

                if ((simpleData != null) && (!string.IsNullOrEmpty(simpleData.Data)))
                {
                    apiUser = new ApiUser()
                    {
                        User_ID   = 0,
                        PublicKey = string.IsNullOrEmpty(simpleData.PublicKey) ? Globals.key_public : simpleData.PublicKey
                    };
                    using (SafeData sd = Encrypt_Data(simpleData.Data)) {
                        apiResponse = new SafeResponse(sd, CodeStatus.Ok);
                    }
                }
                else
                {
                    apiResponse = new SafeResponse(CodeStatus.Ok);
                }
            } catch (ApiException ae) {
                apiResponse.Status = ae.Status;
                Print(ae, Tool.GetCurrentMethod());
                HttpContext.Response.StatusCode = 204; // No content - no connection to DataBase
            } catch (Exception e) {
                apiResponse.Status = new ResponseStatus(CodeStatus.Unhandled_Exception);
                Print(e, Tool.GetCurrentMethod());
                HttpContext.Response.StatusCode = 418; // I'm teapot
            }

            return(apiResponse);
        }
Exemplo n.º 4
0
        internal void Decrypt_Data <ED>(ref ED encrytedData, ref SafeData safeData) where ED : IRequest
        {
            string desDecrypted = string.Empty;

            using (RSAHelper rsa = new RSAHelper(RSAType.RSA2, Encoding.UTF8, Globals.key_private, Globals.key_public)) {
                desDecrypted = rsa.Decrypt(safeData.Des);
            }

            using (RSAHelper rsa_partner = new RSAHelper(RSAType.RSA2, Encoding.UTF8, Globals.key_private, apiUser.PublicKey)) {
                if (rsa_partner.Verify(desDecrypted, safeData.Signature) == false)
                {
                    throw new ApiException(CodeStatus.Signature_Not_Valid);
                }
            }

            using (DESParameters desParameters = JsonConvert.DeserializeObject <DESParameters>(desDecrypted)) {
                TripleDESHelper des     = new TripleDESHelper(desParameters);
                string          message = des.Decrypt(safeData.Data);
                encrytedData    = JsonConvert.DeserializeObject <ED>(message);
                request.User_ID = apiUser.User_ID;
                encrytedData.SetBase(request);
            }

            chainLogger.Step(Tool.GetCurrentMethod());
            Access_Authorization();
            Save_Request();
        }
Exemplo n.º 5
0
        public void WriteAndReadSafeData()
        {
            var cut = new XmlFormatter <SafeData>();

            const string Secret = "S*ecret";

            var data = new SafeData
            {
                Password = Secret
            };

            var stream = new MemoryStream();

            cut.Serialize(data, stream);

            stream.Position = 0;

            var read = cut.Deserialize(stream);

            stream.Position = 0;
            using (var reader = new StreamReader(stream))
            {
                var text = reader.ReadToEnd();
                Assert.IsTrue(!text.Contains(Secret), "serialization contains secret");
            }

            Assert.AreEqual(data.Password, read.Password);
        }
Exemplo n.º 6
0
        internal SafeData Encrypt_Data <DD>(DD decryted_data) where DD : class
        {
            TripleDESHelper des = new TripleDESHelper();

            using (RSAHelper rsa_partner = new RSAHelper(RSAType.RSA2, Encoding.UTF8, Globals.key_private, apiUser.PublicKey)) {
                response = JsonConvert.SerializeObject(decryted_data);
#if DEBUG
                Console.Out.WriteLine(response);
#endif
                string encryptedStr = des.Encrypt(response);

                string desPrms      = des.GetParameters();
                string desEncrypted = rsa_partner.Encrypt(desPrms);
                string signStr      = rsa_partner.Sign(desPrms);
                bool   signVerify   = false;

                using (RSAHelper rsa = new RSAHelper(RSAType.RSA2, Encoding.UTF8, Globals.key_private, Globals.key_public)) {
                    signVerify = rsa.Verify(desPrms, signStr);
                }

                using (SafeData sd = new SafeData()) {
                    sd.Data      = encryptedStr;
                    sd.Signature = signStr;
                    sd.Des       = desEncrypted;

                    chainLogger.Step(Tool.GetCurrentMethod());
                    return(sd);
                }
            }
        }
Exemplo n.º 7
0
        public SafeResponse Post_CardBlock([FromBody] SafeData safeData)
        {
            try {
                Review_HttpRequest(Request);
                Decrypt_Data(ref apiRequest, ref safeData);
                apiRequest.Validate_Status();

                bool data = false;
                if (apiRequest.Status == "ON")
                {
                    data = DA.Block_Card(ref apiRequest);
                }
                else
                {
                    data = DA.UnBlock_Card(ref apiRequest);
                }

                apiResponse = new SafeResponse((data == true) ? CodeStatus.Ok : CodeStatus.Warning);
            } catch (ApiException ae) {
                apiResponse.Status = ae.Status;
                Print(ae, Tool.GetCurrentMethod());
            } catch (Exception e) {
                apiResponse.Status = new ResponseStatus(CodeStatus.Unhandled_Exception);
                Print(e, Tool.GetCurrentMethod());
            } finally {
                Task.Run(() => Save_Response());
                chainLogger.Finish(apiResponse.Status.Detail);
            }

            return(apiResponse);
        }
Exemplo n.º 8
0
        public SafeResponse Post_VirtualAuth([FromBody] SafeData safeData)
        {
            try {
                throw new ApiException(CodeStatus.Not_Allowed_Method);
            } catch (ApiException ae) {
                apiResponse.Status = ae.Status;
                Print(ae, Tool.GetCurrentMethod());
            } catch (Exception e) {
                apiResponse.Status = new ResponseStatus(CodeStatus.Unhandled_Exception);
                Print(e, Tool.GetCurrentMethod());
            } finally {
                chainLogger.Finish(apiResponse.Status.Detail);
            }

            return(apiResponse);
        }
Exemplo n.º 9
0
        public SafeResponse Card_DetailInform([FromBody] SafeData safeData)
        {
            try {
                Review_HttpRequest(Request);
                Decrypt_Data(ref apiRequest, ref safeData);
                bool data = DA.CardDetail_Inform(ref apiRequest);

                apiResponse = new SafeResponse((data == true) ? CodeStatus.Ok : CodeStatus.Warning);
            } catch (ApiException ae) {
                apiResponse.Status = ae.Status;
                Print(ae, Tool.GetCurrentMethod());
            } catch (Exception e) {
                apiResponse.Status = new ResponseStatus(CodeStatus.Unhandled_Exception);
                Print(e, Tool.GetCurrentMethod());
            } finally {
                chainLogger.Finish(apiResponse.Status.Detail);
            }

            return(apiResponse);
        }
Exemplo n.º 10
0
        public SafeResponse Card_Cvc2([FromBody] SafeData safeData)
        {
            try {
                Review_HttpRequest(Request);
                Decrypt_Data(ref apiRequest, ref safeData);

                CardCvc2 data = DA.Get_CardCVC2(ref apiRequest);

                SafeData sd = Encrypt_Data(data);

                apiResponse = new SafeResponse(sd, (data.Cvc2.Length == 3) ? CodeStatus.Ok : CodeStatus.Warning);
            } catch (ApiException ae) {
                apiResponse.Status = ae.Status;
                Print(ae, Tool.GetCurrentMethod());
            } catch (Exception e) {
                apiResponse.Status = new ResponseStatus(CodeStatus.Unhandled_Exception);
                Print(e, Tool.GetCurrentMethod());
            } finally {
                chainLogger.Finish(apiResponse.Status.Detail);
            }

            return(apiResponse);
        }
Exemplo n.º 11
0
        public SafeResponse Post_CardPinCountReset([FromBody] SafeData safeData)
        {
            try {
                Review_HttpRequest(Request);
                Decrypt_Data(ref apiRequest, ref safeData);

                bool data = DA.Reset_Pin_Counter(ref apiRequest);
                chainLogger.Database_Request();

                apiResponse = new SafeResponse((data == true) ? CodeStatus.Ok : CodeStatus.Warning);
            } catch (ApiException ae) {
                apiResponse.Status = ae.Status;
                Print(ae, Tool.GetCurrentMethod());
            } catch (Exception e) {
                apiResponse.Status = new ResponseStatus(CodeStatus.Unhandled_Exception);
                Print(e, Tool.GetCurrentMethod());
            } finally {
                Task.Run(() => Save_Response());
                chainLogger.Finish(apiResponse.Status.Detail);
            }

            return(apiResponse);
        }
Exemplo n.º 12
0
        public void WriteAndReadSafeDataDifferentFormatters()
        {
            const string EncryptionKey = "SuperSecretKey";

            var cut = new XmlFormatter <SafeData>(EncryptionKey);

            const string Secret = "S*ecret";

            var data = new SafeData
            {
                Password = Secret
            };

            var stream = new MemoryStream();

            new XmlFormatter <SafeData>(EncryptionKey).Serialize(data, stream);

            stream.Position = 0;

            var read = cut.Deserialize(stream);

            Assert.AreEqual(data.Password, read.Password);
        }
Exemplo n.º 13
0
        public SafeResponse Post_Response([FromBody] SafeData safeData)
        {
            try {
                Review_HttpRequest(Request);
                Decrypt_Data(ref apiRequest, ref safeData);

                PartnerResponse data = DA.Read_Partner_Response(ref apiRequest);

                SafeData sd = Encrypt_Data(data);

                apiResponse = new SafeResponse(sd, CodeStatus.Ok);
            } catch (ApiException ae) {
                apiResponse.Status = ae.Status;
                Print(ae, Tool.GetCurrentMethod());
            } catch (Exception e) {
                apiResponse.Status = new ResponseStatus(CodeStatus.Unhandled_Exception);
                Print(e, Tool.GetCurrentMethod());
            } finally {
                chainLogger.Finish(apiResponse.Status.Detail);
            }

            return(apiResponse);
        }
Exemplo n.º 14
0
        public SafeResponse Get_AbsTransactions([FromBody] SafeData safeData)
        {
            try {
                Review_HttpRequest(Request);
                Decrypt_Data(ref apiRequest, ref safeData);

                using (AutoDisposeList <Abs_Transaction> data = DA.Get_AbsTransactions(ref apiRequest)) {
                    chainLogger.Database_Request();
                    using (SafeData sd = Encrypt_Data(data)) {
                        apiResponse = new SafeResponse(sd, CodeStatus.Ok);
                    }
                }
            } catch (ApiException ae) {
                apiResponse.Status = ae.Status;
                Print(ae, Tool.GetCurrentMethod());
            } catch (Exception e) {
                apiResponse.Status = new ResponseStatus(CodeStatus.Unhandled_Exception);
                Print(e, Tool.GetCurrentMethod());
            } finally {
                chainLogger.Finish(apiResponse.Status.Detail);
            }

            return(apiResponse);
        }
Exemplo n.º 15
0
        public ItemsForm(InventoryData inventoryData, SafeData safeData, ShopData shopData, WeaponsData weaponsData)
        {
            InitializeComponent();

            GuidStoplist = new List <Guid>();

            InventoryData = inventoryData;
            SafeData      = safeData;
            ShopData      = shopData;
            WeaponsData   = weaponsData;

            var dsInventory = GetInventoryDataSource();
            var dsWeapons   = GetWeaponsDataSource();
            var dsSafe      = GetSafeDataSource();
            var dsShop      = GetShopDataSource();

            if (InventoryData != null)
            {
                foreach (var item in InventoryData.Items)
                {
                    dgvInventory.Rows.Add(
                        item.Slot,
                        item.Descriptor,
                        item.Quantity);
                }
            }

            if (WeaponsData != null)
            {
                for (int i = 0; i < 4; i++)
                {
                    var item = WeaponsData.Items.FirstOrDefault(it => it.Slot == i);
                    dgvWeapons.Rows.Add(
                        i,
                        item?.Descriptor ?? ItemDescriptor.Empty,
                        item?.Quantity ?? 0);
                }
            }

            if (SafeData != null)
            {
                foreach (var item in SafeData.Items)
                {
                    dgvSafe.Rows.Add(
                        item.Slot,
                        item.Descriptor,
                        item.Quantity);
                }
            }

            if (ShopData != null)
            {
                foreach (var item in ShopData.Items)
                {
                    dgvShop.Rows.Add(item.Descriptor);
                }
            }

            colInventoryName.DisplayMember = "Value";
            colInventoryName.ValueMember   = "Key";
            colInventoryName.DataSource    = new BindingSource(dsInventory, null);

            colWeaponsName.DisplayMember = "Value";
            colWeaponsName.ValueMember   = "Key";
            colWeaponsName.DataSource    = new BindingSource(dsWeapons.OrderBy(d => d.Value), null);

            colSafeName.DisplayMember = "Value";
            colSafeName.ValueMember   = "Key";
            colSafeName.DataSource    = new BindingSource(dsSafe, null);

            colShopName.DisplayMember = "Value";
            colShopName.ValueMember   = "Key";
            colShopName.DataSource    = new BindingSource(dsShop, null);
        }
Exemplo n.º 16
0
        private void ApplyNewValues()
        {
            if (cbInfiniteStasis.Checked)
            {
                MiscData.Stasis = float.MaxValue;
            }
            MiscData.Flags[(byte)Flags.InfiniteAmmo] = cbInfiniteAmmo.Checked ? (byte)1 : (byte)0;
            MiscData.Nodes           = (uint)nudNodes.Value;
            MiscData.ActiveSuit      = (ItemDescriptor)cbActiveSuit.SelectedValue;
            NewInventoryData.Credits = (uint)nudCredits.Value;

            NewInventoryData.WriteData(DataStream);
            NewWeaponsData.WriteData(DataStream);
            NewSafeData.WriteData(DataStream);
            NewShopData.WriteData(DataStream);
            MiscData.WriteData(DataStream);

            #region Fix size bytes
            var origSize = (uint)(OriginalInventoryData.GetDataSize() + OriginalSafeData.GetDataSize() + OriginalShopData.GetDataSize() + OriginalWeaponsData.GetDataSize());
            var newSize  = (uint)(NewInventoryData.GetDataSize() + NewSafeData.GetDataSize() + NewShopData.GetDataSize() + NewWeaponsData.GetDataSize());

            DataStream.Seek(0x28BC, SeekOrigin.Begin);
            var totalDataChunkSize = DataStream.ReadUInt32();

            var itemsBlockPos = DataStream.SearchForBytePattern(MagicStuff.ItemBlockMagic) + MagicStuff.ItemBlockMagic.Length;
            DataStream.Seek(itemsBlockPos, SeekOrigin.Begin);
            var itemsBlockSize = DataStream.ReadUInt32();

            // 1st size to fix
            DataStream.Seek(0x28BC, SeekOrigin.Begin);
            DataStream.WriteUInt32(totalDataChunkSize - origSize + newSize);

            // 2nd size to fix
            DataStream.Seek(itemsBlockPos, SeekOrigin.Begin);
            DataStream.WriteUInt32(itemsBlockSize - origSize + newSize);
            #endregion

            OriginalInventoryData = new InventoryData
            {
                Unk1    = NewInventoryData.Unk1,
                Credits = NewInventoryData.Credits,
                Items   = NewInventoryData.Items
            };
            OriginalSafeData = new SafeData
            {
                SafeCapacity = NewSafeData.SafeCapacity,
                Unk1         = NewSafeData.Unk1,
                Items        = NewSafeData.Items
            };
            OriginalShopData = new ShopData
            {
                Unk1  = NewShopData.Unk1,
                Items = NewShopData.Items
            };
            OriginalWeaponsData = new WeaponsData
            {
                ActiveSlots = NewWeaponsData.ActiveSlots,
                Unk1        = NewWeaponsData.Unk1,
                Items       = NewWeaponsData.Items
            };
        }
Exemplo n.º 17
0
        private void LoadFileData()
        {
            Cursor = Cursors.WaitCursor;

            Metadata              = null;
            DataStream            = null;
            MC02Header            = null;
            OriginalInventoryData = null;
            NewInventoryData      = null;
            OriginalSafeData      = null;
            NewSafeData           = null;
            OriginalShopData      = null;
            NewShopData           = null;
            OriginalWeaponsData   = null;
            NewWeaponsData        = null;
            MiscData              = null;

            try
            {
                using (var fs = File.OpenRead(SaveFilePath))
                {
                    DataStream = new MemoryStream();
                    fs.CopyTo(DataStream);
                }

                if (!ValidateSaveFile())
                {
                    return;
                }

                DataStream.Seek(0x2034, SeekOrigin.Begin);
                var meta  = DataStream.ReadUnicodeString();
                var re    = new Regex(@"^\D*(\d{1,2})\D*(\d{1,2})\D*(\d{1,2})\D*(\d{1,2})\D*(\d{1,2})\D*(\d{1,2})\D*(\d{1,2})\D*$");
                var match = re.Match(meta);
                if (match.Success)
                {
                    Metadata = new FileMetadata
                    {
                        Slot          = match.Groups[1].Value,
                        HoursPlayed   = match.Groups[2].Value,
                        MinutesPlayed = match.Groups[3].Value,
                        SecondsPlayed = match.Groups[4].Value,
                        Difficulty    = match.Groups[5].Value,
                        Chapter       = match.Groups[6].Value,
                        Round         = match.Groups[7].Value
                    };
                }

                OriginalInventoryData = new InventoryData(DataStream);
                NewInventoryData      = new InventoryData
                {
                    Unk1    = OriginalInventoryData.Unk1,
                    Credits = OriginalInventoryData.Credits,
                    Items   = new List <InventoryEntity>(OriginalInventoryData.Items)
                };
                OriginalSafeData = new SafeData(DataStream);
                NewSafeData      = new SafeData
                {
                    SafeCapacity = OriginalSafeData.SafeCapacity,
                    Unk1         = OriginalSafeData.Unk1,
                    Items        = new List <SafeEntity>(OriginalSafeData.Items)
                };
                OriginalShopData = new ShopData(DataStream);
                NewShopData      = new ShopData
                {
                    Unk1  = OriginalShopData.Unk1,
                    Items = new List <ShopEntity>(OriginalShopData.Items)
                };
                OriginalWeaponsData = new WeaponsData(DataStream);
                NewWeaponsData      = new WeaponsData
                {
                    ActiveSlots = OriginalWeaponsData.ActiveSlots,
                    Unk1        = OriginalWeaponsData.Unk1,
                    Items       = new List <WeaponEntity>(OriginalWeaponsData.Items)
                };
                MiscData = new MiscData(DataStream);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Sorry, an error occurred while reading from file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }