Improve Android OpenPGP, drafts and release builds
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -426,7 +426,7 @@ internal object AndroidMailService {
|
||||
}
|
||||
}
|
||||
|
||||
private fun validateOpenPgpMime(message: MimeMessage) {
|
||||
internal fun validateOpenPgpMime(message: MimeMessage) {
|
||||
val contentType = message.contentType.lowercase(Locale.ROOT)
|
||||
val multipart = message.content as? Multipart
|
||||
?: throw IllegalArgumentException("The OpenPGP MIME message is malformed.")
|
||||
@@ -434,8 +434,8 @@ internal object AndroidMailService {
|
||||
if (contentType.startsWith("multipart/encrypted")) {
|
||||
val versionPart = multipart.getBodyPart(0)
|
||||
val encryptedPart = multipart.getBodyPart(1)
|
||||
val version = runCatching { versionPart.content.toString().trim() }.getOrDefault("")
|
||||
val armor = runCatching { String(encryptedPart.inputStream.readBytes(), Charsets.US_ASCII) }.getOrDefault("")
|
||||
val version = versionPart.inputStream.bufferedReader(Charsets.US_ASCII).use { it.readText().trim() }
|
||||
val armor = encryptedPart.inputStream.bufferedReader(Charsets.US_ASCII).use { it.readText() }
|
||||
require(versionPart.isMimeType("application/pgp-encrypted") && version == "Version: 1" &&
|
||||
encryptedPart.isMimeType("application/octet-stream") &&
|
||||
armor.contains("-----BEGIN PGP MESSAGE-----") && armor.contains("-----END PGP MESSAGE-----")) {
|
||||
@@ -443,7 +443,7 @@ internal object AndroidMailService {
|
||||
}
|
||||
} else if (contentType.startsWith("multipart/signed")) {
|
||||
val signaturePart = multipart.getBodyPart(1)
|
||||
val armor = runCatching { String(signaturePart.inputStream.readBytes(), Charsets.US_ASCII) }.getOrDefault("")
|
||||
val armor = signaturePart.inputStream.bufferedReader(Charsets.US_ASCII).use { it.readText() }
|
||||
require(signaturePart.isMimeType("application/pgp-signature") &&
|
||||
armor.contains("-----BEGIN PGP SIGNATURE-----") && armor.contains("-----END PGP SIGNATURE-----")) {
|
||||
"The OpenPGP signature is missing or malformed."
|
||||
|
||||
Reference in New Issue
Block a user