Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read NFC tag from "Microsoft IDF 0" my device is a surface go 2 bussiness #232

Open
joselopezbinoovo opened this issue May 16, 2023 · 0 comments

Comments

@joselopezbinoovo
Copy link

My problem is that my program doesn't decode the buffer whitch I recieve from the nfc tag.

The code works well with ACR122 but not with MICROSOF IDF, and I don't understand why.

from smartcard.System import readers
from smartcard.Exceptions import NoCardException
import sys
import time
import requests
from smartcard.util import toHexString

r = readers()

reader = r[0]

print ("Using: ", reader)
error = 'a'
espera = 'a'
#disconnect =''

while espera != '':
     espera = ''
     while error != '':  
          error = '' 
          try: 
               connection = reader.createConnection()
               #@print(connection)
               connection.connect()
          except NoCardException as e:
               error = e 
               time.sleep(1)
               
     COMMAND = [0xFF, 0x86, 0x00, 0x00, 0x05, 0x01, 0x00, 4, 0x60, 0x00]
     print(COMMAND)
     data, sw1, sw2 = connection.transmit(COMMAND)
     print(data,sw1,sw2)    
     if (sw1, sw2) == (0x90, 0x0):
          print ("Status: Decryption sector "+ '1' +" using key #0 as Key A successful.")
     elif (sw1, sw2) == (0x63, 0x0):
          #print ("Status: Decryption sector "+ '1' +" failed. Trying as Key B")
          COMMAND = [0xFF, 0x86, 0x00, 0x00, 0x05, 0x01, 0x00,4, 0x61, 0x00]
          data, sw1, sw2 = connection.transmit(COMMAND)
          if (sw1, sw2) == (0x90, 0x0) or (0x63, 0x0):
               print ("Status: Decryption sector "+ '1' +" using key #0 as Key B successful.")
          elif (sw1, sw2) == (0x63, 0x0):
               print('error de datos')
               sys.exit()
     array = []
     for block in range(1, 8):

          COMMAND = [0xFF, 0xB0, 0x00]
          COMMAND.append(block)
          COMMAND.append(16)
          data, sw1, sw2 = connection.transmit(COMMAND)
          #print ("block "+ str(block) +":\t"+ toHexString(data) +" | "+''.join(chr(i) for i in data))
          array.append(' '.join(chr(i)for i in data))
          
     
     listToStr = ' '.join([str(elem) for elem in array])
     listToStr=listToStr.replace(' ','')
     print(listToStr)
     if ( listToStr != ''):
          if(listToStr.find('Init') != -1):
               sep = 'Init'
               stripped = listToStr.split(sep, 1)[1]
               fin = 'Fin'
               stripped = stripped.split(fin, 1)[0]
               #print(stripped)

               string =  stripped.split('/')
               print(string[0])
               URLString = string[0]
               URIName = string[1]
               print(URIName)
               url = f'https://127.0.0.1:8086/getMyUrl/{URLString}/{URIName}' 
               response = requests.get(url)
               espera = 'relleno'
               error = 'error'
               #time.sleep(2) #No se puede poner 1sg poruqe el NFCRedaer tiene un retardo de desconexion de 2sg
          else:
               sep = 'Form'
               stripped = listToStr.split(sep, 1)[1]
               fin = 'Fin'
               stripped = stripped.split(fin, 1)[0]
               URLString = stripped
               print(URLString)
               url = f'https://127.0.0.1:8086/getMyForm/{URLString}' 
               response = requests.get(url)
               espera = 'relleno'
               error = 'error'
               #time.sleep(2) #No se puede poner 1sg poruqe el NFCRedaer tiene un retardo de desconexion de 2sg
     else: 
          espera = 'relleno'
          error = 'error'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant