Loading k9mail/src/main/java/com/fsck/k9/activity/compose/ComposeCryptoStatus.java +0 −15 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ public class ComposeCryptoStatus { private CryptoProviderState cryptoProviderState; private CryptoMode cryptoMode; private boolean cryptoSupportSignOnly; private boolean allKeysAvailable; private boolean allKeysVerified; private boolean hasRecipients; Loading Loading @@ -100,10 +99,6 @@ public class ComposeCryptoStatus { return cryptoMode == CryptoMode.OPPORTUNISTIC; } public boolean isOpportunisticSignOnly() { return cryptoSupportSignOnly; } public boolean isSignOnly() { return cryptoMode == CryptoMode.SIGN_ONLY; } Loading Loading @@ -132,7 +127,6 @@ public class ComposeCryptoStatus { private Long selfEncryptKeyId; private List<Recipient> recipients; private Boolean enablePgpInline; private Boolean cryptoSupportSignOnly; public ComposeCryptoStatusBuilder setCryptoProviderState(CryptoProviderState cryptoProviderState) { this.cryptoProviderState = cryptoProviderState; Loading @@ -144,11 +138,6 @@ public class ComposeCryptoStatus { return this; } public ComposeCryptoStatusBuilder setCryptoSupportSignOnly(boolean cryptoSupportSignOnly) { this.cryptoSupportSignOnly = cryptoSupportSignOnly; return this; } public ComposeCryptoStatusBuilder setSigningKeyId(long signingKeyId) { this.signingKeyId = signingKeyId; return this; Loading Loading @@ -182,9 +171,6 @@ public class ComposeCryptoStatus { if (enablePgpInline == null) { throw new AssertionError("enablePgpInline must be set!"); } if (cryptoSupportSignOnly == null) { throw new AssertionError("supportSignOnly must be set!"); } ArrayList<String> recipientAddresses = new ArrayList<>(); boolean allKeysAvailable = true; Loading @@ -205,7 +191,6 @@ public class ComposeCryptoStatus { ComposeCryptoStatus result = new ComposeCryptoStatus(); result.cryptoProviderState = cryptoProviderState; result.cryptoMode = cryptoMode; result.cryptoSupportSignOnly = cryptoSupportSignOnly; result.recipientAddresses = recipientAddresses.toArray(new String[0]); result.allKeysAvailable = allKeysAvailable; result.allKeysVerified = allKeysVerified; Loading k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientPresenter.java +0 −1 Original line number Diff line number Diff line Loading @@ -359,7 +359,6 @@ public class RecipientPresenter implements PermissionPingCallback { ComposeCryptoStatusBuilder builder = new ComposeCryptoStatusBuilder() .setCryptoProviderState(cryptoProviderState) .setCryptoMode(currentCryptoMode) .setCryptoSupportSignOnly(false) // TODO get rid of this setting .setEnablePgpInline(cryptoEnablePgpInline) .setRecipients(getAllRecipients()); Loading k9mail/src/main/java/com/fsck/k9/message/PgpMessageBuilder.java +7 −20 Original line number Diff line number Diff line Loading @@ -46,8 +46,6 @@ public class PgpMessageBuilder extends MessageBuilder { private MimeMessage currentProcessedMimeMessage; private ComposeCryptoStatus cryptoStatus; private boolean opportunisticSkipEncryption; private boolean opportunisticSecondPass; public static PgpMessageBuilder newInstance() { Loading Loading @@ -104,7 +102,7 @@ public class PgpMessageBuilder extends MessageBuilder { private void startOrContinueBuildMessage(@Nullable Intent pgpApiIntent) { try { boolean shouldSign = cryptoStatus.isSigningEnabled(); boolean shouldEncrypt = cryptoStatus.isEncryptionEnabled() && !opportunisticSkipEncryption; boolean shouldEncrypt = cryptoStatus.isEncryptionEnabled(); boolean isPgpInlineMode = cryptoStatus.isPgpInlineModeEnabled(); if (!shouldSign && !shouldEncrypt) { Loading @@ -128,13 +126,6 @@ public class PgpMessageBuilder extends MessageBuilder { return; } boolean shouldSignOnly = cryptoStatus.isOpportunisticSignOnly(); if (opportunisticSkipEncryption && shouldSignOnly && !opportunisticSecondPass) { opportunisticSecondPass = true; startOrContinueBuildMessage(null); return; } queueMessageBuildSuccess(currentProcessedMimeMessage); } catch (MessagingException me) { queueMessageBuildException(me); Loading Loading @@ -224,7 +215,11 @@ public class PgpMessageBuilder extends MessageBuilder { } boolean isOpportunisticError = error.getErrorId() == OpenPgpError.OPPORTUNISTIC_MISSING_KEYS; if (isOpportunisticError) { skipEncryptingMessage(); if (!cryptoStatus.isEncryptionOpportunistic()) { throw new IllegalStateException( "Got opportunistic error, but encryption wasn't supposed to be opportunistic!"); } Log.d(K9.LOG_TAG, "Skipping encryption due to opportunistic mode"); return null; } throw new MessagingException(error.getMessage()); Loading Loading @@ -259,8 +254,7 @@ public class PgpMessageBuilder extends MessageBuilder { @NonNull Intent result, @NonNull MimeBodyPart bodyPart, @Nullable BinaryTempFileBody pgpResultTempBody) throws MessagingException { if (pgpResultTempBody == null) { boolean shouldHaveResultPart = cryptoStatus.isPgpInlineModeEnabled() || (cryptoStatus.isEncryptionEnabled() && !opportunisticSkipEncryption); boolean shouldHaveResultPart = cryptoStatus.isPgpInlineModeEnabled() || cryptoStatus.isEncryptionEnabled(); if (shouldHaveResultPart) { throw new AssertionError("encryption or pgp/inline is enabled, but no output part!"); } Loading Loading @@ -335,13 +329,6 @@ public class PgpMessageBuilder extends MessageBuilder { MimeMessageHelper.setBody(currentProcessedMimeMessage, inlineBodyPart); } private void skipEncryptingMessage() throws MessagingException { if (!cryptoStatus.isEncryptionOpportunistic()) { throw new AssertionError("Got opportunistic error, but encryption wasn't supposed to be opportunistic!"); } opportunisticSkipEncryption = true; } public void setCryptoStatus(ComposeCryptoStatus cryptoStatus) { this.cryptoStatus = cryptoStatus; } Loading k9mail/src/test/java/com/fsck/k9/message/PgpMessageBuilderTest.java +1 −37 Original line number Diff line number Diff line Loading @@ -412,7 +412,6 @@ public class PgpMessageBuilderTest { ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder .setRecipients(Collections.singletonList(new Recipient("test", "test@example.org", "labru", -1, "key"))) .setCryptoMode(CryptoMode.OPPORTUNISTIC) .setCryptoSupportSignOnly(false) .build(); pgpMessageBuilder.setCryptoStatus(cryptoStatus); Loading @@ -438,40 +437,6 @@ public class PgpMessageBuilderTest { Assert.assertEquals("text/plain", message.getMimeType()); } @Test public void buildOpportunisticEncrypt__withNoKeysAndSignOnly__shouldBeSigned() throws MessagingException { ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder .setRecipients(Collections.singletonList(new Recipient("test", "test@example.org", "labru", -1, "key"))) .setCryptoMode(CryptoMode.OPPORTUNISTIC) .setCryptoSupportSignOnly(true) .build(); pgpMessageBuilder.setCryptoStatus(cryptoStatus); Intent returnIntentOpportunisticError = new Intent(); returnIntentOpportunisticError.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR); returnIntentOpportunisticError.putExtra(OpenPgpApi.RESULT_ERROR, new OpenPgpError(OpenPgpError.OPPORTUNISTIC_MISSING_KEYS, "Missing keys")); Intent returnIntentSigned = new Intent(); returnIntentSigned.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS); returnIntentSigned.putExtra(OpenPgpApi.EXTRA_DETACHED_SIGNATURE, new byte[] { (byte) 159 }); when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), any(OutputStream.class))) .thenReturn(returnIntentOpportunisticError, returnIntentSigned); Callback mockCallback = mock(Callback.class); pgpMessageBuilder.buildAsync(mockCallback); ArgumentCaptor<MimeMessage> captor = ArgumentCaptor.forClass(MimeMessage.class); verify(mockCallback).onMessageBuildSuccess(captor.capture(), eq(false)); verifyNoMoreInteractions(mockCallback); MimeMessage message = captor.getValue(); Assert.assertEquals("multipart/signed", message.getMimeType()); } @Test public void buildSign__withNoDetachedSignatureExtra__shouldFail() throws MessagingException { ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder Loading Loading @@ -500,8 +465,7 @@ public class PgpMessageBuilderTest { .setSigningKeyId(TEST_SIGN_KEY_ID) .setSelfEncryptId(TEST_SELF_ENCRYPT_KEY_ID) .setRecipients(new ArrayList<Recipient>()) .setCryptoProviderState(CryptoProviderState.OK) .setCryptoSupportSignOnly(true); .setCryptoProviderState(CryptoProviderState.OK); } private static PgpMessageBuilder createDefaultPgpMessageBuilder(OpenPgpApi openPgpApi) { Loading Loading
k9mail/src/main/java/com/fsck/k9/activity/compose/ComposeCryptoStatus.java +0 −15 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ public class ComposeCryptoStatus { private CryptoProviderState cryptoProviderState; private CryptoMode cryptoMode; private boolean cryptoSupportSignOnly; private boolean allKeysAvailable; private boolean allKeysVerified; private boolean hasRecipients; Loading Loading @@ -100,10 +99,6 @@ public class ComposeCryptoStatus { return cryptoMode == CryptoMode.OPPORTUNISTIC; } public boolean isOpportunisticSignOnly() { return cryptoSupportSignOnly; } public boolean isSignOnly() { return cryptoMode == CryptoMode.SIGN_ONLY; } Loading Loading @@ -132,7 +127,6 @@ public class ComposeCryptoStatus { private Long selfEncryptKeyId; private List<Recipient> recipients; private Boolean enablePgpInline; private Boolean cryptoSupportSignOnly; public ComposeCryptoStatusBuilder setCryptoProviderState(CryptoProviderState cryptoProviderState) { this.cryptoProviderState = cryptoProviderState; Loading @@ -144,11 +138,6 @@ public class ComposeCryptoStatus { return this; } public ComposeCryptoStatusBuilder setCryptoSupportSignOnly(boolean cryptoSupportSignOnly) { this.cryptoSupportSignOnly = cryptoSupportSignOnly; return this; } public ComposeCryptoStatusBuilder setSigningKeyId(long signingKeyId) { this.signingKeyId = signingKeyId; return this; Loading Loading @@ -182,9 +171,6 @@ public class ComposeCryptoStatus { if (enablePgpInline == null) { throw new AssertionError("enablePgpInline must be set!"); } if (cryptoSupportSignOnly == null) { throw new AssertionError("supportSignOnly must be set!"); } ArrayList<String> recipientAddresses = new ArrayList<>(); boolean allKeysAvailable = true; Loading @@ -205,7 +191,6 @@ public class ComposeCryptoStatus { ComposeCryptoStatus result = new ComposeCryptoStatus(); result.cryptoProviderState = cryptoProviderState; result.cryptoMode = cryptoMode; result.cryptoSupportSignOnly = cryptoSupportSignOnly; result.recipientAddresses = recipientAddresses.toArray(new String[0]); result.allKeysAvailable = allKeysAvailable; result.allKeysVerified = allKeysVerified; Loading
k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientPresenter.java +0 −1 Original line number Diff line number Diff line Loading @@ -359,7 +359,6 @@ public class RecipientPresenter implements PermissionPingCallback { ComposeCryptoStatusBuilder builder = new ComposeCryptoStatusBuilder() .setCryptoProviderState(cryptoProviderState) .setCryptoMode(currentCryptoMode) .setCryptoSupportSignOnly(false) // TODO get rid of this setting .setEnablePgpInline(cryptoEnablePgpInline) .setRecipients(getAllRecipients()); Loading
k9mail/src/main/java/com/fsck/k9/message/PgpMessageBuilder.java +7 −20 Original line number Diff line number Diff line Loading @@ -46,8 +46,6 @@ public class PgpMessageBuilder extends MessageBuilder { private MimeMessage currentProcessedMimeMessage; private ComposeCryptoStatus cryptoStatus; private boolean opportunisticSkipEncryption; private boolean opportunisticSecondPass; public static PgpMessageBuilder newInstance() { Loading Loading @@ -104,7 +102,7 @@ public class PgpMessageBuilder extends MessageBuilder { private void startOrContinueBuildMessage(@Nullable Intent pgpApiIntent) { try { boolean shouldSign = cryptoStatus.isSigningEnabled(); boolean shouldEncrypt = cryptoStatus.isEncryptionEnabled() && !opportunisticSkipEncryption; boolean shouldEncrypt = cryptoStatus.isEncryptionEnabled(); boolean isPgpInlineMode = cryptoStatus.isPgpInlineModeEnabled(); if (!shouldSign && !shouldEncrypt) { Loading @@ -128,13 +126,6 @@ public class PgpMessageBuilder extends MessageBuilder { return; } boolean shouldSignOnly = cryptoStatus.isOpportunisticSignOnly(); if (opportunisticSkipEncryption && shouldSignOnly && !opportunisticSecondPass) { opportunisticSecondPass = true; startOrContinueBuildMessage(null); return; } queueMessageBuildSuccess(currentProcessedMimeMessage); } catch (MessagingException me) { queueMessageBuildException(me); Loading Loading @@ -224,7 +215,11 @@ public class PgpMessageBuilder extends MessageBuilder { } boolean isOpportunisticError = error.getErrorId() == OpenPgpError.OPPORTUNISTIC_MISSING_KEYS; if (isOpportunisticError) { skipEncryptingMessage(); if (!cryptoStatus.isEncryptionOpportunistic()) { throw new IllegalStateException( "Got opportunistic error, but encryption wasn't supposed to be opportunistic!"); } Log.d(K9.LOG_TAG, "Skipping encryption due to opportunistic mode"); return null; } throw new MessagingException(error.getMessage()); Loading Loading @@ -259,8 +254,7 @@ public class PgpMessageBuilder extends MessageBuilder { @NonNull Intent result, @NonNull MimeBodyPart bodyPart, @Nullable BinaryTempFileBody pgpResultTempBody) throws MessagingException { if (pgpResultTempBody == null) { boolean shouldHaveResultPart = cryptoStatus.isPgpInlineModeEnabled() || (cryptoStatus.isEncryptionEnabled() && !opportunisticSkipEncryption); boolean shouldHaveResultPart = cryptoStatus.isPgpInlineModeEnabled() || cryptoStatus.isEncryptionEnabled(); if (shouldHaveResultPart) { throw new AssertionError("encryption or pgp/inline is enabled, but no output part!"); } Loading Loading @@ -335,13 +329,6 @@ public class PgpMessageBuilder extends MessageBuilder { MimeMessageHelper.setBody(currentProcessedMimeMessage, inlineBodyPart); } private void skipEncryptingMessage() throws MessagingException { if (!cryptoStatus.isEncryptionOpportunistic()) { throw new AssertionError("Got opportunistic error, but encryption wasn't supposed to be opportunistic!"); } opportunisticSkipEncryption = true; } public void setCryptoStatus(ComposeCryptoStatus cryptoStatus) { this.cryptoStatus = cryptoStatus; } Loading
k9mail/src/test/java/com/fsck/k9/message/PgpMessageBuilderTest.java +1 −37 Original line number Diff line number Diff line Loading @@ -412,7 +412,6 @@ public class PgpMessageBuilderTest { ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder .setRecipients(Collections.singletonList(new Recipient("test", "test@example.org", "labru", -1, "key"))) .setCryptoMode(CryptoMode.OPPORTUNISTIC) .setCryptoSupportSignOnly(false) .build(); pgpMessageBuilder.setCryptoStatus(cryptoStatus); Loading @@ -438,40 +437,6 @@ public class PgpMessageBuilderTest { Assert.assertEquals("text/plain", message.getMimeType()); } @Test public void buildOpportunisticEncrypt__withNoKeysAndSignOnly__shouldBeSigned() throws MessagingException { ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder .setRecipients(Collections.singletonList(new Recipient("test", "test@example.org", "labru", -1, "key"))) .setCryptoMode(CryptoMode.OPPORTUNISTIC) .setCryptoSupportSignOnly(true) .build(); pgpMessageBuilder.setCryptoStatus(cryptoStatus); Intent returnIntentOpportunisticError = new Intent(); returnIntentOpportunisticError.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR); returnIntentOpportunisticError.putExtra(OpenPgpApi.RESULT_ERROR, new OpenPgpError(OpenPgpError.OPPORTUNISTIC_MISSING_KEYS, "Missing keys")); Intent returnIntentSigned = new Intent(); returnIntentSigned.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS); returnIntentSigned.putExtra(OpenPgpApi.EXTRA_DETACHED_SIGNATURE, new byte[] { (byte) 159 }); when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), any(OutputStream.class))) .thenReturn(returnIntentOpportunisticError, returnIntentSigned); Callback mockCallback = mock(Callback.class); pgpMessageBuilder.buildAsync(mockCallback); ArgumentCaptor<MimeMessage> captor = ArgumentCaptor.forClass(MimeMessage.class); verify(mockCallback).onMessageBuildSuccess(captor.capture(), eq(false)); verifyNoMoreInteractions(mockCallback); MimeMessage message = captor.getValue(); Assert.assertEquals("multipart/signed", message.getMimeType()); } @Test public void buildSign__withNoDetachedSignatureExtra__shouldFail() throws MessagingException { ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder Loading Loading @@ -500,8 +465,7 @@ public class PgpMessageBuilderTest { .setSigningKeyId(TEST_SIGN_KEY_ID) .setSelfEncryptId(TEST_SELF_ENCRYPT_KEY_ID) .setRecipients(new ArrayList<Recipient>()) .setCryptoProviderState(CryptoProviderState.OK) .setCryptoSupportSignOnly(true); .setCryptoProviderState(CryptoProviderState.OK); } private static PgpMessageBuilder createDefaultPgpMessageBuilder(OpenPgpApi openPgpApi) { Loading