Search in sources :

Example 1 with AutocryptOperations

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);
}
Also used : CoreResourceProvider(com.fsck.k9.CoreResourceProvider) AutocryptOperations(com.fsck.k9.autocrypt.AutocryptOperations) AutocryptOpenPgpApiInteractor(com.fsck.k9.autocrypt.AutocryptOpenPgpApiInteractor) MessageIdGenerator(com.fsck.k9.mail.internet.MessageIdGenerator) BoundaryGenerator(com.fsck.k9.mail.BoundaryGenerator)

Example 2 with AutocryptOperations

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);
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) MessageCryptoAnnotations(com.fsck.k9.mailstore.MessageCryptoAnnotations) RobolectricTest(com.fsck.k9.RobolectricTest) Test(org.junit.Test)

Example 3 with 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));
}
Also used : IOpenPgpCallback(org.openintents.openpgp.util.OpenPgpApi.IOpenPgpCallback) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) MessageCryptoAnnotations(com.fsck.k9.mailstore.MessageCryptoAnnotations) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RobolectricTest(com.fsck.k9.RobolectricTest) Test(org.junit.Test)

Example 4 with AutocryptOperations

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);
}
Also used : MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) BodyPart(com.fsck.k9.mail.BodyPart) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) OutputStream(java.io.OutputStream) RobolectricTest(com.fsck.k9.RobolectricTest) Test(org.junit.Test)

Example 5 with 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);
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) OpenPgpDecryptionResult(org.openintents.openpgp.OpenPgpDecryptionResult) OutputStream(java.io.OutputStream) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) TextBody(com.fsck.k9.mail.internet.TextBody) Body(com.fsck.k9.mail.Body) TestMessageConstructionUtils.messageFromBody(com.fsck.k9.mail.TestMessageConstructionUtils.messageFromBody) OpenPgpSignatureResult(org.openintents.openpgp.OpenPgpSignatureResult) RobolectricTest(com.fsck.k9.RobolectricTest) Test(org.junit.Test)

Aggregations

RobolectricTest (com.fsck.k9.RobolectricTest)4 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)4 Test (org.junit.Test)4 OutputStream (java.io.OutputStream)3 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 Message (com.fsck.k9.mail.Message)2 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)2 MessageCryptoAnnotations (com.fsck.k9.mailstore.MessageCryptoAnnotations)2 CoreResourceProvider (com.fsck.k9.CoreResourceProvider)1 AutocryptOpenPgpApiInteractor (com.fsck.k9.autocrypt.AutocryptOpenPgpApiInteractor)1 AutocryptOperations (com.fsck.k9.autocrypt.AutocryptOperations)1 Body (com.fsck.k9.mail.Body)1 BodyPart (com.fsck.k9.mail.BodyPart)1 BoundaryGenerator (com.fsck.k9.mail.BoundaryGenerator)1 TestMessageConstructionUtils.messageFromBody (com.fsck.k9.mail.TestMessageConstructionUtils.messageFromBody)1 MessageIdGenerator (com.fsck.k9.mail.internet.MessageIdGenerator)1 TextBody (com.fsck.k9.mail.internet.TextBody)1 InputStream (java.io.InputStream)1 OpenPgpDecryptionResult (org.openintents.openpgp.OpenPgpDecryptionResult)1