Java Code Examples for javax.smartcardio.ResponseAPDU#getBytes()
The following examples show how to use
javax.smartcardio.ResponseAPDU#getBytes() .
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 dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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 |
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 jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
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 jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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 |
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-jdk with GNU General Public License v2.0 | 5 votes |
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: GPSecureChannel.java From openjavacard-tools with GNU Lesser General Public License v3.0 | 5 votes |
/** * Convenience wrapper for sending byte buffers * <p/> * @param command to be packed into the C-APDU * @param response buffer to be filled from R-APDU * @return length of data received (XXX define better!?) * @throws CardException on card-related errors */ @Override public int transmit(ByteBuffer command, ByteBuffer response) throws CardException { CommandAPDU capdu = new CommandAPDU(command); ResponseAPDU rapdu = transmit(capdu); byte[] rapduBytes = rapdu.getBytes(); response.put(rapduBytes); return rapduBytes.length; }
Example 8
Source File: Utils.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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: Utils.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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 10
Source File: TestTransmit.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
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 11
Source File: TestTransmit.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
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 12
Source File: TestTransmit.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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 openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
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 14
Source File: TestTransmit.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
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: TestTransmit.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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 16
Source File: TestTransmit.java From hottub with GNU General Public License v2.0 | 4 votes |
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 17
Source File: TestTransmit.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
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: GidsBaseTestClass.java From GidsApplet with GNU General Public License v3.0 | 4 votes |
protected void authenticateMutual(byte[] key, boolean successexpected) { byte[] myChallenge= new byte [16], globalchallenge = new byte[40], challengeresponse = new byte[40]; byte[] cardChallenge; Cipher cipherDES = Cipher.getInstance(Cipher.ALG_DES_CBC_NOPAD, false); DESKey deskey = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_3KEY, false); deskey.setKey(key, (short) 0); new Random().nextBytes(myChallenge); // select admin key execute("00 22 81 A4 03 83 01 80"); // get a challenge ResponseAPDU response = execute("00 87 00 00 14 7C 12 81 10" + DatatypeConverter.printHexBinary(myChallenge) + "00"); if (!Arrays.equals(Arrays.copyOfRange(response.getBytes(), 0, 4), new byte[] {0x7C,0x12,(byte) 0x81,0x10})) { fail("not a challenge:" + DatatypeConverter.printHexBinary(response.getBytes())); } // compute the response cardChallenge = Arrays.copyOfRange(response.getBytes(), 4, 20); //solve challenge //R2 System.arraycopy(cardChallenge, 0, globalchallenge, 0, 16); //R1 System.arraycopy(myChallenge, 0, globalchallenge, 16, 16); // keep Z1 random globalchallenge[(short)39] = (byte) 0x80; cipherDES.init(deskey, Cipher.MODE_ENCRYPT); cipherDES.doFinal(globalchallenge, (short) 0, (short)40, challengeresponse, (short) 0); // send the response String command = "00 87 00 00 2C 7C 2A 82 28" + DatatypeConverter.printHexBinary(challengeresponse); ResponseAPDU responseAPDU = execute(command, true); if (!successexpected) { if(responseAPDU.getSW() != 0x6982) { fail("expected: " + Integer.toHexString(0x6982) + " but was: " + Integer.toHexString(response.getSW())); } return; } if(responseAPDU.getSW() != 0x9000) { fail("expected: " + Integer.toHexString(0x9000) + " but was: " + Integer.toHexString(response.getSW())); } byte[] cardresponse = responseAPDU.getBytes(); if (!Arrays.equals(Arrays.copyOfRange(cardresponse, 0, 4), new byte[] {0x7C,0x2A,(byte)0x82,0x28})) { fail("header verification failed"); } byte[] decryptedCardResponse = new byte[40]; cipherDES.init(deskey, Cipher.MODE_DECRYPT); cipherDES.doFinal(cardresponse, (short) 4, (short)40, decryptedCardResponse, (short) 0); if (!Arrays.equals(Arrays.copyOfRange(decryptedCardResponse, 0, 16), myChallenge)) { fail("R1 verification failed"); } if (!Arrays.equals(Arrays.copyOfRange(decryptedCardResponse, 16, 32), cardChallenge)) { fail("R2 verification failed"); } if (decryptedCardResponse[(short)39] != (byte) 0x80) { fail("padding failed"); } }
Example 19
Source File: TestTransmit.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
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: TestTransmit.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
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."); }