From ef3cda97e29f6ae8193aef0291c8468e422dc81d Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 14 Nov 2016 18:56:26 +0100 Subject: [PATCH] remove support for clearsigned messages in PgpMessageBuilder --- .../fsck/k9/message/PgpMessageBuilder.java | 13 ++++++---- .../k9/message/PgpMessageBuilderTest.java | 24 ++----------------- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/message/PgpMessageBuilder.java b/k9mail/src/main/java/com/fsck/k9/message/PgpMessageBuilder.java index 07245b0b5..e0563555f 100644 --- a/k9mail/src/main/java/com/fsck/k9/message/PgpMessageBuilder.java +++ b/k9mail/src/main/java/com/fsck/k9/message/PgpMessageBuilder.java @@ -39,8 +39,8 @@ import org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource; public class PgpMessageBuilder extends MessageBuilder { + private static final int REQUEST_USER_INTERACTION = 1; - public static final int REQUEST_USER_INTERACTION = 1; private OpenPgpApi openPgpApi; @@ -115,12 +115,16 @@ public class PgpMessageBuilder extends MessageBuilder { throw new MessagingException("Attachments are not supported in PGP/INLINE format!"); } + if (isPgpInlineMode && shouldSign && !shouldEncrypt) { + throw new UnsupportedOperationException("Clearsigning is not supported!"); + } + if (pgpApiIntent == null) { pgpApiIntent = buildOpenPgpApiIntent(shouldSign, shouldEncrypt, isPgpInlineMode); } PendingIntent returnedPendingIntent = launchOpenPgpApiIntent( - pgpApiIntent, shouldEncrypt || isPgpInlineMode, shouldEncrypt || !isPgpInlineMode, isPgpInlineMode); + pgpApiIntent, shouldEncrypt, isPgpInlineMode); if (returnedPendingIntent != null) { queueMessageBuildPendingIntent(returnedPendingIntent, REQUEST_USER_INTERACTION); return; @@ -170,7 +174,7 @@ public class PgpMessageBuilder extends MessageBuilder { } private PendingIntent launchOpenPgpApiIntent(@NonNull Intent openPgpIntent, - boolean captureOutputPart, boolean capturedOutputPartIs7Bit, boolean writeBodyContentOnly) throws MessagingException { + boolean captureOutputPart, boolean writeBodyContentOnly) throws MessagingException { final MimeBodyPart bodyPart = currentProcessedMimeMessage.toBodyPart(); String[] contentType = currentProcessedMimeMessage.getHeader(MimeHeader.HEADER_CONTENT_TYPE); if (contentType.length > 0) { @@ -183,8 +187,7 @@ public class PgpMessageBuilder extends MessageBuilder { OutputStream outputStream = null; if (captureOutputPart) { try { - pgpResultTempBody = new BinaryTempFileBody( - capturedOutputPartIs7Bit ? MimeUtil.ENC_7BIT : MimeUtil.ENC_8BIT); + pgpResultTempBody = new BinaryTempFileBody(MimeUtil.ENC_7BIT); outputStream = pgpResultTempBody.getOutputStream(); // OpenKeychain/BouncyCastle at this point use the system newline for formatting, which is LF on android. // we need this to be CRLF, so we convert the data after receiving. diff --git a/k9mail/src/test/java/com/fsck/k9/message/PgpMessageBuilderTest.java b/k9mail/src/test/java/com/fsck/k9/message/PgpMessageBuilderTest.java index 10bab3661..87fa7e7da 100644 --- a/k9mail/src/test/java/com/fsck/k9/message/PgpMessageBuilderTest.java +++ b/k9mail/src/test/java/com/fsck/k9/message/PgpMessageBuilderTest.java @@ -343,8 +343,8 @@ public class PgpMessageBuilderTest { Assert.assertEquals(MimeUtil.ENC_7BIT, ((BinaryTempFileBody) message.getBody()).getEncoding()); } - @Test - public void buildSign__withInlineEnabled__shouldSucceed() throws MessagingException { + @Test(expected = RuntimeException.class) // this is a wrapped UnsupportedOperationException from AsyncTask + public void buildSign__withInlineEnabled__shouldFail() throws MessagingException { ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder .setCryptoMode(CryptoMode.SIGN_ONLY) .setRecipients(Collections.singletonList(new Recipient("test", "test@example.org", "labru", -1, "key"))) @@ -352,28 +352,8 @@ public class PgpMessageBuilderTest { .build(); pgpMessageBuilder.setCryptoStatus(cryptoStatus); - ArgumentCaptor capturedApiIntent = ArgumentCaptor.forClass(Intent.class); - - Intent returnIntent = new Intent(); - returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS); - - when(openPgpApi.executeApi(capturedApiIntent.capture(), any(OpenPgpDataSource.class), any(OutputStream.class))) - .thenReturn(returnIntent); - Callback mockCallback = mock(Callback.class); pgpMessageBuilder.buildAsync(mockCallback); - - Intent expectedApiIntent = new Intent(OpenPgpApi.ACTION_SIGN); - expectedApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, TEST_SIGN_KEY_ID); - expectedApiIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true); - assertIntentEqualsActionAndExtras(expectedApiIntent, capturedApiIntent.getValue()); - - ArgumentCaptor captor = ArgumentCaptor.forClass(MimeMessage.class); - verify(mockCallback).onMessageBuildSuccess(captor.capture(), eq(false)); - verifyNoMoreInteractions(mockCallback); - - MimeMessage message = captor.getValue(); - Assert.assertEquals("message must be text/plain", "text/plain", message.getMimeType()); } @Test