Mifare Classic 1K authentication troubles - ACR122U and nfctools for java

4.054 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Kishikan

ungelesen,
22.04.2013, 12:04:1222.04.13
an nfc-dev...@googlegroups.com
Hi,

I recently bought an ACR122U reader and a few blank 1k Mifare classic cards (NXP S50) and I've been tinkering with the nfctools library for java (very nice, by the way), but I've been having a lot of trouble trying to authenticate with these cards (63 00 apdu response from the reader).
I've tried most of the common keys (FF FF FF FF FF FF, 00 00 00 00 00 00, A0 A1 A2 A3 A4 A5, etc..) and I am using AbstractCardTool. 

Any read/write operations on the card, on any block results in a LoginException (i.e. org.nfctools.mf.MfLoginException: Login failed. Sector: 0, Block: 0 Key: A, Response: SW1: 99 SW2: 0)
I've attached an XML file dump of the cards I'm using (compiled using my S3, NFC TagInfo app from Google Play) which shows successful results. I'm also able to write to the cards with TagWriter (which formats it as an NDEF tag - I usually reset it to factory settings after doing that) - So, no problem on the android side.

The reader seems to be able to read and write other unsecured tags.

NfcAdapter stuff:
        NfcAdapter nfcAdapter = new NfcAdapter(terminal, TerminalMode.INITIATOR);
        nfcAdapter.registerTagListener(abstractcardtool_class);
        nfcAdapter.registerUnknownTagListerner(new LoggingUnknownTagListener());
        nfcAdapter.startListening();

doWithReaderWriter function (for now)
        public void doWithReaderWriter(MfClassicReaderWriter rw)
        {

            MemoryLayout memoryLayout = rw.getMemoryLayout();
            // Mifare 1K isn't more than 768...
            ByteBuffer outputData = ByteBuffer.allocate(768);
            
            byte[] keyA = {(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff};

            boolean success = true;
            
            // read all data blocks from all sectors
            int sectorCount = memoryLayout.getSectors();
            for (int sector = 0; sector < sectorCount; sector++)
            {
                try
                {
                    MfClassicAccess access = new MfClassicAccess(new KeyValue(Key.A, keyA), sector, 0,
                                                    memoryLayout.getBlocksPerSector(sector) - 1 /*(minus trailer block)*/);
                    MfBlock[] nb = rw.readBlock(access);
                    for (MfBlock b : nb)
                        outputData.put(b.getData());
                    break;
                }
                catch (Exception l)
                {
                    l.printStackTrace();
                    success = false;
                    continue;
                }
            }
            if (success)
                System.out.println("Read succeeded!");
            else
                System.out.println("Read failure!");
        }

Did I do anything wrong at all? This really has me stumped.

Thanks in advance.
tag-041b488ab72080.xml

Adrian Stabiszewski

ungelesen,
23.04.2013, 02:09:2423.04.13
an nfc-dev...@googlegroups.com
Hi,

I'm not sure if the "break/continue" logic is correct in your example. I would not recommend using this GOTO technique.

Anyway if you want to scan a card I've created an example for that:
https://github.com/grundid/nfctools-examples/blob/master/src/main/java/org/nfctools/examples/scancard/ScanWholeCardDemo.java
https://github.com/grundid/nfctools/blob/master/nfctools-core/src/main/java/org/nfctools/mf/tools/MfClassicCardScanner.java

Have you tried to use the ScanWholeCardDemo?

Regards,
Adrian.

Ryun O'Neil

ungelesen,
23.04.2013, 03:08:2723.04.13
an nfc-dev...@googlegroups.com

Hi,

Ah, whoops. Excuse me on that.

And yes, I have tried a few of your demos, including the ScanWholeCardDemo.

Unfortunately, I was still unable to authenticate properly.

--
Sie erhalten diese Nachricht, weil Sie in Google Groups ein Thema der Gruppe "nfc-developers" abonniert haben.
Um Ihr Abonnement für dieses Thema zu beenden, rufen Sie die URL https://groups.google.com/d/topic/nfc-developers/Rwi8o_aZ5F0/unsubscribe?hl=de auf.
Um Ihr Abonnement für diese Gruppe und alle ihre Themen zu beenden, senden Sie eine E-Mail an nfc-developer...@googlegroups.com.
Weitere Optionen: https://groups.google.com/groups/opt_out
 
 

Kishikan

ungelesen,
04.05.2013, 14:37:0204.05.13
an nfc-dev...@googlegroups.com
Sorry for reviving an old-ish thread,

Was hoping if there is any solution to this?
I'm able to read/write the cards on my phone, but not through the reader - can't authenticate.
The keys should be 0xFFFFFFFFFFFF - I've tried most of the common ones too. I also experienced this issue when I wasn't using nfctools (raw APDUs).
The issue isn't specific to a certain card - I've tried a few. (all blank, and won't authenticate)

Funnily enough, normal 137 byte tags read/write just fine!

Any suggestions?

Marco Albarelli

ungelesen,
06.05.2013, 04:19:2006.05.13
an nfc-dev...@googlegroups.com
I'm at this stage too
I made a simple Android app that reads/writes text messages to various tag types 
The code I'm attaching here works fine with Ultralight Cards, but fails with MifareClassic 1k cards

@Override
public void onNdefOperations(NdefOperations ndefOperations) {
try {
if (ndefOperations.isFormatted() ) {
String message = caller.getMessage();
Record r = new TextRecord(message);
ndefOperations.writeNdefMessage(r);
caller.runOnUiThread(new Runnable() {
       @Override
       public void run() {
           caller.manageNDEF(caller.getMessage());
       }
   });
}
else{
ndefOperations.format();
Log.i(NFCTOOLS, "not formatted");
}
}catch (Exception e){
e.printStackTrace();
}
}
I get this exception:
05-06 10:15:34.249: I/NDEFManageActivity(7805): Reader name: ACS ACR122U PICC Interface
05-06 10:15:34.249: I/NDEFManageActivity(7805): Number of slots: 1
05-06 10:15:35.389: I/NFCTOOLS(7805): Sending: FF82000006A0A1A2A3A4A5
05-06 10:15:35.389: I/NFCTOOLS(7805): Received: 2 | 9000000000000000000000000000000000000000000000000000000000000000
05-06 10:15:35.389: I/NFCTOOLS(7805): Sending: FF860000050100036000
05-06 10:15:35.429: I/NFCTOOLS(7805): Received: 2 | 9000000000000000000000000000000000000000000000000000000000000000
05-06 10:15:35.429: I/NFCTOOLS(7805): Sending: FFB0000310
05-06 10:15:35.459: I/NFCTOOLS(7805): Received: 18 | 000000000000787788C100000000000090000000000000000000000000000000
05-06 10:15:35.469: I/NFCTOOLS(7805): Sending: FF82000006A0A1A2A3A4A5
05-06 10:15:35.469: I/NFCTOOLS(7805): Received: 2 | 9000000000000000000000000000000000000000000000000000000000000000
05-06 10:15:35.469: I/NFCTOOLS(7805): Sending: FF860000050100036000
05-06 10:15:35.509: I/NFCTOOLS(7805): Received: 2 | 9000000000000000000000000000000000000000000000000000000000000000
05-06 10:15:35.509: I/NFCTOOLS(7805): Sending: FFB0000310
05-06 10:15:35.529: I/NFCTOOLS(7805): Received: 18 | 000000000000787788C100000000000090000000000000000000000000000000
05-06 10:15:35.529: I/NFCTOOLS(7805): Sending: FF82000006A0A1A2A3A4A5
05-06 10:15:35.539: I/NFCTOOLS(7805): Received: 2 | 9000000000000000000000000000000000000000000000000000000000000000
05-06 10:15:35.539: I/NFCTOOLS(7805): Sending: FF860000050100016000
05-06 10:15:35.579: I/NFCTOOLS(7805): Received: 2 | 9000000000000000000000000000000000000000000000000000000000000000
05-06 10:15:35.579: I/NFCTOOLS(7805): Sending: FFB0000110
05-06 10:15:35.599: I/NFCTOOLS(7805): Received: 18 | 140103E103E103E103E103E103E103E190000000000000000000000000000000
05-06 10:15:35.599: I/NFCTOOLS(7805): Sending: FFB0000210
05-06 10:15:35.619: I/NFCTOOLS(7805): Received: 18 | 03E103E103E103E103E103E103E103E190000000000000000000000000000000
05-06 10:15:35.619: I/NFCTOOLS(7805): Sending: FF82000006FFFFFFFFFFFF
05-06 10:15:35.629: I/NFCTOOLS(7805): Received: 2 | 9000000000000000000000000000000000000000000000000000000000000000
05-06 10:15:35.629: I/NFCTOOLS(7805): Sending: FF860000050100076000
05-06 10:15:35.729: I/NFCTOOLS(7805): Received: 2 | 6300000000000000000000000000000000000000000000000000000000000000
05-06 10:15:35.739: I/AndroidLoggerFactory(7805): Logger name 'org.nfctools.mf.classic.MfClassicNdefOperations' exceeds maximum length of 23 characters, using 'o*.n*.m*.c*.MfClassicN*' instead.
05-06 10:15:35.749: W/System.err(7805): java.lang.IllegalStateException: Tag not writable
05-06 10:15:35.749: W/System.err(7805): at org.nfctools.mf.ndef.AbstractNdefOperations.assertWritable(AbstractNdefOperations.java:74)
05-06 10:15:35.749: W/System.err(7805): at org.nfctools.mf.classic.MfClassicNdefOperations.writeNdefMessage(MfClassicNdefOperations.java:96)
05-06 10:15:35.749: W/System.err(7805): at eu.marcoalbarelli.android.demo.nfc.WritingNdefOperationsListener.onNdefOperations(WritingNdefOperationsListener.java:30)
05-06 10:15:35.749: W/System.err(7805): at org.nfctools.mf.classic.MfClassicNfcTagListener.handleTag(MfClassicNfcTagListener.java:53)
05-06 10:15:35.749: W/System.err(7805): at eu.marcoalbarelli.android.demo.nfc.ReaderStateChangeListener.onStateChange(ReaderStateChangeListener.java:67)
05-06 10:15:35.759: W/System.err(7805): at com.acs.smartcard.Reader$a.run(SourceFile:846)
05-06 10:15:35.759: W/System.err(7805): at java.lang.Thread.run(Thread.java:856)

If I try to format the card before writing I get a LoginException instead of the " Tag not writable" one

Adrian Stabiszewski

ungelesen,
06.05.2013, 05:15:0406.05.13
an nfc-dev...@googlegroups.com
I think, I have found the problem and fixed it in the repo.

You can download an new nfctools-examples.jar with all dependencies from:

Give me a hint if this is working for you so I can create a new milestone for maven central.

Regards,
Adrian.

Motosauro

ungelesen,
06.05.2013, 06:25:0206.05.13
an nfc-dev...@googlegroups.com
Man, you're great :)
Problem solved: I've been able to write and read also MifareClassic Tags
I also removed the slf4j library I explicitly imported in the project because it is contained in the nfctools-examples jar
Thanks a lot


2013/5/6 Adrian Stabiszewski <nit...@googlemail.com>

--
Sie haben diese Nachricht erhalten, weil Sie der Google Groups-Gruppe nfc-developers beigetreten sind.
Um Ihr Abonnement für diese Gruppe zu beenden und keine E-Mails mehr von dieser Gruppe zu erhalten, senden Sie eine Email an nfc-developer...@googlegroups.com.
Weitere Optionen: https://groups.google.com/groups/opt_out
 
 

Kishikan

ungelesen,
06.05.2013, 07:24:1606.05.13
an nfc-dev...@googlegroups.com
I'm still receiving these errors...

SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
May 06, 2013 12:20:15 PM org.nfctools.scio.TerminalHandler getAvailableTerminal
INFO: Checking terminal: ACS ACR122 0
doWithReaderWriter


org.nfctools.mf.MfLoginException: Login failed. Sector: 0, Block: 0 Key: A, Response: SW1: 99 SW2: 0
at org.nfctools.spi.acs.AcrMfClassicReaderWriter.loginIntoSector(AcrMfClassicReaderWriter.java:111)
at org.nfctools.spi.acs.AcrMfClassicReaderWriter.readBlock(AcrMfClassicReaderWriter.java:53)
at TheAppName.TheAppName$ReadCard.doWithReaderWriter(TheAppName.java:166)
at org.nfctools.mf.tools.AbstractCardTool.handleTag(AbstractCardTool.java:64)
at org.nfctools.NfcAdapter.onTag(NfcAdapter.java:78)
at org.nfctools.spi.acs.InitiatorTerminalTagScanner.handleCard(InitiatorTerminalTagScanner.java:71)
at org.nfctools.spi.acs.InitiatorTerminalTagScanner.run(InitiatorTerminalTagScanner.java:47)
at java.lang.Thread.run(Thread.java:722)
org.nfctools.mf.MfLoginException: Login failed. Sector: 1, Block: 0 Key: A, Response: SW1: 99 SW2: 0
at org.nfctools.spi.acs.AcrMfClassicReaderWriter.loginIntoSector(AcrMfClassicReaderWriter.java:111)
at org.nfctools.spi.acs.AcrMfClassicReaderWriter.readBlock(AcrMfClassicReaderWriter.java:53)
at TheAppName.TheAppName$ReadCard.doWithReaderWriter(TheAppName.java:166)
at org.nfctools.mf.tools.AbstractCardTool.handleTag(AbstractCardTool.java:64)
at org.nfctools.NfcAdapter.onTag(NfcAdapter.java:78)
at org.nfctools.spi.acs.InitiatorTerminalTagScanner.handleCard(InitiatorTerminalTagScanner.java:71)
at org.nfctools.spi.acs.InitiatorTerminalTagScanner.run(InitiatorTerminalTagScanner.java:47)
at java.lang.Thread.run(Thread.java:722)
org.nfctools.mf.MfLoginException: Login failed. Sector: 2, Block: 0 Key: A, Response: SW1: 99 SW2: 0
at org.nfctools.spi.acs.AcrMfClassicReaderWriter.loginIntoSector(AcrMfClassicReaderWriter.java:111)
at org.nfctools.spi.acs.AcrMfClassicReaderWriter.readBlock(AcrMfClassicReaderWriter.java:53)
at TheAppName.TheAppName$ReadCard.doWithReaderWriter(TheAppName.java:166)
at org.nfctools.mf.tools.AbstractCardTool.handleTag(AbstractCardTool.java:64)
at org.nfctools.NfcAdapter.onTag(NfcAdapter.java:78)
at org.nfctools.spi.acs.InitiatorTerminalTagScanner.handleCard(InitiatorTerminalTagScanner.java:71)
at org.nfctools.spi.acs.InitiatorTerminalTagScanner.run(InitiatorTerminalTagScanner.java:47)
at java.lang.Thread.run(Thread.java:722)
org.nfctools.mf.MfLoginException: Login failed. Sector: 3, Block: 0 Key: A, Response: SW1: 99 SW2: 0
at org.nfctools.spi.acs.AcrMfClassicReaderWriter.loginIntoSector(AcrMfClassicReaderWriter.java:111)
at org.nfctools.spi.acs.AcrMfClassicReaderWriter.readBlock(AcrMfClassicReaderWriter.java:53)
at theappname.TheAppName$ReadCard.doWithReaderWriter(TheAppName.java:166)
at org.nfctools.mf.tools.AbstractCardTool.handleTag(AbstractCardTool.java:64)
at org.nfctools.NfcAdapter.onTag(NfcAdapter.java:78)
at org.nfctools.spi.acs.InitiatorTerminalTagScanner.handleCard(InitiatorTerminalTagScanner.java:71)
at org.nfctools.spi.acs.InitiatorTerminalTagScanner.run(InitiatorTerminalTagScanner.java:47)
at java.lang.Thread.run(Thread.java:722)

Any ideas?

Adrian Stabiszewski

ungelesen,
06.05.2013, 08:18:3906.05.13
an nfc-dev...@googlegroups.com
I'm sorry, but only looking at the stack trace I cannot tell you what is wrong. 

Can you share your complete project?

Fermín Teuctzintli Vázquez Pérez

ungelesen,
13.08.2013, 17:03:1213.08.13
an nfc-dev...@googlegroups.com
Hello, 

Can you please help me. 

What are those changes. i have updated the project with the one actually in the repository, but i gettin the same response as the partner above writing on MIFARE CLASSIC 4K

Login failed. Sector: 1, Block: 0 Key: B, Response: SW1: 99 SW2: 0

jave....@gmail.com

ungelesen,
17.02.2014, 03:17:0417.02.14
an nfc-dev...@googlegroups.com
Have you solved it?

aghile...@gmail.com

ungelesen,
25.11.2014, 10:37:0325.11.14
an nfc-dev...@googlegroups.com
Hello,

Can you tell me what are the changes that you made because i'm getting the same issue?

Thanks,
Aghiles.

aghile...@gmail.com

ungelesen,
26.11.2014, 03:11:4626.11.14
an nfc-dev...@googlegroups.com
HI,

After some time of investigation i found my problem. It is due to my reader acr128u because in the beginning i made some changes to the Api in order to support it, but it was not enough.
If someone is in the same case as me, my modification of the Api (attached to this response) can save you some time end effort ;).

Thank you Adrian for your Api.

Cheers,
Aghiles.

PS: This will work only for a reader acr128u.
nfctools-api-1.0-SNAPSHOT.jar
nfctools-core-1.0-SNAPSHOT.jar
nfctools-ndef-1.0-SNAPSHOT.jar
nfctools-p2p-1.0-SNAPSHOT.jar

Kings K

ungelesen,
26.11.2014, 03:50:0026.11.14
an nfc-dev...@googlegroups.com
Hello Marco, I am very new to this, would you please help me with your project as a guideline please?
Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten