]> www.average.org Git - YkNeoCR.git/blobdiff - src/org/average/nfcauthcr/NFCAuthCREnroll.java
passing data over
[YkNeoCR.git] / src / org / average / nfcauthcr / NFCAuthCREnroll.java
index bb6b4f0357118db644ce4e7aace211823aa5be34..daea0d848c0bbe42103db9f6841ca48a3542dc57 100644 (file)
@@ -1,5 +1,7 @@
 package org.average.nfcauthcr;
 
 package org.average.nfcauthcr;
 
+import java.util.Random;
+
 import android.os.Bundle;
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.os.Bundle;
 import android.app.Activity;
 import android.app.AlertDialog;
@@ -76,7 +78,7 @@ public class NFCAuthCREnroll extends Activity {
        public void onEnrollClicked(View view) {
                Log.v(TAG, "Enroll clicked");
                if (slot > 0) {
        public void onEnrollClicked(View view) {
                Log.v(TAG, "Enroll clicked");
                if (slot > 0) {
-                       runChallenge(slot);
+                       runEnrollment(slot);
                } else {
                        showEnrollResult("Must specify which slot to use");
                }
                } else {
                        showEnrollResult("Must specify which slot to use");
                }
@@ -86,12 +88,15 @@ public class NFCAuthCREnroll extends Activity {
                                        Intent intent) {
                Log.v(TAG, "Got activity result");
                waitingForResult = false;
                                        Intent intent) {
                Log.v(TAG, "Got activity result");
                waitingForResult = false;
-               if (resultCode == RESULT_OK) {
-                       String res = intent.getStringExtra("response");
-                       Log.v(TAG, "Response is \"" + res + "\"");
-               } else {
+
+               if (resultCode != RESULT_OK) {
                        Log.v(TAG, "Error result code " + resultCode);
                        Log.v(TAG, "Error result code " + resultCode);
+                       return;
                }
                }
+               byte[] challenge = intent.getByteArrayExtra("challenge");
+               Log.v(TAG, "Challenge is \"" + hex(challenge) + "\"");
+               byte[] response = intent.getByteArrayExtra("response");
+               Log.v(TAG, "Response is  \"" + hex(response) + "\"");
        }
 
        private void showEnrollResult(final String msg) {
        }
 
        private void showEnrollResult(final String msg) {
@@ -111,11 +116,23 @@ public class NFCAuthCREnroll extends Activity {
                dialog.show();
        }
 
                dialog.show();
        }
 
-       private void runChallenge(int slot) {
+       private void runEnrollment(int slot) {
+               Random rng = new Random();
+               byte[] challenge = new byte[63];
+               rng.nextBytes(challenge);
+               Log.v(TAG, "Random challenge: " + hex(challenge));
                Log.v(TAG, "Launching challenging activity");
                Intent crIntent = new Intent(this, NFCAuthCRCheck.class);
                crIntent.putExtra("slot", slot);
                Log.v(TAG, "Launching challenging activity");
                Intent crIntent = new Intent(this, NFCAuthCRCheck.class);
                crIntent.putExtra("slot", slot);
+               crIntent.putExtra("challenge", challenge);
                this.startActivityForResult(crIntent, 0);
                waitingForResult = true;
        }
                this.startActivityForResult(crIntent, 0);
                waitingForResult = true;
        }
+
+       private String hex(byte[] a) {
+               StringBuilder sb = new StringBuilder();
+               if (a == null) return "<null>";
+               for (byte b: a) sb.append(String.format("%02x", b&0xff));
+               return sb.toString();
+       }
 }
 }