X-Git-Url: http://www.average.org/gitweb/?p=YkNeoCR.git;a=blobdiff_plain;f=src%2Forg%2Faverage%2Fnfcauthcr%2FYkNeo.java;h=96f3e0fbb53b776a02444b17f07c8608ca80935f;hp=864e7b07d9bf5a58cf757a490545fedad46f76ac;hb=edfc8d9f2aad0bd7c0810d9f67a67e3db4b266c0;hpb=3930ad3656ed5ef6a86c9da684733449a591bbc2 diff --git a/src/org/average/nfcauthcr/YkNeo.java b/src/org/average/nfcauthcr/YkNeo.java index 864e7b0..96f3e0f 100644 --- a/src/org/average/nfcauthcr/YkNeo.java +++ b/src/org/average/nfcauthcr/YkNeo.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.lang.String; import java.util.ArrayList; import java.util.Arrays; +import java.util.Iterator; import android.nfc.NfcAdapter; import android.nfc.Tag; @@ -43,12 +44,6 @@ public class YkNeo { public static ArrayList doChalResp(IsoDep isoTag, int slot, ArrayList cset) throws IOException, CRException { - byte[] challenge = unhex(cset.get(0)); - if (challenge.length > 127) { - throw new CRException(String.format( - "NFC challenge size too big: %d", - challenge.length)); - } if (slot != 1 && slot != 2) { throw new CRException(String.format( "NFC Yubikey slot is %d, can be 1 or 2", @@ -62,33 +57,44 @@ public class YkNeo { "NFC select error code: %02x:%02x", resp[length - 2], resp[length - 1])); } - 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)); - } ArrayList rset = new ArrayList(); - rset.add(hex(Arrays.copyOf(resp, length-2))); + + 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))); + } + return rset; }