-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-router-ssl.sh
executable file
·39 lines (29 loc) · 1.87 KB
/
update-router-ssl.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash -exu
rm .secrets/unifi.keystore.jks || :
# Concat together both private keys.
cat .secrets/privkey.pem .secrets/cert.pem > .secrets/server.pem
# # Send it over to the server.
# scp .secrets/server.pem [email protected]:~
# ssh [email protected] 'sudo su -c "mv /home/voor/server.pem /etc/lighttpd/server.pem"'
# ssh [email protected] 'sudo su -c "chown root:root /etc/lighttpd/server.pem"'
openssl pkcs12 -export -in .secrets/fullchain.pem -inkey .secrets/privkey.pem -certfile .secrets/cert.pem -out .secrets/unifi.p12 -name unifi -password pass:aircontrolenterprise
keytool -importkeystore -srckeystore .secrets/unifi.p12 -srcstoretype PKCS12 -srcstorepass aircontrolenterprise -destkeystore .secrets/unifi.keystore.jks -storepass aircontrolenterprise
cp .secrets/cert.pem .secrets/cloudkey.crt && \
cp .secrets/privkey.pem .secrets/cloudkey.key
pushd .secrets && \
tar cf cert.tar cloudkey.crt cloudkey.key unifi.keystore.jks && \
popd
scp .secrets/cert.tar [email protected]:/etc/ssl/private
# Verify:
# keytool -list -v -keystore .secrets/unifi.keystore.jks
#
# Do this on the router:
# kill -SIGINT $(cat /var/run/lighttpd.pid)
# ssh [email protected] 'sudo su -c "kill -SIGINT $(cat /var/run/lighttpd.pid)"'
# /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf
# ssh [email protected] 'sudo su -c "/usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf"'
# Do this on the cloud key:
ssh [email protected] 'tar xf /etc/ssl/private/cert.tar -C /etc/ssl/private/ \
&& chown root:ssl-cert /etc/ssl/private/cloudkey.crt /etc/ssl/private/cloudkey.key /etc/ssl/private/unifi.keystore.jks /etc/ssl/private/cert.tar \
&& chmod 640 /etc/ssl/private/cloudkey.crt /etc/ssl/private/cloudkey.key /etc/ssl/private/unifi.keystore.jks /etc/ssl/private/cert.tar \
&& nginx -t && /etc/init.d/nginx restart && /etc/init.d/unifi restart'