Example #1
0
        private static CCAddress GetAddress(PTEID_EIDCard card)
        {
            var  pins      = card.getPins();
            var  pin       = pins.getPinByPinRef(PTEID_Pin.ADDR_PIN);
            uint triesLeft = 0;

            if (pin.getTriesLeft() > 1 && pin.verifyPin("0000", ref triesLeft, true))
            {
                var addr = card.getAddr();

                return(new CCAddress
                {
                    Municipality = addr.getMunicipality(),
                    PostalLocality = addr.getPostalLocality(),
                    Place = addr.getPlace(),
                    StreetName = addr.getStreetName(),
                    StreetType = addr.getStreetType(),
                    Side = addr.getSide(),
                    Locality = addr.getLocality(),
                    Floor = addr.getFloor(),
                    DoorNo = addr.getDoorNo(),
                    District = addr.getDistrict(),
                    CountryCode = addr.getCountryCode(),
                });
            }

            return(null);
        }
Example #2
0
 public static void Init(String readerName){
      try {
          PTEID_ReaderSet.initSDK();
          readerSet = PTEID_ReaderSet.instance();
          if (readerName == null || readerName == String.Empty)
              readerContext = readerSet.getReaderByNum(0);
          else 
              readerContext = readerSet.getReaderByName(readerName);
          
          idCard = readerContext.getEIDCard();
      } catch (Exception ex) {
          throw new PteidException(0);
      }
 }
        /*
         * Initializes the SDK and sets main variables
         */
        public void Initiate()
        {
            //Must always be called in the beginning of the program
            PTEID_ReaderSet.initSDK();

            //Gets the set of connected readers, if there is any inserted
            readerSet = PTEID_ReaderSet.instance();

            //Gets the first reader
            //When multiple readers are connected, you should iterate through the various indexes with the methods getReaderName and getReaderByName
            readerContext = readerSet.getReader();

            //Gets the card instance
            eidCard = readerContext.getEIDCard();
        }
Example #4
0
        public ActionResult Get()
        {
            // DOC: https://amagovpt.github.io/autenticacao.gov/manual_sdk.html#windows

            try
            {
                PTEID_ReaderContext readerContext = PTEID_ReaderSet.instance().getReader();
                PTEID_EIDCard       card          = readerContext.getEIDCard();

                var data = GetData(card);

                return(Ok(data));
            }
            catch (PTEID_ExNoCardPresent)
            {
                return(NotFound());
            }
        }
Example #5
0
        private static CCData GetData(PTEID_EIDCard card)
        {
            var eid = card.getID();

            return(new CCData
            {
                GivenName = eid.getGivenName(),
                DocumentNumber = eid.getDocumentNumber(),
                Surname = eid.getSurname(),
                Gender = eid.getGender(),
                DateOfBirth = eid.getDateOfBirth(),
                Height = eid.getHeight(),
                Nationality = eid.getNationality(),
                Country = eid.getCountry(),
                Parents = eid.getParents(),
                TaxNo = eid.getTaxNo(),
                CivilianIdNumber = eid.getCivilianIdNumber(),
                HealthNumber = eid.getHealthNumber(),
                Address = GetAddress(card),
                Photo = eid.getPhotoObj()?.getphoto()?.GetBytes(),
            });
        }
Example #6
0
        public void dumpID(){
		    try {
			    this.idCard = this.readerContext.getEIDCard();

			    Console.WriteLine("\n\nCitizen identification");
			    Console.WriteLine("--------------------------------------");
			    Console.WriteLine("deliveryEntity              " + this.idCard.getID().getIssuingEntity());
			    Console.WriteLine("country                     " + this.idCard.getID().getCountry());
			    Console.WriteLine("documentType                " + this.idCard.getID().getDocumentType());
			    Console.WriteLine("cardNumber                  " + this.idCard.getID().getDocumentNumber());
			    Console.WriteLine("cardNumberPAN               " + this.idCard.getID().getDocumentPAN());
			    Console.WriteLine("cardVersion                 " + this.idCard.getID().getDocumentVersion());
			    Console.WriteLine("deliveryDate                " + this.idCard.getID().getValidityBeginDate());
			    Console.WriteLine("locale                      " + this.idCard.getID().getLocalofRequest());
			    Console.WriteLine("validityDate                " + this.idCard.getID().getValidityEndDate());
			    Console.WriteLine("name                        " + this.idCard.getID().getSurname());
			    //Console.writeline("firstname                   " + id.getGivenName());
			    Console.WriteLine("sex                         " + this.idCard.getID().getGender());
			    Console.WriteLine("nationality                 " + this.idCard.getID().getNationality());
			    Console.WriteLine("birthDate                   " + this.idCard.getID().getDateOfBirth());
			    Console.WriteLine("height                      " + this.idCard.getID().getHeight());
			    Console.WriteLine("numBI                       " + this.idCard.getID().getCivilianIdNumber());
			    Console.WriteLine("nameFather                  " + this.idCard.getID().getSurnameFather());
			    Console.WriteLine("firstnameFather             " + this.idCard.getID().getGivenNameFather());
			    Console.WriteLine("nameMother                  " + this.idCard.getID().getSurnameMother());
			    Console.WriteLine("firstnameMother             " + this.idCard.getID().getGivenNameMother());
			    Console.WriteLine("numNIF                      " + this.idCard.getID().getTaxNo());
			    Console.WriteLine("numSS                       " + this.idCard.getID().getSocialSecurityNumber());
			    Console.WriteLine("numSNS                      " + this.idCard.getID().getHealthNumber());
			    Console.WriteLine("Accidental indications      " + this.idCard.getID().getAccidentalIndications());
			    Console.WriteLine("mrz1                        " + this.idCard.getID().getMRZ1());
			    Console.WriteLine("mrz2                        " + this.idCard.getID().getMRZ2());
			    Console.WriteLine("mrz3                        " + this.idCard.getID().getMRZ3());
			    Console.WriteLine("--------------------------------------");

		    } catch (PTEID_Exception e) {
                Console.WriteLine(e.ToString());
		    }
	    }
Example #7
0
        public static void Init(String readerName)
        {
            try
            {
                PTEID_ReaderSet.initSDK();
                readerSet = PTEID_ReaderSet.instance();
                if (readerName == null || readerName == String.Empty)
                {
                    readerContext = readerSet.getReader();
                }
                else
                {
                    readerContext = readerSet.getReaderByName(readerName);
                }

                pteidlib_dotNet.setCompatReaderContext(readerContext);

                idCard = readerContext.getEIDCard();
            }
            catch (PTEID_ExNoReader)
            {
                throw new PteidException(SC_ERROR_NO_READERS_FOUND);
            }
            catch (PTEID_ExNoCardPresent)
            {
                throw new PteidException(SC_ERROR_CARD_NOT_PRESENT);
            }
            catch (PTEID_ExCardTypeUnknown)
            {
                throw new PteidException(SC_ERROR_INVALID_CARD);
            }
            catch (PTEID_Exception ex)
            {
                throw new PteidException(ex.GetError());
            }
        }
Example #8
0
        /*
         * Sign a given data with the SHA-1 algorithm. This process required the Authentication PIN
         * 
         * @param inputData
         *            the data to be signed
         * @return the byte[] correspondent to what was given but signed
         * 
         * @throws CCError
         */
        /*
        public byte[] signData(final byte[] inputData) throws CCError {
        // we shouldn't use a byte[] from parameter instead we should use a copy of the data.
        final byte[] dataToBeSigned = inputData.clone();
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            final byte[] digest = md.digest(dataToBeSigned);

            final byte[] SHA1_MAGIC_STRING = new byte[] { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 };

            final byte[] hashMagicString = SHA1_MAGIC_STRING;

            final byte[] fullDigest = Arrays.copyOf(hashMagicString, hashMagicString.length + digest.length);
            System.arraycopy(digest, 0, fullDigest, hashMagicString.length, digest.length);

            final PTEID_PIN PIN = new PTEID_PIN(PINUtils.getAuthenticationPin(card));
            pinCallback.verifyPIN(PIN, PIN.getLabel(), bundle.getString("request.authentication.pin.msg"),
                      bundle.getString("request.authentication.pin.msgForPINPad"));

            final PTEID_ByteArray outputData = card.Sign(new PTEID_ByteArray(fullDigest, fullDigest.length));

            return outputData.GetBytes();
        } catch (PTEID_Exception ex) {
            throw new CCError(ex);
        } catch (NoSuchAlgorithmException ex) {
            throw new CCError(ex);
        }
        }

         */





        public void signData()
        {

            String str_to_be_signed;
            PTEID_ByteArray content_to_be_signed;
            PTEID_ByteArray content_signed;

            str_to_be_signed = "String a ser assinada";

            try
            {
                this.idCard = this.readerContext.getEIDCard();
    // TO FIX
                //content_to_be_signed = new PTEID_ByteArray(str_to_be_signed.getBytes(), str_to_be_signed.length());
    //            content_signed = this.idCard.Sign(content_to_be_signed);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Example #9
0
        private void readNotes()
	{
		byte[] content;
		String NOTES_FILE_ID = "3f005f00ef07";
		String notes_content="";

		try {
			this.idCard = this.readerContext.getEIDCard();
			PTEID_ByteArray bytesRead = idCard.readFile(NOTES_FILE_ID, 0);
			//Get Only 256 bytes
			content =  getFirst256(bytesRead.GetBytes());
            char[] sa;
            sa = new char[2];
            sa[0] = 'a';
            sa[1] = '2';

            notes_content = content.ToString();
			//notes_content= new String(getFirst256(content)); // yes, this will remove valid white space in the end...
		} catch (Exception e) {
			Console.WriteLine(e.ToString());
		}
		Console.WriteLine(notes_content);
	}