Search in sources :

Example 1 with CertificateValidationException

use of com.fsck.k9.mail.CertificateValidationException in project k-9 by k9mail.

the class ImapConnection method saslAuthExternal.

private void saslAuthExternal() throws IOException, MessagingException {
    try {
        String command = Commands.AUTHENTICATE_EXTERNAL + " " + Base64.encode(settings.getUsername());
        extractCapabilities(executeSimpleCommand(command, false));
    } catch (NegativeImapResponseException e) {
        /*
             * Provide notification to the user of a problem authenticating
             * using client certificates. We don't use an
             * AuthenticationFailedException because that would trigger a
             * "Username or password incorrect" notification in
             * AccountSetupCheckSettings.
             */
        throw new CertificateValidationException(e.getMessage());
    }
}
Also used : CertificateValidationException(com.fsck.k9.mail.CertificateValidationException)

Example 2 with CertificateValidationException

use of com.fsck.k9.mail.CertificateValidationException in project k-9 by k9mail.

the class ImapConnectionTest method open_withStartTlsButWithoutStartTlsCapability_shouldThrow.

@Test
public void open_withStartTlsButWithoutStartTlsCapability_shouldThrow() throws Exception {
    settings.setConnectionSecurity(ConnectionSecurity.STARTTLS_REQUIRED);
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server);
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.open();
        fail("Expected exception");
    } catch (CertificateValidationException e) {
        //FIXME: CertificateValidationException seems wrong
        assertEquals("STARTTLS connection security not available", e.getMessage());
    }
    server.verifyConnectionClosed();
    server.verifyInteractionCompleted();
}
Also used : MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 3 with CertificateValidationException

use of com.fsck.k9.mail.CertificateValidationException in project k-9 by k9mail.

the class ImapConnectionTest method open_authExternalWithAuthenticationFailure_shouldThrow.

@Test
public void open_authExternalWithAuthenticationFailure_shouldThrow() throws Exception {
    settings.setAuthType(AuthType.EXTERNAL);
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server, "AUTH=EXTERNAL");
    server.expect("2 AUTHENTICATE EXTERNAL " + ByteString.encodeUtf8(USERNAME).base64());
    server.output("2 NO Bad certificate");
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.open();
        fail("Expected exception");
    } catch (CertificateValidationException e) {
        //FIXME: improve exception message
        assertThat(e.getMessage(), containsString("Bad certificate"));
    }
    server.verifyConnectionClosed();
    server.verifyInteractionCompleted();
}
Also used : MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 4 with CertificateValidationException

use of com.fsck.k9.mail.CertificateValidationException in project k-9 by k9mail.

the class RealImapConnectionTest method open_authExternalWithoutAuthExternalCapability_shouldThrow.

@Test
public void open_authExternalWithoutAuthExternalCapability_shouldThrow() throws Exception {
    settings.setAuthType(AuthType.EXTERNAL);
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server, "AUTH=PLAIN");
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.open();
        fail("Expected exception");
    } catch (CertificateValidationException e) {
        assertEquals(Reason.MissingCapability, e.getReason());
    }
    server.verifyConnectionClosed();
    server.verifyInteractionCompleted();
}
Also used : MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 5 with CertificateValidationException

use of com.fsck.k9.mail.CertificateValidationException in project k-9 by k9mail.

the class RealImapConnectionTest method open_authExternalWithAuthenticationFailure_shouldThrow.

@Test
public void open_authExternalWithAuthenticationFailure_shouldThrow() throws Exception {
    settings.setAuthType(AuthType.EXTERNAL);
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server, "AUTH=EXTERNAL");
    server.expect("2 AUTHENTICATE EXTERNAL " + ByteString.encodeUtf8(USERNAME).base64());
    server.output("2 NO Bad certificate");
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.open();
        fail("Expected exception");
    } catch (CertificateValidationException e) {
        // FIXME: improve exception message
        assertThat(e.getMessage(), containsString("Bad certificate"));
    }
    server.verifyConnectionClosed();
    server.verifyInteractionCompleted();
}
Also used : MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Aggregations

CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)15 Test (org.junit.Test)8 XOAuth2ChallengeParserTest (com.fsck.k9.mail.XOAuth2ChallengeParserTest)7 MockImapServer (com.fsck.k9.mail.store.imap.mockserver.MockImapServer)6 MessagingException (com.fsck.k9.mail.MessagingException)5 BufferedInputStream (java.io.BufferedInputStream)3 BufferedOutputStream (java.io.BufferedOutputStream)3 IOException (java.io.IOException)3 SSLException (javax.net.ssl.SSLException)3 InetSocketAddress (java.net.InetSocketAddress)2 Socket (java.net.Socket)2 SocketAddress (java.net.SocketAddress)2 GeneralSecurityException (java.security.GeneralSecurityException)2 SuppressLint (android.annotation.SuppressLint)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1 K9RobolectricTest (com.fsck.k9.K9RobolectricTest)1 Backend (com.fsck.k9.backend.api.Backend)1 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)1 FetchProfile (com.fsck.k9.mail.FetchProfile)1 ServerSettings (com.fsck.k9.mail.ServerSettings)1