1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-15 14:05:05 -05:00

Clean-up related to certificate chains

Per comments in pull request #365
This commit is contained in:
Joe Steele 2013-08-27 18:48:07 -04:00
parent 8b4064b216
commit ac42bce799
2 changed files with 19 additions and 8 deletions

View File

@ -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

View File

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