Add SSL configuration to worker process arguments
@@ -25,12 +25,17 @@ import org.hyperic.sigar.SigarException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.net.ssl.SSLSocket;
import java.io.File;
import java.io.FilenameFilter;
+import java.io.IOException;
import java.net.InetAddress;
-import java.util.List;
+import java.util.*;
+import static java.util.Collections.singletonList;
+import static javax.net.ssl.SSLSocketFactory.getDefault;
import static org.ngrinder.common.constants.GrinderConstants.GRINDER_SECURITY_LEVEL_LIGHT;
+import static org.ngrinder.common.util.NoOp.noOp;
import static org.ngrinder.common.util.Preconditions.checkNotEmpty;
import static org.ngrinder.common.util.Preconditions.checkNotNull;
@@ -45,6 +50,8 @@ import static org.ngrinder.common.util.Preconditions.checkNotNull;
*/
public class PropertyBuilder {
private static final Logger LOGGER = LoggerFactory.getLogger(ProcessBuilder.class);
+ private static final Set<String> DISABLED_SSL_PROTOCOLS = new HashSet<>(singletonList("SSLv2Hello"));
+
private final GrinderProperties properties;
private final Directory baseDirectory;
private final String hostName;
@@ -173,11 +180,14 @@ public class PropertyBuilder {
jvmArguments.append(properties.getProperty("grinder.jvm.arguments", ""));
jvmArguments = addNativeLibraryPath(jvmArguments);
}
+
jvmArguments = addParam(jvmArguments, properties.getProperty("grinder.param", ""));
jvmArguments = addPythonPathJvmArgument(jvmArguments);
jvmArguments = addCustomDns(jvmArguments);
jvmArguments = addUserDir(jvmArguments);
jvmArguments = addContext(jvmArguments);
+ jvmArguments = addHttpsProtocols(jvmArguments);
+ jvmArguments = disableSNIExtension(jvmArguments);
if (server) {
jvmArguments = addServerMode(jvmArguments);
@@ -188,6 +198,34 @@ public class PropertyBuilder {
return jvmArguments.toString();
}
+ protected StringBuilder disableSNIExtension(StringBuilder jvmArguments) {
+ return jvmArguments.append(" -Djsse.enableSNIExtension=false ");
+ }
+
+ protected StringBuilder addHttpsProtocols(StringBuilder jvmArguments) {
+ String[] sslProtocols = {"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"};
+
+ try {
+ SSLSocket socket = (SSLSocket) getDefault().createSocket();
+ sslProtocols = socket.getSupportedProtocols();
+ } catch (IOException e) {
+ noOp();
+ }
+
+ List<String> protocols = new ArrayList<>();
+ for (String protocol: sslProtocols) {
+ if (DISABLED_SSL_PROTOCOLS.contains(protocol)) {
+ continue;
+ }
+ protocols.add(protocol);
+ }
+
+ return jvmArguments
+ .append(" -Dhttps.protocols=")
+ .append(StringUtils.join(protocols, ","))
+ .append(" ");
+ }
+
protected StringBuilder addContext(StringBuilder jvmArguments) {
return jvmArguments.append(" -Dngrinder.context=agent ");
}
