diff options
Diffstat (limited to 'org_apg/src/org/thialfihar/android/apg/ui/ImportFromQRCodeActivity.java')
-rw-r--r-- | org_apg/src/org/thialfihar/android/apg/ui/ImportFromQRCodeActivity.java | 148 |
1 files changed, 81 insertions, 67 deletions
diff --git a/org_apg/src/org/thialfihar/android/apg/ui/ImportFromQRCodeActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/ImportFromQRCodeActivity.java index 5d70e6924..0b751f66c 100644 --- a/org_apg/src/org/thialfihar/android/apg/ui/ImportFromQRCodeActivity.java +++ b/org_apg/src/org/thialfihar/android/apg/ui/ImportFromQRCodeActivity.java @@ -33,6 +33,8 @@ import android.content.Intent; import android.os.Bundle; import android.os.Message; import org.thialfihar.android.apg.util.Log; + +import android.widget.TextView; import android.widget.Toast; import com.google.zxing.integration.android.IntentIntegrator; @@ -61,86 +63,98 @@ public class ImportFromQRCodeActivity extends BaseActivity { new IntentIntegrator(this).initiateScan(); } + // private void importAndSignOld(final long keyId, final String expectedFingerprint) { + // if (expectedFingerprint != null && expectedFingerprint.length() > 0) { + // + // Thread t = new Thread() { + // @Override + // public void run() { + // try { + // // TODO: display some sort of spinner here while the user waits + // + // // TODO: there should be only 1 + // HkpKeyServer server = new HkpKeyServer(mPreferences.getKeyServers()[0]); + // String encodedKey = server.get(keyId); + // + // PGPKeyRing keyring = PGPHelper.decodeKeyRing(new ByteArrayInputStream( + // encodedKey.getBytes())); + // if (keyring != null && keyring instanceof PGPPublicKeyRing) { + // PGPPublicKeyRing publicKeyRing = (PGPPublicKeyRing) keyring; + // + // // make sure the fingerprints match before we cache this thing + // String actualFingerprint = PGPHelper.convertToHex(publicKeyRing + // .getPublicKey().getFingerprint()); + // if (expectedFingerprint.equals(actualFingerprint)) { + // // store the signed key in our local cache + // int retval = PGPMain.storeKeyRingInCache(publicKeyRing); + // if (retval != Id.return_value.ok + // && retval != Id.return_value.updated) { + // status.putString(EXTRA_ERROR, + // "Failed to store signed key in local cache"); + // } else { + // Intent intent = new Intent(ImportFromQRCodeActivity.this, + // SignKeyActivity.class); + // intent.putExtra(EXTRA_KEY_ID, keyId); + // startActivityForResult(intent, Id.request.sign_key); + // } + // } else { + // status.putString( + // EXTRA_ERROR, + // "Scanned fingerprint does NOT match the fingerprint of the received key. You shouldnt trust this key."); + // } + // } + // } catch (QueryException e) { + // Log.e(TAG, "Failed to query KeyServer", e); + // status.putString(EXTRA_ERROR, "Failed to query KeyServer"); + // status.putInt(Constants.extras.STATUS, Id.message.done); + // } catch (IOException e) { + // Log.e(TAG, "Failed to query KeyServer", e); + // status.putString(EXTRA_ERROR, "Failed to query KeyServer"); + // status.putInt(Constants.extras.STATUS, Id.message.done); + // } + // } + // }; + // + // t.setName("KeyExchange Download Thread"); + // t.setDaemon(true); + // t.start(); + // } + // } + private void importAndSign(final long keyId, final String expectedFingerprint) { - if (expectedFingerprint != null && expectedFingerprint.length() > 0) { - - Thread t = new Thread() { - @Override - public void run() { - try { - // TODO: display some sort of spinner here while the user waits - - // TODO: there should be only 1 - HkpKeyServer server = new HkpKeyServer(mPreferences.getKeyServers()[0]); - String encodedKey = server.get(keyId); - - PGPKeyRing keyring = PGPHelper.decodeKeyRing(new ByteArrayInputStream( - encodedKey.getBytes())); - if (keyring != null && keyring instanceof PGPPublicKeyRing) { - PGPPublicKeyRing publicKeyRing = (PGPPublicKeyRing) keyring; - - // make sure the fingerprints match before we cache this thing - String actualFingerprint = PGPHelper.convertToHex(publicKeyRing - .getPublicKey().getFingerprint()); - if (expectedFingerprint.equals(actualFingerprint)) { - // store the signed key in our local cache - int retval = PGPMain.storeKeyRingInCache(publicKeyRing); - if (retval != Id.return_value.ok - && retval != Id.return_value.updated) { - status.putString(EXTRA_ERROR, - "Failed to store signed key in local cache"); - } else { - Intent intent = new Intent(ImportFromQRCodeActivity.this, - SignKeyActivity.class); - intent.putExtra(EXTRA_KEY_ID, keyId); - startActivityForResult(intent, Id.request.sign_key); - } - } else { - status.putString( - EXTRA_ERROR, - "Scanned fingerprint does NOT match the fingerprint of the received key. You shouldnt trust this key."); - } - } - } catch (QueryException e) { - Log.e(TAG, "Failed to query KeyServer", e); - status.putString(EXTRA_ERROR, "Failed to query KeyServer"); - status.putInt(Constants.extras.STATUS, Id.message.done); - } catch (IOException e) { - Log.e(TAG, "Failed to query KeyServer", e); - status.putString(EXTRA_ERROR, "Failed to query KeyServer"); - status.putInt(Constants.extras.STATUS, Id.message.done); - } - } - }; - - t.setName("KeyExchange Download Thread"); - t.setDaemon(true); - t.start(); - } + + // setContentView(R.layout.import_from_qr_code); + } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case IntentIntegrator.REQUEST_CODE: { - boolean debug = true; // TODO: remove this!!! IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); - if (debug || (scanResult != null && scanResult.getFormatName() != null)) { - String[] bits = debug ? new String[] { "5993515643896327656", - "0816 F68A 6816 68FB 01BF 2CA5 532D 3EB9 1E2F EDE8" } : scanResult - .getContents().split(","); - if (bits.length != 2) { - return; // dont know how to handle this. Not a valid code - } + if (scanResult != null && scanResult.getFormatName() != null) { - long keyId = Long.parseLong(bits[0]); - String expectedFingerprint = bits[1]; + // show layout + setContentView(R.layout.import_from_qr_code); + TextView contentView = (TextView) findViewById(R.id.import_from_qr_code_content); - importAndSign(keyId, expectedFingerprint); + String content = scanResult.getContents(); + + contentView.setText(content); + // String[] bits = scanResult.getContents().split(","); + // if (bits.length != 2) { + // return; // dont know how to handle this. Not a valid code + // } + // + // long keyId = Long.parseLong(bits[0]); + // String expectedFingerprint = bits[1]; + + // importAndSign(keyId, expectedFingerprint); - break; } + + break; } case Id.request.sign_key: { |