mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-02 14:02:17 -05:00
Clean-up related to certificate chains
Per comments in pull request #365
This commit is contained in:
parent
8b4064b216
commit
ac42bce799
@ -164,7 +164,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
|
|||||||
if (chain != null) {
|
if (chain != null) {
|
||||||
acceptKeyDialog(
|
acceptKeyDialog(
|
||||||
R.string.account_setup_failed_dlg_certificate_message_fmt,
|
R.string.account_setup_failed_dlg_certificate_message_fmt,
|
||||||
cve, chain);
|
cve);
|
||||||
} else {
|
} else {
|
||||||
showErrorDialog(
|
showErrorDialog(
|
||||||
R.string.account_setup_failed_dlg_server_message_fmt,
|
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,
|
private void acceptKeyDialog(final int msgResId,
|
||||||
final CertificateValidationException ex, final X509Certificate[] chain) {
|
final CertificateValidationException ex) {
|
||||||
mHandler.post(new Runnable() {
|
mHandler.post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (mDestroyed) {
|
if (mDestroyed) {
|
||||||
@ -264,6 +264,9 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
|
|||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
Log.e(K9.LOG_TAG, "Error while initializing MessageDigest", 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++) {
|
for (int i = 0; i < chain.length; i++) {
|
||||||
// display certificate chain information
|
// display certificate chain information
|
||||||
//TODO: localize this strings
|
//TODO: localize this strings
|
||||||
|
@ -8,16 +8,19 @@ import java.security.cert.X509Certificate;
|
|||||||
public class CertificateValidationException extends MessagingException {
|
public class CertificateValidationException extends MessagingException {
|
||||||
public static final long serialVersionUID = -1;
|
public static final long serialVersionUID = -1;
|
||||||
private X509Certificate[] mCertChain;
|
private X509Certificate[] mCertChain;
|
||||||
|
private boolean mNeedsUserAttention = false;
|
||||||
|
|
||||||
public CertificateValidationException(String message) {
|
public CertificateValidationException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
|
scanForCause();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CertificateValidationException(final String message, Throwable throwable) {
|
public CertificateValidationException(final String message, Throwable throwable) {
|
||||||
super(message, throwable);
|
super(message, throwable);
|
||||||
|
scanForCause();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean needsUserAttention() {
|
private void scanForCause() {
|
||||||
Throwable throwable = getCause();
|
Throwable throwable = getCause();
|
||||||
|
|
||||||
/* user attention is required if the certificate was deemed invalid */
|
/* user attention is required if the certificate was deemed invalid */
|
||||||
@ -27,10 +30,16 @@ public class CertificateValidationException extends MessagingException {
|
|||||||
throwable = throwable.getCause();
|
throwable = throwable.getCause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (throwable != null) {
|
||||||
|
mNeedsUserAttention = true;
|
||||||
if (throwable instanceof CertificateChainException) {
|
if (throwable instanceof CertificateChainException) {
|
||||||
mCertChain = ((CertificateChainException) throwable).getCertChain();
|
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.
|
* chain, or else null.
|
||||||
*/
|
*/
|
||||||
public X509Certificate[] getCertChain() {
|
public X509Certificate[] getCertChain() {
|
||||||
needsUserAttention();
|
|
||||||
return mCertChain;
|
return mCertChain;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user