-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-for-docker.sh
executable file
·387 lines (317 loc) · 15.9 KB
/
build-for-docker.sh
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
#/bin/bash
# This script prepares Docker Dockerfiles and Contexts for the Group & EDHOC Applications
# If the flag --build-images is specified, it also builds the Docker images
# Fail script with error if any command fails
set -e
## Build the Jar files for the Group & EDHOC Applications if needed
# Group Applications
FILE=group-applications/OscoreAsServer.jar
if [ -f "$FILE" ]; then
echo "$FILE exists."
else
echo "$FILE does not exist."
./build-group-apps.sh
fi
# EDHOC Applications
FILE=edhoc-applications/Phase4Server.jar
if [ -f "$FILE" ]; then
echo "$FILE exists."
else
echo "$FILE does not exist."
./build-edhoc-apps.sh
fi
## Create working directory for image building
mkdir -p docker-build
cd docker-build
# Create directories for Group Applications and EDHOC Applications
mkdir -p group
mkdir -p edhoc
# Copy needed files (jar files and library files)
cp ../group-applications/*.jar group/
cp ../group-applications/*.py group/
cp -r ../group-applications/lib group/lib
cp ../edhoc-applications/*.jar edhoc/
cp ../edhoc-applications/*.py edhoc/
cp -r ../edhoc-applications/lib edhoc/lib
## Create base Dockerfile. Initial part is same for all images.
# Uses Ubuntu 20.04 as base. Then sets the timezone, and installs OpenJDK.
# Setting the timezone is needed as the OpenJDK install otherwise interactively interrupts.
# Also installs Python and pip3 for the toggling Python scripts.
echo 'FROM ubuntu:20.04' > Dockerfile.base
echo 'ENV DEBIAN_FRONTEND noninteractive' >> Dockerfile.base
echo 'ENV TZ="Europe/Stockholm"' >> Dockerfile.base
echo 'WORKDIR /apps' >> Dockerfile.base
echo 'RUN apt-get -y update && \' >> Dockerfile.base
echo ' apt-get install -yq tzdata && \' >> Dockerfile.base
echo ' ln -fs /usr/share/zoneinfo/Europe/Stockholm /etc/localtime && \' >> Dockerfile.base
echo ' dpkg-reconfigure -f noninteractive tzdata && \' >> Dockerfile.base
echo ' apt-get -y install default-jre-headless && \' >> Dockerfile.base
echo ' apt-get -y install python3 && \' >> Dockerfile.base
echo ' apt-get -y install python3-pip && \' >> Dockerfile.base
echo ' pip3 install RPi.GPIO && \' >> Dockerfile.base
echo ' ln -s $(which python3) /usr/bin/python && \' >> Dockerfile.base
echo ' mkdir -p apps/lib' >> Dockerfile.base
echo '' >> Dockerfile.base
## Prepare to build images for Group Applications
cd group
# Note that entrypoints must be adapted according to the location of entities, including the Servers, SQL database and DHT.
# See the docker-compose.yml for a prepared setup.
# OscoreAsServer: ACE Authorization Server
# Assumes container name mysql for MySQL server
# Assumes root password xxxxxx for MySQL server
echo "root" > db.pwd
echo "xxxxxx mysql" >> db.pwd
dockerfile=Dockerfile-OscoreAsServer
cp ../Dockerfile.base $dockerfile
echo 'EXPOSE 5583/udp' >> $dockerfile
echo 'COPY db.pwd /apps' >> $dockerfile
echo 'COPY OscoreAsServer.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "OscoreAsServer.jar", "-dht"]' >> $dockerfile
# docker build -f $dockerfile -t oscoreasserver .
# OscoreRsServer: Group Manager (ACE Resource Server)
dockerfile=Dockerfile-OscoreRsServer
cp ../Dockerfile.base $dockerfile
echo 'EXPOSE 5783/udp' >> $dockerfile
echo 'COPY OscoreRsServer.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "OscoreRsServer.jar", "-dht"]' >> $dockerfile
# docker build -f $dockerfile -t oscorersserver .
# OscoreAsRsClient: Group OSCORE Server/Client which will join the group(s)
# Client 1 (for Group A)
# Assumes container name "authorization-server" for ACE Authorization Server
# Assumes container name "group-manager" for ACE Resource Server
dockerfile=Dockerfile-OscoreAsRsClient-Client1
cp ../Dockerfile.base $dockerfile
echo 'COPY OscoreAsRsClient.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "OscoreAsRsClient.jar", "-name", "Client1", "-delay", "95", "-as", "coap://authorization-server:5583", "-gm", "coap://group-manager:5783", "-dht"]' >> $dockerfile
# docker build -f $dockerfile -t oscoreasrsclient-client1 .
# OscoreAsRsClient: Group OSCORE Server/Client which will join the group(s)
# Client 2 (for Group B)
# Assumes container name "authorization-server" for ACE Authorization Server
# Assumes container name "group-manager" for ACE Resource Server
dockerfile=Dockerfile-OscoreAsRsClient-Client2
cp ../Dockerfile.base $dockerfile
echo 'COPY OscoreAsRsClient.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "OscoreAsRsClient.jar", "-name", "Client2", "-delay", "80", "-as", "coap://authorization-server:5583", "-gm", "coap://group-manager:5783", "-dht"]' >> $dockerfile
# docker build -f $dockerfile -t oscoreasrsclient-client2 .
# OscoreAsRsClient: Group OSCORE Server/Client which will join the group(s)
# Server 1 (for Group A)
# Assumes container name "authorization-server" for ACE Authorization Server
# Assumes container name "group-manager" for ACE Resource Server
dockerfile=Dockerfile-OscoreAsRsClient-Server1
cp ../Dockerfile.base $dockerfile
echo 'EXPOSE 4683/udp' >> $dockerfile
echo 'COPY LED-on.py /apps' >> $dockerfile
echo 'COPY LED-off.py /apps' >> $dockerfile
echo 'COPY OscoreAsRsClient.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "OscoreAsRsClient.jar", "-name", "Server1", "-delay", "65", "-as", "coap://authorization-server:5583", "-gm", "coap://group-manager:5783"]' >> $dockerfile
# docker build -f $dockerfile -t oscoreasrsclient-server1 .
# OscoreAsRsClient: Group OSCORE Server/Client which will join the group(s)
# Server 2 (for Group A)
# Assumes container name "authorization-server" for ACE Authorization Server
# Assumes container name "group-manager" for ACE Resource Server
dockerfile=Dockerfile-OscoreAsRsClient-Server2
cp ../Dockerfile.base $dockerfile
echo 'EXPOSE 4683/udp' >> $dockerfile
echo 'COPY LED-on.py /apps' >> $dockerfile
echo 'COPY LED-off.py /apps' >> $dockerfile
echo 'COPY OscoreAsRsClient.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "OscoreAsRsClient.jar", "-name", "Server2", "-delay", "55", "-as", "coap://authorization-server:5583", "-gm", "coap://group-manager:5783"]' >> $dockerfile
# docker build -f $dockerfile -t oscoreasrsclient-server2 .
# OscoreAsRsClient: Group OSCORE Server/Client which will join the group(s)
# Server 3 (for Group A)
# Assumes container name "authorization-server" for ACE Authorization Server
# Assumes container name "group-manager" for ACE Resource Server
dockerfile=Dockerfile-OscoreAsRsClient-Server3
cp ../Dockerfile.base $dockerfile
echo 'EXPOSE 4683/udp' >> $dockerfile
echo 'COPY LED-on.py /apps' >> $dockerfile
echo 'COPY LED-off.py /apps' >> $dockerfile
echo 'COPY OscoreAsRsClient.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "OscoreAsRsClient.jar", "-name", "Server3", "-delay", "45", "-as", "coap://authorization-server:5583", "-gm", "coap://group-manager:5783"]' >> $dockerfile
# docker build -f $dockerfile -t oscoreasrsclient-server3 .
# OscoreAsRsClient: Group OSCORE Server/Client which will join the group(s)
# Server 4 (for Group B)
# Assumes container name "authorization-server" for ACE Authorization Server
# Assumes container name "group-manager" for ACE Resource Server
dockerfile=Dockerfile-OscoreAsRsClient-Server4
cp ../Dockerfile.base $dockerfile
echo 'EXPOSE 4683/udp' >> $dockerfile
echo 'COPY LED-on.py /apps' >> $dockerfile
echo 'COPY LED-off.py /apps' >> $dockerfile
echo 'COPY OscoreAsRsClient.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "OscoreAsRsClient.jar", "-name", "Server4", "-delay", "35", "-as", "coap://authorization-server:5583", "-gm", "coap://group-manager:5783"]' >> $dockerfile
# docker build -f $dockerfile -t oscoreasrsclient-server4 .
# OscoreAsRsClient: Group OSCORE Server/Client which will join the group(s)
# Server 5 (for Group B)
# Assumes container name "authorization-server" for ACE Authorization Server
# Assumes container name "group-manager" for ACE Resource Server
dockerfile=Dockerfile-OscoreAsRsClient-Server5
cp ../Dockerfile.base $dockerfile
echo 'EXPOSE 4683/udp' >> $dockerfile
echo 'COPY LED-on.py /apps' >> $dockerfile
echo 'COPY LED-off.py /apps' >> $dockerfile
echo 'COPY OscoreAsRsClient.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "OscoreAsRsClient.jar", "-name", "Server5", "-delay", "25", "-as", "coap://authorization-server:5583", "-gm", "coap://group-manager:5783"]' >> $dockerfile
# docker build -f $dockerfile -t oscoreasrsclient-server5 .
# OscoreAsRsClient: Group OSCORE Server/Client which will join the group(s)
# Server 6 (for Group B)
# Assumes container name "authorization-server" for ACE Authorization Server
# Assumes container name "group-manager" for ACE Resource Server
dockerfile=Dockerfile-OscoreAsRsClient-Server6
cp ../Dockerfile.base $dockerfile
echo 'EXPOSE 4683/udp' >> $dockerfile
echo 'COPY LED-on.py /apps' >> $dockerfile
echo 'COPY LED-off.py /apps' >> $dockerfile
echo 'COPY OscoreAsRsClient.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "OscoreAsRsClient.jar", "-name", "Server6", "-delay", "15", "-as", "coap://authorization-server:5583", "-gm", "coap://group-manager:5783"]' >> $dockerfile
# docker build -f $dockerfile -t oscoreasrsclient-server6 .
# Adversary: Adversary for testing attacks against the group(s)
dockerfile=Dockerfile-Adversary
cp ../Dockerfile.base $dockerfile
echo 'COPY Adversary.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "Adversary.jar"]' >> $dockerfile
# docker build -f $dockerfile -t adversary .
## Prepare to build images for EDHOC Applications
cd ../edhoc
# Phase0Client: CoAP-only client
# Assumes container name "phase4-server" for server-side
dockerfile=Dockerfile-Phase0Client
cp ../Dockerfile.base $dockerfile
echo 'COPY Phase0Client.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "Phase0Client.jar", "-server", "coap://phase4-server:5697", "-dht"]' >> $dockerfile
# docker build -f $dockerfile -t phase0client .
# Phase1Server: EDHOC server using method 0 and no optimized request
dockerfile=Dockerfile-Phase1Server
cp ../Dockerfile.base $dockerfile
echo 'EXPOSE 5694/udp' >> $dockerfile
echo 'COPY LED-on.py /apps' >> $dockerfile
echo 'COPY LED-off.py /apps' >> $dockerfile
echo 'COPY Phase1Server.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "Phase1Server.jar"]' >> $dockerfile
# docker build -f $dockerfile -t phase1server .
# Phase1Client: EDHOC client using method 0 and no optimized request
# Assumes container name phase1-server for server-side
dockerfile=Dockerfile-Phase1Client
cp ../Dockerfile.base $dockerfile
echo 'COPY Phase1Client.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "Phase1Client.jar", "-server", "coap://phase1-server:5694", "-dht"]' >> $dockerfile
# docker build -f $dockerfile -t phase1client .
# Phase2Server: EDHOC server using method 3 and no optimized request
dockerfile=Dockerfile-Phase2Server
cp ../Dockerfile.base $dockerfile
echo 'EXPOSE 5695/udp' >> $dockerfile
echo 'COPY LED-on.py /apps' >> $dockerfile
echo 'COPY LED-off.py /apps' >> $dockerfile
echo 'COPY Phase2Server.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "Phase2Server.jar"]' >> $dockerfile
# docker build -f $dockerfile -t phase2server .
# Phase2Client: EDHOC client using method 3 and no optimized request
# Assumes container name phase2-server for server-side
dockerfile=Dockerfile-Phase2Client
cp ../Dockerfile.base $dockerfile
echo 'COPY Phase2Client.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "Phase2Client.jar", "-server", "coap://phase2-server:5695", "-dht"]' >> $dockerfile
# docker build -f $dockerfile -t phase2client .
# Phase3Server: EDHOC server using method 0 and the optimized request
dockerfile=Dockerfile-Phase3Server
cp ../Dockerfile.base $dockerfile
echo 'EXPOSE 5696/udp' >> $dockerfile
echo 'COPY LED-on.py /apps' >> $dockerfile
echo 'COPY LED-off.py /apps' >> $dockerfile
echo 'COPY Phase3Server.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "Phase3Server.jar"]' >> $dockerfile
# docker build -f $dockerfile -t phase3server .
# Phase3Client: EDHOC client using method 0 and the optimized request
# Assumes container name phase3-server for server-side
dockerfile=Dockerfile-Phase3Client
cp ../Dockerfile.base $dockerfile
echo 'COPY Phase3Client.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "Phase3Client.jar", "-server", "coap://phase3-server:5696", "-dht"]' >> $dockerfile
# docker build -f $dockerfile -t phase3client .
# Phase4Server: EDHOC server using method 3 and the optimized request
dockerfile=Dockerfile-Phase4Server
cp ../Dockerfile.base $dockerfile
echo 'EXPOSE 5697/udp' >> $dockerfile
echo 'COPY LED-on.py /apps' >> $dockerfile
echo 'COPY LED-off.py /apps' >> $dockerfile
echo 'COPY Phase4Server.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "Phase4Server.jar"]' >> $dockerfile
# docker build -f $dockerfile -t phase4server .
# Phase4Client: EDHOC client using method 3 and the optimized request
# Assumes container name "phase4-server" for server-side
dockerfile=Dockerfile-Phase4Client
cp ../Dockerfile.base $dockerfile
echo 'COPY Phase4Client.jar /apps' >> $dockerfile
echo 'COPY lib /apps/lib/' >> $dockerfile
echo '' >> $dockerfile
echo 'ENTRYPOINT ["java", "-jar", "Phase4Client.jar", "-server", "coap://phase4-server:5697", "-dht"]' >> $dockerfile
# docker build -f $dockerfile -t phase4client .
## Actually build the images. Note that only some of the images are built.
# The below part should be done in the Github Actions to push the images to Docker Hub.
# If indicated actually build the images, otherwise exit here
if [ "$1" != "--build-images" ]
then
exit
fi
# Build images for the Group Applications
cd ../group
docker build -f Dockerfile-OscoreAsServer -t authorization-server .
docker build -f Dockerfile-OscoreRsServer -t group-manager .
docker build -f Dockerfile-OscoreAsRsClient-Client1 -t group-client1 .
docker build -f Dockerfile-OscoreAsRsClient-Client2 -t group-client2 .
docker build -f Dockerfile-OscoreAsRsClient-Server1 -t group-server1 .
docker build -f Dockerfile-OscoreAsRsClient-Server2 -t group-server2 .
docker build -f Dockerfile-OscoreAsRsClient-Server3 -t group-server3 .
docker build -f Dockerfile-OscoreAsRsClient-Server4 -t group-server4 .
docker build -f Dockerfile-OscoreAsRsClient-Server5 -t group-server5 .
docker build -f Dockerfile-OscoreAsRsClient-Server6 -t group-server6 .
docker build -f Dockerfile-Adversary -t group-adversary .
# Build images for the EDHOC Applications
cd ../edhoc
docker build -f Dockerfile-Phase0Client -t phase0-client .
docker build -f Dockerfile-Phase1Server -t phase1-server .
docker build -f Dockerfile-Phase1Client -t phase1-client .
docker build -f Dockerfile-Phase2Server -t phase2-server .
docker build -f Dockerfile-Phase2Client -t phase2-client .
docker build -f Dockerfile-Phase3Server -t phase3-server .
docker build -f Dockerfile-Phase3Client -t phase3-client .
docker build -f Dockerfile-Phase4Server -t phase4-server .
docker build -f Dockerfile-Phase4Client -t phase4-client .