chain the exception

This commit is contained in:
Art O Cathain 2014-10-11 16:11:12 +01:00
parent 7945aab8a7
commit d980e49fd1
2 changed files with 7 additions and 9 deletions

View File

@ -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);
}

View File

@ -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);
}
}