Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion FlowCrypt/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ dependencies {
implementation 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20200713.1'
implementation 'org.jsoup:jsoup:1.14.1'

implementation ('org.pgpainless:pgpainless-core:0.2.3') {
implementation ('org.pgpainless:pgpainless-core:0.2.4') {
//exclude group: 'org.bouncycastle' because we will specify it manually
exclude group: 'org.bouncycastle'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.flowcrypt.email.util.exception.DecryptionException
import org.bouncycastle.openpgp.PGPDataValidationException
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection
import org.pgpainless.PGPainless
import org.pgpainless.decryption_verification.ConsumerOptions
import org.pgpainless.decryption_verification.OpenPgpMetadata
import org.pgpainless.exception.MessageNotIntegrityProtectedException
import org.pgpainless.exception.MissingDecryptionMethodException
Expand Down Expand Up @@ -41,10 +42,10 @@ object PgpDecrypt {
try {
val decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(srcStream)
.decryptWith(protector, pgpSecretKeyRingCollection)
.doNotVerify()
.build()

.withOptions(
ConsumerOptions()
.addDecryptionKeys(pgpSecretKeyRingCollection, protector)
)
decryptionStream.use { it.copyTo(outStream) }
return decryptionStream.result
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import org.json.JSONObject
import org.jsoup.Jsoup
import org.owasp.html.HtmlPolicyBuilder
import org.pgpainless.PGPainless
import org.pgpainless.decryption_verification.ConsumerOptions
import org.pgpainless.exception.MessageNotIntegrityProtectedException
import org.pgpainless.exception.ModificationDetectionException
import org.pgpainless.key.info.KeyRingInfo
Expand Down Expand Up @@ -249,15 +250,13 @@ object PgpMsg {

val exception: Exception?
try {
val d = PGPainless.decryptAndOrVerify()
.onInputStream(input)
.decryptWith(UnprotectedKeysProtector(), PGPSecretKeyRingCollection(keyList))
val consumerOptions = ConsumerOptions()
.addDecryptionKeys(PGPSecretKeyRingCollection(keyList), UnprotectedKeysProtector())
pgpPublicKeyRingCollection?.let { consumerOptions.addVerificationCerts(it) }

val decryptionStream = if (pgpPublicKeyRingCollection != null) {
d.verifyWith(pgpPublicKeyRingCollection).ignoreMissingPublicKeys().build()
} else {
d.doNotVerify().build()
}
val decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(input)
.withOptions(consumerOptions)

val output = ByteArrayOutputStream()
decryptionStream.use { it.copyTo(output) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.junit.Assert.assertArrayEquals
import org.junit.BeforeClass
import org.junit.Test
import org.pgpainless.PGPainless
import org.pgpainless.decryption_verification.ConsumerOptions
import org.pgpainless.key.protection.KeyRingProtectionSettings
import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector
import org.pgpainless.key.util.KeyRingUtils
Expand Down Expand Up @@ -97,10 +98,11 @@ class PgpEncryptTest {

val decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(inputStream)
.decryptWith(protector, PGPSecretKeyRingCollection(listOf(pgpSecretKeyRing)))
.verifyWith(pgpPublicKeyRingCollection)
.ignoreMissingPublicKeys()
.build()
.withOptions(
ConsumerOptions()
.addDecryptionKeys(PGPSecretKeyRingCollection(listOf(pgpSecretKeyRing)), protector)
.addVerificationCerts(pgpPublicKeyRingCollection)
)

val outputStreamWithDecryptedData = ByteArrayOutputStream()
decryptionStream.use { it.copyTo(outputStreamWithDecryptedData) }
Expand Down