Using javax.smartcardio from a servlet

839 views Asked by At

I have a servlet that uses javax.smartcardio to try to access the PCSC smartcard reader attached to the server. Unfortunately when I try to list the attached readers in the servlet the list is empty. However, when I run a local java program running the same code the list contains the attached reader as expected. Can someone explain why this could be - is it something to do with security and sandboxing? Is there any way around this?

    TerminalFactory factory = TerminalFactory.getDefault();
    List<CardTerminal> terminals = factory.terminals().list();
        if (terminals.size() < 2) {
            out.println("no readers");
            return;
        }
    out.println("Terminals: " + terminals);
    CardTerminal terminal = terminals.get(1);
    // establish a connection with the card
    Card card = terminal.connect("T=1");
    out.println("card: " + card);
    CardChannel channel = card.getBasicChannel();

The output from above when run in a local java program on the command line is:

Terminals: [PC/SC terminal SDI011 USB Smart Card Reader 00 00, PC/SC terminal SDI011 USB Smart Card Reader 00 01]
card: PC/SC card in SDI011 USB Smart Card Reader 00 01, protocol T=1, state OK

And on the server I get

no readers
0

There are 0 answers