]> www.average.org Git - YkNeoCR.git/blobdiff - src/org/average/nfcauthcr/Enroll.java
handle multivalue challenges
[YkNeoCR.git] / src / org / average / nfcauthcr / Enroll.java
index 8d90488dbc41e34e665aea4e9c84a76b71b93211..3e012d29de524df8834ae1b129c2a025245592a6 100644 (file)
@@ -1,4 +1,4 @@
-package org.average.nfcauthcr;
+package org.average.ykneocr;
 
 import java.util.Random;
 
@@ -10,12 +10,13 @@ import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.Editor;
 import android.content.DialogInterface;
+import android.text.Html;
 import android.util.Log;
 import android.view.View;
 import android.widget.TextView;
 import android.widget.RadioButton;
 
-import org.average.nfcauthcr.Check;
+import org.average.ykneocr.QueryCrToken;
 
 public class Enroll extends Activity {
 
@@ -24,7 +25,6 @@ public class Enroll extends Activity {
        private static boolean waitingForResult = false;
        private static SharedPreferences prefs;
        private static int slot;
-       private AlertDialog swipeDialog;
 
        @Override
        protected void onCreate(Bundle savedInstanceState)
@@ -38,6 +38,8 @@ public class Enroll extends Activity {
        protected void onResume() {
                super.onResume();
                setContentView(R.layout.main);
+               TextView tv = (TextView)findViewById(R.id.info);
+               tv.setText(Html.fromHtml(getString(R.string.info)));
                slot = prefs.getInt("slot_number", -1);
                Log.v(TAG, "found saved slot value " + slot);
                RadioButton btn = null;
@@ -50,19 +52,6 @@ public class Enroll extends Activity {
                if (btn != null) btn.setChecked(true);
        }
 
-       @Override
-       protected void onPause() {
-               super.onPause();
-               Log.v(TAG, "Going inactive, try to stop");
-               if (!waitingForResult) { finish(); }
-       }
-
-       @Override
-       protected void onStop() {
-               super.onStop();
-               Log.v(TAG, "Stop requested");
-       }
-
        public void onSlotSelectionClicked(View view) {
                Log.v(TAG, "Radio Button selected");
                if (! ((RadioButton) view).isChecked()) return;
@@ -75,88 +64,4 @@ public class Enroll extends Activity {
                editor.commit();
                Log.v(TAG, "stored slot number " + slot);
        }
-
-       public void onEnrollClicked(View view) {
-               Log.v(TAG, "Enroll clicked");
-               if (slot > 0) {
-                       runEnrollment(slot);
-               } else {
-                       showEnrollResult(R.string.need_slot);
-               }
-       }
-
-       public void onActivityResult(int requestCode, int resultCode,
-                                       Intent intent) {
-               Log.v(TAG, "Got activity result");
-               waitingForResult = false;
-               if(swipeDialog != null) {
-                       swipeDialog.dismiss();
-                       swipeDialog = null;
-               }
-
-               if (resultCode != RESULT_OK) {
-                       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) + "\"");
-               Editor editor = prefs.edit();
-               editor.putString("challenge", hex(challenge));
-               editor.putString("response", hex(response));
-               editor.commit();
-               showEnrollResult(R.string.enroll_success);
-               Log.v(TAG, "stored new challenge and response");
-       }
-
-       private void showEnrollResult(int messageid) {
-               AlertDialog.Builder builder = new AlertDialog.Builder(this);
-               builder.setTitle(R.string.enrollresult);
-               builder.setMessage(messageid);
-               builder.setPositiveButton(android.R.string.ok,
-                               new DialogInterface.OnClickListener() {
-                       public void onClick(DialogInterface dialog, int which) {
-                               dialog.dismiss();
-                               if (!waitingForResult) { finish(); }
-                       }
-               });
-               AlertDialog dialog = builder.create();
-               dialog.show();
-       }
-
-       private void runEnrollment(int slot) {
-               Random rng = new Random();
-               byte[] challenge = new byte[63];
-               rng.nextBytes(challenge);
-               Log.v(TAG, "Random challenge: " + hex(challenge));
-               Intent crIntent = new Intent(this, Check.class);
-               crIntent.putExtra("slot", slot);
-               crIntent.putExtra("challenge", challenge);
-               this.startActivityForResult(crIntent, 0);
-               waitingForResult = true;
-               if (swipeDialog != null) swipeDialog.dismiss();
-               swipeDialog = makeDialog();
-               swipeDialog.show();
-       }
-
-       private AlertDialog makeDialog() {
-               AlertDialog.Builder builder = new AlertDialog.Builder(this);
-               builder.setTitle(R.string.challenging);
-               builder.setMessage(R.string.swipe);
-               builder.setOnCancelListener(
-                               new DialogInterface.OnCancelListener() {
-                       public void onCancel(DialogInterface dialog) {
-                               Log.v(TAG, "unbind service FIXME");
-                       }
-               });
-               return builder.create();
-       }
-
-       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();
-       }
 }