Exemplo n.º 1
0
        public CardHolderPublicDataEx ReadCard()
        {
            ReaderManagement readerMgr = new ReaderManagement();

            readerMgr.EstablishContext();
            readerMgr.DiscoverReaders();
            PCSCReader       selectedReader   = readerMgr.Readers[0];
            bool             IsConnected      = selectedReader.IsConnected();
            bool             isUAE            = ATRSetting.Is_UAE_Card(selectedReader.ATR);
            PublicDataFacade publicDataFacade = selectedReader.GetPublicDataFacade();

            // Step 6 : In order to use EIDA "secure messaging" in "local mode", the function
            // "IDCardWrapper.LoadConfiguration" shall be called to load the "secure messaging modules configurations"
            // from the sm.cfg file "C:\Program Files\EIDA Toolkit\Libs\sm.cfg"
            // Sample configuration of is described in appendix A.
            IDCardWrapper.LoadConfiguration();

            /* Step 7 : Once PCSCReader object is acquired in a CONNECTED state and with right type,
             *      application can extract the EIDA ID Card related information such as Card Serial Number, and Chip Serial Number.
             *      The retrieved information will be in binary format. By using the format conversion functions of the Toolkit,
             *      Developers can convert data from binary format to string representation. Refer to Utils class for a sample conversion implementation. */

            CardInfo cardInfo    = selectedReader.GetCardInfo();
            int      cardVersion = cardInfo.GetCardVersion();

            if (cardVersion < 2)
            {
                throw new System.Exception("خطأ : البطاقة المستخدمة ذات إصدار قديم وغير صالحة للقراءة. برجاء تحديث البطاقة");
            }

            CardHolderPublicDataEx result = publicDataFacade.ReadPublicDataEx(true, true, true, true, false, true, false, true);

            readerMgr.CloseContext();
            return(result);
        }
Exemplo n.º 2
0
        public static EIDModel CreateFromEIDReader()
        {
            EIDModel         model = new EIDModel();
            ReaderManagement readerManager;
            PCSCReader       reader;

            try
            {
                //System.Windows.Forms.MessageBox.Show("before reader");
                readerManager = new ReaderManagement();
                readerManager.EstablishContext();
                readerManager.DiscoverReaders();
                //System.Windows.Forms.MessageBox.Show("after reader discover");
                if (readerManager.Readers.Length > 0)
                {
                    reader = readerManager.Readers[0];
                    if (reader.IsConnected())
                    {
                        //System.Windows.Forms.MessageBox.Show("after connection to reader, before getting data");
                        PublicDataFacade       pDataFacade = reader.GetPublicDataFacade();
                        CardHolderPublicData   pData       = pDataFacade.ReadPublicData(true, true, true, true, false);
                        CardHolderPublicDataEx pDataEx     = pDataFacade.ReadPublicDataEx(true, false, true, true, false, true, true, true);

                        model.EIDNumber = Utils.ByteArrayToUTF8String(pData.IdNumber);
                        model.Phone     = Utils.ByteArrayToUTF8String(pDataEx.HomeAddress.ResidentPhoneNumber);
                        model.Mobile    = Utils.ByteArrayToUTF8String(pDataEx.HomeAddress.MobilePhoneNumber);
                        model.Email     = Utils.ByteArrayToUTF8String(pDataEx.HomeAddress.Email);
                        model.Pobox     = Utils.ByteArrayToUTF8String(pDataEx.HomeAddress.POBox);
                        model.Emirate   = Utils.ByteArrayToUTF8String(pDataEx.HomeAddress.EmirateDescriptionEnglish);
                        model.City      = Utils.ByteArrayToUTF8String(pDataEx.HomeAddress.CityDescriptionEnglish);
                        model.Area      = Utils.ByteArrayToUTF8String(pDataEx.HomeAddress.AreaDescriptionEnglish);

                        model.Sex        = Utils.ByteArrayToUTF8String(pData.Sex);
                        model.Occupation = Utils.ByteArrayToUTF8String(pData.Occupation);
                        model.Occupation = Utils.ByteArrayToUTF8String(pDataEx.OccupationEnglish);
                        model.Occupation = Utils.ByteArrayToUTF8String(pDataEx.OccupationArabic);
                        model.Occupation = Utils.ByteArrayToUTF8String(pDataEx.OccupationTypeEnglish);
                        model.Occupation = Utils.ByteArrayToUTF8String(pDataEx.OccupationTypeArabic);

                        model.ResidencyType = Utils.ByteArrayToHex(pData.ResidencyType, "");
                        model.DOB           = Utils.ByteArrayToStringDate(pData.DateOfBirth).Replace("/", "-");

                        model.ResidencyExpiry = Utils.ByteArrayToStringDate(pData.ResidencyExpiryDate);
                        model.Name            = RemoveComma(Utils.ByteArrayToUTF8String(pData.FullName));
                        model.NameAr          = RemoveComma(Utils.ByteArrayToUTF8String(pData.ArabicFullName));

                        model.Title          = Utils.ByteArrayToUTF8String(pData.Title);
                        model.TitleAr        = Utils.ByteArrayToUTF8String(pData.ArabicTitle);
                        model.NationalityID  = (Utils.ByteArrayToUTF8String(pData.Nationality));
                        model.PassportNumber = Utils.ByteArrayToUTF8String(pDataEx.PassportNumber);

                        model.SponsorType   = Utils.ByteArrayToHex(pData.SponsorType, "");
                        model.SponsorNumber = Utils.ByteArrayToHex(pData.SponsorNumber, "");
                        model.SponsorName   = Utils.ByteArrayToUTF8String(pData.SponsorName);
                        model.CompanyName   = Utils.ByteArrayToUTF8String(pDataEx.CompanyNameEnglish);
                        if (pData.ResidencyNumber != null)
                        {
                            model.ResidencyNumber = Utils.ByteArrayToUTF8String(pData.ResidencyNumber).Trim();
                        }

                        model.PhotoPath = @"C:\Temp\EID_PHO_" + model.EIDNumber.Replace(" ", "").Trim() + ".jpg";
                        model.Photo     = pData.Photography;
                        if (pData.Photography != null)
                        {
                            System.IO.MemoryStream ms    = new System.IO.MemoryStream(pData.Photography);
                            System.Drawing.Image   image = System.Drawing.Image.FromStream(ms);
                            image.Save(model.PhotoPath, System.Drawing.Imaging.ImageFormat.Jpeg);
                        }

                        model.Signature = pDataEx.HolderSignatureImage;
                        if (pDataEx.HolderSignatureImage != null)
                        {
                            System.IO.MemoryStream ms    = new System.IO.MemoryStream(pDataEx.HolderSignatureImage);
                            System.Drawing.Image   image = System.Drawing.Image.FromStream(ms);
                            image.Save(@"C:\Temp\EID_SIG_" + model.EIDNumber.Replace(" ", "").Trim() + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                        }
                        model.HasData = true;
                    }
                }
            }
            catch (Exception ex)
            {
                model.HasData = false;
                Console.WriteLine("ERROR: " + ex.Message);
            }
            return(model);
        }
Exemplo n.º 3
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            try
            {
                #region Steps 1-5

                readerMgr = new ReaderManagement();
                readerMgr.EstablishContext();

                selectedReader = selectReader();
                IsConnected    = selectedReader.IsConnected();
                isUAE          = ATRSetting.Is_UAE_Card(selectedReader.ATR);

                #endregion Steps 1-5

                #region Step 6

                /* Step 6 : In order to use EIDA "secure messaging" in "local mode", the function
                 *      "IDCardWrapper.LoadConfiguration" shall be called to load the "secure messaging modules configurations"
                 *      from the sm.cfg file "C:\Program Files\EIDA Toolkit\Libs\sm.cfg"
                 *      Sample configuration of is described in appendix A. */
                IDCardWrapper.LoadConfiguration();

                #endregion Step 6

                #region Step 7

                /* Step 7 : Once PCSCReader object is acquired in a CONNECTED state and with right type,
                 *      application can extract the EIDA ID Card related information such as Card Serial Number, and Chip Serial Number.
                 *      The retrieved information will be in binary format. By using the format conversion functions of the Toolkit,
                 *      Developers can convert data from binary format to string representation. Refer to Utils class for a sample conversion implementation. */

                CardInfo cardInfo    = selectedReader.GetCardInfo();
                byte[]   csn         = cardInfo.GetCardSerialNumber();
                byte[]   chipSN      = cardInfo.GetChipSerialNumber();
                byte[]   cplc0101    = cardInfo.GetCPLC0101();
                byte[]   cplc9f7f    = cardInfo.GetCPLC9F7F();
                byte[]   isn         = cardInfo.GetIssuerSerialNumber();
                byte[]   irn         = cardInfo.GetIssuerReferenceNumber();
                byte[]   mocSN       = cardInfo.GetMOCSerialNumber();
                byte[]   mocAppState = cardInfo.GetMOCAppletState();
                byte[]   mocAlgVer   = cardInfo.GetMOCAlgorithmVersion();
                byte[]   maxFailed   = cardInfo.GetMaxFailedMatch();
                int      cardVersion = cardInfo.GetCardVersion();
                String   csnHex      = Utils.ByteArrayToHex(csn);

                #endregion Step 7

                #region Step 8

                /* Step 8 : Reading the "Card Holder Public Data", using the "CardHolderPublicData" Class */

                publicDataFacade = selectedReader.GetPublicDataFacade();
                CardHolderPublicData publicData = publicDataFacade.ReadPublicData(true, true, true, true, false);
                byte[] fullNameBin  = publicData.FullName;
                String fullName     = Utils.ByteArrayToUTF8String(fullNameBin);
                byte[] sexBin       = publicData.Sex;
                String sex          = Utils.ByteArrayToUTF8String(sexBin);
                byte[] issueDateBin = publicData.IssueDate;
                String issueDate    = Utils.ByteArrayToStringDate(issueDateBin);
                byte[] photography  = publicData.Photography;
                pictureBox1.Image = (Image) new ImageConverter().ConvertFrom(photography);
                // use publicData.getX as needed
                //…

                #endregion Step 8

                #region Step 9

                /* Step 9 : Reading the "Card Holder Public Data" is extended to support reading additional public data fields
                 *      added in V2 cards such as address, passport information, Company name, Qualification, Field of Study, etc...  */

                CardHolderPublicDataEx publicDataEx = publicDataFacade.ReadPublicDataEx(true, true, true, true, false, true, true, true);
                byte[] fullNameBinEx          = publicDataEx.FullName;
                String fullNameEx             = Utils.ByteArrayToUTF8String(fullNameBin);
                byte[] sexBinEx               = publicDataEx.Sex;
                String sexEx                  = Utils.ByteArrayToUTF8String(sexBin);
                byte[] issueDateBinEx         = publicDataEx.IssueDate;
                String issueDateEx            = Utils.ByteArrayToStringDate(issueDateBin);
                byte[] photographyEx          = publicDataEx.Photography;
                byte[] FieldofStudyEnglishBin = publicDataEx.FieldofStudyEnglish;
                String FieldofStudyEnglish    = Utils.ByteArrayToUTF8String(FieldofStudyEnglishBin);
                byte[] FieldofStudyArabicBin  = publicDataEx.FieldofStudyArabic;
                String FieldofStudyArabic     = Utils.ByteArrayToUTF8String(FieldofStudyArabicBin);

                #endregion

                #region Step 10 "Family Book Data" (Skipped because it needs a special config in sm.cfg)
                /* Step 10 : Reading the "Family Book Data" */

                //FamilyBookDataFacade familyBookDataFacade = selectedReader.GetFamilyBookDataFacade();
                //FamilyBookData familyBookData = familyBookDataFacade.ReadFamilyBookData(false);
                //byte[] firstNameBinChild1 = familyBookData.Child1.FirstNameArabic;
                //String firstNameChild1 = Utils.ByteArrayToUTF8String(firstNameBinChild1);
                #endregion

                #region Step 11 "Verifying Card Genuine in local mode" (Skipped because it needs a special config in sm.cfg)

                /* Step 11 : Verifying Card Genuine in local mode
                 * In order to invoke isCardGenuine() function in the local mode, the sm.cfg configuration file
                 * must be configured as specified in Appendix A, according to the availability of
                 * secure messaging modules (HSM, SAM or multiple SAM, or Software SAM). */

                bool isGenuine = publicDataFacade.IsCardGenuine();

                #endregion



                readerMgr.CloseContext();
            }
            catch (MiddlewareException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 4
0
        private void btnReadCard_Click(object sender, EventArgs e)
        {
            try
            {
                publicDataEx = new BLL.CardReader().ReadCard();

                txtArabicFullName.Text       = PublicDataUtils.RemoveCommas(Utils.ByteArrayToUTF8String(publicDataEx.ArabicFullName));
                txtFullName.Text             = PublicDataUtils.RemoveCommas(Utils.ByteArrayToUTF8String(publicDataEx.FullName));
                txtMotherFullNameArabic.Text = Utils.ByteArrayToUTF8String(publicDataEx.MotherFullNameArabic);
                txtIDNumber.Text             = Utils.ByteArrayToUTF8String(publicDataEx.IdNumber);
                picPhotography.Image         = (Image) new ImageConverter().ConvertFrom(publicDataEx.Photography);
                txtNationalityAr.Text        = Utils.ByteArrayToUTF8String(publicDataEx.ArabicNationality);
                txtIssueDate.Text            = Utils.ByteArrayToStringDate(publicDataEx.IssueDate);
                txtExpiryDate.Text           = Utils.ByteArrayToStringDate(publicDataEx.ExpiryDate);
                txtDateOfBirth.Text          = Utils.ByteArrayToStringDate(publicDataEx.DateOfBirth);

                txtPlaceOfBirthArabic.Text = Utils.ByteArrayToUTF8String(publicDataEx.PlaceOfBirthArabic);
                txtSex.Text           = PublicDataUtils.GetSex(Utils.ByteArrayToUTF8String(publicDataEx.Sex));
                txtMaritalStatus.Text = PublicDataUtils.GetMaritalStatus(Utils.ByteArrayToHex(publicDataEx.MaritalStatus, ""));
                txtQualificationLevelDescriptionArabic.Text = Utils.ByteArrayToUTF8String(publicDataEx.QualificationLevelDescriptionArabic);

                txtDegreeDescriptionArabic.Text = Utils.ByteArrayToUTF8String(publicDataEx.DegreeDescriptionArabic);
                txtMobilePhoneNumber.Text       = Utils.ByteArrayToUTF8String(publicDataEx.HomeAddress.MobilePhoneNumber);
                txtResidentPhoneNumber.Text     = Utils.ByteArrayToUTF8String(publicDataEx.HomeAddress.ResidentPhoneNumber);
                txtPOBox.Text       = Utils.ByteArrayToUTF8String(publicDataEx.HomeAddress.POBox);
                txtEmail.Text       = Utils.ByteArrayToUTF8String(publicDataEx.HomeAddress.Email);
                txtLandPhoneNo.Text = Utils.ByteArrayToUTF8String(publicDataEx.WorkAddress.LandPhoneNo);

                txtPassportNumber.Text     = Utils.ByteArrayToUTF8String(publicDataEx.PassportNumber);
                txtPassportIssueDate.Text  = Utils.ByteArrayToStringDate(publicDataEx.PassportIssueDate);
                txtPassportExpiryDate.Text = Utils.ByteArrayToStringDate(publicDataEx.PassportExpiryDate);
                txtPassportCountryDescriptionArabic.Text = Utils.ByteArrayToUTF8String(publicDataEx.PassportCountryDescriptionArabic);
                txtOccupation.Text               = PublicDataUtils.GetOccupation(Utils.ByteArrayToHex(publicDataEx.Occupation));
                txtCompanyNameArabic.Text        = Utils.ByteArrayToUTF8String(publicDataEx.WorkAddress.CompanyNameArabic);
                txtEmirateDescriptionArabic.Text = Utils.ByteArrayToUTF8String(publicDataEx.HomeAddress.EmirateDescriptionArabic);
                txtCityDescriptionArabic.Text    = Utils.ByteArrayToUTF8String(publicDataEx.HomeAddress.CityDescriptionArabic);
                txtResidencyType.Text            = PublicDataUtils.GetResidencyType(Utils.ByteArrayToHex(publicDataEx.ResidencyType, ""));
                txtResidencyNumber.Text          = Utils.ByteArrayToUTF8String(publicDataEx.ResidencyNumber);
                txtResidencyExpiryDate.Text      = Utils.ByteArrayToStringDate(publicDataEx.ResidencyExpiryDate);

                #region Checking If User Existing

                ClientContext context = new ClientContext(ConfigFileData.SP_URL);

                List TestForClientsList = context.Web.Lists.GetByTitle(ConfigFileData.ListName);

                bool CheckIfUserExisting = get_CheckIfUserExisting_value();

                if (CheckIfUserExisting)
                {
                    CamlQuery camlQuery = new CamlQuery();
                    camlQuery.ViewXml =
                        @"<View>
                                <Query>
                                   <Where><Eq><FieldRef Name='IDNumber' /><Value Type='Text'>" + txtIDNumber.Text + @"</Value></Eq></Where>
                                </Query>
                                 <ViewFields><FieldRef Name='ID' /></ViewFields>
                          </View>";

                    ListItemCollection listItems = TestForClientsList.GetItems(camlQuery);
                    context.Load(listItems);
                    context.Credentials = new NetworkCredential(ConfigFileData.UserName, ConfigFileData.Password);
                    context.ExecuteQuery();

                    if (listItems.Count > 0)
                    {
                        IsUserExisting = true;
                        ExistingUserID = listItems[0]["ID"].ToString();
                        string PreviousRequestsLink = ConfigFileData.PreviousRequestsLink + ExistingUserID;
                        txtStatus.Text      = "البطاقة مسجلة مسبقا. اضغط الرابط التالى لعرض الطلبات السابقة " + "\n" + PreviousRequestsLink;
                        txtStatus.BackColor = Color.SkyBlue;
                        return;
                    }
                }

                #endregion Checking If User Existing

                txtStatus.BackColor = Color.LightGreen;
                txtStatus.Text      = "تم قراءة بيانات البطاقة بنجاح";
            }
            catch (Exception ex)
            {
                txtStatus.BackColor = Color.LightCoral;

                switch (ex.Message)
                {
                case "NO PCSC Readers":
                    txtStatus.Text = "خطأ : لا يوجد جهاز قارئ للبطاقة";
                    break;

                case "E_SELECT_CM_APPLICATION":
                    txtStatus.Text = "خطأ : لا توجد بطاقة هوية بداخل القارئ";
                    break;

                default:
                    txtStatus.Text = ex.Message;
                    break;
                }
            }
        }