Switch to BC on unsupported protocol

master
M66B 2 days ago
parent 170cfce52d
commit 7a987e71e7

@ -73,6 +73,7 @@ import javax.mail.MessagingException;
import javax.net.SocketFactory; import javax.net.SocketFactory;
import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.SSLSocketFactory;
@ -504,6 +505,17 @@ public class ConnectionHelper {
return false; return false;
} }
static boolean isUnsupportedProtocol(Throwable ex) {
while (ex != null) {
if (ex instanceof SSLHandshakeException &&
ex.getMessage() != null &&
ex.getMessage().contains("UNSUPPORTED_PROTOCOL"))
return true;
ex = ex.getCause();
}
return false;
}
static boolean isAborted(Throwable ex) { static boolean isAborted(Throwable ex) {
while (ex != null) { while (ex != null) {
String msg = ex.getMessage(); String msg = ex.getMessage();

@ -742,6 +742,24 @@ public class EmailService implements AutoCloseable {
((ErrnoException) ex.getCause().getCause()).errno == OsConstants.EACCES) ((ErrnoException) ex.getCause().getCause()).errno == OsConstants.EACCES)
throw new SecurityException("EACCES Please check 'Restrict data usage' in the Android app settings", ex); throw new SecurityException("EACCES Please check 'Restrict data usage' in the Android app settings", ex);
if (!ssl_harden && ConnectionHelper.isUnsupportedProtocol(ex)) {
EntityLog.log(context, EntityLog.Type.Network, "Unsuported protocol");
try {
this.insecure = true;
factory = new SSLSocketFactoryService(context,
host, port, true, false,
false, false, false, false,
false,
true, true,
factory.key, factory.chain, factory.trustedFingerprint);
properties.put("mail." + protocol + ".ssl.socketFactory", factory);
_connect(main, port, require_id, user, factory);
return;
} catch (GeneralSecurityException ex1) {
Log.e(ex1);
}
return;
} else {
boolean ioError = false; boolean ioError = false;
Throwable ce = ex; Throwable ce = ex;
while (ce != null) { while (ce != null) {
@ -818,6 +836,7 @@ public class EmailService implements AutoCloseable {
throw new MessagingException(ex1.getMessage(), ex1); throw new MessagingException(ex1.getMessage(), ex1);
} }
} }
}
throw ex; throw ex;
} }
@ -1111,6 +1130,8 @@ public class EmailService implements AutoCloseable {
private boolean secure; private boolean secure;
private boolean ssl_harden; private boolean ssl_harden;
private boolean ssl_harden_strict; private boolean ssl_harden_strict;
private PrivateKey key;
private X509Certificate[] chain;
private String trustedFingerprint; private String trustedFingerprint;
private SSLSocketFactory factory; private SSLSocketFactory factory;
private X509Certificate certificate; private X509Certificate certificate;
@ -1125,6 +1146,8 @@ public class EmailService implements AutoCloseable {
this.secure = !insecure; this.secure = !insecure;
this.ssl_harden = ssl_harden; this.ssl_harden = ssl_harden;
this.ssl_harden_strict = ssl_harden_strict; this.ssl_harden_strict = ssl_harden_strict;
this.key = key;
this.chain = chain;
this.trustedFingerprint = fingerprint; this.trustedFingerprint = fingerprint;
TrustManager[] tms = SSLHelper.getTrustManagers( TrustManager[] tms = SSLHelper.getTrustManagers(

Loading…
Cancel
Save