X-Git-Url: http://www.average.org/gitweb/?p=YkNeoCR.git;a=blobdiff_plain;f=src%2Forg%2Faverage%2Fnfcauthcr%2FYkNeo.java;h=39c760b795ad4d887ff48d2d3e0865444ee6c1c9;hp=a291eabe1a4f4131a2764bb880916bba31e05b9f;hb=08b05b67a65e78e80fb0fffec8855a69a72ebff9;hpb=a0d60dab1717e69b6d853eb91d0065fe378e3c28 diff --git a/src/org/average/nfcauthcr/YkNeo.java b/src/org/average/nfcauthcr/YkNeo.java index a291eab..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; @@ -7,7 +8,8 @@ import android.nfc.NfcAdapter; import android.nfc.Tag; import android.nfc.TagLostException; import android.nfc.tech.IsoDep; -//import android.util.Log; + +import org.average.nfcauthcr.CRException; public class YkNeo { @@ -22,19 +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) { + public static byte[] doChalResp(IsoDep isoTag, int slot, + byte[] challenge) throws CRException { try { isoTag.connect(); byte[] resp = isoTag.transceive(selectApdu); int length = resp.length; - //Log.v(TAG, "response to select length is " + length); if (resp[length - 2] != (byte)0x90 || resp[length - 1] != 0x00) { - //Log.v(TAG, "Wrong response to select"); - //Toast.makeText(this, R.string.tag_error, - // Toast.LENGTH_LONG).show(); - return null; + 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 @@ -52,24 +52,20 @@ public class YkNeo { length = resp.length; if (resp[length - 2] != (byte)0x90 || resp[length - 1] != 0x00) { - //Log.v(TAG, "Wrong response to challenge"); - //Toast.makeText(this, R.string.tag_error, - // Toast.LENGTH_LONG).show(); - return null; + 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)); } - //Log.v(TAG, "response to challenge length is " + length); return Arrays.copyOf(resp, length-2); } catch (TagLostException e) { - //Log.v(TAG, e.getMessage()); - //Toast.makeText(this, - // R.string.tag_lost, Toast.LENGTH_LONG).show(); + throw new CRException("NFC connection lost", e); } catch (IOException e) { - //Log.v(TAG, e.getMessage()); - //Toast.makeText(this, - // getText(R.string.tag_error) + - // e.getMessage(), - // Toast.LENGTH_LONG).show(); + throw new CRException("NFC I/O: " + e.getMessage(), e); } - return null; } }