smartsign/scripts/create.p12.sh

30 lines
1020 B
Bash
Raw Permalink Normal View History

2023-11-24 23:52:56 +00:00
#!/bin/bash
# Directory where the script and certificates will be stored
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
CERT_DIR="$SCRIPT_DIR/../.nogit"
# Check if .nogit directory exists, if not, create it
if [ ! -d "$CERT_DIR" ]; then
mkdir -p "$CERT_DIR"
fi
# Names of the files
PRIVATE_KEY="$CERT_DIR/private.key"
CERTIFICATE="$CERT_DIR/certificate.crt"
P12_CERTIFICATE="$CERT_DIR/certificate.p12"
2023-11-24 23:54:58 +00:00
# Certificate subject details
SUBJECT="/C=US/ST=California/L=San Francisco/O=Your Company/OU=Your Department/CN=www.yourdomain.com"
2023-11-24 23:52:56 +00:00
# Generate a private key
openssl genpkey -algorithm RSA -out "$PRIVATE_KEY" -pkeyopt rsa_keygen_bits:2048
2023-11-24 23:54:58 +00:00
# Create a self-signed certificate with no prompts
openssl req -new -x509 -days 365 -key "$PRIVATE_KEY" -out "$CERTIFICATE" -subj "$SUBJECT"
2023-11-24 23:52:56 +00:00
# Convert to P12 format
2023-11-24 23:54:58 +00:00
openssl pkcs12 -export -out "$P12_CERTIFICATE" -inkey "$PRIVATE_KEY" -in "$CERTIFICATE" -passout pass:YourPassword
2023-11-24 23:52:56 +00:00
echo "P12 certificate generated at $P12_CERTIFICATE"