From dcf5d150a618b6b9b78b42d38943fca47cdc461b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Veres-Szentkir=C3=A1lyi?= Date: Mon, 4 Apr 2011 16:47:56 +0200 Subject: [PATCH] Added SHA-1 checksum to acceptKeyDialog --- .../setup/AccountSetupCheckSettings.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java b/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java index facae58e2..2aaac3fd5 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java @@ -23,9 +23,13 @@ import com.fsck.k9.mail.Store; import com.fsck.k9.mail.Transport; import com.fsck.k9.mail.store.TrustManagerFactory; import com.fsck.k9.mail.store.WebDavStore; +import com.fsck.k9.mail.filter.Hex; import java.security.cert.CertificateException; +import java.security.cert.CertificateEncodingException; import java.security.cert.X509Certificate; +import java.security.NoSuchAlgorithmException; +import java.security.MessageDigest; /** * Checks the given settings to make sure that they can be used to send and @@ -237,11 +241,26 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList mProgressBar.setIndeterminate(false); StringBuffer chainInfo = new StringBuffer(100); + MessageDigest sha1 = null; + try { + sha1 = MessageDigest.getInstance("SHA-1"); + } catch (NoSuchAlgorithmException e) { + Log.e(K9.LOG_TAG, "Error while initializing MessageDigest", e); + } for (int i = 0; i < chain.length; i++) { // display certificate chain information chainInfo.append("Certificate chain[" + i + "]:\n"); chainInfo.append("Subject: " + chain[i].getSubjectDN().toString() + "\n"); chainInfo.append("Issuer: " + chain[i].getIssuerDN().toString() + "\n"); + if (sha1 != null) { + sha1.reset(); + try { + char[] sha1sum = Hex.encodeHex(sha1.digest(chain[i].getEncoded())); + chainInfo.append("Fingerprint (SHA-1): " + new String(sha1sum) + "\n"); + } catch (CertificateEncodingException e) { + Log.e(K9.LOG_TAG, "Error while encoding certificate", e); + } + } } new AlertDialog.Builder(AccountSetupCheckSettings.this)