From 996a1dbe1cb0fd8754aab7b836df3a94befaa213 Mon Sep 17 00:00:00 2001 From: Thialfihar Date: Wed, 18 Aug 2010 12:26:13 +0000 Subject: [PATCH] integrated key server look-up into decrypt Activity, allowing to touch an unkown signature to import the key Update issue 39 added: Unknown signature, touch to look up key. --- res/layout/decrypt.xml | 3 ++- res/values/strings.xml | 1 + src/org/thialfihar/android/apg/Apg.java | 1 + .../android/apg/DecryptActivity.java | 17 ++++++++++++++ .../thialfihar/android/apg/HkpKeyServer.java | 2 +- .../android/apg/KeyServerQueryActivity.java | 23 ++++++++++++------- .../android/apg/PublicKeyListActivity.java | 2 +- 7 files changed, 38 insertions(+), 11 deletions(-) diff --git a/res/layout/decrypt.xml b/res/layout/decrypt.xml index 2acae3086..8bfa76f01 100644 --- a/res/layout/decrypt.xml +++ b/res/layout/decrypt.xml @@ -144,7 +144,8 @@ android:id="@+id/signature" android:orientation="horizontal" android:layout_height="wrap_content" - android:layout_width="fill_parent"> + android:layout_width="fill_parent" + android:clickable="true"> Note: only subkeys support ElGamal, and for ElGamal the nearest keysize of 1536, 2048, 3072, 4096, or 8192 will be used. Couldn\'t find key %08X. Found %s key(s). + Unknown signature, touch to look up key. diff --git a/src/org/thialfihar/android/apg/Apg.java b/src/org/thialfihar/android/apg/Apg.java index 1561170c2..f1615f6a5 100644 --- a/src/org/thialfihar/android/apg/Apg.java +++ b/src/org/thialfihar/android/apg/Apg.java @@ -116,6 +116,7 @@ public class Apg { public static final String SELECT_SECRET_KEY = "org.thialfihar.android.apg.intent.SELECT_SECRET_KEY"; public static final String IMPORT = "org.thialfihar.android.apg.intent.IMPORT"; public static final String LOOK_UP_KEY_ID = "org.thialfihar.android.apg.intent.LOOK_UP_KEY_ID"; + public static final String LOOK_UP_KEY_ID_AND_RETURN = "org.thialfihar.android.apg.intent.LOOK_UP_KEY_ID_AND_RETURN"; } public static final String EXTRA_TEXT = "text"; diff --git a/src/org/thialfihar/android/apg/DecryptActivity.java b/src/org/thialfihar/android/apg/DecryptActivity.java index a4f4225e5..5b598d725 100644 --- a/src/org/thialfihar/android/apg/DecryptActivity.java +++ b/src/org/thialfihar/android/apg/DecryptActivity.java @@ -28,6 +28,7 @@ import java.util.regex.Matcher; import org.bouncycastle2.jce.provider.BouncyCastleProvider; import org.bouncycastle2.openpgp.PGPException; +import org.bouncycastle2.openpgp.PGPPublicKeyRing; import org.thialfihar.android.apg.provider.DataProvider; import android.app.Dialog; @@ -276,6 +277,21 @@ public class DecryptActivity extends BaseActivity { } mSignatureLayout.setVisibility(View.GONE); + mSignatureLayout.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + if (mSignatureKeyId == 0) { + return; + } + PGPPublicKeyRing key = Apg.getPublicKeyRing(mSignatureKeyId); + if (key != null) { + Intent intent = new Intent(DecryptActivity.this, KeyServerQueryActivity.class); + intent.setAction(Apg.Intent.LOOK_UP_KEY_ID); + intent.putExtra(Apg.EXTRA_KEY_ID, mSignatureKeyId); + startActivity(intent); + } + } + }); mDecryptButton.setOnClickListener(new OnClickListener() { @Override @@ -599,6 +615,7 @@ public class DecryptActivity extends BaseActivity { mSignatureStatusImage.setImageResource(R.drawable.overlay_ok); } else if (data.getBoolean(Apg.EXTRA_SIGNATURE_UNKNOWN)) { mSignatureStatusImage.setImageResource(R.drawable.overlay_error); + Toast.makeText(this, R.string.unknownSignatureKeyTouchToLookUp, Toast.LENGTH_LONG).show(); } else { mSignatureStatusImage.setImageResource(R.drawable.overlay_error); } diff --git a/src/org/thialfihar/android/apg/HkpKeyServer.java b/src/org/thialfihar/android/apg/HkpKeyServer.java index d4e73809b..6890e65bc 100644 --- a/src/org/thialfihar/android/apg/HkpKeyServer.java +++ b/src/org/thialfihar/android/apg/HkpKeyServer.java @@ -82,7 +82,7 @@ public class HkpKeyServer extends KeyServer { } catch (UnknownHostException e) { throw new QueryException(e.toString()); } - for (int i = 5; i < ips.length; ++i) { + for (int i = 0; i < ips.length; ++i) { try { String url = "http://" + ips[i].getHostAddress() + ":" + mPort + request; URL realUrl = new URL(url); diff --git a/src/org/thialfihar/android/apg/KeyServerQueryActivity.java b/src/org/thialfihar/android/apg/KeyServerQueryActivity.java index 4ae171266..c6b5a3865 100644 --- a/src/org/thialfihar/android/apg/KeyServerQueryActivity.java +++ b/src/org/thialfihar/android/apg/KeyServerQueryActivity.java @@ -86,7 +86,8 @@ public class KeyServerQueryActivity extends BaseActivity { }); Intent intent = getIntent(); - if (Apg.Intent.LOOK_UP_KEY_ID.equals(intent.getAction())) { + if (Apg.Intent.LOOK_UP_KEY_ID.equals(intent.getAction()) || + Apg.Intent.LOOK_UP_KEY_ID_AND_RETURN.equals(intent.getAction())) { long keyId = intent.getLongExtra(Apg.EXTRA_KEY_ID, 0); if (keyId != 0) { String query = "0x" + Apg.keyToHex(keyId); @@ -168,15 +169,21 @@ public class KeyServerQueryActivity extends BaseActivity { mAdapter.setKeys(mSearchResult); } } else if (mQueryType == Id.query.get) { - if (mKeyData != null) { - Intent intent = new Intent(this, PublicKeyListActivity.class); - intent.setAction(Apg.Intent.IMPORT); - intent.putExtra(Apg.EXTRA_TEXT, mKeyData); - Intent orgIntent = getIntent(); - if (Apg.Intent.LOOK_UP_KEY_ID.equals(orgIntent.getAction())) { + Intent orgIntent = getIntent(); + if (Apg.Intent.LOOK_UP_KEY_ID_AND_RETURN.equals(orgIntent.getAction())) { + if (mKeyData != null) { + Intent intent = new Intent(); + intent.putExtra(Apg.EXTRA_TEXT, mKeyData); setResult(RESULT_OK, intent); - finish(); } else { + setResult(RESULT_CANCELED); + } + finish(); + } else { + if (mKeyData != null) { + Intent intent = new Intent(this, PublicKeyListActivity.class); + intent.setAction(Apg.Intent.IMPORT); + intent.putExtra(Apg.EXTRA_TEXT, mKeyData); startActivity(intent); } } diff --git a/src/org/thialfihar/android/apg/PublicKeyListActivity.java b/src/org/thialfihar/android/apg/PublicKeyListActivity.java index 70e9c44af..4cc3b4df9 100644 --- a/src/org/thialfihar/android/apg/PublicKeyListActivity.java +++ b/src/org/thialfihar/android/apg/PublicKeyListActivity.java @@ -91,7 +91,7 @@ public class PublicKeyListActivity extends KeyListActivity { } Intent intent = new Intent(this, KeyServerQueryActivity.class); - intent.setAction(Apg.Intent.LOOK_UP_KEY_ID); + intent.setAction(Apg.Intent.LOOK_UP_KEY_ID_AND_RETURN); intent.putExtra(Apg.EXTRA_KEY_ID, keyId); startActivityForResult(intent, Id.request.look_up_key_id); return true;