Skip to content

Commit aa767ea

Browse files
authored
Merge pull request #93 from tls-attacker/timingScanAdjustments
Extended Server Management
2 parents fbee67d + 5758b40 commit aa767ea

File tree

30 files changed

+182
-90
lines changed

30 files changed

+182
-90
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit e4687d050a880ade0a1875e809b41f6158db7b67
1+
Subproject commit 383eddde97eadb5052427bd04f3bd9dd5c7ca493

images/baseimage/entrypoints/cmd/server-entrypoint/main.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"entrypoints/lib"
55
"fmt"
66
"net/http"
7-
"os"
87
"strconv"
98
"time"
109
)
@@ -18,16 +17,11 @@ func infinite() {
1817
elapsed := time.Since(start)
1918

2019
fmt.Println("Server terminated! (" + strconv.Itoa(int(elapsed.Milliseconds())) + "ms)")
21-
if elapsed < 100 * time.Millisecond || exitCode > 0 || exitCode == -1 {
22-
time.Sleep(50 * time.Millisecond)
20+
if elapsed < 20 * time.Millisecond || exitCode > 0 || exitCode == -1 {
2321
failed = failed + 1
2422
} else {
2523
failed = 0
2624
}
27-
28-
if failed > 5 {
29-
os.Exit(99)
30-
}
3125
}
3226
}
3327

@@ -36,6 +30,9 @@ func main() {
3630
go infinite()
3731

3832
http.HandleFunc("/shutdown", lib.Shutdown)
33+
http.HandleFunc("/portrequest", lib.Portrequest)
34+
http.HandleFunc("/enableportswitch", lib.EnablePortSwitch)
35+
http.HandleFunc("/killserver", lib.KillServer)
3936
fmt.Println("Listening on :8090...")
4037
_ = http.ListenAndServe(":8090", nil)
41-
}
38+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module entrypoints
22

33
go 1.14
4+
5+
require github.com/phayes/freeport 1.0.2

images/baseimage/entrypoints/lib/lib.go

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,61 @@ package lib
33
import (
44
"fmt"
55
"net/http"
6+
"strconv"
7+
"strings"
68
"os"
79
"os/exec"
10+
"github.com/phayes/freeport"
11+
"regexp"
812
)
913

1014
var args = os.Args[1:]
15+
var port = -1
16+
var portSwitch = false
17+
var cmd *exec.Cmd
1118

1219
func ExecuteArgs() int {
13-
var cmd *exec.Cmd
20+
freeport, err := freeport.GetFreePort()
21+
if err != nil {
22+
fmt.Printf("Failed to get port")
23+
}
24+
1425
if len(args) > 1 {
1526
program := args[0]
1627
argv := args[1:]
28+
29+
if portSwitch {
30+
port = freeport
31+
replaced := false
32+
// find numbers in arguments and replace with free port
33+
for i, s := range argv {
34+
if _, errA := strconv.Atoi(s); errA == nil {
35+
fmt.Printf("Changing port %q to %q for new container instance.\n", s, strconv.Itoa(port))
36+
argv[i] = strconv.Itoa(port)
37+
}
38+
}
39+
40+
// attempt to replace in structures like --port=4433
41+
if replaced == false {
42+
for j, t := range argv {
43+
regex := regexp.MustCompile("[0-9]+")
44+
found := regex.FindAllString(t, -1)
45+
// ensure argument only has one number and ends with this number
46+
if len(found) == 1 && strings.HasSuffix(t, found[0]) && strings.Contains(t, "=") {
47+
fmt.Printf("Changing port %q of parameter %q to %q for new container instance.\n", found[0], t, strconv.Itoa(port))
48+
argv[j] = strings.Replace(argv[j], found[0], strconv.Itoa(port), -1)
49+
}
50+
}
51+
}
52+
53+
} else {
54+
// try to set port according to arguments
55+
for _, s := range argv {
56+
if val, errA := strconv.Atoi(s); errA == nil {
57+
port = val
58+
}
59+
}
60+
}
1761

1862
cmd = exec.Command(program, argv...)
1963
} else if len(args) > 0 {
@@ -28,7 +72,7 @@ func ExecuteArgs() int {
2872
cmd.Stdout = os.Stdout
2973
cmd.Stderr = os.Stderr
3074
// keep stdin open
31-
_, err := cmd.StdinPipe()
75+
_, err = cmd.StdinPipe()
3276

3377
err = cmd.Run()
3478

@@ -44,3 +88,22 @@ func Shutdown(w http.ResponseWriter, req *http.Request) {
4488

4589
go os.Exit(0)
4690
}
91+
92+
func Portrequest(w http.ResponseWriter, req *http.Request) {
93+
concatenated := strings.Join([]string{"Use:",strconv.Itoa(port), "-Port"}, "")
94+
fmt.Fprintf(w, concatenated)
95+
fmt.Println("Reported port")
96+
}
97+
98+
func EnablePortSwitch(w http.ResponseWriter, req *http.Request) {
99+
portSwitch = true
100+
cmd.Process.Kill()
101+
fmt.Fprintf(w, "Port switching enabled, restarted server")
102+
fmt.Println("Enabled port switching, restarted server")
103+
}
104+
105+
func KillServer(w http.ResponseWriter, req *http.Request) {
106+
cmd.Process.Kill()
107+
fmt.Fprintf(w, "The server is dead, long live the server")
108+
fmt.Println("Killed server as requested")
109+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM alpine-build:3.12 as bearssl-base1
22
ARG VERSION
3-
RUN git clone --depth=1 --branch=v${VERSION} https://www.bearssl.org/git/BearSSL
3+
RUN git clone --depth=1 --branch=${VERSION} https://www.bearssl.org/git/BearSSL
44
WORKDIR BearSSL
55
RUN make
66

images/bearssl/bearssl-0_X.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

images/bearssl/bearssl.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
cd "$(dirname "$0")" || exit 1
3+
source ../helper-functions.sh
4+
5+
# build master when required since releases are rare
6+
_docker build --build-arg VERSION=master -t ${DOCKER_REPOSITORY}bearssl-server:master -f Dockerfile --target bearssl-server .
7+
_docker build --build-arg VERSION=master -t ${DOCKER_REPOSITORY}bearssl-client:master -f Dockerfile --target bearssl-client .
8+
9+
# release versions
10+
versions=(0.4 0.5 0.6)
11+
for i in "${versions[@]}"; do
12+
_docker build --build-arg VERSION=v${i} -t ${DOCKER_REPOSITORY}bearssl-server:${i} -f Dockerfile --target bearssl-server .
13+
_docker build --build-arg VERSION=v${i} -t ${DOCKER_REPOSITORY}bearssl-client:${i} -f Dockerfile --target bearssl-client .
14+
done
15+
16+
exit "$EXITCODE"

images/bearssl/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ cd "$(dirname "$0")" || exit 1
33
source ../helper-functions.sh
44
exit_on_error
55

6-
track_error ./bearssl-0_X.sh
6+
track_error ./bearssl.sh
77

88
exit "$EXITCODE"

images/boringssl/Dockerfile-2214-2661

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM alpine-build:3.12 as boringssl-base1
22
ARG VERSION
3-
RUN git clone --depth=1 -b ${VERSION} https://boringssl.googlesource.com/boringssl
3+
RUN git clone --depth=1 -b ${VERSION} https://github.com/google/boringssl.git
44
#remove the errorflags in CMakeLists.txt otherwise boringssl will not compile (workaround)
55
#/src/boringssl/crypto/pem/pem_lib.c:460:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
66
RUN sed -i -e 's/-Wall -Werror //g' /src/boringssl/CMakeLists.txt

images/boringssl/Dockerfile-2272-2357

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM alpine-build:3.12 as boringssl-base1
22
ARG VERSION
3-
RUN git clone --depth=1 -b ${VERSION} https://boringssl.googlesource.com/boringssl
3+
RUN git clone --depth=1 -b ${VERSION} https://github.com/google/boringssl.git
44
#remove the errorflags in CMakeLists.txt otherwise boringssl will not compile (workaround)
55
#/src/boringssl/crypto/pem/pem_lib.c:460:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
66
RUN sed -i -e 's/-Wall -Wshadow -Werror //g' /src/boringssl/CMakeLists.txt

0 commit comments

Comments
 (0)