anyproxy/cert/gen-cer

49 lines
1.3 KiB
Plaintext
Raw Normal View History

2014-08-08 16:30:53 +08:00
#!/bin/bash
#Required
domain=$1
2014-08-11 16:43:14 +08:00
outputPath=$2
2014-08-08 16:30:53 +08:00
commonname=$domain
#Change to your company details
country=ZH
state=Shanghai
locality=Shanghai
organization=a.com
organizationalunit=IT
email=a@b.com
#Optional
password=a
2014-08-13 11:51:39 +08:00
if [ -z "$domain" ]
2014-08-08 16:30:53 +08:00
then
echo "Argument not present."
2014-08-13 11:51:39 +08:00
echo "Useage $0 [domain] [outputPath]"
2014-08-08 16:30:53 +08:00
exit 99
fi
2014-08-11 16:43:14 +08:00
echo "Generating key request for $outputPath$domain"
2014-08-08 16:30:53 +08:00
#Generate a key
# openssl genrsa -out host.key 2048
2014-08-11 16:43:14 +08:00
# openssl genrsa -des3 -out $outputPath$domain.key 2048 -noout
openssl genrsa -passout pass:$password -out $outputPath$domain.key 2048
2014-08-08 16:30:53 +08:00
#Remove passphrase from the key. Comment the line out to keep the passphrase
echo "Removing passphrase from key"
2014-08-11 16:43:14 +08:00
openssl rsa -in $outputPath$domain.key -passin pass:$password -out $outputPath$domain.key
2014-08-08 16:30:53 +08:00
#Create the request
echo "Creating CSR"
2014-08-11 16:43:14 +08:00
openssl req -new -key $outputPath$domain.key -out $outputPath$domain.csr -passin pass:$password \
2014-08-08 16:30:53 +08:00
-subj "/C=$country/ST=$state/L=$locality/O=$organization/OU=$organizationalunit/CN=$commonname/emailAddress=$email"
#Generating a Self-Signed Certificate
2014-08-11 16:43:14 +08:00
openssl x509 -req -days 365 -in $outputPath$domain.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out $outputPath$domain.crt
2014-09-11 15:31:03 +08:00
# -signkey $outputPath$domain.key
2014-08-08 16:30:53 +08:00
#openssl x509 -req -in host.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out host.crt -days 365
echo "Finished"