Skip to content

Commit 7c60fa1

Browse files
authored
Respect specified port for TLS instance, update port only if mapping exists (#74)
1 parent 6ef6dcb commit 7c60fa1

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/main/java/de/rub/nds/tls/subject/docker/DockerTlsServerInstance.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
import de.rub.nds.tls.subject.HostInfo;
2424
import de.rub.nds.tls.subject.params.ParameterProfile;
2525
import de.rub.nds.tls.subject.properties.ImageProperties;
26-
import static java.lang.Thread.sleep;
27-
import java.util.logging.Level;
28-
import java.util.logging.Logger;
2926

3027
public class DockerTlsServerInstance extends DockerTlsInstance {
3128

@@ -62,10 +59,10 @@ protected CreateContainerCmd prepareCreateContainerCmd(CreateContainerCmd cmd) {
6259
} else {
6360
host = hostInfo.getHostname();
6461
}
65-
return super.prepareCreateContainerCmd(cmd).withCmd(parameterProfile.toParameters(host,
66-
imageProperties.getInternalPort(), imageProperties, additionalParameters, parallelize, insecureConnection))
67-
.withExposedPorts(
68-
new ExposedPort(imageProperties.getInternalPort(), hostInfo.getType().toInternetProtocol()));
62+
return super.prepareCreateContainerCmd(cmd)
63+
.withCmd(parameterProfile.toParameters(host, hostInfo.getPort(), imageProperties, additionalParameters,
64+
parallelize, insecureConnection))
65+
.withExposedPorts(new ExposedPort(hostInfo.getPort(), hostInfo.getType().toInternetProtocol()));
6966
}
7067

7168
@Override
@@ -78,7 +75,20 @@ public void start() {
7875
* Update port to match actually exposed port.
7976
*/
8077
public void updateInstancePort() {
81-
port = imageProperties.getInternalPort();
78+
InspectContainerResponse containerInfo = DOCKER.inspectContainerCmd(getId()).exec();
79+
if (containerInfo == null) {
80+
throw new IllegalStateException("Could not find container with ID:" + getId());
81+
}
82+
NetworkSettings networkSettings = containerInfo.getNetworkSettings();
83+
if (networkSettings == null) {
84+
throw new IllegalStateException(
85+
"Cannot retrieve InstacePort, Network not properly configured for container with ID:" + getId());
86+
}
87+
Binding[] binding = networkSettings.getPorts().getBindings().values().iterator().next();
88+
if (binding != null) {
89+
// only update if port mapping was necessary
90+
port = Integer.valueOf(binding[0].getHostPortSpec());
91+
}
8292
}
8393

8494
public int getPort() {

0 commit comments

Comments
 (0)