+
+ Iterator itr = cset.iterator();
+ while (itr.hasNext()) {
+ byte[] challenge = unhex((String)itr.next());
+ if (challenge.length > 127) {
+ throw new CRException(String.format(
+ "NFC challenge size too big: %d",
+ challenge.length));
+ }
+ byte[] crApdu = new byte[6+challenge.length];
+ crApdu[0] = 0x00; // CLA
+ crApdu[1] = 0x01; // INS
+ switch (slot) {
+ case 1: crApdu[2] = SLOT_CHAL_HMAC1; break; // P1
+ case 2: crApdu[2] = SLOT_CHAL_HMAC2; break; // P1
+ }
+ crApdu[3] = 0x00; // P2
+ crApdu[4] = (byte)challenge.length; // Lc
+ System.arraycopy(challenge, 0, crApdu, 5,
+ challenge.length); // Payload
+ crApdu[5+challenge.length] = 22; // Le
+ resp = isoTag.transceive(crApdu);
+ length = resp.length;
+ if (resp[length - 2] != (byte)0x90 ||
+ resp[length - 1] != 0x00) {
+ throw new CRException(String.format(
+ "NFC CR error code: %02x:%02x",
+ resp[length - 2], resp[length - 1]));
+ }
+ if (length <= 2) {
+ throw new CRException(String.format(
+ "NFC wrong response size: only %d bytes",
+ length-2));
+ }
+ rset.add(hex(Arrays.copyOf(resp, length-2)));
+ }
+