Hello,
i have got a problem with my host application. I am not able to send data from the smart card to the host application. I use the javax.smartcardio package and the following code to communicate with the smartcard.
try {
if (TerminalFactory.getDefault().terminals().list().size() == 0) {
LOGGER.log(Level.SEVERE, "No reader present");
}
CardTerminal terminal = TerminalFactory.getDefault().terminals().list().get(0);
/* Is a card present? */
if (!terminal.isCardPresent()) {
LOGGER.log(Level.SEVERE, "No Card present!");
}
Card card = terminal.connect("*");
CardChannel channel = card.getBasicChannel();
byte[] aid = {(byte) 0xD0, (byte) 0xD1, (byte) 0xD2, (byte) 0xD3, (byte) 0xD4, (byte) 0xD5, (byte) 0x01};
CommandAPDU select = new CommandAPDU(0x00, 0xa4, 0x04, 0x00, aid);
channel.transmit(select);
CommandAPDU cmd = new CommandAPDU((byte) 0xb0, (byte) 0x20, (byte) 0x00 , 0x00,5);
ResponseAPDU response = channel.transmit(cmd);
System.out.println(Integer.toString(response.getSW(), 16));
} catch (CardException ex) {
Logger.getLogger(SmartMeter.class.getName()).log(Level.SEVERE, null, ex);
}
javax.smartcardio.CardException: sun.security.smartcardio.PCSCException: Unknown error 0x8010002f
at sun.security.smartcardio.ChannelImpl.doTransmit(Unknown Source)
at sun.security.smartcardio.ChannelImpl.transmit(Unknown Source)
at de.upb.client.smartmeter.SmartMeter.<init>(SmartMeter.java:106)
at de.upb.client.smartmeter.SmartMeterApplikation.main(SmartMeterApplikation.java:37)
Caused by: sun.security.smartcardio.PCSCException: Unknown error 0x8010002f
at sun.security.smartcardio.PCSC.SCardTransmit(Native Method)
... 4 more
If i send the apdu via GPshell everything works fine. The trace is below:
establish_context
enable_trace
enable_timer
card_connect
command time: 15 ms
send_apdu -sc 0 -APDU 00a4040007a0000000030000
Command --> 00A4040007A0000000030000
Wrapped command --> 00A4040007A0000000030000
Response <-- 6F198408A000000003000000A50D9F6E062091010342759F6501FF9000
send_APDU() returns 0x80209000 (9000: Success. No error.)
command time: 47 ms
send_apdu -sc 0 -APDU 00a4040007D0D1D2D3D4D50101
Command --> 00A4040007D0D1D2D3D4D50101
Wrapped command --> 00A4040007D0D1D2D3D4D50101
Response <-- 9000
send_APDU() returns 0x80209000 (9000: Success. No error.)
command time: 62 ms
send_apdu -sc 0 -APDU b0200002;
Command --> B0200002
Wrapped command --> B0200002
Response <-- 02029000
send_APDU() returns 0x80209000 (9000: Success. No error.)
command time: 110 ms
card_disconnect
command time: 1357 ms
release_context
command time: 15 ms
Does a solution for this problem exist or is there a other way to communicate with the smart card in java ?
Currently i am testing my applet, if it works as expected, i want to use a SecureChannel to communicate with the smart card. Is it possible that the error will disappear then?
Can someone explain how i establish a SecureChannel in a java host application??
Thanks.