diff --git a/FlowCrypt/build.gradle.kts b/FlowCrypt/build.gradle.kts index 58722edafb..115884ad10 100644 --- a/FlowCrypt/build.gradle.kts +++ b/FlowCrypt/build.gradle.kts @@ -58,7 +58,6 @@ android { versionName = rootProject.extra["appVersionName"] as String testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" buildConfigField("int", "MIN_SDK_VERSION", "$minSdk") - multiDexEnabled = true } signingConfigs { @@ -143,7 +142,7 @@ android { testBuildType = "uiTests" sourceSets { - getByName("androidTest").assets.srcDir("$projectDir/schemas") + getByName("androidTest").assets.directories.add("$projectDir/schemas") } flavorDimensions += "standard" @@ -449,8 +448,8 @@ tasks.register("copyReleaseApks") { } } -val devDebugImplementation: Configuration by configurations.creating -val uiTestsImplementation by configurations.named("uiTestsImplementation") +val devDebugImplementation: Configuration = configurations.create("devDebugImplementation") +val uiTestsImplementation = configurations.named("uiTestsImplementation") dependencies { ksp("com.github.bumptech.glide:ksp:5.0.9") diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/SendMsgTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/SendMsgTest.kt index 03da70853b..ad1f2a0074 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/SendMsgTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/SendMsgTest.kt @@ -499,7 +499,7 @@ class SendMsgTest { 0, ).sortedArray() - val actualIds = messageMetadata.recipientKeyIds.toTypedArray().sortedArray() + val actualIds = messageMetadata.recipientKeyIdentifiers.map { it.keyId }.toTypedArray().sortedArray() assertArrayEquals( "Expected = ${expectedIds.contentToString()}, actual = ${actualIds.contentToString()}", @@ -508,7 +508,7 @@ class SendMsgTest { ) assertFalse( - messageMetadata.recipientKeyIds.contains( + messageMetadata.recipientKeyIdentifiers.map { it.keyId }.contains( PgpKey.parseKeys(bccPgpKeyDetails.publicKey) .pgpKeyRingCollection .pgpPublicKeyRingCollection diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/WkdClientTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/WkdClientTest.kt index 408a161bd0..e2b2d93f2a 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/WkdClientTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/WkdClientTest.kt @@ -24,6 +24,7 @@ import okhttp3.mockwebserver.RecordedRequest import org.apache.commons.codec.binary.ZBase32 import org.apache.commons.codec.digest.DigestUtils import org.junit.Assert.assertNull +import org.junit.Assert.assertThrows import org.junit.Assert.assertTrue import org.junit.Ignore import org.junit.Rule @@ -32,6 +33,7 @@ import org.junit.rules.RuleChain import org.junit.rules.TestRule import org.junit.runner.RunWith import org.pgpainless.PGPainless +import java.io.IOException import java.net.HttpURLConnection @SmallTest @@ -57,6 +59,15 @@ class WkdClientTest { ) } + genLookupUrlPath(OVERSIZED_RESPONSE_EMAIL) -> { + val armoredKey = PGPainless.getInstance().generateKey() + .simpleEcKeyRing(OVERSIZED_RESPONSE_EMAIL).toCertificate().toAsciiArmoredString() + val body = buildString { + while (length <= WkdClient.MAX_RESPONSE_SIZE_IN_BYTES) append(armoredKey) + } + return MockResponse().setResponseCode(HttpURLConnection.HTTP_OK).setBody(body) + } + genLookupUrlPath(NOT_EXISTING_EMAIL) -> { return MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_FOUND) .setBody( @@ -109,10 +120,22 @@ class WkdClientTest { assertNull("Key found for non-existing domain", keys) } + @Test + fun oversizedResponseTest() { + val exception = assertThrows(IOException::class.java) { + runBlocking { WkdClient.lookupEmail(context, OVERSIZED_RESPONSE_EMAIL) } + } + assertTrue( + "Unexpected error: ${exception.message}", + exception.message?.contains("exceeds the limit") == true + ) + } + companion object { const val EXISTING_EMAIL = "existing@flowcrypt.test" const val NOT_EXISTING_EMAIL = "not_existing@flowcrypt.test" + const val OVERSIZED_RESPONSE_EMAIL = "oversized_response@flowcrypt.test" private fun genLookupUrlPath(email: String): String { val user = email.substringBefore("@") diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/base/BaseComposeGmailFlow.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/base/BaseComposeGmailFlow.kt index 656e7e2aa4..5de9e69bd9 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/base/BaseComposeGmailFlow.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/base/BaseComposeGmailFlow.kt @@ -233,7 +233,7 @@ abstract class BaseComposeGmailFlow(accountEntity: AccountEntity = BASE_ACCOUNT_ }.toTypedArray().sortedArray() val actualIds = - messageMetadata.recipientKeyIds.toTypedArray().sortedArray() + messageMetadata.recipientKeyIdentifiers.map { it.keyId }.toTypedArray().sortedArray() assertArrayEquals( "Expected = ${finalExpectedIds.contentToString()}, actual = ${actualIds.contentToString()}", @@ -243,7 +243,7 @@ abstract class BaseComposeGmailFlow(accountEntity: AccountEntity = BASE_ACCOUNT_ if (outgoingMessageConfiguration.bcc.isNotEmpty()) { //https://github.com/FlowCrypt/flowcrypt-android/issues/2306 - assertFalse(messageMetadata.recipientKeyIds.contains(extractKeyId(defaultBccPgpKeyDetails))) + assertFalse(messageMetadata.recipientKeyIdentifiers.map { it.keyId }.contains(extractKeyId(defaultBccPgpKeyDetails))) } } diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/PasswordProtectedEncryptedComposeGmailApiFlow.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/PasswordProtectedEncryptedComposeGmailApiFlow.kt index 62d52b0a32..7b71ff24c3 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/PasswordProtectedEncryptedComposeGmailApiFlow.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/PasswordProtectedEncryptedComposeGmailApiFlow.kt @@ -292,7 +292,7 @@ class PasswordProtectedEncryptedComposeGmailApiFlow : BaseComposeGmailFlow() { assertFalse(decryptionResult.isSigned) //check that message was not encrypted by public keys //ref https://github.com/pgpainless/pgpainless/issues/376 - assertTrue(decryptionResult.messageMetadata?.recipientKeyIds?.isEmpty() == true) + assertTrue(decryptionResult.messageMetadata?.recipientKeyIdentifiers?.isEmpty() == true) val decryptedContent = decryptionResult.content assertNotNull(decryptedContent) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/EmailUtil.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/EmailUtil.kt index 853cbc122c..64f9cb50cb 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/EmailUtil.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/EmailUtil.kt @@ -1315,8 +1315,10 @@ class EmailUtil { val replyToMessageEntityId = info.replyToMessageEntityId ?: throw IllegalArgumentException("replyToMessageEntityId is null") - val keys = PGPainless.readKeyRing() - .secretKeyRingCollection(accountEntity.servicePgpPrivateKey) + val keys = PGPSecretKeyRingCollection( + PGPainless.getInstance().readKey().parseKeys(accountEntity.servicePgpPrivateKey) + .map { it.pgpSecretKeyRing } + ) val replyToMessageEntity = FlowCryptRoomDatabase.getDatabase(context).msgDao().getMsgById(replyToMessageEntityId) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/MsgsCacheManager.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/MsgsCacheManager.kt index 7c24795571..0a5ea2e96e 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/MsgsCacheManager.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/MsgsCacheManager.kt @@ -18,6 +18,7 @@ import kotlinx.coroutines.withContext import okio.FileSystem import okio.Path.Companion.toOkioPath import okio.buffer +import org.bouncycastle.openpgp.PGPPublicKeyRingCollection import org.pgpainless.PGPainless import java.io.File import java.io.IOException @@ -110,8 +111,10 @@ object MsgsCacheManager { PgpEncryptAndOrSign.encryptAndOrSign( destOutputStream = bufferedSink.outputStream(), - pgpPublicKeyRingCollection = PGPainless.readKeyRing() - .publicKeyRingCollection(accountEntity.servicePgpPrivateKey) + pgpPublicKeyRingCollection = PGPPublicKeyRingCollection( + PGPainless.getInstance().readKey().parseKeys(accountEntity.servicePgpPrivateKey) + .map { it.getPGPPublicKeyRing() } + ) ) { out -> out.use { outputStream -> action.invoke(outputStream) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/api/wkd/WkdClient.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/api/wkd/WkdClient.kt index 93e9009939..6cb41c58ba 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/api/wkd/WkdClient.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/api/wkd/WkdClient.kt @@ -9,6 +9,7 @@ package com.flowcrypt.email.api.wkd import android.content.Context import com.flowcrypt.email.api.retrofit.ApiHelper import com.flowcrypt.email.api.retrofit.RetrofitApiServiceInterface +import com.flowcrypt.email.extensions.java.io.readBytesWithLimit import com.flowcrypt.email.extensions.kotlin.isValidEmail import com.flowcrypt.email.util.BetterInternetAddress import kotlinx.coroutines.Dispatchers @@ -27,6 +28,7 @@ import java.util.concurrent.TimeUnit object WkdClient { private const val DEFAULT_REQUEST_TIMEOUT = 4000L + internal const val MAX_RESPONSE_SIZE_IN_BYTES = 1024 * 1024 suspend fun lookupEmail(context: Context, email: String): PGPPublicKeyRingCollection? = withContext(Dispatchers.IO) { @@ -119,7 +121,12 @@ object WkdClient { if (!wkdResponse.isSuccessful || incomingBytes == null) { return@withContext UrlLookupResult(true) } else { - val keys = PGPainless.readKeyRing().publicKeyRingCollection(incomingBytes) + // parseKeysOrCertificates() reads the whole stream into memory, so limit the response size + val responseBytes = incomingBytes.use { it.readBytesWithLimit(MAX_RESPONSE_SIZE_IN_BYTES) } + val keys = PGPPublicKeyRingCollection( + PGPainless.getInstance().readKey().parseKeysOrCertificates(responseBytes) + .map { it.getPGPPublicKeyRing() } + ) return@withContext UrlLookupResult(true, keys) } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/ViewExt.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/ViewExt.kt index a834e1d5f2..61ac7b7104 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/ViewExt.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/ViewExt.kt @@ -14,7 +14,7 @@ import android.view.inputmethod.InputMethodManager */ fun View.showKeyboard() { val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager - imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT) + imm.showSoftInput(this, 0) } fun View.hideKeyboard() { diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/com/flowcrypt/email/util/DiskLruCacheSnapshotExt.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/com/flowcrypt/email/util/DiskLruCacheSnapshotExt.kt index 724d0aa790..451eb9cc7c 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/com/flowcrypt/email/util/DiskLruCacheSnapshotExt.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/com/flowcrypt/email/util/DiskLruCacheSnapshotExt.kt @@ -15,6 +15,7 @@ import com.flowcrypt.email.security.pgp.PgpMsg import com.flowcrypt.email.util.cache.DiskLruCache import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext +import org.bouncycastle.openpgp.PGPSecretKeyRingCollection import org.pgpainless.PGPainless import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector import org.pgpainless.util.Passphrase @@ -34,8 +35,10 @@ suspend fun DiskLruCache.Snapshot.processing( val inputStream = context.contentResolver.openInputStream(uri) ?: throw java.lang.IllegalStateException() - val keys = PGPainless.readKeyRing() - .secretKeyRingCollection(accountEntity.servicePgpPrivateKey) + val keys = PGPSecretKeyRingCollection( + PGPainless.getInstance().readKey().parseKeys(accountEntity.servicePgpPrivateKey) + .map { it.pgpSecretKeyRing } + ) val decryptionStream = PgpDecryptAndOrVerify.genDecryptionStream( srcInputStream = inputStream, diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/java/io/InputStreamExt.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/java/io/InputStreamExt.kt index 639ee5046a..ff7eaa51b0 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/java/io/InputStreamExt.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/java/io/InputStreamExt.kt @@ -6,9 +6,32 @@ package com.flowcrypt.email.extensions.java.io +import java.io.ByteArrayOutputStream +import java.io.IOException import java.io.InputStream import java.nio.charset.Charset import java.nio.charset.StandardCharsets fun InputStream.readText(charset: Charset = StandardCharsets.UTF_8): String = String(readBytes(), charset) + +/** + * Read all bytes, but fail with [IOException] as soon as more than [maxBytes] bytes were read. + * Use it for untrusted sources where the size of the content is not known in advance. + */ +fun InputStream.readBytesWithLimit(maxBytes: Int): ByteArray { + require(maxBytes >= 0) { "maxBytes must not be negative" } + val output = ByteArrayOutputStream() + val buffer = ByteArray(DEFAULT_BUFFER_SIZE) + var total = 0L + while (true) { + val read = read(buffer) + if (read == -1) break + total += read + if (total > maxBytes) { + throw IOException("The stream exceeds the limit of $maxBytes bytes") + } + output.write(buffer, 0, read) + } + return output.toByteArray() +} diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/kotlin/IterableExt.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/kotlin/IterableExt.kt index 1691d8096f..79913c871b 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/kotlin/IterableExt.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/kotlin/IterableExt.kt @@ -19,7 +19,10 @@ fun Iterable?.toPGPPublicKeyRingCollection(): PGPPublicKeyRingCollection? val keysStream = ByteArrayInputStream(this.joinToString(separator = "\n").toByteArray()) return keysStream.use { ArmoredInputStream(it).use { armoredInputStream -> - PGPainless.readKeyRing().publicKeyRingCollection(armoredInputStream) + PGPPublicKeyRingCollection( + PGPainless.getInstance().readKey().parseKeysOrCertificates(armoredInputStream) + .map { it.getPGPPublicKeyRing() } + ) } } } @@ -29,7 +32,10 @@ fun Iterable?.toPGPSecretKeyRingCollection(): PGPSecretKeyRingCollection? val keysStream = ByteArrayInputStream(this.joinToString(separator = "\n").toByteArray()) return keysStream.use { ArmoredInputStream(it).use { armoredInputStream -> - PGPainless.readKeyRing().secretKeyRingCollection(armoredInputStream) + PGPSecretKeyRingCollection( + PGPainless.getInstance().readKey().parseKeys(armoredInputStream) + .map { it.pgpSecretKeyRing } + ) } } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/org/bouncycastle/openpgp/PGPSecretKeyRingExt.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/org/bouncycastle/openpgp/PGPSecretKeyRingExt.kt index 7be1753443..d2695afc20 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/org/bouncycastle/openpgp/PGPSecretKeyRingExt.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/org/bouncycastle/openpgp/PGPSecretKeyRingExt.kt @@ -10,5 +10,5 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing import org.pgpainless.key.util.KeyRingUtils fun PGPSecretKeyRing.toPublicKeyRing(): PGPPublicKeyRing { - return KeyRingUtils.publicKeyRingFrom(this) + return KeyRingUtils.publicKeys(this) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/DraftViewModel.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/DraftViewModel.kt index be3ed18e53..d240398b37 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/DraftViewModel.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/DraftViewModel.kt @@ -45,6 +45,7 @@ import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import org.bouncycastle.openpgp.PGPSecretKeyRingCollection import org.pgpainless.PGPainless import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector import org.pgpainless.util.Passphrase @@ -211,8 +212,10 @@ class DraftViewModel( ?.let { fileUri -> (getApplication() as Context).contentResolver?.openInputStream(fileUri) ?.let { inputStream -> - val keys = PGPainless.readKeyRing() - .secretKeyRingCollection(activeAccount.servicePgpPrivateKey) + val keys = PGPSecretKeyRingCollection( + PGPainless.getInstance().readKey().parseKeys(activeAccount.servicePgpPrivateKey) + .map { it.pgpSecretKeyRing } + ) val decryptionStream = PgpDecryptAndOrVerify.genDecryptionStream( srcInputStream = inputStream, diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/EmailAndNameWorker.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/EmailAndNameWorker.kt index 06aa5712e3..2da59818bc 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/EmailAndNameWorker.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/EmailAndNameWorker.kt @@ -34,14 +34,14 @@ class EmailAndNameWorker(context: Context, params: WorkerParameters) : BaseWorke private var recipientDao: RecipientDao = FlowCryptRoomDatabase.getDatabase(context).recipientDao() override suspend fun doWork(): Result { - val emails = inputData.getStringArray(EXTRA_KEY_EMAILS) ?: return Result.failure() - val names = inputData.getStringArray(EXTRA_KEY_NAMES) ?: return Result.failure() + val emails = inputData.getNullableStringArray(EXTRA_KEY_EMAILS) ?: return Result.failure() + val names = inputData.getNullableStringArray(EXTRA_KEY_NAMES) ?: return Result.failure() if (emails.size != names.size) return Result.failure() for (i in emails.indices) { - val email = emails[i].lowercase() - val name = names[i].takeIf { it.isNotEmpty() } + val email = emails[i]?.lowercase() ?: continue + val name = names[i]?.takeIf { it.isNotEmpty() } val recipientEntity = recipientDao.getRecipientByEmailSuspend(email) if (recipientEntity != null) { if (recipientEntity.name.isNullOrEmpty()) { diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/security/KeysStorageImpl.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/security/KeysStorageImpl.kt index 94cd12b325..8ab7c0492a 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/security/KeysStorageImpl.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/security/KeysStorageImpl.kt @@ -162,20 +162,12 @@ class KeysStorageImpl private constructor(context: Context) : KeysStorage { override fun getSecretKeyRingProtector(): SecretKeyRingProtector { val availablePGPSecretKeyRings = getPGPSecretKeyRings() val passphraseProvider = object : SecretKeyPassphraseProvider { - override fun getPassphraseFor(keyId: Long): Passphrase? { - return doGetPassphrase(keyId, true) - } - override fun getPassphraseFor(keyIdentifier: KeyIdentifier): Passphrase? { - return getPassphraseFor(keyIdentifier.keyId) - } - - override fun hasPassphrase(keyId: Long): Boolean { - return doGetPassphrase(keyId, false) != null + return doGetPassphrase(keyIdentifier.keyId, true) } override fun hasPassphrase(keyIdentifier: KeyIdentifier): Boolean { - return hasPassphrase(keyIdentifier.keyId) + return doGetPassphrase(keyIdentifier.keyId, false) != null } private fun doGetPassphrase(keyId: Long, throwException: Boolean): Passphrase? { diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpDecryptAndOrVerify.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpDecryptAndOrVerify.kt index 957d2f6aca..f2e25f7be7 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpDecryptAndOrVerify.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpDecryptAndOrVerify.kt @@ -107,7 +107,7 @@ object PgpDecryptAndOrVerify { return api.processMessage() .onInputStream(srcInputStream) .withOptions( - ConsumerOptions.get() + ConsumerOptions.get(api) .setMissingKeyPassphraseStrategy(MissingKeyPassphraseStrategy.THROW_EXCEPTION) .apply { //this one deprecated but we use it and show warning for a user if needed diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpEncryptAndOrSign.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpEncryptAndOrSign.kt index ab75651a77..aaa7c9dab3 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpEncryptAndOrSign.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpEncryptAndOrSign.kt @@ -176,7 +176,7 @@ object PgpEncryptAndOrSign { generateDetachedSignatures: Boolean = false, ): EncryptionStream { val api = PGPainless.getInstance() - val encOpt = EncryptionOptions.get().apply { + val encOpt = EncryptionOptions.get(api).apply { passphrase?.let { addMessagePassphrase(passphrase) } pgpPublicKeyRingCollection?.forEach { addRecipient(it.toOpenPGPCertificate(api.implementation)) @@ -189,7 +189,7 @@ object PgpEncryptAndOrSign { val producerOptions: ProducerOptions = if (passphrase == null && pgpSecretKeyRingCollection?.any() == true) { - ProducerOptions.signAndEncrypt(encOpt, SigningOptions.get().apply { + ProducerOptions.signAndEncrypt(encOpt, SigningOptions.get(api).apply { pgpSecretKeyRingCollection.forEach { pgpSecretKeyRing -> secretKeyRingProtector?.let { protector -> if (generateDetachedSignatures) { diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpKey.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpKey.kt index 208ab16022..f612b5df5f 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpKey.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpKey.kt @@ -174,7 +174,7 @@ object PgpKey { for (keyRing in secretKeyRings) { val protector = SecretKeyRingProtector.unlockEachKeyWith(passphrase, keyRing) for (key in keyRing.secretKeys) { - UnlockSecretKey.unlockSecretKey(key, protector) + UnlockSecretKey.unlockSecretKey(key, protector, PGPainless.getInstance().algorithmPolicy) } } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpMsg.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpMsg.kt index 165ced2482..d6e77add5e 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpMsg.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpMsg.kt @@ -870,11 +870,11 @@ object PgpMsg { if (verifiedSignatures.isEmpty()) { verifiedSignatures.addAll(verifiedSignaturesList) } else { - val keyIdsOfAllVerifiedSignatures = verifiedSignatures.map { it.signingKey.keyId } - val keyIdsOfCurrentVerifiedSignatures = verifiedSignaturesList.map { - it.signingKey.keyId + val signingKeysOfAllVerifiedSignatures = verifiedSignatures.map { it.signingKey } + val signingKeysOfCurrentVerifiedSignatures = verifiedSignaturesList.map { + it.signingKey } - if (keyIdsOfAllVerifiedSignatures != keyIdsOfCurrentVerifiedSignatures) { + if (signingKeysOfAllVerifiedSignatures != signingKeysOfCurrentVerifiedSignatures) { hasMixedSignatures = true verifiedSignatures.addAll(verifiedSignaturesList) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpSignature.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpSignature.kt index e3cd6bd4ab..c7570cf39c 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpSignature.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/security/pgp/PgpSignature.kt @@ -54,7 +54,7 @@ object PgpSignature { val verificationStream = api.processMessage() .onInputStream(srcInputStream) .withOptions( - ConsumerOptions.get() + ConsumerOptions.get(api) .addVerificationCerts(publicKeys.map { api.toCertificate(it) }) .setMultiPassStrategy(InMemoryMultiPassStrategy()) ) @@ -81,7 +81,7 @@ object PgpSignature { val verificationStream = api.processMessage() .onInputStream(srcInputStream) .withOptions( - ConsumerOptions.get() + ConsumerOptions.get(api) .addVerificationOfDetachedSignatures(signatureInputStream) .addVerificationCerts(publicKeys.map { api.toCertificate(it) }) .setMultiPassStrategy(InMemoryMultiPassStrategy()) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/AuthorizeAndSearchBackupsFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/AuthorizeAndSearchBackupsFragment.kt index 48f0e8c647..c4d42185f9 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/AuthorizeAndSearchBackupsFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/AuthorizeAndSearchBackupsFragment.kt @@ -9,7 +9,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.navigation.fragment.navArgs @@ -94,10 +93,10 @@ class AuthorizeAndSearchBackupsFragment : navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf( - KEY_CHECK_ACCOUNT_SETTINGS_RESULT to it, - KEY_RESULT_TYPE to RESULT_TYPE_SETTINGS - ) + Bundle().apply { + putSerializable(KEY_CHECK_ACCOUNT_SETTINGS_RESULT, it) + putInt(KEY_RESULT_TYPE, RESULT_TYPE_SETTINGS) + } ) countingIdlingResource?.decrementSafely(this@AuthorizeAndSearchBackupsFragment) } @@ -120,10 +119,10 @@ class AuthorizeAndSearchBackupsFragment : navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf( - KEY_PRIVATE_KEY_BACKUPS_RESULT to it, - KEY_RESULT_TYPE to RESULT_TYPE_BACKUPS - ) + Bundle().apply { + putSerializable(KEY_PRIVATE_KEY_BACKUPS_RESULT, it) + putInt(KEY_RESULT_TYPE, RESULT_TYPE_BACKUPS) + } ) countingIdlingResource?.decrementSafely(this@AuthorizeAndSearchBackupsFragment) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CheckCredentialsFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CheckCredentialsFragment.kt index af405a3a72..e6462f758b 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CheckCredentialsFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CheckCredentialsFragment.kt @@ -9,7 +9,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.navigation.fragment.navArgs @@ -67,7 +66,9 @@ class CheckCredentialsFragment : BaseFragment() navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf(KEY_CHECK_ACCOUNT_SETTINGS_RESULT to it) + Bundle().apply { + putSerializable(KEY_CHECK_ACCOUNT_SETTINGS_RESULT, it) + } ) countingIdlingResource?.decrementSafely(this@CheckCredentialsFragment) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CheckKeysFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CheckKeysFragment.kt index 483c63957a..7a61f985ae 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CheckKeysFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CheckKeysFragment.kt @@ -11,7 +11,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.annotation.IntDef -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.lifecycle.ViewModel @@ -297,7 +296,10 @@ class CheckKeysFragment : BaseFragment() { navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf(KEY_UNLOCKED_PRIVATE_KEYS to ArrayList(unlockedKeys), KEY_STATE to checkingState) + Bundle().apply { + putParcelableArrayList(KEY_UNLOCKED_PRIVATE_KEYS, ArrayList(unlockedKeys)) + putInt(KEY_STATE, checkingState) + } ) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreateOrImportPrivateKeyDuringSetupFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreateOrImportPrivateKeyDuringSetupFragment.kt index dfc0d3c98e..1974c4c703 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreateOrImportPrivateKeyDuringSetupFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreateOrImportPrivateKeyDuringSetupFragment.kt @@ -10,7 +10,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.annotation.IntDef -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.setFragmentResultListener import androidx.navigation.NavDirections @@ -94,11 +93,11 @@ class CreateOrImportPrivateKeyDuringSetupFragment : navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf( - KEY_STATE to result, - KEY_PRIVATE_KEYS to ArrayList(keys), - KEY_ACCOUNT to account - ) + Bundle().apply { + putInt(KEY_STATE, result) + putParcelableArrayList(KEY_PRIVATE_KEYS, ArrayList(keys)) + putParcelable(KEY_ACCOUNT, account) + } ) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreatePrivateKeyFirstFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreatePrivateKeyFirstFragment.kt index 808e42f432..21a1f97641 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreatePrivateKeyFirstFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreatePrivateKeyFirstFragment.kt @@ -1,6 +1,6 @@ /* * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com - * Contributors: DenBond7 + * Contributors: denbond7 */ package com.flowcrypt.email.ui.activity.fragment @@ -12,7 +12,6 @@ import android.view.View import android.view.ViewGroup import android.view.inputmethod.EditorInfo import androidx.core.content.ContextCompat -import androidx.core.os.bundleOf import androidx.core.widget.addTextChangedListener import androidx.fragment.app.setFragmentResult import androidx.fragment.app.setFragmentResultListener @@ -111,7 +110,10 @@ class CreatePrivateKeyFirstFragment : navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf(KEY_CREATED_KEY to pgpKeyRingDetails, KEY_ACCOUNT to args.accountEntity) + Bundle().apply { + putParcelable(KEY_CREATED_KEY, pgpKeyRingDetails) + putParcelable(KEY_ACCOUNT, args.accountEntity) + } ) } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreatePrivateKeySecondFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreatePrivateKeySecondFragment.kt index 23c904a63e..19a0f0580c 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreatePrivateKeySecondFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreatePrivateKeySecondFragment.kt @@ -10,7 +10,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.view.inputmethod.EditorInfo -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.setFragmentResultListener import androidx.navigation.fragment.navArgs @@ -103,7 +102,7 @@ class CreatePrivateKeySecondFragment : BaseFragment setFragmentResult( args.requestKey, - bundleOf( - KEY_IMPORTED_PRIVATE_KEYS to ArrayList(pair.second), - KEY_INCOMING_BUNDLE to args.bundle - ) + Bundle().apply { + putParcelableArrayList(KEY_IMPORTED_PRIVATE_KEYS, ArrayList(pair.second)) + putBundle(KEY_INCOMING_BUNDLE, args.bundle) + } ) } countingIdlingResource?.decrementSafely(this@ImportAdditionalPrivateKeysFragment) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ImportMissingPublicKeyFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ImportMissingPublicKeyFragment.kt index 5a68ddf47a..723edc3fd8 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ImportMissingPublicKeyFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ImportMissingPublicKeyFragment.kt @@ -10,7 +10,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.navigation.fragment.navArgs @@ -18,12 +17,12 @@ import com.flowcrypt.email.R import com.flowcrypt.email.api.retrofit.response.base.Result import com.flowcrypt.email.databinding.FragmentImportMissingPublicKeyBinding import com.flowcrypt.email.extensions.androidx.fragment.app.countingIdlingResource -import com.flowcrypt.email.extensions.decrementSafely -import com.flowcrypt.email.extensions.incrementSafely import com.flowcrypt.email.extensions.androidx.fragment.app.launchAndRepeatWithViewLifecycle import com.flowcrypt.email.extensions.androidx.fragment.app.navController import com.flowcrypt.email.extensions.androidx.fragment.app.showFindKeysInClipboardDialogFragment import com.flowcrypt.email.extensions.androidx.fragment.app.showParsePgpKeysFromSourceDialogFragment +import com.flowcrypt.email.extensions.decrementSafely +import com.flowcrypt.email.extensions.incrementSafely import com.flowcrypt.email.jetpack.viewmodel.RecipientsViewModel import com.flowcrypt.email.security.model.PgpKeyRingDetails import com.flowcrypt.email.ui.activity.fragment.base.BaseImportKeyFragment @@ -128,7 +127,7 @@ class ImportMissingPublicKeyFragment : it.data?.let { recipientWithPubKeys -> setFragmentResult( requestKey = args.requestKey, - result = bundleOf(KEY_RECIPIENT_WITH_PUB_KEY to recipientWithPubKeys) + result = Bundle().apply { putParcelable(KEY_RECIPIENT_WITH_PUB_KEY, recipientWithPubKeys) } ) } countingIdlingResource?.decrementSafely(this@ImportMissingPublicKeyFragment) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ImportPrivateKeysDuringSetupFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ImportPrivateKeysDuringSetupFragment.kt index 35ba001165..79d265961e 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ImportPrivateKeysDuringSetupFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ImportPrivateKeysDuringSetupFragment.kt @@ -1,6 +1,6 @@ /* * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com - * Contributors: DenBond7 + * Contributors: denbond7 */ package com.flowcrypt.email.ui.activity.fragment @@ -10,7 +10,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.setFragmentResultListener import androidx.navigation.NavDirections @@ -122,17 +121,22 @@ class ImportPrivateKeysDuringSetupFragment : navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf(KEY_UNLOCKED_PRIVATE_KEYS to keys?.map { - it.copy( - importInfo = (it.importInfo ?: PgpKeyRingDetails.ImportInfo()).copy( - importSourceType = if (activeUri != null) { - KeyImportDetails.SourceType.FILE - } else { - KeyImportDetails.SourceType.CLIPBOARD - } - ), + Bundle().apply { + putParcelableArrayList( + KEY_UNLOCKED_PRIVATE_KEYS, + keys?.map { + it.copy( + importInfo = (it.importInfo ?: PgpKeyRingDetails.ImportInfo()).copy( + importSourceType = if (activeUri != null) { + KeyImportDetails.SourceType.FILE + } else { + KeyImportDetails.SourceType.CLIPBOARD + } + ), + ) + }?.let { ArrayList(it) } ) - }) + } ) } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ProvidePasswordToProtectMsgFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ProvidePasswordToProtectMsgFragment.kt index e25b883ab9..46e746a1e1 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ProvidePasswordToProtectMsgFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ProvidePasswordToProtectMsgFragment.kt @@ -1,6 +1,6 @@ /* * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com - * Contributors: DenBond7 + * Contributors: denbond7 */ package com.flowcrypt.email.ui.activity.fragment @@ -13,17 +13,16 @@ import android.view.inputmethod.EditorInfo import android.widget.CheckedTextView import androidx.core.graphics.BlendModeColorFilterCompat import androidx.core.graphics.BlendModeCompat -import androidx.core.os.bundleOf import androidx.core.widget.addTextChangedListener import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.navigation.fragment.navArgs import com.flowcrypt.email.R import com.flowcrypt.email.databinding.FragmentProvidePasswordToProtectMsgBinding -import com.flowcrypt.email.extensions.hideKeyboard import com.flowcrypt.email.extensions.androidx.fragment.app.launchAndRepeatWithViewLifecycle import com.flowcrypt.email.extensions.androidx.fragment.app.navController import com.flowcrypt.email.extensions.androidx.fragment.app.toast +import com.flowcrypt.email.extensions.hideKeyboard import com.flowcrypt.email.jetpack.viewmodel.WebPortalPasswordStrengthViewModel import com.flowcrypt.email.ui.activity.fragment.base.BaseFragment import com.flowcrypt.email.util.UIUtil @@ -87,7 +86,7 @@ class ProvidePasswordToProtectMsgFragment : navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf(KEY_PASSWORD to (binding?.eTPassphrase?.text ?: "")) + Bundle().apply { putCharSequence(KEY_PASSWORD, binding?.eTPassphrase?.text ?: "") } ) } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/SelectRecipientsFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/SelectRecipientsFragment.kt index 49e7b05fb8..ec6015e306 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/SelectRecipientsFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/SelectRecipientsFragment.kt @@ -1,6 +1,6 @@ /* * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com - * Contributors: DenBond7 + * Contributors: denbond7 */ package com.flowcrypt.email.ui.activity.fragment @@ -13,7 +13,6 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.SearchView -import androidx.core.os.bundleOf import androidx.core.view.MenuHost import androidx.core.view.MenuProvider import androidx.fragment.app.setFragmentResult @@ -27,10 +26,10 @@ import com.flowcrypt.email.api.retrofit.response.base.Result import com.flowcrypt.email.database.entity.RecipientEntity import com.flowcrypt.email.databinding.FragmentSelectRecipientsBinding import com.flowcrypt.email.extensions.androidx.fragment.app.countingIdlingResource -import com.flowcrypt.email.extensions.decrementSafely -import com.flowcrypt.email.extensions.incrementSafely import com.flowcrypt.email.extensions.androidx.fragment.app.navController import com.flowcrypt.email.extensions.androidx.fragment.app.supportActionBar +import com.flowcrypt.email.extensions.decrementSafely +import com.flowcrypt.email.extensions.incrementSafely import com.flowcrypt.email.jetpack.viewmodel.RecipientsViewModel import com.flowcrypt.email.ui.activity.fragment.base.BaseFragment import com.flowcrypt.email.ui.activity.fragment.base.ListProgressBehaviour @@ -59,7 +58,7 @@ class SelectRecipientsFragment : BaseFragment() navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf(KEY_RECIPIENTS to ArrayList(listOf(recipientEntityWithPgpMarker.toRecipientEntity()))) + Bundle().apply { putParcelableArrayList(KEY_RECIPIENTS, ArrayList(listOf(recipientEntityWithPgpMarker.toRecipientEntity()))) } ) } }) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ActionsDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ActionsDialogFragment.kt index a6c88a98e5..5b0da7b4e0 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ActionsDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ActionsDialogFragment.kt @@ -9,7 +9,6 @@ import android.app.AlertDialog import android.app.Dialog import android.content.DialogInterface import android.os.Bundle -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.navigation.fragment.navArgs import com.flowcrypt.email.extensions.androidx.fragment.app.navController @@ -39,10 +38,10 @@ class ActionsDialogFragment : BaseDialogFragment() { navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf( - KEY_REQUEST_RESULT to args.items[which], - KEY_REQUEST_INCOMING_BUNDLE to args.bundle - ) + Bundle().apply { + putParcelable(KEY_REQUEST_RESULT, args.items[which]) + putBundle(KEY_REQUEST_INCOMING_BUNDLE, args.bundle) + } ) } }.create() diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/AddNewUserIdToPrivateKeyDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/AddNewUserIdToPrivateKeyDialogFragment.kt index 97136d77e1..08008320ad 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/AddNewUserIdToPrivateKeyDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/AddNewUserIdToPrivateKeyDialogFragment.kt @@ -11,7 +11,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.appcompat.app.AlertDialog -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.lifecycle.ViewModel @@ -108,7 +107,7 @@ class AddNewUserIdToPrivateKeyDialogFragment : BaseDialogFragment(), ProgressBeh if (it.data == true) { setFragmentResult( args.requestKey, - bundleOf(KEY_RESULT to args.fingerprint) + Bundle().apply { putString(KEY_RESULT, args.fingerprint) } ) } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ChoosePrivateKeyDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ChoosePrivateKeyDialogFragment.kt index bac7df0f4c..4d9b14f201 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ChoosePrivateKeyDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ChoosePrivateKeyDialogFragment.kt @@ -11,7 +11,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.appcompat.app.AlertDialog -import androidx.core.os.bundleOf import androidx.core.util.size import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels @@ -136,7 +135,7 @@ class ChoosePrivateKeyDialogFragment : BaseDialogFragment(), ListProgressBehavio private fun sendResult(fingerprints: List) { setFragmentResult( args.requestKey, - bundleOf(KEY_RESULT to fingerprints.toTypedArray()) + Bundle().apply { putStringArray(KEY_RESULT, fingerprints.toTypedArray()) } ) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ChoosePublicKeyDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ChoosePublicKeyDialogFragment.kt index d65e794e3a..aa06c74d06 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ChoosePublicKeyDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ChoosePublicKeyDialogFragment.kt @@ -15,7 +15,6 @@ import android.view.ViewGroup import android.widget.ListView import android.widget.TextView import androidx.appcompat.app.AlertDialog -import androidx.core.os.bundleOf import androidx.core.util.size import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels @@ -194,10 +193,10 @@ class ChoosePublicKeyDialogFragment : BaseDialogFragment(), View.OnClickListener private fun sendResult(atts: MutableList) { setFragmentResult( args.requestKey, - bundleOf( - KEY_ATTACHMENT_INFO_LIST to atts, - KEY_INCOMING_BUNDLE to args.bundle - ) + Bundle().apply { + putParcelableArrayList(KEY_ATTACHMENT_INFO_LIST, ArrayList(atts)) + putBundle(KEY_INCOMING_BUNDLE, args.bundle) + } ) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/CreatePrivateKeyDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/CreatePrivateKeyDialogFragment.kt index ba2bd80804..f2c69e11ee 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/CreatePrivateKeyDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/CreatePrivateKeyDialogFragment.kt @@ -10,7 +10,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.ViewGroup import androidx.appcompat.app.AlertDialog -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.navigation.fragment.navArgs @@ -98,7 +97,7 @@ class CreatePrivateKeyDialogFragment : BaseDialogFragment() { navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf(KEY_CREATED_KEY to pgpKeyRingDetails) + Bundle().apply { putParcelable(KEY_CREATED_KEY, pgpKeyRingDetails) } ) } countingIdlingResource?.decrementSafely(this@CreatePrivateKeyDialogFragment) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/DecryptAttachmentDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/DecryptAttachmentDialogFragment.kt index 97e7e227f8..785d098706 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/DecryptAttachmentDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/DecryptAttachmentDialogFragment.kt @@ -11,7 +11,6 @@ import android.text.format.DateUtils import android.view.LayoutInflater import android.view.ViewGroup import androidx.appcompat.app.AlertDialog -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.lifecycle.ViewModel @@ -96,16 +95,16 @@ class DecryptAttachmentDialogFragment : BaseDialogFragment() { val newFileName = FilenameUtils.getBaseName(args.attachmentInfo.name) setFragmentResult( args.requestKey, - bundleOf( - KEY_ATTACHMENT to args.attachmentInfo.copy( + Bundle().apply { + putParcelable(KEY_ATTACHMENT, args.attachmentInfo.copy( uri = null, type = newFileName.getPossibleAndroidMimeType() ?: args.attachmentInfo.type, rawData = byteArray, name = newFileName - ), - KEY_REQUEST_CODE to args.requestCode, - KEY_INCOMING_BUNDLE to args.bundle - ) + )) + putInt(KEY_REQUEST_CODE, args.requestCode) + putBundle(KEY_INCOMING_BUNDLE, args.bundle) + } ) } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/DecryptDownloadedAttachmentsBeforeForwardingDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/DecryptDownloadedAttachmentsBeforeForwardingDialogFragment.kt index cf670dbb6c..2ea0d77665 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/DecryptDownloadedAttachmentsBeforeForwardingDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/DecryptDownloadedAttachmentsBeforeForwardingDialogFragment.kt @@ -1,6 +1,6 @@ /* * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com - * Contributors: DenBond7 + * Contributors: denbond7 */ package com.flowcrypt.email.ui.activity.fragment.dialog @@ -10,7 +10,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.ViewGroup import androidx.appcompat.app.AlertDialog -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.lifecycle.ViewModel @@ -18,8 +17,8 @@ import androidx.navigation.fragment.navArgs import com.flowcrypt.email.R import com.flowcrypt.email.api.retrofit.response.base.Result import com.flowcrypt.email.databinding.FragmentDecryptDownloadedAttachmentsBeforeForwardingBinding -import com.flowcrypt.email.extensions.launchAndRepeatWithLifecycle import com.flowcrypt.email.extensions.androidx.fragment.app.navController +import com.flowcrypt.email.extensions.launchAndRepeatWithLifecycle import com.flowcrypt.email.extensions.visible import com.flowcrypt.email.jetpack.lifecycle.CustomAndroidViewModelFactory import com.flowcrypt.email.jetpack.viewmodel.DecryptDownloadedAttachmentsBeforeForwardingViewModel @@ -79,10 +78,10 @@ class DecryptDownloadedAttachmentsBeforeForwardingDialogFragment : BaseDialogFra navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf( - KEY_REQUEST_KEY to args.requestKey, - KEY_RESULT to it, - ) + Bundle().apply { + putString(KEY_REQUEST_KEY, args.requestKey) + putSerializable(KEY_RESULT, it) + } ) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/DeleteDraftDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/DeleteDraftDialogFragment.kt index fa64caa868..8ed4031caa 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/DeleteDraftDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/DeleteDraftDialogFragment.kt @@ -11,7 +11,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.appcompat.app.AlertDialog -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.lifecycle.ViewModel @@ -103,10 +102,10 @@ class DeleteDraftDialogFragment : BaseDialogFragment(), ProgressBehaviour { navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf( - KEY_REQUEST_KEY to args.requestKey, - KEY_RESULT to args.uniqueId, - ) + Bundle().apply { + putString(KEY_REQUEST_KEY, args.requestKey) + putLong(KEY_RESULT, args.uniqueId) + } ) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/DownloadAttachmentDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/DownloadAttachmentDialogFragment.kt index 2f2842d8db..5123020294 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/DownloadAttachmentDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/DownloadAttachmentDialogFragment.kt @@ -11,7 +11,6 @@ import android.text.format.DateUtils import android.view.LayoutInflater import android.view.ViewGroup import androidx.appcompat.app.AlertDialog -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.lifecycle.ViewModel @@ -107,8 +106,8 @@ class DownloadAttachmentDialogFragment : BaseDialogFragment() { it.data?.let { byteArray -> setFragmentResult( args.requestKey, - bundleOf( - KEY_ATTACHMENT to args.attachmentInfo.copy( + Bundle().apply { + putParcelable(KEY_ATTACHMENT, args.attachmentInfo.copy( rawData = byteArray, name = finalName, type = if (args.attachmentInfo.isPossiblyEncrypted) { @@ -121,10 +120,10 @@ class DownloadAttachmentDialogFragment : BaseDialogFragment() { } else { args.attachmentInfo.type }, - ), - KEY_REQUEST_CODE to args.requestCode, - KEY_INCOMING_BUNDLE to args.bundle - ) + )) + putInt(KEY_REQUEST_CODE, args.requestCode) + putBundle(KEY_INCOMING_BUNDLE, args.bundle) + } ) } countingIdlingResource?.decrementSafely(this@DownloadAttachmentDialogFragment) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/EditScreenshotDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/EditScreenshotDialogFragment.kt index a526655da4..6bb8c955fc 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/EditScreenshotDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/EditScreenshotDialogFragment.kt @@ -1,6 +1,6 @@ /* * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com - * Contributors: DenBond7 + * Contributors: denbond7 */ package com.flowcrypt.email.ui.activity.fragment.dialog @@ -14,7 +14,6 @@ import android.view.ViewGroup import androidx.appcompat.app.AlertDialog import androidx.core.content.ContextCompat import androidx.core.graphics.ColorUtils -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.navigation.fragment.navArgs import com.flowcrypt.email.R @@ -68,7 +67,7 @@ class EditScreenshotDialogFragment : BaseDialogFragment() { navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf(KEY_SCREENSHOT to UIUtil.getCompressedByteArrayOfBitmap(saveBitmap, 100)) + Bundle().apply { putByteArray(KEY_SCREENSHOT, UIUtil.getCompressedByteArrayOfBitmap(saveBitmap, 100)) } ) } }) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/FindKeysInClipboardDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/FindKeysInClipboardDialogFragment.kt index b367c03903..bc811091cd 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/FindKeysInClipboardDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/FindKeysInClipboardDialogFragment.kt @@ -12,7 +12,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.ViewGroup import androidx.appcompat.app.AlertDialog -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.navigation.fragment.navArgs @@ -127,7 +126,7 @@ class FindKeysInClipboardDialogFragment : BaseDialogFragment() { navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf(KEY_CLIPBOARD_TEXT to clipboardText) + Bundle().apply { putString(KEY_CLIPBOARD_TEXT, clipboardText) } ) } countingIdlingResource?.decrementSafely(this@FindKeysInClipboardDialogFragment) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/FixNeedPassphraseIssueDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/FixNeedPassphraseIssueDialogFragment.kt index 2d086c803d..8e18ce8953 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/FixNeedPassphraseIssueDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/FixNeedPassphraseIssueDialogFragment.kt @@ -13,7 +13,6 @@ import android.view.ViewGroup import android.view.inputmethod.EditorInfo import androidx.annotation.LongDef import androidx.appcompat.app.AlertDialog -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.lifecycle.ViewModel @@ -252,12 +251,12 @@ class FixNeedPassphraseIssueDialogFragment : BaseDialogFragment() { navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf( - KEY_RESULT to unlockedKeysFingerprints.toTypedArray(), - KEY_PREDEFINED_FINGERPRINTS to args.fingerprints, - KEY_REQUEST_CODE to args.requestCode, - KEY_REQUEST_INCOMING_BUNDLE to args.bundle - ) + Bundle().apply { + putStringArray(KEY_RESULT, unlockedKeysFingerprints.toTypedArray()) + putStringArray(KEY_PREDEFINED_FINGERPRINTS, args.fingerprints) + putInt(KEY_REQUEST_CODE, args.requestCode) + putBundle(KEY_REQUEST_INCOMING_BUNDLE, args.bundle) + } ) } } @@ -266,12 +265,12 @@ class FixNeedPassphraseIssueDialogFragment : BaseDialogFragment() { navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf( - KEY_RESULT to unlockedKeysFingerprints.toTypedArray(), - KEY_PREDEFINED_FINGERPRINTS to args.fingerprints, - KEY_REQUEST_CODE to args.requestCode, - KEY_REQUEST_INCOMING_BUNDLE to args.bundle - ) + Bundle().apply { + putStringArray(KEY_RESULT, unlockedKeysFingerprints.toTypedArray()) + putStringArray(KEY_PREDEFINED_FINGERPRINTS, args.fingerprints) + putInt(KEY_REQUEST_CODE, args.requestCode) + putBundle(KEY_REQUEST_INCOMING_BUNDLE, args.bundle) + } ) } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ImportAllPubKeysFromSourceDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ImportAllPubKeysFromSourceDialogFragment.kt index e2a1ab4726..847d0e2876 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ImportAllPubKeysFromSourceDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ImportAllPubKeysFromSourceDialogFragment.kt @@ -1,6 +1,6 @@ /* * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com - * Contributors: DenBond7 + * Contributors: denbond7 */ package com.flowcrypt.email.ui.activity.fragment.dialog @@ -10,7 +10,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.ViewGroup import androidx.appcompat.app.AlertDialog -import androidx.core.os.bundleOf import androidx.fragment.app.activityViewModels import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels @@ -19,11 +18,11 @@ import com.flowcrypt.email.R import com.flowcrypt.email.api.retrofit.response.base.Result import com.flowcrypt.email.databinding.FragmentImportAllPubKeysFromSourceBinding import com.flowcrypt.email.extensions.androidx.fragment.app.countingIdlingResource +import com.flowcrypt.email.extensions.androidx.fragment.app.navController +import com.flowcrypt.email.extensions.androidx.fragment.app.toast import com.flowcrypt.email.extensions.decrementSafely import com.flowcrypt.email.extensions.incrementSafely import com.flowcrypt.email.extensions.launchAndRepeatWithLifecycle -import com.flowcrypt.email.extensions.androidx.fragment.app.navController -import com.flowcrypt.email.extensions.androidx.fragment.app.toast import com.flowcrypt.email.jetpack.viewmodel.CachedPubKeysKeysViewModel import com.flowcrypt.email.jetpack.viewmodel.ImportPubKeysFromSourceSharedViewModel @@ -98,7 +97,7 @@ class ImportAllPubKeysFromSourceDialogFragment : BaseDialogFragment() { navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf(KEY_IMPORT_PUB_KEYS_RESULT to it.data) + Bundle().apply { putBoolean(KEY_IMPORT_PUB_KEYS_RESULT, it.data == true) } ) countingIdlingResource?.decrementSafely(this@ImportAllPubKeysFromSourceDialogFragment) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/InfoDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/InfoDialogFragment.kt index 1dfa7ee158..4b48f0046a 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/InfoDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/InfoDialogFragment.kt @@ -1,6 +1,6 @@ /* * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com - * Contributors: DenBond7 + * Contributors: denbond7 */ package com.flowcrypt.email.ui.activity.fragment.dialog @@ -10,7 +10,6 @@ import android.os.Bundle import android.webkit.WebView import android.widget.TextView import androidx.appcompat.app.AlertDialog -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.navigation.fragment.navArgs import com.flowcrypt.email.R @@ -50,10 +49,10 @@ class InfoDialogFragment : BaseDialogFragment() { args.requestKey?.let { requestKey -> setFragmentResult( requestKey, - bundleOf( - KEY_REQUEST_CODE to args.requestCode, - KEY_REQUEST_INCOMING_BUNDLE to args.bundle - ) + Bundle().apply { + putInt(KEY_REQUEST_CODE, args.requestCode) + putBundle(KEY_REQUEST_INCOMING_BUNDLE, args.bundle) + } ) } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/LookUpPubKeysDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/LookUpPubKeysDialogFragment.kt index 8380abb627..d43e089524 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/LookUpPubKeysDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/LookUpPubKeysDialogFragment.kt @@ -10,7 +10,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.ViewGroup import androidx.appcompat.app.AlertDialog -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.navigation.fragment.navArgs @@ -77,7 +76,7 @@ class LookUpPubKeysDialogFragment : BaseDialogFragment() { it.data?.pubkey.let { pubKeys -> setFragmentResult( args.requestKey, - bundleOf(KEY_PUB_KEYS to pubKeys) + Bundle().apply { putString(KEY_PUB_KEYS, pubKeys) } ) } countingIdlingResource?.decrementSafely(this@LookUpPubKeysDialogFragment) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/NoPgpFoundDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/NoPgpFoundDialogFragment.kt index 9a2610c98d..97b47ae92e 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/NoPgpFoundDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/NoPgpFoundDialogFragment.kt @@ -9,7 +9,6 @@ import android.app.AlertDialog import android.app.Dialog import android.content.DialogInterface import android.os.Bundle -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.navigation.fragment.navArgs import com.flowcrypt.email.R @@ -96,10 +95,10 @@ class NoPgpFoundDialogFragment : BaseDialogFragment(), DialogInterface.OnClickLi navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf( - KEY_REQUEST_RESULT_CODE to dialogItems[which].id, - KEY_REQUEST_RECIPIENT_WITH_PUB_KEYS to args.recipientWithPubKeys - ) + Bundle().apply { + putInt(KEY_REQUEST_RESULT_CODE, dialogItems[which].id) + putParcelable(KEY_REQUEST_RECIPIENT_WITH_PUB_KEYS, args.recipientWithPubKeys) + } ) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ParsePgpKeysFromSourceDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ParsePgpKeysFromSourceDialogFragment.kt index 40f3b286d9..45ca9574e5 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ParsePgpKeysFromSourceDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ParsePgpKeysFromSourceDialogFragment.kt @@ -1,6 +1,6 @@ /* * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com - * Contributors: DenBond7 + * Contributors: denbond7 */ package com.flowcrypt.email.ui.activity.fragment.dialog @@ -11,7 +11,6 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.annotation.LongDef import androidx.appcompat.app.AlertDialog -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.navigation.fragment.navArgs @@ -19,12 +18,12 @@ import com.flowcrypt.email.R import com.flowcrypt.email.api.retrofit.response.base.Result import com.flowcrypt.email.databinding.FragmentParsePgpKeysFromSourceBinding import com.flowcrypt.email.extensions.androidx.fragment.app.countingIdlingResource +import com.flowcrypt.email.extensions.androidx.fragment.app.navController import com.flowcrypt.email.extensions.decrementSafely import com.flowcrypt.email.extensions.gone import com.flowcrypt.email.extensions.incrementSafely import com.flowcrypt.email.extensions.kotlin.toInputStream import com.flowcrypt.email.extensions.launchAndRepeatWithLifecycle -import com.flowcrypt.email.extensions.androidx.fragment.app.navController import com.flowcrypt.email.extensions.visible import com.flowcrypt.email.jetpack.viewmodel.ParseKeysViewModel import com.flowcrypt.email.ui.activity.fragment.dialog.ParsePgpKeysFromSourceDialogFragment.FilterType.Companion.ALL @@ -118,7 +117,9 @@ class ParsePgpKeysFromSourceDialogFragment : BaseDialogFragment() { navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf(KEY_PARSED_KEYS to keys) + Bundle().apply { + putParcelableArrayList(KEY_PARSED_KEYS, keys?.let { ArrayList(it) }) + } ) } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ProcessMessageDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ProcessMessageDialogFragment.kt index f20fbb6859..263fc614f1 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ProcessMessageDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/ProcessMessageDialogFragment.kt @@ -11,7 +11,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.appcompat.app.AlertDialog -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.lifecycle.ViewModel @@ -111,12 +110,12 @@ class ProcessMessageDialogFragment : BaseDialogFragment(), ProgressBehaviour { navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf( - KEY_REQUEST_KEY to args.requestKey, - KEY_REQUEST_CODE to args.requestCode, - KEY_RESULT to it.data, - KEY_ATTACHMENT_ID to args.attachmentId, - ) + Bundle().apply { + putString(KEY_REQUEST_KEY, args.requestKey) + putInt(KEY_REQUEST_CODE, args.requestCode) + putParcelable(KEY_RESULT, it.data) + putString(KEY_ATTACHMENT_ID, args.attachmentId) + } ) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/SendFeedbackDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/SendFeedbackDialogFragment.kt index 4565a6b3bb..b64ad67a92 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/SendFeedbackDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/SendFeedbackDialogFragment.kt @@ -11,7 +11,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.appcompat.app.AlertDialog -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.navigation.fragment.navArgs @@ -83,7 +82,7 @@ class SendFeedbackDialogFragment : BaseDialogFragment() { navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf(KEY_RESULT to true) + Bundle().apply { putBoolean(KEY_RESULT, true) } ) countingIdlingResource?.decrementSafely(this@SendFeedbackDialogFragment) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/TwoWayDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/TwoWayDialogFragment.kt index 1342c9d8e1..7c9455002d 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/TwoWayDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/TwoWayDialogFragment.kt @@ -8,7 +8,6 @@ package com.flowcrypt.email.ui.activity.fragment.dialog import android.app.Dialog import android.os.Bundle import androidx.appcompat.app.AlertDialog -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.navigation.fragment.navArgs import com.flowcrypt.email.extensions.androidx.fragment.app.navController @@ -65,11 +64,11 @@ class TwoWayDialogFragment : BaseDialogFragment() { args.requestKey?.let { requestKey -> setFragmentResult( requestKey, - bundleOf( - KEY_REQUEST_CODE to args.requestCode, - KEY_RESULT to result, - KEY_REQUEST_INCOMING_BUNDLE to args.bundle - ) + Bundle().apply { + putInt(KEY_REQUEST_CODE, args.requestCode) + putInt(KEY_RESULT, result) + putBundle(KEY_REQUEST_INCOMING_BUNDLE, args.bundle) + } ) } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/UpdatePrivateKeyDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/UpdatePrivateKeyDialogFragment.kt index 562f76c6b4..6a536bd710 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/UpdatePrivateKeyDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/UpdatePrivateKeyDialogFragment.kt @@ -5,7 +5,7 @@ package com.flowcrypt.email.ui.activity.fragment.dialog -import androidx.core.os.bundleOf +import android.os.Bundle import androidx.fragment.app.setFragmentResult import androidx.navigation.fragment.navArgs import com.flowcrypt.email.R @@ -26,7 +26,7 @@ class UpdatePrivateKeyDialogFragment : BaseUpdateKeyDialogFragment() { navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf(KEY_NEW_PRIVATE_KEY to args.newPgpKeyRingDetails) + Bundle().apply { putParcelable(KEY_NEW_PRIVATE_KEY, args.newPgpKeyRingDetails) } ) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/UpdateRecipientPublicKeyDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/UpdateRecipientPublicKeyDialogFragment.kt index 2464817644..a40d1fe132 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/UpdateRecipientPublicKeyDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/UpdateRecipientPublicKeyDialogFragment.kt @@ -6,7 +6,6 @@ package com.flowcrypt.email.ui.activity.fragment.dialog import android.os.Bundle -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.navigation.fragment.navArgs @@ -61,7 +60,7 @@ class UpdateRecipientPublicKeyDialogFragment : BaseUpdateKeyDialogFragment() { it.data?.let { isUpdated -> setFragmentResult( args.requestKey, - bundleOf(KEY_UPDATE_RECIPIENT_PUBLIC_KEY to isUpdated) + Bundle().apply { putBoolean(KEY_UPDATE_RECIPIENT_PUBLIC_KEY, isUpdated) } ) } countingIdlingResource?.decrementSafely(this@UpdateRecipientPublicKeyDialogFragment) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/UpdateSignatureDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/UpdateSignatureDialogFragment.kt index d8d7e91400..e2a3fe0338 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/UpdateSignatureDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/UpdateSignatureDialogFragment.kt @@ -10,7 +10,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.ViewGroup import androidx.appcompat.app.AlertDialog -import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.navigation.fragment.navArgs import com.flowcrypt.email.R @@ -55,7 +54,7 @@ class UpdateSignatureDialogFragment : BaseDialogFragment() { navController?.navigateUp() setFragmentResult( args.requestKey, - bundleOf(KEY_SIGNATURE to binding?.editTextSignature?.text?.toString()) + Bundle().apply { putString(KEY_SIGNATURE, binding?.editTextSignature?.text?.toString()) } ) } diff --git a/FlowCrypt/src/test/java/com/flowcrypt/email/ParcelableTest.kt b/FlowCrypt/src/test/java/com/flowcrypt/email/ParcelableTest.kt index b4cbe357d9..a6efe42c58 100644 --- a/FlowCrypt/src/test/java/com/flowcrypt/email/ParcelableTest.kt +++ b/FlowCrypt/src/test/java/com/flowcrypt/email/ParcelableTest.kt @@ -5,6 +5,7 @@ package com.flowcrypt.email +import android.os.Build import android.os.Parcel import android.os.Parcelable import com.flextrade.jfixture.JFixture @@ -131,7 +132,13 @@ class ParcelableTest(val name: String, private val currentClass: Class(this::class.java.classLoader) + val classLoader = this::class.java.classLoader + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + readParcelable(classLoader, Parcelable::class.java) + } else { + @Suppress("DEPRECATION") + readParcelable(classLoader) + } } Assert.assertEquals("$name failed", objectInstance, retainedParcelable) diff --git a/FlowCrypt/src/test/java/com/flowcrypt/email/extensions/java/io/InputStreamExtTest.kt b/FlowCrypt/src/test/java/com/flowcrypt/email/extensions/java/io/InputStreamExtTest.kt new file mode 100644 index 0000000000..f5beba684e --- /dev/null +++ b/FlowCrypt/src/test/java/com/flowcrypt/email/extensions/java/io/InputStreamExtTest.kt @@ -0,0 +1,50 @@ +/* + * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com + * Contributors: denbond7 + */ + +package com.flowcrypt.email.extensions.java.io + +import org.junit.Assert.assertArrayEquals +import org.junit.Assert.assertThrows +import org.junit.Assert.assertTrue +import org.junit.Test +import java.io.IOException +import java.io.InputStream + +class InputStreamExtTest { + + @Test + fun testReadBytesWithLimitReturnsContentWithinLimit() { + val content = ByteArray(LIMIT) { it.toByte() } + assertArrayEquals(content, content.inputStream().readBytesWithLimit(LIMIT)) + } + + @Test + fun testReadBytesWithLimitFailsWhenContentExceedsLimit() { + val stream = EndlessInputStream() + assertThrows(IOException::class.java) { stream.readBytesWithLimit(LIMIT) } + assertTrue( + "The stream was read too far after the limit", + stream.count <= LIMIT + DEFAULT_BUFFER_SIZE + ) + } + + private class EndlessInputStream : InputStream() { + var count = 0L + + override fun read(): Int { + count++ + return 0 + } + + override fun read(b: ByteArray, off: Int, len: Int): Int { + count += len + return len + } + } + + companion object { + private const val LIMIT = 64 * 1024 + } +} diff --git a/FlowCrypt/src/test/java/com/flowcrypt/email/extensions/kotlin/IterableExtTest.kt b/FlowCrypt/src/test/java/com/flowcrypt/email/extensions/kotlin/IterableExtTest.kt new file mode 100644 index 0000000000..0f0ba3ba01 --- /dev/null +++ b/FlowCrypt/src/test/java/com/flowcrypt/email/extensions/kotlin/IterableExtTest.kt @@ -0,0 +1,58 @@ +/* + * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com + * Contributors: denbond7 + */ + +package com.flowcrypt.email.extensions.kotlin + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotNull +import org.junit.Test +import org.pgpainless.PGPainless + +class IterableExtTest { + + @Test + fun testToPGPPublicKeyRingCollectionFromPublicKeys() { + val firstKey = genKey("first@flowcrypt.test") + val secondKey = genKey("second@flowcrypt.test") + + val collection = listOf( + firstKey.toCertificate().toAsciiArmoredString(), + secondKey.toCertificate().toAsciiArmoredString() + ).toPGPPublicKeyRingCollection() + + assertNotNull(collection) + assertEquals(2, collection?.size()) + assertNotNull(collection?.getPublicKeyRing(firstKey.keyIdentifier.keyId)) + assertNotNull(collection?.getPublicKeyRing(secondKey.keyIdentifier.keyId)) + } + + @Test + fun testToPGPPublicKeyRingCollectionFromPrivateKey() { + val key = genKey("private@flowcrypt.test") + + val collection = listOf(key.toAsciiArmoredString()).toPGPPublicKeyRingCollection() + + assertNotNull(collection) + assertEquals(1, collection?.size()) + assertNotNull(collection?.getPublicKeyRing(key.keyIdentifier.keyId)) + } + + @Test + fun testToPGPSecretKeyRingCollectionFromPrivateKeys() { + val firstKey = genKey("first@flowcrypt.test") + val secondKey = genKey("second@flowcrypt.test") + + val collection = listOf( + firstKey.toAsciiArmoredString(), + secondKey.toAsciiArmoredString() + ).toPGPSecretKeyRingCollection() + + assertNotNull(collection) + assertEquals(2, collection?.size()) + } + + private fun genKey(userId: String) = + PGPainless.getInstance().generateKey().simpleEcKeyRing(userId) +} diff --git a/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/PgpDecryptAndOrVerifyTest.kt b/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/PgpDecryptAndOrVerifyTest.kt index a94a018976..f4c2c4dd6c 100644 --- a/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/PgpDecryptAndOrVerifyTest.kt +++ b/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/PgpDecryptAndOrVerifyTest.kt @@ -473,20 +473,12 @@ class PgpDecryptAndOrVerifyTest { .simpleEcKeyRing("receiver@flowcrypt.test", RECEIVER_PASSWORD).pgpKeyRing val passphraseProvider = object : SecretKeyPassphraseProvider { - override fun getPassphraseFor(keyId: Long): Passphrase? { - return doGetPassphrase(keyId) - } - override fun getPassphraseFor(keyIdentifier: KeyIdentifier): Passphrase? { - return getPassphraseFor(keyIdentifier.keyId) - } - - override fun hasPassphrase(keyId: Long): Boolean { - return doGetPassphrase(keyId) != null + return doGetPassphrase(keyIdentifier.keyId) } override fun hasPassphrase(keyIdentifier: KeyIdentifier): Boolean { - return hasPassphrase(keyIdentifier.keyId) + return doGetPassphrase(keyIdentifier.keyId) != null } private fun doGetPassphrase(keyId: Long?): Passphrase? { diff --git a/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/PgpEncryptAndOrSignTest.kt b/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/PgpEncryptAndOrSignTest.kt index 61b292587a..b6db7bfa50 100644 --- a/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/PgpEncryptAndOrSignTest.kt +++ b/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/PgpEncryptAndOrSignTest.kt @@ -13,11 +13,11 @@ import org.junit.Assert.assertArrayEquals import org.junit.BeforeClass import org.junit.Test import org.pgpainless.PGPainless +import org.pgpainless.bouncycastle.extensions.certificate import org.pgpainless.decryption_verification.ConsumerOptions import org.pgpainless.key.protection.KeyRingProtectionSettings import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector import org.pgpainless.key.protection.passphrase_provider.SecretKeyPassphraseProvider -import org.pgpainless.key.util.KeyRingUtils import org.pgpainless.util.Passphrase import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream @@ -30,8 +30,8 @@ class PgpEncryptAndOrSignTest { @Test fun testEncryptFile() { - val senderPgpPublicKeyRing = KeyRingUtils.publicKeyRingFrom(senderPGPSecretKeyRing) - val recipientPgpPublicKeyRing = KeyRingUtils.publicKeyRingFrom(recipientPGPSecretKeyRing) + val senderPgpPublicKeyRing = senderPGPSecretKeyRing.certificate + val recipientPgpPublicKeyRing = recipientPGPSecretKeyRing.certificate val sourceBytes = source.toByteArray() val outputStreamForEncryptedSource = ByteArrayOutputStream() @@ -100,8 +100,8 @@ class PgpEncryptAndOrSignTest { destOutputStream = outputStreamForEncryptedSource, pgpPublicKeyRingCollection = PGPPublicKeyRingCollection( listOf( - KeyRingUtils.publicKeyRingFrom(senderPGPSecretKeyRing), - KeyRingUtils.publicKeyRingFrom(recipientPGPSecretKeyRing) + senderPGPSecretKeyRing.certificate, + recipientPGPSecretKeyRing.certificate ) ), doArmor = true, @@ -123,14 +123,6 @@ class PgpEncryptAndOrSignTest { val protector = PasswordBasedSecretKeyRingProtector( KeyRingProtectionSettings.secureDefaultSettings(), object : SecretKeyPassphraseProvider { - override fun getPassphraseFor(keyId: Long): Passphrase? { - return doGetPassphrase(keyId) - } - - override fun hasPassphrase(keyId: Long): Boolean { - return doGetPassphrase(keyId) != null - } - private fun doGetPassphrase(keyId: Long?): Passphrase? { pgpSecretKeyRing.publicKeys.forEach { publicKey -> if (publicKey.keyID == keyId) { @@ -141,11 +133,11 @@ class PgpEncryptAndOrSignTest { } override fun getPassphraseFor(keyIdentifier: KeyIdentifier): Passphrase? { - return getPassphraseFor(keyIdentifier.keyId) + return doGetPassphrase(keyIdentifier.keyId) } override fun hasPassphrase(keyIdentifier: KeyIdentifier): Boolean { - return hasPassphrase(keyIdentifier.keyId) + return doGetPassphrase(keyIdentifier.keyId) != null } } ) @@ -155,7 +147,7 @@ class PgpEncryptAndOrSignTest { val decryptionStream = api.processMessage() .onInputStream(inputStream) .withOptions( - ConsumerOptions.get() + ConsumerOptions.get(api) .addDecryptionKey(api.toKey(pgpSecretKeyRing), protector) .addVerificationCerts(pgpPublicKeyRingCollection.map { api.toCertificate(it) }) ) diff --git a/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/SamePGPSignatureVerificationMultiThreadingTest.kt b/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/SamePGPSignatureVerificationMultiThreadingTest.kt index 5f8078873f..f3cda4b18c 100644 --- a/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/SamePGPSignatureVerificationMultiThreadingTest.kt +++ b/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/SamePGPSignatureVerificationMultiThreadingTest.kt @@ -12,6 +12,7 @@ import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext +import org.bouncycastle.openpgp.PGPPublicKeyRingCollection import org.bouncycastle.openpgp.PGPSecretKeyRingCollection import org.junit.Assert.assertNotEquals import org.junit.Test @@ -67,8 +68,10 @@ class SamePGPSignatureVerificationMultiThreadingTest { val secretKeyRingProtector = SecretKeyRingProtector.unlockAnyKeyWith( Passphrase.fromPassword(PASSPHRASE) ) - val pgpPublicKeyRingCollection = PGPainless.readKeyRing().publicKeyRingCollection( - SENDER_PUBLIC_KEY + "\n" + RECEIVER_PUBLIC_KEY + val pgpPublicKeyRingCollection = PGPPublicKeyRingCollection( + listOf(SENDER_PUBLIC_KEY, RECEIVER_PUBLIC_KEY).map { + PGPainless.getInstance().readKey().parseCertificate(it).pgpPublicKeyRing + } ) val secretKeyRingCollection = PGPSecretKeyRingCollection(listOf(secretKeyRing)) @@ -100,9 +103,9 @@ class SamePGPSignatureVerificationMultiThreadingTest { "=osuI\n" + "-----END PGP PRIVATE KEY BLOCK-----" - val secretKeyRing = PGPainless.readKeyRing().secretKeyRing( + val secretKeyRing = PGPainless.getInstance().readKey().parseKey( SENDER_PRIVATE_KEY - ) + ).pgpSecretKeyRing private const val SENDER_PUBLIC_KEY = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + "Version: PGPainless\n" + diff --git a/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/TestKeys.kt b/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/TestKeys.kt index 1a45aeda43..fee1eabc46 100644 --- a/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/TestKeys.kt +++ b/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/TestKeys.kt @@ -16,20 +16,12 @@ import org.pgpainless.util.Passphrase object TestKeys { fun genRingProtector(keys: List): PasswordBasedSecretKeyRingProtector { val passphraseProvider = object : SecretKeyPassphraseProvider { - override fun getPassphraseFor(keyId: Long): Passphrase? { - return doGetPassphrase(keyId) - } - - override fun hasPassphrase(keyId: Long): Boolean { - return doGetPassphrase(keyId) != null - } - override fun getPassphraseFor(keyIdentifier: KeyIdentifier): Passphrase? { - return getPassphraseFor(keyIdentifier.keyId) + return doGetPassphrase(keyIdentifier.keyId) } override fun hasPassphrase(keyIdentifier: KeyIdentifier): Boolean { - return hasPassphrase(keyIdentifier.keyId) + return doGetPassphrase(keyIdentifier.keyId) != null } private fun doGetPassphrase(keyId: Long?): Passphrase? {