Search in sources :

Example 1 with ResponseAPDU

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");
    }
}
Also used : ResponseAPDU(javax.smartcardio.ResponseAPDU) CommandAPDU(javax.smartcardio.CommandAPDU) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException)

Example 2 with ResponseAPDU

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.");
}
Also used : CardChannel(javax.smartcardio.CardChannel) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ResponseAPDU(javax.smartcardio.ResponseAPDU) CardTerminal(javax.smartcardio.CardTerminal) CommandAPDU(javax.smartcardio.CommandAPDU) IOException(java.io.IOException) Card(javax.smartcardio.Card)

Example 3 with ResponseAPDU

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());
}
Also used : ResponseAPDU(javax.smartcardio.ResponseAPDU)

Example 4 with ResponseAPDU

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;
}
Also used : CardManager(cardTools.CardManager) MainApplet(applet.MainApplet) ResponseAPDU(javax.smartcardio.ResponseAPDU) RunConfig(cardTools.RunConfig)

Example 5 with ResponseAPDU

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);
    }
}
Also used : ResponseAPDU(javax.smartcardio.ResponseAPDU) CardException(javax.smartcardio.CardException) CommandAPDU(javax.smartcardio.CommandAPDU) Test(org.testng.annotations.Test)

Aggregations

ResponseAPDU (javax.smartcardio.ResponseAPDU)6 CommandAPDU (javax.smartcardio.CommandAPDU)4 IOException (java.io.IOException)2 CardException (javax.smartcardio.CardException)2 MainApplet (applet.MainApplet)1 CardManager (cardTools.CardManager)1 RunConfig (cardTools.RunConfig)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Card (javax.smartcardio.Card)1 CardChannel (javax.smartcardio.CardChannel)1 CardTerminal (javax.smartcardio.CardTerminal)1 CardCommandAPDU (org.openecard.common.apdu.common.CardCommandAPDU)1 CardResponseAPDU (org.openecard.common.apdu.common.CardResponseAPDU)1 SCIOException (org.openecard.common.ifd.scio.SCIOException)1 Test (org.testng.annotations.Test)1