-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathtrust-cert.sh
More file actions
executable file
·85 lines (73 loc) · 2.76 KB
/
Copy pathtrust-cert.sh
File metadata and controls
executable file
·85 lines (73 loc) · 2.76 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env bash
# trust-cert.sh — Install CAAL's self-signed certificate into the OS/browser trust store.
# Usage: ./trust-cert.sh [--yes]
set -euo pipefail
CERT="./certs/server.crt"
AUTO_YES=false
for arg in "$@"; do
case "$arg" in
--yes|-y) AUTO_YES=true ;;
esac
done
if [ ! -f "$CERT" ]; then
echo "No certificate found at $CERT — start the stack first so it is generated."
exit 0
fi
if [ "$AUTO_YES" = false ]; then
printf "Trust the CAAL self-signed certificate so browsers stop showing warnings? [y/N] "
read -r answer
case "$answer" in
[Yy]*) ;;
*) echo "Skipped."; exit 0 ;;
esac
fi
OS="$(uname -s)"
case "$OS" in
Darwin)
echo "Installing certificate into macOS System Keychain..."
sudo security add-trusted-cert -d -r trustRoot \
-k /Library/Keychains/System.keychain "$CERT"
echo "Done — certificate trusted on macOS."
;;
Linux)
# System trust store
if [ -d /usr/local/share/ca-certificates ]; then
echo "Installing certificate (Debian/Ubuntu)..."
sudo cp "$CERT" /usr/local/share/ca-certificates/caal.crt
sudo update-ca-certificates
elif [ -d /etc/pki/ca-trust/source/anchors ]; then
echo "Installing certificate (RHEL/Fedora)..."
sudo cp "$CERT" /etc/pki/ca-trust/source/anchors/caal.pem
sudo update-ca-trust
elif command -v trust >/dev/null 2>&1; then
echo "Installing certificate (Arch/p11-kit)..."
sudo trust anchor --store "$CERT"
else
echo "Warning: could not detect CA trust directory. Skipping system trust."
fi
# Chrome (NSS database)
if command -v certutil >/dev/null 2>&1; then
NSSDB="$HOME/.pki/nssdb"
if [ -d "$NSSDB" ]; then
echo "Adding certificate to Chrome trust store..."
certutil -d sql:"$NSSDB" -D -n "CAAL" 2>/dev/null || true
certutil -d sql:"$NSSDB" -A -t "C,," -n "CAAL" -i "$CERT"
fi
# Firefox profiles
for profile in "$HOME"/.mozilla/firefox/*.default*; do
if [ -d "$profile" ]; then
echo "Adding certificate to Firefox profile $(basename "$profile")..."
certutil -d sql:"$profile" -D -n "CAAL" 2>/dev/null || true
certutil -d sql:"$profile" -A -t "C,," -n "CAAL" -i "$CERT"
fi
done
else
echo "Tip: install certutil (libnss3-tools) to also trust the cert in Chrome/Firefox."
fi
echo "Done — certificate trusted on Linux."
;;
*)
echo "Unsupported OS: $OS. Please import $CERT manually."
exit 1
;;
esac