pimylifeup / MFRC522-python

Library utilized for Pi My Life Up's guide on setting up an RFID RC522 reader.
https://pimylifeup.com/raspberry-pi-rfid-rc522/
GNU Lesser General Public License v3.0
193 stars 170 forks source link

AUTH ERROR #31

Closed MrTobyUp closed 1 year ago

MrTobyUp commented 3 years ago

When I'm trying to read, I am getting an error saying: "AUTH ERROR!! AUTH ERROR(status2reg & 0x08) != 0" Afterwards the UID is printed out correctly, but the Text is empty. If I write onto a completly new card, and read afterwards, it works fine, but if I'm write onto the card with an mobile app, it's not possible to read. Is there some kind of Authentication going on and can I somehow bypass it?

n1ywb commented 3 years ago

it's probably because you're using a newer RFID tag. I'm having the same issue w NTAG215 tags. read somewhere they don't support auth, which would explain the error. but it's not reading the SN correctly either. I might try to hack in a fix.

n1ywb commented 3 years ago

If you are using an NTAG and you just need the serial number, this hack will dump out the bytes that have it

#!/usr/bin/env python

import RPi.GPIO as GPIO
from mfrc522 import MFRC522
from mfrc522 import SimpleMFRC522
from time import sleep
from datetime import datetime

reader = MFRC522()

try:
    while True:
        status, _ = reader.MFRC522_Request(reader.PICC_REQIDL)
        if status != reader.MI_OK:
            sleep(0.1)
            continue
        status, backData = reader.MFRC522_Anticoll()
        buf = reader.MFRC522_Read(0)
        reader.MFRC522_Request(reader.PICC_HALT)
        if buf:
            print(datetime.now().isoformat(), ':'.join([hex(x) for x in buf]))
finally:
        GPIO.cleanup()

it doesn't trigger authentication so you don't get that error.

https://www.nxp.com/docs/en/data-sheet/NTAG213_215_216.pdf has the secret decoder ring for turning those bytes into a serial number.

anticoll doesn't correctly return the serial number for ntags. it also doesn't finish the anticollision sequence, but oh well. basic reads work.

KaizoKev commented 1 year ago

If you are using an NTAG and you just need the serial number, this hack will dump out the bytes that have it

#!/usr/bin/env python

import RPi.GPIO as GPIO
from mfrc522 import MFRC522
from mfrc522 import SimpleMFRC522
from time import sleep
from datetime import datetime

reader = MFRC522()

try:
    while True:
        status, _ = reader.MFRC522_Request(reader.PICC_REQIDL)
        if status != reader.MI_OK:
            sleep(0.1)
            continue
        status, backData = reader.MFRC522_Anticoll()
        buf = reader.MFRC522_Read(0)
        reader.MFRC522_Request(reader.PICC_HALT)
        if buf:
            print(datetime.now().isoformat(), ':'.join([hex(x) for x in buf]))
finally:
        GPIO.cleanup()

it doesn't trigger authentication so you don't get that error.

https://www.nxp.com/docs/en/data-sheet/NTAG213_215_216.pdf has the secret decoder ring for turning those bytes into a serial number.

anticoll doesn't correctly return the serial number for ntags. it also doesn't finish the anticollision sequence, but oh well. basic reads work.

How can we get the badge id from your method?

MrTobyUp commented 1 year ago

Little late to the party, but thx :)

tslater commented 1 year ago

Has anyone figured out how to actually read the data on a NTAG215?

MatheusTran commented 1 year ago

If you are using an NTAG and you just need the serial number, this hack will dump out the bytes that have it

#!/usr/bin/env python

import RPi.GPIO as GPIO
from mfrc522 import MFRC522
from mfrc522 import SimpleMFRC522
from time import sleep
from datetime import datetime

reader = MFRC522()

try:
    while True:
        status, _ = reader.MFRC522_Request(reader.PICC_REQIDL)
        if status != reader.MI_OK:
            sleep(0.1)
            continue
        status, backData = reader.MFRC522_Anticoll()
        buf = reader.MFRC522_Read(0)
        reader.MFRC522_Request(reader.PICC_HALT)
        if buf:
            print(datetime.now().isoformat(), ':'.join([hex(x) for x in buf]))
finally:
        GPIO.cleanup()

it doesn't trigger authentication so you don't get that error.

https://www.nxp.com/docs/en/data-sheet/NTAG213_215_216.pdf has the secret decoder ring for turning those bytes into a serial number.

anticoll doesn't correctly return the serial number for ntags. it also doesn't finish the anticollision sequence, but oh well. basic reads work.

Hello. This is years later (so sorry) but when I run this code, it keeps saying "Error while reading!"

is there a reason this happens and is there any way to fix it?

clockcoinG1 commented 11 months ago

LOl u need the right auth key for the tag -- theres a handshake and after it completes u can read the data on the other buffers. if u wanna crack the auth key u need to use mfdump and capture the key then bruteforce. if u wanna write different ID on a key you need the auth key. ez. u need to do the 'hack' where you send two handshakes at once, colect response and bruteforce of that. ez

GentNisjes commented 6 months ago

well i guess we'll have to accept the occasional AUTH ERROR ...

y-nk commented 5 months ago

@tslater i'm a noob in python but hopefully chatgpt is not.

i have some luck decoding the code with this snippet:

import mfrc522

# Create an object of the MFRC522 class
mfrc522 = mfrc522.MFRC522()

# Main function
def main():
    try:
        while True:
            # Scan for tags
            (status, TagType) = mfrc522.MFRC522_Request(mfrc522.PICC_REQIDL)

            # If a tag is found
            if status == mfrc522.MI_OK:
                print("Tag detected")

                # Get the UID of the tag
                (status, uid) = mfrc522.MFRC522_Anticoll()

                # If the UID is successfully obtained
                if status == mfrc522.MI_OK:
                    print("UID: " + ":".join([str(x) for x in uid]))

                    # Select the tag
                    mfrc522.MFRC522_SelectTag(uid)

                    # Read data from the tag
                    data = [elem for index in [6] for elem in mfrc522.MFRC522_Read(index)]
                    result = ''.join([chr(charcode) for charcode in data])
                    print("Data read:", result)
                else:
                    print("Error obtaining UID")

    except KeyboardInterrupt:
        print("Exiting...")
        mfrc522.MFRC522_StopCrypto1()

if __name__ == "__main__":
    main()

you'll notice the elem for index in [6] for elem as in "it's weird to have [6]` - i'm still trying to make sense of it and currently manually modify the index list to explore the tags i had set with my android phone - i'm saying this because of https://stackoverflow.com/questions/59515271/why-android-nfc-reader-adds-en-before-the-message

cheers