diff --git a/FlowCrypt/build.gradle.kts b/FlowCrypt/build.gradle.kts index 98a07680ab..a136952eeb 100644 --- a/FlowCrypt/build.gradle.kts +++ b/FlowCrypt/build.gradle.kts @@ -468,7 +468,7 @@ dependencies { implementation("org.bitbucket.b_c:jose4j:0.9.6") implementation("org.jsoup:jsoup:1.19.1") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.1") - implementation("org.pgpainless:pgpainless-core:1.7.2") + implementation("org.pgpainless:pgpainless-core:1.7.5") implementation("org.eclipse.angus:angus-mail:2.0.3") implementation("org.eclipse.angus:gimap:2.0.3") implementation("commons-io:commons-io:2.18.0") diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/fragment/isolation/incontainer/ParseAndSavePubKeysFragmentInIsolationTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/fragment/isolation/incontainer/ParseAndSavePubKeysFragmentInIsolationTest.kt index 9e643b2f32..b056961e1c 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/fragment/isolation/incontainer/ParseAndSavePubKeysFragmentInIsolationTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/fragment/isolation/incontainer/ParseAndSavePubKeysFragmentInIsolationTest.kt @@ -36,7 +36,6 @@ import com.flowcrypt.email.ui.activity.fragment.ParseAndSavePubKeysFragmentArgs import com.flowcrypt.email.util.PrivateKeysManager import com.flowcrypt.email.util.TestGeneralUtil import com.flowcrypt.email.viewaction.ClickOnViewInRecyclerViewItem -import org.hamcrest.Matchers.allOf import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -85,30 +84,7 @@ class ParseAndSavePubKeysFragmentInIsolationTest : BaseTest() { ) onView(withId(R.id.rVPubKeys)) - .check(matches(withRecyclerViewItemCount(6))) - - onView(withId(R.id.rVPubKeys)) - .check( - matches( - hasItem( - withChild( - allOf( - hasSibling( - withText(getResString(R.string.cannot_be_used_for_encryption)) - ), - hasSibling( - withText( - getResString( - R.string.template_message_part_public_key_owner, - "dsa@flowcrypt.test" - ) - ) - ) - ) - ) - ) - ) - ) + .check(matches(withRecyclerViewItemCount(5))) } @Test diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/org/bouncycastle/openpgp/PGPKeyRingExt.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/org/bouncycastle/openpgp/PGPKeyRingExt.kt index 83d7fe0dc2..06f6235b3c 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/org/bouncycastle/openpgp/PGPKeyRingExt.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/org/bouncycastle/openpgp/PGPKeyRingExt.kt @@ -38,6 +38,13 @@ import java.time.Instant @Throws(IOException::class) @WorkerThread fun PGPKeyRing.toPgpKeyRingDetails(hideArmorMeta: Boolean = false): PgpKeyRingDetails { + if (containsHashAlgorithmWithSHA1()) { + val sigHashAlgoPolicy = PGPainless.getPolicy().certificationSignatureHashAlgorithmPolicy + if (!sigHashAlgoPolicy.isAcceptable(HashAlgorithm.SHA1)) { + throw PGPException("Unsupported signature(HashAlgorithm = SHA1)") + } + } + val keyRingInfo = KeyRingInfo(this) val algo = Algo( @@ -56,13 +63,6 @@ fun PGPKeyRing.toPgpKeyRingDetails(hideArmorMeta: Boolean = false): PgpKeyRingDe throw IllegalArgumentException("There are no fingerprints") } - if (containsHashAlgorithmWithSHA1()) { - val sigHashAlgoPolicy = PGPainless.getPolicy().certificationSignatureHashAlgorithmPolicy - if (!sigHashAlgoPolicy.isAcceptable(HashAlgorithm.SHA1)) { - throw PGPException("Unsupported signature(HashAlgorithm = SHA1)") - } - } - val privateKey = if (keyRingInfo.isSecretKey) armor(hideArmorMeta = hideArmorMeta) else null val publicKey = if (keyRingInfo.isSecretKey) { (this as PGPSecretKeyRing).toPublicKeyRing().armor(hideArmorMeta = hideArmorMeta) diff --git a/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/PgpKeyTest.kt b/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/PgpKeyTest.kt index c27c825da6..ba95726f26 100644 --- a/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/PgpKeyTest.kt +++ b/FlowCrypt/src/test/java/com/flowcrypt/email/security/pgp/PgpKeyTest.kt @@ -81,8 +81,13 @@ class PgpKeyTest { ) val parseKeyResult = PgpKey.parseKeys(source = TestKeys.KEYS["rsa1"]!!.publicKey) assertEquals(1, parseKeyResult.getAllKeys().size) - val actual = parseKeyResult.pgpKeyDetailsList.first() - .run { this.copy(publicKey = replaceVersionInKey(this.publicKey)) } + val actual = parseKeyResult.pgpKeyDetailsList.first().copy( + /* + * we replace publicKey source here because it can't be a constant. + * If other fields of [PgpKeyRingDetails] will be the same it means objects are equal + */ + publicKey = expected.publicKey + ) assertEquals(expected, actual) } @@ -122,8 +127,13 @@ class PgpKeyTest { ) val parseKeyResult = PgpKey.parseKeys(source = TestKeys.KEYS["expired"]!!.publicKey) assertEquals(1, parseKeyResult.getAllKeys().size) - val actual = parseKeyResult.pgpKeyDetailsList.first() - .run { this.copy(publicKey = replaceVersionInKey(this.publicKey)) } + val actual = parseKeyResult.pgpKeyDetailsList.first().copy( + /* + * we replace publicKey source here because it can't be a constant. + * If other fields of [PgpKeyRingDetails] will be the same it means objects are equal + */ + publicKey = expected.publicKey + ) assertEquals(expected, actual) }