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;
14 // This is a CCID APDU, ISO 7816-4.
15 // 00 A4 04 00 xx AID - GlobalPlatform - SELECT
16 // Lc, send data = 07: A0 00 00 05 27 20 01
18 private static final byte[] selectApdu =
19 {0x00, (byte) 0xA4, 0x04, 0x00, 0x07, (byte) 0xA0,
20 0x00, 0x00, 0x05, 0x27, 0x20, 0x01, 0x00};
22 private static final byte SLOT_CHAL_HMAC1 = 0x30;
23 private static final byte SLOT_CHAL_HMAC2 = 0x38;
25 public static final byte[] doChallengeYubiKey(IsoDep isoTag, int slot,
29 byte[] resp = isoTag.transceive(selectApdu);
30 int length = resp.length;
31 //Log.v(TAG, "response to select length is " + length);
32 if (resp[length - 2] != (byte)0x90 ||
33 resp[length - 1] != 0x00) {
34 //Log.v(TAG, "Wrong response to select");
35 //Toast.makeText(this, R.string.tag_error,
36 // Toast.LENGTH_LONG).show();
39 byte[] crApdu = new byte[69];
40 crApdu[0] = 0x00; // CLA
41 crApdu[1] = 0x01; // INS
43 case 1: crApdu[2] = SLOT_CHAL_HMAC1; break; // P1
44 case 2: crApdu[2] = SLOT_CHAL_HMAC2; break; // P1
46 crApdu[3] = 0x00; // P2
48 System.arraycopy(challenge, 0, crApdu, 5,
49 challenge.length); // Payload
50 crApdu[crApdu.length-1] = 22; // Le
51 resp = isoTag.transceive(crApdu);
53 if (resp[length - 2] != (byte)0x90 ||
54 resp[length - 1] != 0x00) {
55 //Log.v(TAG, "Wrong response to challenge");
56 //Toast.makeText(this, R.string.tag_error,
57 // Toast.LENGTH_LONG).show();
60 //Log.v(TAG, "response to challenge length is " + length);
61 return Arrays.copyOf(resp, length-2);
62 } catch (TagLostException e) {
63 //Log.v(TAG, e.getMessage());
64 //Toast.makeText(this,
65 // R.string.tag_lost, Toast.LENGTH_LONG).show();
66 } catch (IOException e) {
67 //Log.v(TAG, e.getMessage());
68 //Toast.makeText(this,
69 // getText(R.string.tag_error) +
71 // Toast.LENGTH_LONG).show();