From d980e49fd14c39c1e930311fd9ea1d1b0442af78 Mon Sep 17 00:00:00 2001 From: Art O Cathain Date: Sat, 11 Oct 2014 16:11:12 +0100 Subject: [PATCH] chain the exception --- src/com/fsck/k9/mail/CertificateChainException.java | 10 ++-------- src/com/fsck/k9/net/ssl/TrustManagerFactory.java | 6 +++++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/com/fsck/k9/mail/CertificateChainException.java b/src/com/fsck/k9/mail/CertificateChainException.java index f7ce58f4f..c76145607 100644 --- a/src/com/fsck/k9/mail/CertificateChainException.java +++ b/src/com/fsck/k9/mail/CertificateChainException.java @@ -13,14 +13,8 @@ public class CertificateChainException extends CertificateException { private static final long serialVersionUID = 1103894512106650107L; private X509Certificate[] mCertChain; - public CertificateChainException(String msg, X509Certificate[] chain) { - super(msg); - setCertChain(chain); - } - - public CertificateChainException(CertificateException ce, - X509Certificate[] chain) { - super.initCause(ce); + public CertificateChainException(String msg, X509Certificate[] chain, Throwable cause) { + super(msg, cause); setCertChain(chain); } diff --git a/src/com/fsck/k9/net/ssl/TrustManagerFactory.java b/src/com/fsck/k9/net/ssl/TrustManagerFactory.java index 4a2c7206a..4e20f5c67 100644 --- a/src/com/fsck/k9/net/ssl/TrustManagerFactory.java +++ b/src/com/fsck/k9/net/ssl/TrustManagerFactory.java @@ -63,6 +63,8 @@ public final class TrustManagerFactory { String message = null; X509Certificate certificate = chain[0]; + Throwable cause = null; + try { defaultTrustManager.checkServerTrusted(chain, authType); new StrictHostnameVerifier().verify(mHost, certificate); @@ -70,15 +72,17 @@ public final class TrustManagerFactory { } catch (CertificateException e) { // cert. chain can't be validated message = e.getMessage(); + cause = e; } catch (SSLException e) { // host name doesn't match certificate message = e.getMessage(); + cause = e; } // Check the local key store if we couldn't verify the certificate using the global // key store or if the host name doesn't match the certificate name if (!keyStore.isValidCertificate(certificate, mHost, mPort)) { - throw new CertificateChainException(message, chain); + throw new CertificateChainException(message, chain, cause); } }