SSL debug info

pull/194/merge
M66B 3 years ago
parent cd89ea1bed
commit 3b1ff558db

@ -148,6 +148,7 @@ import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocket;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.TrustManagerFactory;
import io.requery.android.database.CursorWindowAllocationException; import io.requery.android.database.CursorWindowAllocationException;
@ -2698,51 +2699,62 @@ public class Log {
static SpannableStringBuilder getCiphers() { static SpannableStringBuilder getCiphers() {
SpannableStringBuilder ssb = new SpannableStringBuilderEx(); SpannableStringBuilder ssb = new SpannableStringBuilderEx();
for (String protocol : new String[]{"SSL", "TLS"}) { try {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init((KeyStore) null);
ssb.append("Provider: ").append(tmf.getProvider().getName()).append("\r\n");
ssb.append("Algorithm: ").append(tmf.getAlgorithm()).append("\r\n");
TrustManager[] tms = tmf.getTrustManagers();
if (tms != null)
for (TrustManager tm : tms)
ssb.append("Manager: ").append(tm.getClass().getName()).append("\r\n");
SSLContext sslContext;
try { try {
int begin = ssb.length(); sslContext = SSLContext.getInstance("SSL");
ssb.append(protocol).append("\n\n"); } catch (Throwable ex) {
ssb.setSpan(new StyleSpan(Typeface.BOLD), begin, ssb.length(), 0); Log.e(ex);
sslContext = SSLContext.getInstance("TLS");
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); }
tmf.init((KeyStore) null);
SSLContext sslContext = SSLContext.getInstance(protocol);
sslContext.init(null, tmf.getTrustManagers(), null);
SSLSocket socket = (SSLSocket) sslContext.getSocketFactory().createSocket();
List<String> protocols = new ArrayList<>();
protocols.addAll(Arrays.asList(socket.getEnabledProtocols()));
for (String p : socket.getSupportedProtocols()) {
boolean enabled = protocols.contains(p);
int start = ssb.length();
ssb.append(p);
if (!enabled)
ssb.setSpan(new StrikethroughSpan(), start, ssb.length(), 0);
ssb.append("\r\n");
}
ssb.append("\r\n");
List<String> ciphers = new ArrayList<>(); ssb.append("Context: ").append(sslContext.getProtocol()).append("\r\n\r\n");
ciphers.addAll(Arrays.asList(socket.getEnabledCipherSuites()));
sslContext.init(null, tmf.getTrustManagers(), null);
for (String c : socket.getSupportedCipherSuites()) { SSLSocket socket = (SSLSocket) sslContext.getSocketFactory().createSocket();
boolean enabled = ciphers.contains(c);
if (!enabled) List<String> protocols = new ArrayList<>();
ssb.append('('); protocols.addAll(Arrays.asList(socket.getEnabledProtocols()));
int start = ssb.length();
ssb.append(c); for (String p : socket.getSupportedProtocols()) {
if (!enabled) { boolean enabled = protocols.contains(p);
ssb.setSpan(new StrikethroughSpan(), start, ssb.length(), 0); int start = ssb.length();
ssb.append(')'); ssb.append(p);
} if (!enabled)
ssb.append("\r\n"); ssb.setSpan(new StrikethroughSpan(), start, ssb.length(), 0);
ssb.append("\r\n");
}
ssb.append("\r\n");
List<String> ciphers = new ArrayList<>();
ciphers.addAll(Arrays.asList(socket.getEnabledCipherSuites()));
for (String c : socket.getSupportedCipherSuites()) {
boolean enabled = ciphers.contains(c);
if (!enabled)
ssb.append('(');
int start = ssb.length();
ssb.append(c);
if (!enabled) {
ssb.setSpan(new StrikethroughSpan(), start, ssb.length(), 0);
ssb.append(')');
} }
ssb.append("\r\n"); ssb.append("\r\n");
} catch (Throwable ex) {
ssb.append(ex.toString());
} }
ssb.append("\r\n");
} catch (Throwable ex) {
ssb.append(ex.toString());
} }
ssb.setSpan(new RelativeSizeSpan(HtmlHelper.FONT_SMALL), 0, ssb.length(), 0); ssb.setSpan(new RelativeSizeSpan(HtmlHelper.FONT_SMALL), 0, ssb.length(), 0);

Loading…
Cancel
Save