use of com.fsck.k9.activity.compose.ComposeCryptoStatus in project k-9 by k9mail.
the class RecipientPresenter method getCurrentCryptoStatus.
public ComposeCryptoStatus getCurrentCryptoStatus() {
if (cachedCryptoStatus == null) {
ComposeCryptoStatusBuilder builder = new ComposeCryptoStatusBuilder().setCryptoProviderState(cryptoProviderState).setCryptoMode(currentCryptoMode).setEnablePgpInline(cryptoEnablePgpInline).setRecipients(getAllRecipients());
long accountCryptoKey = account.getCryptoKey();
if (accountCryptoKey != Account.NO_OPENPGP_KEY) {
// TODO split these into individual settings? maybe after key is bound to identity
builder.setSigningKeyId(accountCryptoKey);
builder.setSelfEncryptId(accountCryptoKey);
}
cachedCryptoStatus = builder.build();
}
return cachedCryptoStatus;
}
use of com.fsck.k9.activity.compose.ComposeCryptoStatus in project k-9 by k9mail.
the class PgpMessageBuilderTest method buildOpportunisticEncrypt__withNoKeysAndNoSignOnly__shouldNotBeSigned.
@Test
public void buildOpportunisticEncrypt__withNoKeysAndNoSignOnly__shouldNotBeSigned() throws MessagingException {
ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder.setRecipients(Collections.singletonList(new Recipient("test", "test@example.org", "labru", -1, "key"))).setCryptoMode(CryptoMode.OPPORTUNISTIC).build();
pgpMessageBuilder.setCryptoStatus(cryptoStatus);
Intent returnIntent = new Intent();
returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
returnIntent.putExtra(OpenPgpApi.RESULT_ERROR, new OpenPgpError(OpenPgpError.OPPORTUNISTIC_MISSING_KEYS, "Missing keys"));
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), any(OutputStream.class))).thenReturn(returnIntent);
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("text/plain", message.getMimeType());
}
use of com.fsck.k9.activity.compose.ComposeCryptoStatus in project k-9 by k9mail.
the class PgpMessageBuilderTest method buildSign__withNoDetachedSignatureExtra__shouldFail.
@Test
public void buildSign__withNoDetachedSignatureExtra__shouldFail() throws MessagingException {
ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder.setCryptoMode(CryptoMode.SIGN_ONLY).build();
pgpMessageBuilder.setCryptoStatus(cryptoStatus);
Intent returnIntentSigned = new Intent();
returnIntentSigned.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
// no OpenPgpApi.EXTRA_DETACHED_SIGNATURE!
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), any(OutputStream.class))).thenReturn(returnIntentSigned);
Callback mockCallback = mock(Callback.class);
pgpMessageBuilder.buildAsync(mockCallback);
verify(mockCallback).onMessageBuildException(any(MessagingException.class));
verifyNoMoreInteractions(mockCallback);
}
use of com.fsck.k9.activity.compose.ComposeCryptoStatus in project k-9 by k9mail.
the class PgpMessageBuilderTest method buildSign__withInlineEnabled__shouldSucceed.
@Test
public void buildSign__withInlineEnabled__shouldSucceed() throws MessagingException {
ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder.setCryptoMode(CryptoMode.SIGN_ONLY).setRecipients(Collections.singletonList(new Recipient("test", "test@example.org", "labru", -1, "key"))).setEnablePgpInline(true).build();
pgpMessageBuilder.setCryptoStatus(cryptoStatus);
ArgumentCaptor<Intent> 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<MimeMessage> 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());
}
use of com.fsck.k9.activity.compose.ComposeCryptoStatus in project k-9 by k9mail.
the class PgpMessageBuilderTest method buildEncryptWithAttach__withInlineEnabled__shouldThrow.
@Test
public void buildEncryptWithAttach__withInlineEnabled__shouldThrow() throws MessagingException {
ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder.setCryptoMode(CryptoMode.OPPORTUNISTIC).setEnablePgpInline(true).build();
pgpMessageBuilder.setCryptoStatus(cryptoStatus);
pgpMessageBuilder.setAttachments(Collections.singletonList(Attachment.createAttachment(null, 0, null)));
Callback mockCallback = mock(Callback.class);
pgpMessageBuilder.buildAsync(mockCallback);
verify(mockCallback).onMessageBuildException(any(MessagingException.class));
verifyNoMoreInteractions(mockCallback);
verifyNoMoreInteractions(openPgpApi);
}
Aggregations