smartsign/scripts/create.p12.sh
2023-11-25 00:54:58 +01:00

30 lines
1020 B
Bash

#!/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"
# Certificate subject details
SUBJECT="/C=US/ST=California/L=San Francisco/O=Your Company/OU=Your Department/CN=www.yourdomain.com"
# Generate a private key
openssl genpkey -algorithm RSA -out "$PRIVATE_KEY" -pkeyopt rsa_keygen_bits:2048
# Create a self-signed certificate with no prompts
openssl req -new -x509 -days 365 -key "$PRIVATE_KEY" -out "$CERTIFICATE" -subj "$SUBJECT"
# Convert to P12 format
openssl pkcs12 -export -out "$P12_CERTIFICATE" -inkey "$PRIVATE_KEY" -in "$CERTIFICATE" -passout pass:YourPassword
echo "P12 certificate generated at $P12_CERTIFICATE"