Commit b8d92781 authored by Lindsay Harvey's avatar Lindsay Harvey
Browse files

Add Certificate common name validation to ask_key_questions function

parent 3f16a9be
......@@ -24,7 +24,56 @@ SHOREWALLVARS="/etc/shorewall/openvpn.vars"
function ask_key_questions
{
read -p "Common Name of certificate (this should be unique using [A-z0-9_] only ): " OVPN_COMMONNAME
echo ""
read -p "Common Name of certificate, this should be unique,
using 4 to 15 upper or lowercase letters or numbers and _ ONLY: " OVPN_COMMONNAME
# OVPN_COMMONNAME <-- This is the variable to return to the other script
# Yes I stole this validation test from the init script so yes it could be optimized
# this is a quick and dirty fix that at least does the job, I may improve it one day.
#Count the number of characters entered
COUNT=($(echo -n $OVPN_COMMONNAME | wc -m))
if [ $COUNT -eq 0 ]; then
#Enter must have been pressed without any entry so lets just set COMMONNAME_VALID to 0 to catch us in the while loop below
COMMONNAME_VALID=0
else
#There was something entered so lets validate OVPN_COMMONNAME
if [ $COUNT -gt 3 ] && [ $COUNT -lt 16 ]; then
#We have between 4 and 12 characters in the variable, lets validate they are valid
if [[ $OVPN_COMMONNAME =~ ^[0-9A-Za-z_]+$ ]]; then
COMMONNAME_VALID=1 #Yay! winner winner, chicken dinner
fi
else
#There must not have been a valid OVPN_COMMONNAME entered so we continue to the while loop below
COMMONNAME_VALID=0
fi
fi
#If the COMMONNAME_VALID variable was not set to 1 above then we go into this loop to try again
while [[ $COMMONNAME_VALID != 1 ]]; do
echo ""
echo "The certificate name can only consist of (4-15) upper or lowercase letters or numbers and _"
read -p "You entered [$OVPN_COMMONNAME]. Please try again: " OVPN_COMMONNAME
COUNT=($(echo -n $OVPN_COMMONNAME | wc -m))
if [ $COUNT -eq 0 ]; then
#Enter was pressed again so we stay in the loop
COMMONNAME_VALID=0
else
#There was something entered so lets validate the ORGNICK
if [ $COUNT -gt 3 ] && [ $COUNT -lt 16 ]; then
#We have between 4 and 12 characters in the variable, lets validate they are valid letters
if [[ $OVPN_COMMONNAME =~ ^[0-9A-Za-z_]+$ ]]; then
COMMONNAME_VALID=1 #Yay! winner winner, chicken dinner
fi
fi
fi
done
read -p "Users E-mail address for certificate: " OVPN_EMAIL
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment