Reply To: How to limit negative verification attemps with Ultralight EV 1

Forum MIFARE SDK How to limit negative verification attemps with Ultralight EV 1 Reply To: How to limit negative verification attemps with Ultralight EV 1

Re: How to limit negative verification attemps with Ultralight EV 1

1. February 2017 at 15:36
For anyone interested in this feature, after some trial and error I was able to write the corresponding bits in the tag with the following code:

ultralightEV1.enablePasswordProtection(true, 0); // Must be called before writing the tries page since it overwrites the corresponding page, enablePasswordProtection will write 00000000 or 10000000 on the corresponding byte if provided with false and true respectively
ultralightEV1.authenticatePwd(myKey);


//Write the limit tries byte, must be done after enablePasswordProtection
int indexNumTries = ultralightEV1.getTotalMemory() - 12; // Index of associated byte
int pageTries = indexNumTries / 4; // Index of associated page
byte[] dataPage = ultralightEV1.read(pageTries); // We read the associated page with the value written by enablePasswordProtection
byte[] finalPage = new byte[4]; // We create the page to write since dataPage has 16 bytes as documented by taplinx
System.arraycopy(dataPage, 0, finalPage, 0, 4);
finalPage[0] = (byte)(dataPage[0]|0x07); // The least 3 significant bytes are the number of tries, we are setting a max of 7 invalid tries but any value from 0 to 7 is valid (note that 0 disables the protection)

ultralightEV1.write(pageTries, finalPage); //Write the page


Do note that any call to enablePasswordProtection will delete the bytes since it uses the most significative bit of the associated byte to signal if read is password protected and, instead of doing the proper byte operations with the current value of the page, the library will simply overwrite the byte value with 00000000 or 10000000, efectivelly disabling the tries protection.

Hopefully this feature will be supported by taplinx in the future but in the meantime this works.
+ 0  |  - 0