{"action":"created","issue":{"url":"https://api.github.com/repos/pokusew/nfc-pcsc/issues/59","repository_url":"https://api.github.com/repos/pokusew/nfc-pcsc","labels_url":"https://api.github.com/repos/pokusew/nfc-pcsc/issues/59/labels{/name}","comments_url":"https://api.github.com/repos/pokusew/nfc-pcsc/issues/59/comments","events_url":"https://api.github.com/repos/pokusew/nfc-pcsc/issues/59/events","html_url":"https://github.com/pokusew/nfc-pcsc/issues/59","id":393831603,"node_id":"MDU6SXNzdWUzOTM4MzE2MDM=","number":59,"title":"MIFARE Ultralight C authentication","user":{"login":"Franx0","id":8995180,"node_id":"MDQ6VXNlcjg5OTUxODA=","avatar_url":"https://avatars2.githubusercontent.com/u/8995180?v=4","gravatar_id":"","url":"https://api.github.com/users/Franx0","html_url":"https://github.com/Franx0","followers_url":"https://api.github.com/users/Franx0/followers","following_url":"https://api.github.com/users/Franx0/following{/other_user}","gists_url":"https://api.github.com/users/Franx0/gists{/gist_id}","starred_url":"https://api.github.com/users/Franx0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Franx0/subscriptions","organizations_url":"https://api.github.com/users/Franx0/orgs","repos_url":"https://api.github.com/users/Franx0/repos","events_url":"https://api.github.com/users/Franx0/events{/privacy}","received_events_url":"https://api.github.com/users/Franx0/received_events","type":"User","site_admin":false},"labels":[{"id":359540590,"node_id":"MDU6TGFiZWwzNTk1NDA1OTA=","url":"https://api.github.com/repos/pokusew/nfc-pcsc/labels/question","name":"question","color":"cc317c","default":true}],"state":"open","locked":false,"assignee":{"login":"pokusew","id":5508040,"node_id":"MDQ6VXNlcjU1MDgwNDA=","avatar_url":"https://avatars2.githubusercontent.com/u/5508040?v=4","gravatar_id":"","url":"https://api.github.com/users/pokusew","html_url":"https://github.com/pokusew","followers_url":"https://api.github.com/users/pokusew/followers","following_url":"https://api.github.com/users/pokusew/following{/other_user}","gists_url":"https://api.github.com/users/pokusew/gists{/gist_id}","starred_url":"https://api.github.com/users/pokusew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pokusew/subscriptions","organizations_url":"https://api.github.com/users/pokusew/orgs","repos_url":"https://api.github.com/users/pokusew/repos","events_url":"https://api.github.com/users/pokusew/events{/privacy}","received_events_url":"https://api.github.com/users/pokusew/received_events","type":"User","site_admin":false},"assignees":[{"login":"pokusew","id":5508040,"node_id":"MDQ6VXNlcjU1MDgwNDA=","avatar_url":"https://avatars2.githubusercontent.com/u/5508040?v=4","gravatar_id":"","url":"https://api.github.com/users/pokusew","html_url":"https://github.com/pokusew","followers_url":"https://api.github.com/users/pokusew/followers","following_url":"https://api.github.com/users/pokusew/following{/other_user}","gists_url":"https://api.github.com/users/pokusew/gists{/gist_id}","starred_url":"https://api.github.com/users/pokusew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pokusew/subscriptions","organizations_url":"https://api.github.com/users/pokusew/orgs","repos_url":"https://api.github.com/users/pokusew/repos","events_url":"https://api.github.com/users/pokusew/events{/privacy}","received_events_url":"https://api.github.com/users/pokusew/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2018-12-24T08:03:24Z","updated_at":"2019-01-02T10:20:20Z","closed_at":null,"author_association":"NONE","body":"First of all, great work @pokusew, is amazing and super usefull having resources like yours. Thank you!\r\n\r\nI'm on firts step on authentication of MIFARE Ultraligh C tags. Related to the doc I need to use a command to have the default tag key in return.\r\nhttps://www.nxp.com/docs/en/data-sheet/MF0ICU2.pdf (page 15)\r\n\r\nI'm using a block like that:\r\n```javascript\r\nreader.on('card', async card => {\r\n\tconsole.log(`${reader.reader.name}  card ${card.uid} inserted`, card);\r\n\ttry {\r\n\t\tconst buffer = Buffer.from([0x1a, 0x00]);\r\n\t\treturn resolve(await reader.transmit(buffer, 26));\t\t\t\t\r\n\t} cache (err) {\r\n                 console.log(err);\r\n        };\t\t\t\r\n});\r\n```\r\nThe main issue here is that always return a byteArray like that: Uint8Array(2) [99, 0]\r\ninstead of the expected 8 bytes string.\r\nMaybe I am missing something but the following code: 0x1a, 0x00 is neccessary as first authentication step.\r\n\r\nPD: Reader device: ACR1222L\r\n\r\nThank you all ;)\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/pokusew/nfc-pcsc/issues/comments/450828213","html_url":"https://github.com/pokusew/nfc-pcsc/issues/59#issuecomment-450828213","issue_url":"https://api.github.com/repos/pokusew/nfc-pcsc/issues/59","id":450828213,"node_id":"MDEyOklzc3VlQ29tbWVudDQ1MDgyODIxMw==","user":{"login":"Franx0","id":8995180,"node_id":"MDQ6VXNlcjg5OTUxODA=","avatar_url":"https://avatars2.githubusercontent.com/u/8995180?v=4","gravatar_id":"","url":"https://api.github.com/users/Franx0","html_url":"https://github.com/Franx0","followers_url":"https://api.github.com/users/Franx0/followers","following_url":"https://api.github.com/users/Franx0/following{/other_user}","gists_url":"https://api.github.com/users/Franx0/gists{/gist_id}","starred_url":"https://api.github.com/users/Franx0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Franx0/subscriptions","organizations_url":"https://api.github.com/users/Franx0/orgs","repos_url":"https://api.github.com/users/Franx0/repos","events_url":"https://api.github.com/users/Franx0/events{/privacy}","received_events_url":"https://api.github.com/users/Franx0/received_events","type":"User","site_admin":false},"created_at":"2019-01-02T10:20:20Z","updated_at":"2019-01-02T10:20:20Z","author_association":"NONE","body":"> Hi @Franx0,\r\n> \r\n> I am very sorry for the late reply. Thank you for posting your issue here. \r\n> \r\n> I faced the similar issues when I implemented MIFARE Ultralight EV1 password authentication (PWD_AUTH).\r\n> \r\n> **I think, the 5th byte (`0x16`, the `number of bytes to send`) should be `0x04` as you are trying to send these 4 bytes: ` 0xd4 0x42 0x1a 0x00`.**\r\n> \r\n> The following should work:\r\n> \r\n> ```js\r\n> Buffer.from([0xff, 0x00, 0x00, 0x00, 0x16, 0xd4, 0x42, 0x1a, 0x00])\r\n> ```\r\n> \r\n> **Explanation (might be useful for others):**\r\n> (also see the [MIFARE Ultralight EV1 example](https://github.com/pokusew/nfc-pcsc/blob/master/examples/mifare-ultralight-ntag.js#L85) in nfc-pcsc exmap)\r\n> \r\n> As yo figured out correctly, that the only way to send the command, seems to be via the ACR reader's **Direct Transmit** command. It's structure is as follows:\r\n> \r\n> ```js\r\n> const directTrasmit = Buffer.from([\r\n>     0xff,\r\n>     0x00,\r\n>     0x00,\r\n>     0x00,\r\n>     data.length, // number of bytes to send\r\n>     ...data, // data to send (assuming a Buffer or an array of bytes)\r\n> ]);\r\n> ```\r\n> \r\n> The data sent via Direct Transmit are passed directly to the internal NFC frontend chip (in case of ACR readers, that's NXP PN533 or similar). To communicate with the NFC card you have to use the **InCommunicateThru** as described in PN533 API docs. It's structure is as follows:\r\n> \r\n> ```js\r\n> const inCommunicateThru = Buffer.from([\r\n>     0xd4, // Data Exchange Command:\r\n>     0x42, // InCommunicateThru\r\n>     ...apdu, // data which will be sent directly to the card\r\n> ]);\r\n> ```\r\n> \r\n> **So the final structure for sending any direct command to the card for ACR readers might look like this:**\r\n> \r\n> ```js\r\n> const cmd = Buffer.from([/* the bytes of your command */]);\r\n> Buffer.from([\r\n>     0xff, // Class\r\n>     0x00, // Direct Transmit (see ACR122U docs) (INS)\r\n>     0x00, // ... (P2)\r\n>     0x00, // ... (P1)\r\n>     0x02 + cmd.length, // Lc: Length of the Direct Transmit Payload\r\n>     // Payload (2 + cmd.length) bytes\r\n>     0xd4, // Data Exchange Command (see PN533 docs)\r\n>     0x42, // InCommunicateThru\r\n>     ...cmd,\r\n> ]);\r\n> ```\r\n> \r\n> The response should like:\r\n> \r\n> ```\r\n> // d5 43 00 ... ... 90 00\r\n> // byte 0: d5 prefix for response of Data Exchange Command (see PN533 docs)\r\n> // byte 1: 43 prefix for response of Data Exchange Command (see PN533 docs)\r\n> // byte 2: Data Exchange Command Status – 0x00 is success (see PN533 docs, Table 15. Error code list)\r\n> // bytes 3-n: Data Exchange Command Response – response from the card\r\n> // last 2 bytes: ACR reader status code (should be always success – 90 00)\r\n> ```\r\n> **Please let me know if your able to make your command work.**\r\n> \r\n> Also I think, you might be interested in the [MIFARE DESFire example](https://github.com/pokusew/nfc-pcsc/blob/master/examples/mifare-desfire.js), where the 3DES authentication is implemented. It might be similar to the 3DES authentication procedure on the Ultralight C.\r\n> \r\n> Finally, I think that the MIFARE Ultralight C authentication would be great to have in nfc-pcsc examples. Once you finish it, feel free to open a PR to add it. Thanks. \r\n> \r\n> Hope it helps. \r\n> \r\n> PS Don't forget to star my library, if you find it useful. Thanks.\r\n\r\nHi @pokusew thanks for your reply. So many usefull doc in that comment ;), thank's a lot. Unfortunately I'm still not able to make the pcsc command works. Let me show you the two command responses:\r\n\r\n1. Sending the following:\r\n```javascript\r\n    let buffer = Buffer.from([0xff, 0x00, 0x00, 0x00, 0x04, 0xd4, 0x42, 0x1a, 0x00]);\r\n    reader.transmit(buffer, buffer.byteLength);\r\n```\r\nIn that case the response is the tag uid, not the 8byte token.\r\n\r\n2. Sending this one:\r\n```javascript\r\n    let buffer = Buffer.from([0xff, 0x00, 0x00, 0x00, 0x16, 0xd4, 0x42, 0x1a, 0x00]);\r\n    reader.transmit(buffer, buffer.byteLength);\r\n```\r\nThe response is \"d543019000\" as my previous comment. I can not figure out what I'm missing or what can be wrong. I debugged deep in order to see nothing weird in the response except this 01 byte that I assume it's an internal code from reader telling me that might exists a timeout issue. "}}
{"actor":{"display_login":"Franx0"}}