1+ #! /bin/bash
2+
3+ # Create ClickIt Development Certificate for consistent app signing
4+ # This creates a permanent self-signed certificate that maintains app identity across builds
5+
6+ set -e
7+
8+ CERT_NAME=" ClickIt Developer Certificate"
9+ KEYCHAIN=" $HOME /Library/Keychains/login.keychain-db"
10+ TEMP_DIR=$( mktemp -d)
11+
12+ echo " 🔐 Creating ClickIt development certificate..."
13+
14+ # Delete existing certificate if it exists
15+ security delete-certificate -c " $CERT_NAME " 2> /dev/null && echo " Removed existing certificate" || true
16+
17+ # Create certificate configuration
18+ cat > " $TEMP_DIR /cert.conf" << EOF
19+ [req]
20+ default_bits = 2048
21+ prompt = no
22+ distinguished_name = dn
23+ req_extensions = v3_req
24+
25+ [dn]
26+ CN=ClickIt Developer Certificate
27+ O=ClickIt Development
28+ OU=ClickIt Team
29+ C=US
30+
31+ [v3_req]
32+ basicConstraints = CA:FALSE
33+ keyUsage = nonRepudiation, digitalSignature, keyEncipherment
34+ extendedKeyUsage = codeSigning
35+ EOF
36+
37+ echo " 📝 Generating private key and certificate..."
38+
39+ # Generate private key
40+ openssl genrsa -out " $TEMP_DIR /private.key" 2048
41+
42+ # Generate self-signed certificate (valid for 10 years)
43+ openssl req -new -x509 -key " $TEMP_DIR /private.key" -out " $TEMP_DIR /cert.crt" -days 3650 -config " $TEMP_DIR /cert.conf" -extensions v3_req
44+
45+ echo " 🔑 Importing certificate and private key into keychain..."
46+
47+ # Import certificate first
48+ security import " $TEMP_DIR /cert.crt" -k " $KEYCHAIN " -T /usr/bin/codesign -T /usr/bin/security
49+
50+ # Import private key
51+ security import " $TEMP_DIR /private.key" -k " $KEYCHAIN " -T /usr/bin/codesign -T /usr/bin/security
52+
53+ echo " ✅ Certificate imported successfully"
54+
55+ # Set trust settings for code signing (allow without password)
56+ security set-key-partition-list -S apple-tool:,apple: -s -k " " -D " $CERT_NAME " -t private " $KEYCHAIN " 2> /dev/null || echo " Trust settings configured"
57+
58+ # Add trust settings for code signing (this makes it appear in find-identity)
59+ echo " 🔐 Setting certificate trust for code signing..."
60+ security add-trusted-cert -d -r trustRoot -k " $KEYCHAIN " " $TEMP_DIR /cert.crt" 2> /dev/null || echo " Certificate already trusted"
61+
62+ # Verify certificate was created
63+ if security find-certificate -c " $CERT_NAME " > /dev/null 2>&1 ; then
64+ echo " ✅ Certificate verification passed"
65+
66+ # Show certificate details
67+ echo " 📋 Certificate details:"
68+ security find-certificate -c " $CERT_NAME " -p | openssl x509 -subject -dates -noout 2> /dev/null
69+ else
70+ echo " ❌ Certificate verification failed"
71+ exit 1
72+ fi
73+
74+ # Clean up temporary files
75+ rm -rf " $TEMP_DIR "
76+
77+ echo " "
78+ echo " 🎯 Certificate setup complete!"
79+ echo " Name: $CERT_NAME "
80+ echo " This certificate will provide consistent app identity across builds"
81+ echo " Permissions should now persist after rebuilding the app"
0 commit comments