Example usage for javax.smartcardio ResponseAPDU ResponseAPDU

List of usage examples for javax.smartcardio ResponseAPDU ResponseAPDU

Introduction

In this page you can find the example usage for javax.smartcardio ResponseAPDU ResponseAPDU.

Prototype

public ResponseAPDU(byte[] apdu) 

Source Link

Document

Constructs a ResponseAPDU from a byte array containing the complete APDU contents (conditional body and trailed).

Usage

From source file:test.be.fedict.eid.applet.PcscTest.java

@Test
public void testCcid() throws Exception {
    PcscEid pcscEid = new PcscEid(new TestView(), this.messages);
    if (false == pcscEid.isEidPresent()) {
        LOG.debug("insert eID card");
        pcscEid.waitForEidPresent();//from  w  ww .  j ava  2s.c  om
    }

    Card card = pcscEid.getCard();
    // GET FEATURE LIST
    byte[] features = card.transmitControlCommand(0x42000D48, new byte[0]);
    if (0 == features.length) {
        LOG.debug("no CCID reader");
        return;
    }
    LOG.debug("feature list: " + new String(Hex.encodeHex(features)));
    LOG.debug("feature verify pin direct: " + hasFeature(FEATURE_VERIFY_PIN_DIRECT_TAG, features));
    Integer verifyPinControl = findFeature(FEATURE_VERIFY_PIN_DIRECT_TAG, features);
    LOG.debug("VERIFY PIN control: 0x" + Integer.toHexString(verifyPinControl));

    CardChannel cardChannel = pcscEid.getCardChannel();
    CommandAPDU setApdu = new CommandAPDU(0x00, 0x22, 0x41, 0xB6, new byte[] { 0x04, // length of following data
            (byte) 0x80, // algo ref
            0x01, // rsa pkcs#1
            (byte) 0x84, // tag for private key ref
            (byte) 0x82 });
    ResponseAPDU responseApdu = cardChannel.transmit(setApdu);
    if (0x9000 != responseApdu.getSW()) {
        throw new RuntimeException("SELECT error");
    }

    byte[] verifyCommandData = createPINVerificationDataStructure();

    byte[] result = card.transmitControlCommand(verifyPinControl, verifyCommandData);
    responseApdu = new ResponseAPDU(result);
    LOG.debug("status work: " + Integer.toHexString(responseApdu.getSW()));
    if (0x9000 == responseApdu.getSW()) {
        LOG.debug("status OK");
    } else if (0x6401 == responseApdu.getSW()) {
        LOG.debug("canceled by user");
    } else if (0x6400 == responseApdu.getSW()) {
        LOG.debug("timeout");
    }
    /*
     * The other SW values are those from the VERIFY APDU itself.
     */
}