private ApproverResponseBase DoQRCheckAuthStatus(ApproverRequestBase request)
 {
     return(new QRCodeApproverResponse()
     {
         IsApproved = true,
         ResponseMessage = "Approved",
     });
 }
 private ApproverResponseBase DoQRAuth(ApproverRequestBase requestIn)
 {
     return(new QRCodeApproverResponse()
     {
         IsApproved = true,
         ResponseMessage = "Approved",
     });
 }
 public ApproverResponseBase DoCheckAuthStatus(ApproverRequestBase request)
 {
     return(new EMVApproverResponse()
     {
         IsApproved = true,
         ResponseMessage = "Approved Reversal By ContactlessDummyOnlineApprover"
     });
 }
 public ApproverResponseBase DoReversal(ApproverRequestBase request, bool isOnline)
 {
     return(new EMVApproverResponse()
     {
         IsApproved = true,
         ResponseMessage = "Approved Reversal By ContactlessDummyOnlineApprover"
     });
 }
 public ApproverResponseBase DoAuth(ApproverRequestBase request)
 {
     return(new EMVApproverResponse()
     {
         IsApproved = true,
         ResponseMessage = "Approved Auth By ContactlessDummyOnlineApprover"
     });
 }
 public ApproverResponseBase DoCheckAuthStatus(ApproverRequestBase request)
 {
     if (request is EMVApproverRequest)
     {
         throw new NotImplementedException();
     }
     if (request is QRCodeApproverRequest)
     {
         return(DoQRCheckAuthStatus(request));
     }
     else
     {
         throw new NotImplementedException();
     }
 }
示例#7
0
        private ApproverResponseBase DoEMVAuth(ApproverRequestBase requestIn)
        {
            try
            {
                EMVApproverRequest request = ((EMVApproverRequest)requestIn);

                DCEMVDemoServerClient client = SessionSingleton.GenDCEMVServerApiClient();
                using (SessionSingleton.HttpClient)
                {
                    ContactCardOnlineAuthRequest tx = new ContactCardOnlineAuthRequest()
                    {
                        EMV_Data = TLVasJSON.Convert(request.EMV_Data),
                    };
                    string responseJson = "";
                    Task.Run(async() => {
                        responseJson = await client.TransactionAuthtransactiontoissuerPostAsync(tx.ToJsonString());
                    }).Wait();
                    ContactCardOnlineAuthResponse response = ContactCardOnlineAuthResponse.FromJsonString(responseJson);

                    EMVApproverResponse approverResponse = null;
                    switch (response.Response)
                    {
                    case ContactCardOnlineAuthResponseEnum.Approved:
                    case ContactCardOnlineAuthResponseEnum.Declined:
                        approverResponse                   = new EMVApproverResponse();
                        approverResponse.AuthCode_8A       = TLVasJSON.Convert(response.AuthCode_8A);
                        approverResponse.IssuerAuthData_91 = TLVasJSON.Convert(response.IssuerAuthData_91);
                        approverResponse.IsApproved        = response.Response == ContactCardOnlineAuthResponseEnum.Approved ? true : false;
                        approverResponse.ResponseMessage   = response.ResponseMessage;
                        break;

                    case ContactCardOnlineAuthResponseEnum.UnableToGoOnline:
                        break;
                    }

                    return(approverResponse);
                }
            }
            catch
            {
                return(null);
            }
        }
        private ApproverResponseBase DoEMVAuth(ApproverRequestBase requestIn)
        {
            EMVApproverRequest request = ((EMVApproverRequest)requestIn);

            CryptoMetaData cryptoMetaData = EMVDESSecurity.BuildCryptoMeta(request.EMV_Data);

            //Do additional checking here, e.g. customer balances etc
            //if decline set isApproved to false
            bool isApproved = true;
            //do we want to send back a pin change script,
            string newPin = "";// = "4315";
            //decide whether to send 71 or 72 script template, 71 scripts applied before 2nd gen ac , 72 scripts applied after 2nd gen ac
            bool doPinChangeBefore = false;

            TLV    _8A;
            string responseMessage;

            if (isApproved)
            {
                _8A             = TLV.Create(EMVTagsEnum.AUTHORISATION_RESPONSE_CODE_8A_KRN.Tag, arcApproved);
                responseMessage = "Approved";
            }
            else
            {
                _8A             = TLV.Create(EMVTagsEnum.AUTHORISATION_RESPONSE_CODE_8A_KRN.Tag, arcDeclined);
                responseMessage = "Declined";
            }

            TLV _91;

            byte[] arpc;
            //returns null if arqc cannot be verified
            if (cryptoMetaData.CryptoVersion == CrptoVersionEnum._18)
            {
                arpc = EMVDESSecurity.VerifyCryptogramGenARPC(request.EMV_Data, cryptoMetaData, PackCSU());
            }
            else
            {
                arpc = EMVDESSecurity.VerifyCryptogramGenARPC(request.EMV_Data, cryptoMetaData, _8A.Value);
            }

            if (arpc != null)
            {
                _91 = Pack91(cryptoMetaData, arpc, _8A);// TLV.Create(EMVTagsEnum.ISSUER_AUTHENTICATION_DATA_91_KRN.Tag, Formatting.ConcatArrays(arpc, _8A.Value));
                Logger.Log("Tx approved: " + isApproved + " ARQC passed, ARPC is " + Formatting.ByteArrayToHexString(arpc));
            }
            else
            {
                isApproved      = false;
                responseMessage = "Tx Declined: ARQC Failure";
                _8A             = TLV.Create(EMVTagsEnum.AUTHORISATION_RESPONSE_CODE_8A_KRN.Tag, new byte[] { 0x20, 0x20 });
                _91             = Pack91(cryptoMetaData, arpc, _8A); //TLV.Create(EMVTagsEnum.ISSUER_AUTHENTICATION_DATA_91_KRN.Tag, new byte[8]);
                Logger.Log("ARQC failed");
            }

            byte[] _86 = new byte[0];
            //don't allow pin change if arqc could not be validated
            if (!string.IsNullOrWhiteSpace(newPin) && arpc != null)
            {
                try
                {
                    TLV _9F26 = request.EMV_Data.Children.Get(EMVTagsEnum.APPLICATION_CRYPTOGRAM_9F26_KRN.Tag);
                    if (_9F26 == null)
                    {
                        throw new Exception("No Cryptogram found");
                    }
                    //TODO: for mchip we must increment the arqc by one for each subsequent command created
                    _86 = EMVDESSecurity.CalculatePinChangeScript(request.EMV_Data, cryptoMetaData, newPin, _9F26.Value);
                }
                catch
                {
                    _86 = new byte[0];
                }
            }

            TLV _71TLV;
            TLV _72TLV;

            if (doPinChangeBefore)
            {
                _71TLV = TLV.Create(EMVTagsEnum.ISSUER_SCRIPT_TEMPLATE_1_71_KRN.Tag);
                _71TLV.Deserialize(Formatting.ConcatArrays(new byte[] { 0x71, (byte)_86.Length }, _86), 0);

                _72TLV = TLV.Create(EMVTagsEnum.ISSUER_SCRIPT_TEMPLATE_2_72_KRN.Tag);
                _72TLV.Deserialize(Formatting.ConcatArrays(new byte[] { 0x72, 0x00 }, new byte[0]), 0);
            }
            else
            {
                _72TLV = TLV.Create(EMVTagsEnum.ISSUER_SCRIPT_TEMPLATE_2_72_KRN.Tag);
                _72TLV.Deserialize(Formatting.ConcatArrays(new byte[] { 0x72, (byte)_86.Length }, _86), 0);

                _71TLV = TLV.Create(EMVTagsEnum.ISSUER_SCRIPT_TEMPLATE_1_71_KRN.Tag);
                _71TLV.Deserialize(Formatting.ConcatArrays(new byte[] { 0x71, 0x00 }, new byte[0]), 0);
            }

            return(new EMVApproverResponse()
            {
                IsApproved = isApproved,
                ResponseMessage = responseMessage,
                AuthCode_8A = _8A,
                IssuerAuthData_91 = _91,
                IssuerScriptTemplate_72 = _72TLV,
                IssuerScriptTemplate_71 = _71TLV,
            });
        }
 public ApproverResponseBase DoAdvice(ApproverRequestBase request, bool isOnline)
 {
     throw new NotImplementedException();
 }
示例#10
0
 public ApproverResponseBase DoCheckAuthStatus(ApproverRequestBase request)
 {
     throw new NotImplementedException();
 }
示例#11
0
 private ApproverResponseBase DoQRAuth(ApproverRequestBase requestIn)
 {
     throw new NotImplementedException();
 }
示例#12
0
        public ApproverResponseBase DoAuth(ApproverRequestBase requestIn)
        {
            bool isMagStripe;
            EMVApproverRequest request = ((EMVApproverRequest)requestIn);
            TLV cryptogram             = request.EMV_Data.Children.Get(EMVTagsEnum.CRYPTOGRAM_INFORMATION_DATA_9F27_KRN.Tag);

            if (cryptogram != null)
            {
                isMagStripe = false;
            }
            else
            {
                isMagStripe = true;
            }

            TransactionTypeEnum tt = (TransactionTypeEnum)Formatting.GetEnum(typeof(TransactionTypeEnum), request.EMV_Data.Children.Get(EMVTagsEnum.TRANSACTION_TYPE_9C_KRN.Tag).Value[0]);

            TransactionBase np;

            switch (tt)
            {
            case TransactionTypeEnum.PurchaseGoodsAndServices:
                np = new F00_NormalPurchase();
                break;

            case TransactionTypeEnum.PurchaseWithCashback:
                np = new F08_PurchaseWithCashBack();
                break;

            case TransactionTypeEnum.Refund:
                np = new F12_MerchandiseReturnAdjustment();
                break;

            default:
                throw new Exception("Unimplemented TransactionTypeEnum:" + tt);
            }

            np.SetHeaderValues(SPDHTransactionCode.NormalPurchase, SPDHMessageType.FinancialTransaction, SPDHMessageSubType.Online, DateTime.Now, "300047", "");

            np.Fids.Add(new FID_B_Amount1(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.AMOUNT_AUTHORISED_NUMERIC_9F02_KRN.Tag).Value)));

            FIDBase fb_6 = new FIDBase('6', ' ', new byte[0]);

            np.Fids.Add(fb_6);

            if (tt == TransactionTypeEnum.PurchaseWithCashback || tt == TransactionTypeEnum.Refund)
            {
                np.Fids.Add(new FID_C_Amount2(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.AMOUNT_OTHER_NUMERIC_9F03_KRN.Tag).Value)));
            }
            if (isMagStripe)
            {
                np.Fids.Add(new FID_q_Track2_Customer(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.TRACK_2_DATA_9F6B_KRN2.Tag).Value)));
                fb_6.Children.Add(new FID_6_I_TransactionCurrencyCode(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.TRANSACTION_CURRENCY_CODE_5F2A_KRN.Tag).Value)));
                fb_6.Children.Add(new FID_6_E_POSEntryMode(Formatting.ConvertToHexAscii(new byte[] { 0x91 })));
            }
            else
            {
                np.Fids.Add(new FID_q_Track2_Customer(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.TRACK_2_EQUIVALENT_DATA_57_KRN.Tag).Value)));
                fb_6.Children.Add(new FID_6_I_TransactionCurrencyCode(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.TRANSACTION_CURRENCY_CODE_5F2A_KRN.Tag).Value)));
                //fb_6.Children.Add(new FID_6_E_POSEntryMode(Formatting.ConvertToHexAscii(new byte[] { 0x07 })));
                fb_6.Children.Add(new FID_6_E_POSEntryMode(Formatting.ASCIIStringToByteArray("051")));
            }

            if (!isMagStripe)
            {
                List <byte[]> fidBytes        = new List <byte[]>();
                byte[]        smartCardScheme = new byte[] { 0x30, 0x31 };

                fidBytes.Add(smartCardScheme);
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.CRYPTOGRAM_INFORMATION_DATA_9F27_KRN.Tag).Value));
                fidBytes.Add(Formatting.ASCIIStringToByteArray(Formatting.ByteArrayToHexString(request.EMV_Data.Children.Get(EMVTagsEnum.TERMINAL_COUNTRY_CODE_9F1A_KRN.Tag).Value).Substring(1)));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.TRANSACTION_DATE_9A_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.APPLICATION_CRYPTOGRAM_9F26_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.APPLICATION_INTERCHANGE_PROFILE_82_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.UNPREDICTABLE_NUMBER_9F37_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.TERMINAL_VERIFICATION_RESULTS_95_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.TRANSACTION_TYPE_9C_KRN.Tag).Value));
                fidBytes.Add(Formatting.ASCIIStringToByteArray(Formatting.ByteArrayToHexString(request.EMV_Data.Children.Get(EMVTagsEnum.TRANSACTION_CURRENCY_CODE_5F2A_KRN.Tag).Value).Substring(1)));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.AMOUNT_AUTHORISED_NUMERIC_9F02_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.ISSUER_APPLICATION_DATA_9F10_KRN.Tag).Value));

                fb_6.Children.Add(new FID_6_O_EMVRequestData(fidBytes.SelectMany(x => x).ToArray()));

                fidBytes = new List <byte[]>();
                fidBytes.Add(smartCardScheme);
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.APPLICATION_PRIMARY_ACCOUNT_NUMBER_PAN_SEQUENCE_NUMBER_5F34_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.TERMINAL_TYPE_9F35_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.CARDHOLDER_VERIFICATION_METHOD_CVM_RESULTS_9F34_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.APPLICATION_VERSION_NUMBER_TERMINAL_9F09_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.DEDICATED_FILE_DF_NAME_84_KRN.Tag).Value));

                fb_6.Children.Add(new FID_6_P_EMVAdditionalRequestData(fidBytes.SelectMany(x => x).ToArray()));
            }

            Logger.Log(np.ToPrintString());

            bool check = np.Validate();

            byte[] received;

            using (request.TCPClientStream)
            {
                request.TCPClientStream.Connect(host, port);
                received = TCPIPManager.SendTransaction(request.TCPClientStream, np.Serialize());
            }

            int             pos = 0;
            TransactionBase fb;

            switch (tt)
            {
            case TransactionTypeEnum.PurchaseGoodsAndServices:
                fb = new F00_NormalPurchase();
                break;

            case TransactionTypeEnum.PurchaseWithCashback:
                fb = new F08_PurchaseWithCashBack();
                break;

            case TransactionTypeEnum.Refund:
                fb = new F12_MerchandiseReturnAdjustment();
                break;

            default:
                throw new Exception("Unimplemented TransactionTypeEnum:" + tt);
            }
            pos = fb.Deserialize(received, pos);

            Logger.Log(fb.ToPrintString());

            FIDBase responseMessageFid = fb.FindFid(FidMetaList.ResponseDisplay).Get();
            string  responseMessage    = Formatting.ByteArrayToASCIIString(responseMessageFid.Value);
            bool    responseCode;
            int     responseCodeAsNumber = Convert.ToInt32(Formatting.ByteArrayToASCIIString(fb.Header.GetValue(HeaderEntryEnum.ResponseCode)));

            if (responseCodeAsNumber >= 0 && responseCodeAsNumber <= 10)
            {
                responseCode = true;
            }
            else
            {
                responseCode = false;
            }

            FIDBase responseMessage6QFid    = fb.FindFid(FidMetaList.EMVResponseData).Get();
            string  responseMessage6Q       = Formatting.ByteArrayToASCIIString(responseMessage6QFid.Value);
            string  smartCardSchemeResponse = responseMessage6Q.Substring(0, 2);
            string  authResponseCode        = "";
            string  issuerAuthData;

            if (smartCardSchemeResponse == "00") //schem 1
            {
                issuerAuthData = responseMessage6Q.Substring(2);
            }
            else //01 == schem 2
            {
                authResponseCode = responseMessage6Q.Substring(2, 2);
                issuerAuthData   = responseMessage6Q.Substring(4);
            }

            TLV authcodeTLV = null;

            if (!String.IsNullOrEmpty(authResponseCode))
            {
                authcodeTLV = TLV.Create(EMVTagsEnum.AUTHORISATION_RESPONSE_CODE_8A_KRN.Tag, Formatting.ASCIIStringToByteArray(authResponseCode));
            }

            TLV issuerAuthDataTLV = TLV.Create(EMVTagsEnum.ISSUER_AUTHENTICATION_DATA_91_KRN.Tag, Formatting.HexStringToByteArray(issuerAuthData));

            return(new EMVApproverResponse()
            {
                IsApproved = responseCode,
                ResponseMessage = responseMessage,
                AuthCode_8A = authcodeTLV,
                IssuerAuthData_91 = issuerAuthDataTLV
            });
        }