Exemplo n.º 1
0
        private SmartCardManager()
        {
            try
            {
                Console.WriteLine("New SmartCardManager will be created");
                String[] terminals = SmartOp.getCardTerminals();
                String   terminal;
                //List<CardTypeConfig> cards = new SmartCardConfigParser().readConfig();
                //CardType.applyCardTypeConfig(cards);

                if (terminals == null || terminals.Length == 0)
                {
                    throw new SmartCardException("Kart takılı kart okuyucu bulunamadı");
                }

                if (terminals.Length > 1)
                {
                    throw new SmartCardException("Birden fazla kart okuyucu bulundu.");
                }

                Console.WriteLine("Kart okuyucu sayısı : " + terminals.Length);

                int index = 0;
                if (terminals.Length == 1)
                {
                    terminal = terminals[index];
                }
                else
                {
                    //index = askOption(null, null, terminals, "Okuyucu Listesi", new String[] { "Tamam" });
                    terminal = terminals[index];
                }
                Console.WriteLine("PKCS11 Smartcard will be created");
                Pair <long, CardType> slotAndCardType = SmartOp.getSlotAndCardType(terminal);

                bsc = new P11SmartCard(slotAndCardType.getmObj2());
                bsc.openSession(slotAndCardType.getmObj1());

                mSerialNumber = StringUtil.ToString(bsc.getSerial());
                mSlotCount    = terminals.Length;
            }
            catch (SmartCardException e)
            {
                throw new SmartCardException("Kart Okunurken bir hata oluştu(SC).", e);
            }
            catch (PKCS11Exception e)
            {
                throw new SmartCardException("Kart okunurken bir hata oluştu(PKCS11).", e);
            }
            catch (IOException e)
            {
                throw new SmartCardException("Kart okunurken bir hata oluştu(IO).", e);
            }
            catch (Exception e)
            {
                throw new SmartCardException("Genel bir hata oluştu(E)", e);
            }
        }
Exemplo n.º 2
0
        /*
         *
         * @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[] terminals = SmartOp.getCardTerminals();
                String   terminal;


                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;
                }
                Program.TerminalSayisi = terminals.Length;
                int index = 0;
                if (terminals.Length == 1)
                {
                    terminal = terminals[index];
                }
                else
                {
                    index    = askOption(null, null, terminals, "Okuyucu Listesi", new String[] { "Tamam" });
                    terminal = terminals[index];
                }
                Pair <long, CardType> slotAndCardType = SmartOp.getSlotAndCardType(terminal);
                bsc = new P11SmartCard(slotAndCardType.getmObj2());
                bsc.openSession(slotAndCardType.getmObj1());

                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);
            }
        }
Exemplo n.º 3
0
            public byte[] Sign(byte[] message)
            {
                Pair <long, CardType> pair      = SmartOp.getSlotAndCardType(terminal);
                P11SmartCard          smartCard = new P11SmartCard(pair.getmObj2());

                smartCard.openSession(pair.getmObj1());
                smartCard.login(pin);
                BaseSigner signer = smartCard.getSigner(cert, Algorithms.SIGNATURE_RSA_SHA256);

                byte[] buffer = signer.sign(message);
                smartCard.logout();
                smartCard.closeSession();
                return(buffer);
            }
Exemplo n.º 4
0
        /**
         *
         * @throws SmartCardException
         */

        private SmartCardManager()
        {
            try
            {
                LOGGER.Debug("New SmartCardManager will be created");
                String[] terminals = SmartOp.getCardTerminals();
                String   terminal;


                if (terminals == null || terminals.Length == 0)
                {
                    throw new SmartCardException("Kart takılı kart okuyucu bulunamadı");
                }

                LOGGER.Debug("Kart okuyucu sayısı : " + terminals.Length);

                int index = 0;
                if (terminals.Length == 1)
                {
                    terminal = terminals[index];
                }
                else
                {
                    index    = askOption(null, null, terminals, "Okuyucu Listesi", new String[] { "Tamam" });
                    terminal = terminals[index];
                }
                LOGGER.Debug("PKCS11 Smartcard will be created");
                Pair <long, CardType> slotAndCardType = SmartOp.getSlotAndCardType(terminal);
                bsc = new P11SmartCard(slotAndCardType.getmObj2());
                bsc.openSession(slotAndCardType.getmObj1());


                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", e);
            }
        }
Exemplo n.º 5
0
        public List <ECertificate> getSignatureCertificates(string terminal)
        {
            List <ECertificate>   certs           = new List <ECertificate>();
            Pair <long, CardType> slotAndCardType = SmartOp.getSlotAndCardType(terminal);
            IBaseSmartCard        smartCard       = getSmartCard(terminal);

            smartCard.openSession(slotAndCardType.getmObj1());
            List <byte[]> byteOfCerts = smartCard.getSignatureCertificates();

            foreach (byte[] bs in byteOfCerts)
            {
                ECertificate cert = new ECertificate(bs);
                certs.Add(cert);
            }
            return(certs);
        }
Exemplo n.º 6
0
        public IBaseSmartCard getSmartCard(string terminal)
        {
            Pair <long, CardType> slotAndCardType = SmartOp.getSlotAndCardType(terminal);

            return(new P11SmartCard(slotAndCardType.getmObj2()));
        }
Exemplo n.º 7
0
        /*
         *
         * @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);
            }
        }