This repository has been archived by the owner on Mar 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport_cert.sh
executable file
·57 lines (49 loc) · 1.63 KB
/
import_cert.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env bash
set -e
download_cert() {
curl --silent --fail https://outtune-api.prod-gcp.nais.io/cert --data @- << EOF | jq -r '.cert_pem' > cert.pem
{
"serial": "$(cat ~/.config/naisdevice/product_serial)",
"public_key_pem": "$(base64 --wrap 0 < ~/.config/naisdevice/browser_cert_pubkey.pem)"
}
EOF
}
main() {
for profile in "$HOME"/.mozilla/firefox/*.default-release/; do
echo "updating profile: $profile"
# If key already enrolled:
if certutil -d "$profile" -K -n naisdevice &> /dev/null; then
echo "cert only import"
(
set -e
cd "$(mktemp -d)" && echo "working in: $(pwd)"
download_cert
if certutil -d "$profile" -D -n naisdevice > /dev/null; then
echo "removed old cert"
else
echo "failed to remove old cert or no old cert found"
fi
certutil -d "$profile" -A -n naisdevice -i cert.pem -t ,,
rm -f cert.pem
echo "done"
)
else
echo "first time import"
(
set -e
cd "$(mktemp -d)" && echo "working in: $(pwd)"
openssl genrsa -out key.pem 4096
openssl rsa -in key.pem -pubout -outform PEM > ~/.config/naisdevice/browser_cert_pubkey.pem
download_cert
openssl pkcs12 -export -out bundle.p12 -in cert.pem -inkey key.pem -password pass:asd123 -name naisdevice
pk12util -d "$profile" -i bundle.p12 -W asd123
rm -f key.pem cert.pem bundle.p12
echo "done"
)
fi
done
}
# update $profile/ClientAuthRememberList.txt with cert prefs:
# nav-no.managed.us2.access-control.cas.ms:443
# nav-no.managed.prod04.access-control.cas.ms
main