mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-30 05:02:26 -05:00
Clean-up related to certificate chains
Per comments in pull request #365
This commit is contained in:
parent
8b4064b216
commit
ac42bce799
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user