mirror of
https://github.com/moparisthebest/k-9
synced 2025-01-30 14:50:14 -05:00
decoupled PgpData from CryptoProvider, moved the crypto provider into Account
This commit is contained in:
parent
df0ae4e4bf
commit
a93da0ed80
@ -8,6 +8,7 @@ import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import com.fsck.k9.crypto.Apg;
|
||||
import com.fsck.k9.crypto.CryptoProvider;
|
||||
import com.fsck.k9.helper.Utility;
|
||||
import com.fsck.k9.mail.Address;
|
||||
import com.fsck.k9.mail.Folder;
|
||||
@ -112,6 +113,8 @@ public class Account implements BaseAccount
|
||||
private String mCryptoApp;
|
||||
private boolean mCryptoAutoSignature;
|
||||
|
||||
private CryptoProvider mCryptoProvider = null;
|
||||
|
||||
/**
|
||||
* Name of the folder that was last selected for a copy or move operation.
|
||||
*
|
||||
@ -1455,6 +1458,8 @@ public class Account implements BaseAccount
|
||||
public void setCryptoApp(String cryptoApp)
|
||||
{
|
||||
mCryptoApp = cryptoApp;
|
||||
// invalidate the provider
|
||||
mCryptoProvider = null;
|
||||
}
|
||||
|
||||
public boolean getCryptoAutoSignature()
|
||||
@ -1485,4 +1490,11 @@ public class Account implements BaseAccount
|
||||
{
|
||||
lastSelectedFolderName = folderName;
|
||||
}
|
||||
|
||||
public synchronized CryptoProvider getCryptoProvider() {
|
||||
if (mCryptoProvider == null) {
|
||||
mCryptoProvider = CryptoProvider.createInstance(getCryptoApp());
|
||||
}
|
||||
return mCryptoProvider;
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ import com.fsck.k9.R;
|
||||
import com.fsck.k9.controller.MessagingController;
|
||||
import com.fsck.k9.controller.MessagingListener;
|
||||
import com.fsck.k9.crypto.CryptoProvider;
|
||||
import com.fsck.k9.crypto.PgpData;
|
||||
import com.fsck.k9.helper.Utility;
|
||||
import com.fsck.k9.mail.Address;
|
||||
import com.fsck.k9.mail.Body;
|
||||
@ -103,7 +104,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
"com.fsck.k9.activity.MessageCompose.identityChanged";
|
||||
private static final String STATE_IDENTITY =
|
||||
"com.fsck.k9.activity.MessageCompose.identity";
|
||||
private static final String STATE_CRYPTO = "crypto";
|
||||
private static final String STATE_PGP_DATA = "pgpData";
|
||||
private static final String STATE_IN_REPLY_TO = "com.fsck.k9.activity.MessageCompose.inReplyTo";
|
||||
private static final String STATE_REFERENCES = "com.fsck.k9.activity.MessageCompose.references";
|
||||
|
||||
@ -174,7 +175,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
private TextView mCryptoSignatureUserId;
|
||||
private TextView mCryptoSignatureUserIdRest;
|
||||
|
||||
private CryptoProvider mCrypto = null;
|
||||
private PgpData mPgpData = null;
|
||||
|
||||
private String mReferences;
|
||||
private String mInReplyTo;
|
||||
@ -676,7 +677,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
mEncryptCheckbox = (CheckBox)findViewById(R.id.cb_encrypt);
|
||||
|
||||
initializeCrypto();
|
||||
if (mCrypto.isAvailable(this))
|
||||
final CryptoProvider crypto = mAccount.getCryptoProvider();
|
||||
if (crypto.isAvailable(this))
|
||||
{
|
||||
mEncryptLayout.setVisibility(View.VISIBLE);
|
||||
mCryptoSignatureCheckbox.setOnClickListener(new OnClickListener()
|
||||
@ -688,7 +690,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
if (checkBox.isChecked())
|
||||
{
|
||||
mPreventDraftSaving = true;
|
||||
if (!mCrypto.selectSecretKey(MessageCompose.this))
|
||||
if (!crypto.selectSecretKey(MessageCompose.this, mPgpData))
|
||||
{
|
||||
mPreventDraftSaving = false;
|
||||
}
|
||||
@ -696,7 +698,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
}
|
||||
else
|
||||
{
|
||||
mCrypto.setSignatureKeyId(0);
|
||||
mPgpData.setSignatureKeyId(0);
|
||||
updateEncryptLayout();
|
||||
}
|
||||
}
|
||||
@ -704,16 +706,16 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
|
||||
if (mAccount.getCryptoAutoSignature())
|
||||
{
|
||||
long ids[] = mCrypto.getSecretKeyIdsFromEmail(this, mIdentity.getEmail());
|
||||
long ids[] = crypto.getSecretKeyIdsFromEmail(this, mIdentity.getEmail());
|
||||
if (ids != null && ids.length > 0)
|
||||
{
|
||||
mCrypto.setSignatureKeyId(ids[0]);
|
||||
mCrypto.setSignatureUserId(mCrypto.getUserId(this, ids[0]));
|
||||
mPgpData.setSignatureKeyId(ids[0]);
|
||||
mPgpData.setSignatureUserId(crypto.getUserId(this, ids[0]));
|
||||
}
|
||||
else
|
||||
{
|
||||
mCrypto.setSignatureKeyId(0);
|
||||
mCrypto.setSignatureUserId(null);
|
||||
mPgpData.setSignatureKeyId(0);
|
||||
mPgpData.setSignatureUserId(null);
|
||||
}
|
||||
}
|
||||
updateEncryptLayout();
|
||||
@ -728,11 +730,11 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
|
||||
private void initializeCrypto()
|
||||
{
|
||||
if (mCrypto != null)
|
||||
if (mPgpData != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
mCrypto = CryptoProvider.createInstance(mAccount);
|
||||
mPgpData = new PgpData();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -740,7 +742,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
*/
|
||||
public void updateEncryptLayout()
|
||||
{
|
||||
if (!mCrypto.hasSignatureKey())
|
||||
if (!mPgpData.hasSignatureKey())
|
||||
{
|
||||
mCryptoSignatureCheckbox.setText(R.string.btn_crypto_sign);
|
||||
mCryptoSignatureCheckbox.setChecked(false);
|
||||
@ -757,16 +759,16 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
mCryptoSignatureUserId.setText(R.string.unknown_crypto_signature_user_id);
|
||||
mCryptoSignatureUserIdRest.setText("");
|
||||
|
||||
String userId = mCrypto.getSignatureUserId();
|
||||
String userId = mPgpData.getSignatureUserId();
|
||||
if (userId == null)
|
||||
{
|
||||
userId = mCrypto.getUserId(this, mCrypto.getSignatureKeyId());
|
||||
mCrypto.setSignatureUserId(userId);
|
||||
userId = mAccount.getCryptoProvider().getUserId(this, mPgpData.getSignatureKeyId());
|
||||
mPgpData.setSignatureUserId(userId);
|
||||
}
|
||||
|
||||
if (userId != null)
|
||||
{
|
||||
String chunks[] = mCrypto.getSignatureUserId().split(" <", 2);
|
||||
String chunks[] = mPgpData.getSignatureUserId().split(" <", 2);
|
||||
mCryptoSignatureUserId.setText(chunks[0]);
|
||||
if (chunks.length > 1)
|
||||
{
|
||||
@ -819,7 +821,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
outState.putString(STATE_KEY_DRAFT_UID, mDraftUid);
|
||||
outState.putSerializable(STATE_IDENTITY, mIdentity);
|
||||
outState.putBoolean(STATE_IDENTITY_CHANGED, mIdentityChanged);
|
||||
outState.putSerializable(STATE_CRYPTO, mCrypto);
|
||||
outState.putSerializable(STATE_PGP_DATA, mPgpData);
|
||||
outState.putString(STATE_IN_REPLY_TO, mInReplyTo);
|
||||
outState.putString(STATE_REFERENCES, mReferences);
|
||||
}
|
||||
@ -843,7 +845,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
mDraftUid = savedInstanceState.getString(STATE_KEY_DRAFT_UID);
|
||||
mIdentity = (Identity)savedInstanceState.getSerializable(STATE_IDENTITY);
|
||||
mIdentityChanged = savedInstanceState.getBoolean(STATE_IDENTITY_CHANGED);
|
||||
mCrypto = (CryptoProvider) savedInstanceState.getSerializable(STATE_CRYPTO);
|
||||
mPgpData = (PgpData) savedInstanceState.getSerializable(STATE_PGP_DATA);
|
||||
mInReplyTo = savedInstanceState.getString(STATE_IN_REPLY_TO);
|
||||
mReferences = savedInstanceState.getString(STATE_REFERENCES);
|
||||
|
||||
@ -953,9 +955,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
}
|
||||
|
||||
String text = null;
|
||||
if (mCrypto.getEncryptedData() != null)
|
||||
if (mPgpData.getEncryptedData() != null)
|
||||
{
|
||||
text = mCrypto.getEncryptedData();
|
||||
text = mPgpData.getEncryptedData();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1058,7 +1060,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
|
||||
private void saveIfNeeded()
|
||||
{
|
||||
if (!mDraftNeedsSaving || mPreventDraftSaving || mCrypto.hasEncryptionKeys())
|
||||
if (!mDraftNeedsSaving || mPreventDraftSaving || mPgpData.hasEncryptionKeys())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -1069,7 +1071,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
|
||||
public void onEncryptionKeySelectionDone()
|
||||
{
|
||||
if (mCrypto.hasEncryptionKeys())
|
||||
if (mPgpData.hasEncryptionKeys())
|
||||
{
|
||||
onSend();
|
||||
}
|
||||
@ -1081,7 +1083,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
|
||||
public void onEncryptDone()
|
||||
{
|
||||
if (mCrypto.getEncryptedData() != null)
|
||||
if (mPgpData.getEncryptedData() != null)
|
||||
{
|
||||
onSend();
|
||||
}
|
||||
@ -1099,7 +1101,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
Toast.makeText(this, getString(R.string.message_compose_error_no_recipients), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
if (mEncryptCheckbox.isChecked() && !mCrypto.hasEncryptionKeys())
|
||||
if (mEncryptCheckbox.isChecked() && !mPgpData.hasEncryptionKeys())
|
||||
{
|
||||
// key selection before encryption
|
||||
String emails = "";
|
||||
@ -1125,19 +1127,19 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
emails += mIdentity.getEmail();
|
||||
|
||||
mPreventDraftSaving = true;
|
||||
if (!mCrypto.selectEncryptionKeys(MessageCompose.this, emails))
|
||||
if (!mAccount.getCryptoProvider().selectEncryptionKeys(MessageCompose.this, emails, mPgpData))
|
||||
{
|
||||
mPreventDraftSaving = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (mCrypto.hasEncryptionKeys() || mCrypto.hasSignatureKey())
|
||||
if (mPgpData.hasEncryptionKeys() || mPgpData.hasSignatureKey())
|
||||
{
|
||||
if (mCrypto.getEncryptedData() == null)
|
||||
if (mPgpData.getEncryptedData() == null)
|
||||
{
|
||||
String text = buildText(true);
|
||||
mPreventDraftSaving = true;
|
||||
if (!mCrypto.encrypt(this, text))
|
||||
if (!mAccount.getCryptoProvider().encrypt(this, text, mPgpData))
|
||||
{
|
||||
mPreventDraftSaving = false;
|
||||
}
|
||||
@ -1203,7 +1205,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
*/
|
||||
private void onAddAttachment2(final String mime_type)
|
||||
{
|
||||
if (mCrypto.isAvailable(this))
|
||||
if (mAccount.getCryptoProvider().isAvailable(this))
|
||||
{
|
||||
Toast.makeText(this, R.string.attachment_encryption_unsupported, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
@ -1304,7 +1306,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
// if a CryptoSystem activity is returning, then mPreventDraftSaving was set to true
|
||||
mPreventDraftSaving = false;
|
||||
|
||||
if (mCrypto.onActivityResult(this, requestCode, resultCode, data))
|
||||
if (mAccount.getCryptoProvider().onActivityResult(this, requestCode, resultCode, data, mPgpData))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -1454,7 +1456,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
switch (item.getItemId())
|
||||
{
|
||||
case R.id.send:
|
||||
mCrypto.setEncryptionKeys(null);
|
||||
mPgpData.setEncryptionKeys(null);
|
||||
onSend();
|
||||
break;
|
||||
case R.id.save:
|
||||
|
@ -67,6 +67,7 @@ import com.fsck.k9.R;
|
||||
import com.fsck.k9.controller.MessagingController;
|
||||
import com.fsck.k9.controller.MessagingListener;
|
||||
import com.fsck.k9.crypto.CryptoProvider;
|
||||
import com.fsck.k9.crypto.PgpData;
|
||||
import com.fsck.k9.helper.Contacts;
|
||||
import com.fsck.k9.mail.Address;
|
||||
import com.fsck.k9.mail.Flag;
|
||||
@ -89,7 +90,7 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
private static final String EXTRA_NEXT = "com.fsck.k9.MessageView_next";
|
||||
|
||||
private static final String SHOW_PICTURES = "showPictures";
|
||||
private static final String STATE_CRYPTO = "crypto";
|
||||
private static final String STATE_PGP_DATA = "pgpData";
|
||||
|
||||
private static final int ACTIVITY_CHOOSE_FOLDER_MOVE = 1;
|
||||
private static final int ACTIVITY_CHOOSE_FOLDER_COPY = 2;
|
||||
@ -146,7 +147,7 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
private ArrayList<MessageReference> mMessageReferences;
|
||||
|
||||
private Message mMessage;
|
||||
private CryptoProvider mCrypto = null;
|
||||
private PgpData mPgpData = null;
|
||||
|
||||
private static final int PREVIOUS = 1;
|
||||
private static final int NEXT = 2;
|
||||
@ -806,7 +807,7 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
{
|
||||
data = MimeUtility.getTextFromPart(part);
|
||||
}
|
||||
mCrypto.decrypt(MessageView.this, data);
|
||||
mAccount.getCryptoProvider().decrypt(MessageView.this, data, mPgpData);
|
||||
}
|
||||
catch (MessagingException me)
|
||||
{
|
||||
@ -900,7 +901,7 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
mMessageReference = (MessageReference)icicle.getSerializable(EXTRA_MESSAGE_REFERENCE);
|
||||
mMessageReferences = (ArrayList<MessageReference>)icicle.getSerializable(EXTRA_MESSAGE_REFERENCES);
|
||||
|
||||
mCrypto = (CryptoProvider) icicle.getSerializable(STATE_CRYPTO);
|
||||
mPgpData = (PgpData) icicle.getSerializable(STATE_PGP_DATA);
|
||||
updateDecryptLayout();
|
||||
}
|
||||
else
|
||||
@ -1081,7 +1082,7 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
{
|
||||
outState.putSerializable(EXTRA_MESSAGE_REFERENCE, mMessageReference);
|
||||
outState.putSerializable(EXTRA_MESSAGE_REFERENCES, mMessageReferences);
|
||||
outState.putSerializable(STATE_CRYPTO, mCrypto);
|
||||
outState.putSerializable(STATE_PGP_DATA, mPgpData);
|
||||
outState.putBoolean(SHOW_PICTURES, mShowPictures);
|
||||
}
|
||||
|
||||
@ -1093,7 +1094,7 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
mShowPictures = savedInstanceState.getBoolean(SHOW_PICTURES);
|
||||
setLoadPictures(mShowPictures);
|
||||
|
||||
mCrypto = (CryptoProvider) savedInstanceState.getSerializable(STATE_CRYPTO);
|
||||
mPgpData = (PgpData) savedInstanceState.getSerializable(STATE_PGP_DATA);
|
||||
initializeCrypto();
|
||||
|
||||
updateDecryptLayout();
|
||||
@ -1115,22 +1116,16 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
mAttachments.removeAllViews();
|
||||
findSurroundingMessagesUid();
|
||||
|
||||
// grab a new crypto provider object, as the account may have changed, and currently
|
||||
// the decrypted data and signature are stored in the crypto provider object
|
||||
// TODO: separate that storage from the provider
|
||||
// TODO: then move the provider object directly into the account object
|
||||
mCrypto = null;
|
||||
// start with fresh, empty PGP data
|
||||
mPgpData = null;
|
||||
initializeCrypto();
|
||||
|
||||
|
||||
MessagingController.getInstance(getApplication()).loadMessageForView(
|
||||
mAccount,
|
||||
mMessageReference.folderName,
|
||||
mMessageReference.uid,
|
||||
mListener);
|
||||
setupDisplayMessageButtons();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void setupDisplayMessageButtons()
|
||||
@ -1388,7 +1383,7 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
{
|
||||
if (mMessage != null)
|
||||
{
|
||||
MessageCompose.actionReply(this, mAccount, mMessage, false, mCrypto.getDecryptedData());
|
||||
MessageCompose.actionReply(this, mAccount, mMessage, false, mPgpData.getDecryptedData());
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@ -1397,7 +1392,7 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
{
|
||||
if (mMessage != null)
|
||||
{
|
||||
MessageCompose.actionReply(this, mAccount, mMessage, true, mCrypto.getDecryptedData());
|
||||
MessageCompose.actionReply(this, mAccount, mMessage, true, mPgpData.getDecryptedData());
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@ -1406,7 +1401,7 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
{
|
||||
if (mMessage != null)
|
||||
{
|
||||
MessageCompose.actionForward(this, mAccount, mMessage, mCrypto.getDecryptedData());
|
||||
MessageCompose.actionForward(this, mAccount, mMessage, mPgpData.getDecryptedData());
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@ -1513,7 +1508,7 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
if (mCrypto.onActivityResult(this, requestCode, resultCode, data))
|
||||
if (mAccount.getCryptoProvider().onActivityResult(this, requestCode, resultCode, data, mPgpData))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -2164,9 +2159,9 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
|
||||
String text;
|
||||
String type = "text/html";
|
||||
if (mCrypto.getDecryptedData() != null)
|
||||
if (mPgpData.getDecryptedData() != null)
|
||||
{
|
||||
text = mCrypto.getDecryptedData();
|
||||
text = mPgpData.getDecryptedData();
|
||||
type = "text/plain";
|
||||
}
|
||||
else
|
||||
@ -2509,7 +2504,7 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
|
||||
private void initializeCrypto()
|
||||
{
|
||||
if (mCrypto != null)
|
||||
if (mPgpData != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -2517,7 +2512,7 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
{
|
||||
mAccount = Preferences.getPreferences(this).getAccount(mMessageReference.accountUuid);
|
||||
}
|
||||
mCrypto = CryptoProvider.createInstance(mAccount);
|
||||
mPgpData = new PgpData();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2526,11 +2521,11 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
*/
|
||||
public void updateDecryptLayout()
|
||||
{
|
||||
if (mCrypto.getSignatureKeyId() != 0)
|
||||
if (mPgpData.getSignatureKeyId() != 0)
|
||||
{
|
||||
mCryptoSignatureUserIdRest.setText(
|
||||
getString(R.string.key_id, Long.toHexString(mCrypto.getSignatureKeyId() & 0xffffffffL)));
|
||||
String userId = mCrypto.getSignatureUserId();
|
||||
getString(R.string.key_id, Long.toHexString(mPgpData.getSignatureKeyId() & 0xffffffffL)));
|
||||
String userId = mPgpData.getSignatureUserId();
|
||||
if (userId == null)
|
||||
{
|
||||
userId = getString(R.string.unknown_crypto_signature_user_id);
|
||||
@ -2543,11 +2538,11 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
}
|
||||
mCryptoSignatureUserId.setText(name);
|
||||
|
||||
if (mCrypto.getSignatureSuccess())
|
||||
if (mPgpData.getSignatureSuccess())
|
||||
{
|
||||
mCryptoSignatureStatusImage.setImageResource(R.drawable.overlay_ok);
|
||||
}
|
||||
else if (mCrypto.getSignatureUnknown())
|
||||
else if (mPgpData.getSignatureUnknown())
|
||||
{
|
||||
mCryptoSignatureStatusImage.setImageResource(R.drawable.overlay_error);
|
||||
}
|
||||
@ -2563,15 +2558,15 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
mCryptoSignatureLayout.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
if (!true || ((mMessage == null) && (mCrypto.getDecryptedData() == null)))
|
||||
if (!true || ((mMessage == null) && (mPgpData.getDecryptedData() == null)))
|
||||
{
|
||||
mDecryptLayout.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mCrypto.getDecryptedData() != null)
|
||||
if (mPgpData.getDecryptedData() != null)
|
||||
{
|
||||
if (mCrypto.getSignatureKeyId() == 0)
|
||||
if (mPgpData.getSignatureKeyId() == 0)
|
||||
{
|
||||
mDecryptLayout.setVisibility(View.GONE);
|
||||
}
|
||||
@ -2585,12 +2580,13 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
|
||||
mDecryptButton.setVisibility(View.VISIBLE);
|
||||
|
||||
if (mCrypto.isEncrypted(mMessage))
|
||||
CryptoProvider crypto = mAccount.getCryptoProvider();
|
||||
if (crypto.isEncrypted(mMessage))
|
||||
{
|
||||
mDecryptButton.setText(R.string.btn_decrypt);
|
||||
mDecryptLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else if (mCrypto.isSigned(mMessage))
|
||||
else if (crypto.isSigned(mMessage))
|
||||
{
|
||||
mDecryptButton.setText(R.string.btn_verify);
|
||||
mDecryptLayout.setVisibility(View.VISIBLE);
|
||||
@ -2618,7 +2614,7 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
{
|
||||
// TODO: this might not be enough if the orientation was changed while in APG,
|
||||
// sometimes shows the original encrypted content
|
||||
mMessageContentView.loadDataWithBaseURL("email://", mCrypto.getDecryptedData(), "text/plain", "utf-8", null);
|
||||
mMessageContentView.loadDataWithBaseURL("email://", mPgpData.getDecryptedData(), "text/plain", "utf-8", null);
|
||||
updateDecryptLayout();
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ public class Apg extends CryptoProvider
|
||||
Pattern.compile(".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*",
|
||||
Pattern.DOTALL);
|
||||
|
||||
public static Apg createInstance(Account account)
|
||||
public static Apg createInstance()
|
||||
{
|
||||
return new Apg();
|
||||
}
|
||||
@ -128,10 +128,11 @@ public class Apg extends CryptoProvider
|
||||
* Select the signature key.
|
||||
*
|
||||
* @param activity
|
||||
* @param pgpData
|
||||
* @return success or failure
|
||||
*/
|
||||
@Override
|
||||
public boolean selectSecretKey(Activity activity)
|
||||
public boolean selectSecretKey(Activity activity, PgpData pgpData)
|
||||
{
|
||||
android.content.Intent intent = new android.content.Intent(Intent.SELECT_SECRET_KEY);
|
||||
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
|
||||
@ -154,20 +155,21 @@ public class Apg extends CryptoProvider
|
||||
*
|
||||
* @param activity
|
||||
* @param emails The emails that should be used for preselection.
|
||||
* @param pgpData
|
||||
* @return success or failure
|
||||
*/
|
||||
@Override
|
||||
public boolean selectEncryptionKeys(Activity activity, String emails)
|
||||
public boolean selectEncryptionKeys(Activity activity, String emails, PgpData pgpData)
|
||||
{
|
||||
android.content.Intent intent = new android.content.Intent(Apg.Intent.SELECT_PUBLIC_KEYS);
|
||||
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
|
||||
long[] initialKeyIds = null;
|
||||
if (!hasEncryptionKeys())
|
||||
if (!pgpData.hasEncryptionKeys())
|
||||
{
|
||||
Vector<Long> keyIds = new Vector<Long>();
|
||||
if (hasSignatureKey())
|
||||
if (pgpData.hasSignatureKey())
|
||||
{
|
||||
keyIds.add(getSignatureKeyId());
|
||||
keyIds.add(pgpData.getSignatureKeyId());
|
||||
}
|
||||
|
||||
try
|
||||
@ -208,7 +210,7 @@ public class Apg extends CryptoProvider
|
||||
}
|
||||
else
|
||||
{
|
||||
initialKeyIds = mEncryptionKeyIds;
|
||||
initialKeyIds = pgpData.getEncryptionKeys();
|
||||
}
|
||||
intent.putExtra(Apg.EXTRA_SELECTION, initialKeyIds);
|
||||
try
|
||||
@ -321,7 +323,7 @@ public class Apg extends CryptoProvider
|
||||
*/
|
||||
@Override
|
||||
public boolean onActivityResult(Activity activity, int requestCode, int resultCode,
|
||||
android.content.Intent data)
|
||||
android.content.Intent data, PgpData pgpData)
|
||||
{
|
||||
switch (requestCode)
|
||||
{
|
||||
@ -330,37 +332,37 @@ public class Apg extends CryptoProvider
|
||||
{
|
||||
break;
|
||||
}
|
||||
setSignatureKeyId(data.getLongExtra(Apg.EXTRA_KEY_ID, 0));
|
||||
setSignatureUserId(data.getStringExtra(Apg.EXTRA_USER_ID));
|
||||
pgpData.setSignatureKeyId(data.getLongExtra(Apg.EXTRA_KEY_ID, 0));
|
||||
pgpData.setSignatureUserId(data.getStringExtra(Apg.EXTRA_USER_ID));
|
||||
((MessageCompose) activity).updateEncryptLayout();
|
||||
break;
|
||||
|
||||
case Apg.SELECT_PUBLIC_KEYS:
|
||||
if (resultCode != Activity.RESULT_OK || data == null)
|
||||
{
|
||||
mEncryptionKeyIds = null;
|
||||
pgpData.setEncryptionKeys(null);
|
||||
((MessageCompose) activity).onEncryptionKeySelectionDone();
|
||||
break;
|
||||
}
|
||||
mEncryptionKeyIds = data.getLongArrayExtra(Apg.EXTRA_SELECTION);
|
||||
pgpData.setEncryptionKeys(data.getLongArrayExtra(Apg.EXTRA_SELECTION));
|
||||
((MessageCompose) activity).onEncryptionKeySelectionDone();
|
||||
break;
|
||||
|
||||
case Apg.ENCRYPT_MESSAGE:
|
||||
if (resultCode != Activity.RESULT_OK || data == null)
|
||||
{
|
||||
mEncryptedData = null;
|
||||
pgpData.setEncryptionKeys(null);
|
||||
((MessageCompose) activity).onEncryptDone();
|
||||
break;
|
||||
}
|
||||
mEncryptedData = data.getStringExtra(Apg.EXTRA_ENCRYPTED_MESSAGE);
|
||||
pgpData.setEncryptedData(data.getStringExtra(Apg.EXTRA_ENCRYPTED_MESSAGE));
|
||||
// this was a stupid bug in an earlier version, just gonna leave this in for an APG
|
||||
// version or two
|
||||
if (mEncryptedData == null)
|
||||
if (pgpData.getEncryptedData() == null)
|
||||
{
|
||||
mEncryptedData = data.getStringExtra(Apg.EXTRA_DECRYPTED_MESSAGE);
|
||||
pgpData.setEncryptedData(data.getStringExtra(Apg.EXTRA_DECRYPTED_MESSAGE));
|
||||
}
|
||||
if (mEncryptedData != null)
|
||||
if (pgpData.getEncryptedData() != null)
|
||||
{
|
||||
((MessageCompose) activity).onEncryptDone();
|
||||
}
|
||||
@ -372,12 +374,12 @@ public class Apg extends CryptoProvider
|
||||
break;
|
||||
}
|
||||
|
||||
mSignatureUserId = data.getStringExtra(Apg.EXTRA_SIGNATURE_USER_ID);
|
||||
mSignatureKeyId = data.getLongExtra(Apg.EXTRA_SIGNATURE_KEY_ID, 0);
|
||||
mSignatureSuccess = data.getBooleanExtra(Apg.EXTRA_SIGNATURE_SUCCESS, false);
|
||||
mSignatureUnknown = data.getBooleanExtra(Apg.EXTRA_SIGNATURE_UNKNOWN, false);
|
||||
pgpData.setSignatureUserId(data.getStringExtra(Apg.EXTRA_SIGNATURE_USER_ID));
|
||||
pgpData.setSignatureKeyId(data.getLongExtra(Apg.EXTRA_SIGNATURE_KEY_ID, 0));
|
||||
pgpData.setSignatureSuccess(data.getBooleanExtra(Apg.EXTRA_SIGNATURE_SUCCESS, false));
|
||||
pgpData.setSignatureUnknown(data.getBooleanExtra(Apg.EXTRA_SIGNATURE_UNKNOWN, false));
|
||||
|
||||
mDecryptedData = data.getStringExtra(Apg.EXTRA_DECRYPTED_MESSAGE);
|
||||
pgpData.setDecryptedData(data.getStringExtra(Apg.EXTRA_DECRYPTED_MESSAGE));
|
||||
((MessageView) activity).onDecryptDone();
|
||||
|
||||
break;
|
||||
@ -394,17 +396,18 @@ public class Apg extends CryptoProvider
|
||||
*
|
||||
* @param activity
|
||||
* @param data
|
||||
* @param pgpData
|
||||
* @return success or failure
|
||||
*/
|
||||
@Override
|
||||
public boolean encrypt(Activity activity, String data)
|
||||
public boolean encrypt(Activity activity, String data, PgpData pgpData)
|
||||
{
|
||||
android.content.Intent intent = new android.content.Intent(Intent.ENCRYPT_AND_RETURN);
|
||||
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
|
||||
intent.setType("text/plain");
|
||||
intent.putExtra(Apg.EXTRA_TEXT, data);
|
||||
intent.putExtra(Apg.EXTRA_ENCRYPTION_KEY_IDS, mEncryptionKeyIds);
|
||||
intent.putExtra(Apg.EXTRA_SIGNATURE_KEY_ID, mSignatureKeyId);
|
||||
intent.putExtra(Apg.EXTRA_ENCRYPTION_KEY_IDS, pgpData.getEncryptionKeys());
|
||||
intent.putExtra(Apg.EXTRA_SIGNATURE_KEY_ID, pgpData.getSignatureKeyId());
|
||||
try
|
||||
{
|
||||
activity.startActivityForResult(intent, Apg.ENCRYPT_MESSAGE);
|
||||
@ -424,10 +427,11 @@ public class Apg extends CryptoProvider
|
||||
*
|
||||
* @param activity
|
||||
* @param data
|
||||
* @param pgpData
|
||||
* @return success or failure
|
||||
*/
|
||||
@Override
|
||||
public boolean decrypt(Activity activity, String data)
|
||||
public boolean decrypt(Activity activity, String data, PgpData pgpData)
|
||||
{
|
||||
android.content.Intent intent = new android.content.Intent(Apg.Intent.DECRYPT_AND_RETURN);
|
||||
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
|
||||
|
@ -1,12 +1,9 @@
|
||||
package com.fsck.k9.crypto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.mail.Message;
|
||||
|
||||
/**
|
||||
@ -14,99 +11,31 @@ import com.fsck.k9.mail.Message;
|
||||
* It currently also stores the results of such encryption or decryption.
|
||||
* TODO: separate the storage from the provider
|
||||
*/
|
||||
abstract public class CryptoProvider implements Serializable
|
||||
abstract public class CryptoProvider
|
||||
{
|
||||
static final long serialVersionUID = 0x21071234;
|
||||
|
||||
protected long mEncryptionKeyIds[] = null;
|
||||
protected long mSignatureKeyId = 0;
|
||||
protected String mSignatureUserId = null;
|
||||
protected boolean mSignatureSuccess = false;
|
||||
protected boolean mSignatureUnknown = false;
|
||||
protected String mDecryptedData = null;
|
||||
protected String mEncryptedData = null;
|
||||
|
||||
abstract public boolean isAvailable(Context context);
|
||||
abstract public boolean isEncrypted(Message message);
|
||||
abstract public boolean isSigned(Message message);
|
||||
abstract public boolean onActivityResult(Activity activity, int requestCode, int resultCode,
|
||||
Intent data);
|
||||
abstract public boolean selectSecretKey(Activity activity);
|
||||
abstract public boolean selectEncryptionKeys(Activity activity, String emails);
|
||||
abstract public boolean encrypt(Activity activity, String data);
|
||||
abstract public boolean decrypt(Activity activity, String data);
|
||||
Intent data, PgpData pgpData);
|
||||
abstract public boolean selectSecretKey(Activity activity, PgpData pgpData);
|
||||
abstract public boolean selectEncryptionKeys(Activity activity, String emails, PgpData pgpData);
|
||||
abstract public boolean encrypt(Activity activity, String data, PgpData pgpData);
|
||||
abstract public boolean decrypt(Activity activity, String data, PgpData pgpData);
|
||||
abstract public long[] getSecretKeyIdsFromEmail(Context context, String email);
|
||||
abstract public String getUserId(Context context, long keyId);
|
||||
abstract public String getName();
|
||||
abstract public boolean test(Context context);
|
||||
|
||||
public static CryptoProvider createInstance(Account account)
|
||||
public static CryptoProvider createInstance(String name)
|
||||
{
|
||||
if (Apg.NAME.equals(account.getCryptoApp()))
|
||||
if (Apg.NAME.equals(name))
|
||||
{
|
||||
return Apg.createInstance(account);
|
||||
return Apg.createInstance();
|
||||
}
|
||||
|
||||
return None.createInstance(account);
|
||||
}
|
||||
|
||||
public void setSignatureKeyId(long keyId)
|
||||
{
|
||||
mSignatureKeyId = keyId;
|
||||
}
|
||||
|
||||
public long getSignatureKeyId()
|
||||
{
|
||||
return mSignatureKeyId;
|
||||
}
|
||||
|
||||
public void setEncryptionKeys(long keyIds[])
|
||||
{
|
||||
mEncryptionKeyIds = keyIds;
|
||||
}
|
||||
|
||||
public long[] getEncryptionKeys()
|
||||
{
|
||||
return mEncryptionKeyIds;
|
||||
}
|
||||
|
||||
public boolean hasSignatureKey()
|
||||
{
|
||||
return mSignatureKeyId != 0;
|
||||
}
|
||||
|
||||
public boolean hasEncryptionKeys()
|
||||
{
|
||||
return (mEncryptionKeyIds != null) && (mEncryptionKeyIds.length > 0);
|
||||
}
|
||||
|
||||
public String getEncryptedData()
|
||||
{
|
||||
return mEncryptedData;
|
||||
}
|
||||
|
||||
public String getDecryptedData()
|
||||
{
|
||||
return mDecryptedData;
|
||||
}
|
||||
|
||||
public void setSignatureUserId(String userId)
|
||||
{
|
||||
mSignatureUserId = userId;
|
||||
}
|
||||
|
||||
public String getSignatureUserId()
|
||||
{
|
||||
return mSignatureUserId;
|
||||
}
|
||||
|
||||
public boolean getSignatureSuccess()
|
||||
{
|
||||
return mSignatureSuccess;
|
||||
}
|
||||
|
||||
public boolean getSignatureUnknown()
|
||||
{
|
||||
return mSignatureUnknown;
|
||||
return None.createInstance();
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class None extends CryptoProvider
|
||||
static final long serialVersionUID = 0x21071230;
|
||||
public static final String NAME = "";
|
||||
|
||||
public static None createInstance(Account account)
|
||||
public static None createInstance()
|
||||
{
|
||||
return new None();
|
||||
}
|
||||
@ -27,13 +27,13 @@ public class None extends CryptoProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean selectSecretKey(Activity activity)
|
||||
public boolean selectSecretKey(Activity activity, PgpData pgpData)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean selectEncryptionKeys(Activity activity, String emails)
|
||||
public boolean selectEncryptionKeys(Activity activity, String emails, PgpData pgpData)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -52,19 +52,19 @@ public class None extends CryptoProvider
|
||||
|
||||
@Override
|
||||
public boolean onActivityResult(Activity activity, int requestCode, int resultCode,
|
||||
android.content.Intent data)
|
||||
android.content.Intent data, PgpData pgpData)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean encrypt(Activity activity, String data)
|
||||
public boolean encrypt(Activity activity, String data, PgpData pgpData)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean decrypt(Activity activity, String data)
|
||||
public boolean decrypt(Activity activity, String data, PgpData pgpData)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
93
src/com/fsck/k9/crypto/PgpData.java
Normal file
93
src/com/fsck/k9/crypto/PgpData.java
Normal file
@ -0,0 +1,93 @@
|
||||
package com.fsck.k9.crypto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class PgpData implements Serializable {
|
||||
protected long mEncryptionKeyIds[] = null;
|
||||
protected long mSignatureKeyId = 0;
|
||||
protected String mSignatureUserId = null;
|
||||
protected boolean mSignatureSuccess = false;
|
||||
protected boolean mSignatureUnknown = false;
|
||||
protected String mDecryptedData = null;
|
||||
protected String mEncryptedData = null;
|
||||
|
||||
public void setSignatureKeyId(long keyId)
|
||||
{
|
||||
mSignatureKeyId = keyId;
|
||||
}
|
||||
|
||||
public long getSignatureKeyId()
|
||||
{
|
||||
return mSignatureKeyId;
|
||||
}
|
||||
|
||||
public void setEncryptionKeys(long keyIds[])
|
||||
{
|
||||
mEncryptionKeyIds = keyIds;
|
||||
}
|
||||
|
||||
public long[] getEncryptionKeys()
|
||||
{
|
||||
return mEncryptionKeyIds;
|
||||
}
|
||||
|
||||
public boolean hasSignatureKey()
|
||||
{
|
||||
return mSignatureKeyId != 0;
|
||||
}
|
||||
|
||||
public boolean hasEncryptionKeys()
|
||||
{
|
||||
return (mEncryptionKeyIds != null) && (mEncryptionKeyIds.length > 0);
|
||||
}
|
||||
|
||||
public String getEncryptedData()
|
||||
{
|
||||
return mEncryptedData;
|
||||
}
|
||||
|
||||
public void setEncryptedData(String data)
|
||||
{
|
||||
mEncryptedData = data;
|
||||
}
|
||||
|
||||
public String getDecryptedData()
|
||||
{
|
||||
return mDecryptedData;
|
||||
}
|
||||
|
||||
public void setDecryptedData(String data)
|
||||
{
|
||||
mDecryptedData = data;
|
||||
}
|
||||
|
||||
public void setSignatureUserId(String userId)
|
||||
{
|
||||
mSignatureUserId = userId;
|
||||
}
|
||||
|
||||
public String getSignatureUserId()
|
||||
{
|
||||
return mSignatureUserId;
|
||||
}
|
||||
|
||||
public boolean getSignatureSuccess()
|
||||
{
|
||||
return mSignatureSuccess;
|
||||
}
|
||||
|
||||
public void setSignatureSuccess(boolean success)
|
||||
{
|
||||
mSignatureSuccess = success;
|
||||
}
|
||||
|
||||
public boolean getSignatureUnknown()
|
||||
{
|
||||
return mSignatureUnknown;
|
||||
}
|
||||
|
||||
public void setSignatureUnknown(boolean unknown)
|
||||
{
|
||||
mSignatureUnknown = unknown;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user