use of javax.smartcardio.ResponseAPDU in project jdk8u_jdk by JetBrains.
the class Utils method transmitTestCommand.
static void transmitTestCommand(CardChannel channel) throws Exception {
ResponseAPDU r = channel.transmit(new CommandAPDU(C1));
byte[] rb = r.getBytes();
if ((Arrays.equals(rb, R1a) == false) && (Arrays.equals(rb, R1b) == false)) {
System.out.println("expected: " + toString(R1a));
System.out.println("received: " + toString(rb));
throw new Exception("Response does not match");
}
}
use of javax.smartcardio.ResponseAPDU in project jdk8u_jdk by JetBrains.
the class TestTransmit method main.
public static void main(String[] args) throws Exception {
CardTerminal terminal = getTerminal(args);
if (terminal == null) {
System.out.println("Skipping the test: " + "no card terminals available");
return;
}
Card card = terminal.connect("T=0");
CardChannel channel = card.getBasicChannel();
BufferedReader reader = new BufferedReader(new FileReader("apdu.log"));
byte[] command = null;
while (true) {
String line = reader.readLine();
if (line == null) {
break;
}
if (line.startsWith(CMD_MARKER)) {
System.out.println(line);
line = line.substring(CMD_MARKER.length());
command = parse(line);
} else if (line.startsWith(RES_MARKER)) {
System.out.println(line);
line = line.substring(RES_MARKER.length());
Bytes response = parseWildcard(line);
CommandAPDU capdu = new CommandAPDU(command);
ResponseAPDU rapdu = channel.transmit(capdu);
byte[] received = rapdu.getBytes();
if (received.length != response.bytes.length) {
throw new Exception("Length mismatch: " + toString(received));
}
for (int i = 0; i < received.length; i++) {
byte mask = response.mask[i];
if ((received[i] & response.mask[i]) != response.bytes[i]) {
throw new Exception("Mismatch: " + toString(received));
}
}
}
// else ignore
}
// disconnect
card.disconnect(true);
System.out.println("OK.");
}
use of javax.smartcardio.ResponseAPDU in project javacard-gradle-template by ph4r05.
the class AppletTest method hello.
// Example test
@Test
public void hello() throws Exception {
final ResponseAPDU responseAPDU = SimpleAPDU.demoSingleCommand();
Assert.assertNotNull(responseAPDU);
Assert.assertEquals(0x9000, responseAPDU.getSW());
Assert.assertNotNull(responseAPDU.getBytes());
}
use of javax.smartcardio.ResponseAPDU in project javacard-gradle-template by ph4r05.
the class SimpleAPDU method demoSingleCommand.
public static ResponseAPDU demoSingleCommand() throws Exception {
final CardManager cardMngr = new CardManager(true, APPLET_AID_BYTE);
final RunConfig runCfg = RunConfig.getDefaultConfig();
// Running on physical card
// runCfg.setTestCardType(RunConfig.CARD_TYPE.PHYSICAL);
// Running in the simulator
runCfg.setAppletToSimulate(MainApplet.class).setTestCardType(RunConfig.CARD_TYPE.JCARDSIMLOCAL).setbReuploadApplet(true).setInstallData(new byte[8]);
System.out.print("Connecting to card...");
if (!cardMngr.Connect(runCfg)) {
return null;
}
System.out.println(" Done.");
final ResponseAPDU response = sendCommandWithInitSequence(cardMngr, STR_APDU_DUMMY, null);
System.out.println(response);
return response;
}
use of javax.smartcardio.ResponseAPDU in project open-ecard by ecsec.
the class PCSCTest method PCSCTest.
@Test(enabled = false)
public void PCSCTest() {
connect();
byte[] selectmf = new byte[] { (byte) 0x00, (byte) 0xA4, (byte) 0x00, (byte) 0x0C, (byte) 0x02, (byte) 0x3F, (byte) 0x00 };
try {
logger.info("Send APDU {}", ByteUtils.toHexString(selectmf));
ResponseAPDU response = connection.transmit(new CommandAPDU(selectmf));
logger.info("Receive APDU {}", ByteUtils.toHexString(response.getBytes()));
} catch (CardException ex) {
logger.error(ex.getMessage(), ex);
}
}
Aggregations