-
- 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 (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, QueryCrToken.class);
- crIntent.putExtra("challenge", challenge);
- waitingForResult = true;
- this.startActivityForResult(crIntent, 0);
- }
-
- 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();
- }