blob: dce98e7ff4e8c0a300f1103f5aad6f21bb616f83 [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
tylerliu9f19df52020-10-17 21:11:57 -070067DEPLOYMENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
tylerliue4bd6972020-10-17 21:17:12 -070068NDNCERT_DIR="$(dirname "$DEPLOYMENT_DIR")"
tylerliuca486302020-10-17 21:23:07 -070069CURRENT_PATH="$(pwd)"
70cd "$NDNCERT_DIR"
tylerliu9f19df52020-10-17 21:11:57 -070071
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -070072echo "Do you want to (re) compile and build NDNCERT? [Y/N]"
tylerliub7083bd2020-10-17 20:42:14 -070073read -r NDNCERT_COMPILE
Zhiyi Zhang915aa452020-10-17 17:20:58 -070074echo ""
75
76case $NDNCERT_COMPILE in
77 N|n)
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -070078 echo "Okay, we'll skip compilation and build."
Zhiyi Zhang915aa452020-10-17 17:20:58 -070079 ;;
80 Y|y)
tylerliuca486302020-10-17 21:23:07 -070081 CXXFLAGS="-O2" "./waf" configure
82 "./waf"
Zhiyi Zhang915aa452020-10-17 17:20:58 -070083 ;;
84 *)
85 echo "Unknown option, build and install is cancelled"
tylerliuca486302020-10-17 21:23:07 -070086 cd "$CURRENT_PATH"
Zhiyi Zhang915aa452020-10-17 17:20:58 -070087 exit
88 ;;
89esac
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -070090echo "Need sudo to install NDNCERT CLI tools"
tylerliuca486302020-10-17 21:23:07 -070091sudo "./waf" install
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -070092echo ""
Zhiyi Zhang915aa452020-10-17 17:20:58 -070093
94echo "==================================================================="
95echo "=="
96echo "== Deploying NDNCERT"
97echo "=="
98echo "==================================================================="
99echo ""
100echo "Are you sure [Y/n] ?"
tylerliub7083bd2020-10-17 20:42:14 -0700101read -r DEPLOY
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700102
103case $DEPLOY in
104 N|n)
105 echo "Deployment cancelled"
tylerliuca486302020-10-17 21:23:07 -0700106 cd "$CURRENT_PATH"
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700107 exit
108 ;;
109 Y|y)
110 ;;
111 *)
112 echo "Unknown option, deployment cancelled"
tylerliuca486302020-10-17 21:23:07 -0700113 cd "$CURRENT_PATH"
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700114 exit
115 ;;
116esac
117
118echo ""
119echo "==================================================================="
120echo "=="
121echo "== Deployment started"
122echo "=="
123echo "==================================================================="
124
tylerliub7083bd2020-10-17 20:42:14 -0700125echo "What is the CA Prefix (eg. /example) you want to deploy?"
126read -r CA_PREFIX
127echo ""
128
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700129echo "Do you want to install ndncert CA for systemd on this machine? [Y/N]"
tylerliub7083bd2020-10-17 20:42:14 -0700130read -r SYSTEMD_INSTALL
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700131echo ""
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700132
133case $SYSTEMD_INSTALL in
134 N|n)
135 echo "We will not install systemd CA on this machine"
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700136 echo "Successfully finish the deployment of NDNCERT. To run NDNCERT, please use CLI ndncert-ca-server"
tylerliuca486302020-10-17 21:23:07 -0700137 cd "$CURRENT_PATH"
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700138 exit
139 ;;
140 Y|y)
141 echo "Copying NDNCERT-CA systemd service on this machine"
tylerliu9f19df52020-10-17 21:11:57 -0700142 sudo cp "$NDNCERT_DIR/build/systemd/ndncert-ca.service" /etc/systemd/system
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700143 sudo chmod 644 /etc/systemd/system/ndncert-ca.service
144 ;;
145 *)
146 echo "Unknown option, deployment cancelled"
tylerliuca486302020-10-17 21:23:07 -0700147 cd "$CURRENT_PATH"
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700148 exit
149 ;;
150esac
151
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700152echo ""
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700153echo "ndncert-ca service requires user ndn. Will check it now :D"
154if id ndn &>/dev/null; then
155 echo 'ndn user account found, GOOD!'
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700156else
157 echo 'ndn user not found; adding ndn user as root'
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700158 sudo useradd ndn
159fi
160
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700161echo ""
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700162echo "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 -0700163sudo mkdir -p /var/lib/ndncert-ca
164sudo chown ndn /var/lib/ndncert-ca
165echo '/var/lib/ndncert-ca is ready, GOOD!'
166
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700167echo ""
tylerliub7083bd2020-10-17 20:42:14 -0700168echo "Do you want to import an exisitng safebag for $CA_PREFIX ? [Y/N]"
169read -r USE_SAFE_BAG
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700170
171case $USE_SAFE_BAG in
172 N|n)
tylerliub7083bd2020-10-17 20:42:14 -0700173 echo "Generating new NDN identity for $CA_PREFIX"
174 sudo HOME=/var/lib/ndncert-ca -u ndn ndnsec-keygen "$CA_PREFIX"
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700175 ;;
176 Y|y)
177 echo "Reading the safebag."
178 echo "What is the safebag file name?"
tylerliub7083bd2020-10-17 20:42:14 -0700179 read -r SAFE_BAG_PATH
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700180 echo ""
181
182 echo "What is the password of the safebag?"
tylerliub7083bd2020-10-17 20:42:14 -0700183 read -r SAFE_BAG_PWD
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700184 echo ""
185
tylerliub7083bd2020-10-17 20:42:14 -0700186 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 -0700187 ;;
188 *)
189 echo "Unknown option, deployment cancelled"
tylerliuca486302020-10-17 21:23:07 -0700190 cd "$CURRENT_PATH"
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700191 exit
192 ;;
193esac
194
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700195echo ""
tylerliub7083bd2020-10-17 20:42:14 -0700196echo "Do you want to request a certificate from a parent CA? [Y/N]"
197read -r RUN_CLIENT
198case $RUN_CLIENT in
199 Y|y)
200 echo "Running ndncert client"
201 generate_client_config
202 ndncert-client -c ndncert-site-client.conf
203 rm ndncert-site-client.conf
204
205 echo "What is the new certificate name?"
206 read -r new_cert_name
207 ndnsec set-default -c "$new_cert_name"
208 ;;
209 *)
210 echo "Will not request a certificate. "
211 ;;
212esac
213
214generate_ca_config "$CA_PREFIX"
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700215
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700216echo "Do you want to start the service now? [Y/N]"
tylerliub7083bd2020-10-17 20:42:14 -0700217read -r START_NOW
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700218case $START_NOW in
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700219 N|n)
220 echo "Successfully finish the deployment of NDNCERT. You can run sudo systemctl start ndncert-ca when you want to start the service"
tylerliuca486302020-10-17 21:23:07 -0700221 cd "$CURRENT_PATH"
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700222 exit
223 ;;
224 Y|y)
225 echo "Starting the service ndncert-ca"
226 sudo systemctl start ndncert-ca
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700227 sleep 2
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700228 echo "Reading the status of service ndncert-ca"
229 sudo systemctl status ndncert-ca
230 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"
tylerliuca486302020-10-17 21:23:07 -0700231 cd "$CURRENT_PATH"
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700232 exit
233 ;;
234 *)
235 echo "Unknown option, deployment cancelled"
tylerliuca486302020-10-17 21:23:07 -0700236 cd "$CURRENT_PATH"
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700237 exit
238 ;;
239esac
tylerliuca486302020-10-17 21:23:07 -0700240
241cd "$CURRENT_PATH"