3

I load dynamically pkcs11 security Provider in java and it works as long as the smart card reader is inserted before running the application. Could anyone please tell me how to detect a smartcard hotplug when the application is running? Actually I need something like pcsc_scan in java. The environment is Ubuntu 9.10 with java 1.6.0_20. Thanks in advance

user428539
  • 31
  • 1
  • 2

2 Answers2

3

Can you use the javax.smartcardio.* API in conjunction with PKCS #11?

The CardTerminal class has isCardPresent(), waitForCardPresent(timeout), and waitForCardAbsent(timeout) methods which can be used in a seperate thread to poll for card insertion events.

martijno
  • 1,723
  • 1
  • 23
  • 53
  • This answer helped me in an unexpected way. I was wondering why my PKCS #11 application no longer worked after a move from a desktop to a notebook. After running `TerminalFactory.getDefault().terminals().list()` it turned out that I had two card readers. One visible USB reader that I was using and one internal in the notebook that I hadn't seen – Tilman Hausherr Nov 15 '22 at 14:25
2

PKCS#11 doesn't define a standard way to actively notify the application about device insertion/removal. The best you can do is to run a thread which will check the number of slots and their state once a second or so.

Eugene Mayevski 'Callback
  • 45,135
  • 8
  • 71
  • 121
  • 2
    Yes, I did so... I looks like that p11 = PKCS11.getInstance("/usr/local/lib/libsiecap11.so", "C_GetFunctionList", null, false); long[] slots = p11.C_GetSlotList(true); And I encountered the very same problem. The good thing is that I could see whenever a card is removed, but still number of slots does not change while the application is running. For example - if I put a smartcard reader in a usb slot and run my application the number of slots will be 1. Although I put another smartcard reader (while application is still running) the number of slots will remain 1. – user428539 Aug 24 '10 at 07:51
  • 1
    The number of slots is usually the same, but their state will change. The fact that putting two readers (are they of the same vendor?) doesn't change the number of slots can be a defect of PKCS#11 driver. In this case you need to check with driver vendor. – Eugene Mayevski 'Callback Aug 24 '10 at 08:27
  • 1
    Yes the two cards are from the same vendor (manufacturerID: Siemens AG (C)... model: CardOS V4.3B (C))... So if I start the application with no smartcard plugged in advance - the method C_GetSlotList() will always return 0. For example the PC/SC device scanner (pcsc_scan) is working fine and detects whenever I plug or unplug a smarcard in the computer. – user428539 Aug 24 '10 at 08:55
  • 2
    then it's a problem of PKCS#11 driver itself. We saw such problems before with some hardwares. PKCS#11 drivers are far from ideal (partially due to ambiguities in the standard, partially due to programming errors). – Eugene Mayevski 'Callback Aug 24 '10 at 09:48