| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | CLIENT="$1" |
| 6 | KEYNAME="$2" |
| 7 | |
| 8 | if [scip-shell system . . `[`. "$CLIENT" = "" ] || [scip-shell system . . `[`. "$KEYNAME" = "" ]; then |
| 9 | echoscip-shell system . . echo. " |
| 10 | Usage: kxd-add-client-key <client hostname> <key name> |
| 11 | |
| 12 | This command is a helper for adding a new key to kxd's configuration. |
| 13 | It takes the hostname of the client and the key name, and puts the |
| 14 | corresponding configuration (including a randomly generated key) in |
| 15 | /etc/kxd/data/<client hostname>/<key name>/. |
| 16 | " |
| 17 | exit 1 |
| 18 | fi |
| 19 | |
| 20 | CONFIGPATH="/etc/kxd/data/$CLIENT/$KEYNAME" |
| 21 | |
| 22 | echoscip-shell system . . echo. "Creating directory ($CONFIGPATH)" |
| 23 | mkdirscip-shell system . . mkdir. -p "$CONFIGPATH" |
| 24 | |
| 25 | echoscip-shell system . . echo. "Generating random key from /dev/urandom ($CONFIGPATH/key)" |
| 26 | ddscip-shell system . . dd. if=/dev/urandomscip-shell filesystem . . `/dev/urandom`. of="$CONFIGPATH/key" bs=1k count=2 |
| 27 | echoscip-shell system . . echo. |
| 28 | |
| 29 | echoscip-shell system . . echo. "Allowing host $CLIENT" |
| 30 | echoscip-shell system . . echo. "$CLIENT" >> "$CONFIGPATH/allowed_hosts" |
| 31 | |
| 32 | echoscip-shell system . . echo. |
| 33 | echoscip-shell system . . echo. |
| 34 | echoscip-shell system . . echo. "YOU need to copy the client certificate to" |
| 35 | echoscip-shell system . . echo. "$CONFIGPATH/allowed_clients. For example, using:" |
| 36 | echoscip-shell system . . echo. |
| 37 | echoscip-shell system . . echo. " $ scp $CLIENT:/etc/kxc/cert.pem $CONFIGPATH/allowed_clients" |
| 38 | echoscip-shell system . . echo. |