Exemple #1
0
        protected string ProcessPinRequest(PinIssuanceRequest request)
        {
            string response = string.Empty;

            new PANE.ERRORLOG.Error().LogInfo("Start ProcessPinRequest");

            new PANE.ERRORLOG.Error().LogInfo("Before Retrieve from PostCard");
            if (string.IsNullOrEmpty(request.Track2))
            {
                throw new Exception("Track 2 data is empty");
            }

            Card theCard = CardUtilities.GetCardFromPostCard(request.CardPAN, "pc_cards_1_A");

            new PANE.ERRORLOG.Error().LogInfo("After Retrieve from PostCard");
            switch (request.Function.ToLower())
            {
            case "pinselection":
                response = DoPinSelection(request, theCard);
                break;

            case "pinchange":
                response = DoPinChange(request, theCard);
                break;
            }

            new PANE.ERRORLOG.Error().LogInfo("End ProcessPinRequest");
            return(response);
        }
Exemple #2
0
        public string Execute(PinIssuanceRequest theRequest)
        {
            string response = "";

            new PANE.ERRORLOG.Error().LogInfo("message from the pos");

            try
            {
                if (theRequest == null)
                {
                    throw new Exception("Invalid request data");
                }

                response = ProcessPinRequest(theRequest);
            }
            catch (Exception ex)
            {
                new PANE.ERRORLOG.Error().LogToFile(ex);
                //response = string.Format("C:2|DECLINED|{0}", ex.Message);
                response = string.Format("false|{0}", ex.Message);
            }

            return(response);
        }
Exemple #3
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]));
            }
        }
Exemple #4
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));
        }
Exemple #5
0
        protected string DoPinChange(PinIssuanceRequest request, Card theCard)
        {
            if (request.Pin != request.ConfirmPin)
            {
                throw new ApplicationException("New Pin and Confirm New Pin are not the same");
            }

            string            response   = string.Empty;
            ThalesHsm         hsm        = new ThalesHsm();
            ChangePINResponse cpResponse = null;

            // obatin the account number
            string accountNo = "";

            try
            {
                accountNo = theCard.pan.Substring(theCard.pan.Length - 13, 12);
            }
            catch (Exception ex)
            {
                new PANE.ERRORLOG.Error().LogToFile(ex);
                throw new ApplicationException("Unable to derive account number from card PAN. Ensure that card PAN is minimum of 16 digits");
            }

            // Step 4: Do PinChange with random pin as oldpin and translated pin as newpin
            try
            {
                Engine theFepEngine = new PinIssuance.Net.Bridge.PostBridge.Client.Engine(
                    PinConfigurationManager.FepConfig.BridgeHostIp,
                    PinConfigurationManager.FepConfig.InternalServerPort,
                    new CardAcceptor(request.TerminalId, request.TerminalId)
                {
                },
                    "trx"
                    );

                theFepEngine.Connect();

                cpResponse = theFepEngine.DoChangePIN
                             (
                    new CardDetails()
                {
                    ExpiryDate  = DateTime.ParseExact(theCard.expiry_date, "yyMM", DateTimeFormatInfo.InvariantInfo),
                    PAN         = theCard.pan,
                    PIN         = GetPinBlockToPopulateIn52IsoInPinChange(accountNo, request.OldPin), //pinbytearr,
                    NewPINBlock = GetPinBlockToPopulateIn53ISO(accountNo, request.ConfirmPin),        //newEncryptedPinBlock
                    IccData     = request.IccData,
                    Track2      = request.Track2
                },
                    new Bridge.PostBridge.Client.DTO.Account(accountNo, ""), theCard.seq_nr
                             );
            }
            catch (Exception ex)
            {
                new PANE.ERRORLOG.Error().LogToFile(ex);
                Exception ex2 = new ApplicationException("Unable to Do PinChange with random pin as oldpin and translated pin as newpin");
                throw ex2;
            }

            // Step 8: Obtain the isser script from PinChange response and return to the Pos
            if (cpResponse == null || string.IsNullOrEmpty(cpResponse.IssuerScript))
            {
                throw new ApplicationException("Invalid pin change response");
            }
            if (cpResponse.ResponseCode == "00")
            {
                // response = string.Format("C:1|APPROVED|{0}|{1}|", cpResponse.IssuerAuthenticationData, cpResponse.IssuerScript);
                response = string.Format("true|{0}", cpResponse.IccData);
            }
            else
            {
                //response = string.Format("C:2|DECLINED|{0}", cpResponse.ResponseCode);
                response = string.Format("false|{0}", cpResponse.ResponseDescription);
            }
            return(response);
        }
Exemple #6
0
        public string DoPinSelection(PinIssuanceRequest request, Card theCard)
        {
            new PANE.ERRORLOG.Error().LogInfo("Started Do PinSelection");
            if (request.Pin != request.ConfirmPin)
            {
                throw new ApplicationException("New Pin and Confirm New Pin are not the same");
            }

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

            // obatin the account number
            string accountNo = "";

            try
            {
                accountNo = theCard.pan.Substring(theCard.pan.Length - 13, 12);
            }
            catch (Exception ex)
            {
                new PANE.ERRORLOG.Error().LogToFile(ex);
                throw new ApplicationException("Unable to derive account number from card PAN. Ensure that card PAN is minimum of 16 digits");
            }

            // Step 1: Generate a new encrypted Random Pin
            string _encryptedPIN;

            try
            {
                clearRandomPin = new Random().Next(1111, 9999).ToString();
                _encryptedPIN  = hsm.PinGenerator().EncryptClearPin(clearRandomPin, accountNo).EncryptedPin;
                new PANE.ERRORLOG.Error().LogInfo("Generated Default Pin");
            }
            catch (Exception ex)
            {
                new PANE.ERRORLOG.Error().LogToFile(ex);
                Exception ex2 = new ApplicationException("Unable to Generate a new default Pin");
                throw ex2;
            }

            // 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("Generated Pin Offset");
                }
            }
            catch (Exception ex)
            {
                new PANE.ERRORLOG.Error().LogToFile(ex);
                Exception ex2 = new ApplicationException("Unable to Generate the Pin offset for the random pin");
                throw ex2;
            }

            // Step 3: Update PostCard with the generated pin offset
            try
            {
                CardUtilities.UpdateCardPinOffset(theCard, pinOffsset.Offset.Substring(0, 4));

                new PANE.ERRORLOG.Error().LogInfo("Updated Pin Offset");
            }
            catch (Exception ex)
            {
                new PANE.ERRORLOG.Error().LogToFile(ex);
                Exception ex2 = new ApplicationException("Unable to Update PostCard with the generated pin offset");
                throw ex;
            }

            // Step 4: Do PinChange with random pin as oldpin and translated pin as newpin
            try
            {
                new PANE.ERRORLOG.Error().LogInfo("Connecting To FEP");
                Engine theFepEngine = new PinIssuance.Net.Bridge.PostBridge.Client.Engine(
                    PinConfigurationManager.FepConfig.BridgeHostIp,
                    PinConfigurationManager.FepConfig.InternalServerPort,
                    new CardAcceptor(request.TerminalId, request.TerminalId)
                {
                },
                    "trx"
                    );
                bool isConnectedToFEP = theFepEngine.Connect();

                new PANE.ERRORLOG.Error().LogInfo(string.Format("Connected to FEP - {0}", isConnectedToFEP));
                cpResponse = theFepEngine.DoChangePIN
                             (
                    new CardDetails()
                {
                    ExpiryDate  = DateTime.ParseExact(theCard.expiry_date, "yyMM", DateTimeFormatInfo.InvariantInfo),
                    PAN         = theCard.pan,
                    PIN         = GetPinBlockToPopulateIn52ISO(accountNo, clearRandomPin),     //pinbytearr,
                    NewPINBlock = GetPinBlockToPopulateIn53ISO(accountNo, request.ConfirmPin), //newEncryptedPinBlock
                    IccData     = request.IccData,
                    Track2      = request.Track2
                },
                    new Bridge.PostBridge.Client.DTO.Account(accountNo, ""), theCard.seq_nr
                             );
            }
            catch (Exception ex)
            {
                new PANE.ERRORLOG.Error().LogToFile(ex);
                Exception ex2 = new ApplicationException("Unable to Do PinChange with random pin as oldpin and translated pin as newpin");
                throw ex2;
            }

            // Step 5: Obtain the isser script from PinChange response and return to the Pos
            if (cpResponse == null || string.IsNullOrEmpty(cpResponse.IssuerScript))
            {
                throw new ApplicationException("Invalid pin change response");
            }
            if (cpResponse.ResponseCode == "00")
            {
                //response = string.Format("C:1|APPROVED|{0}|{1}", cpResponse.IssuerAuthenticationData, cpResponse.IssuerScript);
                response = string.Format("true|{0}", cpResponse.IccData);
                new PANE.ERRORLOG.Error().LogInfo("Pin Change Response: " + response);
            }
            else
            {
                //  response = string.Format("C:2|DECLINED|{0}", cpResponse.ResponseCode);
                response = string.Format("false|{0}", cpResponse.ResponseDescription);
            }

            new PANE.ERRORLOG.Error().LogInfo("Ended PinSelection");
            return(response);
        }