public static SignalsEnum Execute( Kernel2Database database, KernelQ qManager, CardQ cardQManager, TornTransactionLogManager tornTransactionLogManager, Stopwatch sw) { if (qManager.GetInputQCount() == 0) { throw new EMVProtocolException("Execute_1_Idle: Kernel Input Q empty"); } KernelRequest kernel2Request = qManager.DequeueFromInput(false); switch (kernel2Request.KernelTerminalReaderServiceRequestEnum) { case KernelTerminalReaderServiceRequestEnum.STOP: return(EntryPointSTOP(database, qManager)); case KernelTerminalReaderServiceRequestEnum.CLEAN: return(EntryPointCLEAN(database, kernel2Request, qManager, tornTransactionLogManager)); case KernelTerminalReaderServiceRequestEnum.ACT: return(EntryPointACT(database, kernel2Request, qManager, cardQManager, sw)); default: throw new EMVProtocolException("Invalid Kernel1TerminalReaderServiceRequestEnum in Execute_1_Idle:" + Enum.GetName(typeof(KernelTerminalReaderServiceRequestEnum), kernel2Request.KernelTerminalReaderServiceRequestEnum)); } }
public Kernel2(TransactionTypeEnum tt, TornTransactionLogManager tornTransactionLogManager, CardQProcessor cardQProcessor, PublicKeyCertificateManager publicKeyCertificateManager, EntryPointPreProcessingIndicators processingIndicatorsForSelected, CardExceptionManager cardExceptionManager, IConfigurationProvider configProvider) : base(cardQProcessor, publicKeyCertificateManager, processingIndicatorsForSelected, cardExceptionManager, configProvider) { this.tornTransactionLogManager = tornTransactionLogManager; database = new Kernel2Database(publicKeyCertificateManager); database.InitializeDefaultDataObjects(tt, configProvider); }
public static SignalsEnum Execute( Kernel2Database database, KernelQ qManager, CardQ cardQManager, TornTransactionLogManager tornTransactionLogManager, PublicKeyCertificateManager publicKeyCertificateManager, Stopwatch sw) { if (qManager.GetOutputQCount() > 0) //there is a pending request to the terminal { KernelRequest kernel1Request = qManager.DequeueFromInput(false); switch (kernel1Request.KernelTerminalReaderServiceRequestEnum) { case KernelTerminalReaderServiceRequestEnum.STOP: return(EntryPointSTOP(database, qManager)); case KernelTerminalReaderServiceRequestEnum.DET: return(EntryPointDET(database, kernel1Request)); default: throw new EMVProtocolException("Invalid Kernel1TerminalReaderServiceRequestEnum in State_14_WaitingForCCCResponse2:" + Enum.GetName(typeof(CardInterfaceServiceResponseEnum), kernel1Request.KernelTerminalReaderServiceRequestEnum)); } } else { CardResponse cardResponse = cardQManager.DequeueFromOutput(false); switch (cardResponse.CardInterfaceServiceResponseEnum) { case CardInterfaceServiceResponseEnum.RA: return(EntryPointRA(database, cardResponse, qManager, cardQManager, tornTransactionLogManager, sw, publicKeyCertificateManager)); case CardInterfaceServiceResponseEnum.L1RSP: return(EntryPointL1RSP(database, cardResponse, qManager, tornTransactionLogManager)); default: throw new EMVProtocolException("Invalid Kernel1CardinterfaceServiceResponseEnum in State_14_WaitingForCCCResponse2:" + Enum.GetName(typeof(CardInterfaceServiceResponseEnum), cardResponse.CardInterfaceServiceResponseEnum)); } } }
public static SignalsEnum Execute( Kernel2Database database, KernelQ qManager, CardQ cardQManager, TornTransactionLogManager tornTransactionLogManager, Stopwatch sw) { KernelRequest kernel1Request = qManager.DequeueFromInput(false); switch (kernel1Request.KernelTerminalReaderServiceRequestEnum) { case KernelTerminalReaderServiceRequestEnum.STOP: return EntryPointSTOP(database, qManager); case KernelTerminalReaderServiceRequestEnum.DET: return EntryPointDET(database, kernel1Request, qManager, cardQManager, tornTransactionLogManager, sw); case KernelTerminalReaderServiceRequestEnum.TIMEOUT: return EntryPointTIMEOUT(database, qManager); default: throw new EMVProtocolException("Invalid Kernel1CardinterfaceServiceResponseEnum in State_6_WaitingForEMVModeFirstWriteFlag:" + Enum.GetName(typeof(CardInterfaceServiceResponseEnum), kernel1Request.KernelTerminalReaderServiceRequestEnum)); } }
/* * S1.4, S1.5 and S1.6 */ private static SignalsEnum EntryPointCLEAN(Kernel2Database database, KernelRequest kernel1Request, KernelQ qManager, TornTransactionLogManager tornTransactionLogManager) { foreach (TLV tlv in kernel1Request.InputData) { bool updateConditionsOfTIncludeACTSignal = EMVTagsEnum.DoesTagIncludesPermission(tlv.Tag.TagLable, UpdatePermissionEnum.ACT); if ((database.IsKnown(tlv.Tag.TagLable) || database.IsPresent(tlv.Tag.TagLable)) && updateConditionsOfTIncludeACTSignal) { database.AddToList(tlv); } } TLV discretionaryData = CommonRoutines.InitializeDiscretionaryData(database); foreach (TORN_RECORD_FF8101_KRN2 ttl in tornTransactionLogManager.TornTransactionLogs) { DateTime ttlTransactionDate = EMVTagsEnum.TRANSACTION_DATE_9A_KRN.FormatAsDateTime(ttl.Children.Get(EMVTagsEnum.TRANSACTION_DATE_9A_KRN.Tag).Value); DateTime ttlTransactionTime = EMVTagsEnum.TRANSACTION_TIME_9F21_KRN.FormatAsDateTime(ttl.Children.Get(EMVTagsEnum.TRANSACTION_TIME_9F21_KRN.Tag).Value); DateTime configTransactionDate = EMVTagsEnum.TRANSACTION_DATE_9A_KRN.FormatAsDateTime(database.Get(EMVTagsEnum.TRANSACTION_DATE_9A_KRN.Tag).Value); DateTime configTransactionTime = EMVTagsEnum.TRANSACTION_TIME_9F21_KRN.FormatAsDateTime(database.Get(EMVTagsEnum.TRANSACTION_TIME_9F21_KRN.Tag).Value); TimeSpan tsDate = ttlTransactionDate - configTransactionDate; TimeSpan tsTime = ttlTransactionTime - configTransactionTime; int totalSeconds = tsDate.Seconds + tsTime.Seconds; int defaultToCheck = (int)Formatting.ConvertToInt32(database.GetDefault(EMVTagsEnum.MAX_LIFETIME_OF_TORN_TRANSACTION_LOG_RECORD_DF811C_KRN2).Value); if (totalSeconds > defaultToCheck) { discretionaryData.Children.AddToList(ttl); tornTransactionLogManager.TornTransactionLogs.RemoveFromList(ttl); } } return(CommonRoutines.PostOutcomeOnly(database, qManager, Kernel2OutcomeStatusEnum.END_APPLICATION, Kernel2StartEnum.N_A)); }
/* * S4.3 */ private static SignalsEnum EntryPointRA(Kernel2Database database, CardResponse cardResponse, KernelQ qManager, CardQ cardQManager, TornTransactionLogManager tornTransactionLogManager, Stopwatch sw) { bool signedFlag; byte sfi; #region 4.9 if (!cardResponse.ApduResponse.Succeeded) #endregion { #region 4.10 CommonRoutines.CreateEMVDiscretionaryData(database); return(CommonRoutines.PostOutcome(database, qManager, KernelMessageidentifierEnum.ERROR_OTHER_CARD, KernelStatusEnum.NOT_READY, null, Kernel2OutcomeStatusEnum.END_APPLICATION, Kernel2StartEnum.N_A, true, KernelMessageidentifierEnum.ERROR_OTHER_CARD, L1Enum.NOT_SET, cardResponse.ApduResponse.SW12, L2Enum.STATUS_BYTES, L3Enum.NOT_SET)); #endregion } #region 4.11 if (database.ActiveAFL.Value.Entries[0].OfflineDataAuthenticationRecordLength > 0) #endregion { #region 4.12 signedFlag = true; #endregion } else { #region 4.13 signedFlag = false; #endregion } #region 4.14 sfi = database.ActiveAFL.Value.Entries[0].SFI; database.ActiveAFL.Value.Entries.RemoveAt(0); #endregion #region 4.15 TLV nextTLV = database.TagsToReadYet.GetNextGetDataTagFromList(); if (nextTLV != null) { database.ActiveTag = nextTLV.Tag.TagLable; } else { database.ActiveTag = null; } #endregion if (database.ActiveTag != null) { #region 4.16 - 4.19 EMVGetDataRequest request = new EMVGetDataRequest(Formatting.HexStringToByteArray(database.ActiveTag)); cardQManager.EnqueueToInput(new CardRequest(request, CardinterfaceServiceRequestEnum.ADPU)); database.NextCommandEnum = NextCommandEnum.GET_DATA; #endregion } else { #region 4.19 if (database.ActiveAFL.Value.Entries.Count == 0) #endregion { #region 4.20 database.NextCommandEnum = NextCommandEnum.NONE; #endregion } else { #region 4.21 - 4.23 EMVReadRecordRequest request = new EMVReadRecordRequest(database.ActiveAFL.Value.Entries[0].SFI, database.ActiveAFL.Value.Entries[0].FirstRecordNumber); cardQManager.EnqueueToInput(new CardRequest(request, CardinterfaceServiceRequestEnum.ADPU)); database.NextCommandEnum = NextCommandEnum.READ_RECORD; #endregion } } bool parsingResult; #region 4.24 if (sfi <= 10) #endregion { if (cardResponse.ApduResponse.ResponseData.Length > 0 && cardResponse.ApduResponse.ResponseData[0] == 0x70) { parsingResult = database.ParseAndStoreCardResponse(cardResponse.ApduResponse.ResponseData); } else { parsingResult = false; } } else //Processing of records in proprietary files is beyond the scope of thisspecification { parsingResult = false; } #region 4.25 if (!parsingResult) #endregion { #region 4.26 if (database.NextCommandEnum == NextCommandEnum.NONE) #endregion { #region 4.27.1 - 4.27.2 CommonRoutines.CreateEMVDiscretionaryData(database); return(CommonRoutines.PostOutcome(database, qManager, KernelMessageidentifierEnum.ERROR_OTHER_CARD, KernelStatusEnum.NOT_READY, null, Kernel2OutcomeStatusEnum.END_APPLICATION, Kernel2StartEnum.N_A, true, KernelMessageidentifierEnum.ERROR_OTHER_CARD, L1Enum.NOT_SET, null, L2Enum.PARSING_ERROR, L3Enum.NOT_SET)); #endregion } else { return(SignalsEnum.TEMINATE_ON_NEXT_RA); } } TLVList responseTags; if (cardResponse.ApduResponse is EMVReadRecordResponse) { responseTags = (cardResponse.ApduResponse as EMVReadRecordResponse).GetResponseTags(); } else if (cardResponse.ApduResponse is EMVGetDataResponse) { responseTags = (cardResponse.ApduResponse as EMVGetDataResponse).GetResponseTags(); } else { throw new EMVProtocolException("Invalid card response in State4"); } #region 4.28 TLVList cdols = responseTags.FindAll(EMVTagsEnum.CARD_RISK_MANAGEMENT_DATA_OBJECT_LIST_1_CDOL1_8C_KRN.Tag); if (cdols.Count > 0) #endregion { TLVList cdolList = TLV.DeserializeChildrenWithNoV(cdols.GetFirst().Value, 0); DATA_NEEDED_DF8106_KRN2 dataNeeded = new DATA_NEEDED_DF8106_KRN2(database); #region 4.29 foreach (TLV tlv in cdolList) { if (database.IsEmpty(tlv.Tag.TagLable)) { dataNeeded.Value.Tags.Add(tlv.Tag.TagLable); } } dataNeeded.UpdateDB(); #endregion } #region 4.30 TLVList dsdols = responseTags.FindAll(EMVTagsEnum.DSDOL_9F5B_KRN2.Tag); if (dsdols.Count > 0) #endregion { #region 4.31 IDS_STATUS_DF8128_KRN2 ids = new IDS_STATUS_DF8128_KRN2(database); if (ids.Value.IsRead) #endregion { #region 4.32 if (database.IsNotEmpty(EMVTagsEnum.DS_SLOT_MANAGEMENT_CONTROL_9F6F_KRN2.Tag) && new DS_SLOT_MANAGEMENT_CONTROL_9F6F_KRN2(database).Value.LockedSlot) #endregion { DATA_NEEDED_DF8106_KRN2 dataNeeded = new DATA_NEEDED_DF8106_KRN2(database); #region 4.33 foreach (TLV tlv in dsdols.GetFirst().Children) { if (database.IsEmpty(tlv.Tag.TagLable)) { dataNeeded.Value.Tags.Add(tlv.Tag.TagLable); } } dataNeeded.UpdateDB(); #endregion } else { #region 4.34 Do434(database, signedFlag, sfi, cardResponse, responseTags); #endregion } } else { #region 4.34 Do434(database, signedFlag, sfi, cardResponse, responseTags); #endregion } } else { #region 4.34 Do434(database, signedFlag, sfi, cardResponse, responseTags); #endregion } return(State_4_5_6_CommonProcessing.DoCommonProcessing("State_4_WaitingForEMVReadRecord", database, qManager, cardQManager, sw, tornTransactionLogManager)); }
/* * 7.3 */ private static SignalsEnum EntryPointRA(Kernel2Database database, CardResponse cardResponse, KernelQ qManager, CardQ cardQManager, TornTransactionLogManager tornTransactionLogManager, Stopwatch sw) { #region 7.9 if (!cardResponse.ApduResponse.Succeeded) #endregion { #region 7.10.1 - 7.10.2 CommonRoutines.CreateMSDiscretionaryDataRecord(database); return(CommonRoutines.PostOutcome(database, qManager, KernelMessageidentifierEnum.ERROR_OTHER_CARD, KernelStatusEnum.NOT_READY, null, Kernel2OutcomeStatusEnum.END_APPLICATION, Kernel2StartEnum.N_A, true, KernelMessageidentifierEnum.ERROR_OTHER_CARD, L1Enum.NOT_SET, cardResponse.ApduResponse.SW12, L2Enum.STATUS_BYTES, L3Enum.NOT_SET)); #endregion } #region 7.11 bool parsingResult = false; if (cardResponse.ApduResponse.ResponseData.Length > 0 && cardResponse.ApduResponse.ResponseData[0] == 0x70) { parsingResult = database.ParseAndStoreCardResponse(cardResponse.ApduResponse.ResponseData); } else { parsingResult = false; } #endregion if (!parsingResult) { #region 7.13.1 CommonRoutines.CreateMSDiscretionaryDataRecord(database); return(CommonRoutines.PostOutcome(database, qManager, KernelMessageidentifierEnum.ERROR_OTHER_CARD, KernelStatusEnum.NOT_READY, null, Kernel2OutcomeStatusEnum.END_APPLICATION, Kernel2StartEnum.N_A, true, KernelMessageidentifierEnum.ERROR_OTHER_CARD, L1Enum.NOT_SET, null, L2Enum.PARSING_ERROR, L3Enum.NOT_SET)); #endregion } #region 7.14 if ((cardResponse.ApduResponse as EMVReadRecordResponse).GetResponseTags().IsPresent(EMVTagsEnum.UDOL_9F69_KRN2.Tag)) #endregion { #region 7.15 TLV udol = (cardResponse.ApduResponse as EMVReadRecordResponse).GetResponseTags().Get(EMVTagsEnum.UDOL_9F69_KRN2.Tag); foreach (TLV tlv in udol.Children) { if (database.IsEmpty(tlv.Tag.TagLable)) { database.Get(EMVTagsEnum.DATA_NEEDED_DF8106_KRN2).Children.AddToList(tlv); } } #endregion } #region 7.16 database.ActiveAFL.Value.Entries.RemoveAt(0); #endregion #region 7.17 if (database.ActiveAFL.Value.Entries.Count != 0) #endregion { #region 7.18 - 7.19 EMVReadRecordRequest request = new EMVReadRecordRequest(database.ActiveAFL.Value.Entries[0].SFI, database.ActiveAFL.Value.Entries[0].FirstRecordNumber); cardQManager.EnqueueToInput(new CardRequest(request, CardinterfaceServiceRequestEnum.ADPU)); return(SignalsEnum.WAITING_FOR_MAG_STRIPE_READ_RECORD_RESPONSE); #endregion } #region 7.20 if (database.IsEmpty(EMVTagsEnum.TRACK_2_DATA_9F6B_KRN2.Tag) || database.IsEmpty(EMVTagsEnum.PUNATC_TRACK2_9F66_KRN2.Tag) || database.IsEmpty(EMVTagsEnum.PCVC3_TRACK2_9F65_KRN2.Tag) || database.IsEmpty(EMVTagsEnum.NATC_TRACK2_9F67_KRN2.Tag)) #endregion { #region 7.21.1 CommonRoutines.CreateMSDiscretionaryDataRecord(database); return(CommonRoutines.PostOutcome(database, qManager, KernelMessageidentifierEnum.ERROR_OTHER_CARD, KernelStatusEnum.NOT_READY, null, Kernel2OutcomeStatusEnum.END_APPLICATION, Kernel2StartEnum.N_A, true, KernelMessageidentifierEnum.ERROR_OTHER_CARD, L1Enum.NOT_SET, null, L2Enum.CARD_DATA_MISSING, L3Enum.NOT_SET)); #endregion } #region 7.22 TLV punatc2 = database.Get(EMVTagsEnum.PUNATC_TRACK2_9F66_KRN2); int natc2 = Formatting.ConvertToInt16(database.Get(EMVTagsEnum.NATC_TRACK2_9F67_KRN2).Value); int nonZeroBits = 0; for (int i = 0; i < 8; i++) { if (((punatc2.Value[0] >> i) & 0x01) == 0x01) { nonZeroBits++; } if (((punatc2.Value[1] >> i) & 0x01) == 0x01) { nonZeroBits++; } } int check2 = nonZeroBits - natc2; database.NUN = check2; if (check2 < 0 && check2 > 8) { #region 7.24.1 return(DoInvalidResponse(database, qManager)); #endregion } if (database.IsNotEmpty(EMVTagsEnum.TRACK_1_DATA_56_KRN2.Tag)) { int check1 = 0; if (database.IsNotEmpty(EMVTagsEnum.NATC_TRACK1_9F64_KRN2.Tag) && database.IsNotEmpty(EMVTagsEnum.PUNATC_TRACK1_9F63_KRN2.Tag)) { TLV punatc1 = database.Get(EMVTagsEnum.PUNATC_TRACK1_9F63_KRN2); int natc1 = Formatting.ConvertToInt16(database.Get(EMVTagsEnum.NATC_TRACK1_9F64_KRN2).Value); int nonZeroBits1 = 0; for (int i = 0; i < 8; i++) { if (((punatc1.Value[0] >> i) & 0x01) == 0x01) { nonZeroBits1++; } if (((punatc1.Value[1] >> i) & 0x01) == 0x01) { nonZeroBits1++; } if (((punatc1.Value[2] >> i) & 0x01) == 0x01) { nonZeroBits1++; } if (((punatc1.Value[3] >> i) & 0x01) == 0x01) { nonZeroBits1++; } if (((punatc1.Value[4] >> i) & 0x01) == 0x01) { nonZeroBits1++; } if (((punatc1.Value[5] >> i) & 0x01) == 0x01) { nonZeroBits1++; } } check1 = nonZeroBits1 - natc1; } else { #region 7.24.1 return(DoInvalidResponse(database, qManager)); #endregion } if ((database.IsNotPresent(EMVTagsEnum.NATC_TRACK1_9F64_KRN2.Tag) || database.IsEmpty(EMVTagsEnum.NATC_TRACK1_9F64_KRN2.Tag)) || (database.IsNotPresent(EMVTagsEnum.PCVC3_TRACK1_9F62_KRN2.Tag) || database.IsEmpty(EMVTagsEnum.PCVC3_TRACK1_9F62_KRN2.Tag)) || (database.IsNotPresent(EMVTagsEnum.PUNATC_TRACK1_9F63_KRN2.Tag) || database.IsEmpty(EMVTagsEnum.PUNATC_TRACK1_9F63_KRN2.Tag)) || check1 != check2 ) { #region 7.24.1 return(DoInvalidResponse(database, qManager)); #endregion } } #region 7.23 TRACK_2_DATA_9F6B_KRN2 t2d = new TRACK_2_DATA_9F6B_KRN2(database); TLV ddCardT2 = database.Get(EMVTagsEnum.DD_CARD_TRACK2_DF812B_KRN2); if (ddCardT2 == null) { ddCardT2 = TLV.Create(EMVTagsEnum.DD_CARD_TRACK2_DF812B_KRN2.Tag); } ddCardT2.Value = t2d.Value.DiscretionaryData; if (database.IsNotEmpty(EMVTagsEnum.TRACK_1_DATA_56_KRN2.Tag)) { TRACK_1_DATA_56_KRN2 t1d = new TRACK_1_DATA_56_KRN2(database); TLV ddCardT1 = database.Get(EMVTagsEnum.DD_CARD_TRACK1_DF812A_KRN2); if (ddCardT1 == null) { ddCardT1 = TLV.Create(EMVTagsEnum.DD_CARD_TRACK1_DF812A_KRN2.Tag); } ddCardT1.Value = t1d.Value.DiscretionaryData; } return(State_7_8_CommonProcessing.DoCommonProcessing("State_7_WaitingForMagStripeReadRecordResponse", database, qManager, cardQManager, sw)); #endregion #endregion }
/* * S9.2 */ private static SignalsEnum EntryPointRA(Kernel2Database database, CardResponse cardResponse, KernelQ qManager, CardQ cardQManager, TornTransactionLogManager tornTransactionLogManager, Stopwatch sw, PublicKeyCertificateManager publicKeyCertificateManager) { #region 10.7 if (!cardResponse.ApduResponse.Succeeded) #endregion { #region 10.8 EMVGenerateACRequest request = PrepareGenACCommandProcedure_7_6.PrepareGenACCommand(database, qManager, cardQManager); cardQManager.EnqueueToInput(new CardRequest(request, CardinterfaceServiceRequestEnum.ADPU)); return(SignalsEnum.WAITING_FOR_GEN_AC_2); #endregion } #region 10.10 tornTransactionLogManager.TornTransactionLogs.RemoveFromList(database.Get(EMVTagsEnum.TORN_RECORD_FF8101_KRN2)); #endregion #region 10.11 foreach (TLV tlv in database.TornTempRecord.Children) { database.AddToList(tlv); } #endregion #region 10.12 bool parsingResult = false; if (cardResponse.ApduResponse.ResponseData.Length > 0 && cardResponse.ApduResponse.ResponseData[0] == 0x77) #endregion { EMVGetProcessingOptionsResponse response = cardResponse.ApduResponse as EMVGetProcessingOptionsResponse; parsingResult = database.ParseAndStoreCardResponse(response.ResponseData); } if (!parsingResult) { #region 10.14 return(State_9_10_CommonProcessing.DoInvalidResponsePart_C(database, qManager, L1Enum.NOT_SET, L2Enum.PARSING_ERROR, L3Enum.NOT_SET)); #endregion } else { #region 10.13 if (!(database.IsNotEmpty(EMVTagsEnum.APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN.Tag) && database.IsNotEmpty(EMVTagsEnum.CRYPTOGRAM_INFORMATION_DATA_9F27_KRN.Tag))) #endregion { #region 10.16 return(State_9_10_CommonProcessing.DoInvalidResponsePart_C(database, qManager, L1Enum.NOT_SET, L2Enum.CARD_DATA_MISSING, L3Enum.NOT_SET)); #endregion } else { #region 10.17 REFERENCE_CONTROL_PARAMETER_DF8114_KRN2 rcp = new REFERENCE_CONTROL_PARAMETER_DF8114_KRN2(database); if ( ((database.Get(EMVTagsEnum.CRYPTOGRAM_INFORMATION_DATA_9F27_KRN).Value[0] & 0xC0) == 0x40 && rcp.Value.ACTypeEnum == ACTypeEnum.TC) && (((database.Get(EMVTagsEnum.CRYPTOGRAM_INFORMATION_DATA_9F27_KRN).Value[0] & 0xC0) == 0x80) && (rcp.Value.ACTypeEnum == ACTypeEnum.TC || rcp.Value.ACTypeEnum == ACTypeEnum.ARQC)) || (database.Get(EMVTagsEnum.CRYPTOGRAM_INFORMATION_DATA_9F27_KRN).Value[0] & 0xC0) == 0x00 ) #endregion { #region 10.18 return(State_9_10_CommonProcessing.DoInvalidResponsePart_C(database, qManager, L1Enum.NOT_SET, L2Enum.CARD_DATA_ERROR, L3Enum.NOT_SET)); #endregion } else { #region 10.19 SignalsEnum result = PostGenACBalanceReading_7_3.PostGenACBalanceReading(database, qManager, cardQManager); if (result != SignalsEnum.NONE) { return(result); } #endregion #region 10.20 if (!database.IsNotEmptyList(EMVTagsEnum.TAGS_TO_WRITE_AFTER_GEN_AC_FF8103_KRN2.Tag)) #endregion { #region 10.21 CommonRoutines.PostUIOnly(database, qManager, KernelMessageidentifierEnum.CLEAR_DISPLAY, KernelStatusEnum.CARD_READ_SUCCESSFULLY, true); #endregion } #region 10.22 if (database.IsNotEmpty(EMVTagsEnum.SIGNED_DYNAMIC_APPLICATION_DATA_9F4B_KRN.Tag)) #endregion { return(State_9_10_CommonProcessing.DoCDA9_10_1(database, qManager, publicKeyCertificateManager, cardQManager, cardResponse)); } else { return(State_9_10_CommonProcessing.DoNOCDA9_10_30(database, qManager, publicKeyCertificateManager, cardQManager, cardResponse)); } } } } }
/* * 14.1 */ private static SignalsEnum EntryPointL1RSP(Kernel2Database database, CardResponse cardResponse, KernelQ qManager, TornTransactionLogManager tornTransactionLogManager) { #region 14.2 int waitTime = ((2 ^ database.FailedMSCntr) * 300); Task.Delay(TimeSpan.FromMilliseconds(waitTime)).Wait(); #endregion #region 14.3 database.FailedMSCntr = Math.Min(database.FailedMSCntr + 1, 5); #endregion #region 14.4 - 14.5 CommonRoutines.CreateEMVDiscretionaryData(database); return(CommonRoutines.PostOutcome(database, qManager, KernelMessageidentifierEnum.TRY_AGAIN, KernelStatusEnum.READY_TO_READ, new byte[] { 0x00, 0x00, 0x00 }, Kernel2OutcomeStatusEnum.END_APPLICATION, Kernel2StartEnum.B, false, KernelMessageidentifierEnum.TRY_AGAIN, L1Enum.NOT_SET, cardResponse.ApduResponse.SW12, L2Enum.STATUS_BYTES, L3Enum.NOT_SET)); #endregion }
/* * 11.1 */ private static SignalsEnum EntryPointL1RSP(Kernel2Database database, CardResponse cardResponse, KernelQ qManager, TornTransactionLogManager tornTransactionLogManager) { #region 11.11 IDS_STATUS_DF8128_KRN2.IDS_STATUS_DF8128_KRN2_VALUE idsV = new IDS_STATUS_DF8128_KRN2.IDS_STATUS_DF8128_KRN2_VALUE(EMVTagsEnum.IDS_STATUS_DF8128_KRN2.DataFormatter); idsV.Deserialize(database.TornTempRecord.Children.Get(EMVTagsEnum.IDS_STATUS_DF8128_KRN2.Tag).Value, 0); if (!idsV.IsWrite) #endregion { #region 11.12 tornTransactionLogManager.TornTransactionLogs.RemoveFromList(database.Get(EMVTagsEnum.TORN_RECORD_FF8101_KRN2)); #endregion } #region 11.13 database.TornTempRecord = new TORN_RECORD_FF8101_KRN2(database); database.TornTempRecord.Initialize(); database.TornTempRecord.AddTornTransactionLog(database); #endregion #region 11.15 tornTransactionLogManager.AddTornTransactionLog(database); #endregion #region 11.16 - 11.17 CommonRoutines.CreateEMVDiscretionaryData(database); return(CommonRoutines.PostOutcome(database, qManager, KernelMessageidentifierEnum.TRY_AGAIN, KernelStatusEnum.READY_TO_READ, new byte[] { 0x00, 0x00, 0x00 }, Kernel2OutcomeStatusEnum.END_APPLICATION, Kernel2StartEnum.B, false, KernelMessageidentifierEnum.TRY_AGAIN, L1Enum.NOT_SET, cardResponse.ApduResponse.SW12, L2Enum.STATUS_BYTES, L3Enum.NOT_SET)); #endregion }
/* * 11.2 */ private static SignalsEnum EntryPointRA(Kernel2Database database, CardResponse cardResponse, KernelQ qManager, CardQ cardQManager, TornTransactionLogManager tornTransactionLogManager, Stopwatch sw, PublicKeyCertificateManager publicKeyCertificateManager) { tornTransactionLogManager.TornTransactionLogs.RemoveFromList(database.Get(EMVTagsEnum.TORN_RECORD_FF8101_KRN2)); #region 11.6 if (!cardResponse.ApduResponse.Succeeded) #endregion { #region 11.7 return(DoInvalidResponsePart_C(database, qManager, cardResponse, KernelMessageidentifierEnum.TRY_AGAIN, L1Enum.RETURN_CODE, L2Enum.NOT_SET, L3Enum.NOT_SET)); #endregion } #region 11.8 bool parsingResult = false; if (cardResponse.ApduResponse.ResponseData.Length > 0 && cardResponse.ApduResponse.ResponseData[0] == 0x77) #endregion { EMVGetProcessingOptionsResponse response = cardResponse.ApduResponse as EMVGetProcessingOptionsResponse; parsingResult = database.ParseAndStoreCardResponse(response.ResponseData); } else { if (cardResponse.ApduResponse.ResponseData.Length > 0 && cardResponse.ApduResponse.ResponseData[0] == 0x80) { if (cardResponse.ApduResponse.ResponseData.Length < 11 || cardResponse.ApduResponse.ResponseData.Length > 43 || database.IsNotEmpty(EMVTagsEnum.CRYPTOGRAM_INFORMATION_DATA_9F27_KRN.Tag) || database.IsNotEmpty(EMVTagsEnum.APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN.Tag) || database.IsNotEmpty(EMVTagsEnum.APPLICATION_CRYPTOGRAM_9F26_KRN.Tag) || (cardResponse.ApduResponse.ResponseData.Length > 11 && database.IsNotEmpty(EMVTagsEnum.ISSUER_APPLICATION_DATA_9F10_KRN.Tag)) ) { parsingResult = false; } else { byte[] responseBuffer = new byte[cardResponse.ApduResponse.ResponseData.Length - 2]; Array.Copy(cardResponse.ApduResponse.ResponseData, 2, responseBuffer, 0, responseBuffer.Length); database.AddToList(TLV.Create(EMVTagsEnum.CRYPTOGRAM_INFORMATION_DATA_9F27_KRN.Tag, new byte[] { responseBuffer[0] })); database.AddToList(TLV.Create(EMVTagsEnum.APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN.Tag, new byte[] { responseBuffer[1], responseBuffer[2] })); byte[] ac = new byte[8]; Array.Copy(responseBuffer, 3, ac, 0, 8); database.AddToList(TLV.Create(EMVTagsEnum.APPLICATION_CRYPTOGRAM_9F26_KRN.Tag, ac)); if (responseBuffer.Length > 11) { byte[] iad = new byte[responseBuffer.Length - 11]; Array.Copy(responseBuffer, 11, iad, 0, iad.Length); database.AddToList(TLV.Create(EMVTagsEnum.ISSUER_APPLICATION_DATA_9F10_KRN.Tag, iad)); } parsingResult = true; } } } #region 11.9 if (!parsingResult) #endregion { #region 11.10 return(DoInvalidResponsePart_C(database, qManager, cardResponse, KernelMessageidentifierEnum.N_A, L1Enum.NOT_SET, L2Enum.PARSING_ERROR, L3Enum.NOT_SET)); #endregion } #region 11.18 if (!(database.IsNotEmpty(EMVTagsEnum.APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN.Tag) && database.IsNotEmpty(EMVTagsEnum.CRYPTOGRAM_INFORMATION_DATA_9F27_KRN.Tag))) #endregion { #region 11.19 return(DoInvalidResponsePart_C(database, qManager, cardResponse, KernelMessageidentifierEnum.N_A, L1Enum.NOT_SET, L2Enum.CARD_DATA_MISSING, L3Enum.NOT_SET)); #endregion } #region 11.20 REFERENCE_CONTROL_PARAMETER_DF8114_KRN2 rcp = new REFERENCE_CONTROL_PARAMETER_DF8114_KRN2(database); if ( ((database.Get(EMVTagsEnum.CRYPTOGRAM_INFORMATION_DATA_9F27_KRN).Value[0] & 0xC0) == 0x40 && rcp.Value.ACTypeEnum == ACTypeEnum.TC) && (((database.Get(EMVTagsEnum.CRYPTOGRAM_INFORMATION_DATA_9F27_KRN).Value[0] & 0xC0) == 0x80) && (rcp.Value.ACTypeEnum == ACTypeEnum.TC || rcp.Value.ACTypeEnum == ACTypeEnum.ARQC)) || (database.Get(EMVTagsEnum.CRYPTOGRAM_INFORMATION_DATA_9F27_KRN).Value[0] & 0xC0) == 0x00 ) #endregion { #region 11.22 SignalsEnum result = PostGenACBalanceReading_7_3.PostGenACBalanceReading(database, qManager, cardQManager); if (result != SignalsEnum.NONE) { return(result); } #endregion #region 11.23 if (!database.IsNotEmptyList(EMVTagsEnum.TAGS_TO_WRITE_AFTER_GEN_AC_FF8103_KRN2.Tag)) #endregion { #region 11.24 CommonRoutines.PostUIOnly(database, qManager, KernelMessageidentifierEnum.CLEAR_DISPLAY, KernelStatusEnum.CARD_READ_SUCCESSFULLY, true); #endregion } #region 11.25 if (database.IsNotEmpty(EMVTagsEnum.SIGNED_DYNAMIC_APPLICATION_DATA_9F4B_KRN.Tag)) #endregion { return(DoCDAPart_A(database, qManager, publicKeyCertificateManager, cardQManager, cardResponse)); } else { return(DoNOCDAPart_B(database, qManager, publicKeyCertificateManager, cardQManager, cardResponse)); } } else { #region 11.21 return(DoInvalidResponsePart_C(database, qManager, cardResponse, KernelMessageidentifierEnum.N_A, L1Enum.NOT_SET, L2Enum.CARD_DATA_ERROR, L3Enum.NOT_SET)); #endregion } }
/* * S6.5 - S6.7 */ private static SignalsEnum EntryPointDET(Kernel2Database database, KernelRequest kernel1Request, KernelQ qManager, CardQ cardQManager, TornTransactionLogManager tornTransactionLogManager, Stopwatch sw) { #region 6.6 database.UpdateWithDETData(kernel1Request.InputData); #endregion #region 6.7 sw.Stop(); #endregion #region 6.8 TLV nextTLV = database.TagsToReadYet.GetNextGetDataTagFromList(); if (nextTLV != null) database.ActiveTag = nextTLV.Tag.TagLable; else database.ActiveTag = null; if (database.ActiveTag != null) #endregion { #region 6.9 - 6.12 EMVGetDataRequest request = new EMVGetDataRequest(Formatting.HexStringToByteArray(database.ActiveTag)); cardQManager.EnqueueToInput(new CardRequest(request, CardinterfaceServiceRequestEnum.ADPU)); database.NextCommandEnum = NextCommandEnum.GET_DATA; #endregion } else { #region 6.12 database.NextCommandEnum = NextCommandEnum.NONE; #endregion } return State_4_5_6_CommonProcessing.DoCommonProcessing("State_6_WaitingForEMVModeFirstWriteFlag", database, qManager, cardQManager, sw, tornTransactionLogManager); }
/* * S9.1 */ private static SignalsEnum EntryPointL1RSP(Kernel2Database database, CardResponse cardResponse, KernelQ qManager, TornTransactionLogManager tornTransactionLogManager) { int mnttl = (int)Formatting.ConvertToInt32(database.GetDefault(EMVTagsEnum.MAX_NUMBER_OF_TORN_TRANSACTION_LOG_RECORDS_DF811D_KRN2).Value); #region 9.5 if (!(mnttl > 0 && database.IsNotEmpty(EMVTagsEnum.DRDOL_9F51_KRN2.Tag))) #endregion { #region 9.6 IDS_STATUS_DF8128_KRN2 ids = new IDS_STATUS_DF8128_KRN2(database); if (ids.Value.IsWrite) #endregion { #region 9.7 - 9.8 CommonRoutines.CreateEMVDiscretionaryData(database); CommonRoutines.CreateEMVDataRecord(database); return(CommonRoutines.PostOutcome(database, qManager, KernelMessageidentifierEnum.ERROR_OTHER_CARD, KernelStatusEnum.NOT_READY, null, Kernel2OutcomeStatusEnum.END_APPLICATION, Kernel2StartEnum.N_A, true, KernelMessageidentifierEnum.ERROR_OTHER_CARD, cardResponse.L1Enum, null, L2Enum.NOT_SET, L3Enum.NOT_SET)); #endregion } else { #region 9.9 - 9.10 CommonRoutines.CreateEMVDiscretionaryData(database); return(CommonRoutines.PostOutcome(database, qManager, KernelMessageidentifierEnum.TRY_AGAIN, KernelStatusEnum.READY_TO_READ, new byte[] { 0x00, 0x00, 0x00 }, Kernel2OutcomeStatusEnum.END_APPLICATION, Kernel2StartEnum.B, false, KernelMessageidentifierEnum.TRY_AGAIN, cardResponse.L1Enum, null, L2Enum.NOT_SET, L3Enum.NOT_SET)); #endregion } } #region 9.11 database.TornTempRecord = new TORN_RECORD_FF8101_KRN2(database); database.TornTempRecord.Initialize(); database.TornTempRecord.AddTornTransactionLog(database); #endregion #region 9.13 tornTransactionLogManager.AddTornTransactionLog(database); #endregion { #region 9.14 - 9.15 CommonRoutines.CreateEMVDiscretionaryData(database); return(CommonRoutines.PostOutcome(database, qManager, KernelMessageidentifierEnum.TRY_AGAIN, KernelStatusEnum.READY_TO_READ, new byte[] { 0x00, 0x00, 0x00 }, Kernel2OutcomeStatusEnum.END_APPLICATION, Kernel2StartEnum.B, false, KernelMessageidentifierEnum.TRY_AGAIN, cardResponse.L1Enum, null, L2Enum.STATUS_BYTES, L3Enum.NOT_SET)); #endregion } }
public static SignalsEnum DoCommonProcessing(string source, Kernel2Database database, KernelQ qManager, CardQ cardQManager, Stopwatch sw, TornTransactionLogManager tornTransactionLogManager) { #region 456.1 if (database.NextCommandEnum == NextCommandEnum.READ_RECORD) #endregion { #region 456.2 TLVList toRemove = new TLVList(); foreach (TLV tlv in database.TagsToReadYet) { if (database.IsNotEmpty(tlv.Tag.TagLable)) { database.Get(EMVTagsEnum.DATA_TO_SEND_FF8104_KRN2).Children.AddToList(tlv); toRemove.AddToList(tlv); } } foreach (TLV tlv in toRemove) { database.TagsToReadYet.RemoveFromList(tlv); } #endregion #region 456.3 if (database.IsNotEmptyList(EMVTagsEnum.DATA_TO_SEND_FF8104_KRN2.Tag) && database.TagsToReadYet.Count == 0) #endregion { #region 456.4 CommonRoutines.PostDEK(database, qManager); database.Get(EMVTagsEnum.DATA_TO_SEND_FF8104_KRN2).Initialize(); database.Get(EMVTagsEnum.DATA_NEEDED_DF8106_KRN2).Initialize(); #endregion } return(SignalsEnum.WAITING_FOR_EMV_READ_RECORD_RESPONSE); } else { if (database.NextCommandEnum == NextCommandEnum.GET_DATA) { return(SignalsEnum.WAITING_FOR_GET_DATA_RESPONSE); } else { #region 456.5 if (database.IsEmpty(EMVTagsEnum.PROCEED_TO_FIRST_WRITE_FLAG_DF8110_KRN2.Tag)) #endregion { DATA_NEEDED_DF8106_KRN2 dataNeeded = new DATA_NEEDED_DF8106_KRN2(database); #region 456.6 dataNeeded.Value.Tags.Add(EMVTagsEnum.PROCEED_TO_FIRST_WRITE_FLAG_DF8110_KRN2.Tag); #endregion dataNeeded.UpdateDB(); return(Do456_7_To_456_10(source, database, qManager, cardQManager, sw)); } else { #region 456.11 if (database.IsPresent(EMVTagsEnum.PROCEED_TO_FIRST_WRITE_FLAG_DF8110_KRN2.Tag) && database.Get(EMVTagsEnum.PROCEED_TO_FIRST_WRITE_FLAG_DF8110_KRN2).Value[0] == 0x00) #endregion { #region 456.7 return(Do456_7_To_456_10(source, database, qManager, cardQManager, sw)); #endregion } } } } #region 456.12 if (database.IsEmpty(EMVTagsEnum.AMOUNT_AUTHORISED_NUMERIC_9F02_KRN.Tag)) #endregion { #region 456.13 CommonRoutines.CreateEMVDiscretionaryData(database); return(CommonRoutines.PostOutcomeWithError(database, qManager, Kernel2OutcomeStatusEnum.END_APPLICATION, Kernel2StartEnum.N_A, L1Enum.NOT_SET, L2Enum.NOT_SET, L3Enum.AMOUNT_NOT_PRESENT)); #endregion } #region 456.14 long aa = Formatting.BcdToLong(database.Get(EMVTagsEnum.AMOUNT_AUTHORISED_NUMERIC_9F02_KRN).Value); long rctl = database.ReaderContactlessTransactionLismit; if (aa > rctl) #endregion { #region 456.15 CommonRoutines.CreateEMVDiscretionaryData(database); return(CommonRoutines.PostOutcomeWithError(database, qManager, Kernel2OutcomeStatusEnum.SELECT_NEXT, Kernel2StartEnum.C, L1Enum.NOT_SET, L2Enum.MAX_LIMIT_EXCEEDED, L3Enum.NOT_SET)); #endregion } #region 456.16 if (!(database.IsNotEmpty(EMVTagsEnum.APPLICATION_EXPIRATION_DATE_5F24_KRN.Tag) && database.IsNotEmpty(EMVTagsEnum.APPLICATION_PRIMARY_ACCOUNT_NUMBER_PAN_5A_KRN.Tag) && database.IsNotEmpty(EMVTagsEnum.CARD_RISK_MANAGEMENT_DATA_OBJECT_LIST_1_CDOL1_8C_KRN.Tag))) #endregion { #region 456.17 CommonRoutines.CreateEMVDiscretionaryData(database); return(CommonRoutines.PostOutcome(database, qManager, KernelMessageidentifierEnum.ERROR_OTHER_CARD, KernelStatusEnum.NOT_READY, null, Kernel2OutcomeStatusEnum.END_APPLICATION, Kernel2StartEnum.N_A, true, KernelMessageidentifierEnum.N_A, L1Enum.NOT_SET, null, L2Enum.CARD_DATA_MISSING, L3Enum.NOT_SET)); #endregion } #region 456.18 IDS_STATUS_DF8128_KRN2 ids = new IDS_STATUS_DF8128_KRN2(database); if (ids.Value.IsRead) #endregion { #region 456.19 string dsid = Formatting.ByteArrayToHexString(database.Get(EMVTagsEnum.DS_ID_9F5E_KRN2).Value); string pan = Formatting.ByteArrayToHexString(database.Get(EMVTagsEnum.APPLICATION_PRIMARY_ACCOUNT_NUMBER_PAN_5A_KRN).Value); string seqNumber = "00"; if (database.IsNotEmpty(EMVTagsEnum.APPLICATION_PRIMARY_ACCOUNT_NUMBER_PAN_SEQUENCE_NUMBER_5F34_KRN.Tag)) { seqNumber = Formatting.ByteArrayToHexString(database.Get(EMVTagsEnum.APPLICATION_PRIMARY_ACCOUNT_NUMBER_PAN_SEQUENCE_NUMBER_5F34_KRN).Value); } string concat = pan + seqNumber; if (concat.Length % 2 != 0) { concat = "0" + concat; } if (concat.Length < 16) { concat.PadLeft(16, '0'); } if (dsid != concat) #endregion { #region 456.20.1,456.20.2 CommonRoutines.CreateEMVDiscretionaryData(database); return(CommonRoutines.PostOutcome(database, qManager, KernelMessageidentifierEnum.ERROR_OTHER_CARD, KernelStatusEnum.NOT_READY, null, Kernel2OutcomeStatusEnum.END_APPLICATION, Kernel2StartEnum.N_A, true, KernelMessageidentifierEnum.ERROR_OTHER_CARD, L1Enum.NOT_SET, null, L2Enum.CARD_DATA_ERROR, L3Enum.NOT_SET)); #endregion } } #region 456.21 TLVList toRemove2 = new TLVList(); foreach (TLV tlv in database.TagsToReadYet) { if (database.IsPresent(tlv.Tag.TagLable)) { database.Get(EMVTagsEnum.DATA_TO_SEND_FF8104_KRN2).Children.AddToList(tlv); } else { if (database.IsKnown(tlv.Tag.TagLable)) { database.Get(EMVTagsEnum.DATA_TO_SEND_FF8104_KRN2).Children.AddToList(TLV.Create(tlv.Tag.TagLable)); } } toRemove2.AddToList(tlv); } foreach (TLV tlv in toRemove2) { database.TagsToReadYet.RemoveFromList(tlv); } #endregion #region 456.22 if (database.IsNotEmptyList(EMVTagsEnum.DATA_TO_SEND_FF8104_KRN2.Tag)) #endregion { #region 456.23 CommonRoutines.PostDEK(database, qManager); database.Get(EMVTagsEnum.DATA_TO_SEND_FF8104_KRN2).Initialize(); database.Get(EMVTagsEnum.DATA_NEEDED_DF8106_KRN2).Initialize(); #endregion } #region 456.24 if (database.ODAStatus == 0x80) #endregion { TERMINAL_VERIFICATION_RESULTS_95_KRN tvr = new TERMINAL_VERIFICATION_RESULTS_95_KRN(database); #region 456.25 if (!( database.IsNotEmpty(EMVTagsEnum.CERTIFICATION_AUTHORITY_PUBLIC_KEY_INDEX_8F_KRN.Tag) && database.IsNotEmpty(EMVTagsEnum.ISSUER_PUBLIC_KEY_CERTIFICATE_90_KRN.Tag) && database.IsNotEmpty(EMVTagsEnum.ISSUER_PUBLIC_KEY_EXPONENT_9F32_KRN.Tag) && database.IsNotEmpty(EMVTagsEnum.INTEGRATED_CIRCUIT_CARD_ICC_PUBLIC_KEY_CERTIFICATE_9F46_KRN.Tag) && database.IsNotEmpty(EMVTagsEnum.INTEGRATED_CIRCUIT_CARD_ICC_PUBLIC_KEY_EXPONENT_9F47_KRN.Tag) && database.IsNotEmpty(EMVTagsEnum.STATIC_DATA_AUTHENTICATION_TAG_LIST_9F4A_KRN.Tag) )) { tvr.Value.ICCDataMissing = true; tvr.Value.CDAFailed = true; } if (database.PublicKeyCertificateManager.GetCAPK(RIDEnum.A000000004, database.Get(EMVTagsEnum.CERTIFICATION_AUTHORITY_PUBLIC_KEY_INDEX_8F_KRN).Value[0]) == null) { tvr.Value.CDAFailed = true; } #endregion #region 456.26 bool test = false; TLV aip = null; if (database.IsNotEmpty(EMVTagsEnum.STATIC_DATA_AUTHENTICATION_TAG_LIST_9F4A_KRN.Tag)) { TLV sdal = database.Get(EMVTagsEnum.STATIC_DATA_AUTHENTICATION_TAG_LIST_9F4A_KRN); TLVList list = TLV.DeserializeChildrenWithNoLV(sdal.Value, 0); if (list.Count == 1) { aip = list.Get(EMVTagsEnum.APPLICATION_INTERCHANGE_PROFILE_82_KRN.Tag); if (aip != null) { test = true; } } } if (test == false) { #region 456.27.1 - 456.27.2 CommonRoutines.CreateEMVDiscretionaryData(database); return(CommonRoutines.PostOutcome(database, qManager, KernelMessageidentifierEnum.ERROR_OTHER_CARD, KernelStatusEnum.NOT_READY, null, Kernel2OutcomeStatusEnum.END_APPLICATION, Kernel2StartEnum.N_A, true, KernelMessageidentifierEnum.ERROR_OTHER_CARD, L1Enum.NOT_SET, null, L2Enum.CARD_DATA_ERROR, L3Enum.NOT_SET)); #endregion } #endregion #region 456.28 int length = database.StaticDataToBeAuthenticated.Serialize().Length; if (2048 - length >= aip.Value.Length) { database.StaticDataToBeAuthenticated.AddToList(database.Get(EMVTagsEnum.APPLICATION_INTERCHANGE_PROFILE_82_KRN)); } else { tvr.Value.CDAFailed = true; } #endregion tvr.UpdateDB(); } #region 456.30 long cvmrl = Formatting.BcdToLong(database.Get(EMVTagsEnum.READER_CVM_REQUIRED_LIMIT_DF8126_KRN2).Value); if (aa > cvmrl) #endregion { #region 456.31 CommonRoutines.UpdateOutcomeParameterSet(database, true); #endregion #region 456.32 database.Get(EMVTagsEnum.TERMINAL_CAPABILITIES_9F33_KRN).Value[1] = database.Get(EMVTagsEnum.CVM_CAPABILITY_CVM_REQUIRED_DF8118_KRN2).Value[0]; #endregion } else { #region 456.33 database.Get(EMVTagsEnum.TERMINAL_CAPABILITIES_9F33_KRN).Value[1] = database.Get(EMVTagsEnum.CVM_CAPABILITY_NO_CVM_REQUIRED_DF8119_KRN2).Value[0]; #endregion } #region 456.34 SignalsEnum se = PreGenACBalanceReading_7_1.PreGenACBalanceReading(database, qManager, cardQManager); if (se != SignalsEnum.NONE) { return(se); } #endregion #region 456.35 ProcessingRestrictions_7_7.ProcessingRestrictions(database); #endregion #region 456.35 CVMSelection_7_5.CVMSelection(database, new Func <bool>(() => { return(new KERNEL_CONFIGURATION_DF811B_KRN2(database).Value.OnDeviceCardholderVerificationSupported); })); #endregion #region 456.36 long rcfl = Formatting.BcdToLong(database.Get(EMVTagsEnum.READER_CONTACTLESS_FLOOR_LIMIT_DF8123_KRN2).Value); if (aa > rcfl) #endregion { #region 456.38 TERMINAL_VERIFICATION_RESULTS_95_KRN tvr = new TERMINAL_VERIFICATION_RESULTS_95_KRN(database); tvr.Value.TransactionExceedsFloorLimit = true; tvr.UpdateDB(); #endregion } #region 456.39 database.ACType.Value.DSACTypeEnum = TerminalActionAnalysis_7_8.TerminalActionAnalysis(database); #endregion //#region support for Refunds pg 177 //byte transactionType = database.Get(EMVTagsEnum.TRANSACTION_TYPE_9C_KRN).Value[0]; //if (transactionType == (byte)TransactionTypeEnum.Refund) //{ // database.ACType.Value.DSACTypeEnum = ACTypeEnum.AAC; // database.ODAStatus = 0x00; //dont request CDA in first gen ac //} //#endregion #region 456.42 if (database.IsNotEmptyList(EMVTagsEnum.TAGS_TO_WRITE_BEFORE_GEN_AC_FF8102_KRN2.Tag)) #endregion { #region 456.50 TLV tlvRemoved = database.TagsToWriteBeforeGenACYet.GetFirstAndRemoveFromList(); EMVPutDataRequest request = new EMVPutDataRequest(tlvRemoved); cardQManager.EnqueueToInput(new CardRequest(request, CardinterfaceServiceRequestEnum.ADPU)); return(SignalsEnum.WAITING_FOR_PUT_DATA_RESPONSE_BEFORE_GEN_AC); #endregion } else { TORN_RECORD_FF8101_KRN2 foundTTL = null; #region 456.43 uint mnttl = Formatting.ConvertToInt32(database.GetDefault(EMVTagsEnum.MAX_NUMBER_OF_TORN_TRANSACTION_LOG_RECORDS_DF811D_KRN2).Value); if (database.IsNotEmpty(EMVTagsEnum.DRDOL_9F51_KRN2.Tag) && mnttl != 0) #endregion { #region 456.44 foreach (TORN_RECORD_FF8101_KRN2 tlv in tornTransactionLogManager.TornTransactionLogs) { if (database.IsNotEmpty(EMVTagsEnum.APPLICATION_PRIMARY_ACCOUNT_NUMBER_PAN_SEQUENCE_NUMBER_5F34_KRN.Tag)) { if ((Formatting.ByteArrayToHexString(tlv.Children.Get(EMVTagsEnum.APPLICATION_PRIMARY_ACCOUNT_NUMBER_PAN_5A_KRN.Tag).Value) == Formatting.ByteArrayToHexString(database.Get(EMVTagsEnum.APPLICATION_PRIMARY_ACCOUNT_NUMBER_PAN_5A_KRN).Value)) && (Formatting.ByteArrayToHexString(tlv.Children.Get(EMVTagsEnum.APPLICATION_PRIMARY_ACCOUNT_NUMBER_PAN_SEQUENCE_NUMBER_5F34_KRN.Tag).Value) == Formatting.ByteArrayToHexString(database.Get(EMVTagsEnum.APPLICATION_PRIMARY_ACCOUNT_NUMBER_PAN_SEQUENCE_NUMBER_5F34_KRN).Value))) { foundTTL = tlv; } } else { if ((Formatting.ByteArrayToHexString(tlv.Children.Get(EMVTagsEnum.APPLICATION_PRIMARY_ACCOUNT_NUMBER_PAN_5A_KRN.Tag).Value) == Formatting.ByteArrayToHexString(database.Get(EMVTagsEnum.APPLICATION_PRIMARY_ACCOUNT_NUMBER_PAN_5A_KRN).Value)) && (tlv.Children.IsNotPresent(EMVTagsEnum.APPLICATION_PRIMARY_ACCOUNT_NUMBER_PAN_SEQUENCE_NUMBER_5F34_KRN.Tag))) { foundTTL = tlv; } } } #endregion if (foundTTL == null) { #region 456.45 EMVGenerateACRequest request = PrepareGenACCommandProcedure_7_6.PrepareGenACCommand(database, qManager, cardQManager); cardQManager.EnqueueToInput(new CardRequest(request, CardinterfaceServiceRequestEnum.ADPU)); return(SignalsEnum.WAITING_FOR_GEN_AC_1); #endregion } else { #region 456.47 database.TornTempRecord = foundTTL; #endregion #region 456.48 database.Get(EMVTagsEnum.DRDOL_RELATED_DATA_DF8113_KRN2).Value = database.TornTempRecord.Children.Get(EMVTagsEnum.DRDOL_RELATED_DATA_DF8113_KRN2.Tag).Value; EMVRecoverACRequest requestRecover = new EMVRecoverACRequest(database.Get(EMVTagsEnum.DRDOL_RELATED_DATA_DF8113_KRN2)); cardQManager.EnqueueToInput(new CardRequest(requestRecover, CardinterfaceServiceRequestEnum.ADPU)); return(SignalsEnum.WAITING_FOR_RECOVER_AC); #endregion } } else { #region 456.45 EMVGenerateACRequest request = PrepareGenACCommandProcedure_7_6.PrepareGenACCommand(database, qManager, cardQManager); cardQManager.EnqueueToInput(new CardRequest(request, CardinterfaceServiceRequestEnum.ADPU)); return(SignalsEnum.WAITING_FOR_GEN_AC_1); #endregion } } }
/* * 14.6 */ private static SignalsEnum EntryPointRA(Kernel2Database database, CardResponse cardResponse, KernelQ qManager, CardQ cardQManager, TornTransactionLogManager tornTransactionLogManager, Stopwatch sw, PublicKeyCertificateManager publicKeyCertificateManager) { #region 14.9 if (!cardResponse.ApduResponse.Succeeded) #endregion { #region 14.10 CommonRoutines.UpdateErrorIndication(database, cardResponse, L1Enum.NOT_SET, L2Enum.STATUS_BYTES, L3Enum.NOT_SET); return(DoInvalidResponse(database, qManager)); #endregion } #region 14.11 bool parsingResult = false; if (cardResponse.ApduResponse.ResponseData.Length > 0 && cardResponse.ApduResponse.ResponseData[0] == 0x77) { EMVComputeCryptographicChecksumResponse response = cardResponse.ApduResponse as EMVComputeCryptographicChecksumResponse; parsingResult = database.ParseAndStoreCardResponse(response.ResponseData); } else { parsingResult = false; } #endregion #region 14.12 if (!parsingResult) #endregion { #region 14.13 CommonRoutines.UpdateErrorIndication(database, cardResponse, L1Enum.NOT_SET, L2Enum.PARSING_ERROR, L3Enum.NOT_SET); return(DoInvalidResponse(database, qManager)); #endregion } #region 14.12.1 CommonRoutines.PostUIOnly(database, qManager, KernelMessageidentifierEnum.CLEAR_DISPLAY, KernelStatusEnum.CARD_READ_SUCCESSFULLY, true); #endregion #region 14.14 if (database.IsEmpty(EMVTagsEnum.APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN.Tag) || database.IsEmpty(EMVTagsEnum.POS_CARDHOLDER_INTERACTION_INFORMATION_DF4B_KRN2.Tag)) #endregion { #region 14.17 CommonRoutines.UpdateErrorIndication(database, cardResponse, L1Enum.NOT_SET, L2Enum.CARD_DATA_MISSING, L3Enum.NOT_SET); return(DoInvalidResponse(database, qManager)); #endregion } long nUN = 0; #region 14.15 if (database.IsNotEmpty(EMVTagsEnum.CVC3_TRACK2_9F61_KRN2.Tag)) #endregion { #region 14.16 if (database.IsNotEmpty(EMVTagsEnum.TRACK_1_DATA_56_KRN2.Tag) && (database.IsNotPresent(EMVTagsEnum.CVC3_TRACK1_9F60_KRN2.Tag) || database.IsEmpty(EMVTagsEnum.CVC3_TRACK1_9F60_KRN2.Tag))) #endregion { #region 14.17 CommonRoutines.UpdateErrorIndication(database, cardResponse, L1Enum.NOT_SET, L2Enum.CARD_DATA_MISSING, L3Enum.NOT_SET); return(DoInvalidResponse(database, qManager)); #endregion } #region 14.20 byte pcii = database.Get(EMVTagsEnum.POS_CARDHOLDER_INTERACTION_INFORMATION_DF4B_KRN2).Value[1]; #endregion if ((pcii & 0x10) == 0x10) //OD-CVM verification successful { #region 14.24 nUN = (nUN + 5) % 10; #endregion } else { #region 14.21 long aa = Formatting.BcdToLong(database.Get(EMVTagsEnum.AMOUNT_AUTHORISED_NUMERIC_9F02_KRN).Value); long rctl = database.ReaderContactlessTransactionLismit; if (aa > rctl) #endregion { #region 14.21.1 CommonRoutines.UpdateErrorIndication(database, cardResponse, L1Enum.NOT_SET, L2Enum.CARD_DATA_ERROR, L3Enum.NOT_SET); return(DoInvalidResponse(database, qManager)); #endregion } else { #region 14.25 nUN = (int)Formatting.ConvertToInt32(database.Get(EMVTagsEnum.UNPREDICTABLE_NUMBER_9F37_KRN).Value); #endregion } } #region 14.25.1 database.FailedMSCntr = 0; #endregion #region 14.26 TRACK_2_DATA_9F6B_KRN2 t2d = new TRACK_2_DATA_9F6B_KRN2(database); ushort t2 = Formatting.ConvertToInt16(database.Get(EMVTagsEnum.NATC_TRACK2_9F67_KRN2).Value); TLV PCVC3_TRACK2_9F65_KRN2 = database.Get(EMVTagsEnum.PCVC3_TRACK2_9F65_KRN2); MagBitmap bitmapPCVC3_TRACK2_9F65_KRN2 = new MagBitmap(PCVC3_TRACK2_9F65_KRN2.Value); TLV CVC3_TRACK2_9F61_KRN2 = database.Get(EMVTagsEnum.CVC3_TRACK2_9F61_KRN2); ushort cvc3T2AsShort = Formatting.ConvertToInt16(CVC3_TRACK2_9F61_KRN2.Value.Reverse().ToArray()); string q2LeastSigDigits = Convert.ToString(cvc3T2AsShort); q2LeastSigDigits = q2LeastSigDigits.Substring(q2LeastSigDigits.Length - bitmapPCVC3_TRACK2_9F65_KRN2.NonZeroCount); t2d.Value.DiscretionaryData = Formatting.StringToBcd(bitmapPCVC3_TRACK2_9F65_KRN2.ReplaceValues(Formatting.BcdToString(t2d.Value.DiscretionaryData), q2LeastSigDigits, bitmapPCVC3_TRACK2_9F65_KRN2.NonZeroCount, true), false); TLV PUNATC_TRACK2_9F66_KRN2 = database.Get(EMVTagsEnum.PUNATC_TRACK2_9F66_KRN2); MagBitmap bitmapPUNATC_TRACK2_9F66_KRN2 = new MagBitmap(PUNATC_TRACK2_9F66_KRN2.Value); uint unpredInt = Formatting.ConvertToInt32(database.Get(EMVTagsEnum.UNPREDICTABLE_NUMBER_NUMERIC_9F6A_KRN2).Value.Reverse().ToArray()); string unpredString = Convert.ToString(unpredInt); unpredString = unpredString.Substring(unpredString.Length - database.NUN); t2d.Value.DiscretionaryData = Formatting.StringToBcd(bitmapPUNATC_TRACK2_9F66_KRN2.ReplaceValues(Formatting.BcdToString(t2d.Value.DiscretionaryData), unpredString, database.NUN, true), false); if (t2 != 0) { TLV APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN = database.Get(EMVTagsEnum.APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN); uint atcAsShort = Formatting.ConvertToInt32(APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN.Value.Reverse().ToArray()); string atcAsShortLeastSigDigits = Convert.ToString(atcAsShort); atcAsShortLeastSigDigits = atcAsShortLeastSigDigits.PadLeft(t2, '0').Substring(atcAsShortLeastSigDigits.Length - t2); t2d.Value.DiscretionaryData = Formatting.StringToBcd(bitmapPUNATC_TRACK2_9F66_KRN2.ReplaceValues(Formatting.BcdToString(t2d.Value.DiscretionaryData), atcAsShortLeastSigDigits, t2, false), false); } #endregion #region 14.27 StringBuilder dd = new StringBuilder(Formatting.BcdToString(t2d.Value.DiscretionaryData)); dd[dd.Length - 1] = Convert.ToString(nUN)[0]; t2d.Value.DiscretionaryData = Formatting.StringToBcd(dd.ToString(), false); #endregion t2d.Serialize(); //reserialize in case the length of discretionary data changed t2d.UpdateDB(); #region 14.28 if (database.IsNotEmpty(EMVTagsEnum.TRACK_1_DATA_56_KRN2.Tag)) #endregion { #region 14.29 TRACK_1_DATA_56_KRN2 t1d = new TRACK_1_DATA_56_KRN2(database); ushort t1 = Formatting.ConvertToInt16(database.Get(EMVTagsEnum.NATC_TRACK1_9F64_KRN2).Value); TLV PCVC3_TRACK1_9F62_KRN2 = database.Get(EMVTagsEnum.PCVC3_TRACK1_9F62_KRN2); MagBitmap bitmapPCVC3_TRACK1_9F62_KRN2 = new MagBitmap(PCVC3_TRACK1_9F62_KRN2.Value); TLV CVC3_TRACK1_9F60_KRN2 = database.Get(EMVTagsEnum.CVC3_TRACK1_9F60_KRN2); ushort cvc3T1AsShort = Formatting.ConvertToInt16(CVC3_TRACK1_9F60_KRN2.Value.Reverse().ToArray()); string q1LeastSigDigits = Convert.ToString(cvc3T1AsShort); q1LeastSigDigits = q1LeastSigDigits.Substring(q1LeastSigDigits.Length - bitmapPCVC3_TRACK1_9F62_KRN2.NonZeroCount); t1d.Value.DiscretionaryData = Formatting.ASCIIStringToByteArray(bitmapPCVC3_TRACK1_9F62_KRN2.ReplaceValues(Formatting.ByteArrayToASCIIString(t1d.Value.DiscretionaryData), q1LeastSigDigits, bitmapPCVC3_TRACK1_9F62_KRN2.NonZeroCount, true)); TLV PUNATC_TRACK1_9F63_KRN2 = database.Get(EMVTagsEnum.PUNATC_TRACK1_9F63_KRN2); MagBitmap bitmapPUNATC_TRACK1_9F63_KRN2 = new MagBitmap(PUNATC_TRACK1_9F63_KRN2.Value); t1d.Value.DiscretionaryData = Formatting.ASCIIStringToByteArray(bitmapPUNATC_TRACK1_9F63_KRN2.ReplaceValues(Formatting.ByteArrayToASCIIString(t1d.Value.DiscretionaryData), unpredString, database.NUN, true)); if (t2 != 0) { TLV APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN = database.Get(EMVTagsEnum.APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN); uint atcAsShort = Formatting.ConvertToInt32(APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN.Value.Reverse().ToArray()); string atcAsShortLeastSigDigits = Convert.ToString(atcAsShort); atcAsShortLeastSigDigits = atcAsShortLeastSigDigits.PadLeft(t2, '0').Substring(atcAsShortLeastSigDigits.Length - t1); t2d.Value.DiscretionaryData = Formatting.ASCIIStringToByteArray(bitmapPUNATC_TRACK1_9F63_KRN2.ReplaceValues(Formatting.ByteArrayToASCIIString(t1d.Value.DiscretionaryData), atcAsShortLeastSigDigits, t1, false)); } #endregion #region 14.30 StringBuilder dd1 = new StringBuilder(Formatting.ByteArrayToASCIIString(t1d.Value.DiscretionaryData)); dd1[dd1.Length - 1] = Convert.ToString(nUN)[0]; t1d.Value.DiscretionaryData = Formatting.ASCIIStringToByteArray(dd1.ToString()); #endregion t1d.Serialize(); //reserialize in case the length of discretionary data changed t1d.UpdateDB(); } #region 14.32 Kernel2OutcomeStatusEnum k2OutcomeStatus = Kernel2OutcomeStatusEnum.ONLINE_REQUEST; KernelCVMEnum cvmEnum = KernelCVMEnum.N_A; bool receipt = false; pcii = database.Get(EMVTagsEnum.POS_CARDHOLDER_INTERACTION_INFORMATION_DF4B_KRN2).Value[1]; if ((pcii & 0x10) == 0x10) //OD-CVM verification successful #endregion { #region 14.34 cvmEnum = KernelCVMEnum.CONFIRMATION_CODE_VERIFIED; long aa = Formatting.BcdToLong(database.Get(EMVTagsEnum.AMOUNT_AUTHORISED_NUMERIC_9F02_KRN).Value); long rctl = database.ReaderContactlessTransactionLismit; if (aa > rctl) { receipt = true; } #endregion } else { #region 14.33 cvmEnum = KernelCVMEnum.NO_CVM; #endregion } CommonRoutines.CreateMSDiscretionaryDataRecord(database); CommonRoutines.CreateMSDataRecord(database); return(CommonRoutines.PostOutcomeOnly(database, qManager, k2OutcomeStatus, cvmEnum, receipt)); } else { #region 14.19.1 if (((int)Formatting.ConvertToInt32(database.Get(EMVTagsEnum.POS_CARDHOLDER_INTERACTION_INFORMATION_DF4B_KRN2).Value) & 0x00030F) != 0x000000) #endregion { KernelMessageidentifierEnum k2MessageIdentifier = KernelMessageidentifierEnum.DECLINED; KernelStatusEnum k2Status = KernelStatusEnum.READY_TO_READ; byte[] holdTime = new byte[] { 0x00, 0x00, 0x00 }; #region 14.22 PHONE_MESSAGE_TABLE_DF8131_KRN2 pmt = (PHONE_MESSAGE_TABLE_DF8131_KRN2)database.GetDefault(EMVTagsEnum.PHONE_MESSAGE_TABLE_DF8131_KRN2); foreach (PhoneMessageTableEntry_DF8131 entry in pmt.Value.Entries) { int pcii = (int)Formatting.ConvertToInt32(database.Get(EMVTagsEnum.POS_CARDHOLDER_INTERACTION_INFORMATION_DF4B_KRN2).Value); int pciMask = (int)Formatting.ConvertToInt32(entry.PCIIMask); int pciValue = (int)Formatting.ConvertToInt32(entry.PCIIValue); if ((pciMask & pcii) == pciValue) { k2MessageIdentifier = entry.MessageIdentifier; k2Status = entry.Status; holdTime = database.GetDefault(EMVTagsEnum.MESSAGE_HOLD_TIME_DF812D_KRN2).Value; break; } } #endregion #region 14.21.1 int waitTime = ((2 ^ database.FailedMSCntr) * 300); Task.Delay(TimeSpan.FromMilliseconds(waitTime)).Wait(); #endregion #region 14.21.2 database.FailedMSCntr = Math.Min(database.FailedMSCntr + 1, 5); #endregion #region 14.23 CommonRoutines.CreateMSDiscretionaryDataRecord(database); CommonRoutines.CreateMSDataRecord(database); return(CommonRoutines.PostOutcome(database, qManager, k2MessageIdentifier, k2Status, holdTime, Kernel2OutcomeStatusEnum.END_APPLICATION, Kernel2StartEnum.B, false, KernelMessageidentifierEnum.N_A, L1Enum.NOT_SET, null, L2Enum.NOT_SET, L3Enum.NOT_SET)); #endregion } else { #region 14.19.2.1 int waitTime = ((2 ^ database.FailedMSCntr) * 300); Task.Delay(TimeSpan.FromMilliseconds(waitTime)).Wait(); #endregion #region 14.19.2.2 database.FailedMSCntr = Math.Min(database.FailedMSCntr + 1, 5); #endregion #region 14.19.3 CommonRoutines.CreateMSDiscretionaryDataRecord(database); CommonRoutines.CreateMSDataRecord(database); return(CommonRoutines.PostOutcome(database, qManager, KernelMessageidentifierEnum.DECLINED, KernelStatusEnum.NOT_READY, database.GetDefault(EMVTagsEnum.MESSAGE_HOLD_TIME_DF812D_KRN2).Value, Kernel2OutcomeStatusEnum.END_APPLICATION, Kernel2StartEnum.N_A, true, KernelMessageidentifierEnum.N_A, L1Enum.NOT_SET, null, L2Enum.NOT_SET, L3Enum.NOT_SET)); #endregion } } }
/* * S12.2 */ private static SignalsEnum EntryPointRA(Kernel2Database database, CardResponse cardResponse, KernelQ qManager, CardQ cardQManager, TornTransactionLogManager tornTransactionLogManager, Stopwatch sw) { #region 12.8 if (cardResponse.ApduResponse.Succeeded) #endregion { #region 12.9 if (database.TagsToWriteBeforeGenACYet.Count != 0) #endregion { #region 12.10 TLV tagToPut = database.TagsToWriteBeforeGenACYet.GetFirstAndRemoveFromList(); EMVPutDataRequest requestPutData = new EMVPutDataRequest(tagToPut); #endregion #region 12.11 cardQManager.EnqueueToInput(new CardRequest(requestPutData, CardinterfaceServiceRequestEnum.ADPU)); return(SignalsEnum.WAITING_FOR_PUT_DATA_RESPONSE_BEFORE_GEN_AC); #endregion } else { #region 12.12 byte pgacps = database.Get(EMVTagsEnum.PREGEN_AC_PUT_DATA_STATUS_DF810F_KRN2).Value[0]; pgacps = (byte)(pgacps | 0x80); database.Get(EMVTagsEnum.PREGEN_AC_PUT_DATA_STATUS_DF810F_KRN2).Value[0] = pgacps; #endregion } } #region 12.13 int mnttl = (int)Formatting.ConvertToInt32(database.GetDefault(EMVTagsEnum.MAX_NUMBER_OF_TORN_TRANSACTION_LOG_RECORDS_DF811D_KRN2).Value); if (database.IsNotEmpty(EMVTagsEnum.DRDOL_9F51_KRN2.Tag) && mnttl != 0) #endregion { #region 12.14 foreach (TORN_RECORD_FF8101_KRN2 ttr in tornTransactionLogManager.TornTransactionLogs) { string pan = Formatting.ByteArrayToHexString(database.Get(EMVTagsEnum.APPLICATION_PRIMARY_ACCOUNT_NUMBER_PAN_5A_KRN).Value); string panR = Formatting.ByteArrayToHexString(ttr.Children.Get(EMVTagsEnum.APPLICATION_PRIMARY_ACCOUNT_NUMBER_PAN_5A_KRN.Tag).Value); if (ttr.Children.IsNotEmpty(EMVTagsEnum.APPLICATION_PRIMARY_ACCOUNT_NUMBER_PAN_SEQUENCE_NUMBER_5F34_KRN.Tag)) { string sn = Formatting.ByteArrayToHexString(database.Get(EMVTagsEnum.APPLICATION_PRIMARY_ACCOUNT_NUMBER_PAN_SEQUENCE_NUMBER_5F34_KRN).Value); string snR = Formatting.ByteArrayToHexString(ttr.Children.Get(EMVTagsEnum.APPLICATION_PRIMARY_ACCOUNT_NUMBER_PAN_SEQUENCE_NUMBER_5F34_KRN.Tag).Value); if (pan == panR && sn == snR) { database.Get(EMVTagsEnum.TORN_RECORD_FF8101_KRN2).Value = ttr.Value; #region 12.17 database.TornTempRecord.Value = database.Get(EMVTagsEnum.TORN_RECORD_FF8101_KRN2).Value; #endregion #region 12.18 database.Get(EMVTagsEnum.DRDOL_RELATED_DATA_DF8113_KRN2).Value = database.TornTempRecord.Children.Get(EMVTagsEnum.DRDOL_RELATED_DATA_DF8113_KRN2.Tag).Value; EMVRecoverACRequest requestRecover = new EMVRecoverACRequest(database.Get(EMVTagsEnum.DRDOL_RELATED_DATA_DF8113_KRN2)); #endregion #region 12.19 cardQManager.EnqueueToInput(new CardRequest(requestRecover, CardinterfaceServiceRequestEnum.ADPU)); return(SignalsEnum.WAITING_FOR_RECOVER_AC); #endregion } } else { if (pan == panR) { database.Get(EMVTagsEnum.TORN_RECORD_FF8101_KRN2).Value = ttr.Value; #region 12.17 database.TornTempRecord.Value = database.Get(EMVTagsEnum.TORN_RECORD_FF8101_KRN2).Value; #endregion #region 12.18 database.Get(EMVTagsEnum.DRDOL_RELATED_DATA_DF8113_KRN2).Value = database.TornTempRecord.Children.Get(EMVTagsEnum.DRDOL_RELATED_DATA_DF8113_KRN2.Tag).Value; EMVRecoverACRequest requestRecover = new EMVRecoverACRequest(database.Get(EMVTagsEnum.DRDOL_RELATED_DATA_DF8113_KRN2)); #endregion #region 12.19 cardQManager.EnqueueToInput(new CardRequest(requestRecover, CardinterfaceServiceRequestEnum.ADPU)); return(SignalsEnum.WAITING_FOR_RECOVER_AC); #endregion } } } #endregion } #region 12.15 EMVGenerateACRequest request = PrepareGenACCommandProcedure_7_6.PrepareGenACCommand(database, qManager, cardQManager); cardQManager.EnqueueToInput(new CardRequest(request, CardinterfaceServiceRequestEnum.ADPU)); return(SignalsEnum.WAITING_FOR_GEN_AC_1); #endregion }
/* * 7.4, 7.5, 7.6 */ private static SignalsEnum EntryPointL1RSP(Kernel2Database database, CardResponse cardResponse, KernelQ qManager, TornTransactionLogManager tornTransactionLogManager) { CommonRoutines.CreateMSDiscretionaryDataRecord(database); return(CommonRoutines.PostOutcome(database, qManager, KernelMessageidentifierEnum.TRY_AGAIN, KernelStatusEnum.READY_TO_READ, new byte[] { 0x00, 0x00, 0x00 }, Kernel2OutcomeStatusEnum.END_APPLICATION, Kernel2StartEnum.B, false, KernelMessageidentifierEnum.TRY_AGAIN, cardResponse.L1Enum, null, L2Enum.STATUS_BYTES, L3Enum.NOT_SET)); }
/* * 15.2 */ private static SignalsEnum EntryPointRA(Kernel2Database database, CardResponse cardResponse, KernelQ qManager, CardQ cardQManager, TornTransactionLogManager tornTransactionLogManager, Stopwatch sw) { #region 15.5 if (cardResponse.ApduResponse.Succeeded) #endregion { #region 15.6 if (database.TagsToWriteAfterGenACYet.Count != 0) #endregion { #region 15.7 TLV tagToPut = database.TagsToWriteAfterGenACYet.GetFirstAndRemoveFromList(); EMVPutDataRequest requestPutData = new EMVPutDataRequest(tagToPut); #endregion #region 15.8 cardQManager.EnqueueToInput(new CardRequest(requestPutData, CardinterfaceServiceRequestEnum.ADPU)); return(SignalsEnum.WAITING_FOR_PUT_DATA_RESPONSE_AFTER_GEN_AC); #endregion } else { #region 15.9 byte pgacps = database.Get(EMVTagsEnum.POSTGEN_AC_PUT_DATA_STATUS_DF810E_KRN2).Value[0]; pgacps = (byte)(pgacps | 0x80); database.Get(EMVTagsEnum.POSTGEN_AC_PUT_DATA_STATUS_DF810E_KRN2).Value[0] = pgacps; #endregion } } return(DoCommon(database, cardResponse, qManager)); }
/* * S5.3 */ private static SignalsEnum EntryPointRA(Kernel2Database database, CardResponse cardResponse, KernelQ qManager, CardQ cardQManager, TornTransactionLogManager tornTransactionLogManager, Stopwatch sw) { #region 5.9 string currentTag = database.ActiveTag; #endregion TLV nextTLV = database.TagsToReadYet.GetNextGetDataTagFromList(); if (nextTLV != null) { database.ActiveTag = nextTLV.Tag.TagLable; } else { database.ActiveTag = null; } #region 5.10 if (database.ActiveTag != null) #endregion { #region 5.11 - 5.13 EMVGetDataRequest request = new EMVGetDataRequest(Formatting.HexStringToByteArray(database.ActiveTag)); cardQManager.EnqueueToInput(new CardRequest(request, CardinterfaceServiceRequestEnum.ADPU)); database.NextCommandEnum = NextCommandEnum.GET_DATA; #endregion } else { #region 5.14 if (database.ActiveAFL == null) #endregion { #region 5.15 database.NextCommandEnum = NextCommandEnum.NONE; #endregion } else { #region 5.16 - 5.18 EMVReadRecordRequest request = new EMVReadRecordRequest(database.ActiveAFL.Value.Entries[0].SFI, database.ActiveAFL.Value.Entries[0].FirstRecordNumber); cardQManager.EnqueueToInput(new CardRequest(request, CardinterfaceServiceRequestEnum.ADPU)); #endregion } } #region 5.19 if (!cardResponse.ApduResponse.Succeeded) #endregion { #region 5.20 bool parsingResult = false; EMVGetProcessingOptionsResponse response = cardResponse.ApduResponse as EMVGetProcessingOptionsResponse; parsingResult = database.ParseAndStoreCardResponse(response.ResponseData); #endregion #region 5.21 if (parsingResult) { #region 5.22 if (currentTag == response.GetResponseTags().GetFirst().Tag.TagLable) { #region 5.23 database.Get(EMVTagsEnum.DATA_TO_SEND_FF8104_KRN2).Children.AddToList(response.GetResponseTags().GetFirst()); #endregion } else { #region 5.24 database.Get(EMVTagsEnum.DATA_TO_SEND_FF8104_KRN2).Children.AddToList(TLV.Create(currentTag)); #endregion } #endregion } else { #region 5.24 database.Get(EMVTagsEnum.DATA_TO_SEND_FF8104_KRN2).Children.AddToList(TLV.Create(currentTag)); #endregion } #endregion } else { #region 5.24 database.Get(EMVTagsEnum.DATA_TO_SEND_FF8104_KRN2).Children.AddToList(TLV.Create(currentTag)); #endregion } return(State_4_5_6_CommonProcessing.DoCommonProcessing("State_5_WaitingForGetDataResponse", database, qManager, cardQManager, sw, tornTransactionLogManager)); }