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

Mifare Classic 1K: Authentication Error after Multiple Writes #16

Closed
riseansmal opened this issue May 27, 2017 · 10 comments
Closed

Mifare Classic 1K: Authentication Error after Multiple Writes #16

riseansmal opened this issue May 27, 2017 · 10 comments

Comments

@riseansmal
Copy link

riseansmal commented May 27, 2017

Hi @pokusew,

Something weird is happening when attempting multiple writes. I have the following simple script that (1) Authenticates Blocks 4-7, Reads Blocks 4-7 and then Writes to Blocks 4-7.

It seems that the cards become unusable after attempting multiple write operations as they refuse to Authenticate. I have also tried this using promises.

I really like this package due to its quality, straightforward installation across platforms and Electron support.

Any suggestions or advice from your side?

https://gist.github.com/therealri/96adfa625d8bb3b2929a956ec1919cda

1:53:04 AM info ACS ACR122 0  device attached
1:53:05 AM info ACS ACR122 0  card detected
card:
  type: TAG_ISO_14443_3
  uid:  4e62e3f5
1:53:05 AM error ACS ACR122 0  error when authenticating data
card:
  type: TAG_ISO_14443_3
  uid:  4e62e3f5
err:
  name: AuthenticationError
  code: operation_failed
@pokusew pokusew self-assigned this May 28, 2017
@pokusew
Copy link
Owner

pokusew commented May 30, 2017

Hi @therealri,

Just to clarify:
Does the script fail always (so you cannot write any data) or does it work just for the first time (meaning that it allows you to write data just once)?

Thanks for your answer.

@riseansmal
Copy link
Author

Hey @pokusew,

So it works just the first time but thereafter the card becomes unusable.

So yes, it allows me to write data just once using the Exact Script in the Gist and thereafter it's not possible use the card again.

Thanks!

@pokusew
Copy link
Owner

pokusew commented May 30, 2017

@therealri And does it work when you restart the script (CTRL-C and run again)?

@pokusew
Copy link
Owner

pokusew commented May 30, 2017

@therealri I have got the idea, where the problem comes from. ❗️❗️❗️

@pokusew
Copy link
Owner

pokusew commented May 30, 2017

@therealri I think that the problem is here:

I am looking into the technical documentation of Mifare Classic 1K.

Section 8.6 is about Memory organization.

... memory is organized in 16 sectors of 4 blocks. One block
contains 16 bytes.

When accessing these blocks with this library, blocks are numbered as follows:

  • sector 0:
    • block 0 – manufacturer data (read only)
    • block 1 – data block
    • block 2 – data block
    • block 3 – sector trailer
  • sector 1:
    • block 4 – data block
    • block 5 – data block
    • block 6 – data block
    • block 7 – sector trailer
  • sector 2:
    • block 8 – data block
    • block 9 – data block
    • block 10 – data block
    • block 11 – sector trailer
  • and so on

That's important, it's that the last block in each sector is "sector trailer" (see Section 8.6.3), which contains access conditions for the other 3 data blocks.

So block 7, which you are trying to write to in your code, is not for data. After you write to it, it changes access conditions (including key) and you cannot authenticate your card then.

I don't have any Mifare Classic card to test it, but according to documentation it is quite clear.

Could you please update your code (remove interaction with block 7, see updated gist here) and test it with a NEW BLANK card if it works?

Hope it helps and looking forward to your answer.

PS Don't forget to star ⭐️ my library, if you find it useful. 😃 Thanks.

@pokusew
Copy link
Owner

pokusew commented Jun 2, 2017

Hi @therealri,

I have just noticed another problem in you gist, on line 100, 104, 108, 112 you forgot to add the third, blockSize, argument 16 (4, 16, 16). It probably causes unneeded read operations.

Just to be sure, you probably do know it, 16bit integer takes just 2 bytes, not 16 bytes (1 bytes = 8 bits). So before writing only 2-byte 16-bit integer into 16-byte unsafely-allocated Buffer, add data.fill(0), more info here.

I fixed all these things in my fork here. Take a look!

Also let me know, if everything works for you as expected, and I will close the issue then. Thanks.

Hope it helps.

PS Don't forget to star ⭐️ my library, if you find it useful. 😃 Thanks.

pokusew added a commit that referenced this issue Jun 2, 2017
Improve examples (#16, #7)
Add new keywords into package.json
Add example from readme into examples folder
@riseansmal
Copy link
Author

Hey @pokusew,

Thanks so much and sorry for not getting back to you sooner, I have been travelling.

I also needed to get some extra Mifare Classic 1K Stock.

I have read through your comments and see where I went wrong on the configuration. I appreciate the updated code and all your help and time!

I have tested and it works perfectly, I have a clear understanding of the Mifare Classic 1K Data Layout now :)

Thanks so much!

@vamsideepak
Copy link

vamsideepak commented Oct 8, 2018

it is not working with angular 6 and it throwing error while importing like "nfc is not a constructor".
import {NFC} from 'nfc-pcsc' throwing error
ERROR in ./node_modules/bindings/bindings.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\Admin\Desktop\electronapp\node_modules\bindings'
ERROR in ./node_modules/bindings/bindings.js
Module not found: Error: Can't resolve 'path' in 'C:\Users\Admin\Desktop\electronapp\node_modules\bindings'

reason i found fs module will not work with angular 6. by inbuilt nfc containing fs .

because of these reason i accessed nfc from html and i declared in angular 6 component like "declare var NFC: any; "
because of above i am getting nfc is not a constructor

@fabioloreggian
Copy link

@therealri I have been having troubles trying to read some data from my Mifare Class 1k card. Do you think you could spare some time and help out?

@pokusew
Copy link
Owner

pokusew commented Apr 5, 2019

Hi @fabioloreggian, what troubles do you have? I am happy to help. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants