Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
tylerliu | b7083bd | 2020-10-17 20:42:14 -0700 | [diff] [blame^] | 3 | function generate_client_config() { |
| 4 | echo |
| 5 | echo "What is the parent CA's prefix?" |
| 6 | read -r parent_ca_prefix |
| 7 | echo "what is the parent certificate?" |
| 8 | root_cert=$(cat | tr -d '\n') |
| 9 | |
| 10 | cat > 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 |
| 28 | echo "config file generated at ndncert-site-client.conf" |
| 29 | echo |
| 30 | } |
| 31 | |
| 32 | function generate_ca_config() { |
| 33 | echo "Load the new configuration file for the CA" |
| 34 | echo "Would you like to allow email challenge for this CA? [Y/N]" |
| 35 | read -r allow_email_challenge |
| 36 | # prepare CA configuration file |
| 37 | cat > /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 |
| 50 | if [ "$allow_email_challenge" = 'y' ]; then |
| 51 | echo '{ "challenge": "email" },' >> /usr/local/etc/ndncert/ca.conf |
| 52 | elif [ "$allow_email_challenge" = 'Y' ]; then |
| 53 | echo '{ "challenge": "email" },' >> /usr/local/etc/ndncert/ca.conf |
| 54 | fi |
| 55 | cat >> /usr/local/etc/ndncert/ca.conf << ~EOF |
| 56 | { "challenge": "pin" } |
| 57 | ], |
| 58 | "name-assignment": |
| 59 | { |
| 60 | "param": "/email" |
| 61 | } |
| 62 | } |
| 63 | ~EOF |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 64 | echo "" |
tylerliu | b7083bd | 2020-10-17 20:42:14 -0700 | [diff] [blame^] | 65 | } |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 66 | |
Zhiyi Zhang | c318a7a | 2020-10-17 17:41:19 -0700 | [diff] [blame] | 67 | echo "Do you want to (re) compile and build NDNCERT? [Y/N]" |
tylerliu | b7083bd | 2020-10-17 20:42:14 -0700 | [diff] [blame^] | 68 | read -r NDNCERT_COMPILE |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 69 | echo "" |
| 70 | |
| 71 | case $NDNCERT_COMPILE in |
| 72 | N|n) |
Zhiyi Zhang | c318a7a | 2020-10-17 17:41:19 -0700 | [diff] [blame] | 73 | echo "Okay, we'll skip compilation and build." |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 74 | ;; |
| 75 | Y|y) |
| 76 | cd ../ && CXXFLAGS="-O2" ./waf configure |
| 77 | ./waf |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 78 | ;; |
| 79 | *) |
| 80 | echo "Unknown option, build and install is cancelled" |
| 81 | exit |
| 82 | ;; |
| 83 | esac |
Zhiyi Zhang | c318a7a | 2020-10-17 17:41:19 -0700 | [diff] [blame] | 84 | echo "Need sudo to install NDNCERT CLI tools" |
| 85 | sudo ./waf install |
| 86 | echo "" |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 87 | |
| 88 | echo "===================================================================" |
| 89 | echo "==" |
| 90 | echo "== Deploying NDNCERT" |
| 91 | echo "==" |
| 92 | echo "===================================================================" |
| 93 | echo "" |
| 94 | echo "Are you sure [Y/n] ?" |
tylerliu | b7083bd | 2020-10-17 20:42:14 -0700 | [diff] [blame^] | 95 | read -r DEPLOY |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 96 | |
| 97 | case $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 | ;; |
| 108 | esac |
| 109 | |
| 110 | echo "" |
| 111 | echo "===================================================================" |
| 112 | echo "==" |
| 113 | echo "== Deployment started" |
| 114 | echo "==" |
| 115 | echo "===================================================================" |
| 116 | |
tylerliu | b7083bd | 2020-10-17 20:42:14 -0700 | [diff] [blame^] | 117 | echo "What is the CA Prefix (eg. /example) you want to deploy?" |
| 118 | read -r CA_PREFIX |
| 119 | echo "" |
| 120 | |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 121 | echo "Do you want to install ndncert CA for systemd on this machine? [Y/N]" |
tylerliu | b7083bd | 2020-10-17 20:42:14 -0700 | [diff] [blame^] | 122 | read -r SYSTEMD_INSTALL |
Zhiyi Zhang | c318a7a | 2020-10-17 17:41:19 -0700 | [diff] [blame] | 123 | echo "" |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 124 | |
| 125 | case $SYSTEMD_INSTALL in |
| 126 | N|n) |
| 127 | echo "We will not install systemd CA on this machine" |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 128 | 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" |
tylerliu | b7083bd | 2020-10-17 20:42:14 -0700 | [diff] [blame^] | 133 | sudo cp "$(pwd)/../build/systemd/ndncert-ca.service" /etc/systemd/system |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 134 | sudo chmod 644 /etc/systemd/system/ndncert-ca.service |
| 135 | ;; |
| 136 | *) |
| 137 | echo "Unknown option, deployment cancelled" |
| 138 | exit |
| 139 | ;; |
| 140 | esac |
| 141 | |
Zhiyi Zhang | c318a7a | 2020-10-17 17:41:19 -0700 | [diff] [blame] | 142 | echo "" |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 143 | echo "ndncert-ca service requires user ndn. Will check it now :D" |
| 144 | if id ndn &>/dev/null; then |
| 145 | echo 'ndn user account found, GOOD!' |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 146 | else |
| 147 | echo 'ndn user not found; adding ndn user as root' |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 148 | sudo useradd ndn |
| 149 | fi |
| 150 | |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 151 | echo "" |
Zhiyi Zhang | c318a7a | 2020-10-17 17:41:19 -0700 | [diff] [blame] | 152 | echo "ndncert-ca service requires /var/lib/ndncert-ca. Will check or create the keychain in /var/lib/ndncert-ca" |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 153 | sudo mkdir -p /var/lib/ndncert-ca |
| 154 | sudo chown ndn /var/lib/ndncert-ca |
| 155 | echo '/var/lib/ndncert-ca is ready, GOOD!' |
| 156 | |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 157 | echo "" |
tylerliu | b7083bd | 2020-10-17 20:42:14 -0700 | [diff] [blame^] | 158 | echo "Do you want to import an exisitng safebag for $CA_PREFIX ? [Y/N]" |
| 159 | read -r USE_SAFE_BAG |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 160 | |
| 161 | case $USE_SAFE_BAG in |
| 162 | N|n) |
tylerliu | b7083bd | 2020-10-17 20:42:14 -0700 | [diff] [blame^] | 163 | echo "Generating new NDN identity for $CA_PREFIX" |
| 164 | sudo HOME=/var/lib/ndncert-ca -u ndn ndnsec-keygen "$CA_PREFIX" |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 165 | ;; |
| 166 | Y|y) |
| 167 | echo "Reading the safebag." |
| 168 | echo "What is the safebag file name?" |
tylerliu | b7083bd | 2020-10-17 20:42:14 -0700 | [diff] [blame^] | 169 | read -r SAFE_BAG_PATH |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 170 | echo "" |
| 171 | |
| 172 | echo "What is the password of the safebag?" |
tylerliu | b7083bd | 2020-10-17 20:42:14 -0700 | [diff] [blame^] | 173 | read -r SAFE_BAG_PWD |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 174 | echo "" |
| 175 | |
tylerliu | b7083bd | 2020-10-17 20:42:14 -0700 | [diff] [blame^] | 176 | sudo HOME=/var/lib/ndncert-ca -u ndn ndnsec-import -i "$SAFE_BAG_PATH" -P "$SAFE_BAG_PWD" |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 177 | ;; |
| 178 | *) |
| 179 | echo "Unknown option, deployment cancelled" |
| 180 | exit |
| 181 | ;; |
| 182 | esac |
| 183 | |
Zhiyi Zhang | c318a7a | 2020-10-17 17:41:19 -0700 | [diff] [blame] | 184 | echo "" |
tylerliu | b7083bd | 2020-10-17 20:42:14 -0700 | [diff] [blame^] | 185 | echo "Do you want to request a certificate from a parent CA? [Y/N]" |
| 186 | read -r RUN_CLIENT |
| 187 | case $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 | ;; |
| 201 | esac |
| 202 | |
| 203 | generate_ca_config "$CA_PREFIX" |
Zhiyi Zhang | c318a7a | 2020-10-17 17:41:19 -0700 | [diff] [blame] | 204 | |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 205 | echo "Do you want to start the service now? [Y/N]" |
tylerliu | b7083bd | 2020-10-17 20:42:14 -0700 | [diff] [blame^] | 206 | read -r START_NOW |
Zhiyi Zhang | c318a7a | 2020-10-17 17:41:19 -0700 | [diff] [blame] | 207 | case $START_NOW in |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 208 | 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 Zhang | c318a7a | 2020-10-17 17:41:19 -0700 | [diff] [blame] | 215 | sleep 2 |
Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame] | 216 | 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 | ;; |
| 225 | esac |