use of com.fsck.k9.autocrypt.AutocryptOperations in project k-9 by k9mail.
the class PgpMessageBuilder method newInstance.
public static PgpMessageBuilder newInstance() {
MessageIdGenerator messageIdGenerator = MessageIdGenerator.getInstance();
BoundaryGenerator boundaryGenerator = BoundaryGenerator.getInstance();
AutocryptOperations autocryptOperations = AutocryptOperations.getInstance();
AutocryptOpenPgpApiInteractor autocryptOpenPgpApiInteractor = AutocryptOpenPgpApiInteractor.getInstance();
CoreResourceProvider resourceProvider = DI.get(CoreResourceProvider.class);
return new PgpMessageBuilder(messageIdGenerator, boundaryGenerator, autocryptOperations, autocryptOpenPgpApiInteractor, resourceProvider);
}
use of com.fsck.k9.autocrypt.AutocryptOperations in project k-9 by k9mail.
the class MessageCryptoHelperTest method textPlain.
@Test
public void textPlain() throws Exception {
MimeMessage message = new MimeMessage();
message.setUid("msguid");
message.setHeader("Content-Type", "text/plain");
MessageCryptoCallback messageCryptoCallback = mock(MessageCryptoCallback.class);
messageCryptoHelper.asyncStartOrResumeProcessingMessage(message, messageCryptoCallback, null, false);
ArgumentCaptor<MessageCryptoAnnotations> captor = ArgumentCaptor.forClass(MessageCryptoAnnotations.class);
verify(messageCryptoCallback).onCryptoOperationsFinished(captor.capture());
MessageCryptoAnnotations annotations = captor.getValue();
assertTrue(annotations.isEmpty());
verifyNoMoreInteractions(messageCryptoCallback);
verify(autocryptOperations).hasAutocryptHeader(message);
verifyNoMoreInteractions(autocryptOperations);
}
use of com.fsck.k9.autocrypt.AutocryptOperations in project k-9 by k9mail.
the class MessageCryptoHelperTest method textPlain_withAutocrypt.
@Test
public void textPlain_withAutocrypt() throws Exception {
MimeMessage message = new MimeMessage();
message.setUid("msguid");
message.setHeader("Content-Type", "text/plain");
when(autocryptOperations.hasAutocryptHeader(message)).thenReturn(true);
when(autocryptOperations.addAutocryptPeerUpdateToIntentIfPresent(same(message), any(Intent.class))).thenReturn(true);
MessageCryptoCallback messageCryptoCallback = mock(MessageCryptoCallback.class);
messageCryptoHelper.asyncStartOrResumeProcessingMessage(message, messageCryptoCallback, null, false);
ArgumentCaptor<MessageCryptoAnnotations> captor = ArgumentCaptor.forClass(MessageCryptoAnnotations.class);
verify(messageCryptoCallback).onCryptoOperationsFinished(captor.capture());
MessageCryptoAnnotations annotations = captor.getValue();
assertTrue(annotations.isEmpty());
verifyNoMoreInteractions(messageCryptoCallback);
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(autocryptOperations).addAutocryptPeerUpdateToIntentIfPresent(same(message), intentCaptor.capture());
verify(openPgpApi).executeApiAsync(same(intentCaptor.getValue()), same((InputStream) null), same((OutputStream) null), any(IOpenPgpCallback.class));
}
use of com.fsck.k9.autocrypt.AutocryptOperations in project k-9 by k9mail.
the class MessageCryptoHelperTest method multipartSigned__shouldCallOpenPgpApiAsync.
@Test
public void multipartSigned__shouldCallOpenPgpApiAsync() throws Exception {
BodyPart signedBodyPart = spy(bodypart("text/plain", "content"));
Message message = messageFromBody(multipart("signed", "protocol=\"application/pgp-signature\"", signedBodyPart, bodypart("application/pgp-signature", "content")));
message.setFrom(Address.parse("Test <test@example.org>")[0]);
OutputStream outputStream = mock(OutputStream.class);
processSignedMessageAndCaptureMocks(message, signedBodyPart, outputStream);
assertEquals(OpenPgpApi.ACTION_DECRYPT_VERIFY, capturedApiIntent.getAction());
assertEquals("test@example.org", capturedApiIntent.getStringExtra(OpenPgpApi.EXTRA_SENDER_ADDRESS));
verify(autocryptOperations).addAutocryptPeerUpdateToIntentIfPresent(message, capturedApiIntent);
verifyNoMoreInteractions(autocryptOperations);
}
use of com.fsck.k9.autocrypt.AutocryptOperations in project k-9 by k9mail.
the class MessageCryptoHelperTest method multipartEncrypted__shouldCallOpenPgpApiAsync.
@Test
public void multipartEncrypted__shouldCallOpenPgpApiAsync() throws Exception {
Body encryptedBody = spy(new TextBody("encrypted data"));
Message message = messageFromBody(multipart("encrypted", "protocol=\"application/pgp-encrypted\"", bodypart("application/pgp-encrypted", "content"), bodypart("application/octet-stream", encryptedBody)));
message.setFrom(Address.parse("Test <test@example.org>")[0]);
OutputStream outputStream = mock(OutputStream.class);
Intent resultIntent = new Intent();
resultIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
OpenPgpDecryptionResult decryptionResult = mock(OpenPgpDecryptionResult.class);
resultIntent.putExtra(OpenPgpApi.RESULT_DECRYPTION, decryptionResult);
OpenPgpSignatureResult signatureResult = mock(OpenPgpSignatureResult.class);
resultIntent.putExtra(OpenPgpApi.RESULT_SIGNATURE, signatureResult);
PendingIntent pendingIntent = mock(PendingIntent.class);
resultIntent.putExtra(OpenPgpApi.RESULT_INTENT, pendingIntent);
processEncryptedMessageAndCaptureMocks(message, encryptedBody, outputStream);
MimeBodyPart decryptedPart = new MimeBodyPart(new TextBody("text"));
capturedCallback.onReturn(resultIntent, decryptedPart);
assertEquals(OpenPgpApi.ACTION_DECRYPT_VERIFY, capturedApiIntent.getAction());
assertEquals("test@example.org", capturedApiIntent.getStringExtra(OpenPgpApi.EXTRA_SENDER_ADDRESS));
assertPartAnnotationHasState(message, messageCryptoCallback, CryptoError.OPENPGP_OK, decryptedPart, decryptionResult, signatureResult, pendingIntent);
verify(autocryptOperations).addAutocryptPeerUpdateToIntentIfPresent(message, capturedApiIntent);
verifyNoMoreInteractions(autocryptOperations);
}
Aggregations