1 package org.average.nfcauthcr;
3 import java.io.IOException;
4 import java.util.Arrays;
6 import android.nfc.NfcAdapter;
7 import android.nfc.Tag;
8 import android.nfc.TagLostException;
9 import android.nfc.tech.IsoDep;
10 import android.util.Log;
12 import org.average.nfcauthcr.NFCAuthCRYubiNeo;
14 public class NFCAuthCRYubiNeo {
16 private static final String TAG = "NFCAuthCRYubiNeo";
18 // Is it CCID APDU? ISO 7816-4?
20 // 00 A4 04 00 xx AID - GlobalPlatform - SELECT
21 // Le send data = 07: A0 00 00 05 27 20 01
23 private static final byte[] selectCommand =
24 {0x00, (byte) 0xA4, 0x04, 0x00, 0x07, (byte) 0xA0,
25 0x00, 0x00, 0x05, 0x27, 0x20, 0x01, 0x00};
27 private static final byte[] crCommand =
28 {0x00, 0x01, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00};
30 private static final byte SLOT_CHAL_HMAC1 = 0x30;
31 private static final byte SLOT_CHAL_HMAC2 = 0x38;
33 public static final byte[] doChallengeYubiKey(IsoDep isoTag, int slot,
37 byte[] resp = isoTag.transceive(selectCommand);
38 int length = resp.length;
39 Log.v(TAG, "response to select length is " + length);
40 if (resp[length - 2] != (byte)0x90 ||
41 resp[length - 1] != 0x00) {
42 Log.v(TAG, "Wrong response to select");
43 //Toast.makeText(this, R.string.tag_error,
44 // Toast.LENGTH_LONG).show();
47 byte[] apdu = new byte[69];
48 apdu[0] = 0x00; // CLA
49 apdu[1] = 0x01; // INS
51 case 1: apdu[2] = SLOT_CHAL_HMAC1; break; // P1
52 case 2: apdu[2] = SLOT_CHAL_HMAC2; break; // P1
56 System.arraycopy(challenge, 0, apdu, 5,
58 apdu[apdu.length-1] = 22;
59 resp = isoTag.transceive(apdu);
61 if (resp[length - 2] != (byte)0x90 ||
62 resp[length - 1] != 0x00) {
63 Log.v(TAG, "Wrong response to challenge");
64 //Toast.makeText(this, R.string.tag_error,
65 // Toast.LENGTH_LONG).show();
68 Log.v(TAG, "response to challenge length is " + length);
69 return Arrays.copyOf(resp, length-2);
70 } catch (TagLostException e) {
71 Log.v(TAG, e.getMessage());
72 //Toast.makeText(this,
73 // R.string.tag_lost, Toast.LENGTH_LONG).show();
74 } catch (IOException e) {
75 Log.v(TAG, e.getMessage());
76 //Toast.makeText(this,
77 // getText(R.string.tag_error) +
79 // Toast.LENGTH_LONG).show();