#!/bin/bash
echo "Введите название сертификата VPN сервера"
read cert
echo "Введите dns name vpn-сервера"
read dnsname
echo "Введите email"
read email
echo "Введите срок действия сертификата"
read day
echo "Введите пароль"
read password
openssl genrsa -aes256 -passout pass:$password -out $cert.key 4096
openssl rsa -passin pass:$password -in $cert.key -out ${cert}_key.pem
cat > $cert.conf  <<EOF
[ req ]
prompt = no
days = $day
req_extensions = v3_req
distinguished_name = req_distinguished_name

[ req_distinguished_name ]
C = Ru
ST = Moscow
L = Moscow
O = cnfs.ru
OU = cnfs.ru
CN = $dnsname
emailAddress = $email

[ v3_req ]
keyUsage = critical, digitalSignature
extendedKeyUsage = serverAuth
subjectAltName = @sans

[ sans ] 
DNS.0 = $dnsname
EOF
openssl req -new -key ${cert}_key.pem -out $cert.csr -sha256 -config $cert.conf
#openssl x509 -CAcreateserial -req -extfile $cert.conf -extensions v3_req -days 365 -in $cert.csr -CA rootCA.pem -CAkey rootCA.key -out $cert.pem
