Exemplo n.º 1
0
        public virtual byte[] PutDataFCI(Apdu apdu)
        {
            TLV fci = new TLV(apdu.Data);
            var Aid = fci[0x84];
            var AC  = fci[0x86];
            var SM  = card.GetSMTLV(fci);

            if (Aid != null && Aid.Length > 16)
            {
                return(Error.DataFieldNotValid);
            }

            if (context.CurFile is EF)
            {
                if (!handler.IsVerifiedAC(context.CurFile, EF_AC.AC_ADMIN))
                {
                    return(Error.SecurityStatusNotSatisfied);
                }
            }
            else if (context.CurFile is DF)
            {
                if (!handler.IsVerifiedAC(context.CurFile, DF_AC.AC_ADMIN))
                {
                    return(Error.SecurityStatusNotSatisfied);
                }
            }

            if (context.CurEF != null && Aid != null)
            {
                return(Error.CommandIncompatibleWithFileStructure);
            }
            if (AC != null)
            {
                context.CurFile.AC.Set(AC);
            }
            if (SM != null)
            {
                context.CurFile.SM.Set(SM);
            }

            if (context.CurDF != null)
            {
                if (Aid != null)
                {
                    context.CurDF.AID = Aid;
                }
            }

            return(Error.Ok);
        }
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);
        }