TLS debugging

pull/194/merge
M66B 4 years ago
parent 5603fe88ca
commit f0cf46db94

@ -2255,11 +2255,12 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
message.headers, message.blocklist != null && message.blocklist); message.headers, message.blocklist != null && message.blocklist);
if (BuildConfig.DEBUG && headers instanceof SpannableStringBuilder) { if (BuildConfig.DEBUG && headers instanceof SpannableStringBuilder) {
SpannableStringBuilder ssb = (SpannableStringBuilder) headers; SpannableStringBuilder ssb = (SpannableStringBuilder) headers;
ssb.append("TLS=" + message.tls).append('\n'); ssb.append("TLS=" + message.tls)
ssb.append("DKIM=" + message.dkim).append('\n'); .append(" DKIM=" + message.dkim)
ssb.append("SPF=" + message.spf).append('\n'); .append(" SPF=" + message.spf)
ssb.append("DMARC=" + message.dmarc).append('\n'); .append(" DMARC=" + message.dmarc)
ssb.append("BL=" + message.blocklist).append('\n'); .append(" BL=" + message.blocklist)
.append('\n');
} }
tvHeaders.setText(headers); tvHeaders.setText(headers);
ibCopyHeaders.setVisibility(View.VISIBLE); ibCopyHeaders.setVisibility(View.VISIBLE);

@ -2380,6 +2380,8 @@ public class HtmlHelper {
static Spanned highlightHeaders(Context context, String headers, boolean blocklist) { static Spanned highlightHeaders(Context context, String headers, boolean blocklist) {
SpannableStringBuilder ssb = new SpannableStringBuilderEx(headers); SpannableStringBuilder ssb = new SpannableStringBuilderEx(headers);
int textColorLink = Helper.resolveColor(context, android.R.attr.textColorLink); int textColorLink = Helper.resolveColor(context, android.R.attr.textColorLink);
int colorVerified = Helper.resolveColor(context, R.attr.colorVerified);
int colorWarning = Helper.resolveColor(context, R.attr.colorWarning);
int index = 0; int index = 0;
for (String line : headers.split("\n")) { for (String line : headers.split("\n")) {
@ -2421,8 +2423,6 @@ public class HtmlHelper {
int iconSize = context.getResources().getDimensionPixelSize(R.dimen.menu_item_icon_size); int iconSize = context.getResources().getDimensionPixelSize(R.dimen.menu_item_icon_size);
d.setBounds(0, 0, iconSize, iconSize); d.setBounds(0, 0, iconSize, iconSize);
int colorWarning = Helper.resolveColor(context, R.attr.colorWarning);
d.setTint(colorWarning); d.setTint(colorWarning);
ssb.append(" \uFFFC"); // Object replacement character ssb.append(" \uFFFC"); // Object replacement character
@ -2462,6 +2462,14 @@ public class HtmlHelper {
j++; j++;
} }
Boolean tls = MessageHelper.isTLS(h);
ssb.append(" TLS=");
int t = ssb.length();
ssb.append(tls == null ? "?" : Boolean.toString(tls));
if (tls != null)
ssb.setSpan(new ForegroundColorSpan(tls ? colorVerified : colorWarning), t, ssb.length(), 0);
ssb.append("\n\n"); ssb.append("\n\n");
} }
} }

@ -2055,7 +2055,15 @@ public class MessageHelper {
for (String r : received) { for (String r : received) {
String header = MimeUtility.unfold(r); String header = MimeUtility.unfold(r);
Log.i("--- header=" + header); Log.i("--- header=" + header);
Boolean tls = isTLS(header);
if (!Boolean.TRUE.equals(tls))
return tls;
}
return true;
}
static Boolean isTLS(String header) {
// Strip date // Strip date
int semi = header.lastIndexOf(';'); int semi = header.lastIndexOf(';');
if (semi > 0) if (semi > 0)
@ -2064,13 +2072,13 @@ public class MessageHelper {
if (header.contains("using TLS") || if (header.contains("using TLS") ||
header.contains("version=TLS")) { header.contains("version=TLS")) {
Log.i("--- found TLS"); Log.i("--- found TLS");
continue; return true;
} }
// (qmail nnn invoked by uid nnn); 1 Jan 2022 00:00:00 -0000 // (qmail nnn invoked by uid nnn); 1 Jan 2022 00:00:00 -0000
if (header.contains("qmail") && header.contains("invoked by uid")) { if (header.contains("qmail") && header.contains("invoked by uid")) {
Log.i("--- found qmail"); Log.i("--- found qmail");
continue; return true;
} }
// Get key/values // Get key/values
@ -2100,7 +2108,7 @@ public class MessageHelper {
String by = kv.get("by").toString(); String by = kv.get("by").toString();
if (isLocal(by)) { if (isLocal(by)) {
Log.i("--- local by=" + by); Log.i("--- local by=" + by);
continue; return true;
} }
} }
@ -2109,7 +2117,7 @@ public class MessageHelper {
String from = kv.get("from").toString(); String from = kv.get("from").toString();
if (isLocal(from)) { if (isLocal(from)) {
Log.i("--- local from=" + from); Log.i("--- local from=" + from);
continue; return true;
} }
} }
@ -2119,7 +2127,7 @@ public class MessageHelper {
String via = kv.get("via").toString(); String via = kv.get("via").toString();
if ("Frontend Transport".equals(via)) { if ("Frontend Transport".equals(via)) {
Log.i("--- frontend via=" + via); Log.i("--- frontend via=" + via);
continue; return true;
} }
} }
@ -2138,20 +2146,20 @@ public class MessageHelper {
if ("local".equals(protocol)) { if ("local".equals(protocol)) {
// Exim // Exim
Log.i("--- local with=" + with); Log.i("--- local with=" + with);
continue; return true;
} }
if ("mapi".equals(protocol)) { if ("mapi".equals(protocol)) {
// https://en.wikipedia.org/wiki/MAPI // https://en.wikipedia.org/wiki/MAPI
Log.i("--- mapi with=" + with); Log.i("--- mapi with=" + with);
continue; return true;
} }
if ("http".equals(protocol) || if ("http".equals(protocol) ||
"httprest".equals(protocol)) { "httprest".equals(protocol)) {
// httprest by gmailapi.google.com // httprest by gmailapi.google.com
Log.i("--- http with=" + with); Log.i("--- http with=" + with);
continue; return true;
} }
if (!protocol.contains("mtp")) { if (!protocol.contains("mtp")) {
@ -2159,17 +2167,15 @@ public class MessageHelper {
return null; return null;
} }
if (!protocol.contains("mtps" /* STARTTLS */) && if (protocol.contains("mtps")) {
!protocol.contains("_mtpa" /* AUTH */)) {
Log.i("--- insecure with=" + with); Log.i("--- insecure with=" + with);
return false; return true;
}
} }
return true; return false;
} }
private boolean isLocal(String value) { private static boolean isLocal(String value) {
if (value.contains("localhost") || if (value.contains("localhost") ||
value.contains("[127.0.0.1]") || value.contains("[127.0.0.1]") ||
value.contains("[::1]")) value.contains("[::1]"))

Loading…
Cancel
Save