ff51e2771079acf39df3297e1841bfbe77ef9ef6
[sim/o1-interface.git] / ntsimulator / deploy / tls / enable_connections.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 int_re='^[0-9]+$'
21
22 ssh_conn=`jq '.["ssh-connections"]' /opt/dev/scripts/configuration.json`
23 tls_conn=`jq '.["tls-connections"]' /opt/dev/scripts/configuration.json`
24
25 echo "Enabling $ssh_conn SSH connections and $tls_conn TLS connections in device..."
26
27 # if [ "$#" -ne 2 ]; then
28 #   echo "Usage: $0 NUM_SSH_CONNECTIONS NUM_TLS_CONNECTIONS" >&2
29 #   exit 1
30 # fi
31
32 if ! [[ $ssh_conn =~ $int_re ]] ; then
33    echo "error: Argument '$ssh_conn' is not a number" >&2
34    exit 1
35 fi
36
37 if ! [[ $tls_conn =~ $int_re ]] ; then
38    echo "error: Argument '$tls_conn' is not a number" >&2
39    exit 1
40 fi
41
42 netconf_port=830
43
44 echo '<netconf-server xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-server"><listen>' > connections.xml
45
46 for (( ssh_counter=0; ssh_counter<$ssh_conn; ssh_counter++ ))
47 do
48   echo "<endpoint><name>MNG$ssh_counter</name><ssh><address>::</address><port>$netconf_port</port><host-keys><host-key><name>imported SSH key</name><public-key>ssh_host_rsa_key</public-key></host-key></host-keys></ssh></endpoint>" >> connections.xml
49   ((netconf_port++))
50 done
51
52 for (( tls_counter=0; tls_counter<$tls_conn; tls_counter++ ))
53 do
54   echo "<endpoint><name>MNGTLS$tls_counter</name><tls><address>::</address><port>$netconf_port</port><certificates><certificate><name>melacon_server_cert</name></certificate></certificates><client-auth><trusted-ca-certs>trusted_ca_list</trusted-ca-certs><cert-maps><cert-to-name><id>1</id><fingerprint>02:E9:38:1F:F6:8B:62:DE:0A:0B:C5:03:81:A8:03:49:A0:00:7F:8B:F3</fingerprint><map-type xmlns:x509c2n=\"urn:ietf:params:xml:ns:yang:ietf-x509-cert-to-name\">x509c2n:specified</map-type><name>netconf</name></cert-to-name></cert-maps></client-auth></tls></endpoint>" >> connections.xml
55   ((netconf_port++))
56 done
57
58 echo '</listen></netconf-server>' >> connections.xml
59
60 sysrepocfg --import=connections.xml --format=xml ietf-netconf-server
61 rm connections.xml
62
63 echo 'Done'
64 exit 0