Refactoring

pull/178/head
M66B 5 years ago
parent 3574e1f45e
commit f3489df28c

@ -773,31 +773,39 @@ public class EmailService implements AutoCloseable {
private Socket configure(Socket socket) { private Socket configure(Socket socket) {
if (socket instanceof SSLSocket) { if (socket instanceof SSLSocket) {
// https://developer.android.com/reference/javax/net/ssl/SSLSocket.html
SSLSocket sslSocket = (SSLSocket) socket; SSLSocket sslSocket = (SSLSocket) socket;
if (!secure) {
sslSocket.setEnabledProtocols(sslSocket.getSupportedProtocols());
List<String> ciphers = new ArrayList<>();
for (String cipher : sslSocket.getSupportedCipherSuites())
if (!cipher.endsWith("_SCSV"))
ciphers.add(cipher);
sslSocket.setEnabledCipherSuites(ciphers.toArray(new String[0]));
} else if (harden) {
List<String> protocols = new ArrayList<>(); List<String> protocols = new ArrayList<>();
for (String protocol : for (String protocol : sslSocket.getEnabledProtocols())
secure ? sslSocket.getEnabledProtocols() : sslSocket.getSupportedProtocols()) if (SSL_PROTOCOL_BLACKLIST.contains(protocol))
if (secure && harden && SSL_PROTOCOL_BLACKLIST.contains(protocol))
Log.i("SSL disabling protocol=" + protocol); Log.i("SSL disabling protocol=" + protocol);
else else
protocols.add(protocol); protocols.add(protocol);
Log.i("SSL protocols=" + TextUtils.join(",", protocols));
sslSocket.setEnabledProtocols(protocols.toArray(new String[0])); sslSocket.setEnabledProtocols(protocols.toArray(new String[0]));
ArrayList<String> ciphers = new ArrayList<>(); List<String> ciphers = new ArrayList<>();
for (String cipher : for (String cipher : sslSocket.getEnabledCipherSuites()) {
secure ? sslSocket.getEnabledCipherSuites() : sslSocket.getSupportedCipherSuites()) { if (SSL_CIPHER_BLACKLIST.matcher(cipher).matches())
if (secure && harden && SSL_CIPHER_BLACKLIST.matcher(cipher).matches())
Log.i("SSL disabling cipher=" + cipher); Log.i("SSL disabling cipher=" + cipher);
else if (secure || !cipher.endsWith("_SCSV")) else
ciphers.add(cipher); ciphers.add(cipher);
} }
Log.i("SSL ciphers=" + TextUtils.join(",", ciphers));
sslSocket.setEnabledCipherSuites(ciphers.toArray(new String[0])); sslSocket.setEnabledCipherSuites(ciphers.toArray(new String[0]));
} }
Log.i("SSL protocols=" + TextUtils.join(",", sslSocket.getEnabledProtocols()));
Log.i("SSL ciphers=" + TextUtils.join(",", sslSocket.getEnabledCipherSuites()));
}
return socket; return socket;
} }

Loading…
Cancel
Save