blob: 0dc654d3aad70f096c0ff63ce0e33383ca972468 [file] [log] [blame]
Zhiyi Zhang915aa452020-10-17 17:20:58 -07001#!/usr/bin/env bash
2
tylerliub7083bd2020-10-17 20:42:14 -07003function generate_client_config() {
4echo
5echo "What is the parent CA's prefix?"
6read -r parent_ca_prefix
7echo "what is the parent certificate?"
8root_cert=$(cat | tr -d '\n')
9
10cat > ndncert-site-client.conf << ~EOF
11{
12 "ca-list":
13 [
14 {
15 "ca-prefix": "$parent_ca_prefix",
16 "ca-info": "NDN Testbed Root Trust Anchor",
17 "max-validity-period": "1296000",
18 "max-suffix-length": "3",
19 "probe-parameters":
20 [
21 {"probe-parameter-key": "pin"}
22 ],
23 "certificate": "$root_cert"
24 }
25 ]
26}
27~EOF
28echo "config file generated at ndncert-site-client.conf"
29echo
30}
31
32function generate_ca_config() {
33echo "Load the new configuration file for the CA"
34echo "Would you like to allow email challenge for this CA? [Y/N]"
35read -r allow_email_challenge
36# prepare CA configuration file
37cat > /usr/local/etc/ndncert/ca.conf << ~EOF
38{
39 "ca-prefix": "$1",
40 "ca-info": "NDN Trust Anchor: $1",
41 "max-validity-period": "1296000",
42 "max-suffix-length": "2",
43 "probe-parameters":
44 [
45 {"probe-parameter-key": "email"}
46 ],
47 "supported-challenges":
48 [
49~EOF
50if [ "$allow_email_challenge" = 'y' ]; then
51 echo '{ "challenge": "email" },' >> /usr/local/etc/ndncert/ca.conf
52elif [ "$allow_email_challenge" = 'Y' ]; then
53 echo '{ "challenge": "email" },' >> /usr/local/etc/ndncert/ca.conf
54fi
55cat >> /usr/local/etc/ndncert/ca.conf << ~EOF
56 { "challenge": "pin" }
57 ],
58 "name-assignment":
59 {
60 "param": "/email"
61 }
62}
63~EOF
Zhiyi Zhang915aa452020-10-17 17:20:58 -070064echo ""
tylerliub7083bd2020-10-17 20:42:14 -070065}
Zhiyi Zhang915aa452020-10-17 17:20:58 -070066
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -070067echo "Do you want to (re) compile and build NDNCERT? [Y/N]"
tylerliub7083bd2020-10-17 20:42:14 -070068read -r NDNCERT_COMPILE
Zhiyi Zhang915aa452020-10-17 17:20:58 -070069echo ""
70
71case $NDNCERT_COMPILE in
72 N|n)
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -070073 echo "Okay, we'll skip compilation and build."
Zhiyi Zhang915aa452020-10-17 17:20:58 -070074 ;;
75 Y|y)
76 cd ../ && CXXFLAGS="-O2" ./waf configure
77 ./waf
Zhiyi Zhang915aa452020-10-17 17:20:58 -070078 ;;
79 *)
80 echo "Unknown option, build and install is cancelled"
81 exit
82 ;;
83esac
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -070084echo "Need sudo to install NDNCERT CLI tools"
85sudo ./waf install
86echo ""
Zhiyi Zhang915aa452020-10-17 17:20:58 -070087
88echo "==================================================================="
89echo "=="
90echo "== Deploying NDNCERT"
91echo "=="
92echo "==================================================================="
93echo ""
94echo "Are you sure [Y/n] ?"
tylerliub7083bd2020-10-17 20:42:14 -070095read -r DEPLOY
Zhiyi Zhang915aa452020-10-17 17:20:58 -070096
97case $DEPLOY in
98 N|n)
99 echo "Deployment cancelled"
100 exit
101 ;;
102 Y|y)
103 ;;
104 *)
105 echo "Unknown option, deployment cancelled"
106 exit
107 ;;
108esac
109
110echo ""
111echo "==================================================================="
112echo "=="
113echo "== Deployment started"
114echo "=="
115echo "==================================================================="
116
tylerliub7083bd2020-10-17 20:42:14 -0700117echo "What is the CA Prefix (eg. /example) you want to deploy?"
118read -r CA_PREFIX
119echo ""
120
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700121echo "Do you want to install ndncert CA for systemd on this machine? [Y/N]"
tylerliub7083bd2020-10-17 20:42:14 -0700122read -r SYSTEMD_INSTALL
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700123echo ""
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700124
125case $SYSTEMD_INSTALL in
126 N|n)
127 echo "We will not install systemd CA on this machine"
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700128 echo "Successfully finish the deployment of NDNCERT. To run NDNCERT, please use CLI ndncert-ca-server"
129 exit
130 ;;
131 Y|y)
132 echo "Copying NDNCERT-CA systemd service on this machine"
tylerliub7083bd2020-10-17 20:42:14 -0700133 sudo cp "$(pwd)/../build/systemd/ndncert-ca.service" /etc/systemd/system
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700134 sudo chmod 644 /etc/systemd/system/ndncert-ca.service
135 ;;
136 *)
137 echo "Unknown option, deployment cancelled"
138 exit
139 ;;
140esac
141
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700142echo ""
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700143echo "ndncert-ca service requires user ndn. Will check it now :D"
144if id ndn &>/dev/null; then
145 echo 'ndn user account found, GOOD!'
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700146else
147 echo 'ndn user not found; adding ndn user as root'
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700148 sudo useradd ndn
149fi
150
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700151echo ""
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700152echo "ndncert-ca service requires /var/lib/ndncert-ca. Will check or create the keychain in /var/lib/ndncert-ca"
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700153sudo mkdir -p /var/lib/ndncert-ca
154sudo chown ndn /var/lib/ndncert-ca
155echo '/var/lib/ndncert-ca is ready, GOOD!'
156
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700157echo ""
tylerliub7083bd2020-10-17 20:42:14 -0700158echo "Do you want to import an exisitng safebag for $CA_PREFIX ? [Y/N]"
159read -r USE_SAFE_BAG
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700160
161case $USE_SAFE_BAG in
162 N|n)
tylerliub7083bd2020-10-17 20:42:14 -0700163 echo "Generating new NDN identity for $CA_PREFIX"
164 sudo HOME=/var/lib/ndncert-ca -u ndn ndnsec-keygen "$CA_PREFIX"
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700165 ;;
166 Y|y)
167 echo "Reading the safebag."
168 echo "What is the safebag file name?"
tylerliub7083bd2020-10-17 20:42:14 -0700169 read -r SAFE_BAG_PATH
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700170 echo ""
171
172 echo "What is the password of the safebag?"
tylerliub7083bd2020-10-17 20:42:14 -0700173 read -r SAFE_BAG_PWD
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700174 echo ""
175
tylerliub7083bd2020-10-17 20:42:14 -0700176 sudo HOME=/var/lib/ndncert-ca -u ndn ndnsec-import -i "$SAFE_BAG_PATH" -P "$SAFE_BAG_PWD"
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700177 ;;
178 *)
179 echo "Unknown option, deployment cancelled"
180 exit
181 ;;
182esac
183
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700184echo ""
tylerliub7083bd2020-10-17 20:42:14 -0700185echo "Do you want to request a certificate from a parent CA? [Y/N]"
186read -r RUN_CLIENT
187case $RUN_CLIENT in
188 Y|y)
189 echo "Running ndncert client"
190 generate_client_config
191 ndncert-client -c ndncert-site-client.conf
192 rm ndncert-site-client.conf
193
194 echo "What is the new certificate name?"
195 read -r new_cert_name
196 ndnsec set-default -c "$new_cert_name"
197 ;;
198 *)
199 echo "Will not request a certificate. "
200 ;;
201esac
202
203generate_ca_config "$CA_PREFIX"
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700204
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700205echo "Do you want to start the service now? [Y/N]"
tylerliub7083bd2020-10-17 20:42:14 -0700206read -r START_NOW
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700207case $START_NOW in
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700208 N|n)
209 echo "Successfully finish the deployment of NDNCERT. You can run sudo systemctl start ndncert-ca when you want to start the service"
210 exit
211 ;;
212 Y|y)
213 echo "Starting the service ndncert-ca"
214 sudo systemctl start ndncert-ca
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700215 sleep 2
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700216 echo "Reading the status of service ndncert-ca"
217 sudo systemctl status ndncert-ca
218 echo "Successfully finish the deployment of NDNCERT. You can run sudo systemctl status ndncert-ca when you want to check the status of the service"
219 exit
220 ;;
221 *)
222 echo "Unknown option, deployment cancelled"
223 exit
224 ;;
225esac