File: interop.sh

package info (click to toggle)
libreswan 5.2-2.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 81,632 kB
  • sloc: ansic: 129,988; sh: 32,018; xml: 20,646; python: 10,303; makefile: 3,022; javascript: 1,506; sed: 574; yacc: 511; perl: 264; awk: 52
file content (247 lines) | stat: -rwxr-xr-x 5,002 bytes parent folder | download
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# algo-{ikev1,ikev2}-<ike>-{esp,ah}-<esp|ah>

if test $# -eq 0 ; then
    cat <<EOF 1>&2
Usage:

  $0 <dir> ...

where the <dir> name is used to generate the test:

  <os(west)>-<os(east)>

	interop from <os(west)> to <os(east)); possible OSs are
	freebsd, netbsd, fedora, openbsd, debian, alpine, linux (aka
	east, west)

	default is linux

  strongswan|iked|racoon

	interop using the specified daemon; iked implies os=openbsd
	and racoon implies os=netbsd; hence iked-racoon interops from
	openbsd(west) to netbsd(east)

	default is libreswan

  ikev1|ikev2

  	force IKE version

  transport|tunnel

        propose transport (or tunnel)

  ipcomp

	propose ipcomp

  ike|esp|ah

	force interop to use the specified ike/esp/ah algorithm; for
	instance ike=aes_gcm or ah-sha2

  ipv4|ipv6|4in4|4in6|6in4|6in6

        force interop to use the INNERinOUTER protocols; default is IPv4

EOF
    exit 1
fi

emit() {
    echo
    echo "===> $1"
    echo
    tee $p/$1
}

i=0
script() {
    i=$(expr $i + 1)
    local n=$(printf "%02d-%s" $i $1)
    emit ${n}
}

for d in "$@" ; do

    p=$(realpath ${d})
    t=$(basename ${d})

    rm -vf ${p}/*.sh ${p}/*.conf ${p}/*.secrets

    i=0
    e=
    w=
    type='#type='
    compress='#compress='
    keyexchange='#keyexchange='
    ikev1_policy='#ikev1_policy'
    phase2='#phase2='
    ike='#ike='
    p2=
    p2a=
    k=
    daemon=libreswan

    for h in $(echo ${t} | tr '-' ' ') ; do
	case ${h} in

	    interop ) ;;

	    freebsd|netbsd|fedora|openbsd|debian|alpine) w=${e} ; e=${h} ;;
	    linux) w=${e} ; e= ;;

	    strongswan ) daemon=strongswan ; w=${e} ; e= ;;
	    iked )       daemon=iked       ; w=${e} ; e=openbsd ;;
	    racoon )     daemon=racoon     ; w=${e} ; e=netbsd ;;

	    transport ) type=type=transport ;;
	    tunnel )    type=type=tunnel    ;;

	    ipcomp) compress=compress=yes ;;

	    ikev1 ) k= ; keyexchange=keyexchange=ikev1 ; ikev1_policy=ikev1-policy=accept ;;
	    ikev2 ) k= ; keyexchange=keyexchange=ikev2 ; ikev1_policy=ikev1-policy=drop   ;;

	    ike ) k= ;;
	    esp ) p2=esp ; p2a= ; phase2=phase2=esp ;;
	    ah )  p2=ah  ; p2a= ; phase2=phase2=ah  ;;

	    ipv4 ) inner=ipv4 ; outer=ipv4 ;;
	    ipv6 ) inner=ipv6 ; outer=ipv6 ;;

	    4in4 ) inner=ipv4 ; outer=ipv4 ;;
	    4in6 ) inner=ipv4 ; outer=ipv6 ;;
	    6in4 ) inner=ipv6 ; outer=ipv4 ;;
	    6in6 ) inner=ipv6 ; outer=ipv6 ;;

	    * )
		# need to strip leading -
		if test -n "${p2}" ; then
		    p2a=${p2a}-${h}
		    phase2alg=${p2}=$(expr ${p2a} : '-\(.*\)')
		else
		    k=${k}-${h}
		    ike=ike=$(expr ${k} : '-\(.*\)')
		fi
		;;

	esac
    done

    if test -n "${w}" ; then
	west=${w}w
    else
	west=west
    fi

    if test -n "${e}" ; then
	east=${e}e
    else
	east=east
    fi

    left='#left='
    right='#right='
    case ${outer} in
	ipv6 )   left=left=2001:db8:1:2::45 ; right=right=2001:db8:1:2::23 ;;
	ipv4|* ) left=left=192.1.2.45       ; right=right=192.1.2.23       ;;
    esac

    leftsubnet='#leftsubnet='
    rightsubnet='#rightsubnet='
    case ${inner} in
	ipv4|* ) leftsubnet=leftsubnet=192.0.1.0/24      ; rightsubnet=rightsubnet=192.0.2.0/24      ;;
	ipv6 )   leftsubnet=leftsubnet=2001:db8:0:1::/64 ; rightsubnet=rightsubnet=2001:db8:0:2::/64 ;;
    esac

    swan_prep="swan-prep"
    case ${inner}-in-${outer} in
	ipv4-in-ipv4 ) swan_prep="swan-prep -4" ;;
	ipv6-in-ipv6 ) swan_prep="swan-prep -6" ;;
	ipv4-in-ipv6 ) swan_prep="swan-prep -46" ;;
	ipv6-in-ipv4 ) swan_prep="swan-prep -46" ;;
    esac

    emit <<EOF ipsec.conf
config setup
	# put the logs in /tmp for the UMLs, so that we can operate
	# without syslogd, which seems to break on UMLs
	logfile=/tmp/pluto.log
	logtime=no
	logappend=no
	dumpdir=/tmp
	plutodebug=all
	${ikev1_policy}
conn interop
	# IKE
	${keyexchange}
	${ike}
	${left}
	${right}
	authby=secret
	leftid=@west
	rightid=@east
	# CHILD
	${leftsubnet}
	${rightsubnet}
	${phase2}
	${phase2alg}
	${type}
	${compress}
EOF

    emit <<EOF ipsec.secrets
@east @west : PSK "this is a really really big secret"
EOF

    for init in init-${east}.sh init-${west}.sh ; do
	case ${init} in
	    *bsd*)
		script <<EOF ${init}
../../guestbin/netbsd-prep.sh
EOF
		;;
	    *)
		script <<EOF ${init}
../../guestbin/${swan_prep}
EOF
		;;
	esac
    done

    for start in start-${east}.sh start-${west}.sh ; do
	script <<EOF ${start}
ipsec start
../../guestbin/wait-until-pluto-started
ipsec add interop
EOF
    done

    script <<EOF initiate-${west}.sh
ipsec up interop
../../guestbin/ipsec-kernel-state.sh
../../guestbin/ipsec-kernel-policy.sh
EOF

    # IKEv1 needs this
    script <<EOF established-${east}
../../guestbin/wait-for.sh --match interop -- ipsec trafficstatus
EOF

    script <<EOF ping-${west}.sh
../../guestbin/ping-once.sh --up -I 192.0.1.254 192.0.2.254
EOF

    for traffic in traffic-${east}.sh traffic-${west}.sh ; do
	script <<EOF ${traffic}
ipsec trafficstatus
EOF
    done

    touch $p/description.txt
    touch $p/${west}.console.txt
    touch $p/${east}.console.txt

done