I have a seemingly easy task, which is to read unencrypted data from a chip card with Java. I have no experience at all with smart cards and I'm hoping that someone can point me in the right direction.
I set up a project with the javax.smartcardio library and while that works like a charm with my credit card (card reader recognized, cart insert recognized, card connection established), it doesn't work with the card I'm trying to read.
The problem is that the card doesn't conform to smartcard standards (I believe), because I get an SCARD_E_NO_SMARTCARD
error when I insert the card into the reader.
I do not have any documentation on how the data is actually stored on the card, but I would like to (if possible) just poke around a bit and figure it out. I also don't need to write to the card, just read the data stored on it.
I would like to create a CardTerminal implementation that allows me to just send arbitrary commands to the card instead of initiating a protocol.
This is what I have:
import java.util.List;
import javax.smartcardio.*;
public class SReader {
public static int listCounted() {
TerminalFactory factory = TerminalFactory.getDefault();
try {
List terminals = factory.terminals().list();
CardTerminal ter = (CardTerminal)terminals.get(0);
ter.waitForCardPresent(3000000);
if(ter.isCardPresent())
{
System.out.println("Card present");
// this causes the issue
Card ca = ter.connect("*");
System.out.println(ca);
}
System.out.println( ((CardTerminal)terminals.get(0)).isCardPresent());
return terminals.size();
} catch (CardException e) {
e.printStackTrace();
}
return 0;
}
public static void main(String[] args) {
listCounted();
}
}
and this is the error message I get when I insert the card:
Card present
javax.smartcardio.CardNotPresentException: No card present
at java.smartcardio/sun.security.smartcardio.TerminalImpl.connect(TerminalImpl.java:83)
at Smaca/com.Smaca.SReader.listCounted(SReader.java:35)
at Smaca/com.Smaca.SReader.main(SReader.java:58)
Caused by: sun.security.smartcardio.PCSCException: SCARD_E_NO_SMARTCARD
at java.smartcardio/sun.security.smartcardio.PCSC.SCardConnect(Native Method)
at java.smartcardio/sun.security.smartcardio.CardImpl.<init>(CardImpl.java:97)
at java.smartcardio/sun.security.smartcardio.TerminalImpl.connect(TerminalImpl.java:79)
... 2 more
I guess I need to write a custom TerminalFactory implementation to be able to read the card? I have searched for days to find an example on how to do this but couldn't find anything useful. I'm also not sure if this approach is right for what I'm trying to achieve.
Any cross-platform solution that would allow me to do this (node.js, python, Java) would work.
Any help is greatly appreciated!
Thanks, Tom