/* * * @throws SmartCardException */ /** * BaseSigner interface for the requested certificate. Do not forget to logout after your crypto * operation finished * @param aCardPIN * @param aCert * @return * @throws SmartCardException */ public SmartCardManager() { try { LOGGER.Debug("New SmartCardManager will be created"); String terminal; int index = 0; String[] terminals = SmartOp.getCardTerminals(); if (terminals == null || terminals.Length == 0) { MesajiIsle("Kart takılı kart okuyucu bulunamadı (SmartCardManager)", 1); Program.KartOkuyucuYok = 1; return; // throw new SmartCardException("Kart takılı kart okuyucu bulunamadı"); } LOGGER.Debug("Kart okuyucu sayısı : " + terminals.Length); if (terminals.Length != Program.TerminalSayisi && Program.TerminalSayisi != 0) { MesajiIsle("Kart seçildikten sonra imzalama aşamasında yeni kart okuyucu takıldı.", 1); Program.KartOkuyucuYok = 1; return; } // MesajiIsle("Bilgi 1 - Terminal: " + terminal, 0); try { // karttipi bastan parametre ile gelmisse if (Program.ParamCardType != "") { Program.ParamSlotID = SmartOp.findSlotNumber(CardTypeConverter.AsCardType(Program.ParamCardType)).ToString(); bsc = new P11SmartCard(CardTypeConverter.AsCardType(Program.ParamCardType)); mSerialNumber = StringUtil.ToString(bsc.getSerial(Convert.ToInt64(Program.ParamSlotID))); bsc.openSession(Convert.ToInt64(Program.ParamSlotID)); Program.CardType = Program.ParamCardType; } else { if (terminals.Length == 1) { terminal = terminals[index]; } else { index = askOption(null, null, terminals, "Okuyucu Listesi", new String[] { "Tamam" }); terminal = terminals[index]; } // burada try catch gerek olmadan kart tipi ve slot id tesbit ediliyor... // ama sadece akis icin calisiyor, safesign da calismadi Pair <long, CardType> slotAndCardType = SmartOp.getSlotAndCardType(terminal); // MesajiIsle("Bilgi 2 - Terminal: " + terminal + " SmartCard Type: " + slotAndCardType.getmObj2().ToString() + " SlotID: " + slotAndCardType.getmObj1().ToString(), 0); // bulunan kart type kullanilarak kart yapisi olusturuluyor bsc = new P11SmartCard(slotAndCardType.getmObj2()); // olusturulan kart yapisi bulunan slotid kullanilarak aciliyor bsc.openSession(slotAndCardType.getmObj1()); Program.ParamSlotID = slotAndCardType.getmObj1().ToString(); Program.CardType = slotAndCardType.getmObj2().ToString(); Program.Terminal = terminal; } } catch { // etugra //bsc = new P11SmartCard(tr.gov.tubitak.uekae.esya.api.smartcard.pkcs11.CardType.SAFESIGN); //bsc.openSession(52481); //MessageBox.Show(index.ToString() + " nolu terminal serino"); //MessageBox.Show(StringUtil.ToString(bsc.getSerial())); //MessageBox.Show("Serino gösterdi"); // continue; // bu slot id belirleme ve open session kismini, manuel imzalamada signerhelp icerisine aldim, yoksa // burada acilan sessioni gormuyordu bir sekilde. bu kisim sertifika okuma ozelligi cozulebilirse iptal edilebilir belki... long[] PresentSlots; // long[] PresentSerials; try { sc = new SmartCard(tr.gov.tubitak.uekae.esya.api.smartcard.pkcs11.CardType.AKIS); if (Program.ParamSlotID == "") { FindSlotID(); } string s = new string(sc.getSlotInfo(Convert.ToInt64(Program.ParamSlotID)).slotDescription); s = new string(sc.getSlotInfo(Convert.ToInt64(Program.ParamSlotID)).manufacturerID); s = sc.getSlotInfo(Convert.ToInt64(Program.ParamSlotID)).ToString(); // MesajiIsle("slotDescription (SlotID(" +Program.ParamSlotID+"): "+ s, 0); //Program.ParamSlotIndex = index.ToString(); Program.CardType = sc.getCardType().ToString(); bsc = new P11SmartCard(sc.getCardType()); // MesajiIsle("Bilgi 3 - SmartCard Type: " + sc.getCardType().ToString() + " SlotID: " + Program.ParamSlotID, 0); bsc.openSession(Convert.ToInt64(Program.ParamSlotID)); } catch { try { sc = new SmartCard(tr.gov.tubitak.uekae.esya.api.smartcard.pkcs11.CardType.SAFESIGN); if (Program.ParamSlotID == "") { FindSlotID(); } string s = new string(sc.getSlotInfo(Convert.ToInt64(Program.ParamSlotID)).slotDescription); // MesajiIsle("slotDescription (SlotID(" +Program.ParamSlotID+"): "+ s, 0); //Program.ParamSlotIndex = index.ToString(); Program.CardType = sc.getCardType().ToString(); bsc = new P11SmartCard(sc.getCardType()); // MesajiIsle("Bilgi 3 - SmartCard Type: " + sc.getCardType().ToString() + " SlotID: " + Program.ParamSlotID, 0); bsc.openSession(Convert.ToInt64(Program.ParamSlotID)); } catch { try { sc = new SmartCard(tr.gov.tubitak.uekae.esya.api.smartcard.pkcs11.CardType.GEMPLUS); } catch { try { sc = new SmartCard(tr.gov.tubitak.uekae.esya.api.smartcard.pkcs11.CardType.TKART); } catch { try { sc = new SmartCard(tr.gov.tubitak.uekae.esya.api.smartcard.pkcs11.CardType.ALADDIN); } catch { try { sc = new SmartCard(tr.gov.tubitak.uekae.esya.api.smartcard.pkcs11.CardType.SEFIROT); //PresentSlots = sc.getTokenPresentSlotList(); // tokenli slot listesini al //for (m = 0; m < PresentSlots.Length; m++) //{ // ListSmartCard.Add(new P11SmartCard(sc.getCardType())); // ListSmartCard[index].openSession(PresentSlots[m]); // etugra icin 52481 // tekkartSerialNumber = StringUtil.ToString(ListSmartCard[index].getSerial()); // // sertifika getirme islemi // ImzaSertifikasiGetirTek(true, false, index); // PresentSlots[m].ToString(); // index = index + 1; //} } catch { } } } } } } if (sc != null) { PresentSlots = sc.getTokenPresentSlotList(); // tokenli slot listesini al // PresentSerials = sc.getTokenSerialNo(); // secim kutusu haline getirerek slotid al index = 0; // long SlotID = 0; if (PresentSlots.Length == 1) { Program.ParamSlotID = PresentSlots[index].ToString(); } else { Program.ParamSlotID = askOptionValue(null, null, PresentSlots, "Slot Listesi", new String[] { "Tamam" }); } // sc.getSlotInfo(slots[0]).slotDescription; string s = new string(sc.getSlotInfo(Convert.ToInt64(Program.ParamSlotID)).slotDescription); // MesajiIsle("slotDescription (SlotID(" +Program.ParamSlotID+"): "+ s, 0); //Program.ParamSlotIndex = index.ToString(); Program.CardType = sc.getCardType().ToString(); bsc = new P11SmartCard(sc.getCardType()); // MesajiIsle("Bilgi 3 - SmartCard Type: " + sc.getCardType().ToString() + " SlotID: " + Program.ParamSlotID, 0); bsc.openSession(Convert.ToInt64(Program.ParamSlotID)); //bsc.openSession(SlotID); //MessageBox.Show("bsc.login(5255)"); //bsc.login("5255"); //MessageBox.Show("login ok"); } else { MesajiIsle("Kart tipi belirlenemedi", 0); } } mSerialNumber = StringUtil.ToString(bsc.getSerial()); mSlotCount = terminals.Length; } catch (SmartCardException e) { throw e; } catch (PKCS11Exception e) { throw new SmartCardException("Pkcs11 exception", e); } catch (IOException e) { throw new SmartCardException("Smart Card IO exception - Detay bilgilerine bakınız", e); } }
/* * * @throws SmartCardException */ /** * BaseSigner interface for the requested certificate. Do not forget to logout after your crypto * operation finished * @param aCardPIN * @param aCert * @return * @throws SmartCardException */ public SmartCardManagerKimlikNodanSec(int desktop) { try { LOGGER.Debug("New SmartCardManager will be created"); String[] terminals = SmartOp.getCardTerminals(); if (terminals == null || terminals.Length == 0) { MesajiIsle("İçinde kart takılı bir kart okuyucu bulunamadı-SmartCardManagerKimlikNodanSec", 1); Program.KartOkuyucuYok = 1; return; // throw new SmartCardException("Kart takılı kart okuyucu bulunamadı"); } LOGGER.Debug("Kart okuyucu sayısı : " + terminals.Length); if (terminals.Length != Program.TerminalSayisi && Program.TerminalSayisi != 0) { MesajiIsle("Kart seçildikten sonra imzalama aşamasında yeni kart okuyucu takıldı.", 1); Program.KartOkuyucuYok = 1; return; } if (desktop == 0) { //******************************* // sadece parametre ile gelen slotID & karttipine session ac //******************************* // dbden oku MesajiIsle("ParamSQLServer:" + Program.ParamSQLServer + " " + Program.ParamSlotID, 0); String SqlCumlesi = ""; SqlCumlesi = "select * from AkilliKartlar where TCKimlikNo = '" + Program.ParamTCKimlikNo + "' and SlotID = " + Program.ParamSlotID; SqlConnection SQLFormVeriBaglantisi = new SqlConnection(); SQLFormVeriBaglantisi.ConnectionString = "server=" + Program.ParamSQLServer + ";user="******";pwd=" + Program.ParamSQLPassword + ";database=konur;"; SQLFormVeriBaglantisi.Open(); SqlCommand qryVeriOku = new SqlCommand(SqlCumlesi, SQLFormVeriBaglantisi); SqlDataReader reader = qryVeriOku.ExecuteReader(); string KayitliKartTipi = "", KayitliAdiSoyadi = "", KayitliPinKodu = ""; //while ( reader.Read(); KayitliKartTipi = reader["KartTipi"].ToString().Trim(); KayitliAdiSoyadi = reader["AdiSoyadi"].ToString().Trim(); reader.Close(); // ikinci veri okuma kismi // PIN kodunun teyidi SqlCumlesi = "select EimzaPin from TnmPersonel where TCKimlikNo = '" + Program.ParamTCKimlikNo + "' and isnull(EimzaPin,'') <> '' and CalismaDurumu = 'E' "; qryVeriOku.CommandText = SqlCumlesi; reader = qryVeriOku.ExecuteReader(); reader.Read(); KayitliPinKodu = reader["EimzaPin"].ToString().Trim(); reader.Close(); // baglantiyi kapat SQLFormVeriBaglantisi.Close(); if (KayitliKartTipi == "") { MesajiIsle("Kart Tipi kaydı AkilliKartlar tablosunda bulunamadı", 1); } if (KayitliPinKodu == "") { MesajiIsle("PIN Kodu kaydı Personel tablosunda bulunamadı. TCKimlikNo: " + Program.ParamTCKimlikNo, 1); } if (KayitliPinKodu != Program.ParamPin) { MesajiIsle("Bulunan PIN Kodu kaydı gelen PIN kodu ile eşleşmiyor. TnmPersonel PIN: " + KayitliPinKodu + " Param.PIN: " + Program.ParamPin + " TCKimlikNo: " + Program.ParamTCKimlikNo, 1); } MesajiIsle("KayitliKartTipi Okundu:" + KayitliKartTipi + " " + KayitliAdiSoyadi + "SlotID: " + Program.ParamSlotID, 0); // MesajiIsle("Secili SlotID:" + PTerminal, 0); try { bsc = new P11SmartCard(CardTypeConverter.AsCardType(KayitliKartTipi)); MesajiIsle("new P11SmartCard ok: " + KayitliKartTipi, 0); bsc.openSession(Convert.ToInt64(Program.ParamSlotID)); } catch { MesajiIsle("Kartı otomatik açmada hata oluştu:" + KayitliKartTipi + " " + KayitliAdiSoyadi, 0); //// etugra //bsc = new P11SmartCard(tr.gov.tubitak.uekae.esya.api.smartcard.pkcs11.CardType.SAFESIGN); //bsc.openSession(52481); ////MessageBox.Show(index.ToString() + " nolu terminal serino"); ////MessageBox.Show(StringUtil.ToString(bsc.getSerial())); ////MessageBox.Show("Serino gösterdi"); //// continue; } mSerialNumber = StringUtil.ToString(bsc.getSerial()); mSlotCount = terminals.Length; getSignatureCertificate(true, false); String Temp = mSignatureCert.ToString(); int startIndex1 = Temp.IndexOf("SERIALNUMBER="); //TC = Temp.Substring(startIndex1 + 13, 11); // adsoyad alma int startIndex2 = Temp.IndexOf("CN="); int endIndex = Temp.IndexOf(",", startIndex2); //Ad=Temp.Substring(startIndex2 + 3, endIndex - (startIndex2 + 3)); if (Program.ParamTCKimlikNo == Temp.Substring(startIndex1 + 13, 11) && Program.ParamAdiSoyadi == Temp.Substring(startIndex2 + 3, endIndex - (startIndex2 + 3))) { MesajiIsle("Otomatik olarak dogru karta konumlandi", 0); } else {// MesajiIsle("Dogru karta konumlanamadi. Karttaki TCNo ve Isim:" + // Temp.Substring(startIndex1 + 13, 11) +" "+ Temp.Substring(startIndex2 + 3, endIndex - (startIndex2 + 3))+ // ", Recetedeki Doktor TCNo ve Isim:" + Program.ParamTCKimlikNo + " " + Program.ParamAdiSoyadi, 1); } } else { // desktop = 1 ise // imzalama oncesi session acma kismi //******************************* // kart tipini deneyerek bul ve o kart tipine session ac //******************************* try { // sadece parametre ile gelen (giriste ilk timerda okunuyor ya) slotID & karttipine session ac bsc = new P11SmartCard(CardTypeConverter.AsCardType(Program.CardType)); bsc.openSession(Convert.ToInt64(Program.ParamSlotID)); // sonra tc, serial kontrolu falan yapmak lazim programa girip oto. kart okunduktan sonra kart degismis mi diye // .. // ... } catch { SmartCard sc = null; string KartTipi = ""; //, AdiSoyadi = "", TCKimlikNo = ""; // aslinda giriste okudugundan burada sadece giriste elde edilen terminal, slotid ve cardtype degerleri uzerinden baglanip // seri no kontrolu yapmali try sc catch kisimlarini kaldirmali sadece giriste birakmali... 11.12.2015 try { sc = new SmartCard(tr.gov.tubitak.uekae.esya.api.smartcard.pkcs11.CardType.AKIS); } catch { try { sc = new SmartCard(tr.gov.tubitak.uekae.esya.api.smartcard.pkcs11.CardType.SAFESIGN); } catch { try { sc = new SmartCard(tr.gov.tubitak.uekae.esya.api.smartcard.pkcs11.CardType.GEMPLUS); } catch { try { sc = new SmartCard(tr.gov.tubitak.uekae.esya.api.smartcard.pkcs11.CardType.TKART); } catch { try { sc = new SmartCard(tr.gov.tubitak.uekae.esya.api.smartcard.pkcs11.CardType.ALADDIN); } catch { try { sc = new SmartCard(tr.gov.tubitak.uekae.esya.api.smartcard.pkcs11.CardType.SEFIROT); //PresentSlots = sc.getTokenPresentSlotList(); // tokenli slot listesini al //for (m = 0; m < PresentSlots.Length; m++) //{ // ListSmartCard.Add(new P11SmartCard(sc.getCardType())); // ListSmartCard[index].openSession(PresentSlots[m]); // etugra icin 52481 // tekkartSerialNumber = StringUtil.ToString(ListSmartCard[index].getSerial()); // // sertifika getirme islemi // ImzaSertifikasiGetirTek(true, false, index); // PresentSlots[m].ToString(); // index = index + 1; //} } catch { } } } } } } if (sc != null) { // slotid tesbit et long[] PresentSlots; // long SlotID = 0; PresentSlots = sc.getTokenPresentSlotList(); // tokenli slot listesini al if (PresentSlots.Length == 1) { Program.ParamSlotID = PresentSlots[0].ToString(); } else { Program.ParamSlotID = SmartCardManager.askOptionValue(null, null, PresentSlots, "Slot Listesi", new String[] { "Tamam" }); } KartTipi = sc.getCardType().ToString(); try { bsc = new P11SmartCard(sc.getCardType()); MesajiIsle("SmartCard Type: " + KartTipi + " SlotID: " + Program.ParamSlotID, 0); bsc.openSession(Convert.ToInt64(Program.ParamSlotID)); } catch { MesajiIsle("Kartı açmada hata oluştu. Kart Tipi: " + KartTipi + " SlotID: " + Program.ParamSlotID, 0); } } else { MesajiIsle("Kart tipi belirlenemedi", 0); } } //mSerialNumber = StringUtil.ToString(bsc.getSerial()); //mSlotCount = terminals.Length; getSignatureCertificate(true, false); String Temp = mSignatureCert.ToString(); // adsoyad alma (gereksiz... labela koymak istersen dursun, degilse sil...) 11.12.2015 //int startIndex1 = Temp.IndexOf("SERIALNUMBER="); //int startIndex2 = Temp.IndexOf("CN="); //int endIndex = Temp.IndexOf(",", startIndex2); //KartTipi = sc.getCardType().ToString(); //TCKimlikNo = Temp.Substring(startIndex1 + 13, 11); //AdiSoyadi = Temp.Substring(startIndex2 + 3, endIndex - (startIndex2 + 3)); } } catch (SmartCardException e) { throw e; } catch (PKCS11Exception e) { throw new SmartCardException("Pkcs11 exception", e); } catch (IOException e) { throw new SmartCardException("Smart Card IO exception - Detay bilgilerine bakınız", e); } }