Beispiel #1
1
        bool isArtigoConjunto(String artigo)
        {
            StdBELista tblArtigo = new StdBELista();
            bool       rv        = false;

            try
            {
                tblArtigo = BSO.Consulta("select TipoComponente from Artigo where Artigo = '" + artigo + "'");


                //alterar armazem dos artigos na linha
                if (tblArtigo.Vazia() == false)
                {
                    rv = tblArtigo.DaValor <int>("TipoComponente") == 1 ? true : false;
                }
            }
            catch (Exception err)
            {
                PSO.Dialogos.MostraErro("[Consulta Artigo]: " + err.ToString());
                rv = false;
            }



            return(rv);
        }
Beispiel #2
0
        private void Remove()
        {
            try
            {
                int number = (int)numericUpDownNumber.Value;

                // Start a transaction
                BSO.IniciaTransaccao();

                // Delete the rows
                RemoveRows(number);

                // Delete the cabec
                RemoveCabec(number);

                // Finish the transaction
                BSO.TerminaTransaccao();
            }
            catch (Exception ex)
            {
                // Abort the transaction
                BSO.DesfazTransaccao();
                throw ex;
            }
        }
Beispiel #3
0
        private void Save()
        {
            try
            {
                int numero = 0;

                // Start a transaction
                BSO.IniciaTransaccao();

                // Save the cabec and returns the record number
                SaveCabec(ref numero);

                // Save the rows with the returned record number
                SaveRows(numero);

                // Finish the transaction
                BSO.TerminaTransaccao();
            }
            catch (Exception ex)
            {
                // Abort the transaction
                BSO.DesfazTransaccao();
                throw ex;
            }
        }
Beispiel #4
0
        public void getSMKeys(Apdu apdu, out BSO sigIn, out BSO encIn, out BSO sigOut, out BSO encOut)
        {
            CardContext context = handler.Context;

            sigIn = null;
            encIn = null;
            sigOut = null;
            encOut = null;

            ushort pinId = (ushort)(apdu.P2 & 0x7f);
            BSO pin = null;
            if (pinId != 0)
            {
                bool backTrack = (apdu.P2 & 0x80) != 0;
                if (backTrack)
                    pin = context.CurDF.GetChildBSO(pinId, backTrack);
                else
                    pin = context.CurDF.Owner.MasterFile.GetChildBSO(pinId, false);
            }
            else
                pin = handler.GetEnvironmentKey(SecurityEnvironmentComponent.TEST);

            if (pin == null)
                throw new ISO7816Exception(Error.ObjectNotFound);

            encIn = handler.getSMKey(pin, BSO_SM.SM_ENC_USE);
            sigIn = handler.getSMKey(pin, BSO_SM.SM_SIG_USE);

        }
        public void getSMKeys(Apdu apdu, out BSO sigIn, out BSO encIn, out BSO sigOut, out BSO encOut)
        {
            sigOut = null;
            encOut = null;

            BSO key = null;

            if (apdu.P1 == 0x80 && apdu.P2 == 0x86)
            {
                key = handler.GetEnvironmentKey(SecurityEnvironmentComponent.CON);
            }
            else if (apdu.P1 == 0x86 && apdu.P2 == 0x80)
            {
                key = handler.GetEnvironmentKey(SecurityEnvironmentComponent.CON);
            }
            else if (apdu.P1 == 0x9E && apdu.P2 == 0x9A)
            {
                key = handler.GetEnvironmentKey(SecurityEnvironmentComponent.CDS);
            }


            encIn  = handler.getSMKey(key, BSO_SM.SM_ENC_USE);
            sigIn  = handler.getSMKey(key, BSO_SM.SM_SIG_USE);
            encOut = handler.getSMKey(key, BSO_SM.SM_ENC_USE_OUT);
            sigOut = handler.getSMKey(key, BSO_SM.SM_SIG_USE_OUT);
        }
 public void getSMKeys(Apdu apdu, out BSO sigIn, out BSO encIn, out BSO sigOut, out BSO encOut)
 {
     sigIn = null;
     encIn = null;
     sigOut = null;
     encOut = null;
 }
        public void getSMKeys(Apdu apdu, out BSO sigIn, out BSO encIn, out BSO sigOut, out BSO encOut)
        {
            CardContext context = handler.Context;

            sigOut = null;
            encOut = null;

            ushort bsoId     = Util.ToUShort(apdu.P1, (byte)(apdu.P2 & 0x7f));
            bool   backTrack = (apdu.P2 & 0x80) != 0;
            BSO    bso       = null;

            if (backTrack)
            {
                bso = context.CurDF.GetChildBSO(bsoId, backTrack);
            }
            else
            {
                bso = context.CurDF.Owner.MasterFile.GetChildBSO(bsoId, false);
            }
            if (bso == null)
            {
                throw new ISO7816Exception(Error.FileNotFound);
            }

            encIn = handler.getSMKey(bso, BSO_SM.SM_ENC_CHANGE);
            sigIn = handler.getSMKey(bso, BSO_SM.SM_SIG_CHANGE);
        }
 public void getSMKeys(Apdu apdu, out BSO sigIn, out BSO encIn, out BSO sigOut, out BSO encOut)
 {
     sigIn  = null;
     encIn  = null;
     sigOut = null;
     encOut = null;
 }
Beispiel #9
0
        public BSOBaseModel(BSO bso) : base()
        {
            if (bso != null)
            {
                this.BSO_ID = bso.Id;
                this.TemporaryPolicyNumber = bso.TemporaryPolicyNumber;
                this.PolicyPartyNumber     = bso.PolicyPartyNumber;
                this.Status           = bso.Status;
                this.StatusDate       = bso.StatusDate;
                this.DeliveryCenterId = bso.DeliveryCenterId;
                this.DeliveryCenter   = bso.DeliveryCenter;
                this.DeliveryPointId  = bso.DeliveryPointId;
                this.DeliveryPoint    = bso.DeliveryPoint;
                this.Comment          = bso.Comment;
                this.UserId           = bso.UserId;
                this.History          = bso.History;
                this.VisitGroupId     = bso.VisitGroupId;
                this.ResponsibleID    = bso.ResponsibleID;
                this.ChangeDate       = bso.ChangeDate;

                List <BSOHistoryModel> listBsoHistoryModel = new List <BSOHistoryModel>();
                foreach (BSOHistoryItem a in bso.History)
                {
                    BSOHistoryModel bsoHistoryModel = new BSOHistoryModel(a);
                    listBsoHistoryModel.Add(bsoHistoryModel);
                }
                this.HistoryModel = listBsoHistoryModel;
            }
        }
Beispiel #10
0
        private void ValidateChangeOther(BSOSaveDataModel bsoSaveDataModel, BSO bso)
        {
            if (bso.PolicyPartyNumber == bsoSaveDataModel.PolicyPartyNumber &&
                bso.DeliveryPointId == bsoSaveDataModel.DeliveryPointId &&
                bso.Status.Id == bsoSaveDataModel.StatusId &&
                bso.ResponsibleID == bsoSaveDataModel.ResponsibleID &&
                bso.VisitGroupId == bsoSaveDataModel.VisitGroupId &&
                bso.StatusDate == bsoSaveDataModel.StatusDate)
            {
                isValid = false;
                this.Messages.Add("Не было изменений по существу.");
            }

            if (bsoSaveDataModel.StatusId == (long)ListBSOStatusID.OnResponsible && bsoSaveDataModel.ResponsibleID == null)
            {
                isValid = false;
                this.Messages.Add("При статусе [На ответственном] необходимо выбрать ответственного.");
            }

            if (bsoSaveDataModel.StatusId == (long)ListBSOStatusID.FailOnResponsible && bsoSaveDataModel.ResponsibleID == null)
            {
                isValid = false;
                this.Messages.Add("При статусе [Испорчен, на ответственном] необходимо выбрать ответственного.");
            }

            if (bsoSaveDataModel.StatusId == (long)ListBSOStatusID.OnDelivery && bsoSaveDataModel.DeliveryPointId == null)
            {
                isValid = false;
                this.Messages.Add("Вы поставили статус [На точке], но не указали точку выдачи.");
            }
        }
        public void PutDataFCIKeys(Apdu apdu, out BSO sigIn, out BSO encIn, out BSO sigOut, out BSO encOut)
        {
            if (context.CurFile == null)
            {
                throw new ISO7816Exception(Error.NoCurrentEFSelected);
            }

            sigOut = null;
            encOut = null;

            if (context.CurFile is DF)
            {
                encIn = handler.getSMKey(context.CurFile, DF_SM.SM_ENC_ADMIN);
                sigIn = handler.getSMKey(context.CurFile, DF_SM.SM_SIG_ADMIN);
            }
            else if (context.CurFile is EF)
            {
                encIn = handler.getSMKey(context.CurFile, EF_SM.SM_ENC_ADMIN);
                sigIn = handler.getSMKey(context.CurFile, EF_SM.SM_SIG_ADMIN);
            }
            else
            {
                throw new ISO7816Exception(Error.NoCurrentEFSelected);
            }
        }
        public virtual byte[] processCommand(Apdu apdu)
        {
            CardContext context = handler.Context;

            ushort bsoId     = Util.ToUShort(apdu.P1, (byte)(apdu.P2 & 0x7f));
            bool   backTrack = (apdu.P2 & 0x80) != 0;
            BSO    bso       = null;

            if (backTrack)
            {
                bso = context.CurDF.GetChildBSO(bsoId, backTrack);
            }
            else
            {
                bso = context.CurDF.Owner.MasterFile.GetChildBSO(bsoId, false);
            }
            if (bso == null)
            {
                return(Error.FileNotFound);
            }

            if (!handler.IsVerifiedAC(bso, BSO_AC.AC_CHANGE))
            {
                return(Error.SecurityStatusNotSatisfied);
            }

            if (bso.Data.Length != apdu.Data.Length)
            {
                return(Error.DataFieldNotValid);
            }
            bso.Data = apdu.Data;

            handler.UnblockBSO(bso);
            return(Error.Ok);
        }
        public void GenerateKey(BSO privExpBso, BSO moduleBso, EFLinearTLV pubKeyEF, ushort pubExpLen)
        {
            BigInteger publicExponent;
            BigInteger privateExponent;
            BigInteger module;

            BigInteger.GenerateRSAKey(1024, pubExpLen, out publicExponent, out module, out privateExponent);

            ByteArray baPrivateExponent = new ByteArray(new byte[] { 0, 0 });

            baPrivateExponent    = baPrivateExponent.Append(privateExponent.getBytes());
            baPrivateExponent[0] = (byte)(baPrivateExponent.Size - 1);
            privExpBso.Data      = baPrivateExponent;

            ByteArray baModule = new ByteArray(new byte[] { 0, 0 });

            baModule       = baModule.Append(module.getBytes());
            baModule[0]    = (byte)(baModule.Size - 1);
            moduleBso.Data = baModule;

            TLV modTlv = new TLV();

            modTlv.addTag(0x10, baModule);
            pubKeyEF.Append(modTlv.GetBytes());

            ByteArray baPublicExponent = new ByteArray(new byte[] { 0, 0 });

            baPublicExponent    = baPublicExponent.Append(publicExponent.getBytes());
            baPublicExponent[0] = (byte)(baPublicExponent.Size - 1);

            TLV pubExpTlv = new TLV();

            pubExpTlv.addTag(0x11, baPublicExponent);
            pubKeyEF.Append(pubExpTlv.GetBytes());
        }
        public void getSMKeys(Apdu apdu, out BSO sigIn, out BSO encIn, out BSO sigOut, out BSO encOut)
        {
            CardContext context = handler.Context;

            sigIn = null;
            encIn = null;
            sigOut = null;
            encOut = null;


            ushort bsoId = (ushort)(apdu.P2 & 0x7f);
            bool backTrack = (apdu.P2 & 0x80) != 0;
            BSO bso = null;
            if (backTrack)
                bso = context.CurDF.GetChildBSO(bsoId, backTrack);
            else
                bso = context.CurDF.Owner.MasterFile.GetChildBSO(bsoId, false);

            if (bso == null) 
                throw new ISO7816Exception(Error.ObjectNotFound);

            encIn = handler.getSMKey(bso, BSO_SM.SM_ENC_UNBLOCK);
            sigIn = handler.getSMKey(bso, BSO_SM.SM_SIG_UNBLOCK);

        }
        byte[] UpdateBSO(BSO bso, TLV oci)
        {
            var AC   = oci[0x86];
            var SM   = card.GetSMTLV(oci);
            var Data = oci[0x8F];

            var curDF = context.CurDF;

            if (curDF == null)
            {
                return(Error.InsNotValid);
            }

            if (!handler.IsVerifiedAC(context.CurDF, DF_AC.AC_UPDATE))
            {
                return(Error.SecurityStatusNotSatisfied);
            }

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

            return(Error.Ok);
        }
Beispiel #16
0
        public ActionResult BSOHistory(long id)
        {
            BSO          bso   = bsoBusinessLogic.BSO_GetByID(id);
            BSOBaseModel model = new BSOBaseModel(bso);

            if (bso.VisitGroupId != null)
            {
                ClientVisit clientVisit = clientBusinessLogic.ClientVisit_GetLastClientVisitInGroup((long)bso.VisitGroupId);
                model.ClientVisitId = clientVisit.Id;
                model.ClientId      = clientVisit.ClientId;
            }

            foreach (var a in model.HistoryModel)
            {
                if (model.UserId != null)
                {
                    User user = userBusinessLogic.User_Get((long)a.UserId);
                    if (user != null)
                    {
                        a.UserName = user.Lastname + " " + user.Firstname.Remove(1) + "." + " " + user.Secondname.Remove(1) + ".";
                    }
                }

                if (a.ResponsibleID != null)
                {
                    User user = userBusinessLogic.User_Get((long)a.ResponsibleID);
                    if (user != null)
                    {
                        a.ResponsibleName = user.Lastname + " " + user.Firstname.Remove(1) + "." + " " + user.Secondname.Remove(1) + ".";
                    }
                }
            }
            return(View(model));
        }
Beispiel #17
0
 public void PlayBSO(BSO bso)
 {
     if (BSOs[(int)bso] != null && BSOAudioSource != null)
     {
         BSOAudioSource.clip = BSOs[(int)bso];
         BSOAudioSource.Play();
     }
 }
Beispiel #18
0
        private void ValidateChangeStatusBSO(BSOSaveDataModel bsoSaveDataModel, BSO bso, ModelValidationContext context)
        {
            string Message = BSOStatusValidator.Validator(bso.Status.Id, (long)bsoSaveDataModel.StatusId, context.currenUser);

            if (!string.IsNullOrEmpty(Message))
            {
                isValid = false; this.Messages.Add(Message);
            }
        }
Beispiel #19
0
        public BSO BSO_GetByNumber(string temporaryPolicyNumber)
        {
            List <SqlParameter> parameters = new List <SqlParameter>();

            parameters.AddInputParameter("@TemporaryPolicyNumber", SqlDbType.NVarChar, temporaryPolicyNumber);
            BSO bso = Execute_Get(BSOMaterializer.Instance, "BSO_GetByNumber", parameters);

            return(bso);
        }
Beispiel #20
0
        public BSO BSO_GetByID(long bso_id)
        {
            List <SqlParameter> parameters = new List <SqlParameter>();

            parameters.AddInputParameter("@BSO_ID", SqlDbType.BigInt, bso_id);
            BSO bso = Execute_Get(BSOMaterializer.Instance, "BSO_GetByID", parameters);

            return(bso);
        }
Beispiel #21
0
        public void getSMKeys(Apdu apdu, out BSO sigIn, out BSO encIn, out BSO sigOut, out BSO encOut)
        {
            var context = handler.Context;

            sigOut = null;
            encOut = null;

            encIn = handler.getSMKey(context.CurDF, DF_SM.SM_ENC_CREATE);
            sigIn = handler.getSMKey(context.CurDF, DF_SM.SM_SIG_CREATE);
        }
        public void getSMKeys(Apdu apdu, out BSO sigIn, out BSO encIn, out BSO sigOut, out BSO encOut)
        {
            var context = handler.Context;

            sigOut = null;
            encOut = null;

            encIn = handler.getSMKey(context.CurDF, DF_SM.SM_ENC_CREATE);
            sigIn = handler.getSMKey(context.CurDF, DF_SM.SM_SIG_CREATE);
        }
Beispiel #23
0
        public void PutDataSEKeys(Apdu apdu, out BSO sigIn, out BSO encIn, out BSO sigOut, out BSO encOut) {
            sigOut = null;
            encOut = null;

            if (context.CurDF == null)
                throw new ISO7816Exception(Error.ClaNotValid);

            encIn = handler.getSMKey(context.CurDF, DF_SM.SM_ENC_UPDATE_APPEND);
            sigIn = handler.getSMKey(context.CurDF, DF_SM.SM_SIG_UPDATE_APPEND);
        }
        public bool IsVerifiedAC(ICardObject obj, byte ac)
        {
            if (!(obj is IObjectWithAC))
            {
                throw new ISO7816Exception(Error.InternalError);
            }
            IObjectWithAC acObj     = obj as IObjectWithAC;
            byte          condition = acObj.AC[ac];

            if (condition == AC.Never)
            {
                return(false);
            }
            if (condition == AC.Always)
            {
                return(true);
            }
            BSO refrencedObject = obj is DF ? (obj as DF).GetChildBSO(condition, true) : obj.Parent.GetChildBSO(condition, true);

            if (context.securityStatus.ContainsKey(condition))
            {
                BSO bso = context.securityStatus[condition];
                if (refrencedObject == bso)
                {
                    if (bso.CurValidityCounter == 0)
                    {
                        context.securityStatus.Remove((byte)bso.ID);
                        return(false);
                    }
                    else if (bso.CurValidityCounter != 0xff)
                    {
                        bso.CurValidityCounter--;
                    }
                    return(true);
                }
                return(false);
            }
            else
            {
                // potrebbe essereun logical
                if (refrencedObject == null)
                {
                    return(false);
                }
                if (refrencedObject.Algo == BSOAlgo.Logic)
                {
                    int exprLen;
                    return(TestLogic(refrencedObject, refrencedObject.Data.Length - 1, out exprLen));
                }
                else
                {
                    return(false);
                }
            }
        }
        public static byte[] GetSMResponse(Apdu apdu, byte[] resp, BSO encOut, BSO sigOut, byte[] random)
        {
            TLV       respTLV   = new TLV();
            ByteArray ClearData = new ByteArray(resp).Sub(0, resp.Length - 2);

            byte[] CypherTextObject = null;
            if (encOut == null && sigOut == null)
            {
                if (ClearData.Size != 0)
                {
                    respTLV[0x81] = ClearData;
                }
            }
            else
            {
                if (encOut != null)
                {
                    respTLV[0x87]    = new ByteArray(1).Append(CardHandler.encrypt3DES(encOut.Data, ClearData));
                    CypherTextObject = respTLV[0x87];
                }
                else
                {
                    if (ClearData.Size != 0)
                    {
                        respTLV[0x81] = ClearData;
                    }
                }
                if (sigOut != null)
                {
                    if (random == null)
                    {
                        throw new ISO7816Exception(Error.ConditionsOfUseNotSatisfied);
                    }
                    var MACObject = new ByteArray(random);
                    MACObject = MACObject.Append(ByteArray.ANSIPad(new ByteArray(apdu.GetBytes()).Left(4)));
                    TLV MacTLV = new TLV();
                    if (CypherTextObject != null)
                    {
                        MacTLV[0x87] = CypherTextObject;
                    }
                    else
                    {
                        MacTLV[0x81] = ClearData;
                    }
                    MACObject = MACObject.Append(MacTLV.GetBytes());
                    var mac = CardHandler.getMAC(sigOut.Data, ByteArray.ANSIPad(MACObject));
                    respTLV[0x8e] = mac;
                }
            }
            ByteArray smResp = new ByteArray(respTLV.GetBytes());

            smResp = smResp.Append(new byte[] { resp[resp.Length - 2], resp[resp.Length - 1] });
            return(smResp);
        }
Beispiel #26
0
        public void getSMKeys(Apdu apdu, out BSO sigIn, out BSO encIn, out BSO sigOut, out BSO encOut)
        {
            context = handler.Context;

            if (apdu.P1 == 0x01 && apdu.P2 == 0x6E)
                PutDataOCIKeys(apdu, out sigIn, out encIn, out sigOut, out encOut);
            else if (apdu.P1 == 0x01 && apdu.P2 == 0x6F)
                PutDataFCIKeys(apdu, out sigIn, out encIn, out sigOut, out encOut);
            else if (apdu.P1 == 0x01 && apdu.P2 == 0x6D)
                PutDataSEKeys(apdu, out sigIn, out encIn, out sigOut, out encOut);
            else throw new ISO7816Exception(Error.P1OrP2NotValid);
        }
 bool IsInScope(DF scope, BSO obj)
 {
     if (scope == obj.Parent)
     {
         return(true);
     }
     if (scope.Parent == null)
     {
         return(false);
     }
     return(IsInScope(scope.Parent, obj));
 }
Beispiel #28
0
        private void ValidateInternalFields(
            BSOSaveDataModel bsoSaveDataModel,
            ModelValidationContext context)
        {
            isValid = true;
            BusinessLogic.BSOBusinessLogic bsoLogic = new BusinessLogic.BSOBusinessLogic();
            BSO bso = bsoLogic.BSO_GetByNumber(bsoSaveDataModel.TemporaryPolicyNumber);

            ValidateChangeStatusBSO(bsoSaveDataModel, bso, context);
            ValidateChangeOther(bsoSaveDataModel, bso);
            ValidateChangeVisitGroupId(bsoSaveDataModel, bso);
        }
Beispiel #29
0
        private void EditRows(int number)
        {
            StringBuilder sql = new StringBuilder();

            sql.AppendLine("SELECT		linhas.*, DescArtigo = art.Descricao, ent.Nome");
            sql.AppendLine("FROM		TDU_LinhasAnomalias	linhas");
            sql.AppendLine("INNER JOIN	Artigo				art		ON linhas.CDU_Artigo = art.Artigo");
            sql.AppendLine("LEFT JOIN	(");
            sql.AppendLine("						SELECT TipoEntidade = 'C', Entidade = Cliente, Nome FROM Clientes");
            sql.AppendLine("				UNION	SELECT TipoEntidade = 'F', Entidade = Fornecedor, Nome FROM Fornecedores");
            sql.AppendLine("				UNION	SELECT TipoEntidade = 'O', Entidade = Terceiro, Nome FROM OutrosTerceiros");
            sql.AppendLine("			)					ent		ON linhas.CDU_TipoEntidade = ent.TipoEntidade AND linhas.CDU_Entidade = ent.Entidade");
            sql.AppendLine(PSO.Sql.FormatSQL("WHERE       linhas.CDU_Numero = @1@", number));

            StdBELista list = BSO.Consulta(sql.ToString());

            if (list != null)
            {
                int row = 1;

                while (!list.NoFim())
                {
                    // Grupo Artigo
                    priGrelha1.SetGRID_SetValorCelula(row, colArtigo, list.Valor("CDU_Artigo"));
                    priGrelha1.SetGRID_SetValorCelula(row, colDescArtigo, list.Valor("DescArtigo"));
                    priGrelha1.SetGRID_SetValorCelula(row, colLote, list.Valor("CDU_Lote"));
                    priGrelha1.SetGRID_SetValorCelula(row, colNumSerie, list.Valor("CDU_NumSerie"));

                    // Grupo Entidade
                    string tipoEntidade = list.Valor("CDU_TipoEntidade");
                    SetValorComboboxGrelha(colTipoEntidade, row, GetDescTipoEntidade(tipoEntidade));

                    priGrelha1.SetGRID_SetValorCelula(row, colEntidade, list.Valor("CDU_Entidade"));
                    priGrelha1.SetGRID_SetValorCelula(row, colNomeEntidade, list.Valor("Nome"));

                    // Grupo Anomalia
                    int tipoAnomalia = list.Valor("CDU_TipoAnomalia");
                    priGrelha1.SetGRID_SetValorCelula(row, colTipoAnomalia, GetDescTipoAnomalia(tipoAnomalia));
                    priGrelha1.SetGRID_SetValorCelula(row, colDescricao, list.Valor("CDU_Descricao"));
                    priGrelha1.SetGRID_SetValorCelula(row, colQuantidade, list.Valor("CDU_Quantidade"));
                    priGrelha1.SetGRID_SetValorCelula(row, colUnidade, list.Valor("CDU_Unidade"));

                    // Grupo Localização
                    priGrelha1.SetGRID_SetValorCelula(row, colArmazem, list.Valor("CDU_Armazem"));
                    priGrelha1.SetGRID_SetValorCelula(row, colLocalizacao, list.Valor("CDU_Localizacao"));
                    priGrelha1.SetGRID_SetValorCelula(row, colEstado, list.Valor("CDU_Estado"));

                    list.Seguinte();
                    row++;
                }
            }
        }
Beispiel #30
0
        public ActionResult GoToBSOHistory(string temporaryPolicyNumber)
        {
            BSO bso = bsoBusinessLogic.BSO_GetByNumber(temporaryPolicyNumber);

            if (bso != null)
            {
                return(RedirectToAction("BSOHistory", "BSO", new { id = bso.Id }));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
        public void PutDataOCIKeys(Apdu apdu, out BSO sigIn, out BSO encIn, out BSO sigOut, out BSO encOut)
        {
            sigOut = null;
            encOut = null;

            if (context.CurDF == null)
            {
                throw new ISO7816Exception(Error.ClaNotValid);
            }

            encIn = handler.getSMKey(context.CurDF, DF_SM.SM_ENC_UPDATE_APPEND);
            sigIn = handler.getSMKey(context.CurDF, DF_SM.SM_SIG_UPDATE_APPEND);
        }
Beispiel #32
0
        public virtual byte[] processCommand(Apdu apdu)
        {
            CardContext context = handler.Context;

            if (apdu.P1 != 0)
            {
                return(Error.P1OrP2NotValid);
            }
            ushort pinId = (ushort)(apdu.P2 & 0x7f);
            BSO    pin   = null;

            if (pinId != 0)
            {
                bool backTrack = (apdu.P2 & 0x80) != 0;
                if (backTrack)
                {
                    pin = context.CurDF.GetChildBSO(pinId, backTrack);
                }
                else
                {
                    pin = context.CurDF.Owner.MasterFile.GetChildBSO(pinId, false);
                }
            }
            else
            {
                pin = handler.GetEnvironmentKey(SecurityEnvironmentComponent.TEST);
            }

            if (pin == null)
            {
                return(Error.FileNotFound);
            }
            if (pin.Class != BSOClass.Test || pin.Algo == BSOAlgo.PIN)
            {
                return(Error.InsNotValid);
            }

            if (!handler.IsVerifiedAC(pin, BSO_AC.AC_USE))
            {
                return(Error.SecurityStatusNotSatisfied);
            }

            if (handler.VerifyBSO(pin, apdu.Data))
            {
                return(Error.Ok);
            }
            else
            {
                return(Error.VerificationFailed);
            }
        }
        public byte[] DigitalSignature(BSO key, byte[] data)
        {
            BSO key2 = key.Parent.GetChildBSO((ushort)(key.ID | 0x100));

            if (key2 == null)
            {
                throw new ISO7816Exception(Error.ObjectNotFound);
            }
            var       module     = new BigInteger(new ByteArray(key.Data).Sub(2));
            var       privExp    = new BigInteger(new ByteArray(key2.Data).Sub(2));
            ByteArray paddedData = ByteArray.BT1Pad(new ByteArray(data), key.Data.Length - 2);

            return(new BigInteger(paddedData).modPow(privExp, module).getBytes());
        }
Beispiel #34
0
        private int GetMaxNumber()
        {
            int result = 0;

            try
            {
                string sql = "SELECT MaxNumero = MAX(CDU_Numero) FROM TDU_CabecAnomalias";
                result = (int)BSO.Consulta(sql).Valor("MaxNumero");
            }
            catch
            {
                result = 0;
            }

            return(result);
        }
Beispiel #35
0
 public ActionResult Edit(long?id)
 {
     if (id != null)
     {
         BSO bso = bsoBusinessLogic.BSO_GetByID((long)id);
         BSOSaveDataModel model = new BSOSaveDataModel(bso);
         model.Comment    = null;
         model.StatusDate = DateTime.Now;
         return(PartialView(model));
     }
     else
     {
         BSOSaveDataModel model = new BSOSaveDataModel();
         return(PartialView(model));
     }
 }
        public void getSMKeys(Apdu apdu, out BSO sigIn, out BSO encIn, out BSO sigOut, out BSO encOut)
        {
            CardContext context = handler.Context;

            sigIn = null;
            encIn = null;
            sigOut = null;
            encOut = null;

            var efBin = context.CurEF as EFBinary;
            if (efBin == null)
                return;

            encIn = handler.getSMKey(efBin, EF_SM.SM_ENC_UPDATE);
            sigIn = handler.getSMKey(efBin, EF_SM.SM_SIG_UPDATE);
        }
Beispiel #37
0
 private void ValidateChangeVisitGroupId(BSOSaveDataModel bsoSaveDataModel, BSO bso)
 {
     if (bsoSaveDataModel.VisitGroupId != bso.VisitGroupId && bsoSaveDataModel.VisitGroupId != null)
     {
         BusinessLogic.ClientBusinessLogic clientBusinessLogic = new BusinessLogic.ClientBusinessLogic();
         try
         {
             ClientVisit cv = clientBusinessLogic.ClientVisit_GetFirstClientVisitInGroup((long)bsoSaveDataModel.VisitGroupId);
         }
         catch
         {
             isValid = false;
             this.Messages.Add(string.Format("Вы ввели несуществующий идентификатор обращения {0}!", bsoSaveDataModel.VisitGroupId));
         }
     }
 }
        public void getSMKeys(Apdu apdu, out BSO sigIn, out BSO encIn, out BSO sigOut, out BSO encOut)
        {
            sigOut = null;
            encOut = null;

            BSO key =null;
            if (apdu.P1 == 0x80 && apdu.P2 == 0x86)
                key = handler.GetEnvironmentKey(SecurityEnvironmentComponent.CON);
            else if (apdu.P1 == 0x86 && apdu.P2 == 0x80)
                key = handler.GetEnvironmentKey(SecurityEnvironmentComponent.CON);
            else if (apdu.P1 == 0x9E && apdu.P2 == 0x9A)
                key = handler.GetEnvironmentKey(SecurityEnvironmentComponent.CDS);


            encIn = handler.getSMKey(key, BSO_SM.SM_ENC_USE);
            sigIn = handler.getSMKey(key, BSO_SM.SM_SIG_USE);
            encOut = handler.getSMKey(key, BSO_SM.SM_ENC_USE_OUT);
            sigOut = handler.getSMKey(key, BSO_SM.SM_SIG_USE_OUT);
        }
        public void getSMKeys(Apdu apdu, out BSO sigIn, out BSO encIn, out BSO sigOut, out BSO encOut)
        {
            CardContext context = handler.Context;

            sigIn = null;
            encIn = null;
            sigOut = null;
            encOut = null;

            var efBin = context.CurEF as EFRecord;
            if (efBin == null)
                return;

            encIn = handler.getSMKey(efBin, EF_SM.SM_ENC_READ_IN);
            sigIn = handler.getSMKey(efBin, EF_SM.SM_SIG_READ_IN);

            encOut = handler.getSMKey(efBin, EF_SM.SM_ENC_READ_OUT);
            sigOut = handler.getSMKey(efBin, EF_SM.SM_SIG_READ_OUT);
        }
Beispiel #40
0
        public void PutDataFCIKeys(Apdu apdu, out BSO sigIn, out BSO encIn, out BSO sigOut, out BSO encOut)
        {
            if (context.CurFile == null)
                throw new ISO7816Exception(Error.NoCurrentEFSelected);

            sigOut = null;
            encOut = null;

            if (context.CurFile is DF)
            {
                encIn = handler.getSMKey(context.CurFile, DF_SM.SM_ENC_ADMIN);
                sigIn = handler.getSMKey(context.CurFile, DF_SM.SM_SIG_ADMIN);
            }
            else if (context.CurFile is EF)
            {
                encIn = handler.getSMKey(context.CurFile, EF_SM.SM_ENC_ADMIN);
                sigIn = handler.getSMKey(context.CurFile, EF_SM.SM_SIG_ADMIN);
            }
            else
                throw new ISO7816Exception(Error.NoCurrentEFSelected);
        }
 bool TestLogic(BSO bso, int ptr, out int exprLen)
 {
     byte[] logicExp = bso.Data;
     if (logicExp[ptr] == 0x00) { 
         int expLen1;
         int expLen2;
         bool a = TestLogic(bso, ptr - 1, out expLen1);
         bool b = TestLogic(bso, ptr - 1 - expLen1, out expLen2);
         exprLen = 1 + expLen1 + expLen2;
         return a && b;
     }
     if (logicExp[ptr] == 0xff)
     {
         int expLen1;
         int expLen2;
         bool a = TestLogic(bso, ptr - 1, out expLen1);
         bool b = TestLogic(bso, ptr - 1 - expLen1, out expLen2);
         exprLen = 1 + expLen1 + expLen2;
         return a || b;
     }
     exprLen = 1;
     byte condition=logicExp[ptr];
     if (context.securityStatus.ContainsKey(condition))
     {
         if (bso.Parent==context.CurDF)
             return true;
         if (context.CurDF.GetChildBSO(condition,true) == bso.Parent.GetChildBSO(condition,true))
             return true;
         return false;
     }
     return false;
 }
        bool VerifyKeyBSO(BSO bso, byte[] response, out bool verificationFailed)
        {
            verificationFailed = false;
            if (bso.Algo == BSOAlgo.PIN) {
                verificationFailed = !Util.CompareByteArray(response, bso.Data);
                return !verificationFailed;
            }
            else if (bso.Algo == BSOAlgo.MAC3_Test_SMSig) {
                if (context.Challenge == null)
                    throw new ISO7816Exception(Error.ConditionsOfUseNotSatisfied);
                var challenge = context.Challenge;
                context.Challenge = null;

                if ((challenge.Length & 0x7) != 0)
                    throw new ISO7816Exception(Error.ReferencedDataInvalidated);
                
                var cardResponse = getMAC(bso.Data, challenge);
                if (cardResponse.Length != response.Length)
                    throw new ISO7816Exception(Error.WrongLength);
                verificationFailed = !Util.CompareByteArray(response, cardResponse);
                return !verificationFailed;
            }
            else if (bso.Algo == BSOAlgo.RSA_DS_Test)
            {
                if (context.Challenge == null)
                    throw new ISO7816Exception(Error.ConditionsOfUseNotSatisfied);
                var challenge = context.Challenge;
                context.Challenge = null;

                if ((challenge.Length & 0x7) != 0)
                    throw new ISO7816Exception(Error.ReferencedDataInvalidated);

                BSO exp = bso.Parent.GetChildBSO((ushort)(bso.ID | 0x100));
                if (exp == null)
                    throw new ISO7816Exception(Error.ObjectNotFound);

                if (response.Length != (bso.Data.Length - 2))
                    throw new ISO7816Exception(Error.WrongLength);

                ByteArray dec = decryptRSA(new ByteArray(bso.Data).Sub(2), new ByteArray(exp.Data).Sub(2), response);
                if (dec[0] == 1)
                    dec = new ByteArray(0).Append(dec);
                try
                {
                    dec = ByteArray.RemoveBT1(dec);
                }
                catch {
                    verificationFailed = true;
                    return false;
                }
                verificationFailed = !Util.CompareByteArray(dec, challenge);
                return !verificationFailed;
            }
            throw new ISO7816Exception(Error.ObjectNotFound);
        }
        public bool VerifyBSO(BSO bso,byte[] response) 
        {
            bool isVerified = false;
            bool verificationFailed = false;
            try
            {
                if (bso.Blocked)
                    throw new ISO7816Exception(Error.BSOBlocked);
                isVerified = VerifyKeyBSO(bso, response, out verificationFailed);
                return isVerified;
            }
            finally {
                if (isVerified)
                {
                    bso.CurValidityCounter = (bso.ValidityCounter != 0xff && bso.ValidityCounter != 0) ? bso.ValidityCounter : 0xff;
                    context.securityStatus[bso.KeyID] = bso;

                    bso.CurErrorCounter = (bso.MaxErrorCounter != 0 && bso.MaxErrorCounter != 0x0f) ? bso.MaxErrorCounter : 0x0f;
                }
                else
                {
                    if (verificationFailed)
                    {
                        if (context.securityStatus.ContainsKey(bso.KeyID) &&
                            context.securityStatus[bso.KeyID] == bso)
                            context.securityStatus.Remove(bso.KeyID);

                        if (bso.CurErrorCounter != 0x0f)
                            bso.CurErrorCounter--;

                        if (bso.CurErrorCounter == 0x00)
                        {
                            bso.Blocked = true;
                        }
                    }
                }
            }
        }
 public void UnblockBSO(BSO bso)
 {
     bso.Blocked = false;
     bso.CurErrorCounter = (bso.MaxErrorCounter != 0 && bso.MaxErrorCounter != 0x0f) ? bso.MaxErrorCounter : 0x0f;
 }
        public void GenerateKey(BSO privExpBso,BSO moduleBso, EFLinearTLV pubKeyEF, ushort pubExpLen)
        {
            BigInteger publicExponent;
            BigInteger privateExponent;
            BigInteger module;
            BigInteger.GenerateRSAKey(1024, pubExpLen, out publicExponent, out module, out privateExponent);

            ByteArray baPrivateExponent = new ByteArray(new byte[] { 0, 0 });
            baPrivateExponent=baPrivateExponent.Append(privateExponent.getBytes());
            baPrivateExponent[0]=(byte)(baPrivateExponent.Size-1);
            privExpBso.Data = baPrivateExponent;

            ByteArray baModule = new ByteArray(new byte[] { 0, 0 });
            baModule = baModule.Append(module.getBytes());
            baModule[0] = (byte)(baModule.Size - 1);
            moduleBso.Data = baModule;

            TLV modTlv = new TLV();
            modTlv.addTag(0x10, baModule);
            pubKeyEF.Append(modTlv.GetBytes());

            ByteArray baPublicExponent = new ByteArray(new byte[] { 0, 0 });
            baPublicExponent = baPublicExponent.Append(publicExponent.getBytes());
            baPublicExponent[0] = (byte)(baPublicExponent.Size - 1);

            TLV pubExpTlv = new TLV();
            pubExpTlv.addTag(0x11, baPublicExponent);
            pubKeyEF.Append(pubExpTlv.GetBytes());
        }
        public byte[] Encrypt(BSO key, byte[] data)
        {
            if (key.Algo == BSOAlgo.DES3_Enc_SMEnc)
            {
                return encrypt3DES(key.Data, data);
            }
            if (key.Algo == BSOAlgo.RSA_Enc)
            {
                BSO exp = key.Parent.GetChildBSO((ushort)(key.ID | 0x100));
                if (exp == null)
                    throw new ISO7816Exception(Error.ObjectNotFound);

                return encryptRSA(new ByteArray(key.Data).Sub(2), new ByteArray(exp.Data).Sub(2), data);
            }
            return Error.ObjectNotFound;
        }
Beispiel #47
0
        byte[] CreateBSO(TLV oci)
        {
            var Id = oci[0x83];
            var Options = oci[0x85];
            var AC = oci[0x86];
            var SM = card.GetSMTLV(oci);
            var Data = oci[0x8F];

            if (Id == null) return Error.DataFieldNotValid;
            if (Options == null) return Error.DataFieldNotValid;
            if (Data == null) return Error.DataFieldNotValid;
            if (AC == null) return Error.DataFieldNotValid;

            if (Options.Length != 8) return Error.DataFieldNotValid;
            if (Id.Length != 2) return Error.DataFieldNotValid;

            if (!card.CheckBSOId(Id[1]))
                return Error.DataFieldNotValid;

            var curDF = context.CurDF;
            if (curDF == null)
                return Error.InsNotValid;

            if (!handler.IsVerifiedAC(context.CurDF, DF_AC.AC_APPEND))
                return Error.SecurityStatusNotSatisfied;

            //if (!curDF->ACGranted(AC_DF_APPEND))
            //    SCReturnWithError(0x6982);

            BSO bso = new BSO(Util.ToUShort(Id), card, curDF);
            bso.Options = Options;
            bso.AC.Set(AC);
            if (SM != null)
                bso.SM.Set(SM);
            bso.Data = Data;

            return Error.Ok;
        }
 bool IsInScope(DF scope,BSO obj) {
     if (scope == obj.Parent) return true;
     if (scope.Parent == null)
         return false;
     return IsInScope(scope.Parent, obj);
 }
Beispiel #49
0
 public static byte[] GetSMResponse(Apdu apdu, byte[] resp, BSO encOut, BSO sigOut, byte[] random)
 {
     TLV respTLV=new TLV();
     ByteArray ClearData=new ByteArray(resp).Sub(0, resp.Length - 2);
     byte[] CypherTextObject = null;
     if (encOut == null && sigOut == null)
     {
         if (ClearData.Size!=0)
             respTLV[0x81] = ClearData;
     }
     else {
         if (encOut != null)
         {
             respTLV[0x87] = new ByteArray(1).Append(CardHandler.encrypt3DES(encOut.Data,ClearData));
             CypherTextObject = respTLV[0x87];
         }
         else {
             if (ClearData.Size != 0)
                 respTLV[0x81] = ClearData;
         }
         if (sigOut != null)
         {
             if (random==null)
                 throw new ISO7816Exception(Error.ConditionsOfUseNotSatisfied);
             var MACObject = new ByteArray(random);
             MACObject = MACObject.Append(ByteArray.ANSIPad(new ByteArray(apdu.GetBytes()).Left(4)));
             TLV MacTLV = new TLV();
             if (CypherTextObject!=null)
                 MacTLV[0x87] = CypherTextObject;
             else
                 MacTLV[0x81] = ClearData;
             MACObject = MACObject.Append(MacTLV.GetBytes());
             var mac = CardHandler.getMAC(sigOut.Data, ByteArray.ANSIPad(MACObject));
             respTLV[0x8e] = mac;
         }
     }
     ByteArray smResp=new ByteArray(respTLV.GetBytes());
     smResp = smResp.Append(new byte[] { resp[resp.Length - 2], resp[resp.Length - 1] });
     return smResp;
 }
Beispiel #50
0
        byte[] UpdateBSO(BSO bso, TLV oci)
        {
            var AC = oci[0x86];
            var SM = card.GetSMTLV(oci);
            var Data = oci[0x8F];

            var curDF = context.CurDF;
            if (curDF == null)
                return Error.InsNotValid;

            if (!handler.IsVerifiedAC(context.CurDF, DF_AC.AC_UPDATE))
                return Error.SecurityStatusNotSatisfied;

            if (AC != null) bso.AC.Set(AC);
            if (SM != null) bso.SM.Set(SM);
            if (Data != null) bso.Data = Data;

            return Error.Ok;
        }
 public byte[] DigitalSignature(BSO key, byte[] data)
 {
     BSO key2 = key.Parent.GetChildBSO((ushort)(key.ID | 0x100));
     if (key2 == null)
         throw new ISO7816Exception(Error.ObjectNotFound);
     var module = new BigInteger(new ByteArray(key.Data).Sub(2));
     var privExp = new BigInteger(new ByteArray(key2.Data).Sub(2));
     ByteArray paddedData = ByteArray.BT1Pad(new ByteArray(data), key.Data.Length - 2);
     return new BigInteger(paddedData).modPow(privExp, module).getBytes();
 }
Beispiel #52
0
        public static Apdu GetClearApdu(Apdu smApdu, BSO encKey, BSO sigKey, BSO outEncKey, BSO outSigKey, byte[] challenge) {
            if (sigKey==null && encKey==null) {
                Apdu apdu2=new Apdu();
                apdu2.CLA=0;
                apdu2.INS = smApdu.INS;
                apdu2.P1 = smApdu.P1;
                apdu2.P2 = smApdu.P2;
                apdu2.Data = smApdu.Data;
                apdu2.LE = smApdu.LE;
                apdu2.UseLE = smApdu.UseLE;
                return apdu2;
            }
            TLV tlv = new TLV(smApdu.Data);
            ByteArray ClearData=null;
            var NetLEObject = tlv[0x96];
            var CypherTextObject = tlv[0x87];
            var PlainTextObject = tlv[0x81];
            var MACObject = tlv[0x8E];

            if (CypherTextObject != null && PlainTextObject!=null)
                throw new ISO7816Exception(Error.DataFieldNotValid);

            if ((encKey != null && CypherTextObject == null) ||
                (encKey == null && CypherTextObject != null))
                throw new ISO7816Exception(Error.ConditionsOfUseNotSatisfied);

            if ((sigKey != null && MACObject == null) ||
                (sigKey == null && MACObject != null))
                throw new ISO7816Exception(Error.ConditionsOfUseNotSatisfied);

            if (PlainTextObject != null)
                ClearData = PlainTextObject;

            if (encKey!=null && CypherTextObject!=null)
                ClearData = ByteArray.RemoveISOPad(CardHandler.decrypt3DES(encKey.Data, new ByteArray(CypherTextObject).Sub(1)));

            if (sigKey != null && MACObject != null)
            {
                if (challenge==null)
                    throw new ISO7816Exception(Error.ConditionsOfUseNotSatisfied);
                var HeaderBlock = new ByteArray(challenge);
                HeaderBlock = HeaderBlock.Append(new ByteArray(smApdu.GetBytes()).Left(4));
                HeaderBlock = ByteArray.ANSIPad(HeaderBlock);
                byte[] toMAC=null;
                if (CypherTextObject != null && CypherTextObject.Length != 0)
                {
                    TLV ptb = new TLV();
                    ptb[0x87] = CypherTextObject;
                    toMAC = ptb.GetBytes();
                }
                else
                {
                    if (ClearData != null && ClearData.Size != 0)
                    {
                        TLV ptb = new TLV();
                        ptb[0x81] = ClearData;
                        toMAC = ptb.GetBytes();
                    }
                    else
                    {
                        if (PlainTextObject != null)
                            throw new ISO7816Exception(Error.SMDataObjectsIncorrect);
                        toMAC = new byte[0];
                    }
                }
                HeaderBlock = HeaderBlock.Append(ByteArray.ANSIPad(toMAC));
                var mac=CardHandler.getMAC(sigKey.Data, HeaderBlock);
                if (!new ByteArray(mac).CompareByteArray(MACObject))
                    throw new ISO7816Exception(Error.VerificationFailed);
            }

            Apdu ClearApdu = new Apdu((byte)(smApdu.CLA & 0xf0), smApdu.INS, smApdu.P1, smApdu.P2, ClearData);
            if (NetLEObject != null)
            {
                ClearApdu.UseLE = true;
                ClearApdu.LE = NetLEObject[0];
            }
            else
            {
                ClearApdu.UseLE = smApdu.UseLE;
                if (ClearApdu.UseLE)
                {
                    int orLE = smApdu.LE;
                    if (orLE == 0)
                        orLE = 255;
                    if (outEncKey==null && outSigKey==null)
                        ClearApdu.LE = (byte)(orLE - 2);
                    else if (outEncKey != null && outSigKey == null)
                        ClearApdu.LE = (byte)((orLE - 3) & ~7);
                    else if (outEncKey == null && outSigKey != null)
                        ClearApdu.LE = (byte)(orLE - 12);
                    else if (outEncKey != null && outSigKey != null)
                        ClearApdu.LE = (byte)((orLE - 20) & ~7);
                }
            }
            return ClearApdu;
        }