#!/bin/bash
if [ $# -ne 2 ]; then
echo "Usage: openssl.sh
"
exit 1
fi
# Creating CA private key
#openssl genrsa -out "$1/ca.key"
# Creating CA private key and cert
openssl req -newkey rsa:$2 -nodes -keyout "$1/ca.key" -new -x509 -days 3650 -out "$1/ca.pem"
# Creating RSA cert request
openssl req -newkey rsa:$2 -nodes -keyout "$1/rsa.key" -new -days 1825 -out "$1/rsareq.pem"
# Creating RSA cert with the previusly created request
openssl x509 -days 1825 -CA "$1/ca.pem" -CAkey "$1/ca.key" -req -CAcreateserial -in "$1/rsareq.pem" -out "$1/rsa.pem"
# Verifying new cert with the root key
openssl verify -CAfile "$1/ca.pem" "$1/rsa.pem"
# Checking details
openssl x509 -text -noout -in "$1/ca.key"
openssl x509 -text -noout -in "$1/rsa.key"