Exemplo n.º 1
0
        private void creaEFTLVToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (treeView1.SelectedNode == null)
            {
                return;
            }
            ICardObject obj = treeView1.SelectedNode.Tag as ICardObject;

            if (!(obj is DF))
            {
                return;
            }
            DF df = obj as DF;

            card.CreateEFLinearTLV(1, df, 10);
        }
Exemplo n.º 2
0
        public virtual byte[] processCommand(Apdu apdu)
        {
            CardContext context = handler.Context;

            if (context.CurDF == null)
            {
                return(Error.ClaNotValid);
            }

            TLV fciExt = new TLV(apdu.Data);

            if (fciExt[0x62] == null)
            {
                return(Error.DataFieldNotValid);
            }
            TLV fci     = new TLV(fciExt[0x62]);
            var Size1   = fci[0x80];
            var Size2   = fci[0x81];
            var Options = fci[0x82];
            var Id      = fci[0x83];
            var Fixed   = fci[0x85];
            var AC      = fci[0x86];
            var SM      = card.GetSMTLV(fci);

            if (Size1 != null && Size2 != null)
            {
                return(Error.DataFieldNotValid);
            }
            if (Options == null)
            {
                return(Error.DataFieldNotValid);
            }
            if (Id == null)
            {
                return(Error.DataFieldNotValid);
            }
            if (Fixed == null)
            {
                return(Error.DataFieldNotValid);
            }
            if (AC == null)
            {
                return(Error.DataFieldNotValid);
            }

            if (Options.Length != 3)
            {
                return(Error.DataFieldNotValid);
            }
            if (Id.Length != 2)
            {
                return(Error.DataFieldNotValid);
            }
            if (Fixed.Length != 1)
            {
                return(Error.DataFieldNotValid);
            }

            if (Fixed[0] != 1)
            {
                return(Error.DataFieldNotValid);
            }
            if (Options[0] == 0x38 && Size2 == null)
            {
                return(Error.DataFieldNotValid);
            }

            if (!handler.IsVerifiedAC(context.CurDF, DF_AC.AC_CREATE))
            {
                return(Error.SecurityStatusNotSatisfied);
            }
            ushort newId = Util.ToUShort(Id);

            if (newId == 0x3F00 || newId == 0x3FFF || newId == 0xFFFF)
            {
                return(Error.DataFieldNotValid);
            }

            if (context.CurDF.GetChildEForDF(newId) != null)
            {
                return(Error.FileAlreadyExists);
            }

            CardSelectable obj = null;

            if (Options[0] == 0x38)
            {
                obj = card.CreateDF(newId, context.CurDF);
            }
            else if (Options[0] == 0x01)
            {
                obj = card.CreateEF(newId, context.CurDF, Util.ToUInt(Size1));
            }
            else if (Options[0] == 0x02)
            {
                obj = new EFLinearFixed(newId, card, context.CurDF, Util.ToUInt(Size1), Options[2]);
            }
            else if (Options[0] == 0x05)
            {
                obj = card.CreateEFLinearTLV(newId, context.CurDF, Util.ToUInt(Size1));
            }
            else if (Options[0] == 0x06)
            {
                obj = new EFCyclic(newId, card, context.CurDF, Util.ToUInt(Size1), Options[2]);
            }
            else
            {
                return(Error.DataFieldNotValid);
            }

            if (AC != null)
            {
                obj.AC.Set(AC);
            }
            if (SM != null)
            {
                obj.SM.Set(SM);
            }

            if (obj != null)
            {
                context.CurFile = obj;
            }

            return(Error.Ok);
        }