Loading k9mail/src/main/java/com/fsck/k9/crypto/MessageDecryptVerifier.java +9 −0 Original line number Diff line number Diff line Loading @@ -195,4 +195,13 @@ public class MessageDecryptVerifier { return isPgpEncrypted || isPgpSigned; } public static boolean isPartPgpInlineEncrypted(Part part) { if (!part.isMimeType(TEXT_PLAIN) && !part.isMimeType(APPLICATION_PGP)) { return false; } String text = MessageExtractor.getTextFromPart(part, TEXT_LENGTH_FOR_INLINE_CHECK); return !TextUtils.isEmpty(text) && text.startsWith(PGP_INLINE_START_MARKER); } } k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java +28 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import com.fsck.k9.K9; import com.fsck.k9.crypto.MessageDecryptVerifier; import com.fsck.k9.mail.Body; import com.fsck.k9.mail.BodyPart; import com.fsck.k9.mail.Flag; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.Multipart; import com.fsck.k9.mail.Part; Loading @@ -47,6 +48,7 @@ import org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSink; import org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource; import org.openintents.openpgp.util.OpenPgpServiceConnection; import org.openintents.openpgp.util.OpenPgpServiceConnection.OnBound; import org.openintents.openpgp.util.OpenPgpUtils; public class MessageCryptoHelper { Loading Loading @@ -159,6 +161,16 @@ public class MessageCryptoHelper { private void addFoundInlinePgpParts(List<Part> foundParts) { for (Part part : foundParts) { if (!currentMessage.getFlags().contains(Flag.X_DOWNLOADED_FULL)) { if (MessageDecryptVerifier.isPartPgpInlineEncrypted(part)) { addErrorAnnotation(part, CryptoError.OPENPGP_ENCRYPTED_BUT_INCOMPLETE, NO_REPLACEMENT_PART); } else { MimeBodyPart replacementPart = extractClearsignedTextReplacementPart(part); addErrorAnnotation(part, CryptoError.OPENPGP_SIGNED_BUT_INCOMPLETE, replacementPart); } continue; } CryptoPart cryptoPart = new CryptoPart(CryptoPartType.PGP_INLINE, part); partsToDecryptOrVerify.add(cryptoPart); } Loading Loading @@ -650,4 +662,20 @@ public class MessageCryptoHelper { } return replacementPart; } private static MimeBodyPart extractClearsignedTextReplacementPart(Part part) { try { String clearsignedText = MessageExtractor.getTextFromPart(part); String replacementText = OpenPgpUtils.extractClearsignedMessage(clearsignedText); if (replacementText == null) { Log.e(K9.LOG_TAG, "failed to extract clearsigned text for replacement part"); return NO_REPLACEMENT_PART; } return new MimeBodyPart(new TextBody(replacementText), "text/plain"); } catch (MessagingException e) { Log.e(K9.LOG_TAG, "failed to create clearsigned text replacement part", e); return NO_REPLACEMENT_PART; } } } plugins/openpgp-api-lib/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java +19 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package org.openintents.openpgp.util; import java.util.List; import java.util.Locale; import java.util.regex.Matcher; Loading @@ -32,6 +33,9 @@ public class OpenPgpUtils { "(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", Pattern.DOTALL); public static final String PGP_MARKER_CLEARSIGN_BEGIN_MESSAGE = "-----BEGIN PGP SIGNED MESSAGE-----"; public static final String PGP_MARKER_CLEARSIGN_BEGIN_SIGNATURE = "-----BEGIN PGP SIGNATURE-----"; public static final Pattern PGP_SIGNED_MESSAGE = Pattern.compile( "(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*", Pattern.DOTALL); Loading Loading @@ -75,6 +79,21 @@ public class OpenPgpUtils { return hexString; } public static String extractClearsignedMessage(String text) { if (!text.startsWith(PGP_MARKER_CLEARSIGN_BEGIN_MESSAGE)) { return null; } int endOfHeader = text.indexOf("\r\n\r\n") +4; if (endOfHeader < 0) { return null; } int endOfCleartext = text.indexOf(PGP_MARKER_CLEARSIGN_BEGIN_SIGNATURE); if (endOfCleartext < 0) { endOfCleartext = text.length(); } return text.substring(endOfHeader, endOfCleartext); } private static final Pattern USER_ID_PATTERN = Pattern.compile("^(.*?)(?: \\((.*)\\))?(?: <(.*)>)?$"); Loading Loading
k9mail/src/main/java/com/fsck/k9/crypto/MessageDecryptVerifier.java +9 −0 Original line number Diff line number Diff line Loading @@ -195,4 +195,13 @@ public class MessageDecryptVerifier { return isPgpEncrypted || isPgpSigned; } public static boolean isPartPgpInlineEncrypted(Part part) { if (!part.isMimeType(TEXT_PLAIN) && !part.isMimeType(APPLICATION_PGP)) { return false; } String text = MessageExtractor.getTextFromPart(part, TEXT_LENGTH_FOR_INLINE_CHECK); return !TextUtils.isEmpty(text) && text.startsWith(PGP_INLINE_START_MARKER); } }
k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java +28 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import com.fsck.k9.K9; import com.fsck.k9.crypto.MessageDecryptVerifier; import com.fsck.k9.mail.Body; import com.fsck.k9.mail.BodyPart; import com.fsck.k9.mail.Flag; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.Multipart; import com.fsck.k9.mail.Part; Loading @@ -47,6 +48,7 @@ import org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSink; import org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource; import org.openintents.openpgp.util.OpenPgpServiceConnection; import org.openintents.openpgp.util.OpenPgpServiceConnection.OnBound; import org.openintents.openpgp.util.OpenPgpUtils; public class MessageCryptoHelper { Loading Loading @@ -159,6 +161,16 @@ public class MessageCryptoHelper { private void addFoundInlinePgpParts(List<Part> foundParts) { for (Part part : foundParts) { if (!currentMessage.getFlags().contains(Flag.X_DOWNLOADED_FULL)) { if (MessageDecryptVerifier.isPartPgpInlineEncrypted(part)) { addErrorAnnotation(part, CryptoError.OPENPGP_ENCRYPTED_BUT_INCOMPLETE, NO_REPLACEMENT_PART); } else { MimeBodyPart replacementPart = extractClearsignedTextReplacementPart(part); addErrorAnnotation(part, CryptoError.OPENPGP_SIGNED_BUT_INCOMPLETE, replacementPart); } continue; } CryptoPart cryptoPart = new CryptoPart(CryptoPartType.PGP_INLINE, part); partsToDecryptOrVerify.add(cryptoPart); } Loading Loading @@ -650,4 +662,20 @@ public class MessageCryptoHelper { } return replacementPart; } private static MimeBodyPart extractClearsignedTextReplacementPart(Part part) { try { String clearsignedText = MessageExtractor.getTextFromPart(part); String replacementText = OpenPgpUtils.extractClearsignedMessage(clearsignedText); if (replacementText == null) { Log.e(K9.LOG_TAG, "failed to extract clearsigned text for replacement part"); return NO_REPLACEMENT_PART; } return new MimeBodyPart(new TextBody(replacementText), "text/plain"); } catch (MessagingException e) { Log.e(K9.LOG_TAG, "failed to create clearsigned text replacement part", e); return NO_REPLACEMENT_PART; } } }
plugins/openpgp-api-lib/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java +19 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package org.openintents.openpgp.util; import java.util.List; import java.util.Locale; import java.util.regex.Matcher; Loading @@ -32,6 +33,9 @@ public class OpenPgpUtils { "(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", Pattern.DOTALL); public static final String PGP_MARKER_CLEARSIGN_BEGIN_MESSAGE = "-----BEGIN PGP SIGNED MESSAGE-----"; public static final String PGP_MARKER_CLEARSIGN_BEGIN_SIGNATURE = "-----BEGIN PGP SIGNATURE-----"; public static final Pattern PGP_SIGNED_MESSAGE = Pattern.compile( "(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*", Pattern.DOTALL); Loading Loading @@ -75,6 +79,21 @@ public class OpenPgpUtils { return hexString; } public static String extractClearsignedMessage(String text) { if (!text.startsWith(PGP_MARKER_CLEARSIGN_BEGIN_MESSAGE)) { return null; } int endOfHeader = text.indexOf("\r\n\r\n") +4; if (endOfHeader < 0) { return null; } int endOfCleartext = text.indexOf(PGP_MARKER_CLEARSIGN_BEGIN_SIGNATURE); if (endOfCleartext < 0) { endOfCleartext = text.length(); } return text.substring(endOfHeader, endOfCleartext); } private static final Pattern USER_ID_PATTERN = Pattern.compile("^(.*?)(?: \\((.*)\\))?(?: <(.*)>)?$"); Loading