mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-26 19:22:23 -05:00
PGP: Introduce key preference per account for OpenPGP APIv7
This commit is contained in:
parent
dc95f5feab
commit
16f09611fe
@ -220,6 +220,7 @@ public class Account implements BaseAccount, StoreConfig {
|
|||||||
private boolean mStripSignature;
|
private boolean mStripSignature;
|
||||||
private boolean mSyncRemoteDeletions;
|
private boolean mSyncRemoteDeletions;
|
||||||
private String mCryptoApp;
|
private String mCryptoApp;
|
||||||
|
private long mCryptoKey;
|
||||||
private boolean mMarkMessageAsReadOnView;
|
private boolean mMarkMessageAsReadOnView;
|
||||||
private boolean mAlwaysShowCcBcc;
|
private boolean mAlwaysShowCcBcc;
|
||||||
private boolean mAllowRemoteSearch;
|
private boolean mAllowRemoteSearch;
|
||||||
@ -314,6 +315,7 @@ public class Account implements BaseAccount, StoreConfig {
|
|||||||
mStripSignature = DEFAULT_STRIP_SIGNATURE;
|
mStripSignature = DEFAULT_STRIP_SIGNATURE;
|
||||||
mSyncRemoteDeletions = true;
|
mSyncRemoteDeletions = true;
|
||||||
mCryptoApp = NO_OPENPGP_PROVIDER;
|
mCryptoApp = NO_OPENPGP_PROVIDER;
|
||||||
|
mCryptoKey = 0;
|
||||||
mAllowRemoteSearch = false;
|
mAllowRemoteSearch = false;
|
||||||
mRemoteSearchFullText = false;
|
mRemoteSearchFullText = false;
|
||||||
mRemoteSearchNumResults = DEFAULT_REMOTE_SEARCH_NUM_RESULTS;
|
mRemoteSearchNumResults = DEFAULT_REMOTE_SEARCH_NUM_RESULTS;
|
||||||
@ -724,6 +726,7 @@ public class Account implements BaseAccount, StoreConfig {
|
|||||||
editor.putBoolean(mUuid + ".replyAfterQuote", mReplyAfterQuote);
|
editor.putBoolean(mUuid + ".replyAfterQuote", mReplyAfterQuote);
|
||||||
editor.putBoolean(mUuid + ".stripSignature", mStripSignature);
|
editor.putBoolean(mUuid + ".stripSignature", mStripSignature);
|
||||||
editor.putString(mUuid + ".cryptoApp", mCryptoApp);
|
editor.putString(mUuid + ".cryptoApp", mCryptoApp);
|
||||||
|
editor.putLong(mUuid + ".cryptoKey", mCryptoKey);
|
||||||
editor.putBoolean(mUuid + ".allowRemoteSearch", mAllowRemoteSearch);
|
editor.putBoolean(mUuid + ".allowRemoteSearch", mAllowRemoteSearch);
|
||||||
editor.putBoolean(mUuid + ".remoteSearchFullText", mRemoteSearchFullText);
|
editor.putBoolean(mUuid + ".remoteSearchFullText", mRemoteSearchFullText);
|
||||||
editor.putInt(mUuid + ".remoteSearchNumResults", mRemoteSearchNumResults);
|
editor.putInt(mUuid + ".remoteSearchNumResults", mRemoteSearchNumResults);
|
||||||
@ -1605,6 +1608,14 @@ public class Account implements BaseAccount, StoreConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getCryptoKey() {
|
||||||
|
return mCryptoKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCryptoKey(long keyId) {
|
||||||
|
mCryptoKey = keyId;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean allowRemoteSearch() {
|
public boolean allowRemoteSearch() {
|
||||||
return mAllowRemoteSearch;
|
return mAllowRemoteSearch;
|
||||||
}
|
}
|
||||||
|
@ -1298,9 +1298,11 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
|||||||
if (mEncryptCheckbox.isChecked() && mCryptoSignatureCheckbox.isChecked()) {
|
if (mEncryptCheckbox.isChecked() && mCryptoSignatureCheckbox.isChecked()) {
|
||||||
Intent intent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
|
Intent intent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
|
||||||
intent.putExtra(OpenPgpApi.EXTRA_USER_IDS, emailsArray);
|
intent.putExtra(OpenPgpApi.EXTRA_USER_IDS, emailsArray);
|
||||||
|
intent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, mAccount.getCryptoKey());
|
||||||
executeOpenPgpMethod(intent);
|
executeOpenPgpMethod(intent);
|
||||||
} else if (mCryptoSignatureCheckbox.isChecked()) {
|
} else if (mCryptoSignatureCheckbox.isChecked()) {
|
||||||
Intent intent = new Intent(OpenPgpApi.ACTION_SIGN);
|
Intent intent = new Intent(OpenPgpApi.ACTION_SIGN);
|
||||||
|
intent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, mAccount.getCryptoKey());
|
||||||
executeOpenPgpMethod(intent);
|
executeOpenPgpMethod(intent);
|
||||||
} else if (mEncryptCheckbox.isChecked()) {
|
} else if (mEncryptCheckbox.isChecked()) {
|
||||||
Intent intent = new Intent(OpenPgpApi.ACTION_ENCRYPT);
|
Intent intent = new Intent(OpenPgpApi.ACTION_ENCRYPT);
|
||||||
@ -1338,10 +1340,6 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
|||||||
|
|
||||||
private void executeOpenPgpMethod(Intent intent) {
|
private void executeOpenPgpMethod(Intent intent) {
|
||||||
intent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
intent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
||||||
// this follows user id format of OpenPGP to allow key generation based on it
|
|
||||||
// includes account number to make it unique
|
|
||||||
String accName = OpenPgpApiHelper.buildAccountName(mIdentity);
|
|
||||||
intent.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, accName);
|
|
||||||
|
|
||||||
final InputStream is = getOpenPgpInputStream();
|
final InputStream is = getOpenPgpInputStream();
|
||||||
final ByteArrayOutputStream os = new ByteArrayOutputStream();
|
final ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
|
@ -39,6 +39,7 @@ import com.fsck.k9.activity.ChooseIdentity;
|
|||||||
import com.fsck.k9.activity.ColorPickerDialog;
|
import com.fsck.k9.activity.ColorPickerDialog;
|
||||||
import com.fsck.k9.activity.K9PreferenceActivity;
|
import com.fsck.k9.activity.K9PreferenceActivity;
|
||||||
import com.fsck.k9.activity.ManageIdentities;
|
import com.fsck.k9.activity.ManageIdentities;
|
||||||
|
import com.fsck.k9.crypto.OpenPgpApiHelper;
|
||||||
import com.fsck.k9.mail.Folder;
|
import com.fsck.k9.mail.Folder;
|
||||||
import com.fsck.k9.mail.Store;
|
import com.fsck.k9.mail.Store;
|
||||||
import com.fsck.k9.mailstore.LocalFolder;
|
import com.fsck.k9.mailstore.LocalFolder;
|
||||||
@ -46,6 +47,7 @@ import com.fsck.k9.mailstore.StorageManager;
|
|||||||
import com.fsck.k9.service.MailService;
|
import com.fsck.k9.service.MailService;
|
||||||
|
|
||||||
import org.openintents.openpgp.util.OpenPgpAppPreference;
|
import org.openintents.openpgp.util.OpenPgpAppPreference;
|
||||||
|
import org.openintents.openpgp.util.OpenPgpKeyPreference;
|
||||||
import org.openintents.openpgp.util.OpenPgpUtils;
|
import org.openintents.openpgp.util.OpenPgpUtils;
|
||||||
|
|
||||||
|
|
||||||
@ -110,6 +112,7 @@ public class AccountSettings extends K9PreferenceActivity {
|
|||||||
private static final String PREFERENCE_SYNC_REMOTE_DELETIONS = "account_sync_remote_deletetions";
|
private static final String PREFERENCE_SYNC_REMOTE_DELETIONS = "account_sync_remote_deletetions";
|
||||||
private static final String PREFERENCE_CRYPTO = "crypto";
|
private static final String PREFERENCE_CRYPTO = "crypto";
|
||||||
private static final String PREFERENCE_CRYPTO_APP = "crypto_app";
|
private static final String PREFERENCE_CRYPTO_APP = "crypto_app";
|
||||||
|
private static final String PREFERENCE_CRYPTO_KEY = "crypto_key";
|
||||||
private static final String PREFERENCE_CLOUD_SEARCH_ENABLED = "remote_search_enabled";
|
private static final String PREFERENCE_CLOUD_SEARCH_ENABLED = "remote_search_enabled";
|
||||||
private static final String PREFERENCE_REMOTE_SEARCH_NUM_RESULTS = "account_remote_search_num_results";
|
private static final String PREFERENCE_REMOTE_SEARCH_NUM_RESULTS = "account_remote_search_num_results";
|
||||||
private static final String PREFERENCE_REMOTE_SEARCH_FULL_TEXT = "account_remote_search_full_text";
|
private static final String PREFERENCE_REMOTE_SEARCH_FULL_TEXT = "account_remote_search_full_text";
|
||||||
@ -175,6 +178,7 @@ public class AccountSettings extends K9PreferenceActivity {
|
|||||||
private ListPreference mMaxPushFolders;
|
private ListPreference mMaxPushFolders;
|
||||||
private boolean mHasCrypto = false;
|
private boolean mHasCrypto = false;
|
||||||
private OpenPgpAppPreference mCryptoApp;
|
private OpenPgpAppPreference mCryptoApp;
|
||||||
|
private OpenPgpKeyPreference mCryptoKey;
|
||||||
|
|
||||||
private PreferenceScreen mSearchScreen;
|
private PreferenceScreen mSearchScreen;
|
||||||
private CheckBoxPreference mCloudSearchEnabled;
|
private CheckBoxPreference mCloudSearchEnabled;
|
||||||
@ -688,14 +692,27 @@ public class AccountSettings extends K9PreferenceActivity {
|
|||||||
mHasCrypto = OpenPgpUtils.isAvailable(this);
|
mHasCrypto = OpenPgpUtils.isAvailable(this);
|
||||||
if (mHasCrypto) {
|
if (mHasCrypto) {
|
||||||
mCryptoApp = (OpenPgpAppPreference) findPreference(PREFERENCE_CRYPTO_APP);
|
mCryptoApp = (OpenPgpAppPreference) findPreference(PREFERENCE_CRYPTO_APP);
|
||||||
|
mCryptoKey = (OpenPgpKeyPreference) findPreference(PREFERENCE_CRYPTO_KEY);
|
||||||
|
|
||||||
mCryptoApp.setValue(String.valueOf(mAccount.getCryptoApp()));
|
mCryptoApp.setValue(String.valueOf(mAccount.getCryptoApp()));
|
||||||
mCryptoApp.setSummary(mCryptoApp.getEntry());
|
|
||||||
mCryptoApp.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
mCryptoApp.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
String value = newValue.toString();
|
String value = newValue.toString();
|
||||||
mCryptoApp.setSummary(mCryptoApp.getEntryByValue(value));
|
|
||||||
mCryptoApp.setValue(value);
|
mCryptoApp.setValue(value);
|
||||||
|
|
||||||
|
mCryptoKey.setOpenPgpProvider(value);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mCryptoKey.setValue(mAccount.getCryptoKey());
|
||||||
|
mCryptoKey.setOpenPgpProvider(mCryptoApp.getValue());
|
||||||
|
// TODO: other identities?
|
||||||
|
mCryptoKey.setDefaultUserId(OpenPgpApiHelper.buildUserId(mAccount.getIdentity(0)));
|
||||||
|
mCryptoKey.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
long value = (Long) newValue;
|
||||||
|
mCryptoKey.setValue(value);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -765,6 +782,7 @@ public class AccountSettings extends K9PreferenceActivity {
|
|||||||
mAccount.setLocalStorageProviderId(mLocalStorageProvider.getValue());
|
mAccount.setLocalStorageProviderId(mLocalStorageProvider.getValue());
|
||||||
if (mHasCrypto) {
|
if (mHasCrypto) {
|
||||||
mAccount.setCryptoApp(mCryptoApp.getValue());
|
mAccount.setCryptoApp(mCryptoApp.getValue());
|
||||||
|
mAccount.setCryptoKey(mCryptoKey.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
// In webdav account we use the exact folder name also for inbox,
|
// In webdav account we use the exact folder name also for inbox,
|
||||||
@ -832,6 +850,9 @@ public class AccountSettings extends K9PreferenceActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
if (mCryptoKey != null && mCryptoKey.handleOnActivityResult(requestCode, resultCode, data)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (resultCode == RESULT_OK) {
|
if (resultCode == RESULT_OK) {
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case SELECT_AUTO_EXPAND_FOLDER:
|
case SELECT_AUTO_EXPAND_FOLDER:
|
||||||
|
@ -16,7 +16,7 @@ public class OpenPgpApiHelper {
|
|||||||
*
|
*
|
||||||
* @see org.openintents.openpgp.util.OpenPgpApi#EXTRA_ACCOUNT_NAME
|
* @see org.openintents.openpgp.util.OpenPgpApi#EXTRA_ACCOUNT_NAME
|
||||||
*/
|
*/
|
||||||
public static String buildAccountName(Identity identity) {
|
public static String buildUserId(Identity identity) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
String name = identity.getName();
|
String name = identity.getName();
|
||||||
|
@ -170,10 +170,6 @@ public class MessageCryptoHelper {
|
|||||||
private void decryptVerify(Intent intent) {
|
private void decryptVerify(Intent intent) {
|
||||||
intent.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
|
intent.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
|
||||||
|
|
||||||
Identity identity = IdentityHelper.getRecipientIdentityFromMessage(account, message);
|
|
||||||
String accountName = OpenPgpApiHelper.buildAccountName(identity);
|
|
||||||
intent.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, accountName);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CryptoPartType cryptoPartType = currentCryptoPart.type;
|
CryptoPartType cryptoPartType = currentCryptoPart.type;
|
||||||
switch (cryptoPartType) {
|
switch (cryptoPartType) {
|
||||||
|
@ -569,8 +569,9 @@ Please submit bug reports, contribute new features and ask questions at
|
|||||||
<string name="account_settings_folders">Folders</string>
|
<string name="account_settings_folders">Folders</string>
|
||||||
<string name="account_settings_quote_prefix_label">Quoted text prefix</string>
|
<string name="account_settings_quote_prefix_label">Quoted text prefix</string>
|
||||||
<string name="account_settings_crypto">Cryptography</string>
|
<string name="account_settings_crypto">Cryptography</string>
|
||||||
<string name="account_settings_crypto_app">OpenPGP Provider</string>
|
<string name="account_settings_crypto_app">OpenPGP app</string>
|
||||||
<string name="account_settings_no_openpgp_provider_installed">No OpenPGP Provider installed</string>
|
<string name="account_settings_crypto_key">My Key</string>
|
||||||
|
<string name="account_settings_no_openpgp_provider_installed">No OpenPGP app installed</string>
|
||||||
|
|
||||||
<string name="account_settings_mail_check_frequency_label">Folder poll frequency</string>
|
<string name="account_settings_mail_check_frequency_label">Folder poll frequency</string>
|
||||||
|
|
||||||
|
@ -471,6 +471,11 @@
|
|||||||
android:key="crypto_app"
|
android:key="crypto_app"
|
||||||
android:title="@string/account_settings_crypto_app" />
|
android:title="@string/account_settings_crypto_app" />
|
||||||
|
|
||||||
|
<org.openintents.openpgp.util.OpenPgpKeyPreference
|
||||||
|
android:persistent="false"
|
||||||
|
android:key="crypto_key"
|
||||||
|
android:title="@string/account_settings_crypto_key" />
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@ -201,14 +201,23 @@ public class OpenPgpAppPreference extends DialogPreference {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public API
|
||||||
|
*/
|
||||||
public String getEntry() {
|
public String getEntry() {
|
||||||
return getEntryByValue(mSelectedPackage);
|
return getEntryByValue(mSelectedPackage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public API
|
||||||
|
*/
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return mSelectedPackage;
|
return mSelectedPackage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public API
|
||||||
|
*/
|
||||||
public void setValue(String packageName) {
|
public void setValue(String packageName) {
|
||||||
setAndPersist(packageName);
|
setAndPersist(packageName);
|
||||||
}
|
}
|
||||||
|
@ -145,6 +145,20 @@ public class OpenPgpKeyPreference extends Preference {
|
|||||||
setAndPersist(newValue);
|
setAndPersist(newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public API
|
||||||
|
*/
|
||||||
|
public void setValue(long keyId) {
|
||||||
|
setAndPersist(keyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public API
|
||||||
|
*/
|
||||||
|
public long getValue() {
|
||||||
|
return mKeyId;
|
||||||
|
}
|
||||||
|
|
||||||
private void setAndPersist(long newValue) {
|
private void setAndPersist(long newValue) {
|
||||||
mKeyId = newValue;
|
mKeyId = newValue;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user