Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/main/java/com/globocom/grou/groot/channel/ChannelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.netty.util.concurrent.ScheduledFuture;
import java.net.URI;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
Expand All @@ -49,7 +50,8 @@ public class ChannelManager {
private final long start;
private final ScheduledExecutorService executor;

private SslService sslService = null;
private final SslEngine sslEngine = new SslEngine();
private List<String> ciphers = null;
private MonitorService monitorService = null;
private Bootstrap bootstrap = null;
private EventLoopGroup group = null;
Expand All @@ -66,11 +68,6 @@ public ChannelManager() {
executor = Executors.newSingleThreadScheduledExecutor();
}

public ChannelManager setSslService(SslService sslService) {
this.sslService = sslService;
return this;
}

public ChannelManager setMonitorService(MonitorService monitorService) {
this.monitorService = monitorService;
return this;
Expand Down Expand Up @@ -109,9 +106,13 @@ public ChannelManager setNumConn(int numConn) {
return this;
}

public ChannelManager setSslCiphers(List<String> ciphers) {
this.ciphers = ciphers;
return this;
}

public ChannelManager check() throws IllegalArgumentException {
if (monitorService == null ||
sslService == null ||
numConn == 0 ||
durationSec == 0 ||
bootstrap == null ||
Expand All @@ -125,9 +126,9 @@ public ChannelManager check() throws IllegalArgumentException {

private ChannelInitializer initializer(Proto proto) {
if (proto == Proto.H2 || proto == Proto.H2C) {
return new Http2ClientInitializer(sslService.sslContext(proto.isSsl()), Integer.MAX_VALUE, monitorService);
return new Http2ClientInitializer(sslEngine.setCiphers(ciphers).sslContext(proto.isSsl()), Integer.MAX_VALUE, monitorService);
}
return new Http1ClientInitializer(sslService.sslContext(proto.isSsl()), monitorService);
return new Http1ClientInitializer(sslEngine.setCiphers(ciphers).sslContext(proto.isSsl()), monitorService);
}

private SimpleImmutableEntry<Channel, ScheduledFuture> newChannel() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,22 @@
import io.netty.handler.ssl.SslProvider;
import io.netty.handler.ssl.SupportedCipherSuiteFilter;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import java.util.List;
import javax.net.ssl.SSLException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

@Service
public class SslService {
public class SslEngine {

private static final Log LOGGER = LogFactory.getLog(SslService.class);
private static final Log LOGGER = LogFactory.getLog(SslEngine.class);
private static final List<String> DEFAULT_CIPHERS = Http2SecurityUtil.CIPHERS;

private List<String> ciphers = null;

public SslEngine setCiphers(List<String> ciphers) {
this.ciphers = ciphers;
return this;
}

public SslContext sslContext(boolean ssl) {
if (ssl) {
Expand All @@ -46,7 +53,7 @@ public SslContext sslContext(boolean ssl) {
.sslProvider(provider)
/* NOTE: the cipher filter may not include all ciphers required by the HTTP/2 specification.
* Please refer to the HTTP/2 specification for cipher requirements. */
.ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
.ciphers(ciphers == null ? DEFAULT_CIPHERS : ciphers, SupportedCipherSuiteFilter.INSTANCE)
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.applicationProtocolConfig(new ApplicationProtocolConfig(
Protocol.ALPN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
import com.globocom.grou.groot.channel.BootstrapBuilder;
import com.globocom.grou.groot.channel.ChannelManager;
import com.globocom.grou.groot.channel.RequestUtils;
import com.globocom.grou.groot.channel.SslService;
import com.globocom.grou.groot.monit.MonitorService;
import com.globocom.grou.groot.test.properties.BaseProperty;
import com.globocom.grou.groot.test.properties.SslProperty;
import io.netty.bootstrap.Bootstrap;
import io.netty.handler.codec.http.FullHttpRequest;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand All @@ -38,12 +39,10 @@ public class RequestExecutorService {

private static final Log LOGGER = LogFactory.getLog(RequestExecutorService.class);

private final SslService sslService;
private final MonitorService monitorService;

@Autowired
public RequestExecutorService(SslService sslService, MonitorService monitorService) {
this.sslService = sslService;
public RequestExecutorService(MonitorService monitorService) {
this.monitorService = monitorService;
}

Expand All @@ -52,6 +51,8 @@ public void submit(BaseProperty property) throws RuntimeException {
int maxTestDuration = Integer.parseInt(SystemEnv.MAX_TEST_DURATION.getValue());
int durationSec = getDurationSec(property, maxTestDuration);
int fixedDelay = property.getFixedDelay();
SslProperty sslProperty = Optional.ofNullable(property.getSsl()).orElse(new SslProperty());
List<String> ciphers = sslProperty.getCiphers();

String scheme = RequestUtils.extractScheme(property);
if (scheme == null) {
Expand All @@ -66,7 +67,7 @@ public void submit(BaseProperty property) throws RuntimeException {
final ChannelManager channelManager = new ChannelManager()
.setBootstrap(bootstrap)
.setMonitorService(monitorService)
.setSslService(sslService)
.setSslCiphers(ciphers)
.setProto(proto)
.setDurationSec(durationSec)
.setFixedDelay(fixedDelay)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public class BaseProperty implements Serializable {
*/
private AuthProperty auth;

/**
* SSL properties.
*/
private SslProperty ssl;

/**
* Body request
*/
Expand Down Expand Up @@ -229,6 +234,15 @@ public BaseProperty setAuth(AuthProperty auth) {
return this;
}

public SslProperty getSsl() {
return ssl;
}

public BaseProperty setSsl(SslProperty ssl) {
this.ssl = ssl;
return this;
}

public String getBody() {
return body;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.globocom.grou.groot.test.properties;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;

import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable;
import java.util.List;

@JsonInclude(NON_NULL)
public class SslProperty implements Serializable {

private static final long serialVersionUID = 1L;

private List<String> ciphers;

public List<String> getCiphers() {
return ciphers;
}

public SslProperty setCiphers(List<String> ciphers) {
this.ciphers = ciphers;
return this;
}
}