Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac42bce7 authored by Joe Steele's avatar Joe Steele
Browse files

Clean-up related to certificate chains

Per comments in pull request #365
parent 8b4064b2
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -164,7 +164,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
                    if (chain != null) {
                        acceptKeyDialog(
                                R.string.account_setup_failed_dlg_certificate_message_fmt,
                            cve, chain);
                                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
+13 −5
Original line number Diff line number Diff line
@@ -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 != 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