Loading src/com/fsck/k9/Account.java +50 −0 Original line number Diff line number Diff line package com.fsck.k9; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; Loading @@ -22,6 +24,7 @@ import android.net.ConnectivityManager; import android.net.Uri; import android.util.Log; import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection; import com.fsck.k9.crypto.Apg; import com.fsck.k9.crypto.CryptoProvider; import com.fsck.k9.helper.Utility; Loading @@ -40,6 +43,7 @@ import com.fsck.k9.search.SqlQueryBuilder; import com.fsck.k9.search.SearchSpecification.Attribute; import com.fsck.k9.search.SearchSpecification.SearchCondition; import com.fsck.k9.search.SearchSpecification.Searchfield; import com.fsck.k9.security.LocalKeyStore; import com.fsck.k9.view.ColorChip; import com.larswerkman.colorpicker.ColorPicker; Loading Loading @@ -1865,4 +1869,50 @@ public class Account implements BaseAccount { search.and(Searchfield.FOLDER, folderName, Attribute.NOT_EQUALS); } } /** * Add a new certificate for the incoming or outgoing server to the local key store. */ public void addCertificate(CheckDirection direction, X509Certificate certificate) throws CertificateException { Uri uri; if (direction.equals(CheckDirection.INCOMING)) { uri = Uri.parse(getStoreUri()); } else { uri = Uri.parse(getTransportUri()); } LocalKeyStore.getInstance().addCertificate(uri.getHost(), uri.getPort(), certificate); } /** * Examine the existing settings for an account. If the old host/port is different from the * new host/port, then try and delete any (possibly non-existent) certificate stored for the * old host/port. */ public void deleteCertificate(String newHost, int newPort, CheckDirection direction) { Uri uri; if (direction.equals(CheckDirection.INCOMING)) { uri = Uri.parse(getStoreUri()); } else { uri = Uri.parse(getTransportUri()); } String oldHost = uri.getHost(); int oldPort = uri.getPort(); if (!newHost.equals(oldHost) || newPort != oldPort) { LocalKeyStore.getInstance().deleteCertificate(oldHost, oldPort); } } /** * Examine the settings for the account and attempt to delete (possibly non-existent) * certificates for the incoming and outgoing servers. */ public void deleteCertificates() { LocalKeyStore localKeyStore = LocalKeyStore.getInstance(); Uri uri = Uri.parse(getStoreUri()); localKeyStore.deleteCertificate(uri.getHost(), uri.getPort()); uri = Uri.parse(getTransportUri()); localKeyStore.deleteCertificate(uri.getHost(), uri.getPort()); } } src/com/fsck/k9/Preferences.java +1 −1 Original line number Diff line number Diff line Loading @@ -128,8 +128,8 @@ public class Preferences { Store.removeAccount(account); account.deleteCertificates(); account.delete(this); LocalKeyStore.getInstance().deleteCertificates(account); if (newAccount == account) { newAccount = null; Loading src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java +1 −2 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ import com.fsck.k9.mail.Store; import com.fsck.k9.mail.Transport; import com.fsck.k9.mail.store.WebDavStore; import com.fsck.k9.mail.filter.Hex; import com.fsck.k9.security.LocalKeyStore; import java.security.cert.CertificateException; import java.security.cert.CertificateEncodingException; Loading Loading @@ -364,7 +363,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { try { LocalKeyStore.getInstance().addCertificate(mAccount, mDirection, chain[0]); mAccount.addCertificate(mDirection, chain[0]); } catch (CertificateException e) { showErrorDialog( R.string.account_setup_failed_dlg_certificate_message_fmt, Loading src/com/fsck/k9/activity/setup/AccountSetupIncoming.java +1 −2 Original line number Diff line number Diff line Loading @@ -26,7 +26,6 @@ import com.fsck.k9.mail.store.Pop3Store; import com.fsck.k9.mail.store.WebDavStore; import com.fsck.k9.mail.store.ImapStore.ImapStoreSettings; import com.fsck.k9.mail.store.WebDavStore.WebDavStoreSettings; import com.fsck.k9.security.LocalKeyStore; import java.io.UnsupportedEncodingException; import java.net.URI; Loading Loading @@ -429,7 +428,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener mWebdavMailboxPathView.getText().toString()); } LocalKeyStore.getInstance().deleteCertificate(mAccount, host, port, CheckDirection.INCOMING); mAccount.deleteCertificate(host, port, CheckDirection.INCOMING); ServerSettings settings = new ServerSettings(mStoreType, host, port, connectionSecurity, authType, username, password, extra); Loading src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java +1 −2 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ import com.fsck.k9.activity.K9Activity; import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection; import com.fsck.k9.helper.Utility; import com.fsck.k9.mail.transport.SmtpTransport; import com.fsck.k9.security.LocalKeyStore; import java.io.UnsupportedEncodingException; import java.net.URI; Loading Loading @@ -313,7 +312,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, String newHost = mServerView.getText().toString(); int newPort = Integer.parseInt(mPortView.getText().toString()); uri = new URI(smtpSchemes[securityType], userInfo, newHost, newPort, null, null, null); LocalKeyStore.getInstance().deleteCertificate(mAccount, newHost, newPort, CheckDirection.OUTGOING); mAccount.deleteCertificate(newHost, newPort, CheckDirection.OUTGOING); mAccount.setTransportUri(uri.toString()); AccountSetupCheckSettings.actionCheckSettings(this, mAccount, CheckDirection.OUTGOING); } catch (UnsupportedEncodingException enc) { Loading Loading
src/com/fsck/k9/Account.java +50 −0 Original line number Diff line number Diff line package com.fsck.k9; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; Loading @@ -22,6 +24,7 @@ import android.net.ConnectivityManager; import android.net.Uri; import android.util.Log; import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection; import com.fsck.k9.crypto.Apg; import com.fsck.k9.crypto.CryptoProvider; import com.fsck.k9.helper.Utility; Loading @@ -40,6 +43,7 @@ import com.fsck.k9.search.SqlQueryBuilder; import com.fsck.k9.search.SearchSpecification.Attribute; import com.fsck.k9.search.SearchSpecification.SearchCondition; import com.fsck.k9.search.SearchSpecification.Searchfield; import com.fsck.k9.security.LocalKeyStore; import com.fsck.k9.view.ColorChip; import com.larswerkman.colorpicker.ColorPicker; Loading Loading @@ -1865,4 +1869,50 @@ public class Account implements BaseAccount { search.and(Searchfield.FOLDER, folderName, Attribute.NOT_EQUALS); } } /** * Add a new certificate for the incoming or outgoing server to the local key store. */ public void addCertificate(CheckDirection direction, X509Certificate certificate) throws CertificateException { Uri uri; if (direction.equals(CheckDirection.INCOMING)) { uri = Uri.parse(getStoreUri()); } else { uri = Uri.parse(getTransportUri()); } LocalKeyStore.getInstance().addCertificate(uri.getHost(), uri.getPort(), certificate); } /** * Examine the existing settings for an account. If the old host/port is different from the * new host/port, then try and delete any (possibly non-existent) certificate stored for the * old host/port. */ public void deleteCertificate(String newHost, int newPort, CheckDirection direction) { Uri uri; if (direction.equals(CheckDirection.INCOMING)) { uri = Uri.parse(getStoreUri()); } else { uri = Uri.parse(getTransportUri()); } String oldHost = uri.getHost(); int oldPort = uri.getPort(); if (!newHost.equals(oldHost) || newPort != oldPort) { LocalKeyStore.getInstance().deleteCertificate(oldHost, oldPort); } } /** * Examine the settings for the account and attempt to delete (possibly non-existent) * certificates for the incoming and outgoing servers. */ public void deleteCertificates() { LocalKeyStore localKeyStore = LocalKeyStore.getInstance(); Uri uri = Uri.parse(getStoreUri()); localKeyStore.deleteCertificate(uri.getHost(), uri.getPort()); uri = Uri.parse(getTransportUri()); localKeyStore.deleteCertificate(uri.getHost(), uri.getPort()); } }
src/com/fsck/k9/Preferences.java +1 −1 Original line number Diff line number Diff line Loading @@ -128,8 +128,8 @@ public class Preferences { Store.removeAccount(account); account.deleteCertificates(); account.delete(this); LocalKeyStore.getInstance().deleteCertificates(account); if (newAccount == account) { newAccount = null; Loading
src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java +1 −2 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ import com.fsck.k9.mail.Store; import com.fsck.k9.mail.Transport; import com.fsck.k9.mail.store.WebDavStore; import com.fsck.k9.mail.filter.Hex; import com.fsck.k9.security.LocalKeyStore; import java.security.cert.CertificateException; import java.security.cert.CertificateEncodingException; Loading Loading @@ -364,7 +363,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { try { LocalKeyStore.getInstance().addCertificate(mAccount, mDirection, chain[0]); mAccount.addCertificate(mDirection, chain[0]); } catch (CertificateException e) { showErrorDialog( R.string.account_setup_failed_dlg_certificate_message_fmt, Loading
src/com/fsck/k9/activity/setup/AccountSetupIncoming.java +1 −2 Original line number Diff line number Diff line Loading @@ -26,7 +26,6 @@ import com.fsck.k9.mail.store.Pop3Store; import com.fsck.k9.mail.store.WebDavStore; import com.fsck.k9.mail.store.ImapStore.ImapStoreSettings; import com.fsck.k9.mail.store.WebDavStore.WebDavStoreSettings; import com.fsck.k9.security.LocalKeyStore; import java.io.UnsupportedEncodingException; import java.net.URI; Loading Loading @@ -429,7 +428,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener mWebdavMailboxPathView.getText().toString()); } LocalKeyStore.getInstance().deleteCertificate(mAccount, host, port, CheckDirection.INCOMING); mAccount.deleteCertificate(host, port, CheckDirection.INCOMING); ServerSettings settings = new ServerSettings(mStoreType, host, port, connectionSecurity, authType, username, password, extra); Loading
src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java +1 −2 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ import com.fsck.k9.activity.K9Activity; import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection; import com.fsck.k9.helper.Utility; import com.fsck.k9.mail.transport.SmtpTransport; import com.fsck.k9.security.LocalKeyStore; import java.io.UnsupportedEncodingException; import java.net.URI; Loading Loading @@ -313,7 +312,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, String newHost = mServerView.getText().toString(); int newPort = Integer.parseInt(mPortView.getText().toString()); uri = new URI(smtpSchemes[securityType], userInfo, newHost, newPort, null, null, null); LocalKeyStore.getInstance().deleteCertificate(mAccount, newHost, newPort, CheckDirection.OUTGOING); mAccount.deleteCertificate(newHost, newPort, CheckDirection.OUTGOING); mAccount.setTransportUri(uri.toString()); AccountSetupCheckSettings.actionCheckSettings(this, mAccount, CheckDirection.OUTGOING); } catch (UnsupportedEncodingException enc) { Loading