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

Bugfix AID length + bugfix reading beyond block 255 + add readClass option #55

Merged
merged 3 commits into from
Dec 27, 2018

Conversation

martijnthe
Copy link
Contributor

@pokusew pokusew merged commit cca3781 into pokusew:master Dec 27, 2018
@pokusew
Copy link
Owner

pokusew commented Dec 27, 2018

Hi @martijnthe,

thank you very much for your PR! 👍
All the fixes are perfectly OK. 👍
I merged it into the master.

Could you just please explain what your use-case of specifying the read class is?

According to the documentation of the Class byte in the section 5.4.1 is can be used to indicate:

  • to what extent the command and the response comply with this part of ISO/IEC 7816
  • and when applicable (see table 9), the format of secure messaging and the logical channel number.

If you were able to give some examples, it would be really helpful. 🙂 Eventually, it could be reasonable to allow specifying the class in other commands, too. (e.g. in the WRITE command).

Thanks.

@martijnthe
Copy link
Contributor Author

Could you just please explain what your use-case of specifying the read class is?

I’m reading the NDEF records from a type 4 tag inside a device (Elsys sensor). I was looking at how another program (https://itunes.apple.com/us/app/nfc-ideas/id1245536234?mt=12) was reading the tag. It involved setting the class to zero. I don’t know why (I know very little about these protocols) but with the default 0xFF it was not working.

@pokusew
Copy link
Owner

pokusew commented Dec 28, 2018

@martijnthe OK Thanks for explanation. I'll add the note about reading from Elsys sensors into the docs. 🙂

@alanezze
Copy link

Hi, I have a big problem, I can't authenticate and it seems that it doesn't receive the correct KeyType, I don't know if it's because it converts it from hex to decimal or I don't know, it's a mifare classic 1k, I can read the UID but I can't authenticate for R / W on the card

I would appreciate any help, I've been with this for days

Sin título

@pokusew
Copy link
Owner

pokusew commented Feb 18, 2021

Hi @alanezze,

Thank you for posting your problem here. I think that I know what the cause is (thanks to your screenshot). Let me explain:

nfc-pcsc supports mainly ACR122 USB reader but other PC/SC compliant devices normally also work with nfc-pcsc (out-of-the-box). From the screenshot, you posted, it seems that you are using OMNIKEY 5422 NFC reader.

In nfc-pcsc, a new instance of Reader class is created upon the reader connection class). If it is a known supported device, a special subclass of Reader is created, for example ACR122Reader (it is done here in NFC. The subclass can modify the behavior / implement special functions in respect with the reader API docs. As I mentioned above, most PC/SC readers will work out-of-the-box via Reader class.

However, on OMNIKEY 5422, loading of MIFARE Classic keys into the reader memory (part of the authentication, reader.authenticate) is (just a little bit) different from the one that is used in the common Reader class (which is based on the one from ACR122).

I looked into the OMNIKEY 5422 Software Developer Guide and in the section 11.1.3, there is a description for the Load Keys command.

The MIFARE Classic authentication implementation on PC/SC readers requires that a key that is used in General Authenticate command is at first loaded into the reader memory. The key can be stored either in volatile or in non-volatile memory. Usually, the key is stored only in volatile memory and thus must be reloaded upon reader reconnection. The OMNIKEY 5422 supports 32 key slots for MIFARE Classic keys and requires that MIFARE Classic keys are stored in non-volatile memory (i.e. they are persisted even after reader power off) (see section 11.2 of OMNIKEY 5422 Software Developer Guide).

The problem is, that current implementation of Load Keys command in [Reader.loadAuthenticationKey] (https://github.com/pokusew/nfc-pcsc/blob/master/src/Reader.js#L342) uses hard-coded P1 parameter 0x00 that indicates the volatile memory. Therefore, when this loadAuthenticationKey is executed (it is called internally in reader.authenticate), the Load Keys command fail with error code 27014(= 0x6986 in HEX = Volatile memory is not available error per OMNIKEY docs). Another (non fatal) problems are that the implementation in Reader class considers only 2 key slots and does not support optimized loading of persistent key slots.

Possible solutions:

  1. improve the current implementation in Reader class and make it more abstract to support configurable loading of keys
  2. (and/or) create a subclass of Reader class (i.e. OMNIKEY5422Reader) that implements reader.authenticate specifically for OMNIKEY 5422

Right now, I am working on PoC for 1. and will soon post instructions on how to install and test a modified version of nfc-pcsc.

Hope it helps. 🙂


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

@pokusew
Copy link
Owner

pokusew commented Feb 18, 2021

Hi @alanezze,

I rewrote the PC/SC Authentication implementation in Reader class to be more universal (branch #universal-pcsc-authentication). 😅 Now it is fully configurable and it should work (not only) on OMNIKEY 5422.

You can find an updated MIFARE Classic example here. To test it locally, please run:

git clone https://github.com/pokusew/nfc-pcsc.git
cd nfc-pcsc
git checkout universal-pcsc-authentication
yarn # or npm install
yarn run example-mifare-classic # or npm run example-mifare-classic

Please let me know, if it works for you. 🙂

@alanezze
Copy link

alanezze commented Feb 19, 2021 via email

@ColinMall94
Copy link

Could you just please explain what your use-case of specifying the read class is?

I’m reading the NDEF records from a type 4 tag inside a device (Elsys sensor). I was looking at how another program (https://itunes.apple.com/us/app/nfc-ideas/id1245536234?mt=12) was reading the tag. It involved setting the class to zero. I don’t know why (I know very little about these protocols) but with the default 0xFF it was not working.

@martijnthe Would you remember what your authentication key was for the sensors? I can't seem to get the key correct to try read from them

@martijnthe
Copy link
Contributor Author

@ColinMall94 i don’t recall there being any auth involved.

@ColinMall94
Copy link

ColinMall94 commented Feb 12, 2022

@martijnthe Thanks for the response. Having a tough time getting it to return a valid response. Could be my ACR122u though...

@ColinMall94
Copy link

@martijnthe May i ask what reader you used to read the elsys sensors?

@martijnthe
Copy link
Contributor Author

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

Successfully merging this pull request may close these issues.

Malformed SELECT FILE command?
4 participants