-
-
-
PROJECT_NAME=$1
-
-
if
[ "x" = "x$PROJECT_NAME" ];
-
then
-
echo
Missing project name
-
echo
Run $0 PROJECT_NAME
-
exit
1
-
fi
-
-
basename=$(
echo
$PROJECT_NAME | \
-
iconv
-f UTF-8 -t ascii//TRANSLIT | \
-
tr
[:upper:] [:lower:] | \
-
sed
's/[^0-9a-z.]/-/g')
-
-
key_filename=$basename.key
-
csr_filename=$basename.csr
-
cnf_filename=$basename.cnf
-
crt_filename=$basename.crt
-
-
-
-
if
[ ! -f $cnf_filename ];
-
then
-
cat
> $cnf_filename <<EOT
-
[ req ]
-
distinguished_name = req_distinguished_name
-
req_extensions = v3_req # The extensions to add to a certificate request
-
-
[ req_distinguished_name ]
-
countryName = Country Name (2 letter code)
-
countryName_default = FR
-
countryName_min = 2
-
countryName_max = 2
-
stateOrProvinceName = State or Province Name (full name)
-
stateOrProvinceName_default = Some-State
-
localityName = Locality Name (eg, city)
-
0.organizationName = Organization Name (eg, company)
-
0.organizationName_default = Internet Widgits Pty Ltd
-
organizationalUnitName = Organizational Unit Name (eg, section)
-
commonName = Common Name (e.g. server FQDN or YOUR name)
-
commonName_max = 64
-
emailAddress = Email Address
-
emailAddress_max = 64
-
-
[ v3_req ]
-
subjectAltName = @alt_names
-
-
[ alt_names ]
-
DNS.1 = $PROJECT_NAME
-
DNS.2 = www.$PROJECT_NAME
-
DNS.3 = api.$PROJECT_NAME
-
DNS.4 = cdn.$PROJECT_NAME
-
EOT
-
fi
-
-
-
-
if
[ ! -f $key_filename ];
-
then
-
-
openssl
genrsa -out $key_filename
-
fi
-
-
if
[ ! -f $csr_filename ];
-
then
-
-
openssl
req -new \
-
-key $key_filename \
-
-out $csr_filename \
-
-config $cnf_filename
-
fi
-
-
-
openssl
req -in $csr_filename -noout -text
-
-
if
[ ! -f $crt_filename ];
-
then
-
-
openssl
x509 -req \
-
-days 3650 \
-
-in $csr_filename \
-
-signkey $key_filename \
-
-out $crt_filename \
-
-extensions v3_req \
-
-extfile $cnf_filename
-
fi
-
-
if
which certutil
> /dev/null;
-
then
-
if
! certutil
-d sql:$HOME/.pki/nssdb -L -n "$PROJECT_NAME" > /dev/null;
-
then
-
-
certutil
-d sql:$HOME/.pki/nssdb -A -t "P,," -n "$PROJECT_NAME" -i $crt_filename
-
fi
-
fi
-
-
cat
<<EOT
-
-
httpd.conf:
-
SSLEngine on
-
SSLCertificateFile $PWD/$crt_filename
-
SSLCertificateKeyFile $PWD/$key_filename
-
EOT