-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip automation of the certificate signing
- Loading branch information
1 parent
0d359d6
commit c26b9dc
Showing
4 changed files
with
76 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
cmake/ | ||
cmake/ | ||
capassphrase.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
# Romain Jacob | ||
|
||
# do NOT run as root | ||
|
||
source capassphrase.sh | ||
source serverIpConfig.sh | ||
DEVICENAME=$(hostname) | ||
|
||
# ssh into the server (which works thanks to agent forwarding) | ||
tmux kill-session -t certs # clean up if session already exists | ||
tmux new-session -d -s certs # create a tmux session | ||
tmux send-keys -t certs '' C-m # wait a bit | ||
tmux send-keys -t certs '' C-m | ||
tmux send-keys -t certs '' C-m | ||
tmux send-keys -t certs "ssh autopower@${REMOTEHOST}" C-m | ||
|
||
# clean existing read-only files | ||
echo "cleaning existing files on the server..." | ||
tmux send-keys -t certs 'cd /usr/autopower/zabbix/' C-m | ||
tmux send-keys -t certs "rm -f zabbix_client_${DEVICENAME}.psk" C-m | ||
tmux send-keys -t certs 'cd /usr/autopower/certs/' C-m | ||
tmux send-keys -t certs "rm -f /usr/autopower/certs/client_${DEVICENAME}.csr" C-m | ||
sleep 2 # wait a bit to give time to the tmux command to run | ||
|
||
|
||
# copy the certificate to the server with scp | ||
echo "copying the new files..." | ||
sudo cp /etc/mmclient/client_${DEVICENAME}.csr . | ||
scp client_${DEVICENAME}.csr autopower@${REMOTEHOST}:/usr/autopower/certs/client_${DEVICENAME}.csr | ||
# copy the psk to wherever (probably the server as well, I should make a directory for that) | ||
scp zabbix_psk.psk autopower@${REMOTEHOST}:/usr/autopower/zabbix/zabbix_client_${DEVICENAME}.psk | ||
|
||
# sign the certificate on the server | ||
echo "signing the new certificate..." | ||
SIGN_CMD="openssl x509 -req -in client_${DEVICENAME}.csr -CA ca.cer -CAkey ca.key -CAcreateserial -out client_${DEVICENAME}.cer -days 365 -sha512 -passin pass:'${PASSPHRASE}'" | ||
tmux send-keys -t certs "${SIGN_CMD}" C-m | ||
sleep 2 # wait a bit to give time to the tmux command to run | ||
|
||
# copy back client.cer and ca.cer (can be done via scp from the PI) | ||
# > scp-ing directly would require to make the mmclient directory globally writable | ||
echo "copying the signed certificate back on the client..." | ||
scp autopower@${REMOTEHOST}:/usr/autopower/certs/client_${DEVICENAME}.cer ~/client.cer | ||
scp autopower@${REMOTEHOST}:/usr/autopower/certs/ca.cer ~/ca.cer | ||
sudo mv ~/*.cer /etc/mmclient/ | ||
sudo chown mmclient: /etc/mmclient/client.cer | ||
sudo chown mmclient: /etc/mmclient/ca.cer | ||
|