Skip to content

Commit 482c673

Browse files
Bump org.pgpainless:pgpainless-core from 1.7.6 to 2.0.1 (#3143)
* Bump org.pgpainless:pgpainless-core from 1.7.6 to 2.0.1 Bumps [org.pgpainless:pgpainless-core](https://github.com/pgpainless/pgpainless) from 1.7.6 to 2.0.1. - [Release notes](https://github.com/pgpainless/pgpainless/releases) - [Changelog](https://github.com/pgpainless/pgpainless/blob/main/CHANGELOG.md) - [Commits](pgpainless/pgpainless@1.7.6...2.0.1) --- updated-dependencies: - dependency-name: org.pgpainless:pgpainless-core dependency-version: 2.0.1 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * Migrated code to use PGPainless 2.0.1 * Refactored code * Fixed some tests * Fixed some more tests * Disabled one JUnit test(waining for PGPainless dev response) * Temporary disabled some tests * wip * Fixed ParseAndSavePubKeysFragmentInIsolationTest.testParsingStringSourceWithUnsupportedPublicKeys() * Fixed PrivateKeysListFragmentInIsolationTest.testShowKeyWithManyUserIds() --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: denbond7 <denbond7@gmail.com>
1 parent 9588085 commit 482c673

25 files changed

Lines changed: 284 additions & 170 deletions

FlowCrypt/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ dependencies {
514514
//kotlinx-serialization-core added to fix runtime issue with dependencies conflict.
515515
//Maybe it will be removed in future.
516516
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.9.0")
517-
implementation("org.pgpainless:pgpainless-core:1.7.6")
517+
implementation("org.pgpainless:pgpainless-core:2.0.1")
518518
implementation("org.eclipse.angus:angus-mail:2.0.5")
519519
implementation("org.eclipse.angus:gimap:2.0.5")
520520
implementation("commons-io:commons-io:2.20.0")

FlowCrypt/src/androidTest/java/com/flowcrypt/email/WkdClientTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class WkdClientTest {
5353
genLookupUrlPath(EXISTING_EMAIL) -> {
5454
return MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)
5555
.setBody(
56-
PGPainless.generateKeyRing().simpleEcKeyRing(EXISTING_EMAIL).publicKey.armor()
56+
PGPainless.getInstance().generateKey().simpleEcKeyRing(EXISTING_EMAIL).armor()
5757
)
5858
}
5959

FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/ComposeScreenReloadPublicKeyFlowTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class ComposeScreenReloadPublicKeyFlowTest : BaseComposeScreenTest() {
5959
override val activityScenario: ActivityScenario<*>?
6060
get() = activityScenarioRule.scenario
6161

62-
private val pgpKeyRingDetails = PGPainless.generateKeyRing()
63-
.simpleEcKeyRing(RECIPIENT, TestConstants.DEFAULT_PASSWORD).toPgpKeyRingDetails()
62+
private val pgpKeyRingDetails = PGPainless.getInstance().generateKey()
63+
.simpleEcKeyRing(RECIPIENT, TestConstants.DEFAULT_PASSWORD).pgpKeyRing.toPgpKeyRingDetails()
6464

6565
private val addRecipientsToDatabaseRule = AddRecipientsToDatabaseRule(
6666
listOf(

FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/SubmitPublicKeyToAttesterForImportedKeyDuringSetupFlowTest.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ class SubmitPublicKeyToAttesterForImportedKeyDuringSetupFlowTest : BaseSignTest(
7878

7979
@Before
8080
fun prepareResources() {
81-
val generatedKey = PGPainless.generateKeyRing().simpleEcKeyRing(
82-
UserId.nameAndEmail(USER_ENFORCE_ATTESTER_SUBMIT, USER_ENFORCE_ATTESTER_SUBMIT),
81+
val generatedKey = PGPainless.getInstance().generateKey()
82+
.simpleEcKeyRing(
83+
UserId.nameAndEmail(USER_ENFORCE_ATTESTER_SUBMIT, USER_ENFORCE_ATTESTER_SUBMIT),
8384
TestConstants.DEFAULT_STRONG_PASSWORD
84-
).toPgpKeyRingDetails()
85+
).pgpKeyRing.toPgpKeyRingDetails()
8586

8687
privateKey = requireNotNull(generatedKey.privateKey)
8788
fileWithPrivateKey = TestGeneralUtil.createFileWithTextContent(

FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/base/BaseGmailApiTest.kt

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,26 +1766,31 @@ abstract class BaseGmailApiTest(val accountEntity: AccountEntity = BASE_ACCOUNT_
17661766
const val DEFAULT_CC_RECIPIENT = "Cc <default_cc@flowcrypt.test>"
17671767
const val DEFAULT_BCC_RECIPIENT = "Bcc <default_bcc@flowcrypt.test>"
17681768

1769-
val existingCcPgpKeyDetails = PGPainless.generateKeyRing().simpleEcKeyRing(
1769+
val existingCcPgpKeyDetails = PGPainless.getInstance().generateKey()
1770+
.simpleEcKeyRing(
17701771
EXISTING_MESSAGE_CC_RECIPIENT,
17711772
TestConstants.DEFAULT_PASSWORD
1772-
).toPgpKeyRingDetails()
1773-
val defaultFromPgpKeyDetails = PGPainless.generateKeyRing().simpleEcKeyRing(
1773+
).pgpKeyRing.toPgpKeyRingDetails()
1774+
val defaultFromPgpKeyDetails = PGPainless.getInstance().generateKey()
1775+
.simpleEcKeyRing(
17741776
DEFAULT_FROM_RECIPIENT,
17751777
TestConstants.DEFAULT_PASSWORD
1776-
).toPgpKeyRingDetails()
1777-
val defaultToPgpKeyDetails = PGPainless.generateKeyRing().simpleEcKeyRing(
1778+
).pgpKeyRing.toPgpKeyRingDetails()
1779+
val defaultToPgpKeyDetails = PGPainless.getInstance().generateKey()
1780+
.simpleEcKeyRing(
17781781
DEFAULT_TO_RECIPIENT,
17791782
TestConstants.DEFAULT_PASSWORD
1780-
).toPgpKeyRingDetails()
1781-
val defaultCcPgpKeyDetails = PGPainless.generateKeyRing().simpleEcKeyRing(
1783+
).pgpKeyRing.toPgpKeyRingDetails()
1784+
val defaultCcPgpKeyDetails = PGPainless.getInstance().generateKey()
1785+
.simpleEcKeyRing(
17821786
DEFAULT_CC_RECIPIENT,
17831787
TestConstants.DEFAULT_PASSWORD
1784-
).toPgpKeyRingDetails()
1785-
val defaultBccPgpKeyDetails = PGPainless.generateKeyRing().simpleEcKeyRing(
1788+
).pgpKeyRing.toPgpKeyRingDetails()
1789+
val defaultBccPgpKeyDetails = PGPainless.getInstance().generateKey()
1790+
.simpleEcKeyRing(
17861791
DEFAULT_BCC_RECIPIENT,
17871792
TestConstants.DEFAULT_PASSWORD
1788-
).toPgpKeyRingDetails()
1793+
).pgpKeyRing.toPgpKeyRingDetails()
17891794

17901795
val secretKeyRingProtector = SecretKeyRingProtector.unlockAnyKeyWith(
17911796
Passphrase.fromPassword(TestConstants.DEFAULT_PASSWORD)
@@ -1836,4 +1841,4 @@ abstract class BaseGmailApiTest(val accountEntity: AccountEntity = BASE_ACCOUNT_
18361841
), useAPI = true, useCustomerFesUrl = true
18371842
)
18381843
}
1839-
}
1844+
}

FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/base/BasePublicKeyDetailsTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ abstract class BasePublicKeyDetailsTest : BaseTest(), AddAccountToDatabaseRuleIn
5959
)
6060

6161
val bitStrength =
62-
if (keyRingInfo.publicKey.bitStrength != -1) keyRingInfo.publicKey.bitStrength else null
62+
if (keyRingInfo.primaryKey.pgpPublicKey.bitStrength != -1) keyRingInfo.primaryKey.pgpPublicKey.bitStrength else null
6363
val algoWithBits = keyRingInfo.algorithm.name + (bitStrength?.let { "/$it" } ?: "")
6464

6565
onView(withId(R.id.textViewPrimaryKeyAlgorithm))
@@ -251,4 +251,4 @@ abstract class BasePublicKeyDetailsTest : BaseTest(), AddAccountToDatabaseRuleIn
251251
)
252252
}
253253
}
254-
}
254+
}

FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/fragment/isolation/incontainer/PrivateKeysListFragmentInIsolationTest.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
/*
22
* © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
3-
* Contributors: DenBond7
3+
* Contributors: denbond7
44
*/
55

66
package com.flowcrypt.email.ui.fragment.isolation.incontainer
77

88
import androidx.test.espresso.Espresso.onView
99
import androidx.test.espresso.assertion.ViewAssertions.matches
10-
import androidx.test.espresso.matcher.ViewMatchers.*
10+
import androidx.test.espresso.matcher.ViewMatchers.Visibility
11+
import androidx.test.espresso.matcher.ViewMatchers.hasSibling
12+
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
13+
import androidx.test.espresso.matcher.ViewMatchers.withChild
14+
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
15+
import androidx.test.espresso.matcher.ViewMatchers.withId
16+
import androidx.test.espresso.matcher.ViewMatchers.withText
1117
import androidx.test.ext.junit.runners.AndroidJUnit4
1218
import androidx.test.filters.MediumTest
1319
import com.flowcrypt.email.R
@@ -219,9 +225,9 @@ class PrivateKeysListFragmentInIsolationTest : BaseTest() {
219225
),
220226
statusLabelText = getResString(R.string.valid),
221227
statusLabelIconResId = R.drawable.ic_baseline_gpp_good_16,
222-
statusLabelTintColorResId = R.color.colorAccent,
228+
statusLabelTintColorResId = R.color.gray,
223229
usableForEncryption = false,
224-
usableForSigning = true
230+
usableForSigning = false
225231
)
226232
}
227233

FlowCrypt/src/main/java/com/flowcrypt/email/FlowCryptApplication.kt

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import org.acra.data.StringFormat
4242
import org.acra.ktx.initAcra
4343
import org.acra.sender.HttpSender
4444
import org.pgpainless.PGPainless
45+
import org.pgpainless.policy.Policy
4546
import org.pgpainless.policy.Policy.HashAlgorithmPolicy
4647
import java.util.Calendar
4748
import java.util.concurrent.TimeUnit
@@ -84,10 +85,12 @@ class FlowCryptApplication : Application(), Configuration.Provider {
8485
}
8586

8687
private fun setupPGPainless() {
87-
enableDeprecatedSHA1ForPGPainlessPolicy()
88-
89-
//https://github.com/FlowCrypt/flowcrypt-android/issues/2111
90-
PGPainless.getPolicy().enableKeyParameterValidation = true
88+
PGPainless.setInstance(
89+
PGPainless(algorithmPolicy = generatePGPainlessPolicy().apply {
90+
//https://github.com/FlowCrypt/flowcrypt-android/issues/2111
91+
PGPainless.getInstance().algorithmPolicy.enableKeyParameterValidation = true
92+
})
93+
)
9194
}
9295

9396
private fun setupGlobalSettingsForJavaMail() {
@@ -106,21 +109,20 @@ class FlowCryptApplication : Application(), Configuration.Provider {
106109
* More details here https://github.com/FlowCrypt/flowcrypt-android/issues/1478 and here
107110
* https://github.com/pgpainless/pgpainless/issues/158
108111
*/
109-
private fun enableDeprecatedSHA1ForPGPainlessPolicy() {
110-
@Suppress("KotlinConstantConditions")
111-
if (BuildConfig.FLAVOR == Constants.FLAVOR_NAME_ENTERPRISE) {
112-
PGPainless.getPolicy().dataSignatureHashAlgorithmPolicy =
113-
HashAlgorithmPolicy.static2022SignatureHashAlgorithmPolicy()
114-
115-
PGPainless.getPolicy().certificationSignatureHashAlgorithmPolicy =
116-
HashAlgorithmPolicy.static2022SignatureHashAlgorithmPolicy()
117-
} else {
118-
PGPainless.getPolicy().dataSignatureHashAlgorithmPolicy =
119-
HashAlgorithmPolicy.static2022RevocationSignatureHashAlgorithmPolicy()
120-
121-
PGPainless.getPolicy().certificationSignatureHashAlgorithmPolicy =
122-
HashAlgorithmPolicy.static2022RevocationSignatureHashAlgorithmPolicy()
123-
}
112+
@Suppress("KotlinConstantConditions")
113+
private fun generatePGPainlessPolicy(): Policy {
114+
val isEnterpriseBuild = BuildConfig.FLAVOR == Constants.FLAVOR_NAME_ENTERPRISE
115+
val strongPolicySince2022 = HashAlgorithmPolicy.static2022SignatureHashAlgorithmPolicy()
116+
val policyBefore2022Standard =
117+
HashAlgorithmPolicy.static2022RevocationSignatureHashAlgorithmPolicy()
118+
return Policy.Builder(PGPainless.getInstance().algorithmPolicy)
119+
.withDataSignatureHashAlgorithmPolicy(
120+
if (isEnterpriseBuild) strongPolicySince2022 else policyBefore2022Standard
121+
)
122+
.withCertificationSignatureHashAlgorithmPolicy(
123+
if (isEnterpriseBuild) strongPolicySince2022 else policyBefore2022Standard
124+
)
125+
.build()
124126
}
125127

126128
private fun setupKeysStorage() {
@@ -134,6 +136,7 @@ class FlowCryptApplication : Application(), Configuration.Provider {
134136
}
135137
}
136138

139+
@Suppress("KotlinConstantConditions")
137140
private fun initACRA() {
138141
if (GeneralUtil.isDebugBuild()) {
139142
val isAcraEnabled = SharedPreferencesHelper.getBoolean(
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
3+
* Contributors: denbond7
4+
*/
5+
6+
package com.flowcrypt.email.extensions.org.bouncycastle.openpgp
7+
8+
import com.flowcrypt.email.security.SecurityUtils
9+
import org.bouncycastle.openpgp.api.OpenPGPCertificate
10+
import org.pgpainless.bouncycastle.extensions.encode
11+
import java.io.IOException
12+
13+
/**
14+
* @author Denys Bondarenko
15+
*/
16+
@Throws(IOException::class)
17+
fun OpenPGPCertificate.armor(hideArmorMeta: Boolean = false): String =
18+
SecurityUtils.armor(hideArmorMeta) { this.encode(it) }

FlowCrypt/src/main/java/com/flowcrypt/email/extensions/org/bouncycastle/openpgp/PGPKeyRingExt.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ import java.time.Instant
3939
@WorkerThread
4040
fun PGPKeyRing.toPgpKeyRingDetails(hideArmorMeta: Boolean = false): PgpKeyRingDetails {
4141
if (containsHashAlgorithmWithSHA1()) {
42-
val sigHashAlgoPolicy = PGPainless.getPolicy().certificationSignatureHashAlgorithmPolicy
42+
val sigHashAlgoPolicy =
43+
PGPainless.getInstance().algorithmPolicy.certificationSignatureHashAlgorithmPolicy
4344
if (!sigHashAlgoPolicy.isAcceptable(HashAlgorithm.SHA1)) {
4445
throw PGPException("Unsupported signature(HashAlgorithm = SHA1)")
4546
}
@@ -50,7 +51,11 @@ fun PGPKeyRing.toPgpKeyRingDetails(hideArmorMeta: Boolean = false): PgpKeyRingDe
5051
val algo = Algo(
5152
algorithm = keyRingInfo.algorithm.name,
5253
algorithmId = keyRingInfo.algorithm.algorithmId,
53-
bits = if (keyRingInfo.publicKey.bitStrength != -1) keyRingInfo.publicKey.bitStrength else 0,
54+
bits = if (keyRingInfo.primaryKey.pgpPublicKey.bitStrength != -1) {
55+
keyRingInfo.primaryKey.pgpPublicKey.bitStrength
56+
} else {
57+
0
58+
},
5459
curve = runCatching { publicKey.getCurveName() }.getOrNull()
5560
)
5661

@@ -85,11 +90,13 @@ fun PGPKeyRing.toPgpKeyRingDetails(hideArmorMeta: Boolean = false): PgpKeyRingDe
8590
lastModified = keyRingInfo.lastModified.time,
8691
expiration = keyRingInfo.primaryKeyExpirationDate?.time,
8792
algo = algo,
88-
primaryKeyId = keyRingInfo.keyId,
93+
primaryKeyId = keyRingInfo.keyIdentifier.keyId,
8994
possibilities = mutableSetOf<Int>().apply {
9095
addAll(
91-
keyRingInfo.publicKeys.flatMap { keyRingInfo.getKeyFlagsOf(it.keyID) }.toSet()
92-
.map { it.flag })
96+
keyRingInfo.publicKeys.flatMap { openPGPComponentKey ->
97+
keyRingInfo.getKeyFlagsOf(openPGPComponentKey.keyIdentifier)
98+
}.toSet().map { it.flag }
99+
)
93100
}
94101
)
95102
}

0 commit comments

Comments
 (0)