Last active
March 24, 2017 13:47
-
-
Save OSapozhnikov/cdcc9df20eda71a10afbe7d094b5cdbc to your computer and use it in GitHub Desktop.
createReqCSR
This file contains hidden or 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 | |
| # Constants | |
| RED='\033[0;31m' | |
| GR='\033[0;32m' | |
| NC='\033[0m' # No Color | |
| # Hello | |
| echo "Hello, ${RED}"$USER"${NC}. This script will generate CSR for SSL Cert" | |
| # CommonName | |
| echo -n "${GR}Enter your domain CommonName [ENTER]: ${NC}" | |
| read domain | |
| #Required | |
| commonname=$domain | |
| #Change to your company details | |
| country= | |
| state=" | |
| locality= | |
| organization= | |
| organizationalunit= | |
| email=EMAIL | |
| #while read CERT_DATA; do echo "$CERT_DATA" ; done < cert_data #For future | |
| #Optional | |
| password= | |
| # Confirm data | |
| echo "${GR}Please confirm data:${NC}" | |
| echo "${RED}Country Name= ${GR}$country${NC}" | |
| echo "${RED}State Name= ${GR}$state${NC}" | |
| echo "${RED}Locality Name= ${GR}$locality${NC}" | |
| echo "${RED}Organization Name= ${GR}$organization${NC}" | |
| echo "${RED}Email Address= ${GR}$email${NC}" | |
| echo "${RED}Common Name= ${GR}$domain${NC}" | |
| echo -n "Start? (y/n) " | |
| read item | |
| case "$item" in | |
| y|Y);; | |
| n|N) exit 0;; | |
| *);; | |
| esac | |
| if [ -z "$domain" ] | |
| then | |
| echo "Argument not present." | |
| echo "Useage $0 [common name]" | |
| exit 99 | |
| fi | |
| #Create directory | |
| mkdir $domain | |
| #Create the request | |
| echo "Creating CSR" | |
| openssl req -days 365 -out $domain/$domain.csr -new -newkey rsa:2048 -nodes -keyout $domain/$domain.key \ | |
| -subj "/C=$country/ST=$state/L=$locality/O=$organization/CN=$commonname/emailAddress=$email" | |
| echo "---------------------------" | |
| echo "-----Below is your CSR-----" | |
| echo "---------------------------" | |
| echo | |
| cat $domain/$domain.csr | |
| echo | |
| echo "---------------------------" | |
| echo "-----Below is your Key-----" | |
| echo "---------------------------" | |
| echo | |
| cat $domain/$domain.key | |
| echo | |
| echo "---------------------------" | |
| echo "-----Files locations-----" | |
| echo "---------------------------" | |
| echo "Your CSR file in directory: $domain/$domain.csr" | |
| echo "Your Key file in directory: $domain/$domain.key" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment