mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
testing thread-pausing in verifyText()
This commit is contained in:
parent
2e981bf3db
commit
3052ae80d5
@ -42,6 +42,7 @@
|
||||
<string name="title_keyNotFound">Key Not Found</string>
|
||||
<string name="title_help">Getting Started</string>
|
||||
<string name="title_keyServerQuery">Query Key Server</string>
|
||||
<string name="title_unknownSignatureKey">Unknown Signature Key</string>
|
||||
|
||||
<!-- section_lowerCase: capitalized words, no punctuation -->
|
||||
<string name="section_userIds">User IDs</string>
|
||||
@ -211,6 +212,7 @@
|
||||
<string name="unknownSignatureKeyTouchToLookUp">Unknown signature, touch to look up key.</string>
|
||||
<string name="keyEditingIsBeta">Key editing is still kind of beta.</string>
|
||||
<string name="badKeysEncountered">%s bad secret key(s) ignored. Perhaps you exported with the option\n --export-secret-subkeys\nMake sure you export with\n --export-secret-keys\ninstead.</string>
|
||||
<string name="lookupUnknownKey">Unknown key %s, do you want to try finding it on a keyserver?</string>
|
||||
|
||||
<!-- error_lowerCase: phrases, no punctuation, all lowercase,
|
||||
they will be put after "errorMessage", e.g. "Error: file not found" -->
|
||||
|
@ -100,7 +100,7 @@ import android.database.sqlite.SQLiteDatabase;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public class Apg {
|
||||
@ -1717,10 +1717,9 @@ public class Apg {
|
||||
return returnData;
|
||||
}
|
||||
|
||||
public static Bundle verifyText(Context context,
|
||||
public static Bundle verifyText(BaseActivity context,
|
||||
InputData data, OutputStream outStream,
|
||||
ProgressDialogUpdater progress,
|
||||
PausableThread thread, Handler handler)
|
||||
ProgressDialogUpdater progress)
|
||||
throws IOException, GeneralException, PGPException, SignatureException {
|
||||
Bundle returnData = new Bundle();
|
||||
|
||||
@ -1768,6 +1767,19 @@ public class Apg {
|
||||
if (signatureKeyId == 0) {
|
||||
signatureKeyId = signature.getKeyID();
|
||||
}
|
||||
if (signatureKey == null) {
|
||||
Bundle pauseData = new Bundle();
|
||||
pauseData.putInt(Constants.extras.status, Id.message.unknown_signature_key);
|
||||
pauseData.putLong(Constants.extras.key_id, signatureKeyId);
|
||||
Message msg = new Message();
|
||||
msg.setData(pauseData);
|
||||
context.sendMessage(msg);
|
||||
// pause here
|
||||
context.getRunningThread().pause();
|
||||
// see whether the key was found in the meantime
|
||||
signatureKey = getPublicKey(signature.getKeyID());
|
||||
}
|
||||
|
||||
if (signatureKey == null) {
|
||||
signature = null;
|
||||
} else {
|
||||
|
@ -414,10 +414,6 @@ public class BaseActivity extends Activity
|
||||
return mRunningThread;
|
||||
}
|
||||
|
||||
public Handler getHandler() {
|
||||
return mHandler;
|
||||
}
|
||||
|
||||
public void startThread() {
|
||||
mRunningThread = new PausableThread(this);
|
||||
mRunningThread.start();
|
||||
|
@ -46,5 +46,6 @@ public final class Constants {
|
||||
public static final String progress_max = "max";
|
||||
public static final String status = "status";
|
||||
public static final String message = "message";
|
||||
public static final String key_id = "keyId";
|
||||
}
|
||||
}
|
||||
|
@ -31,8 +31,10 @@ import org.bouncycastle2.openpgp.PGPException;
|
||||
import org.bouncycastle2.openpgp.PGPPublicKeyRing;
|
||||
import org.thialfihar.android.apg.provider.DataProvider;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
@ -92,6 +94,8 @@ public class DecryptActivity extends BaseActivity {
|
||||
private DataSource mDataSource = null;
|
||||
private DataDestination mDataDestination = null;
|
||||
|
||||
private long mUnknownSignatureKeyId = 0;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -509,7 +513,7 @@ public class DecryptActivity extends BaseActivity {
|
||||
OutputStream out = mDataDestination.getOutputStream(this);
|
||||
|
||||
if (mSignedOnly) {
|
||||
data = Apg.verifyText(this, in, out, this, getRunningThread(), getHandler());
|
||||
data = Apg.verifyText(this, in, out, this);
|
||||
} else {
|
||||
data = Apg.decrypt(this, in, out, Apg.getCachedPassPhrase(getSecretKeyId()),
|
||||
this, mAssumeSymmetricEncryption);
|
||||
@ -549,6 +553,7 @@ public class DecryptActivity extends BaseActivity {
|
||||
sendMessage(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerCallback(Message msg) {
|
||||
Bundle data = msg.getData();
|
||||
if (data == null) {
|
||||
@ -556,7 +561,9 @@ public class DecryptActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
if (data.getInt(Constants.extras.status) == Id.message.unknown_signature_key) {
|
||||
|
||||
mUnknownSignatureKeyId = data.getLong(Constants.extras.key_id);
|
||||
showDialog(Id.dialog.lookup_unknown_key);
|
||||
return;
|
||||
}
|
||||
|
||||
super.handlerCallback(msg);
|
||||
@ -673,6 +680,14 @@ public class DecryptActivity extends BaseActivity {
|
||||
return;
|
||||
}
|
||||
|
||||
case Id.request.look_up_key_id: {
|
||||
PausableThread thread = getRunningThread();
|
||||
if (thread != null && thread.isPaused()) {
|
||||
thread.unpause();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
@ -707,6 +722,39 @@ public class DecryptActivity extends BaseActivity {
|
||||
Id.request.output_filename);
|
||||
}
|
||||
|
||||
case Id.dialog.lookup_unknown_key: {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
||||
|
||||
alert.setIcon(android.R.drawable.ic_dialog_alert);
|
||||
alert.setTitle(R.string.title_unknownSignatureKey);
|
||||
alert.setMessage(getString(R.string.lookupUnknownKey, Apg.getFingerPrint(mUnknownSignatureKeyId)));
|
||||
|
||||
alert.setPositiveButton(android.R.string.ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
removeDialog(Id.dialog.lookup_unknown_key);
|
||||
Intent intent = new Intent(DecryptActivity.this,
|
||||
KeyServerQueryActivity.class);
|
||||
intent.setAction(Apg.Intent.LOOK_UP_KEY_ID);
|
||||
intent.putExtra(Apg.EXTRA_KEY_ID, mUnknownSignatureKeyId);
|
||||
startActivityForResult(intent, Id.request.look_up_key_id);
|
||||
}
|
||||
});
|
||||
alert.setNegativeButton(android.R.string.cancel,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
removeDialog(Id.dialog.lookup_unknown_key);
|
||||
PausableThread thread = getRunningThread();
|
||||
if (thread != null && thread.isPaused()) {
|
||||
thread.unpause();
|
||||
}
|
||||
}
|
||||
});
|
||||
alert.setCancelable(true);
|
||||
|
||||
return alert.create();
|
||||
}
|
||||
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
|
@ -85,6 +85,7 @@ public final class Id {
|
||||
public static final int deleting = 0x21070013;
|
||||
public static final int help = 0x21070014;
|
||||
public static final int querying = 0x21070015;
|
||||
public static final int lookup_unknown_key = 0x21070016;
|
||||
}
|
||||
|
||||
public static final class task {
|
||||
|
Loading…
Reference in New Issue
Block a user