Created
July 13, 2023 14:38
-
-
Save aslafy-z/382e692a724002dd2e0faac7e1e8d9ae to your computer and use it in GitHub Desktop.
generate-csr.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Generate a CSR for a list of subject alt names | |
set -e -o pipefail | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <common name> [subject alt names]" | |
exit 1 | |
fi | |
common_name=$1 | |
shift | |
filename_prefix="$(mktemp -d)/$(echo "$common_name" | sed -e 's/[^A-Za-z0-9_-]/_/g')" | |
set -- "$@" "$common_name" | |
subject_alt_names="$(echo "$@" | sed -e 's/[^ ]* */DNS:&/g' -e 's/ /,/g')" | |
openssl req -nodes -newkey rsa:2048 \ | |
-keyout "${filename_prefix}.key" \ | |
-out "${filename_prefix}.csr" \ | |
-subj "/C=FR/O=Carrefour France/OU=OneCloud/CN=$common_name" \ | |
-addext "subjectAltName = $subject_alt_names" | |
echo | |
echo "success: CSR generation successful" | |
echo "CSR: ${filename_prefix}.csr" | |
echo "KEY: ${filename_prefix}.key" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment