]> www.average.org Git - YkNeoCR.git/blobdiff - src/org/average/nfcauthcr/YkNeo.java
reorg, separate roles
[YkNeoCR.git] / src / org / average / nfcauthcr / YkNeo.java
index 1537459ba7e7c6ef4513370a844fc8b234194e07..39c760b795ad4d887ff48d2d3e0865444ee6c1c9 100644 (file)
@@ -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);
                }
        }
 }