2023-01-04 01:02:07 +01:00
|
|
|
#!/bin/bash
|
2023-01-03 13:25:44 +01:00
|
|
|
|
|
|
|
# Check for openssl
|
|
|
|
command -v openssl >/dev/null 2>&1 || { echo >&2 "openssl required but not found. Aborting."; exit 1; }
|
|
|
|
|
2023-01-04 01:02:07 +01:00
|
|
|
DIR="$PWD/.keys"
|
2023-01-03 13:25:44 +01:00
|
|
|
|
2023-01-04 01:02:07 +01:00
|
|
|
# if previous keys exist, remove them
|
|
|
|
if [ -d "$DIR" ]; then
|
|
|
|
rm -rf "$DIR"
|
2023-01-03 13:25:44 +01:00
|
|
|
fi
|
|
|
|
|
2023-01-04 01:02:07 +01:00
|
|
|
# create new directory
|
|
|
|
mkdir "$DIR"
|
2023-01-03 13:25:44 +01:00
|
|
|
|
|
|
|
# Generate new keys
|
|
|
|
openssl req -x509 -newkey rsa:4096 -keyout "$DIR/key.pem" -out "$DIR/cert.cert" -days 36500 -subj '/CN=www.mydom.com/O=My Company Name LTD./C=US' -outform DER -passout pass:test
|
|
|
|
openssl x509 -inform DER -in "$DIR/cert.cert" -out "$DIR/cert.pem"
|
|
|
|
openssl pkcs12 -export -out "$DIR/cert.pfx" -inkey "$DIR/key.pem" -in "$DIR/cert.pem" -passin pass:test -passout pass:test
|