johnnyb / ntag424-java

A Java library for the NXP NTAG 424 DNA chip
MIT License
18 stars 3 forks source link

Rewrite NFC Tag doesn't work #6

Closed ChristianGreiner closed 4 months ago

ChristianGreiner commented 4 months ago

Hey @johnnyb !

I'm currently experimenting with the NTAG 424 and stumbled upon your repository. Thanks for the awesome work!

I tested your example app, and it works so far. However, when I try to rewrite the NFC tag (with another URL), I encounter the following exception. So it seems that synchronizing the keys again doesn't work. I'm not sure if this is the intended behavior. I didn't change any keys or permission flags.

Is there also a way to reset the NFC tags to factory settings?

Thanks alot!

Here is the exception:

2024-04-22 14:14:11.905 32221-32221 NfcApp                  com.bplearning.ntag424demo           D  New intent received: android.nfc.action.NDEF_DISCOVERED
2024-04-22 14:14:11.905 32221-32221 NfcApp                  com.bplearning.ntag424demo           D  Received NFC Intent: android.nfc.action.NDEF_DISCOVERED
2024-04-22 14:14:11.908 32221-32221 NfcApp                  com.bplearning.ntag424demo           D  Tag ID: 04AB6E520C1090
2024-04-22 14:14:11.908 32221-32221 NfcApp                  com.bplearning.ntag424demo           D  Tag Tech: android.nfc.tech.IsoDep, android.nfc.tech.NfcA, android.nfc.tech.Ndef
2024-04-22 14:14:11.910 32221-32221 NfcApp                  com.bplearning.ntag424demo           D  Found adapter: registering for intents
2024-04-22 14:14:11.912 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: Beginning communication
2024-04-22 14:14:11.920 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesSending: 00A4000C02E11000
2024-04-22 14:14:11.940 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesReceived: 9000
2024-04-22 14:14:11.948 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesSending: 9071000002000000
2024-04-22 14:14:11.971 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesReceived: AF5DDEDD3DFED8DEE2C9BFAC7052553A91AF
2024-04-22 14:14:11.999 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesSending: 90AF0000206869A12B79FEFC3D99D13D3E1B72F5942C305565DA7C6BE0252A2AB2231E955400
2024-04-22 14:14:12.026 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesReceived: DF5D275A80001FB3FBA788E8116F2010EB10481702329611A08E782A3BB3CF8B9100
2024-04-22 14:14:12.039 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Login successful
2024-04-22 14:14:12.046 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesSending: 90510000083D2B7F1346FE24BD00
2024-04-22 14:14:12.061 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesReceived: 611F11F0581A0DF5C85232378FC2D2B11684CCBAABB165B19100
2024-04-22 14:14:12.073 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: Decrypted data: 04AB6E520C1090800000000000000000
2024-04-22 14:14:12.074 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Card UID: 04AB6E520C1090
2024-04-22 14:14:12.083 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesSending: 9064000009007CE5F5F05DFE869100
2024-04-22 14:14:12.092 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesReceived: 000A3B7E45AFDA90949100
2024-04-22 14:14:12.095 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Key 0 version: 0
2024-04-22 14:14:12.101 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesSending: 9051000008DD653C2E01A2E20400
2024-04-22 14:14:12.115 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesReceived: 9EAD60E2002C502457AC37EB2C72594A7E44519294B55E449100
2024-04-22 14:14:12.124 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: Decrypted data: 04AB6E520C1090800000000000000000
2024-04-22 14:14:12.128 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: Data before encryption: 0000000000000000000000000000000000
2024-04-22 14:14:12.141 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesSending: 90C400002900AC1453308CCDC834C1B4A9656E6160B9F1DE73FEF6312619679F22A86B152CD15A1C1E714B4A89BB00
2024-04-22 14:14:12.160 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesReceived: 9100
2024-04-22 14:14:12.160 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: Decrypted data: 
2024-04-22 14:14:12.162 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesSending: 9071000002000000
2024-04-22 14:14:12.178 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesReceived: C58640A40A5E74D8D93D6E5AB93F1BF991AF
2024-04-22 14:14:12.186 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesSending: 90AF000020AABDF0E0F5F8248797D6107A0A1DDEF6FC7022086FF79528FE2DEEA2509E435A00
2024-04-22 14:14:12.205 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesReceived: 54724CE3DE5C9AC6FDCE6C29706E02C063179BC606323C7E8D9E9CB6595B2D7D9100
2024-04-22 14:14:12.217 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesSending: 90510000082FD20B2CDC12B93100
2024-04-22 14:14:12.232 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesReceived: 9BE17CA081283BE12BDFDF818E823C500005E181F2557DEE9100
2024-04-22 14:14:12.239 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: Decrypted data: 04AB6E520C1090800000000000000000
2024-04-22 14:14:12.250 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: Data before encryption: 0000000000000000000000000000000000AAB44413
2024-04-22 14:14:12.264 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesSending: 90C4000029013D1442B431008048E624E35F03BFAC17BEA6FD83D0A87460A7E9C3CA3707246C3AE0084CC59EA75C00
2024-04-22 14:14:12.287 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesReceived: 83FFF1280857061E9100
2024-04-22 14:14:12.291 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: Decrypted data: 
2024-04-22 14:14:12.295 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesSending: 9051000008D0AA91F09D86693A00
2024-04-22 14:14:12.309 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesReceived: 6B6E7D87DC51E24DCEE692FBE0419C6BD65F7535D66C0FED9100
2024-04-22 14:14:12.317 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: Decrypted data: 04AB6E520C1090800000000000000000
2024-04-22 14:14:12.326 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: Data before encryption: 0000000000000000000000000000000000AAB44413
2024-04-22 14:14:12.338 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesSending: 90C400002902022AE10FD3CE1CEAD001EF48BEA1D150FB8E4CECBB2C514878DF120D398AC2693C2C0647DF006C3900
2024-04-22 14:14:12.362 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesReceived: 2BE48740028195539100
2024-04-22 14:14:12.365 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: Decrypted data: 
2024-04-22 14:14:12.370 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesSending: 90510000089B995A0C613B51A900
2024-04-22 14:14:12.386 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesReceived: 37B2487DCACE1A34D5B83577B3821258594C9BA2373754459100
2024-04-22 14:14:12.394 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: Decrypted data: 04AB6E520C1090800000000000000000
2024-04-22 14:14:12.406 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: Data before encryption: 450E82F7115ED6BBF53336259548108601C71DA7C5
2024-04-22 14:14:12.417 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesSending: 90C40000290306618993EBC9D176CBCB406EA6EFE440B36D6465FA46EE4BA86FBCA61F4490BFD169E9F4A071700400
2024-04-22 14:14:12.433 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesReceived: 911E
2024-04-22 14:14:12.433 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: Decrypted data: 
2024-04-22 14:14:12.444 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: Data before encryption: 0000000000000000000000000000000001C71DA7C5
2024-04-22 14:14:12.454 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesSending: 90C400002903236E52E773244C2FD7CCFACE7338B2B583C365D0102B0FD41F79C1E53B0D6D00CB0B48F019DD02E400
2024-04-22 14:14:12.472 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesReceived: 91AE
2024-04-22 14:14:12.473 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: Decrypted data: 
2024-04-22 14:14:12.479 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesSending: 90510000082FFF6B58844958B100
2024-04-22 14:14:12.487 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: BytesReceived: 917E
2024-04-22 14:14:12.487 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  Communicator: Decrypted data: 
2024-04-22 14:14:12.488 32221-32278 NfcApp                  com.bplearning.ntag424demo           D  error communicating
                                                                                                    net.bplearning.ntag424.exception.ProtocolException: Invalid status result: 917E
                                                                                                        at net.bplearning.ntag424.CommandResult.throwUnlessSuccessful(CommandResult.java:34)
                                                                                                        at net.bplearning.ntag424.command.GetCardUid.run(GetCardUid.java:13)
                                                                                                        at net.bplearning.ntag424.card.KeyInfo.synchronizeKey(KeyInfo.java:73)
                                                                                                        at net.bplearning.ntag424.card.KeySet.synchronizeKeys(KeySet.java:34)
                                                                                                        at com.bplearning.ntag424demo.MainActivity.lambda$communicateWithTag$5$com-bplearning-ntag424demo-MainActivity(MainActivity.java:261)
                                                                                                        at com.bplearning.ntag424demo.MainActivity$$ExternalSyntheticLambda0.run(Unknown Source:4)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)
johnnyb commented 4 months ago

I think I fixed synchronizeKeys to work. HOWEVER, it depends on the key version being set when you create your keys. Key version 0 should always be factory keys. I updated the example app to 1.0.3 (which has lots of refactoring/breaking changes - I consider my 1.0 line to be "still in development"). Key sync should be performed before logging in.

Note - I haven't tested my example app because I'm running low on test cards and need to use the ones I have for work, but I can't think of a reason it shouldn't work.

Anyway, please check to see if these changes fix your situation, as I still haven't tested it fully.

ChristianGreiner commented 4 months ago

@johnnyb I tested it with your latest commit (version 1.03) and it works now! Thank you very much!