From afc4febd5da1635c6f1bbee5686413187e6c2c73 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Wed, 13 Sep 2017 11:37:41 +0200 Subject: [PATCH] MessageDecryptVerified -> MessageCryptoStructureDetector --- ...va => MessageCryptoStructureDetector.java} | 2 +- .../ComposePgpEnableByDefaultDecider.java | 4 +- .../k9/message/ComposePgpInlineDecider.java | 4 +- .../extractors/EncryptionDetector.java | 4 +- .../k9/ui/crypto/MessageCryptoHelper.java | 17 ++--- .../k9/ui/crypto/MessageCryptoSplitter.java | 4 +- ...> MessageCryptoStructureDetectorTest.java} | 71 ++++++++++--------- 7 files changed, 57 insertions(+), 49 deletions(-) rename k9mail/src/main/java/com/fsck/k9/crypto/{MessageDecryptVerifier.java => MessageCryptoStructureDetector.java} (99%) rename k9mail/src/test/java/com/fsck/k9/crypto/{MessageDecryptVerifierTest.java => MessageCryptoStructureDetectorTest.java} (82%) diff --git a/k9mail/src/main/java/com/fsck/k9/crypto/MessageDecryptVerifier.java b/k9mail/src/main/java/com/fsck/k9/crypto/MessageCryptoStructureDetector.java similarity index 99% rename from k9mail/src/main/java/com/fsck/k9/crypto/MessageDecryptVerifier.java rename to k9mail/src/main/java/com/fsck/k9/crypto/MessageCryptoStructureDetector.java index 07ba83793..219778f27 100644 --- a/k9mail/src/main/java/com/fsck/k9/crypto/MessageDecryptVerifier.java +++ b/k9mail/src/main/java/com/fsck/k9/crypto/MessageCryptoStructureDetector.java @@ -26,7 +26,7 @@ import com.fsck.k9.ui.crypto.MessageCryptoAnnotations; import static com.fsck.k9.mail.internet.MimeUtility.isSameMimeType; -public class MessageDecryptVerifier { +public class MessageCryptoStructureDetector { private static final String MULTIPART_ENCRYPTED = "multipart/encrypted"; private static final String MULTIPART_SIGNED = "multipart/signed"; private static final String PROTOCOL_PARAMETER = "protocol"; diff --git a/k9mail/src/main/java/com/fsck/k9/message/ComposePgpEnableByDefaultDecider.java b/k9mail/src/main/java/com/fsck/k9/message/ComposePgpEnableByDefaultDecider.java index fb881474e..3350ce6e7 100644 --- a/k9mail/src/main/java/com/fsck/k9/message/ComposePgpEnableByDefaultDecider.java +++ b/k9mail/src/main/java/com/fsck/k9/message/ComposePgpEnableByDefaultDecider.java @@ -3,7 +3,7 @@ package com.fsck.k9.message; import java.util.List; -import com.fsck.k9.crypto.MessageDecryptVerifier; +import com.fsck.k9.crypto.MessageCryptoStructureDetector; import com.fsck.k9.mail.Message; import com.fsck.k9.mail.Part; @@ -14,7 +14,7 @@ public class ComposePgpEnableByDefaultDecider { } private boolean messageIsEncrypted(Message localMessage) { - List encryptedParts = MessageDecryptVerifier.findMultipartEncryptedParts(localMessage); + List encryptedParts = MessageCryptoStructureDetector.findMultipartEncryptedParts(localMessage); return !encryptedParts.isEmpty(); } } diff --git a/k9mail/src/main/java/com/fsck/k9/message/ComposePgpInlineDecider.java b/k9mail/src/main/java/com/fsck/k9/message/ComposePgpInlineDecider.java index cef058c41..e3146b390 100644 --- a/k9mail/src/main/java/com/fsck/k9/message/ComposePgpInlineDecider.java +++ b/k9mail/src/main/java/com/fsck/k9/message/ComposePgpInlineDecider.java @@ -3,7 +3,7 @@ package com.fsck.k9.message; import java.util.List; -import com.fsck.k9.crypto.MessageDecryptVerifier; +import com.fsck.k9.crypto.MessageCryptoStructureDetector; import com.fsck.k9.mail.Message; import com.fsck.k9.mail.Part; @@ -15,7 +15,7 @@ public class ComposePgpInlineDecider { } private boolean messageHasPgpInlineParts(Message localMessage) { - List inlineParts = MessageDecryptVerifier.findPgpInlineParts(localMessage); + List inlineParts = MessageCryptoStructureDetector.findPgpInlineParts(localMessage); return !inlineParts.isEmpty(); } } diff --git a/k9mail/src/main/java/com/fsck/k9/message/extractors/EncryptionDetector.java b/k9mail/src/main/java/com/fsck/k9/message/extractors/EncryptionDetector.java index f7a6f7f87..084c9c512 100644 --- a/k9mail/src/main/java/com/fsck/k9/message/extractors/EncryptionDetector.java +++ b/k9mail/src/main/java/com/fsck/k9/message/extractors/EncryptionDetector.java @@ -3,7 +3,7 @@ package com.fsck.k9.message.extractors; import android.support.annotation.NonNull; -import com.fsck.k9.crypto.MessageDecryptVerifier; +import com.fsck.k9.crypto.MessageCryptoStructureDetector; import com.fsck.k9.mail.Body; import com.fsck.k9.mail.BodyPart; import com.fsck.k9.mail.Message; @@ -31,7 +31,7 @@ class EncryptionDetector { private boolean containsInlinePgpEncryptedText(Message message) { Part textPart = textPartFinder.findFirstTextPart(message); - return MessageDecryptVerifier.isPartPgpInlineEncrypted(textPart); + return MessageCryptoStructureDetector.isPartPgpInlineEncrypted(textPart); } private boolean containsPartWithMimeType(Part part, String... wantedMimeTypes) { diff --git a/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java b/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java index 4bf46b8a5..b8e7e2e86 100644 --- a/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java +++ b/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java @@ -19,7 +19,7 @@ import android.support.annotation.WorkerThread; import com.fsck.k9.K9; import com.fsck.k9.autocrypt.AutocryptOperations; -import com.fsck.k9.crypto.MessageDecryptVerifier; +import com.fsck.k9.crypto.MessageCryptoStructureDetector; import com.fsck.k9.mail.Address; import com.fsck.k9.mail.Body; import com.fsck.k9.mail.BodyPart; @@ -124,13 +124,13 @@ public class MessageCryptoHelper { } private void findPartsForMultipartEncryptionPass() { - List encryptedParts = MessageDecryptVerifier.findMultipartEncryptedParts(currentMessage); + List encryptedParts = MessageCryptoStructureDetector.findMultipartEncryptedParts(currentMessage); for (Part part : encryptedParts) { if (!MessageHelper.isCompletePartAvailable(part)) { addErrorAnnotation(part, CryptoError.OPENPGP_ENCRYPTED_BUT_INCOMPLETE, MessageHelper.createEmptyPart()); continue; } - if (MessageDecryptVerifier.isMultipartEncryptedOpenPgpProtocol(part)) { + if (MessageCryptoStructureDetector.isMultipartEncryptedOpenPgpProtocol(part)) { CryptoPart cryptoPart = new CryptoPart(CryptoPartType.PGP_ENCRYPTED, part); partsToProcess.add(cryptoPart); continue; @@ -140,14 +140,15 @@ public class MessageCryptoHelper { } private void findPartsForMultipartSignaturePass() { - List signedParts = MessageDecryptVerifier.findMultipartSignedParts(currentMessage, messageAnnotations); + List signedParts = MessageCryptoStructureDetector + .findMultipartSignedParts(currentMessage, messageAnnotations); for (Part part : signedParts) { if (!MessageHelper.isCompletePartAvailable(part)) { MimeBodyPart replacementPart = getMultipartSignedContentPartIfAvailable(part); addErrorAnnotation(part, CryptoError.OPENPGP_SIGNED_BUT_INCOMPLETE, replacementPart); continue; } - if (MessageDecryptVerifier.isMultipartSignedOpenPgpProtocol(part)) { + if (MessageCryptoStructureDetector.isMultipartSignedOpenPgpProtocol(part)) { CryptoPart cryptoPart = new CryptoPart(CryptoPartType.PGP_SIGNED, part); partsToProcess.add(cryptoPart); continue; @@ -158,10 +159,10 @@ public class MessageCryptoHelper { } private void findPartsForPgpInlinePass() { - List inlineParts = MessageDecryptVerifier.findPgpInlineParts(currentMessage); + List inlineParts = MessageCryptoStructureDetector.findPgpInlineParts(currentMessage); for (Part part : inlineParts) { if (!currentMessage.getFlags().contains(Flag.X_DOWNLOADED_FULL)) { - if (MessageDecryptVerifier.isPartPgpInlineEncrypted(part)) { + if (MessageCryptoStructureDetector.isPartPgpInlineEncrypted(part)) { addErrorAnnotation(part, CryptoError.OPENPGP_ENCRYPTED_BUT_INCOMPLETE, NO_REPLACEMENT_PART); } else { MimeBodyPart replacementPart = extractClearsignedTextReplacementPart(part); @@ -386,7 +387,7 @@ public class MessageCryptoHelper { private void callAsyncDetachedVerify(Intent intent) throws IOException, MessagingException { OpenPgpDataSource dataSource = getDataSourceForSignedData(currentCryptoPart.part); - byte[] signatureData = MessageDecryptVerifier.getSignatureData(currentCryptoPart.part); + byte[] signatureData = MessageCryptoStructureDetector.getSignatureData(currentCryptoPart.part); intent.putExtra(OpenPgpApi.EXTRA_DETACHED_SIGNATURE, signatureData); openPgpApi.executeApiAsync(intent, dataSource, new IOpenPgpSinkResultCallback() { diff --git a/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoSplitter.java b/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoSplitter.java index e0ef238fb..02c439eff 100644 --- a/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoSplitter.java +++ b/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoSplitter.java @@ -8,7 +8,7 @@ import java.util.List; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import com.fsck.k9.crypto.MessageDecryptVerifier; +import com.fsck.k9.crypto.MessageCryptoStructureDetector; import com.fsck.k9.mail.Message; import com.fsck.k9.mail.Part; import com.fsck.k9.mailstore.CryptoResultAnnotation; @@ -21,7 +21,7 @@ public class MessageCryptoSplitter { @Nullable public static CryptoMessageParts split(@NonNull Message message, @Nullable MessageCryptoAnnotations annotations) { ArrayList extraParts = new ArrayList<>(); - Part primaryPart = MessageDecryptVerifier.findPrimaryEncryptedOrSignedPart(message, extraParts); + Part primaryPart = MessageCryptoStructureDetector.findPrimaryEncryptedOrSignedPart(message, extraParts); if (primaryPart == null) { return null; } diff --git a/k9mail/src/test/java/com/fsck/k9/crypto/MessageDecryptVerifierTest.java b/k9mail/src/test/java/com/fsck/k9/crypto/MessageCryptoStructureDetectorTest.java similarity index 82% rename from k9mail/src/test/java/com/fsck/k9/crypto/MessageDecryptVerifierTest.java rename to k9mail/src/test/java/com/fsck/k9/crypto/MessageCryptoStructureDetectorTest.java index 366dfd556..352d7bed3 100644 --- a/k9mail/src/test/java/com/fsck/k9/crypto/MessageDecryptVerifierTest.java +++ b/k9mail/src/test/java/com/fsck/k9/crypto/MessageCryptoStructureDetectorTest.java @@ -31,7 +31,7 @@ import static org.mockito.Mockito.mock; @SuppressWarnings("WeakerAccess") @RunWith(K9RobolectricTestRunner.class) @Config(manifest = Config.NONE) -public class MessageDecryptVerifierTest { +public class MessageCryptoStructureDetectorTest { MessageCryptoAnnotations messageCryptoAnnotations = mock(MessageCryptoAnnotations.class); static final String PGP_INLINE_DATA = "" + "-----BEGIN PGP MESSAGE-----\n" + @@ -47,7 +47,7 @@ public class MessageDecryptVerifierTest { Message message = new MimeMessage(); MimeMessageHelper.setBody(message, new TextBody(PGP_INLINE_DATA)); - Part cryptoPart = MessageDecryptVerifier.findPrimaryEncryptedOrSignedPart(message, outputExtraParts); + Part cryptoPart = MessageCryptoStructureDetector.findPrimaryEncryptedOrSignedPart(message, outputExtraParts); assertSame(message, cryptoPart); } @@ -63,7 +63,7 @@ public class MessageDecryptVerifierTest { ) ); - Part cryptoPart = MessageDecryptVerifier.findPrimaryEncryptedOrSignedPart(message, outputExtraParts); + Part cryptoPart = MessageCryptoStructureDetector.findPrimaryEncryptedOrSignedPart(message, outputExtraParts); assertSame(pgpInlinePart, cryptoPart); } @@ -79,7 +79,7 @@ public class MessageDecryptVerifierTest { ) ); - Part cryptoPart = MessageDecryptVerifier.findPrimaryEncryptedOrSignedPart(message, outputExtraParts); + Part cryptoPart = MessageCryptoStructureDetector.findPrimaryEncryptedOrSignedPart(message, outputExtraParts); assertSame(pgpInlinePart, cryptoPart); } @@ -99,7 +99,7 @@ public class MessageDecryptVerifierTest { ) ); - Part cryptoPart = MessageDecryptVerifier.findPrimaryEncryptedOrSignedPart(message, outputExtraParts); + Part cryptoPart = MessageCryptoStructureDetector.findPrimaryEncryptedOrSignedPart(message, outputExtraParts); assertSame(pgpInlinePart, cryptoPart); } @@ -111,7 +111,7 @@ public class MessageDecryptVerifierTest { multipart("alternative", null) ); - Part cryptoPart = MessageDecryptVerifier.findPrimaryEncryptedOrSignedPart(message, outputExtraParts); + Part cryptoPart = MessageCryptoStructureDetector.findPrimaryEncryptedOrSignedPart(message, outputExtraParts); assertNull(cryptoPart); } @@ -123,7 +123,7 @@ public class MessageDecryptVerifierTest { multipart("mixed", null) ); - Part cryptoPart = MessageDecryptVerifier.findPrimaryEncryptedOrSignedPart(message, outputExtraParts); + Part cryptoPart = MessageCryptoStructureDetector.findPrimaryEncryptedOrSignedPart(message, outputExtraParts); assertNull(cryptoPart); } @@ -138,7 +138,7 @@ public class MessageDecryptVerifierTest { ) ); - Part cryptoPart = MessageDecryptVerifier.findPrimaryEncryptedOrSignedPart(message, outputExtraParts); + Part cryptoPart = MessageCryptoStructureDetector.findPrimaryEncryptedOrSignedPart(message, outputExtraParts); assertNull(cryptoPart); } @@ -147,7 +147,7 @@ public class MessageDecryptVerifierTest { public void findEncryptedPartsShouldReturnEmptyListForEmptyMessage() throws Exception { MimeMessage emptyMessage = new MimeMessage(); - List encryptedParts = MessageDecryptVerifier.findMultipartEncryptedParts(emptyMessage); + List encryptedParts = MessageCryptoStructureDetector.findMultipartEncryptedParts(emptyMessage); assertEquals(0, encryptedParts.size()); } @@ -157,7 +157,7 @@ public class MessageDecryptVerifierTest { MimeMessage message = new MimeMessage(); message.setBody(new TextBody("message text")); - List encryptedParts = MessageDecryptVerifier.findMultipartEncryptedParts(message); + List encryptedParts = MessageCryptoStructureDetector.findMultipartEncryptedParts(message); assertEquals(0, encryptedParts.size()); } @@ -171,7 +171,7 @@ public class MessageDecryptVerifierTest { ) ); - List encryptedParts = MessageDecryptVerifier.findMultipartEncryptedParts(message); + List encryptedParts = MessageCryptoStructureDetector.findMultipartEncryptedParts(message); assertEquals(1, encryptedParts.size()); assertSame(message, encryptedParts.get(0)); @@ -186,7 +186,7 @@ public class MessageDecryptVerifierTest { ) ); - List encryptedParts = MessageDecryptVerifier.findMultipartEncryptedParts(message); + List encryptedParts = MessageCryptoStructureDetector.findMultipartEncryptedParts(message); assertTrue(encryptedParts.isEmpty()); } @@ -213,7 +213,7 @@ public class MessageDecryptVerifierTest { ) ); - List encryptedParts = MessageDecryptVerifier.findMultipartEncryptedParts(message); + List encryptedParts = MessageCryptoStructureDetector.findMultipartEncryptedParts(message); assertTrue(encryptedParts.isEmpty()); } @@ -226,7 +226,7 @@ public class MessageDecryptVerifierTest { ) ); - List encryptedParts = MessageDecryptVerifier.findMultipartEncryptedParts(message); + List encryptedParts = MessageCryptoStructureDetector.findMultipartEncryptedParts(message); assertTrue(encryptedParts.isEmpty()); } @@ -242,7 +242,7 @@ public class MessageDecryptVerifierTest { ) ); - List encryptedParts = MessageDecryptVerifier.findMultipartEncryptedParts(message); + List encryptedParts = MessageCryptoStructureDetector.findMultipartEncryptedParts(message); assertEquals(1, encryptedParts.size()); assertSame(getPart(message, 0), encryptedParts.get(0)); @@ -264,7 +264,7 @@ public class MessageDecryptVerifierTest { ) ); - List encryptedParts = MessageDecryptVerifier.findMultipartEncryptedParts(message); + List encryptedParts = MessageCryptoStructureDetector.findMultipartEncryptedParts(message); assertEquals(2, encryptedParts.size()); assertSame(getPart(message, 0), encryptedParts.get(0)); @@ -283,7 +283,7 @@ public class MessageDecryptVerifierTest { ) ); - List encryptedParts = MessageDecryptVerifier.findMultipartEncryptedParts(message); + List encryptedParts = MessageCryptoStructureDetector.findMultipartEncryptedParts(message); assertEquals(1, encryptedParts.size()); assertSame(getPart(message, 1), encryptedParts.get(0)); @@ -301,7 +301,7 @@ public class MessageDecryptVerifierTest { ) ); - List encryptedParts = MessageDecryptVerifier.findMultipartEncryptedParts(message); + List encryptedParts = MessageCryptoStructureDetector.findMultipartEncryptedParts(message); assertEquals(1, encryptedParts.size()); assertSame(getPart(message, 0), encryptedParts.get(0)); @@ -316,7 +316,8 @@ public class MessageDecryptVerifierTest { ) ); - List signedParts = MessageDecryptVerifier.findMultipartSignedParts(message, messageCryptoAnnotations); + List signedParts = MessageCryptoStructureDetector + .findMultipartSignedParts(message, messageCryptoAnnotations); assertEquals(1, signedParts.size()); assertSame(message, signedParts.get(0)); @@ -331,7 +332,8 @@ public class MessageDecryptVerifierTest { ) ); - List signedParts = MessageDecryptVerifier.findMultipartSignedParts(message, messageCryptoAnnotations); + List signedParts = MessageCryptoStructureDetector + .findMultipartSignedParts(message, messageCryptoAnnotations); assertTrue(signedParts.isEmpty()); } @@ -359,7 +361,8 @@ public class MessageDecryptVerifierTest { ) ); - List signedParts = MessageDecryptVerifier.findMultipartSignedParts(message, messageCryptoAnnotations); + List signedParts = MessageCryptoStructureDetector + .findMultipartSignedParts(message, messageCryptoAnnotations); assertTrue(signedParts.isEmpty()); } @@ -376,7 +379,8 @@ public class MessageDecryptVerifierTest { ) ); - List signedParts = MessageDecryptVerifier.findMultipartSignedParts(message, messageCryptoAnnotations); + List signedParts = MessageCryptoStructureDetector + .findMultipartSignedParts(message, messageCryptoAnnotations); assertEquals(1, signedParts.size()); assertSame(message, signedParts.get(0)); @@ -393,7 +397,8 @@ public class MessageDecryptVerifierTest { ) ); - List signedParts = MessageDecryptVerifier.findMultipartSignedParts(message, messageCryptoAnnotations); + List signedParts = MessageCryptoStructureDetector + .findMultipartSignedParts(message, messageCryptoAnnotations); assertEquals(1, signedParts.size()); assertSame(getPart(message, 0), signedParts.get(0)); @@ -411,7 +416,8 @@ public class MessageDecryptVerifierTest { ) ); - List signedParts = MessageDecryptVerifier.findMultipartSignedParts(message, messageCryptoAnnotations); + List signedParts = MessageCryptoStructureDetector + .findMultipartSignedParts(message, messageCryptoAnnotations); assertEquals(1, signedParts.size()); assertSame(getPart(message, 0), signedParts.get(0)); @@ -429,7 +435,8 @@ public class MessageDecryptVerifierTest { ) ); - List signedParts = MessageDecryptVerifier.findMultipartSignedParts(message, messageCryptoAnnotations); + List signedParts = MessageCryptoStructureDetector + .findMultipartSignedParts(message, messageCryptoAnnotations); assertEquals(1, signedParts.size()); assertSame(getPart(message, 1), signedParts.get(0)); @@ -446,7 +453,7 @@ public class MessageDecryptVerifierTest { MimeMessage message = new MimeMessage(); message.setBody(new TextBody(pgpInlineData)); - assertTrue(MessageDecryptVerifier.isPartPgpInlineEncrypted(message)); + assertTrue(MessageCryptoStructureDetector.isPartPgpInlineEncrypted(message)); } @Test @@ -461,8 +468,8 @@ public class MessageDecryptVerifierTest { MimeMessage message = new MimeMessage(); message.setBody(new TextBody(pgpInlineData)); - assertTrue(MessageDecryptVerifier.isPartPgpInlineEncryptedOrSigned(message)); - assertTrue(MessageDecryptVerifier.isPartPgpInlineEncrypted(message)); + assertTrue(MessageCryptoStructureDetector.isPartPgpInlineEncryptedOrSigned(message)); + assertTrue(MessageCryptoStructureDetector.isPartPgpInlineEncrypted(message)); } @Test @@ -477,8 +484,8 @@ public class MessageDecryptVerifierTest { MimeMessage message = new MimeMessage(); message.setBody(new TextBody(pgpInlineData)); - assertFalse(MessageDecryptVerifier.isPartPgpInlineEncryptedOrSigned(message)); - assertFalse(MessageDecryptVerifier.isPartPgpInlineEncrypted(message)); + assertFalse(MessageCryptoStructureDetector.isPartPgpInlineEncryptedOrSigned(message)); + assertFalse(MessageCryptoStructureDetector.isPartPgpInlineEncrypted(message)); } @Test @@ -495,7 +502,7 @@ public class MessageDecryptVerifierTest { MimeMessage message = new MimeMessage(); message.setBody(new TextBody(pgpInlineData)); - assertTrue(MessageDecryptVerifier.isPartPgpInlineEncryptedOrSigned(message)); + assertTrue(MessageCryptoStructureDetector.isPartPgpInlineEncryptedOrSigned(message)); } @Test @@ -512,7 +519,7 @@ public class MessageDecryptVerifierTest { MimeMessage message = new MimeMessage(); message.setBody(new TextBody(pgpInlineData)); - assertFalse(MessageDecryptVerifier.isPartPgpInlineEncrypted(message)); + assertFalse(MessageCryptoStructureDetector.isPartPgpInlineEncrypted(message)); } static Part getPart(Part searchRootPart, int... indexes) {