Example #1
0
        public string GenerateTrack2DataForMagstripe(string pan, string expiry, string serviceCode)
        {
            string    response = string.Empty;
            ThalesHsm hsm      = new ThalesHsm();
            IGeneratePinOffsetResponse pinOffsset = null;

            // ChangePINResponse cpResponse = null;

            new PANE.ERRORLOG.Error().LogInfo("In GenerateTrack2DataForMagstripe");
            // obatin the account number
            string accountNo = "";

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

            #region Derive PIN Using the IBM Method

            new PANE.ERRORLOG.Error().LogInfo("In GenerateTrack2DataForMagstripe Step 1");
            // Step 1: Generate a new encrypted Random Pin
            string _encryptedPIN;
            try
            {
                //_encryptedPIN = hsm.PinGenerator().DeriveEncryptedPin(pan).EncryptedPin;
                _encryptedPIN = hsm.PinGenerator().EncryptClearPin("0000", accountNo).EncryptedPin;
                new PANE.ERRORLOG.Error().LogInfo("Derived: " + _encryptedPIN);
            }
            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);
            }

            #endregion


            #region Generate PVV
            new PANE.ERRORLOG.Error().LogInfo("In GenerateTrack2DataForMagstripe Step 2");
            // Step 2: Generate the Pin offset for the random pin
            try
            {
                //pinOffsset = hsm.PinGenerator().GeneratePVV(_encryptedPIN, accountNo, pan);
                pinOffsset = hsm.PinGenerator().GeneratePinOffset(_encryptedPIN, accountNo, pan);
            }
            catch (Exception ex)
            {
                new PANE.ERRORLOG.Error().LogToFile(new Exception("Unable to Generate the PVV", ex));
                response = "1:System PVV Generation Error";
                return(response);
            }

            #endregion
            //return string.Format("0:{0}", pinOffsset.Offset.Substring(0, 4)); ;


            #region Generate CVV
            IGenerateCVVResponse cvv = hsm.CvvGenerator().GenerateCvv(pan, expiry, PinConfigurationManager.HsmConfig.CardVerificationKey, serviceCode);
            #endregion

            #region Format Track Data
            string discretionaryDataLessCvv = serviceCode + "01" + pinOffsset.Offset.Substring(0, 4);

            string cardHolderName = "CARDHOLDER";
            string track1         = string.Format("B{0}^{1}^{2}{3}{4}", pan, cardHolderName, expiry, discretionaryDataLessCvv, cvv.Cvv);
            string track2         = string.Format("{0}={1}{2}{3}", pan, expiry, discretionaryDataLessCvv, cvv.Cvv);
            #endregion

            new PANE.ERRORLOG.Error().LogInfo(track1);
            new PANE.ERRORLOG.Error().LogInfo(track2);


            return(string.Format("0:{0}", track2));
        }
Example #2
0
        public string GetPinOffsetAccess(string pin, string pan)
        {
            string    response = string.Empty;
            ThalesHsm hsm      = new ThalesHsm();
            IGeneratePinOffsetResponse pinOffsset = null;
            // ChangePINResponse cpResponse = null;
            string clearPin = null;


            new PANE.ERRORLOG.Error().LogInfo("In GetPinOffset");
            // obatin the account number
            string accountNo = "";

            try
            {
                accountNo = pan.Substring(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("In GetPinOffset Step 1");
            // Step 1: Generate a new encrypted Random Pin
            string _encryptedPIN;

            try
            {
                clearPin      = 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("In GetPinOffset Step 2");
            // Step 2: Generate the Pin offset for the random pin
            try
            {
                pinOffsset = hsm.PinGenerator().GeneratePinOffset(_encryptedPIN, accountNo, 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 :" + 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);
            }

            return(string.Format("0:{0}", pinOffsset.Offset.Substring(0, 4)));;
        }
Example #3
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));
        }
Example #4
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);
        }