RoopeHakulinen / cordova-plugin-mifare-ultralight

Cordova plugin for interacting with Mifare Ultralight NFC tags.
MIT License
9 stars 3 forks source link

Implement lockWithPin #5

Open gjuchault opened 6 years ago

gjuchault commented 6 years ago

Hello,

You implemented unlockWithPin, and I was wondering if you were opened to a lockWithPin method.

Some good links for it: https://stackoverflow.com/questions/44395283/how-to-set-and-unset-password-on-a-mifare-ultralight-ev1-tag https://stackoverflow.com/questions/22719465/ntag212-mifare-ultralight-with-authentication

Unlock

send: Ox1B 0xPIN1 0xPIN2 0xPIN3 0xPIN4 receive: 0xPACK1 0xPACK2 compare PACK1 and PACK2 with values given in lock (or don't compare)

Lock

  1. Write PIN

PAGE: NTAG212 = page 39 MF0UL11 = page 12 MF0UL21 = page 27

send: 0xA2 0xPAGE 0xPIN1 0xPIN2 0xPIN3 0xPIN4

  1. Write PIN ACK (PACK)

PAGE: NTAG212 = page 40 MF0UL11 = page 13 MF0UL21 = page 28

send: 0xA2 0xPAGE 0xPACK1 0xPACK2 0x00 0x00

  1. Write protection wanted (PROT)

Protection can be set to 0 (PIN needed for write operations) or 1 (PIN needed for read or write operations)

PAGE: NTAG212 = page 38, byte 0, bit 7 MF0UL11 = page 11, byte 0, bit 7 MF0UL21 = page 26, byte 0, bit 7

send: 0x30 0xPAGE (get the complete page to only modify wanted bits) recieve: 0xRES1 0xRES2 0xRES3 0xRES4

ACCESS = 0xRES1 & 0x07F # PIN needed for write ACCESS = ACCESS | 0x80 # PIN needed for read

send: 0xA2 0xPAGE 0xACCESS 0xRES2 0xRES3 0xRES4

  1. Write first page being protected (AUTH0)

PAGE: NTAG212 = page 37, byte 3 MF0UL11 = page 10, byte 3 MF0UL21 = page 25, byte 3

send: 0x30 0xPAGE (get the complete page to only modify wanted bits) receive: 0xRES1 0xRES2 0xRES3 0xRES4 ... send: 0xA2 0xPAGE 0xRES1 0xRES2 0xRES3 0xAUTH0

RoopeHakulinen commented 6 years ago

Hey @gjuchault and thanks for the issue. Sorry it took quite some time to react.

I took a look into this and it seemed doable so I did a basic implementation. Could you please review the PR (#6) carefully and test if it works at all? I don't have any tags to try this out. The version should be installable with

npm install cordova-plugin-mifare-ultralight@beta

The documentation can be found in the README of the branch implementing the feature.

Let me know how it is :)

gjuchault commented 6 years ago

@RoopeHakulinen Hi that's so cool ! I'm a bit busy until 2th of July, I'll check around this date :)