cryptographix / pcsc-deno

Deno FFI binding to the PCSC API
MIT License
1 stars 3 forks source link

Incorrect use of pioSendPci #7

Closed LudovicRousseau closed 1 year ago

LudovicRousseau commented 2 years ago

Like in https://github.com/cryptographix/pcsc-deno/issues/6 we have a problem with the size of DWORD.

Another problem is that you hard code the protocol value to 1 (for T=0) in https://github.com/cryptographix/pcsc-deno/blob/master/deno-pcsc-ffi/pcsc-ffi-wrapper.ts#L282 This will NOT work for a T=1 card.

You must use the protocol value returned by SCardConnect() in the pdwActiveProtocol parameter.

Here is a patch to be able to send an APDU to a T=1 card on GNU/Linux:

diff --git a/deno-pcsc-ffi/pcsc-ffi-wrapper.ts b/deno-pcsc-ffi/pcsc-ffi-wrapper.ts
index 54ef493..682a450 100644
--- a/deno-pcsc-ffi/pcsc-ffi-wrapper.ts
+++ b/deno-pcsc-ffi/pcsc-ffi-wrapper.ts
@@ -278,11 +278,11 @@ export function SCardDisconnect(
 }

 function prepareTransmit(recvLength: DWORD) {
-  const pioSendPci = new Uint8Array(8);
-  new DataView(pioSendPci.buffer).setUint32(0, 1, true);
-  new DataView(pioSendPci.buffer).setUint32(4, 8, true);
+  const pioSendPci = new Uint8Array(16);
+  new DataView(pioSendPci.buffer).setUint32(0, 2, true);
+  new DataView(pioSendPci.buffer).setUint32(8, 16, true);

-  const pioRecvPci = new Uint8Array(8);
+  const pioRecvPci = new Uint8Array(16);
   pioRecvPci.set(pioSendPci);

   const recvBuffer = new Uint8Array(recvLength + 2);

I had to:

cryptographix commented 1 year ago

Thanks for the issue.

Deno has recently including "static" data imports from DLL, so maybe can use pcsc exports for pioRecv and pioSend.

I'll have a look,

LudovicRousseau commented 1 year ago

It works for me now