Пример #1
0
        public string GetClearPosPinBlock(string encryptedPinBlock)
        {
            string clearPosPinBlock = string.Empty;

            try
            {
                string sessionKeyName = System.Configuration.ConfigurationManager.AppSettings["SessionKeyName"];

                //the decryption key here is the zpk as it is
                string decryptionKey = LiteDAO.GetLocalKey(sessionKeyName);// PinConfigurationManager.HsmConfig.ZPK; //ThalesSim.Core.Utility.XORHexStringsFull(PinConfigurationManager.PosConfig.Tpk1, PinConfigurationManager.PosConfig.Tpk2);
                clearPosPinBlock = ThalesSim.Core.Cryptography.TripleDES.TripleDESDecrypt(new ThalesSim.Core.Cryptography.HexKey(decryptionKey.Substring(0, 32)), encryptedPinBlock);

                new PANE.ERRORLOG.Error().LogInfo("clear pinblock " + clearPosPinBlock);
                new PANE.ERRORLOG.Error().LogInfo("Configuration.PinConfigurationManager.PosConfig.Tpk1: " + PinConfigurationManager.PosConfig.Tpk1);
            }
            catch (Exception ex)
            {
                new PANE.ERRORLOG.Error().LogToFile(ex);
                Exception ex2 = new ApplicationException("Unable to Get Clear Pos PinBlock");
                throw ex2;
            }
            return(clearPosPinBlock);
        }
Пример #2
0
        public string DoCardActivation(PinIssuanceRequest request, Card theCard, string pinOffset, string oldCardPan)
        {
            string newPin         = PinReverse.GetPin(oldCardPan, pinOffset);
            string sessionKeyName = System.Configuration.ConfigurationManager.AppSettings["SessionKeyName"];
            string encryptionKey  = LiteDAO.GetLocalKey(sessionKeyName);

            request.Pin        = GetPinBlock(request.CardPAN, newPin, encryptionKey);
            request.ConfirmPin = request.Pin;

            string response = DoPinSelection(request, theCard);

            if (string.IsNullOrWhiteSpace(response))
            {
                return("1:Could not activate card");
            }
            if (response.StartsWith("true"))
            {
                return("0:Succesful Card Activation");
            }
            else
            {
                return(string.Format("1:{1}", response.Split('|')[1]));
            }
        }
Пример #3
0
        public string getCardDetails(string panComponent, string phone, out string expiry)
        {
            new PANE.ERRORLOG.Error().LogInfo("Inside get Card details");

            expiry = "";
            string clearPan = "";

            try
            {
                string staticKeyName = System.Configuration.ConfigurationManager.AppSettings["StaticKeyName"];
                string pageApiUrl    = Convert.ToString(ConfigurationManager.AppSettings["PageApiUrl"]);
                string relativePath  = "api/Flow?flowID=61f63e11-2885-409c-b0fc-6920f73b5774&awaitResponse=True&timeOut=30&isWeb=False&userName=3_31&ic=31&isClientFunc=False&hfService=4&FunctionID="; //Sterling

                //"api/Flow?flowID=61f63e11-2885-409c-b0fc-6920f73b5774&awaitResponse=True&timeOut=30&isWeb=False&userName=3_26&ic=26&isClientFunc=False&hfService=4&FunctionID=";
                //FBN
                //

                new PANE.ERRORLOG.Error().LogInfo(string.Format("{0}{1}", pageApiUrl, relativePath));

                Dictionary <string, object> result = null;

                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(pageApiUrl);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));


                    ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

                    IDictionary <string, object> requestData = new Dictionary <string, object>();

                    requestData.Add("PhoneNumber", phone);

                    requestData.Add("PanComponent", panComponent);

                    var response = client.PostAsJsonAsync(relativePath, requestData).Result;
                    if (response != null)
                    {
                        new PANE.ERRORLOG.Error().LogInfo(response.ToString());
                    }
                    if (response.IsSuccessStatusCode)
                    {
                        new PANE.ERRORLOG.Error().LogInfo("Response is successfull");
                        object obj;
                        object encryptedPanObj;
                        object expiryDateObj;
                        result = response.Content.ReadAsAsync <Dictionary <string, object> >().Result;


                        result.TryGetValue("CommandFields", out obj);

                        var data = JsonConvert.DeserializeObject <Dictionary <string, object> >(Convert.ToString(obj));
                        var sb   = new StringBuilder();
                        sb.Append(string.Format("{0}", Convert.ToString(obj)));
                        new PANE.ERRORLOG.Error().LogInfo(sb.ToString());
                        data.TryGetValue("EncryptedPan", out encryptedPanObj);
                        data.TryGetValue("ExpiryDate", out expiryDateObj);

                        if (encryptedPanObj != null && expiryDateObj != null)
                        {
                            new PANE.ERRORLOG.Error().LogInfo("EncryptedPan is not null");
                            var sb1 = new StringBuilder();
                            sb1.Append(string.Format("{0}", Convert.ToString(encryptedPanObj)));
                            var sb2 = new StringBuilder();
                            sb2.Append(string.Format("{0}", Convert.ToString(expiryDateObj)));
                            expiry = sb2.ToString();
                            string encryptedPan = sb1.ToString();
                            new PANE.ERRORLOG.Error().LogInfo("Encrypted Pan : " + encryptedPan + ", Expiry : " + expiry);
                            expiry = String.Format("{0}{1}", expiry.Split('/')[1], expiry.Split('/')[0]);
                            string panEncryptionKey = LiteDAO.GetLocalKey(staticKeyName);
                            clearPan = ThalesSim.Core.Cryptography.TripleDES.TripleDESDecrypt(new ThalesSim.Core.Cryptography.HexKey(panEncryptionKey.Substring(0, 32)), encryptedPan);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                new PANE.ERRORLOG.Error().LogToFile(ex);
            }

            return(clearPan);
        }
Пример #4
0
        public string IssuePin(string card, string phoneNumber)
        {
            bool     usePrimeHSM         = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UsePrimeHSM"]);
            string   theMessage          = "";
            string   response            = string.Empty;
            string   encryptionIndicator = string.Empty;
            IRequest pinRequest          = new USSDPinIssuanceRequest();

            try
            {
                new PANE.ERRORLOG.Error().LogInfo("PinController Web service entered...");
                new PANE.ERRORLOG.Error().LogInfo(string.Format("{0} - {1}", card, phoneNumber));
                if (string.IsNullOrWhiteSpace(card))
                {
                    return("1:Card value cannot be null");
                }
                if (string.IsNullOrWhiteSpace(phoneNumber))
                {
                    return("1:Phone cannot be null");
                }

                if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UseDefaultUSSDCardData"]))
                {
                    // theMessage = "C:cardpan=5334771222311096,expiryDate=2204"; //- Sterling
                    // theMessage = "C:cardpan=5399232123065994,expiryDate=1802"; //-FBN
                    //theMessage = "C:cardpan=6280515555555555,expiryDate=2008"; //Keystone
                    theMessage = "C:cardpan=5334775926989586,expiryDate=2009";
                }
                else
                {
                    string expiry = "";
                    string pan    = getCardDetails(card, phoneNumber, out expiry);

                    if (string.IsNullOrWhiteSpace(pan) || string.IsNullOrWhiteSpace(expiry))
                    {
                        return("1:An error occurred.");
                    }
                    theMessage = String.Format("C:cardpan={0},expiryDate={1},pin=1234,terminalId=12345678,PinOffset=1234|5399232123033091", pan, expiry);
                    new PANE.ERRORLOG.Error().LogInfo(theMessage);
                    //call prime method to get Pin Issuance Request
                }
                // formulate the actual request data
                USSDPinIssuanceRequest theRequest = PosMessageParser.ParseRequestMessage <USSDPinIssuanceRequest>(theMessage);
                pinRequest            = theRequest as USSDPinIssuanceRequest;
                pinRequest.Pin        = new Random().Next(1111, 9999).ToString();
                pinRequest.TerminalId = string.Format("USSD{0}", theRequest.CardPAN.Substring(theRequest.CardPAN.Length - 4));
                pinRequest.Function   = "pinselection";

                Card theCard = null;

                if (usePrimeHSM)
                {
                    string staticKeyName    = System.Configuration.ConfigurationManager.AppSettings["StaticKeyName"];
                    string panEncryptionKey = LiteDAO.GetLocalKey(staticKeyName);
                    string encryptedPan     = ThalesSim.Core.Cryptography.TripleDES.TripleDESDecrypt(new ThalesSim.Core.Cryptography.HexKey(panEncryptionKey.Substring(0, 32)), pinRequest.CardPAN);

                    theCard = GetCardDetailsFromService(encryptedPan, pinRequest.ExpiryDate);
                }
                else
                {
                    theCard = CardUtilities.RetrieveCard(pinRequest.CardPAN, pinRequest.ExpiryDate, "pc_cards_1_A");
                }


                if (theCard == null)
                {
                    return("1:Invalid card data");
                }
                if (theCard.expiry_date != pinRequest.ExpiryDate)
                {
                    return("1:Invalid expiry date");
                }
                response = new PosMessageProcessor().DoPinOffsetUpdate(
                    new PinIssuanceRequest()
                {
                    CardPAN    = pinRequest.CardPAN,
                    ExpiryDate = pinRequest.ExpiryDate,
                    Pin        = pinRequest.Pin,
                    ConfirmPin = pinRequest.Pin,
                    TerminalId = pinRequest.TerminalId
                },
                    theCard);
                // pinRequest as PinIssuanceRequest,
            }
            catch (Exception ex)
            {
                response = string.Format("1:{0}", ex.Message);
                new PANE.ERRORLOG.Error().LogToFile(ex);
            }

            return(response);
        }
Пример #5
0
        public string DoPinOffsetUpdate(PinIssuanceRequest request, Card theCard)
        {
            string guid = Guid.NewGuid().ToString();
            int    step = 0;

            new PANE.ERRORLOG.Error().LogInfo(string.Format("In PosMessageProcessor.DoPinSelection HIT! [{0}]; Step: {1}", guid, ++step));

            string    response = string.Empty;
            ThalesHsm hsm      = new ThalesHsm();
            IGeneratePinOffsetResponse pinOffsset = null;
            // ChangePINResponse cpResponse = null;
            string clearPin = null;

            if (request.Pin != request.ConfirmPin)
            {
                response = "1:Invalid request data. New Pin and Confirm New Pin are not the same";
                return(response);
            }

            new PANE.ERRORLOG.Error().LogInfo(string.Format("In PosMessageProcessor.DoPinSelection [{0}]; Step: {1}", guid, ++step));
            // obatin the account number
            string accountNo = "";

            try
            {
                accountNo = theCard.pan.Substring(theCard.pan.Length - 13, 12);
            }
            catch (Exception)
            {
                response = "1:Invalid CardNumber, ensure the card number is minimum of 16 digits";
                return(response);
            }

            new PANE.ERRORLOG.Error().LogInfo(string.Format("In PosMessageProcessor.DoPinSelection [{0}]; Step: {1}", guid, ++step));
            // Step 1: Generate a new encrypted Random Pin
            string _encryptedPIN;

            try
            {
                clearPin      = request.Pin;
                _encryptedPIN = hsm.PinGenerator().EncryptClearPin(clearPin, accountNo).EncryptedPin;
                new PANE.ERRORLOG.Error().LogInfo("Clear Pin: " + clearPin);
            }
            catch (Exception ex)
            {
                new PANE.ERRORLOG.Error().LogToFile(new Exception("Unable to Encrypt clear Pin", ex));
                //Exception ex2 = new ApplicationException("System error");
                //throw ex2;
                response = "1:System PIN Error";
                return(response);
            }

            new PANE.ERRORLOG.Error().LogInfo(string.Format("In PosMessageProcessor.DoPinSelection [{0}]; Step: {1}", guid, ++step));
            // Step 2: Generate the Pin offset for the random pin
            try
            {
                if (theCard.pan.StartsWith("4"))
                {
                    pinOffsset = hsm.PinGenerator().GenerateVISAPinOffset(_encryptedPIN, accountNo, theCard.pan);
                }
                else
                {
                    pinOffsset = hsm.PinGenerator().GeneratePinOffset(_encryptedPIN, accountNo, theCard.pan);
                }
                new PANE.ERRORLOG.Error().LogInfo("PinVerificationKey :" + ConfigurationManager.HsmConfig.PinVerificationKey);
                new PANE.ERRORLOG.Error().LogInfo("PinValidationData :" + ConfigurationManager.HsmConfig.PinValidationData);
                new PANE.ERRORLOG.Error().LogInfo("DecimalisationTable for pin :" + ConfigurationManager.HsmConfig.DecimalisationTable);
                new PANE.ERRORLOG.Error().LogInfo("PinOffsset :" + pinOffsset);
                new PANE.ERRORLOG.Error().LogInfo("EncryptedPIN :" + _encryptedPIN);
                new PANE.ERRORLOG.Error().LogInfo("AccountNo :" + accountNo);
                new PANE.ERRORLOG.Error().LogInfo("Card.Pan :" + theCard.pan);
            }
            catch (Exception ex)
            {
                new PANE.ERRORLOG.Error().LogToFile(new Exception("Unable to Generate the Pin offset for the random pin", ex));
                response = "1:System PIN OffSet Error";
                return(response);
            }

            new PANE.ERRORLOG.Error().LogInfo(string.Format("In PosMessageProcessor.DoPinSelection [{0}]; Step: {1}", guid, ++step));
            // Step 3: Update PostCard with the generated pin offset
            try
            {
                bool usePrimeHSM     = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UsePrimeHSM"]);
                bool useActiveActive = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UseActiveActive"]);
                if (usePrimeHSM)
                {
                    string staticKeyName    = System.Configuration.ConfigurationManager.AppSettings["StaticKeyName"];
                    string panEncryptionKey = LiteDAO.GetLocalKey(staticKeyName);
                    string encryptedPan     = ThalesSim.Core.Cryptography.TripleDES.TripleDESDecrypt(new ThalesSim.Core.Cryptography.HexKey(panEncryptionKey.Substring(0, 32)), theCard.pan);
                    UpdatePinOffsetService(encryptedPan, theCard.expiry_date, pinOffsset.Offset.Substring(0, 4));
                }
                else if (useActiveActive)
                {
                    CardUtilities.UpdateCardPinOffset_ActiveActive(theCard, pinOffsset.Offset.Substring(0, 4));
                }
                else
                {
                    CardUtilities.UpdateCardPinOffset(theCard, pinOffsset.Offset.Substring(0, 4));
                }
            }
            catch (Exception ex)
            {
                new PANE.ERRORLOG.Error().LogToFile(new Exception("Unable to Update PostCard with the generated pin offset", ex));
                //Exception ex2 = new ApplicationException("System error");
                //throw ex2;
                response = "1:System PIN OffSet Update Error";
                return(response);
            }

            new PANE.ERRORLOG.Error().LogInfo(string.Format("In PosMessageProcessor.DoPinSelection [{0}]; Step: {1}", guid, ++step));
            return(string.Format("0:{0}", clearPin));
        }