-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow the user to set: the supported TLS versions, the minimum DH key size, and the supported SSL cipher suites.
- Loading branch information
Showing
9 changed files
with
192 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 8 additions & 3 deletions
11
src/main/java/co/casterlabs/katana/config/SSLConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
package co.casterlabs.katana.config; | ||
|
||
import co.casterlabs.katana.http.TLSVersion; | ||
import lombok.ToString; | ||
|
||
@ToString | ||
public class SSLConfiguration { | ||
public boolean enabled = false; | ||
|
||
public TLSVersion[] tls = TLSVersion.values(); | ||
public String[] enabled_cipher_suites = null; // Null = All Available | ||
public boolean allow_insecure = true; | ||
public boolean force = false; | ||
public int dh_size = 2048; | ||
|
||
public String keystore_password = ""; | ||
public String key_password = ""; | ||
public String keystore = ""; | ||
|
||
public String keystore; | ||
public String keystore_password; | ||
public String key_password; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package co.casterlabs.katana.http; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
import xyz.e3ndr.reflectionlib.ReflectionLib; | ||
|
||
public enum TLSVersion { | ||
TLSv1, | ||
TLSv1_1, | ||
TLSv1_2, | ||
TLSv1_3; | ||
|
||
public String getRuntimeName() { | ||
return this.name().replace('_', '.'); | ||
} | ||
|
||
@SuppressWarnings("restriction") | ||
public boolean existsInRuntime() { | ||
try { | ||
ReflectionLib.invokeStaticMethod(sun.security.ssl.ProtocolVersion.class, "valueOf", this.getRuntimeName()); | ||
|
||
return true; | ||
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | InvocationTargetException e) { | ||
if (e.getCause() instanceof IllegalArgumentException) { | ||
return false; | ||
} else { | ||
e.printStackTrace(); | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
src/main/java/co/casterlabs/katana/http/WrappedSSLSocketFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package co.casterlabs.katana.http; | ||
|
||
import java.io.IOException; | ||
import java.net.InetAddress; | ||
import java.net.ServerSocket; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import javax.net.ssl.SSLServerSocket; | ||
import javax.net.ssl.SSLServerSocketFactory; | ||
|
||
import co.casterlabs.katana.config.SSLConfiguration; | ||
import xyz.e3ndr.fastloggingframework.logging.FastLogger; | ||
import xyz.e3ndr.fastloggingframework.logging.LogLevel; | ||
|
||
public class WrappedSSLSocketFactory extends SSLServerSocketFactory { | ||
private SSLServerSocketFactory wrappedFactory; | ||
private String[] cipherSuites; | ||
|
||
public WrappedSSLSocketFactory(SSLServerSocketFactory factory, SSLConfiguration ssl) { | ||
this.wrappedFactory = factory; | ||
|
||
if ((ssl.enabled_cipher_suites == null) || (ssl.enabled_cipher_suites.length == 0)) { | ||
this.cipherSuites = this.wrappedFactory.getSupportedCipherSuites(); | ||
} else { | ||
List<String> enabled = Arrays.asList(ssl.enabled_cipher_suites); | ||
List<String> supported = new ArrayList<>(); | ||
|
||
for (String def : this.wrappedFactory.getSupportedCipherSuites()) { | ||
if (enabled.contains(def)) { | ||
supported.add(def); | ||
} else { | ||
FastLogger.logStatic(LogLevel.DEBUG, "Disabled Cipher Suite: %s.", def); | ||
} | ||
} | ||
|
||
FastLogger.logStatic(LogLevel.DEBUG, "Using the following Cipher Suites: %s.", supported); | ||
|
||
this.cipherSuites = supported.toArray(new String[0]); | ||
} | ||
} | ||
|
||
@Override | ||
public String[] getDefaultCipherSuites() { | ||
return this.cipherSuites; | ||
} | ||
|
||
@Override | ||
public String[] getSupportedCipherSuites() { | ||
return this.cipherSuites; | ||
} | ||
|
||
@Override | ||
public ServerSocket createServerSocket() throws IOException { | ||
SSLServerSocket socket = (SSLServerSocket) this.wrappedFactory.createServerSocket(); | ||
|
||
socket.setEnabledCipherSuites(this.cipherSuites); | ||
|
||
return socket; | ||
} | ||
|
||
@Override | ||
public ServerSocket createServerSocket(int port) throws IOException { | ||
SSLServerSocket socket = (SSLServerSocket) this.wrappedFactory.createServerSocket(port); | ||
|
||
socket.setEnabledCipherSuites(this.cipherSuites); | ||
|
||
return socket; | ||
} | ||
|
||
@Override | ||
public ServerSocket createServerSocket(int port, int backlog) throws IOException { | ||
SSLServerSocket socket = (SSLServerSocket) this.wrappedFactory.createServerSocket(port, backlog); | ||
|
||
socket.setEnabledCipherSuites(this.cipherSuites); | ||
|
||
return socket; | ||
} | ||
|
||
@Override | ||
public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException { | ||
SSLServerSocket socket = (SSLServerSocket) this.wrappedFactory.createServerSocket(port, backlog, ifAddress); | ||
|
||
socket.setEnabledCipherSuites(this.cipherSuites); | ||
|
||
return socket; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters