3

I'm using sun.security.smartcardio library to work with smartcards. I've used the example source code in Java suggested by Ludovic Rousseau. If I loop that code, when I perform the selection of available card terminals (sun.security.smartcardio.PCSCTerminals.list(Unknown Source)), I have the following exception:

sun.security.smartcardio.PCSCException: SCARD_E_NO_SERVICE

If I restart the application after each use of smartcard, everything works well. Anyone knows why it happens in this way?

Thanks for your help

Francesco

FrancescoDS
  • 1,077
  • 4
  • 21
  • 55
  • Please point to the source code sample and include a SSCCE if possible. You should not use anything in `sun` packages directly, use `javax.smartcardio` instead. Note that `javax.smartcardio` may not be present, so you may have to download the implementation if it is not available. The documentation is also missing when you donwload the docs, use online docs or the one found in the JSR instead. – Maarten Bodewes Jan 03 '13 at 16:45
  • In my source code, I've used the javax.smartcardio package. The problem is that I have not found any good docs about it, and there are no samples that uses a loop of calls to smartcards. I've noticed that, following the sample of Ludovic Rousseau, when I perform the Card.disconnect(), I have the same problem described in the post. I use the pcscd tool on Ubuntu to allow the use of smartcard reader with pcsc driver. – FrancescoDS Jan 04 '13 at 08:25
  • now the error is changed - MESSAGE: disconnect() failed - CAUSE: sun.security.smartcardio.PCSCException: Unknown error 0x5f6e6570 - sun.security.smartcardio.CardImpl.disconnect(Unknown Source) I have not found anything about this error code! – FrancescoDS Jan 04 '13 at 11:17
  • It comes out if I call the disconnect() without the card in the reader. If the card is in the reader (and pcscd running) I see the error SCARD_E_NO_SERVICE – FrancescoDS Jan 04 '13 at 11:35
  • 1
    Note that in general there are a lot of bugs in smartcard reader software. I had to choose a specific reader to do repetative testing, and I had to program around bugs even then. Did you try using time-outs on between the commands to the reader? The error you get is probably PCSC or reader manufacturer specific. – Maarten Bodewes Jan 04 '13 at 11:36
  • The problem is that the disconnect always gave me an error and I don't know why...plus the error code is unknown...I give timeouts between calls. Maybe there is something wrong in my code...following a short list of calls: 1. pcscd start; 2. selectCardTerminal; 3. waitforcardpresent; 4. connect; 5. getbasicchannel; 6. apdus to smartcard; 7. disconnect – FrancescoDS Jan 04 '13 at 15:46
  • I don't see any issues. Note that you cannot close the basic channel and that you could try to get exclusive access to the terminal; but those are just hints. Don't forget to request a card reset, or play around with them a bit. If all else fails try another reader, omnikey or the more expensive smartware readers are recommended. – Maarten Bodewes Jan 04 '13 at 23:24
  • So, do you mean that there can be problems with smartcard reader and its drivers? It can be a real big problem...I don't close the basic channel, but I only try to close connection with card. I will try to perform disconnect() with reset of the card. What do you mean with "exclusive access"?Thanks a lot for your help – FrancescoDS Jan 07 '13 at 08:54
  • There should be a method Terminal.beginExclusive(), which should make sure that only tour app has access to the reader. – Maarten Bodewes Jan 07 '13 at 09:48
  • when beginExclusive must be called?after cardTerminal.connect() and before each apdu command? Notice that my application is the only one that access the reader surely (is the only app running in the OS) – FrancescoDS Jan 07 '13 at 14:06
  • This is basically troubleshooting, it could work (e.g against windows services) – Maarten Bodewes Jan 07 '13 at 14:38
  • Please see http://docs.oracle.com/javase/6/docs/jre/api/security/smartcardio/spec/javax/smartcardio/Card.html#beginExclusive(), so it was Card, not Terminal. – Maarten Bodewes Jan 07 '13 at 16:26
  • In Windows 8, the service shuts down when there are no more readers plugged in. See also http://stackoverflow.com/questions/16921785/smartcard-terminal-removal-scard-e-no-service-cardexception – yonran Nov 13 '13 at 15:44
  • 1
    This should help https://stackoverflow.com/questions/16921785/smartcard-terminal-removal-scard-e-no-service-cardexception – devesh-ahuja Jun 21 '17 at 17:31

0 Answers0