Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cedcd7e4 authored by Joe Steele's avatar Joe Steele
Browse files

Eliminate the need to pass a context to LocalKeyStore.getInstance

Instead, have K9.onCreate initialize the location of the key
store file (similar to what is done with
BinaryTempFileBody.setTempDirectory).

Also, LocalKeyStore.getInstance has been changed so that it
no longer needs to be synchronized.
parent 9333f4f7
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -1873,7 +1873,7 @@ public class Account implements BaseAccount {
    /**
     * Add a new certificate for the incoming or outgoing server to the local key store.
     */
    public void addCertificate(Context context, CheckDirection direction,
    public void addCertificate(CheckDirection direction,
            X509Certificate certificate) throws CertificateException {
        Uri uri;
        if (direction.equals(CheckDirection.INCOMING)) {
@@ -1881,7 +1881,7 @@ public class Account implements BaseAccount {
        } else {
            uri = Uri.parse(getTransportUri());
        }
        LocalKeyStore localKeyStore = LocalKeyStore.getInstance(context);
        LocalKeyStore localKeyStore = LocalKeyStore.getInstance();
        localKeyStore.addCertificate(uri.getHost(), uri.getPort(), certificate);
    }

@@ -1890,7 +1890,7 @@ public class Account implements BaseAccount {
     * new host/port, then try and delete any (possibly non-existent) certificate stored for the
     * old host/port.
     */
    public void deleteCertificate(Context context, String newHost, int newPort,
    public void deleteCertificate(String newHost, int newPort,
            CheckDirection direction) {
        Uri uri;
        if (direction.equals(CheckDirection.INCOMING)) {
@@ -1905,7 +1905,7 @@ public class Account implements BaseAccount {
            return;
        }
        if (!newHost.equals(oldHost) || newPort != oldPort) {
            LocalKeyStore localKeyStore = LocalKeyStore.getInstance(context);
            LocalKeyStore localKeyStore = LocalKeyStore.getInstance();
            localKeyStore.deleteCertificate(oldHost, oldPort);
        }
    }
@@ -1914,8 +1914,8 @@ public class Account implements BaseAccount {
     * Examine the settings for the account and attempt to delete (possibly non-existent)
     * certificates for the incoming and outgoing servers.
     */
    public void deleteCertificates(Context context) {
        LocalKeyStore localKeyStore = LocalKeyStore.getInstance(context);
    public void deleteCertificates() {
        LocalKeyStore localKeyStore = LocalKeyStore.getInstance();

        Uri uri = Uri.parse(getStoreUri());
        localKeyStore.deleteCertificate(uri.getHost(), uri.getPort());
+3 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.internet.BinaryTempFileBody;
import com.fsck.k9.mail.store.LocalStore;
import com.fsck.k9.provider.UnreadWidgetProvider;
import com.fsck.k9.security.LocalKeyStore;
import com.fsck.k9.service.BootReceiver;
import com.fsck.k9.service.MailService;
import com.fsck.k9.service.ShutdownReceiver;
@@ -590,6 +591,8 @@ public class K9 extends Application {
         */
        BinaryTempFileBody.setTempDirectory(getCacheDir());

        LocalKeyStore.setKeyStoreLocation(getDir("KeyStore", MODE_PRIVATE).toString());

        /*
         * Enable background sync of messages
         */
+1 −2
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@ import android.util.Log;
import com.fsck.k9.mail.Store;
import com.fsck.k9.preferences.Editor;
import com.fsck.k9.preferences.Storage;
import com.fsck.k9.security.LocalKeyStore;

public class Preferences {

@@ -128,7 +127,7 @@ public class Preferences {

        Store.removeAccount(account);

        account.deleteCertificates(mContext);
        account.deleteCertificates();
        account.delete(this);

        if (newAccount == account) {
+1 −1
Original line number Diff line number Diff line
@@ -363,7 +363,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        try {
                            mAccount.addCertificate(getApplicationContext(), mDirection, chain[0]);
                            mAccount.addCertificate(mDirection, chain[0]);
                        } catch (CertificateException e) {
                            showErrorDialog(
                                R.string.account_setup_failed_dlg_certificate_message_fmt,
+1 −1
Original line number Diff line number Diff line
@@ -428,7 +428,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
                        mWebdavMailboxPathView.getText().toString());
            }

            mAccount.deleteCertificate(this, host, port, CheckDirection.INCOMING);
            mAccount.deleteCertificate(host, port, CheckDirection.INCOMING);
            ServerSettings settings = new ServerSettings(mStoreType, host, port,
                    connectionSecurity, authType, username, password, extra);

Loading