blob: 8a3bacd75d69d130d4914c53c8ace44bfcc6c4fe [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")"
tylerliu9f19df52020-10-17 21:11:57 -070069
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -070070echo "Do you want to (re) compile and build NDNCERT? [Y/N]"
tylerliub7083bd2020-10-17 20:42:14 -070071read -r NDNCERT_COMPILE
Zhiyi Zhang915aa452020-10-17 17:20:58 -070072echo ""
73
74case $NDNCERT_COMPILE in
75 N|n)
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -070076 echo "Okay, we'll skip compilation and build."
Zhiyi Zhang915aa452020-10-17 17:20:58 -070077 ;;
78 Y|y)
tylerliu9f19df52020-10-17 21:11:57 -070079 CXXFLAGS="-O2" "$NDNCERT_DIR/waf" configure
80 "$NDNCERT_DIR/waf"
Zhiyi Zhang915aa452020-10-17 17:20:58 -070081 ;;
82 *)
83 echo "Unknown option, build and install is cancelled"
84 exit
85 ;;
86esac
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -070087echo "Need sudo to install NDNCERT CLI tools"
tylerliu9f19df52020-10-17 21:11:57 -070088sudo "$NDNCERT_DIR/waf" install
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -070089echo ""
Zhiyi Zhang915aa452020-10-17 17:20:58 -070090
91echo "==================================================================="
92echo "=="
93echo "== Deploying NDNCERT"
94echo "=="
95echo "==================================================================="
96echo ""
97echo "Are you sure [Y/n] ?"
tylerliub7083bd2020-10-17 20:42:14 -070098read -r DEPLOY
Zhiyi Zhang915aa452020-10-17 17:20:58 -070099
100case $DEPLOY in
101 N|n)
102 echo "Deployment cancelled"
103 exit
104 ;;
105 Y|y)
106 ;;
107 *)
108 echo "Unknown option, deployment cancelled"
109 exit
110 ;;
111esac
112
113echo ""
114echo "==================================================================="
115echo "=="
116echo "== Deployment started"
117echo "=="
118echo "==================================================================="
119
tylerliub7083bd2020-10-17 20:42:14 -0700120echo "What is the CA Prefix (eg. /example) you want to deploy?"
121read -r CA_PREFIX
122echo ""
123
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700124echo "Do you want to install ndncert CA for systemd on this machine? [Y/N]"
tylerliub7083bd2020-10-17 20:42:14 -0700125read -r SYSTEMD_INSTALL
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700126echo ""
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700127
128case $SYSTEMD_INSTALL in
129 N|n)
130 echo "We will not install systemd CA on this machine"
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700131 echo "Successfully finish the deployment of NDNCERT. To run NDNCERT, please use CLI ndncert-ca-server"
132 exit
133 ;;
134 Y|y)
135 echo "Copying NDNCERT-CA systemd service on this machine"
tylerliu9f19df52020-10-17 21:11:57 -0700136 sudo cp "$NDNCERT_DIR/build/systemd/ndncert-ca.service" /etc/systemd/system
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700137 sudo chmod 644 /etc/systemd/system/ndncert-ca.service
138 ;;
139 *)
140 echo "Unknown option, deployment cancelled"
141 exit
142 ;;
143esac
144
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700145echo ""
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700146echo "ndncert-ca service requires user ndn. Will check it now :D"
147if id ndn &>/dev/null; then
148 echo 'ndn user account found, GOOD!'
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700149else
150 echo 'ndn user not found; adding ndn user as root'
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700151 sudo useradd ndn
152fi
153
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700154echo ""
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700155echo "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 -0700156sudo mkdir -p /var/lib/ndncert-ca
157sudo chown ndn /var/lib/ndncert-ca
158echo '/var/lib/ndncert-ca is ready, GOOD!'
159
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700160echo ""
tylerliub7083bd2020-10-17 20:42:14 -0700161echo "Do you want to import an exisitng safebag for $CA_PREFIX ? [Y/N]"
162read -r USE_SAFE_BAG
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700163
164case $USE_SAFE_BAG in
165 N|n)
tylerliub7083bd2020-10-17 20:42:14 -0700166 echo "Generating new NDN identity for $CA_PREFIX"
167 sudo HOME=/var/lib/ndncert-ca -u ndn ndnsec-keygen "$CA_PREFIX"
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700168 ;;
169 Y|y)
170 echo "Reading the safebag."
171 echo "What is the safebag file name?"
tylerliub7083bd2020-10-17 20:42:14 -0700172 read -r SAFE_BAG_PATH
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700173 echo ""
174
175 echo "What is the password of the safebag?"
tylerliub7083bd2020-10-17 20:42:14 -0700176 read -r SAFE_BAG_PWD
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700177 echo ""
178
tylerliub7083bd2020-10-17 20:42:14 -0700179 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 -0700180 ;;
181 *)
182 echo "Unknown option, deployment cancelled"
183 exit
184 ;;
185esac
186
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700187echo ""
tylerliub7083bd2020-10-17 20:42:14 -0700188echo "Do you want to request a certificate from a parent CA? [Y/N]"
189read -r RUN_CLIENT
190case $RUN_CLIENT in
191 Y|y)
192 echo "Running ndncert client"
193 generate_client_config
194 ndncert-client -c ndncert-site-client.conf
195 rm ndncert-site-client.conf
196
197 echo "What is the new certificate name?"
198 read -r new_cert_name
199 ndnsec set-default -c "$new_cert_name"
200 ;;
201 *)
202 echo "Will not request a certificate. "
203 ;;
204esac
205
206generate_ca_config "$CA_PREFIX"
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700207
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700208echo "Do you want to start the service now? [Y/N]"
tylerliub7083bd2020-10-17 20:42:14 -0700209read -r START_NOW
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700210case $START_NOW in
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700211 N|n)
212 echo "Successfully finish the deployment of NDNCERT. You can run sudo systemctl start ndncert-ca when you want to start the service"
213 exit
214 ;;
215 Y|y)
216 echo "Starting the service ndncert-ca"
217 sudo systemctl start ndncert-ca
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700218 sleep 2
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700219 echo "Reading the status of service ndncert-ca"
220 sudo systemctl status ndncert-ca
221 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"
222 exit
223 ;;
224 *)
225 echo "Unknown option, deployment cancelled"
226 exit
227 ;;
228esac