2008-11-01 17:32:06 -04:00
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
package com.fsck.k9.mail;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2013-01-08 18:16:26 -05:00
|
|
|
import java.security.cert.CertPathValidatorException;
|
|
|
|
import java.security.cert.CertificateException;
|
2013-08-25 15:43:36 -04:00
|
|
|
import java.security.cert.X509Certificate;
|
2013-01-08 18:16:26 -05:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public class CertificateValidationException extends MessagingException {
|
2008-11-01 17:32:06 -04:00
|
|
|
public static final long serialVersionUID = -1;
|
2013-08-25 15:43:36 -04:00
|
|
|
private X509Certificate[] mCertChain;
|
2013-08-27 18:48:07 -04:00
|
|
|
private boolean mNeedsUserAttention = false;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public CertificateValidationException(String message) {
|
2008-11-01 17:32:06 -04:00
|
|
|
super(message);
|
2013-08-27 18:48:07 -04:00
|
|
|
scanForCause();
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2013-01-17 09:24:22 -05:00
|
|
|
public CertificateValidationException(final String message, Throwable throwable) {
|
2008-11-01 17:32:06 -04:00
|
|
|
super(message, throwable);
|
2013-08-27 18:48:07 -04:00
|
|
|
scanForCause();
|
2013-01-17 09:24:22 -05:00
|
|
|
}
|
|
|
|
|
2013-08-27 18:48:07 -04:00
|
|
|
private void scanForCause() {
|
2013-01-17 09:24:22 -05:00
|
|
|
Throwable throwable = getCause();
|
|
|
|
|
|
|
|
/* user attention is required if the certificate was deemed invalid */
|
2013-01-08 18:16:26 -05:00
|
|
|
while (throwable != null
|
|
|
|
&& !(throwable instanceof CertPathValidatorException)
|
|
|
|
&& !(throwable instanceof CertificateException)) {
|
|
|
|
throwable = throwable.getCause();
|
|
|
|
}
|
2013-01-17 09:24:22 -05:00
|
|
|
|
2013-08-27 18:48:07 -04:00
|
|
|
if (throwable != null) {
|
|
|
|
mNeedsUserAttention = true;
|
|
|
|
if (throwable instanceof CertificateChainException) {
|
|
|
|
mCertChain = ((CertificateChainException) throwable).getCertChain();
|
|
|
|
}
|
2013-08-25 15:43:36 -04:00
|
|
|
}
|
2013-08-27 18:48:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean needsUserAttention() {
|
|
|
|
return mNeedsUserAttention;
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
2013-08-25 15:43:36 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If the cause of this {@link CertificateValidationException} was a
|
|
|
|
* {@link CertificateChainException}, then the offending chain is available
|
|
|
|
* for return.
|
|
|
|
*
|
|
|
|
* @return An {@link X509Certificate X509Certificate[]} containing the Cert.
|
|
|
|
* chain, or else null.
|
|
|
|
*/
|
|
|
|
public X509Certificate[] getCertChain() {
|
|
|
|
return mCertChain;
|
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|