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

Recovering from Error #37

Open
bierlair opened this issue Mar 10, 2018 · 2 comments
Open

Recovering from Error #37

bierlair opened this issue Mar 10, 2018 · 2 comments
Assignees
Labels

Comments

@bierlair
Copy link

bierlair commented Mar 10, 2018

I'm trying to write some methods that are checking if a card (in my case NTAG-21x) needs authentication or not.

So far what I'm doing is reading 4 Bytes from Page 4 and if it fails, it means that I need to authenticate.

The problem occurs that the error thrown during that reading failure is preventing me from doing anything meaningful until I disconnect and reconnect the card.

Here some code:

try {
	let data = await this.reader.read(4, 4);
	return true;
} catch (err) {
	console.log("Cannot read, so we must authenticate!");
}

try {
	// if first try block is commented out, this block here works just fine!!!
	console.log("This fails, even though this area is not password protected");
	let data2 = await this.reader.read(0, 4);
} catch (err) {
	console.log("I will always be thrown, no matter what... WHY?", err);
}

Errors looks somewhat like this:

first try/catch:

ERR-0: { ReadError: Read operation failed: Status code: 0x6300
at /home/yoga/node/backend/node_modules/nfc-pcsc/dist/Reader.js:503:11
at Generator.next (<anonymous>)
at step (/home/yoga/node/backend/node_modules/nfc-pcsc/dist/Reader.js:18:191)
at /home/yoga/node/backend/node_modules/nfc-pcsc/dist/Reader.js:18:361
at <anonymous> name: 'ReadError', code: 'operation_failed' }

second try/catch:

ERR-1: { ReadError: Read operation failed: Status code: 0x6300
at /home/yoga/node/backend/node_modules/nfc-pcsc/dist/Reader.js:503:11
at Generator.next (<anonymous>)
at step (/home/yoga/node/backend/node_modules/nfc-pcsc/dist/Reader.js:18:191)
at /home/yoga/node/backend/node_modules/nfc-pcsc/dist/Reader.js:18:361
at <anonymous> name: 'ReadError', code: 'operation_failed' }

Is there a way to reset the state without disconnecting the card?
... or is my authentication approach simply inefficient?

@pokusew
Copy link
Owner

pokusew commented Mar 13, 2018

Hi @bierlair,

Sorry for the late response. I've been quite busy.

I'll take a look at it this afternoon. I'll test it with my card.

I'll let you know what I figure out. 🙂

@pokusew pokusew self-assigned this Mar 13, 2018
@bierlair
Copy link
Author

bierlair commented Mar 13, 2018

From what I've found out so far is that once you receive a 0x6300 message, you cannot do anything else until the card reader goes back into "IDLE" mode (usually within 1-2 seconds, when the LED switches back to steady green).

If I was to build some kind of artificial timeout of 2 seconds between both try/catch blocks, it would work fine.

This leads me to believe that it's a by-design feature that cannot be changed... unless there is a certain APDU that forces to go back into IDLE state right away.

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

No branches or pull requests

2 participants