Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 15
issue #1347 Detect wrong armor checksum#1371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
7dcd645b5bf11c51646e2175d99b5875e663912ab7e5c3108File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -31,7 +31,6 @@ import com.flowcrypt.email.extensions.org.bouncycastle.openpgp.armor | ||
| import com.flowcrypt.email.extensions.org.bouncycastle.openpgp.toPgpKeyDetails | ||
| import com.flowcrypt.email.extensions.org.owasp.html.allowAttributesOnElementsExt | ||
| import com.flowcrypt.email.security.pgp.PgpArmor.ARMOR_HEADER_DICT | ||
| import org.bouncycastle.bcpg.ArmoredInputStream | ||
| import org.bouncycastle.bcpg.PacketTags | ||
| import org.bouncycastle.openpgp.PGPDataValidationException | ||
| import org.bouncycastle.openpgp.PGPException | ||
| @@ -54,6 +53,7 @@ import org.pgpainless.key.info.KeyRingInfo | ||
| import org.pgpainless.key.protection.UnprotectedKeysProtector | ||
| import org.pgpainless.util.Passphrase | ||
| import java.io.ByteArrayOutputStream | ||
| import java.io.IOException | ||
| import java.io.InputStream | ||
| import java.nio.charset.StandardCharsets | ||
| import java.util.Locale | ||
| @@ -202,9 +202,8 @@ object PgpMsg { | ||
| ) | ||
| } | ||
| val input = data.inputStream() | ||
| val chunk = data.copyOfRange(0, data.size.coerceAtMost(50)).toString(StandardCharsets.US_ASCII) | ||
| var input = data.inputStream() as InputStream | ||
| if (chunk.contains(ARMOR_HEADER_DICT[MsgBlock.Type.SIGNED_MSG]!!.begin)) { | ||
| val msg: PgpArmor.CleartextSignedMessage | ||
| try { | ||
| @@ -227,9 +226,6 @@ object PgpMsg { | ||
| return DecryptionResult.withCleartext(msg.content, msg.signature) | ||
| } | ||
| val isArmored = chunk.contains(ARMOR_HEADER_DICT[MsgBlock.Type.ENCRYPTED_MSG]!!.begin) | ||
| if (isArmored) input = ArmoredInputStream(input) | ||
| val keyList: List<PGPSecretKeyRing> | ||
| try { | ||
| keyList = keys.map { | ||
| @@ -252,20 +248,26 @@ object PgpMsg { | ||
| ) | ||
| } | ||
| val exception: Exception? | ||
| try { | ||
| val consumerOptions = ConsumerOptions() | ||
| .addDecryptionKeys(PGPSecretKeyRingCollection(keyList), UnprotectedKeysProtector()) | ||
| pgpPublicKeyRingCollection?.let { consumerOptions.addVerificationCerts(it) } | ||
| val decryptionStream = PGPainless.decryptAndOrVerify() | ||
| .onInputStream(input) | ||
| .withOptions(consumerOptions) | ||
| val output = ByteArrayOutputStream() | ||
| decryptionStream.use { it.copyTo(output) } | ||
| val streamResult = decryptionStream.result | ||
| return DecryptionResult.withDecrypted(output, streamResult.fileName) | ||
| try { | ||
| decryptionStream.use { it.copyTo(output) } | ||
| } catch (ex: IOException) { | ||
| val message = ex.message | ||
| if (message != null && message.contains("crc check not found")) { | ||
| decryptionStream.close() | ||
| } else { | ||
| throw ex | ||
| } | ||
| } | ||
| return DecryptionResult.withDecrypted(output, decryptionStream.result.fileName) | ||
| } catch (ex: MessageNotIntegrityProtectedException) { | ||
| return DecryptionResult.withError( | ||
| type = PgpDecrypt.DecryptionErrorType.NO_MDC, | ||
| @@ -294,10 +296,28 @@ object PgpMsg { | ||
| message = "There is no suitable decryption key" | ||
| ) | ||
| } | ||
| // other PGP error, fallback to default error return in the bottom | ||
| exception = ex | ||
| } catch (ex: Exception) { | ||
| if ( | ||
| ex is IOException && | ||
| ex.message?.contains("crc check failed in armored message") == true | ||
Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does | ||
| ) { | ||
| return DecryptionResult.withError( | ||
| type = PgpDecrypt.DecryptionErrorType.FORMAT, | ||
| message = "Armor CRC check failed" | ||
| ) | ||
| } else { | ||
| exception = ex | ||
| } | ||
| } | ||
| var message = "Decryption failed" | ||
| if (exception != null) { | ||
| message = "$message: ${exception.javaClass.canonicalName}: ${exception.message}" | ||
| } | ||
| return DecryptionResult.withError( | ||
| type = PgpDecrypt.DecryptionErrorType.OTHER, | ||
| message = "Decryption failed" | ||
| message = message | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| -----BEGIN PGP MESSAGE----- | ||
| Version: FlowCrypt 5.0.4 Gmail Encryption flowcrypt.com | ||
| Comment: Seamlessly send, receive and search encrypted email | ||
| wcFMA+ADv/5v4RgKAQ/+K2rrAqhjMe9FLCfklI9Y30Woktg0Q/xe71EVw6WO | ||
| tVD/VK+xv4CHzi+HojtE0U2F+vqoPSO0q5TN9giKPMTiK25PnCzfd7Q+zXiF | ||
| j+5RSHTVJxC62qLHhtKsAQtC4asub8cQIFXbZz3Ns4+7jKtSWPcRqhKTurWv | ||
| XVH0YAFJDsFYo26r2V9c+Ie0uoQPx8graEGpKO9GtoQjXMKK32oApuBSSlmS | ||
| Q+nxyxMx1V+gxP4qgGBCxqkBFRYB/Ve6ygNHL1KxxCVTEw9pgnxJscn89Iio | ||
| dO6qZ9EgIV0PVQN0Yw033MTgAhCHunlE/qXvDxib4tdihoNsLN0q5kdOeiMW | ||
| +ntm3kphjMpQ6TMCUGtdS7UmvnadZ+dh5s785M8S9oY64mQd6QuYA2iy1IQv | ||
| q3zpW4/ba2gqL36qCCw/OaruXpQ4NeBr3hMaJQjWgeSuMsQnNGYUn5Nn1+9X | ||
| wtlithO8eLi3M1dg19dpDky8CacWfGgHD7SNsZ2zqFqyd1qtdFcit5ynQUHS | ||
| IiJKeUknGv1dQAnPPJ1FdXyyqC/VDBZG6CNdnxjonmQDRh1YlqNwSnmrR/Sy | ||
| X7n+nGra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dgEJLj | ||
| /W2u0Lp4NY8cwqcXuGKgl72TVJ34Iawl35Y0yr47k/7Y1vEQ5Q3bT7HP5A== | ||
| =FdCC | ||
| -----END PGP MESSAGE----- |
Uh oh!
There was an error while loading. Please reload this page.