diff --git a/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java b/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java index 136d32717..5941f7369 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java @@ -163,8 +163,8 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList // Avoid NullPointerException in acceptKeyDialog() if (chain != null) { acceptKeyDialog( - R.string.account_setup_failed_dlg_certificate_message_fmt, - cve, chain); + R.string.account_setup_failed_dlg_certificate_message_fmt, + cve); } else { showErrorDialog( R.string.account_setup_failed_dlg_server_message_fmt, @@ -235,7 +235,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList } private void acceptKeyDialog(final int msgResId, - final CertificateValidationException ex, final X509Certificate[] chain) { + final CertificateValidationException ex) { mHandler.post(new Runnable() { public void run() { if (mDestroyed) { @@ -264,6 +264,9 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList } catch (NoSuchAlgorithmException e) { Log.e(K9.LOG_TAG, "Error while initializing MessageDigest", e); } + + final X509Certificate[] chain = ex.getCertChain(); + // We already know chain != null (tested before calling this method) for (int i = 0; i < chain.length; i++) { // display certificate chain information //TODO: localize this strings diff --git a/src/com/fsck/k9/mail/CertificateValidationException.java b/src/com/fsck/k9/mail/CertificateValidationException.java index d1e9b7c8e..8f04d13c3 100644 --- a/src/com/fsck/k9/mail/CertificateValidationException.java +++ b/src/com/fsck/k9/mail/CertificateValidationException.java @@ -8,16 +8,19 @@ import java.security.cert.X509Certificate; public class CertificateValidationException extends MessagingException { public static final long serialVersionUID = -1; private X509Certificate[] mCertChain; + private boolean mNeedsUserAttention = false; public CertificateValidationException(String message) { super(message); + scanForCause(); } public CertificateValidationException(final String message, Throwable throwable) { super(message, throwable); + scanForCause(); } - public boolean needsUserAttention() { + private void scanForCause() { Throwable throwable = getCause(); /* user attention is required if the certificate was deemed invalid */ @@ -27,10 +30,16 @@ public class CertificateValidationException extends MessagingException { throwable = throwable.getCause(); } - if (throwable instanceof CertificateChainException) { - mCertChain = ((CertificateChainException) throwable).getCertChain(); + if (throwable != null) { + mNeedsUserAttention = true; + if (throwable instanceof CertificateChainException) { + mCertChain = ((CertificateChainException) throwable).getCertChain(); + } } - return throwable != null; + } + + public boolean needsUserAttention() { + return mNeedsUserAttention; } /** @@ -42,7 +51,6 @@ public class CertificateValidationException extends MessagingException { * chain, or else null. */ public X509Certificate[] getCertChain() { - needsUserAttention(); return mCertChain; } } \ No newline at end of file