Beispiel #1
0
        public static void WriteFileInOffset(byte[] file, byte[] data, byte pinId, int offset)
        {
            PTEID_ByteArray pb  = new PTEID_ByteArray(data, (uint)data.Length);
            PTEID_Pin       pin = null;

            if (readerContext != null)
            {
                try
                {
                    if (pinId != 0)
                    {
                        PTEID_Pins pins = idCard.getPins();
                        for (uint pinIdx = 0; pinIdx < pins.count(); pinIdx++)
                        {
                            pin = (pins.getPinByNumber(pinIdx));
                            if (pin.getPinRef() == pinId)
                            {
                                break;
                            }
                        }
                    }

                    bool ret = idCard.writeFile(ashex(file), pb, pin, "", (uint)offset);
                }
                catch (PTEID_Exception ex)
                {
                    handleUnderlyingException(ex);
                }
            }
        }
Beispiel #2
0
        /*
         * Prints address info present in the card (requires address pin)
         */
        public void ShowAddressInfo()
        {
            //The number of tries that the user has (updated with each call to verifyPin)
            uint triesLeft = uint.MaxValue;

            //Get the collection of card PINs
            PTEID_Pins pins = eidCard.getPins();

            //Get the specific PIN we want
            PTEID_Pin pin = pins.getPinByPinRef(PTEID_Pin.ADDR_PIN);

            //If the method verifyPin is called with "" as the first argument it prompts the middleware GUI for the user to insert its PIN
            //Otherwise we can provide the PIN as the first argument and the end result will be the same
            if (pin.verifyPin("", ref triesLeft, true))
            {
                //SDK class that handles address related information
                PTEID_Address address = eidCard.getAddr();
                Console.WriteLine("\n\nReading address details of: " + eid.getGivenName() + " " + eid.getSurname() + ":");

                if (address.isNationalAddress())
                {
                    Console.WriteLine("---National Address---");
                    Console.WriteLine("District:                       " + address.getDistrict());
                    Console.WriteLine("District (code):                " + address.getDistrictCode());
                    Console.WriteLine("Municipality:                   " + address.getMunicipality());
                    Console.WriteLine("Municipality (code):            " + address.getMunicipalityCode());
                    Console.WriteLine("Parish:                         " + address.getCivilParish());
                    Console.WriteLine("Parish (code):                  " + address.getCivilParishCode());
                    Console.WriteLine("Street Type (Abbreviated):      " + address.getAbbrStreetType());
                    Console.WriteLine("Street Type:                    " + address.getStreetType());
                    Console.WriteLine("Street Name:                    " + address.getStreetName());
                    Console.WriteLine("Building Type (Abbreviated):    " + address.getAbbrBuildingType());
                    Console.WriteLine("Building Type:                  " + address.getBuildingType());
                    Console.WriteLine("Door nº:                        " + address.getDoorNo());
                    Console.WriteLine("Floor:                          " + address.getFloor());
                    Console.WriteLine("Side:                           " + address.getSide());
                    Console.WriteLine("Locality:                       " + address.getLocality());
                    Console.WriteLine("Place:                          " + address.getPlace());
                    Console.WriteLine("Postal code:                    " + address.getZip4() + "-" + address.getZip3());
                    Console.WriteLine("Postal Locality:                " + address.getPostalLocality());
                }
                else
                {
                    Console.WriteLine("---Foreign Address---");
                    Console.WriteLine("Address:     " + address.getForeignAddress());
                    Console.WriteLine("City:        " + address.getForeignCity());
                    Console.WriteLine("Locality:    " + address.getForeignLocality());
                    Console.WriteLine("Postal Code: " + address.getForeignPostalCode());
                    Console.WriteLine("Region:      " + address.getForeignRegion());
                    Console.WriteLine("Country:     " + address.getForeignCountry());
                }
            }
        }
        /*
         * Saves all card info in XML format and prints it to a file
         */
        public void SaveXML()
        {
            //The number of tries that the user has (updated with each call to verifyPin)
            uint triesLeft = uint.MaxValue;

            //Sets of the card PINs
            PTEID_Pins pins = eidCard.getPins();

            //Gets the specific PIN we want
            //ADDR_PIN - Address Pin
            //AUTH_PIN - Authentication Pin
            //SIGN_PIN - Signature Pin
            PTEID_Pin pin = pins.getPinByPinRef(PTEID_Pin.ADDR_PIN);

            //If the method verifyPin is called with "" as the first argument it prompts the middleware GUI for the user to insert its PIN
            //Otherwise we can send the PIN as the first argument and the end result will be the same
            if (pin.verifyPin("", ref triesLeft, true))
            {
                //Selects information to be requested in XML format
                //You can add or remove fields at will
                PTEID_XmlUserRequestedInfo requestedInfo = new PTEID_XmlUserRequestedInfo();

                XMLUserData[] data = new XMLUserData[] { XMLUserData.XML_PHOTO, XMLUserData.XML_NAME, XMLUserData.XML_GIVEN_NAME,
                                                         XMLUserData.XML_SURNAME, XMLUserData.XML_NIC, XMLUserData.XML_EXPIRY_DATE, XMLUserData.XML_GENDER, XMLUserData.XML_HEIGHT,
                                                         XMLUserData.XML_NATIONALITY, XMLUserData.XML_DATE_OF_BIRTH, XMLUserData.XML_GIVEN_NAME_FATHER, XMLUserData.XML_SURNAME_FATHER,
                                                         XMLUserData.XML_GIVEN_NAME_MOTHER, XMLUserData.XML_SURNAME_MOTHER, XMLUserData.XML_ACCIDENTAL_INDICATIONS, XMLUserData.XML_DOCUMENT_NO,
                                                         XMLUserData.XML_TAX_NO, XMLUserData.XML_SOCIAL_SECURITY_NO, XMLUserData.XML_HEALTH_NO, XMLUserData.XML_MRZ1, XMLUserData.XML_MRZ2,
                                                         XMLUserData.XML_MRZ3, XMLUserData.XML_CARD_VERSION, XMLUserData.XML_CARD_NUMBER_PAN, XMLUserData.XML_ISSUING_DATE, XMLUserData.XML_ISSUING_ENTITY,
                                                         XMLUserData.XML_DOCUMENT_TYPE, XMLUserData.XML_LOCAL_OF_REQUEST, XMLUserData.XML_VERSION, XMLUserData.XML_DISTRICT, XMLUserData.XML_MUNICIPALITY,
                                                         XMLUserData.XML_CIVIL_PARISH, XMLUserData.XML_ABBR_STREET_TYPE, XMLUserData.XML_STREET_TYPE, XMLUserData.XML_STREET_NAME, XMLUserData.XML_ABBR_BUILDING_TYPE,
                                                         XMLUserData.XML_BUILDING_TYPE, XMLUserData.XML_DOOR_NO, XMLUserData.XML_FLOOR, XMLUserData.XML_SIDE, XMLUserData.XML_PLACE, XMLUserData.XML_LOCALITY,
                                                         XMLUserData.XML_ZIP4, XMLUserData.XML_ZIP3, XMLUserData.XML_POSTAL_LOCALITY, XMLUserData.XML_PERSONAL_NOTES, XMLUserData.XML_FOREIGN_COUNTRY,
                                                         XMLUserData.XML_FOREIGN_ADDRESS, XMLUserData.XML_FOREIGN_CITY, XMLUserData.XML_FOREIGN_REGION, XMLUserData.XML_FOREIGN_LOCALITY, XMLUserData.XML_FOREIGN_POSTAL_CODE };

                //Adds each field of the vector to the request
                foreach (XMLUserData field in data)
                {
                    requestedInfo.add(field);
                }

                //Gets the XML information from the card and transforms it to a string
                PTEID_CCXML_Doc ccxml     = eidCard.getXmlCCDoc(requestedInfo);
                String          resultXml = ccxml.getCCXML();

                using (var streamWriter = new StreamWriter("../../files/info.xml", false))
                {
                    streamWriter.WriteLine(resultXml);
                    streamWriter.Close();
                }

                Console.WriteLine("Your XML info has been saved successfully in files/info.xml.");
            }
        }
        /*
         * Writes notes to the card (needs authentication pin)
         */
        public void WriteNotes()
        {
            //Prepares a string (notes) to be written in the card
            String notes = "We wrote successfully to the card!";

            byte[]          notesBytes    = Encoding.UTF8.GetBytes(notes);
            PTEID_ByteArray personalNotes = new PTEID_ByteArray(notesBytes, (uint)notesBytes.Length);
            Boolean         ok;

            //Gets authentication pin
            PTEID_Pins pins = eidCard.getPins();
            PTEID_Pin  pin  = pins.getPinByPinRef(PTEID_Pin.AUTH_PIN);

            //Writes notes to card
            ok = eidCard.writePersonalNotes(personalNotes, pin);
            Console.WriteLine("Was writing successful? " + (ok? "Yes!" : "No."));
        }
Beispiel #5
0
        /*
         * Prints the current tries left for each pin in the card
         */
        public void showPinInfo()
        {
            Console.WriteLine("User:"******"Name: " + eid.getGivenName() + " " + eid.getSurname());
            Console.WriteLine("List of pins and respective \"tries left\":");

            //Gets the Pins objects (with the informations of all pins)
            PTEID_Pins pins = eidCard.getPins();

            //Iterates through all pins and prints the number of tries left for the user to type the correct pin
            for (uint i = 0; i < pins.count(); i++)
            {
                PTEID_Pin pin = pins.getPinByNumber(i);

                Console.WriteLine(pin.getLabel() + ":\nTries left: " + pin.getTriesLeft());
            }
        }
Beispiel #6
0
        public static int UnblockPIN_Ext(byte pinId, String puk, String newPin, uint flags)
        {
            uint ul  = 0;
            int  ret = -1;

            if (readerContext != null)
            {
                try
                {
                    if (pinId != 1 && pinId != PTEID_AUTH_PIN && pinId != PTEID_SIGNATURE_PIN && pinId != PTEID_ADDRESS_PIN)
                    {
                        return(0);
                    }

                    PTEID_Pins pins = idCard.getPins();
                    for (uint pinIdx = 0; pinIdx < pins.count(); pinIdx++)
                    {
                        PTEID_Pin pin = pins.getPinByNumber(pinIdx);
                        if (pin.getPinRef() == pinId)
                        {
                            if (!pin.unlockPin(puk, newPin, ref ul, flags))
                            {
                                if (ul == 0)
                                {
                                    throw new PteidException(SC_ERROR_AUTH_METHOD_BLOCKED);
                                }
                                else
                                {
                                    throw new PteidException(SC_ERROR_PIN_CODE_INCORRECT);
                                }
                            }
                            ret = (int)ul;
                        }
                    }
                }
                catch (PTEID_Exception ex)
                {
                    handleUnderlyingException(ex);
                }
            }

            return(ret);
        }
Beispiel #7
0
        public static byte[] ReadFile(byte[] fileID, byte pinId)
        {
            PTEID_ByteArray pb = new PTEID_ByteArray();

            byte[]    retArray = null;
            PTEID_Pin pin      = null;

            if (readerContext != null)
            {
                try {
                    if (pinId != 0)
                    {
                        PTEID_Pins pins = idCard.getPins();
                        for (uint pinIdx = 0; pinIdx < pins.count(); pinIdx++)
                        {
                            pin = (pins.getPinByNumber(pinIdx));
                            if (pin.getPinRef() == pinId)
                            {
                                break;
                            }
                        }
                    }

                    idCard.readFile(ashex(fileID), pb, pin);

                    int trimmedSize = trimStart(pb.GetBytes());
                    if ((trimmedSize == 0) && (pb.Size() > 0))
                    {
                        trimmedSize = (int)pb.Size();
                    }

                    retArray = new byte[trimmedSize];
                    Array.Copy(pb.GetBytes(), 0, retArray, 0, retArray.Length);
                }
                catch (PTEID_Exception ex)
                {
                    handleUnderlyingException(ex);
                }
            }
            return(retArray);
        }
Beispiel #8
0
        public static int VerifyPIN(byte pinId, String strPin)
        {
            uint tries_left = 0;
            int  triesLeft  = 0;

            if (readerContext != null)
            {
                //PIN ID = 1 is legacy from IAS 1.01 cards
                if (pinId != 1 && pinId != PTEID_AUTH_PIN && pinId != PTEID_SIGNATURE_PIN && pinId != PTEID_ADDRESS_PIN)
                {
                    return(0);
                }
                try {
                    PTEID_Pins pins = idCard.getPins();
                    for (uint pinIdx = 0; pinIdx < pins.count(); pinIdx++)
                    {
                        PTEID_Pin pin = pins.getPinByNumber(pinIdx);
                        if (pin.getPinRef() == pinId)
                        {
                            bool ret = pin.verifyPin(strPin, ref tries_left, false);
                            if (!ret)
                            {
                                if (tries_left == 0)
                                {
                                    throw new PteidException(SC_ERROR_AUTH_METHOD_BLOCKED);
                                }
                                else
                                {
                                    throw new PteidException(SC_ERROR_PIN_CODE_INCORRECT);
                                }
                            }
                            triesLeft = (int)tries_left;
                        }
                    }
                    return(triesLeft);
                } catch (PTEID_Exception ex) {
                    handleUnderlyingException(ex);
                }
            }
            return(triesLeft);
        }
Beispiel #9
0
        public static int ChangePIN(byte pinId, String oldPin, String newPin)
        {
            uint ul        = 0;
            int  triesLeft = 0;

            if (readerContext != null)
            {
                if (pinId != 1 && pinId != PTEID_AUTH_PIN && pinId != PTEID_SIGNATURE_PIN && pinId != PTEID_ADDRESS_PIN)
                {
                    return(0);
                }
                try {
                    PTEID_Pins pins = idCard.getPins();
                    for (uint pinIdx = 0; pinIdx < pins.count(); pinIdx++)
                    {
                        PTEID_Pin pin = pins.getPinByNumber(pinIdx);
                        if (pin.getPinRef() == pinId)
                        {
                            if (!pin.changePin(oldPin, newPin, ref ul, pin.getLabel(), false))
                            {
                                if (ul == 0)
                                {
                                    throw new PteidException(SC_ERROR_AUTH_METHOD_BLOCKED);
                                }
                                else
                                {
                                    throw new PteidException(SC_ERROR_PIN_CODE_INCORRECT);
                                }
                            }
                            triesLeft = (int)ul;
                            break;
                        }
                    }
                }
                catch (PTEID_Exception ex)  {
                    handleUnderlyingException(ex);
                }
            }
            return(triesLeft);
        }
Beispiel #10
0
        public static PteidAddr GetAddr()
        {
            try
            {
                uint       ul   = 0;
                PTEID_Pins pins = idCard.getPins();
                for (uint i = 0; i < pins.count(); i++)
                {
                    PTEID_Pin pin = pins.getPinByNumber(i);
                    if (pin.getPinRef() == PTEID_ADDRESS_PIN)
                    {
                        if (pin.verifyPin("", ref ul, false))
                        {
                            return(new PteidAddr(idCard.getAddr()));
                        }
                        else
                        {
                            if (ul == 0)
                            {
                                throw new PteidException(SC_ERROR_AUTH_METHOD_BLOCKED);
                            }
                            else
                            {
                                throw new PteidException(SC_ERROR_PIN_CODE_INCORRECT);
                            }
                        }
                    }
                }
            }
            catch (PTEID_Exception ex)
            {
                handleUnderlyingException(ex);
            }

            //Fix build: should never happen
            return(null);
        }
Beispiel #11
0
        public static PteidPin[] GetPINs()
        {
            PteidPin[] pinArray = null;
            int        currentId;

            if (readerContext != null)
            {
                try {
                    PTEID_Pins pins = idCard.getPins();
                    pinArray = new PteidPin[PTEID_PIN_COUNT];
                    for (uint pinIdx = 0; pinIdx < pins.count(); pinIdx++)
                    {
                        PTEID_Pin pin = pins.getPinByNumber(pinIdx);
                        if (pin.getId() == 1 || pin.getId() == 2 || pin.getId() == 3)
                        {
                            currentId                      = (int)pin.getId() - 1;
                            pinArray[currentId]            = new PteidPin();
                            pinArray[currentId].flags      = (int)pin.getFlags();
                            pinArray[currentId].usageCode  = (int)pin.getId(); // martinho: might not be the intended use, but gives the expected compatible result.
                            pinArray[currentId].pinType    = (int)pin.getType();
                            pinArray[currentId].label      = pin.getLabel();
                            pinArray[currentId].triesLeft  = pin.getTriesLeft();
                            pinArray[currentId].id         = (byte)pin.getPinRef();
                            pinArray[currentId].shortUsage = null;
                            pinArray[currentId].longUsage  = null;
                        }
                    }
                }
                catch (PTEID_Exception ex)
                {
                    throw new PteidException(ex.GetError());
                }
            }

            return(pinArray);
        }