aboutsummaryrefslogtreecommitdiff
path: root/tlsproxy.sh
blob: a89387262b3738cbb6d481c0e7acd964eae075fe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh

set -xe

# Enter proper cluster subdirectory

cd $(dirname $0)

CLUSTER="$1"
if [ ! -d "cluster/$CLUSTER" ]; then
	echo "Usage: $0 <cluster name>"
	echo "The cluster name must be the name of a subdirectory of cluster/"
	exit 1
fi

cd cluster/$CLUSTER

# Do actual stuff

YEAR=$(date +%Y)

_int() {
  echo "Caught SIGINT signal!"
  kill -INT "$child1" 2>/dev/null
  kill -INT "$child2" 2>/dev/null
}

trap _int SIGINT

socat -dd tcp4-listen:4646,reuseaddr,fork openssl:localhost:14646,cert=secrets/pki/nomad$YEAR-client.crt,key=secrets/pki/nomad$YEAR-client.key,cafile=secrets/pki/nomad$YEAR.crt &
child1=$!

socat -dd tcp4-listen:8500,reuseaddr,fork openssl:localhost:8501,cert=secrets/pki/consul$YEAR-client.crt,key=secrets/pki/consul$YEAR-client.key,cafile=secrets/pki/consul$YEAR.crt &
child2=$!

wait "$child1"
wait "$child2"