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

Authentication failed for same blocks BUT is Working in others #134

Open
koubi54 opened this issue Aug 10, 2022 · 1 comment
Open

Authentication failed for same blocks BUT is Working in others #134

koubi54 opened this issue Aug 10, 2022 · 1 comment

Comments

@koubi54
Copy link

koubi54 commented Aug 10, 2022

i have seen your documentation it was very helpful but i have this probleme i can't solve
when i scanne my card i can read 0,1,2,3 blocks but from 4 to 64 i have an error

Note: the card is note empty

ACS ACR122U PICC Interface 0 card detected {
atr: <Buffer 3b 8f 80 01 80 4f 0c a0 00 00 03 06 03 00 01 00 00 00 00 6a>,
standard: 'TAG_ISO_14443_3',
type: 'TAG_ISO_14443_3',
uid: '0336a703'
}
Mifare Classic 1k
AuthenticationError: Authentication operation failed: Status code: 0x6300
at ACR122Reader.authenticate (C:\Users\azerty\Desktop\nodejs\nfc\node_modules\nfc-pcsc\dist\Reader.js:380:13)
at async ACR122Reader. (C:\Users\azerty\Desktop\nodejs\nfc\test.js:67:13) {
code: 'operation_failed'
}

############## my code ###################

const { NFC ,TAG_ISO_14443_3, TAG_ISO_14443_4, KEY_TYPE_A, KEY_TYPE_B } = require('nfc-pcsc');
const fs = require('fs');
const nfc = new NFC(); // optionally you can pass logger
nfc.on('reader', reader => {
console.log(${reader.reader.name} device attached);
reader.aid = 'F222222222';
reader.on('card', async card => {
try {
await reader.authenticate(0,KEY_TYPE_B, "ffffffffffff")
const data0 = await reader.read(0, 16, 16);
console.log(data0);
await reader.authenticate(1,KEY_TYPE_B, "ffffffffffff")
const data1 = await reader.read(1, 16, 16);
console.log(data1);
await reader.authenticate(4,KEY_TYPE_B, "ffffffffffff")
const data4 = await reader.read(4, 16, 16);
console.log(data4);
await reader.authenticate(5,KEY_TYPE_B, "ffffffffffff")
const data5 = await reader.read(5, 16, 16);
console.log(data5);
} catch (err) {
console.error(err);
}
});
reader.on('card.off', card => {
console.log(${reader.reader.name} card removed, card);
});
reader.on('error', err => {
console.log(${reader.reader.name} an error occurred, err);
});
reader.on('end', () => {
console.log(${reader.reader.name} device removed);
});
});
nfc.on('error', err => {
console.log('an error occurred', err);
});

@davidgs
Copy link

davidgs commented Apr 5, 2023

You cannot authenticate to block 0, as far as I'm aware. You have to start at block 4. I haven't tried using the KEY_TYPE_B but with my Mifare classic 1k cards KEY_TYPE_A works.

const key = 'FFFFFFFFFFFF'; 
const keyType = NFC.KEY_TYPE_A;
try {
      await Promise.all([
        reader.authenticate(4, keyType, key),
        reader.authenticate(5, keyType, key),
        reader.authenticate(6, keyType, key),
      ]);
      console.log(`3 sectors successfully authenticated`, reader);
    } catch (err) {
      console.log(
        `error when authenticating block 4 within the sector 1`,
        reader,
        err
      );
      return;
    }

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

No branches or pull requests

2 participants