LudovicRousseau / pyscard

pyscard smartcard library for python
http://pyscard.sourceforge.net/
GNU Lesser General Public License v2.1
396 stars 113 forks source link

Pyscard doesn't recover from PCSC error #82

Closed massey101 closed 5 years ago

massey101 commented 5 years ago

If pcscd is restarted after a monitor is created a ListReadersException is generated in the monitoring thread which causes it to exit the loop and stop monitoring. No attempt is made to restart monitoring and no notification is sent to the application. This leaves us in the awkward situation where the only way for a user to recover from this is to notice that their actions don't correspond with what is on screen and restart the application.

I propose that there should be some way to notify observers that monitoring has ceased. The application can then either attempt to restart the monitoring or abort. What would you suggest would be the optimal way to notify this?

LudovicRousseau commented 5 years ago

Why do you want to restart pcscd?

massey101 commented 5 years ago

We have a use case where we use YubiKeys both in a virtual machine and on the host machine, in order to pass the smartcard through to the virtual machine it must not be in use on the host. The application is a chrome extension and therefore the only way to restart it is to close all of your chrome windows. We also use virtual machines as developers and this presents the same issue.

LudovicRousseau commented 5 years ago

So you manually kill pcscd to free the YubiKeys from the host and make them available in the virtual machine? Am I correct?

massey101 commented 5 years ago

In this use case pcscd is automatically killed when the user changes focus to the virtual machine and then restarted when focus is returned. A co-worker has presented a workaround that tracks the PID of pcscd and restarts the monitoring when it changes. I figured this would be a cleaner solution and it would work in a variety of cases, such as if there was another error. Do you have any other ideas?

LudovicRousseau commented 5 years ago

Another idea would be to ask PC/SC to disconnect a specific reader (so it can become accessible from the VM). I don't think the official PC/SC API proposes such a service. It could be implemented using SCardControl() and a special control code.

LudovicRousseau commented 5 years ago

Your problem should be solved at the https://github.com/LudovicRousseau/PCSC level. I can work on the solution I proposed if you want. Just contact me.