use of com.fsck.k9.mail.CertificateValidationException in project k-9 by k9mail.
the class ImapConnectionTest 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();
}
use of com.fsck.k9.mail.CertificateValidationException in project k-9 by k9mail.
the class MessagingControllerTest method sendPendingMessagesSynchronous_withCertificateFailure_shouldNotify.
@Test
public void sendPendingMessagesSynchronous_withCertificateFailure_shouldNotify() throws MessagingException {
setupAccountWithMessageToSend();
doThrow(new CertificateValidationException("Test")).when(backend).sendMessage(localMessageToSend1);
controller.sendPendingMessagesSynchronous(account);
verify(notificationController).showCertificateErrorNotification(account, false);
}
use of com.fsck.k9.mail.CertificateValidationException in project k-9 by k9mail.
the class Pop3Connection method open.
void open() throws MessagingException {
try {
SocketAddress socketAddress = new InetSocketAddress(settings.getHost(), settings.getPort());
if (settings.getConnectionSecurity() == ConnectionSecurity.SSL_TLS_REQUIRED) {
socket = trustedSocketFactory.createSocket(null, settings.getHost(), settings.getPort(), settings.getClientCertificateAlias());
} else {
socket = new Socket();
}
socket.connect(socketAddress, SOCKET_CONNECT_TIMEOUT);
in = new BufferedInputStream(socket.getInputStream(), 1024);
out = new BufferedOutputStream(socket.getOutputStream(), 512);
socket.setSoTimeout(SOCKET_READ_TIMEOUT);
if (!isOpen()) {
throw new MessagingException("Unable to connect socket");
}
String serverGreeting = executeSimpleCommand(null);
capabilities = getCapabilities();
if (settings.getConnectionSecurity() == ConnectionSecurity.STARTTLS_REQUIRED) {
performStartTlsUpgrade(trustedSocketFactory, settings.getHost(), settings.getPort(), settings.getClientCertificateAlias());
}
performAuthentication(settings.getAuthType(), serverGreeting);
} catch (SSLException e) {
if (e.getCause() instanceof CertificateException) {
throw new CertificateValidationException(e.getMessage(), e);
} else {
throw new MessagingException("Unable to connect", e);
}
} catch (GeneralSecurityException gse) {
throw new MessagingException("Unable to open connection to POP server due to security error.", gse);
} catch (IOException ioe) {
throw new MessagingException("Unable to open connection to POP server.", ioe);
}
}
use of com.fsck.k9.mail.CertificateValidationException in project k-9 by k9mail.
the class Pop3Connection method performStartTlsUpgrade.
/*
* If STARTTLS is not available throws a CertificateValidationException which in K-9
* triggers a "Certificate error" notification that takes the user to the incoming
* server settings for review. This might be needed if the account was configured with an obsolete
* "STARTTLS (if available)" setting.
*/
private void performStartTlsUpgrade(TrustedSocketFactory trustedSocketFactory, String host, int port, String clientCertificateAlias) throws MessagingException, NoSuchAlgorithmException, KeyManagementException, IOException {
if (capabilities.stls) {
executeSimpleCommand(STLS_COMMAND);
socket = trustedSocketFactory.createSocket(socket, host, port, clientCertificateAlias);
socket.setSoTimeout(SOCKET_READ_TIMEOUT);
in = new BufferedInputStream(socket.getInputStream(), 1024);
out = new BufferedOutputStream(socket.getOutputStream(), 512);
if (!isOpen()) {
throw new MessagingException("Unable to connect socket");
}
capabilities = getCapabilities();
} else {
throw new CertificateValidationException("STARTTLS connection security not available");
}
}
use of com.fsck.k9.mail.CertificateValidationException in project k-9 by k9mail.
the class RealImapConnectionTest 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();
}
Aggregations