Example #1
0
        public List<string> CheckCertificateValidity(string xml, ElectronicServiceApplicant applicant, string signatureXPath, IDictionary<string, string> signatureXPathNamespaces)
        {
            bool missingRequiredAuthentication = false;
            bool missingRequiredSignature = false;
            X509Certificate2 signingCertificate = null;

            if (applicant != null)
            {
                missingRequiredAuthentication = !HasFilledElectronicServiceApplicant(applicant);

                if (signatureXPath != null)
                {
                    missingRequiredSignature = !HasValidSignature(xml, signatureXPath, signatureXPathNamespaces, out signingCertificate);
                }
            }

            if (missingRequiredAuthentication || missingRequiredSignature)
            {
                return new List<string>() { "NotAuthenticated" };
            }

            var x509Chain = new X509Chain();
            x509Chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain;
            x509Chain.ChainPolicy.RevocationMode = X509RevocationMode.Online;

            x509Chain.Build(signingCertificate);

            signingCertificate.Verify();

            return x509Chain.ChainStatus.Select(e => e.StatusInformation).ToList();
        }
Example #2
0
        private List<Correspondent> GetDocumentCorrespondents(ElectronicServiceApplicant electronicServiceApplicant, ElectronicServiceApplicantContactData electronicServiceApplicantContactData)
        {
            List<Correspondent> returnValue = new List<Correspondent>();

            if (electronicServiceApplicant != null && electronicServiceApplicant.RecipientGroupCollection[0].RecipientCollection.Count > 0)
            {
                foreach (var recipient in electronicServiceApplicant.RecipientGroupCollection[0].RecipientCollection)
                {
                    Correspondent correspondent = null;

                    bool isNew = false;

                    string email = electronicServiceApplicant.EmailAddress ?? "";

                    if (recipient.Person != null)
                    {
                        string bgCitizenFirstName = recipient.Person.Names.First;
                        string bgCitizenLastName = recipient.Person.Names.Last;
                        string bgCitizenEgn = recipient.Person.Identifier.EGN;

                        //Get EmptyCorrespondent
                        if (String.IsNullOrWhiteSpace(email) ||
                            String.IsNullOrWhiteSpace(bgCitizenFirstName) ||
                            String.IsNullOrWhiteSpace(bgCitizenLastName) ||
                            String.IsNullOrWhiteSpace(bgCitizenEgn))
                        {
                            correspondent = this.unitOfWork.DbContext.Set<Correspondent>().SingleOrDefault(e => e.Alias == "Empty");
                        }
                        else
                        {
                            correspondent = this.correspondentRepository.GetBgCitizenCorrespondent(email, bgCitizenFirstName, bgCitizenLastName, bgCitizenEgn);

                            if (correspondent == null)
                            {
                                isNew = true;

                                correspondent = new Correspondent();
                                correspondent.CorrespondentGroupId = this.unitOfWork.DbContext.Set<CorrespondentGroup>()
                                    .SingleOrDefault(e => e.Alias == "Applicants")
                                    .CorrespondentGroupId;
                                correspondent.CorrespondentTypeId = this.unitOfWork.DbContext.Set<CorrespondentType>()
                                    .SingleOrDefault(e => e.Alias == "BulgarianCitizen")
                                    .CorrespondentTypeId;
                                correspondent.BgCitizenFirstName = bgCitizenFirstName;
                                correspondent.BgCitizenLastName = bgCitizenLastName;
                                correspondent.BgCitizenUIN = bgCitizenEgn;
                            }
                        }
                    }
                    else if (recipient.ForeignPerson != null)
                    {
                        string foreignerFirstName = recipient.ForeignPerson.Names.FirstLatin;
                        string foreignerLastName = recipient.ForeignPerson.Names.LastLatin;
                        string foreignerSettlement = recipient.ForeignPerson.PlaceOfBirth != null ? recipient.ForeignPerson.PlaceOfBirth.SettlementName : string.Empty;
                        DateTime? foreignerBirthDate = recipient.ForeignPerson.BirthDate;
                        string foreignerCountryCode = recipient.ForeignPerson.PlaceOfBirth != null ? recipient.ForeignPerson.PlaceOfBirth.CountryCode : string.Empty;
                        int? foreignerCountryId = null;

                        if (!String.IsNullOrWhiteSpace(foreignerCountryCode))
                        {
                            var country = this.unitOfWork.DbContext.Set<Country>()
                                .SingleOrDefault(e => e.Code == foreignerCountryCode);
                            foreignerCountryId = country != null ? country.CountryId : (int?)null;
                        }

                        //Get EmptyCorrespondent
                        if (String.IsNullOrWhiteSpace(email) ||
                            String.IsNullOrWhiteSpace(foreignerFirstName) ||
                            String.IsNullOrWhiteSpace(foreignerLastName))
                        {
                            correspondent = this.unitOfWork.DbContext.Set<Correspondent>().SingleOrDefault(e => e.Alias == "Empty");
                        }
                        else
                        {
                            correspondent = this.correspondentRepository.GetForeignerCorrespondent(email, foreignerFirstName, foreignerLastName, foreignerCountryId, foreignerSettlement, foreignerBirthDate);

                            if (correspondent == null)
                            {
                                isNew = true;

                                correspondent = new Correspondent();
                                correspondent.CorrespondentGroupId = this.unitOfWork.DbContext.Set<CorrespondentGroup>()
                                    .SingleOrDefault(e => e.Alias == "Applicants")
                                    .CorrespondentGroupId;
                                correspondent.CorrespondentTypeId = this.unitOfWork.DbContext.Set<CorrespondentType>()
                                    .SingleOrDefault(e => e.Alias == "Foreigner")
                                    .CorrespondentTypeId;
                                correspondent.ForeignerFirstName = foreignerFirstName;
                                correspondent.ForeignerLastName = foreignerLastName;
                                correspondent.ForeignerCountryId = foreignerCountryId;
                                correspondent.ForeignerSettlement = foreignerSettlement;
                                correspondent.ForeignerBirthDate = foreignerBirthDate;
                            }
                        }
                    }
                    else if (recipient.Entity != null)
                    {
                        string legalEntityName = recipient.Entity.Name;
                        string legalEntityBulstat = recipient.Entity.Identifier;

                        //Get EmptyCorrespondent
                        if (String.IsNullOrWhiteSpace(email) ||
                            String.IsNullOrWhiteSpace(legalEntityName) ||
                            String.IsNullOrWhiteSpace(legalEntityBulstat))
                        {
                            correspondent = this.unitOfWork.DbContext.Set<Correspondent>().SingleOrDefault(e => e.Alias == "Empty");
                        }
                        else
                        {
                            correspondent = this.correspondentRepository.GetLegalEntityCorrespondent(email, legalEntityName, legalEntityBulstat);

                            if (correspondent == null)
                            {
                                isNew = true;

                                correspondent = new Correspondent();
                                correspondent.CorrespondentGroupId = this.unitOfWork.DbContext.Set<CorrespondentGroup>()
                                    .SingleOrDefault(e => e.Alias == "Applicants")
                                    .CorrespondentGroupId;
                                correspondent.CorrespondentTypeId = this.unitOfWork.DbContext.Set<CorrespondentType>()
                                    .SingleOrDefault(e => e.Alias == "LegalEntity")
                                    .CorrespondentTypeId;
                                correspondent.LegalEntityName = legalEntityName;
                                correspondent.LegalEntityBulstat = legalEntityBulstat;
                            }
                        }
                    }
                    else if (recipient.ForeignEntity != null)
                    {
                        string fLEgalEntityName = recipient.ForeignEntity.ForeignEntityName;
                        string fLegalEntityRegisterName = recipient.ForeignEntity.ForeignEntityRegister;
                        string fLegalEntityRegisterNumber = recipient.ForeignEntity.ForeignEntityIdentifier;
                        string fLegalEntityOtherData = recipient.ForeignEntity.ForeignEntityOtherData;
                        string fLegalEntityCountryCode = recipient.ForeignEntity.CountryISO3166TwoLetterCode;
                        int? fLegalEntityCountryId = null;

                        if (!String.IsNullOrWhiteSpace(fLegalEntityCountryCode))
                        {
                            var country = this.unitOfWork.DbContext.Set<Country>()
                                .SingleOrDefault(e => e.Code == fLegalEntityCountryCode);
                            fLegalEntityCountryId = country != null ? country.CountryId : (int?)null;
                        }

                        //Get EmptyCorrespondent
                        if (String.IsNullOrWhiteSpace(email) ||
                            String.IsNullOrWhiteSpace(fLEgalEntityName) ||
                            !fLegalEntityCountryId.HasValue)
                        {
                            correspondent = this.unitOfWork.DbContext.Set<Correspondent>().SingleOrDefault(e => e.Alias == "Empty");
                        }
                        else
                        {
                            correspondent = this.correspondentRepository.GetFLegalEntityCorrespondent(email, fLEgalEntityName, fLegalEntityCountryId, fLegalEntityRegisterName, fLegalEntityRegisterNumber);

                            if (correspondent == null)
                            {
                                isNew = true;

                                correspondent = new Correspondent();
                                correspondent.CorrespondentGroupId = this.unitOfWork.DbContext.Set<CorrespondentGroup>()
                                    .SingleOrDefault(e => e.Alias == "Applicants")
                                    .CorrespondentGroupId;
                                correspondent.CorrespondentTypeId = this.unitOfWork.DbContext.Set<CorrespondentType>()
                                    .SingleOrDefault(e => e.Alias == "ForeignLegalEntity")
                                    .CorrespondentTypeId;
                                correspondent.FLegalEntityName = fLEgalEntityName;
                                correspondent.FLegalEntityCountryId = fLegalEntityCountryId;
                                correspondent.FLegalEntityRegisterName = fLegalEntityRegisterName;
                                correspondent.FLegalEntityName = fLegalEntityRegisterNumber;
                                correspondent.FLegalEntityOtherData = fLegalEntityOtherData;
                            }
                        }
                    }

                    if (electronicServiceApplicantContactData != null)
                    {
                        int? contactDistrictId = null;
                        int? contactMunicipalityId = null;
                        int? contactSettlementId = null;

                        if (!String.IsNullOrWhiteSpace(electronicServiceApplicantContactData.DistrictCode))
                        {
                            var district = this.unitOfWork.DbContext.Set<District>()
                                .SingleOrDefault(e => e.Code == electronicServiceApplicantContactData.DistrictCode);
                            contactDistrictId = district != null ? district.DistrictId : (int?)null;
                        }

                        if (!String.IsNullOrWhiteSpace(electronicServiceApplicantContactData.MunicipalityCode))
                        {
                            var municipality = this.unitOfWork.DbContext.Set<Municipality>()
                                .SingleOrDefault(e => e.Code == electronicServiceApplicantContactData.MunicipalityCode);
                            contactMunicipalityId = municipality != null ? municipality.MunicipalityId : (int?)null;
                        }

                        if (!String.IsNullOrWhiteSpace(electronicServiceApplicantContactData.SettlementCode))
                        {
                            var settlement = this.unitOfWork.DbContext.Set<Settlement>()
                                .SingleOrDefault(e => e.Code == electronicServiceApplicantContactData.SettlementCode);
                            contactSettlementId = settlement != null ? settlement.SettlementId : (int?)null;
                        }

                        correspondent.ContactDistrictId = contactDistrictId;
                        correspondent.ContactMunicipalityId = contactMunicipalityId;
                        correspondent.ContactSettlementId = contactSettlementId;
                        correspondent.ContactAddress = electronicServiceApplicantContactData.AddressDescription;
                        correspondent.ContactPostCode = electronicServiceApplicantContactData.PostCode;
                        correspondent.ContactPostOfficeBox = electronicServiceApplicantContactData.PostOfficeBox;

                        if (electronicServiceApplicantContactData.PhoneNumbers != null &&
                            electronicServiceApplicantContactData.PhoneNumbers.PhoneNumberCollection != null &&
                            electronicServiceApplicantContactData.PhoneNumbers.PhoneNumberCollection.Count > 0)
                        {
                            correspondent.ContactPhone = electronicServiceApplicantContactData.PhoneNumbers.PhoneNumberCollection[0];
                        }

                        if (electronicServiceApplicantContactData.FaxNumbers != null &&
                            electronicServiceApplicantContactData.FaxNumbers.ElectronicServiceApplicantFaxNumberCollection != null &&
                            electronicServiceApplicantContactData.FaxNumbers.ElectronicServiceApplicantFaxNumberCollection.Count > 0)
                        {
                            correspondent.ContactFax = electronicServiceApplicantContactData.FaxNumbers.ElectronicServiceApplicantFaxNumberCollection[0];
                        }
                    }

                    if (isNew)
                    {
                        correspondent.RegisterIndexId = 1;
                        correspondent.Email = email;
                        correspondent.IsActive = true;
                    }

                    returnValue.Add(correspondent);
                }
            }

            return returnValue;
        }