lookup key fixes
This commit is contained in:
@@ -1636,8 +1636,8 @@ public class PGPMain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Bundle verifyText(Context context, InputData data, OutputStream outStream,
|
public static Bundle verifyText(Context context, InputData data, OutputStream outStream,
|
||||||
ProgressDialogUpdater progress) throws IOException, GeneralException, PGPException,
|
boolean lookupUnknownKey, ProgressDialogUpdater progress) throws IOException,
|
||||||
SignatureException {
|
GeneralException, PGPException, SignatureException {
|
||||||
Bundle returnData = new Bundle();
|
Bundle returnData = new Bundle();
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
@@ -1686,7 +1686,15 @@ public class PGPMain {
|
|||||||
if (signatureKeyId == 0) {
|
if (signatureKeyId == 0) {
|
||||||
signatureKeyId = signature.getKeyID();
|
signatureKeyId = signature.getKeyID();
|
||||||
}
|
}
|
||||||
if (signatureKey == null) {
|
// if key is not known and we want to lookup unknown ones...
|
||||||
|
if (signatureKey == null && lookupUnknownKey) {
|
||||||
|
|
||||||
|
returnData = new Bundle();
|
||||||
|
returnData.putLong(ApgService.RESULT_SIGNATURE_KEY_ID, signatureKeyId);
|
||||||
|
returnData.putBoolean(ApgService.RESULT_SIGNATURE_LOOKUP_KEY, true);
|
||||||
|
|
||||||
|
return returnData;
|
||||||
|
|
||||||
// TODO: reimplement!
|
// TODO: reimplement!
|
||||||
// Bundle pauseData = new Bundle();
|
// Bundle pauseData = new Bundle();
|
||||||
// pauseData.putInt(Constants.extras.STATUS, Id.message.unknown_signature_key);
|
// pauseData.putInt(Constants.extras.STATUS, Id.message.unknown_signature_key);
|
||||||
|
|||||||
@@ -31,10 +31,6 @@ public class ApgHandler extends Handler {
|
|||||||
public static final int MESSAGE_OKAY = 1;
|
public static final int MESSAGE_OKAY = 1;
|
||||||
public static final int MESSAGE_EXCEPTION = 2;
|
public static final int MESSAGE_EXCEPTION = 2;
|
||||||
public static final int MESSAGE_UPDATE_PROGRESS = 3;
|
public static final int MESSAGE_UPDATE_PROGRESS = 3;
|
||||||
|
|
||||||
// used in decrypt
|
|
||||||
public static final int MESSAGE_UNKOWN_KEY = 4;
|
|
||||||
|
|
||||||
|
|
||||||
// possible data keys for messages
|
// possible data keys for messages
|
||||||
public static final String DATA_ERROR = "error";
|
public static final String DATA_ERROR = "error";
|
||||||
|
|||||||
@@ -86,11 +86,12 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
|||||||
public static final String OUTPUT_FILE = "outputFile";
|
public static final String OUTPUT_FILE = "outputFile";
|
||||||
public static final String PROVIDER_URI = "providerUri";
|
public static final String PROVIDER_URI = "providerUri";
|
||||||
|
|
||||||
// decrypt
|
// decrypt/verify
|
||||||
public static final String SIGNED_ONLY = "signedOnly";
|
public static final String SIGNED_ONLY = "signedOnly";
|
||||||
public static final String RETURN_BYTES = "returnBinary";
|
public static final String RETURN_BYTES = "returnBinary";
|
||||||
public static final String CIPHERTEXT_BYTES = "ciphertextBytes";
|
public static final String CIPHERTEXT_BYTES = "ciphertextBytes";
|
||||||
public static final String ASSUME_SYMMETRIC = "assumeSymmetric";
|
public static final String ASSUME_SYMMETRIC = "assumeSymmetric";
|
||||||
|
public static final String LOOKUP_UNKNOWN_KEY = "lookup_unknown_key";
|
||||||
|
|
||||||
// edit keys
|
// edit keys
|
||||||
public static final String NEW_PASSPHRASE = "newPassphrase";
|
public static final String NEW_PASSPHRASE = "newPassphrase";
|
||||||
@@ -132,14 +133,16 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
|||||||
public static final String RESULT_ENCRYPTED_DATA = "encryptedData";
|
public static final String RESULT_ENCRYPTED_DATA = "encryptedData";
|
||||||
public static final String RESULT_URI = "resultUri";
|
public static final String RESULT_URI = "resultUri";
|
||||||
|
|
||||||
// decrypt
|
// decrypt/verify
|
||||||
public static final String RESULT_DECRYPTED_MESSAGE = "decryptedMessage";
|
public static final String RESULT_DECRYPTED_MESSAGE = "decryptedMessage";
|
||||||
public static final String RESULT_DECRYPTED_DATA = "decryptedData";
|
public static final String RESULT_DECRYPTED_DATA = "decryptedData";
|
||||||
public static final String RESULT_SIGNATURE = "signature";
|
public static final String RESULT_SIGNATURE = "signature";
|
||||||
public static final String RESULT_SIGNATURE_KEY_ID = "signatureKeyId";
|
public static final String RESULT_SIGNATURE_KEY_ID = "signatureKeyId";
|
||||||
public static final String RESULT_SIGNATURE_USER_ID = "signatureUserId";
|
public static final String RESULT_SIGNATURE_USER_ID = "signatureUserId";
|
||||||
|
|
||||||
public static final String RESULT_SIGNATURE_SUCCESS = "signatureSuccess";
|
public static final String RESULT_SIGNATURE_SUCCESS = "signatureSuccess";
|
||||||
public static final String RESULT_SIGNATURE_UNKNOWN = "signatureUnknown";
|
public static final String RESULT_SIGNATURE_UNKNOWN = "signatureUnknown";
|
||||||
|
public static final String RESULT_SIGNATURE_LOOKUP_KEY = "lookupKey";
|
||||||
|
|
||||||
Messenger mMessenger;
|
Messenger mMessenger;
|
||||||
|
|
||||||
@@ -340,6 +343,8 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
|||||||
boolean returnBytes = data.getBoolean(RETURN_BYTES);
|
boolean returnBytes = data.getBoolean(RETURN_BYTES);
|
||||||
boolean assumeSymmetricEncryption = data.getBoolean(ASSUME_SYMMETRIC);
|
boolean assumeSymmetricEncryption = data.getBoolean(ASSUME_SYMMETRIC);
|
||||||
|
|
||||||
|
boolean lookupUnknownKey = data.getBoolean(LOOKUP_UNKNOWN_KEY);
|
||||||
|
|
||||||
InputStream inStream = null;
|
InputStream inStream = null;
|
||||||
long inLength = -1;
|
long inLength = -1;
|
||||||
InputData inputData = null;
|
InputData inputData = null;
|
||||||
@@ -416,7 +421,8 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
|||||||
// verifyText and decrypt returning additional resultData values for the
|
// verifyText and decrypt returning additional resultData values for the
|
||||||
// verification of signatures
|
// verification of signatures
|
||||||
if (signedOnly) {
|
if (signedOnly) {
|
||||||
resultData = PGPMain.verifyText(this, inputData, outStream, this);
|
resultData = PGPMain.verifyText(this, inputData, outStream, lookupUnknownKey,
|
||||||
|
this);
|
||||||
} else {
|
} else {
|
||||||
resultData = PGPMain.decrypt(this, inputData, outStream,
|
resultData = PGPMain.decrypt(this, inputData, outStream,
|
||||||
PGPMain.getCachedPassPhrase(secretKeyId), this,
|
PGPMain.getCachedPassPhrase(secretKeyId), this,
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import org.thialfihar.android.apg.service.ApgHandler;
|
|||||||
import org.thialfihar.android.apg.service.ApgService;
|
import org.thialfihar.android.apg.service.ApgService;
|
||||||
import org.thialfihar.android.apg.ui.dialog.DeleteFileDialogFragment;
|
import org.thialfihar.android.apg.ui.dialog.DeleteFileDialogFragment;
|
||||||
import org.thialfihar.android.apg.ui.dialog.FileDialogFragment;
|
import org.thialfihar.android.apg.ui.dialog.FileDialogFragment;
|
||||||
|
import org.thialfihar.android.apg.ui.dialog.LookupUnknownKeyDialogFragment;
|
||||||
import org.thialfihar.android.apg.ui.dialog.PassphraseDialogFragment;
|
import org.thialfihar.android.apg.ui.dialog.PassphraseDialogFragment;
|
||||||
import org.thialfihar.android.apg.ui.dialog.ProgressDialogFragment;
|
import org.thialfihar.android.apg.ui.dialog.ProgressDialogFragment;
|
||||||
import org.thialfihar.android.apg.util.Compatibility;
|
import org.thialfihar.android.apg.util.Compatibility;
|
||||||
@@ -129,6 +130,8 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
private ProgressDialogFragment mDecryptingDialog;
|
private ProgressDialogFragment mDecryptingDialog;
|
||||||
private FileDialogFragment mFileDialog;
|
private FileDialogFragment mFileDialog;
|
||||||
|
|
||||||
|
private boolean mLookupUnknownKey = true;
|
||||||
|
|
||||||
public void setSecretKeyId(long id) {
|
public void setSecretKeyId(long id) {
|
||||||
mSecretKeyId = id;
|
mSecretKeyId = id;
|
||||||
}
|
}
|
||||||
@@ -603,7 +606,6 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
inStream = new ByteArrayInputStream(mData);
|
inStream = new ByteArrayInputStream(mData);
|
||||||
} else {
|
} else {
|
||||||
inStream = new ByteArrayInputStream(mMessage.getText().toString().getBytes());
|
inStream = new ByteArrayInputStream(mMessage.getText().toString().getBytes());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -666,6 +668,31 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
mFileDialog.show(getSupportFragmentManager(), "fileDialog");
|
mFileDialog.show(getSupportFragmentManager(), "fileDialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void lookupUnknownKey(long unknownKeyId) {
|
||||||
|
// Message is received after passphrase is cached
|
||||||
|
Handler returnHandler = new Handler() {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message message) {
|
||||||
|
if (message.what == LookupUnknownKeyDialogFragment.MESSAGE_OKAY) {
|
||||||
|
// the result is handled by onActivityResult() as LookupUnknownKeyDialogFragment
|
||||||
|
// starts a new Intent which then returns data
|
||||||
|
} else if (message.what == LookupUnknownKeyDialogFragment.MESSAGE_CANCEL) {
|
||||||
|
// decrypt again, but don't lookup unknown keys!
|
||||||
|
mLookupUnknownKey = false;
|
||||||
|
decryptStart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create a new Messenger for the communication back
|
||||||
|
Messenger messenger = new Messenger(returnHandler);
|
||||||
|
|
||||||
|
LookupUnknownKeyDialogFragment lookupKeyDialog = LookupUnknownKeyDialogFragment
|
||||||
|
.newInstance(messenger, unknownKeyId);
|
||||||
|
|
||||||
|
lookupKeyDialog.show(getSupportFragmentManager(), "unknownKeyDialog");
|
||||||
|
}
|
||||||
|
|
||||||
private void decryptStart() {
|
private void decryptStart() {
|
||||||
Log.d(Constants.TAG, "decryptStart");
|
Log.d(Constants.TAG, "decryptStart");
|
||||||
|
|
||||||
@@ -682,7 +709,6 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
data.putInt(ApgService.TARGET, ApgService.TARGET_STREAM);
|
data.putInt(ApgService.TARGET, ApgService.TARGET_STREAM);
|
||||||
|
|
||||||
data.putString(ApgService.PROVIDER_URI, mContentUri.toString());
|
data.putString(ApgService.PROVIDER_URI, mContentUri.toString());
|
||||||
|
|
||||||
} else if (mDecryptTarget == Id.target.file) {
|
} else if (mDecryptTarget == Id.target.file) {
|
||||||
data.putInt(ApgService.TARGET, ApgService.TARGET_FILE);
|
data.putInt(ApgService.TARGET, ApgService.TARGET_FILE);
|
||||||
|
|
||||||
@@ -691,7 +717,6 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
|
|
||||||
data.putString(ApgService.INPUT_FILE, mInputFilename);
|
data.putString(ApgService.INPUT_FILE, mInputFilename);
|
||||||
data.putString(ApgService.OUTPUT_FILE, mOutputFilename);
|
data.putString(ApgService.OUTPUT_FILE, mOutputFilename);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
data.putInt(ApgService.TARGET, ApgService.TARGET_BYTES);
|
data.putInt(ApgService.TARGET, ApgService.TARGET_BYTES);
|
||||||
|
|
||||||
@@ -706,6 +731,7 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
data.putLong(ApgService.SECRET_KEY_ID, getSecretKeyId());
|
data.putLong(ApgService.SECRET_KEY_ID, getSecretKeyId());
|
||||||
|
|
||||||
data.putBoolean(ApgService.SIGNED_ONLY, mSignedOnly);
|
data.putBoolean(ApgService.SIGNED_ONLY, mSignedOnly);
|
||||||
|
data.putBoolean(ApgService.LOOKUP_UNKNOWN_KEY, mLookupUnknownKey);
|
||||||
data.putBoolean(ApgService.RETURN_BYTES, mReturnBinary);
|
data.putBoolean(ApgService.RETURN_BYTES, mReturnBinary);
|
||||||
data.putBoolean(ApgService.ASSUME_SYMMETRIC, mAssumeSymmetricEncryption);
|
data.putBoolean(ApgService.ASSUME_SYMMETRIC, mAssumeSymmetricEncryption);
|
||||||
|
|
||||||
@@ -725,6 +751,14 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
// get returned data bundle
|
// get returned data bundle
|
||||||
Bundle returnData = message.getData();
|
Bundle returnData = message.getData();
|
||||||
|
|
||||||
|
// if key is unknown show lookup dialog
|
||||||
|
if (returnData.getBoolean(ApgService.RESULT_SIGNATURE_LOOKUP_KEY) && mLookupUnknownKey) {
|
||||||
|
mUnknownSignatureKeyId = returnData
|
||||||
|
.getLong(ApgService.RESULT_SIGNATURE_KEY_ID);
|
||||||
|
lookupUnknownKey(mUnknownSignatureKeyId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mSignatureKeyId = 0;
|
mSignatureKeyId = 0;
|
||||||
mSignatureLayout.setVisibility(View.GONE);
|
mSignatureLayout.setVisibility(View.GONE);
|
||||||
mReplyEnabled = false;
|
mReplyEnabled = false;
|
||||||
@@ -842,14 +876,12 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this request is returned after the LookupUnknownKeyDialogFragment was displayed and the
|
// this request is returned after LookupUnknownKeyDialogFragment started
|
||||||
// user choose okay
|
// KeyServerQueryActivity and user looked uo key
|
||||||
case Id.request.look_up_key_id: {
|
case Id.request.look_up_key_id: {
|
||||||
// TODO
|
// decrypt again without lookup
|
||||||
// PausableThread thread = getRunningThread();
|
mLookupUnknownKey = false;
|
||||||
// if (thread != null && thread.isPaused()) {
|
decryptStart();
|
||||||
// thread.unpause();
|
|
||||||
// }
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -861,47 +893,4 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Dialog onCreateDialog(int id) {
|
|
||||||
switch (id) {
|
|
||||||
|
|
||||||
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,
|
|
||||||
PGPHelper.getSmallFingerPrint(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(KeyServerQueryActivity.ACTION_LOOK_UP_KEY_ID);
|
|
||||||
intent.putExtra(KeyServerQueryActivity.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);
|
|
||||||
// TODO
|
|
||||||
// PausableThread thread = getRunningThread();
|
|
||||||
// if (thread != null && thread.isPaused()) {
|
|
||||||
// thread.unpause();
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
alert.setCancelable(true);
|
|
||||||
|
|
||||||
return alert.create();
|
|
||||||
}
|
|
||||||
|
|
||||||
default: {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.onCreateDialog(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user