예제 #1
0
        private async Task <List <ApplicationInformation> > ListPseApplications(Application application)
        {
            var result = new List <ApplicationInformation>();
            var record = 1;

            while (true)
            {
                var res = await card.ReadAsync(application.Template.Sfi, record);

                if (res.Body is null || res.Body.Length < 1)
                {
                    break;
                }
                ;
                var tlv = new Tlv.Tlv(res.Body);
                if (!tlv.ContainsKey(0x70))
                {
                    throw new InvalidOperationException("Invalid Pse Record");
                }
                tlv = new Tlv.Tlv(tlv[0x70]);
                if (!tlv.ContainsKey(0x61))
                {
                    throw new InvalidOperationException("Invalid Pse Record");
                }
                var info = TlvSerializer.Deserialize <ApplicationInformation>(tlv, 0x61);
                result.Add(info);
                record++;
            }

            return(result);
        }
        public void TestDeserialiser()
        {
            var tlvBytes = Helpers.HexStringToByteArray("6F1A840E315041592E5359532E4444463031A5088801015F2D02656E");
            var tlv      = new Tlv.Tlv(tlvBytes);

            var result = TlvSerializer.Deserialize <Application>(tlv, "0x6f");

            Assert.NotNull(result);
        }
예제 #3
0
        public async Task <ProcessingOptions> GetProcessingAsync(Tlv.Tlv pdol)
        {
            var pdolData = pdol.Encode();
            var res      = await SendApduAsync(new APDUCommand
            {
                Class = 0x80, Instruction = 0xA8, Data = pdolData
            });

            var body = new Tlv.Tlv(res.Body);

            if (body.ContainsKey(0x77))
            {
                return(TlvSerializer.Deserialize <ProcessingOptions>(body, 0x77));
            }

            if (!body.TryGetValue(0x80, out byte[] raw))
예제 #4
0
        private async void ProcessCardInformation()
        {
            var groupTlv = new Tlv.Tlv();

            foreach (var app in ProcessingOptions.ApplicationFileList)
            {
                var sdaCount = app.SdaCount;

                for (int i = app.Start; i <= app.End; i++)
                {
                    var record = await card.ReadAsync(app.Sfi, i);

                    var body = new Tlv.Tlv(record.Body);
                    if (!body.ContainsKey(0x70))
                    {
                        throw new InvalidOperationException("malformed application file");
                    }
                    if (sdaCount > 0)
                    {
                        if (app.Sfi <= 10)
                        {
                            sdaData.AddRange(body[0x70]);
                        }
                        else
                        {
                            sdaData.AddRange(record.Body);
                        }
                        sdaCount--;
                    }

                    var template = new Tlv.Tlv(body[0x70]);
                    groupTlv.CopyFrom(template);
                }
            }
            CardInformation = TlvSerializer.Deserialize <CardInformation>(groupTlv);
        }
예제 #5
0
        public async Task <Application> SelectApplicationAsync(byte[] name, bool first)
        {
            var rsp = await SelectAsync(name, first);

            if (rsp.SW1 == 0x6A && rsp.SW2 == 0x82)
            {
                return(null);
            }
            if (rsp.SW1 != 0x90 && rsp.SW2 != 0x00)
            {
                return(null);
            }

            var tlv = new Tlv.Tlv(rsp.Body);

            try
            {
                return(TlvSerializer.Deserialize <Application>(tlv, 0x6f));
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("Error decoding Tlv");
            }
        }