From e3f6561008fc1e5b2e45af17c300691c1f95f044 Mon Sep 17 00:00:00 2001 From: cketti Date: Fri, 28 Oct 2011 04:59:08 +0200 Subject: [PATCH] Don't crash when trying to connect to an non-SSL service using SSL Fixes issue 3798 --- .../activity/setup/AccountSetupCheckSettings.java | 14 +++++++++++--- .../fsck/k9/mail/store/TrustManagerFactory.java | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java b/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java index dad534767..c64928cfd 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java @@ -153,9 +153,17 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList afe.getMessage() == null ? "" : afe.getMessage()); } catch (final CertificateValidationException cve) { Log.e(K9.LOG_TAG, "Error while testing settings", cve); - acceptKeyDialog( - R.string.account_setup_failed_dlg_certificate_message_fmt, - cve); + + // Avoid NullPointerException in acceptKeyDialog() + if (TrustManagerFactory.getLastCertChain() != null) { + acceptKeyDialog( + R.string.account_setup_failed_dlg_certificate_message_fmt, + cve); + } else { + showErrorDialog( + R.string.account_setup_failed_dlg_server_message_fmt, + (cve.getMessage() == null ? "" : cve.getMessage())); + } } catch (final Throwable t) { Log.e(K9.LOG_TAG, "Error while testing settings", t); showErrorDialog( diff --git a/src/com/fsck/k9/mail/store/TrustManagerFactory.java b/src/com/fsck/k9/mail/store/TrustManagerFactory.java index b6ead8d9d..32c9f4572 100644 --- a/src/com/fsck/k9/mail/store/TrustManagerFactory.java +++ b/src/com/fsck/k9/mail/store/TrustManagerFactory.java @@ -76,6 +76,8 @@ public final class TrustManagerFactory { public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { + // FIXME: Using a static field to store the certificate chain is a bad idea. Instead + // create a CertificateException subclass and store the chain there. TrustManagerFactory.setLastCertChain(chain); try { defaultTrustManager.checkServerTrusted(chain, authType);