Ejemplo n.º 1
0
        static PDOLResolver CreateResolver()
        {
            var rnd      = new Random();
            var resolver = new PDOLResolver();

            //TTQ
            resolver.PDOLCodesResolvers.Add(0x9F66, (l) =>
            {
                return(new byte[] { 0xB6, 0x20, 0xC0, 0x00 });
            });

            //Amount
            resolver.PDOLCodesResolvers.Add(0x9F02, (l) =>
            {
                var buff    = new byte[l];
                buff[l - 1] = 1;
                return(buff);
            });

            //Unpredictable number
            resolver.PDOLCodesResolvers.Add(0x9F37, (l) =>
            {
                var buff = new byte[l];
                rnd.NextBytes(buff);
                return(buff);
            });

            //Transaction Country
            resolver.PDOLCodesResolvers.Add(0x9F1A, (l) =>
            {
                return(new byte[] { 0x06, 0x43 });
            });
            //Transaction Currency code
            resolver.PDOLCodesResolvers.Add(0x5F2A, (l) =>
            {
                return(new byte[] { 0x06, 0x43 });
            });
            //Transaction date
            resolver.PDOLCodesResolvers.Add(0x9A03, (l) =>
            {
                var decYear  = DateTime.Now.Year % 100;
                var decMonth = DateTime.Now.Month;
                var decDate  = DateTime.Now.Day;
                //bcd date
                return(new byte[]
                {
                    (byte)((decYear / 10 << 4) | (decYear % 10)),
                    (byte)((decMonth / 10 << 4) | (decMonth % 10)),
                    (byte)((decDate / 10 << 4) | (decDate % 10))
                });
            });

            resolver.PDOLCodesResolvers.Add(0x9F40, (l) =>
            {
                return(new byte[] { 0x70, 0x00, 0x80, 0xB0, 0x01 });
            });

            return(resolver);
        }
Ejemplo n.º 2
0
        private bool ProcessCardFromAID(byte[] aid, EMVCard card)
        {
            var selectedApplication = Handler.SelectApplication(aid);

            if (selectedApplication.Tag != 0x6F)
            {
                return(false);
            }

            var aidInnerEntries = selectedApplication.ReadInnerTlvTags();

            var aidFCI = aidInnerEntries.FirstOrDefault(x => x.Tag == 0xA5);

            if (aidFCI == null)
            {
                return(false);
            }

            var aidFCIInner = aidFCI.ReadInnerTlvTags();

            var aidNameTag = aidFCIInner.FirstOrDefault(x => x.Tag == 0x50);
            var aidName    = aidNameTag == null ? "Unknown" : Encoding.ASCII.GetString(aidNameTag.Value);

            card.CardName = aidName;

            var pdol = aidFCIInner.FirstOrDefault(x => x.Tag == 0x9F38);

            byte[] PDOLResponse = null;
            if (pdol == null)
            {
                PDOLResponse = new byte[] { 0x83, 0x00 };
            }
            else
            {
                if (PDOLResolver == null)
                {
                    throw new SL600Sharp.SL600Exception("No PDOL resolver availible");
                }

                PDOLResponse = PDOLResolver.Resolve(pdol.Value);
            }

            var gpoResponse = Handler.GetProcessingOptions(PDOLResponse);

            byte[] afl = null;
            ushort auc = 0;

            if (gpoResponse.Tag == 0x77)
            {
                var gpoResponseInner = gpoResponse.ReadInnerTlvTags();
                var aucTag           = gpoResponseInner.FirstOrDefault(x => x.Tag == 0x82);
                var aflTag           = gpoResponseInner.FirstOrDefault(x => x.Tag == 0x94);

                if (aflTag == null || aucTag == null)
                {
                    throw new SL600Sharp.SL600Exception("No AUC or AFL presented");
                }

                auc = (ushort)((aucTag.Value[0] << 8) | aucTag.Value[0]);
                afl = aflTag.Value;
            }
            else if (gpoResponse.Tag == 0x80)
            {
                auc = (ushort)((gpoResponse.Value[0] << 8) | gpoResponse.Value[1]);
                afl = new byte[gpoResponse.Value.Length - 2];
                Array.ConstrainedCopy(gpoResponse.Value, 2, afl, 0, afl.Length);
            }
            else
            {
                throw new SL600Sharp.SL600Exception($"Not supported tag for GPO operation ({gpoResponse.Tag.Value.ToString("X2")})");
            }

            for (int i = 0; i < afl.Length; i += 4)
            {
                var sfiFromAFL = afl[i] >> 3;
                var firstRec   = afl[i + 1];
                var lastRec    = afl[i + 2];
                var sda        = afl[i + 3];

                for (byte page = firstRec; page <= lastRec; page++)
                {
                    ProcessMembank(Handler.ReadRecord((byte)sfiFromAFL, page), card);
                }
            }

            return(true);
        }