-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-cert.sh
More file actions
executable file
·72 lines (60 loc) · 2.03 KB
/
Copy pathsetup-cert.sh
File metadata and controls
executable file
·72 lines (60 loc) · 2.03 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
#!/bin/bash
# Creates a local self-signed code-signing certificate in your login Keychain.
# Run this once; build.sh calls it automatically if the cert is missing.
#
# macOS will ask for your login password once to add the trust setting.
# That prompt is enforced by the OS and cannot be skipped.
set -e
CERT_NAME="ScribeBuddy Dev"
if security find-identity -v -p codesigning 2>/dev/null | grep -q "$CERT_NAME"; then
echo "✓ Certificate '$CERT_NAME' already exists — nothing to do."
exit 0
fi
echo "Creating signing certificate '$CERT_NAME'…"
echo "(macOS will ask for your login password once to set the trust — this is normal)"
echo ""
TMP=$(mktemp -d)
trap 'rm -rf "$TMP"' EXIT
# Write an OpenSSL config that marks the cert for code signing.
cat > "$TMP/cert.conf" << 'CONF'
[req]
distinguished_name = dn
x509_extensions = ext
prompt = no
[dn]
CN = ScribeBuddy Dev
[ext]
keyUsage = critical, digitalSignature
extendedKeyUsage = critical, codeSigning
basicConstraints = critical, CA:true
subjectKeyIdentifier = hash
CONF
# Generate key + self-signed certificate (10-year validity).
openssl genrsa -out "$TMP/key.pem" 2048 2>/dev/null
openssl req -new -x509 \
-key "$TMP/key.pem" \
-out "$TMP/cert.pem" \
-days 3650 \
-config "$TMP/cert.conf" 2>/dev/null
# Bundle into PKCS12 so `security import` can ingest both key and cert.
openssl pkcs12 -export \
-out "$TMP/cert.p12" \
-inkey "$TMP/key.pem" \
-in "$TMP/cert.pem" \
-passout pass:tmp 2>/dev/null
# Import into the login keychain.
# -A lets codesign use the key without a per-use prompt.
security import "$TMP/cert.p12" \
-k ~/Library/Keychains/login.keychain-db \
-P tmp \
-A \
-f pkcs12 2>/dev/null
# Mark the certificate as trusted for code signing.
# This is the step that triggers the macOS password prompt.
security add-trusted-cert \
-d \
-r trustRoot \
-k ~/Library/Keychains/login.keychain-db \
"$TMP/cert.pem"
echo ""
echo "✓ Done. '$CERT_NAME' is now trusted for code signing."