Add simulator enhancements.
[sim/o1-interface.git] / ntsimulator / deploy / tls / enable_tls.sh
1 #! /bin/bash
2 ################################################################################
3 #
4 # Copyright 2020 highstreet technologies GmbH and others
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9
10 #     http://www.apache.org/licenses/LICENSE-2.0
11
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17
18 ################################################################################
19
20 sleep 10
21
22 openssl genrsa -out melacon.server.key 2048
23
24 openssl req -new -sha256 -key melacon.server.key -subj "/C=US/ST=CA/O=MeLaCon, Inc./CN=melacon.com" -out melacon.server.csr
25 openssl x509 -req -in melacon.server.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out melacon.server.crt -days 500 -sha256
26 rm melacon.server.csr
27
28 MELACON_SERVER_KEY="$(sed '1d;$d' melacon.server.key)"
29
30 echo '<action xmlns="urn:ietf:params:xml:ns:yang:1"><keystore xmlns="urn:ietf:params:xml:ns:yang:ietf-keystore"><private-keys><load-private-key><name>melacon_server_key</name>' >> load_private_key.xml
31 echo '<private-key>'"$MELACON_SERVER_KEY"'</private-key></load-private-key></private-keys></keystore></action>' >> load_private_key.xml
32
33 netopeer2-cli <<END
34 auth pref publickey 1000
35 auth keys add /home/netconf/.ssh/id_dsa.pub /home/netconf/.ssh/id_dsa
36 connect --host 127.0.0.1 --login netconf
37 user-rpc --content=load_private_key.xml
38 disconnect
39 END
40
41 rm load_private_key.xml
42
43 MELACON_CERT="$(sed '1d;$d' melacon.server.crt)"
44 CA_CERT="$(sed '1d;$d' ca.pem)"
45
46 echo '<keystore xmlns="urn:ietf:params:xml:ns:yang:ietf-keystore"><private-keys><private-key><name>melacon_server_key</name><certificate-chains><certificate-chain><name>melacon_server_cert</name>' >> load_server_certs.xml
47 echo '<certificate>'"$MELACON_CERT"'</certificate></certificate-chain></certificate-chains></private-key></private-keys><trusted-certificates><name>trusted_ca_list</name><trusted-certificate><name>ca</name>' >> load_server_certs.xml
48 echo '<certificate>'"$CA_CERT"'</certificate></trusted-certificate></trusted-certificates></keystore>' >> load_server_certs.xml
49
50 sysrepocfg --merge=load_server_certs.xml --format=xml ietf-keystore
51 rm load_server_certs.xml
52
53 # enable the SSH and TLS connections, according to the configuration file
54 ./enable_connections.sh
55
56 echo 'Done'
57 exit 0