X-Git-Url: http://www.average.org/gitweb/?p=YkNeoCR.git;a=blobdiff_plain;f=src%2Forg%2Faverage%2Fnfcauthcr%2FNFCAuthCRCheck.java;h=ea37128d65ed936f8dda42c0079809ed7318392f;hp=6637c00164221415b39f0a8c99624c23ef6341bd;hb=bdfe828f712fa2a187a424923c6594f12e965a5d;hpb=16a341cff772b8d413af1d95a21e181a5b4879ff diff --git a/src/org/average/nfcauthcr/NFCAuthCRCheck.java b/src/org/average/nfcauthcr/NFCAuthCRCheck.java index 6637c00..ea37128 100644 --- a/src/org/average/nfcauthcr/NFCAuthCRCheck.java +++ b/src/org/average/nfcauthcr/NFCAuthCRCheck.java @@ -1,8 +1,5 @@ package org.average.nfcauthcr; -import java.io.IOException; - -import android.os.Bundle; import android.app.Activity; import android.app.AlertDialog; import android.app.PendingIntent; @@ -16,14 +13,12 @@ import android.nfc.tech.IsoDep; import android.util.Log; import android.widget.Toast; +import org.average.nfcauthcr.NFCAuthCRYubiNeo; + public class NFCAuthCRCheck extends Activity { private final String TAG = getClass().getName(); - private static final byte[] selectCommand = - {0x00, (byte) 0xA4, 0x04, 0x00, 0x07, (byte) 0xA0, - 0x00, 0x00, 0x05, 0x27, 0x20, 0x01, 0x00}; - private AlertDialog swipeDialog; private PendingIntent tagIntent; @@ -33,19 +28,16 @@ public class NFCAuthCRCheck extends Activity { Log.v(TAG, "Starting the work"); Intent intent = getIntent(); - Bundle extras = intent.getExtras(); setResult(RESULT_CANCELED); - if(swipeDialog != null) { + if (swipeDialog != null) { swipeDialog.dismiss(); swipeDialog = null; } - if(extras != null) { - int slot = extras.getInt("slot"); - if (slot > 0) { - swipeDialog = makeDialog(); - swipeDialog.show(); - enableDispatch(slot); - } + int slot = intent.getIntExtra("slot", -1); + if (slot > 0) { + swipeDialog = makeDialog(); + swipeDialog.show(); + enableDispatch(slot); } } @@ -64,29 +56,17 @@ public class NFCAuthCRCheck extends Activity { public void onNewIntent(Intent intent) { Log.v(TAG, "NFC Intent arrived"); int slot = intent.getIntExtra("slot", -1); + byte[] challenge = intent.getByteArrayExtra("challenge"); if (slot <= 0) return; Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); if (tag == null) return; IsoDep isoTag = IsoDep.get(tag); - try { - isoTag.connect(); - byte[] resp = isoTag.transceive(selectCommand); - int length = resp.length; - if (resp[length - 2] == (byte)0x90 && - resp[length - 1] == 0x00) { - doChallengeYubiKey(isoTag, slot); - } else { - Toast.makeText(this, R.string.tag_error, - Toast.LENGTH_LONG).show(); - } - } catch (TagLostException e) { - Toast.makeText(this, - R.string.tag_lost, Toast.LENGTH_LONG).show(); - } catch (IOException e) { - Toast.makeText(this, - getText(R.string.tag_error) + - e.getMessage(), - Toast.LENGTH_LONG).show(); + byte[] response = NFCAuthCRYubiNeo.doChallengeYubiKey( + isoTag, slot, challenge); + if (response != null) { + Intent data = getIntent(); + data.putExtra("response", response); + setResult(RESULT_OK, data); } finish(); } @@ -139,11 +119,4 @@ public class NFCAuthCRCheck extends Activity { adapter.disableForegroundDispatch(this); } } - - private void doChallengeYubiKey(IsoDep isoTag, int slot) - throws IOException { - Intent data = getIntent(); - data.putExtra("response","real data here"); - setResult(RESULT_OK, data); - } }