fix no such file or directory error
[aaf/sshsm.git] / test / func / setup.sh
1 #!/bin/bash
2 #
3 # Copyright 2018 Intel Corporation
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17
18 # Receives two arguments 1. srk_handle 2. password
19
20 docker login -u docker -p docker nexus3.onap.org:10001
21 docker pull nexus3.onap.org:10001/onap/aaf/distcenter
22 docker pull nexus3.onap.org:10001/onap/aaf/abrmd
23 docker pull nexus3.onap.org:10001/onap/aaf/testcaservice
24 docker pull nexus3.onap.org:10001/onap/aaf/aaf_cm
25
26 ABRMD_DATA="$(pwd)/data/abrmd"
27 SEC_FOLDER="$(pwd)/data/abrmd/cred"
28
29 DISTCENTER_DATA="$(pwd)/data/distcenter"
30 DISTCENTER_SEC="$(pwd)/data/distcenter/data"
31
32 CASERVICE_DATA="$(pwd)/data/caservice"
33 WORKDIR="$(pwd)/"
34
35 mkdir -p $(pwd)/data/abrmd/cred
36 echo $1 > $ABRMD_DATA/cred/srk_handle.txt
37 echo $2 > $ABRMD_DATA/cred/opass.txt
38
39 cp $ABRMD_DATA/cred/opass.txt $CASERVICE_DATA/ipass.txt
40 base64 $ABRMD_DATA/cred/opass.txt > $ABRMD_DATA/cred/opass
41 base64 $ABRMD_DATA/cred/srk_handle.txt > $ABRMD_DATA/cred/srk_handle
42
43
44 if [ -e /dev/tpm0 ]; then
45
46     echo "found tpm device"
47     #
48     # Running the abrmd container for tpm init
49     #
50     docker run --privileged -device=/dev/tpm0 -e ABRMD_DATA=/abrmd/data \
51        -e TPM_NODE_NAME=testnode \
52        -v $SEC_FOLDER:/abrmd/cred \
53        -v $ABRMD_DATA:/abrmd/data \
54        --entrypoint /abrmd/bin/initialize_tpm.sh \
55        --name tpm-init nexus3.onap.org:10001/onap/aaf/abrmd
56
57     sleep 1m
58     mkdir -p $DISTCENTER_DATA/host_testnode
59     ls  $ABRMD_DATA/host_testnode/
60     cp  $ABRMD_DATA/host_testnode/out_parent_public \
61           $DISTCENTER_DATA/host_testnode/
62
63     docker run -d --privileged -device=/dev/tpm0 \
64             -v /tmp/run/dbus:/var/run/dbus:rw \
65        --entrypoint /abrmd/bin/run_abrmd.sh \
66        --name abrmd nexus3.onap.org:10001/onap/aaf/abrmd
67
68     sleep 1m
69 fi
70
71 #
72 # Running the distcenter container
73 #
74 docker run -v $DISTCENTER_DATA:/distcenter/data \
75   --name distcenter nexus3.onap.org:10001/onap/aaf/distcenter
76
77
78 mkdir -p $CASERVICE_DATA/host_testnode
79 if [ -f $DISTCENTER_DATA/privkey.pem.gpg ]; then
80     cp $DISTCENTER_DATA/privkey.pem.gpg $CASERVICE_DATA/host_testnode/
81     cp $DISTCENTER_DATA/ca.cert $CASERVICE_DATA/host_testnode/
82     cp $DISTCENTER_DATA/passphrase $CASERVICE_DATA/host_testnode/
83 else
84     cp  $DISTCENTER_DATA/host_testnode/* \
85           $CASERVICE_DATA/host_testnode
86     cp $SEC_FOLDER/srk_handle $CASERVICE_DATA/host_testnode/
87 fi
88
89 cp $CASERVICE_DATA/passphrase-ipass $CASERVICE_DATA/host_testnode/
90 cp $CASERVICE_DATA/passphrase-pin $CASERVICE_DATA/host_testnode/
91 cd $CASERVICE_DATA/
92 cat passphrase-ipass | gpg --symmetric -z 9 --require-secmem \
93        --cipher-algo AES256 --s2k-cipher-algo AES256 --s2k-digest-algo SHA512 \
94        --s2k-mode 3 --s2k-count 65000000 --compress-algo BZIP2 \
95         --passphrase-fd 0 ipass.txt
96 cat passphrase-pin | gpg --symmetric -z 9 --require-secmem \
97        --cipher-algo AES256 --s2k-cipher-algo AES256 --s2k-digest-algo SHA512 \
98        --s2k-mode 3 --s2k-count 65000000 --compress-algo BZIP2 \
99         --passphrase-fd 0 upin.txt
100 cat passphrase-pin | gpg --symmetric -z 9 --require-secmem \
101        --cipher-algo AES256 --s2k-cipher-algo AES256 --s2k-digest-algo SHA512 \
102        --s2k-mode 3 --s2k-count 65000000 --compress-algo BZIP2 \
103         --passphrase-fd 0 sopin.txt
104 cp $CASERVICE_DATA/*.gpg $CASERVICE_DATA/host_testnode/
105 cp $ABRMD_DATA/cred/srk_handle.txt $CASERVICE_DATA/host_testnode/tpm-handle.txt
106 cp $ABRMD_DATA/cred/opass $CASERVICE_DATA/host_testnode/prk_passwd
107 sleep 1m