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

Ultralight EV1 password authentication #32

Closed
RomanBobko opened this issue Jan 9, 2018 · 1 comment
Closed

Ultralight EV1 password authentication #32

RomanBobko opened this issue Jan 9, 2018 · 1 comment

Comments

@RomanBobko
Copy link

Hello,
Thanks a lot for this library!
I'm try write data to Mifare Ultralight EV1 card with password.
Before write, i'm try send pseudo-APDU command PWD_AUTH (0x1B) but response empty buffer and data write error.
How can i send authenticate command?
Pleas help.

Here is my code:

const { NFC } = require('nfc-pcsc');
const nfc = new NFC();

nfc.on('reader', reader => {

    console.log(`${ reader.reader.name } device attached`);

    reader.on('card', async card => {

        try {
            // APDU CMD: Update Binary Block
            const packet = new Buffer([
                0xFF, // Class				
                0x00,
                0x00,
                0x00,
                0x05, //Length
                0x1B, //PWD_AUTH
                0x11, //my pass
                0x22, //my pass
                0x33, //my pass
                0x44 //my pass
            ]);
            var pwdResponse = await reader.transmit(packet, 2);  
            console.log('pwd response', pwdResponse);
        } catch (err) {
            console.log('error pwd_auth');
        }
        
        try {
            const data = Buffer.allocUnsafe(12);
            data.fill(0);
            const text = (new Date()).toTimeString();
            data.write(text);      
            await reader.write(4, data); 

            console.log('data written');
           
        } catch (err) {
            console.error('error when writing data', err);
        }       
    });
});
ACS ACR122 0 device attached
pwd response <Buffer >
error when writing data { WriteError: Write operation failed: Status code: 0x6300
    at C:\Users\admin\Documents\acr122u\node_modules\nfc-pcsc\dist\Reader.js:579:11
    at Generator.next (<anonymous>)
    at step (C:\Users\admin\Documents\acr122u\node_modules\nfc-pcsc\dist\Reader.js:18:191)
    at C:\Users\admin\Documents\acr122u\node_modules\nfc-pcsc\dist\Reader.js:18:361
    at <anonymous> name: 'WriteError', code: 'operation_failed' }
@RomanBobko
Copy link
Author

I finded solution my problem.
In packet need insert 2 bytes 0xD4, 0x42, and Length change to 0x07
In method response second paramether change to 7

        // APDU CMD: Update Binary Block
        const packet = new Buffer([
            0xFF, // Class				
            0x00,
            0x00,
            0x00,
            0x07, //Length
            0xD4, // inserted
            0x42, // inserted
            0x1B, //PWD_AUTH
            0x11, //my pass
            0x22, //my pass
            0x33, //my pass
            0x44 //my pass
        ]);
        var pwdResponse = await reader.transmit(packet, 7);  // 7 response size
        console.log('pwd response', pwdResponse);

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

1 participant