Created
March 29, 2023 02:21
-
-
Save takeshi-d/c287e8f75b98c53914280b92336cf0f4 to your computer and use it in GitHub Desktop.
generate CSR
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
#!/bin/bash | |
# DEST_DIR=/home/user/path/to/dir | |
# FILENAME_FQDN='example.com'; | |
# SUBJECT_FQDN='*.example.com'; | |
DEST_DIR=${1} | |
FILENAME_FQDN=${2} | |
SUBJECT_FQDN=${3} | |
if [ -z ${1} ] || [ -z ${2} ] || [ -z ${3} ] | |
then echo "not enough args... usage: `basename ${0}` DEST_DIR FILE_NAME_FQDN CSR_FQDN"; | |
exit; | |
fi | |
if [ -e ${DEST_DIR} ] | |
then echo 'OK... directory exists'; | |
if [ -e ${DEST_DIR}/${FILENAME_FQDN}.key ] | |
then echo 'ERROR... file already exists'; | |
else | |
cd ${DEST_DIR}; | |
openssl req -new -newkey rsa:2048 -nodes -keyout ${FILENAME_FQDN}.key -out ${FILENAME_FQDN}.csr -subj "/C=JP/ST=Tokyo/L=Musashino-Shi/O=Example Co Ltd/CN=${SUBJECT_FQDN}" | |
fi | |
openssl req -text -noout -verify -in ${DEST_DIR}/${FILENAME_FQDN}.csr | grep 'Subject:' | sed 's/^[ \t]\+//' | |
openssl rsa -in ${DEST_DIR}/${FILENAME_FQDN}.key -check | head -1 | |
else | |
echo 'ERROR... directory does not exist'; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment