Java Code Examples for javax.smartcardio.CardChannel#transmit()

The following examples show how to use javax.smartcardio.CardChannel#transmit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example 2
Source File: Utils.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example 3
Source File: Utils.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example 4
Source File: Utils.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example 5
Source File: Utils.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example 6
Source File: Utils.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example 7
Source File: Utils.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example 8
Source File: Utils.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example 9
Source File: PCSCUtils.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private static ResponseAPDU transmit(CommandAPDU commandApdu) throws CardException {
   TerminalFactory factory = TerminalFactory.getDefault();
   List<CardTerminal> terminals = factory.terminals().list();
   LOG.debug("Terminals: " + terminals);
   Card card = null;
   Iterator i$ = terminals.iterator();

   while(i$.hasNext()) {
      CardTerminal terminal = (CardTerminal)i$.next();
      if (terminal.isCardPresent()) {
         card = terminal.connect("*");
         if (card != null && matchesEidAtr(card.getATR())) {
            break;
         }
      }
   }

   if (card == null) {
      throw new CardNotPresentException("EID is not present");
   } else {
      card.beginExclusive();
      LOG.debug("card: " + card);
      CardChannel cardChannel = card.getBasicChannel();
      ResponseAPDU responseApdu = cardChannel.transmit(commandApdu);
      if (108 == responseApdu.getSW1()) {
         LOG.debug("sleeping...");

         try {
            Thread.sleep(10L);
         } catch (InterruptedException var7) {
            throw new be.ehealth.technicalconnector.exception.InterruptedException("Cannot sleep", var7);
         }

         responseApdu = cardChannel.transmit(commandApdu);
      }

      card.endExclusive();
      card.disconnect(false);
      return responseApdu;
   }
}
 
Example 10
Source File: PCSCUtils.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private static ResponseAPDU transmit(CommandAPDU commandApdu) throws CardException {
   TerminalFactory factory = TerminalFactory.getDefault();
   List<CardTerminal> terminals = factory.terminals().list();
   LOG.debug("Terminals: " + terminals);
   Card card = null;
   Iterator i$ = terminals.iterator();

   while(i$.hasNext()) {
      CardTerminal terminal = (CardTerminal)i$.next();
      if (terminal.isCardPresent()) {
         card = terminal.connect("*");
         if (card != null && matchesEidAtr(card.getATR())) {
            break;
         }
      }
   }

   if (card == null) {
      throw new CardNotPresentException("EID is not present");
   } else {
      card.beginExclusive();
      LOG.debug("card: " + card);
      CardChannel cardChannel = card.getBasicChannel();
      ResponseAPDU responseApdu = cardChannel.transmit(commandApdu);
      if (108 == responseApdu.getSW1()) {
         LOG.debug("sleeping...");

         try {
            Thread.sleep(10L);
         } catch (InterruptedException var7) {
            throw new be.ehealth.technicalconnector.exception.InterruptedException("Cannot sleep", var7);
         }

         responseApdu = cardChannel.transmit(commandApdu);
      }

      card.endExclusive();
      card.disconnect(false);
      return responseApdu;
   }
}
 
Example 11
Source File: TestTransmit.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    CardTerminal terminal = getTerminal(args);

    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.");
}
 
Example 12
Source File: TestTransmit.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    CardTerminal terminal = getTerminal(args);

    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.");
}
 
Example 13
Source File: TestTransmit.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    CardTerminal terminal = getTerminal(args);

    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.");
}
 
Example 14
Source File: TestTransmit.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    CardTerminal terminal = getTerminal(args);

    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.");
}
 
Example 15
Source File: PCSCUtils.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private static ResponseAPDU transmit(CommandAPDU commandApdu) throws CardException {
   TerminalFactory factory = TerminalFactory.getDefault();
   List<CardTerminal> terminals = factory.terminals().list();
   LOG.debug("Terminals: " + terminals);
   Card card = null;
   Iterator i$ = terminals.iterator();

   while(i$.hasNext()) {
      CardTerminal terminal = (CardTerminal)i$.next();
      if (terminal.isCardPresent()) {
         card = terminal.connect("*");
         if (card != null && matchesEidAtr(card.getATR())) {
            break;
         }
      }
   }

   if (card == null) {
      throw new CardNotPresentException("EID is not present");
   } else {
      card.beginExclusive();
      LOG.debug("card: " + card);
      CardChannel cardChannel = card.getBasicChannel();
      ResponseAPDU responseApdu = cardChannel.transmit(commandApdu);
      if (108 == responseApdu.getSW1()) {
         LOG.debug("sleeping...");

         try {
            Thread.sleep(10L);
         } catch (InterruptedException var7) {
            throw new be.ehealth.technicalconnector.exception.InterruptedException("Cannot sleep", var7);
         }

         responseApdu = cardChannel.transmit(commandApdu);
      }

      card.endExclusive();
      card.disconnect(false);
      return responseApdu;
   }
}
 
Example 16
Source File: TestTransmit.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
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.");
}
 
Example 17
Source File: TestTransmit.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
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.");
}
 
Example 18
Source File: TestTransmit.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
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.");
}
 
Example 19
Source File: TestTransmit.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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.");
}
 
Example 20
Source File: GenericCard.java    From openjavacard-tools with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * Exchange APDUs on the given channel
 *
 * @param channel to use
 * @param command to execute
 * @return response to command
 * @throws CardException for terminal and card errors
 */
public ResponseAPDU transmit(CardChannel channel, CommandAPDU command) throws CardException {
    LOG.debug("apdu > " + APDUUtil.toString(command));
    ResponseAPDU response = channel.transmit(command);
    LOG.debug("apdu < " + APDUUtil.toString(response));
    return response;
}