X-Git-Url: http://www.average.org/gitweb/?p=YkNeoCR.git;a=blobdiff_plain;f=src%2Forg%2Faverage%2Fnfcauthcr%2FYkNeo.java;h=39c760b795ad4d887ff48d2d3e0865444ee6c1c9;hp=1537459ba7e7c6ef4513370a844fc8b234194e07;hb=08b05b67a65e78e80fb0fffec8855a69a72ebff9;hpb=28b4d52dc728ff9016890ff3630d1237f1f2650b diff --git a/src/org/average/nfcauthcr/YkNeo.java b/src/org/average/nfcauthcr/YkNeo.java index 1537459..39c760b 100644 --- a/src/org/average/nfcauthcr/YkNeo.java +++ b/src/org/average/nfcauthcr/YkNeo.java @@ -1,5 +1,6 @@ package org.average.nfcauthcr; +import java.lang.String; import java.io.IOException; import java.util.Arrays; @@ -23,17 +24,17 @@ public class YkNeo { private static final byte SLOT_CHAL_HMAC1 = 0x30; private static final byte SLOT_CHAL_HMAC2 = 0x38; - public static final byte[] doChallengeYubiKey(IsoDep isoTag, int slot, - byte[] challenge) - throws CRException { + public static byte[] doChalResp(IsoDep isoTag, int slot, + byte[] challenge) throws CRException { try { isoTag.connect(); byte[] resp = isoTag.transceive(selectApdu); int length = resp.length; if (resp[length - 2] != (byte)0x90 || resp[length - 1] != 0x00) { - throw new CRException( - "NFC Error code in the response to select"); + throw new CRException(String.format( + "NFC select error code: %02x:%02x", + resp[length - 2], resp[length - 1])); } byte[] crApdu = new byte[69]; crApdu[0] = 0x00; // CLA @@ -51,14 +52,20 @@ public class YkNeo { length = resp.length; if (resp[length - 2] != (byte)0x90 || resp[length - 1] != 0x00) { - throw new CRException( - "NFC Error code in the response to CR"); + throw new CRException(String.format( + "NFC CR error code: %02x:%02x", + resp[length - 2], resp[length - 1])); + } + if (length != 22) { + throw new CRException(String.format( + "NFC wrong response size: got %d, need 20", + length-2)); } return Arrays.copyOf(resp, length-2); } catch (TagLostException e) { throw new CRException("NFC connection lost", e); } catch (IOException e) { - throw new CRException("NFC I/O error", e); + throw new CRException("NFC I/O: " + e.getMessage(), e); } } }