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

Unverified Commit e6e0d7c1 authored by Vincent Breitmoser's avatar Vincent Breitmoser Committed by GitHub
Browse files

Merge pull request #3772 from k9mail/cleanup-localkeystore

Clean up LocalKeyStore and related
parents aa8621cc 8fd2b56a
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -65,7 +65,6 @@ object Core : KoinComponent {

    fun init(context: Context) {
        BinaryTempFileBody.setTempDirectory(context.cacheDir)
        LocalKeyStore.setKeyStoreLocation(context.getDir("KeyStore", Context.MODE_PRIVATE).toString())

        setServicesEnabled(context)
        registerReceivers(context)
+8 −0
Original line number Diff line number Diff line
@@ -3,6 +3,10 @@ package com.fsck.k9
import android.content.Context
import com.fsck.k9.helper.Contacts
import com.fsck.k9.mail.power.PowerManager
import com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory
import com.fsck.k9.mail.ssl.LocalKeyStore
import com.fsck.k9.mail.ssl.TrustManagerFactory
import com.fsck.k9.mail.ssl.TrustedSocketFactory
import com.fsck.k9.mailstore.LocalStoreProvider
import com.fsck.k9.mailstore.StorageManager
import com.fsck.k9.power.TracingPowerManager
@@ -15,4 +19,8 @@ val mainModule = applicationContext {
    bean { LocalStoreProvider() }
    bean { TracingPowerManager.getPowerManager(get()) as PowerManager }
    bean { Contacts.getInstance(get()) }
    bean { LocalKeyStore.createInstance(get()) }
    bean { TrustManagerFactory.createInstance(get()) }
    bean { LocalKeyStoreManager(get()) }
    bean { DefaultTrustedSocketFactory(get(), get()) as TrustedSocketFactory }
}
+7 −9
Original line number Diff line number Diff line
@@ -7,18 +7,17 @@ import java.security.cert.CertificateException
import java.security.cert.X509Certificate

class LocalKeyStoreManager(
        val localKeyStore: LocalKeyStore
        private val localKeyStore: LocalKeyStore
) {
    /**
     * Add a new certificate for the incoming or outgoing server to the local key store.
     */
    @Throws(CertificateException::class)
    fun addCertificate(account: Account, direction: MailServerDirection, certificate: X509Certificate) {
        val uri: Uri
        if (direction === MailServerDirection.INCOMING) {
            uri = Uri.parse(account.storeUri)
        val uri = if (direction === MailServerDirection.INCOMING) {
            Uri.parse(account.storeUri)
        } else {
            uri = Uri.parse(account.transportUri)
            Uri.parse(account.transportUri)
        }
        localKeyStore.addCertificate(uri.host, uri.port, certificate)
    }
@@ -29,11 +28,10 @@ class LocalKeyStoreManager(
     * old host/port.
     */
    fun deleteCertificate(account: Account, newHost: String, newPort: Int, direction: MailServerDirection) {
        val uri: Uri
        if (direction === MailServerDirection.INCOMING) {
            uri = Uri.parse(account.storeUri)
        val uri = if (direction === MailServerDirection.INCOMING) {
            Uri.parse(account.storeUri)
        } else {
            uri = Uri.parse(account.transportUri)
            Uri.parse(account.transportUri)
        }
        val oldHost = uri.host
        val oldPort = uri.port
+0 −2
Original line number Diff line number Diff line
@@ -22,8 +22,6 @@ val coreNotificationModule = applicationContext {
        )
    }
    bean { AccountPreferenceSerializer(get(), get()) }
    bean { LocalKeyStore.getInstance() }
    bean { LocalKeyStoreManager(get()) }
    bean { CertificateErrorNotifications(get(), get(), get()) }
    bean { AuthenticationErrorNotifications(get(), get(), get()) }
    bean { SyncNotifications(get(), get(), get()) }
+5 −3
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ import com.fsck.k9.mail.ServerSettings
import com.fsck.k9.mail.oauth.OAuth2TokenProvider
import com.fsck.k9.mail.power.PowerManager
import com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory
import com.fsck.k9.mail.ssl.TrustedSocketFactory
import com.fsck.k9.mail.store.imap.ImapStore
import com.fsck.k9.mail.transport.smtp.SmtpTransport
import com.fsck.k9.mail.transport.smtp.SmtpTransportUriCreator
@@ -21,7 +22,8 @@ import com.fsck.k9.mailstore.K9BackendStorageFactory
class ImapBackendFactory(
        private val context: Context,
        private val powerManager: PowerManager,
        private val backendStorageFactory: K9BackendStorageFactory
        private val backendStorageFactory: K9BackendStorageFactory,
        private val trustedSocketFactory: TrustedSocketFactory
) : BackendFactory {
    override val transportUriPrefix = "smtp"

@@ -39,7 +41,7 @@ class ImapBackendFactory(
        return ImapStore(
                serverSettings,
                account,
                DefaultTrustedSocketFactory(context),
                trustedSocketFactory,
                context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager,
                oAuth2TokenProvider
        )
@@ -48,7 +50,7 @@ class ImapBackendFactory(
    private fun createSmtpTransport(account: Account): SmtpTransport {
        val serverSettings = decodeTransportUri(account.transportUri)
        val oauth2TokenProvider: OAuth2TokenProvider? = null
        return SmtpTransport(serverSettings, account, DefaultTrustedSocketFactory(context), oauth2TokenProvider)
        return SmtpTransport(serverSettings, account, trustedSocketFactory, oauth2TokenProvider)
    }

    override fun decodeStoreUri(storeUri: String): ServerSettings {
Loading