Closed timolehto closed 2 months ago
It is a bit more complex than that. Most important part here is https://learn.microsoft.com/en-us/windows/win32/api/winscard/nf-winscard-scardbegintransaction#remarks
I'd say that you need to make sure that you have exclusive access (no other apps) yourself as well.
I'm not entirely sure what you mean? Are you saying that we need to employ some special tricks to take account on the possibility that there would be longer pauses between operations than 5s? What could cause such a long pause in between operations within an interaction? Did we used to do that?
Now, ofc making sure other apps don't mess up with access is something that probably usually makes sense too and I'm looking into that as well, but why wouldn't we want to grab a lock and prevent anyone else from messing up with the interaction (like we used to) post https://github.com/martinpaljak/GlobalPlatformPro/commit/6347f0f5dc7eff1a48c22d498dc8007c8a0ff995?
After some heavy debugging, I think the issue is that for some reason:
pcsc-lite-acsccid
drivers are doing something insane because....instantly when I insert a card on the reader the pcscd debug log fills with this kind of interaction (and this would just go on for like forever). Like what is this?! :dizzy_face:
00000003 [139943663593728] -> 000000 65 00 00 00 00 00 00 00 00 00
00000168 [139943663593728] <- 000000 81 00 00 00 00 00 00 02 81 00
00000002 [139943663593728] -> 000000 65 00 00 00 00 00 01 00 00 00
00001056 [139943663593728] <- 000000 81 00 00 00 00 00 01 02 81 00
00000005 [139943630341824] -> 000000 65 00 00 00 00 00 02 00 00 00
00000848 [139943630341824] <- 000000 81 00 00 00 00 00 02 02 81 00
00000002 [139943630341824] -> 000000 65 00 00 00 00 00 03 00 00 00
00000999 [139943630341824] <- 000000 81 00 00 00 00 00 03 02 81 00
00000004 [139943663593728] -> 000001 65 00 00 00 00 00 00 00 00 00
00001144 [139943663593728] <- 000001 81 00 00 00 00 00 00 02 00 00
00000003 [139943609370304] -> 000001 62 00 00 00 00 00 01 00 00 00
00007905 [139943609370304] <- 000001 80 00 00 00 00 00 01 02 00 00
00000003 [139943630341824] -> 000000 65 00 00 00 00 00 04 00 00 00
00051519 [139943630341824] <- 000000 81 00 00 00 00 00 04 00 81 00
00000002 [139943630341824] -> 000000 65 00 00 00 00 00 05 00 00 00
00001044 [139943630341824] <- 000000 81 00 00 00 00 00 05 00 81 00
00000002 [139943630341824] -> 000000 62 00 00 00 00 00 06 00 00 00
00001096 [139943630341824] <- 000000 80 0A 00 00 00 00 06 00 81 00 3B 85 80 01 80 73 C8 21 10 0E
00000003 [139943510804160] -> 000000 61 07 00 00 00 00 07 01 00 00 11 10 00 4D 00 20 00
00001011 [139943510804160] <- 000000 82 07 00 00 00 00 07 00 81 01 11 10 01 4D 00 FE 00
00000004 [139943510804160] -> 000000 6F 0C 00 00 00 00 08 00 00 00 00 A4 04 00 07 62 76 01 FF 00 00 00
00017004 [139943510804160] <- 000000 80 02 00 00 00 00 08 00 81 00 6A 82
00000002 [139943510804160] -> 000000 6F 0B 00 00 00 00 09 00 00 00 00 A4 04 00 06 A0 00 00 00 01 01
00008495 [139943510804160] <- 000000 80 02 00 00 00 00 09 00 81 00 6A 82
00000003 [139943510804160] -> 000000 6F 11 00 00 00 00 0A 00 00 00 00 A4 04 00 0B E8 2B 06 01 04 01 81 C3 1F 02 01 00
00009028 [139943510804160] <- 000000 80 02 00 00 00 00 0A 00 81 00 6A 82
00000004 [139943510804160] -> 000000 6F 05 00 00 00 00 0B 00 00 00 00 CA DF 30 05
00009113 [139943510804160] <- 000000 80 02 00 00 00 00 0B 00 81 00 6A 80
00000007 [139943510804160] -> 000000 6F 09 00 00 00 00 0C 00 00 00 00 CB 3F FF 03 5C 01 7E 00
00006937 [139943510804160] <- 000000 80 02 00 00 00 00 0C 00 81 00 6E 00
00000007 [139943510804160] -> 000000 6F 0F 00 00 00 00 0D 00 00 00 00 A4 04 00 09 A0 00 00 03 08 00 00 10 00 00
00008766 [139943510804160] <- 000000 80 02 00 00 00 00 0D 00 81 00 6A 82
00000005 [139943510804160] -> 000000 6F 0D 00 00 00 00 0E 00 00 00 00 A4 04 0C 07 A0 00 00 01 16 DB 00 00
00008699 [139943510804160] <- 000000 80 02 00 00 00 00 0E 00 81 00 6A 82
00000006 [139943510804160] -> 000000 6F 0D 00 00 00 00 0F 00 00 00 00 A4 04 0C 07 A0 00 00 00 79 10 00 00
00008614 [139943510804160] <- 000000 80 02 00 00 00 00 0F 00 81 00 6A 82
00000005 [139943510804160] -> 000000 6F 0D 00 00 00 00 10 00 00 00 00 A4 04 0C 07 A0 00 00 00 79 01 00 00
00008722 [139943510804160] <- 000000 80 02 00 00 00 00 10 00 81 00 6A 82
00000004 [139943510804160] -> 000000 6F 0D 00 00 00 00 11 00 00 00 00 A4 04 0C 07 A0 00 00 00 79 01 01 00
00008648 [139943510804160] <- 000000 80 02 00 00 00 00 11 00 81 00 6A 82
00000007 [139943510804160] -> 000000 6F 0D 00 00 00 00 12 00 00 00 00 A4 04 0C 07 A0 00 00 00 79 01 02 00
00008777 [139943510804160] <- 000000 80 02 00 00 00 00 12 00 81 00 6A 82
00000006 [139943510804160] -> 000000 6F 0D 00 00 00 00 13 00 00 00 00 A4 04 0C 07 A0 00 00 00 79 01 03 00
00008565 [139943510804160] <- 000000 80 02 00 00 00 00 13 00 81 00 6A 82
00000006 [139943510804160] -> 000000 6F 0D 00 00 00 00 14 00 00 00 00 A4 04 0C 07 A0 00 00 00 79 01 04 00
00002129 [139943510804160] <- 000000 80 02 00 00 00 00 14 00 81 00 6A 82
00000006 [139943510804160] -> 000000 6F 0D 00 00 00 00 15 00 00 00 00 A4 04 0C 07 A0 00 00 00 79 01 05 00
00011224 [139943510804160] <- 000000 80 02 00 00 00 00 15 00 81 00 6A 82
00000005 [139943510804160] -> 000000 6F 0D 00 00 00 00 16 00 00 00 00 A4 04 0C 07 A0 00 00 00 79 01 06 00
00009035 [139943510804160] <- 000000 80 02 00 00 00 00 16 00 81 00 6A 82
00000006 [139943510804160] -> 000000 6F 0D 00 00 00 00 17 00 00 00 00 A4 04 0C 07 A0 00 00 00 79 01 07 00
00010351 [139943510804160] <- 000000 80 02 00 00 00 00 17 00 81 00 6A 82
00000007 [139943510804160] -> 000000 6F 0D 00 00 00 00 18 00 00 00 00 A4 04 0C 07 A0 00 00 00 79 01 08 00
00009873 [139943510804160] <- 000000 80 02 00 00 00 00 18 00 81 00 6A 82
00000005 [139943510804160] -> 000000 6F 0D 00 00 00 00 19 00 00 00 00 A4 04 0C 07 A0 00 00 00 79 01 09 00
00008666 [139943510804160] <- 000000 80 02 00 00 00 00 19 00 81 00 6A 82
00000007 [139943510804160] -> 000000 6F 0D 00 00 00 00 1A 00 00 00 00 A4 04 0C 07 A0 00 00 00 79 01 0A 00
00008171 [139943510804160] <- 000000 80 02 00 00 00 00 1A 00 81 00 6A 82
00000007 [139943510804160] -> 000000 6F 0D 00 00 00 00 1B 00 00 00 00 A4 04 0C 07 A0 00 00 00 79 01 0B 00
00008517 [139943510804160] <- 000000 80 02 00 00 00 00 1B 00 81 00 6A 82
00000006 [139943510804160] -> 000000 6F 0D 00 00 00 00 1C 00 00 00 00 A4 04 0C 07 A0 00 00 00 79 01 0C 00
00008949 [139943510804160] <- 000000 80 02 00 00 00 00 1C 00 81 00 6A 82
00000008 [139943510804160] -> 000000 6F 0D 00 00 00 00 1D 00 00 00 00 A4 04 0C 07 A0 00 00 00 79 01 0D 00
00009121 [139943510804160] <- 000000 80 02 00 00 00 00 1D 00 81 00 6A 82
00000008 [139943510804160] -> 000000 6F 0D 00 00 00 00 1E 00 00 00 00 A4 04 0C 07 A0 00 00 00 79 01 0E 00
00008675 [139943510804160] <- 000000 80 02 00 00 00 00 1E 00 81 00 6A 82
00000007 [139943510804160] -> 000000 6F 0D 00 00 00 00 1F 00 00 00 00 A4 04 0C 07 A0 00 00 00 79 01 0F 00
00008876 [139943510804160] <- 000000 80 02 00 00 00 00 1F 00 81 00 6A 82
00000007 [139943510804160] -> 000000 6F 11 00 00 00 00 20 00 00 00 00 A4 04 00 0C F2 76 A2 88 BC FB A6 9D 34 F3 10 01
However, after I removed those ACS specific drivers forcing pcscd
to pick the generic pcsc-lite-ccid
drivers instead this nonsense stopped. It's still in polling mode sure, but it just polls the CMD_GET_READERS_STATE
and no APDU commands get issued. Maybe this bugs been fixed in later versions. I might check that and if not report it to the maintainers.
But regardless.. I'm not seeing any reason not to wrap inteactions in a transation as suggested in this commit and like it is with the current latest stable release of GPP. If there is some cases where this could be disadvantageous, then perhaps allowing to configure that via cmd line options would make sense. If you prefere that, I can try and enhance this PR to work so that the cli takes --exclusive
option and only if it's provided it wraps the interation in a transaction.
Please have a look at the next branch. I'd recommend connecting to the reader in exclusive mode if possible, by using -X
-X is present in master, together with returned default transactions
...as was done until commit 6347f0f removed this behaviour