Commit f4055b34 authored by Hussein's avatar Hussein

P4A-5 Remove Import pEp and PGP manual key import logic from messaging controller and pEpProvider

parent 6edc2303
......@@ -142,7 +142,7 @@ import static com.fsck.k9.mail.Flag.X_REMOTE_COPY_STARTED;
* removed from the queue once the activity is no longer active.
*/
@SuppressWarnings("unchecked") // TODO change architecture to actually work with generics
public class MessagingController implements Sync.MessageToSendCallback, KeyImportMessagingActions {
public class MessagingController implements Sync.MessageToSendCallback {
public static final long INVALID_MESSAGE_ID = -1;
private static final Set<Flag> SYNC_FLAGS = EnumSet.of(Flag.SEEN, Flag.FLAGGED, Flag.ANSWERED, Flag.FORWARDED);
......@@ -165,7 +165,6 @@ public class MessagingController implements Sync.MessageToSendCallback, KeyImpor
private PEpProvider pEpProvider;
private MessagingListener checkMailListener = null;
private volatile boolean stopped = false;
private ImportKeyController importKeyController;
@VisibleForTesting
......@@ -1686,54 +1685,22 @@ public class MessagingController implements Sync.MessageToSendCallback, KeyImpor
if (!rating.equals(Rating.pEpRatingUndefined)) {
// if we are on a trusted server and already had an EncStatus, then is already encrypted by someone else.
alreadyDecrypted = controller.getAlreadyDecrypted(message, account, rating);
tempResult = new PEpProvider.DecryptResult((MimeMessage) tempResult.msg, rating, null, tempResult.flags);
tempResult = new PEpProvider.DecryptResult((MimeMessage) tempResult.msg, rating, tempResult.flags);
}
}
if (tempResult.flags == -1)
Timber.e("PEPJNI %s", "messageFinished: null");
if (tempResult.flags != -1) {
Timber.e("PEPJNI %s: %s", "messageFinished", tempResult.flags);
/* For keysync not needed intil pEp sync is in place again.
switch (tempResult.flags) {
case PEPDecryptFlagConsumed:
Timber.v("pEpJNI", "messageFinished: Deleting");
tempResult = null;
store = false;
break;
case PEPDecryptFlagIgnored:
Timber.v("pEpJNI", "messageFinished: ");
tempResult = new PEpProvider.DecryptResult((MimeMessage) message, Rating.pEpRatingUndefined, null, null);
store = false;
break;
}
*/
/*
if ((tempResult.flags & DecryptFlags.pEpDecryptFlagConsumed.value) == DecryptFlags.pEpDecryptFlagConsumed.value) {
Timber.v("pEpJNI %s", "messageFinished: Deleting");
tempResult = null;
store = false;
} else if ((tempResult.flags & DecryptFlags.pEpDecryptFlagIgnored.value) == DecryptFlags.pEpDecryptFlagIgnored.value) {
tempResult = new PEpProvider.DecryptResult((MimeMessage) message, Rating.pEpRatingUndefined, null, -1);
store = false;
}
*/
}
result = tempResult;
Timber.d("pEp", "messageDecrypted: " + (System.currentTimeMillis() - time));
} else {
result = new PEpProvider.DecryptResult((MimeMessage) message, Rating.pEpRatingUndefined, null, -1);
result = new PEpProvider.DecryptResult((MimeMessage) message, Rating.pEpRatingUndefined, -1);
}
// PEpUtils.dumpMimeMessage("downloadSmallMessages", result.msg);
importKeyController = ImportKeyControllerFactory.getInstance().getImportKeyController(context, pEpProvider);
importKeyController.setMessagingActions(MessagingController.this);
importKeyController.setAccount(account);
if (result == null) {
deleteMessage(message, account, folder, localFolder);
} else if (importKeyController.isKeyImportMessage(message, result)) {
importKeyController.processKeyImportMessage(message, result, folder, localFolder);
} else if (result.keyDetails != null) {
showImportKeyDialogIfNeeded(message, result, account);
deleteMessage(message, account, folder, localFolder);
} else if (store
&& (!account.ispEpPrivacyProtected()
|| account.ispEpPrivacyProtected() && (result.rating != Rating.pEpRatingUndefined
......@@ -1803,7 +1770,7 @@ public class MessagingController implements Sync.MessageToSendCallback, KeyImpor
try {
tempResult = pEpProvider.decryptMessage(message);
} catch (AppCannotDecryptException error) {
tempResult = new PEpProvider.DecryptResult(message, Rating.pEpRatingUndefined, null, -1);
tempResult = new PEpProvider.DecryptResult(message, Rating.pEpRatingUndefined, -1);
}
return tempResult;
}
......@@ -1815,30 +1782,6 @@ public class MessagingController implements Sync.MessageToSendCallback, KeyImpor
localFolder.setFlags(Collections.singletonList(message), Collections.singleton(Flag.DELETED), true);
}
public <T extends Message> void showImportKeyDialogIfNeeded(final T message, final PEpProvider.DecryptResult result, Account account) {
Handler handler = new Handler(Looper.getMainLooper());
String currentFpr = pEpProvider.myself(PEpUtils.createIdentity(new Address(account.getEmail(), account.getName()), context)).fpr;
// if (!message.getFrom()[0].getAddress().equals(result.keyDetails.getAddress().getAddress())) {
if (!result.keyDetails.getFpr().equals(currentFpr) && result.keyDetails.getStringAddress().equalsIgnoreCase(account.getEmail())) {
handler.post(new Runnable() {
@Override
public void run() {
Intent broadcastIntent = new Intent(context, K9ActivityCommon.PrivateKeyReceiver.class);
fillPrivateKeyDetails(broadcastIntent, message, result);
context.getApplicationContext().sendOrderedBroadcast(broadcastIntent, null);
}
});
}
}
private <T extends Message> void fillPrivateKeyDetails(Intent broadcastIntent, T message, PEpProvider.DecryptResult result) {
broadcastIntent.putExtra(PEpProvider.PEP_PRIVATE_KEY_FROM, message.getFrom()[0].getAddress());
broadcastIntent.putExtra(PEpProvider.PEP_PRIVATE_KEY_FPR, result.keyDetails.getFpr());
broadcastIntent.putExtra(PEpProvider.PEP_PRIVATE_KEY_ADDRESS, result.keyDetails.getAddress().getAddress());
broadcastIntent.putExtra(PEpProvider.PEP_PRIVATE_KEY_USERNAME, result.keyDetails.getAddress().getPersonal());
}
private <T extends Message> void downloadLargeMessages(final Account account, final Folder<T> remoteFolder,
final LocalFolder localFolder,
List<T> largeMessages,
......@@ -4573,15 +4516,6 @@ public class MessagingController implements Sync.MessageToSendCallback, KeyImpor
}
}
public void startKeyImport(Account account, ImportWizardPresenter.Callback callback, boolean ispEp) {
importKeyController.start(ispEp, callback);
}
public void setImportKeyController(ImportKeyController importKeyController) {
this.importKeyController = importKeyController;
importKeyController.setMessagingActions(this);
}
public MessagingListener getCheckMailListener() {
return checkMailListener;
}
......@@ -4984,23 +4918,6 @@ public class MessagingController implements Sync.MessageToSendCallback, KeyImpor
return pEpProvider;
}
@Override
public void deleteMessage(Account account, Message srcMsg, String folder, LocalFolder localFolder) throws MessagingException {
deleteMessage(srcMsg, account, folder, localFolder);
}
@Override
public void sendMessage(Account account, Message message) throws MessagingException {
Log.i("pEpKeyImport", "sendingMessage: ");
Transport transport = transportProvider.getTransport(K9.app, account, K9.oAuth2TokenStore);
sendMessage(transport, message);
}
public ImportKeyController getImportKeyController() {
return importKeyController;
}
private interface MessageActor {
void act(Account account, LocalFolder messageFolder, List<LocalMessage> messages);
}
......
......@@ -269,13 +269,11 @@ public interface PEpProvider extends AutoCloseable {
}
class DecryptResult {
public final KeyDetail keyDetails;
public int flags = -1;
public DecryptResult(MimeMessage msg, Rating rating, KeyDetail keyDetails, int flags) {
public DecryptResult(MimeMessage msg, Rating rating, int flags) {
this.msg = msg;
this.rating = rating;
this.keyDetails = keyDetails;
this.flags = flags;
}
......
......@@ -228,21 +228,12 @@ public class PEpProviderImpl implements PEpProvider {
decMsg.setFlag(Flag.X_PEP_NEVER_UNSECURE, neverUnprotected);
extractpEpImportHeaderFromReplyTo(decMsg);
// TODO: 2020-02-20 Seem like this flgs currently are not used on the engine, this needs to be reviewed and probably removed
DecryptResult flaggedResult = processKeyImportSyncMessages(decReturn, decMsg);
if (flaggedResult != null) return flaggedResult;
if (isUsablePrivateKey(decReturn)) {
if (decMsg.getHeaderNames().contains(MimeHeader.HEADER_PEP_KEY_IMPORT)
|| decMsg.getHeaderNames().contains(MimeHeader.HEADER_PEP_KEY_IMPORT_LEGACY)) {
Log.d(TAG, "pEpdecryptMessage() after decrypt has usable pEp key (import)");
return new DecryptResult(decMsg, decReturn.rating, new KeyDetail("", null), decReturn.flags);
} else if (!PEpUtils.isAutoConsumeMessage(decMsg)) {
Log.d(TAG, "pEpdecryptMessage() after decrypt has usable PGP key (import)");
return new DecryptResult(decMsg, decReturn.rating, getOwnKeyDetails(srcMsg), decReturn.flags);
} else return new DecryptResult(decMsg, decReturn.rating, null, 0x2);
}
else return new DecryptResult(decMsg, decReturn.rating, null, -1);
}catch (Throwable t) {
return new DecryptResult(decMsg, decReturn.rating, -1);
} catch (Throwable t) {
Log.e(TAG, "while decrypting message: " + source.getSubject()
+ "\n" + source.getFrom()[0]
+ "\n" + source.getSentDate().toString()
......@@ -266,17 +257,16 @@ public class PEpProviderImpl implements PEpProvider {
if (lastValidDate.after(decryptedMimeMessage.getSentDate())) {
flags = DecryptFlags.pEpDecryptFlagConsumed.value;
return new DecryptResult(decryptedMimeMessage, decReturn.rating, null, flags);
return new DecryptResult(decryptedMimeMessage, decReturn.rating, flags);
}
}
else if (PEpUtils.isAutoConsumeMessage(decryptedMimeMessage)) {
if (lastValidDate.after(decryptedMimeMessage.getSentDate())) {
flags = DecryptFlags.pEpDecryptFlagConsumed.value;
return new DecryptResult(decryptedMimeMessage, decReturn.rating, null, flags);
} else {
flags = DecryptFlags.pEpDecryptFlagIgnored.value;
return new DecryptResult(decryptedMimeMessage, decReturn.rating, null, flags);
}
return new DecryptResult(decryptedMimeMessage, decReturn.rating, flags);
}
return null;
}
......@@ -323,16 +313,9 @@ public class PEpProviderImpl implements PEpProvider {
Message message = decReturn.dst;
MimeMessage decMsg = getMimeMessage(source, message);
if (isUsablePrivateKey(decReturn)) {
notifyLoaded(new DecryptResult(decMsg, decReturn.rating, getOwnKeyDetails(srcMsg), -1), callback);
}
else notifyLoaded(new DecryptResult(decMsg, decReturn.rating, null, decReturn.flags), callback);
// } catch (pEpMessageConsume | pEpMessageIgnore pe) {
// // TODO: 15/11/16 deal with it as flag not exception
notifyLoaded(new DecryptResult(decMsg, decReturn.rating, decReturn.flags), callback);
// // throw pe;
// return null;
}catch (Throwable t) {
} catch (Throwable t) {
Log.e(TAG, "while decrypting message:", t);
notifyError(new AppCannotDecryptException("Could not decrypt", t), callback);
} finally {
......@@ -802,7 +785,11 @@ public class PEpProviderImpl implements PEpProvider {
engine.stopKeyserverLookup();
}
/**
* @deprecated private key detection is not supported anymore, alternatives are pEp sync and import from FS
*/
@Override
@Deprecated
public synchronized KeyDetail getOwnKeyDetails(Message message) {
Identity id;
try {
......@@ -1194,7 +1181,8 @@ public class PEpProviderImpl implements PEpProvider {
public void keyResetIdentity(Identity ident, String fpr) {
createEngineInstanceIfNeeded();
ident = updateIdentity(ident);
engine.key_reset_identity(ident, fpr);
engine.key_reset_identity(ident,
fpr);
}
@Override
......
......@@ -41,7 +41,7 @@ public class ImportWizardPresenter implements Presenter {
public void onStartClicked(Account account) {
//new Thread(() ->
messagingController.startKeyImport(account, new Callback() {
importKeyController.start(ispEp, new Callback() {
@Override
public void onStart() {
view.starSendKeyImportRequest();
......@@ -52,7 +52,7 @@ public class ImportWizardPresenter implements Presenter {
if (success) view.finishSendingKeyImport();
else view.showSendError();
}
}, ispEp);
});
//).start();
}
......@@ -61,7 +61,6 @@ public class ImportWizardPresenter implements Presenter {
this.view = view;
importKeyController.setAccount(account);
importKeyController.setStarter(isStarter);
messagingController.setImportKeyController(importKeyController);
showInitialScreen(serializableExtra);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment