-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to generate the tls certificates
- Loading branch information
1 parent
d67bc35
commit 28c697a
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#! /bin/bash | ||
|
||
# References:- 1. https://devopscube.com/create-self-signed-certificates-openssl/, | ||
# 2. https://mariadb.com/docs/server/security/data-in-transit-encryption/create-self-signed-certificates-keys-openssl/ | ||
# Modification is done as per this project | ||
|
||
if [ "$#" -ne 1 ] | ||
then | ||
echo "Error: No domain name argument provided" | ||
echo "Usage: Provide a domain name as an argument" | ||
exit 1 | ||
fi | ||
|
||
DOMAIN=$1 | ||
|
||
# Create root CA & Private key | ||
openssl req -x509 \ | ||
-sha256 -days 356 \ | ||
-nodes \ | ||
-newkey rsa:2048 \ | ||
-subj "/CN=${DOMAIN}/C=DE/L=San Fransisco" \ | ||
-keyout rootCA.key -out rootCA.crt | ||
|
||
# Generate Private key | ||
openssl genrsa -out ${DOMAIN}.key 2048 | ||
|
||
# Create csf conf | ||
|
||
cat > csr.conf <<EOF | ||
[ req ] | ||
default_bits = 2048 | ||
prompt = no | ||
default_md = sha256 | ||
req_extensions = req_ext | ||
distinguished_name = dn | ||
[ dn ] | ||
C = US | ||
ST = California | ||
L = San Fransisco | ||
O = MLopsHub | ||
OU = MlopsHub Dev | ||
CN = ${DOMAIN} | ||
[ req_ext ] | ||
subjectAltName = @alt_names | ||
[ alt_names ] | ||
DNS.1 = ${DOMAIN} | ||
DNS.2 = www.${DOMAIN} | ||
IP.1 = 192.168.1.5 | ||
IP.2 = 192.168.1.6 | ||
EOF | ||
|
||
# create CSR request using private key | ||
openssl req -new -key ${DOMAIN}.key -out ${DOMAIN}.csr -config csr.conf | ||
|
||
# Create a external config file for the certificate | ||
cat > cert.conf <<EOF | ||
authorityKeyIdentifier=keyid,issuer | ||
basicConstraints=CA:FALSE | ||
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment | ||
subjectAltName = @alt_names | ||
[alt_names] | ||
DNS.1 = ${DOMAIN} | ||
EOF | ||
|
||
# Create SSl with self signed CA | ||
openssl x509 -req \ | ||
-in ${DOMAIN}.csr \ | ||
-CA rootCA.crt -CAkey rootCA.key \ | ||
-CAcreateserial -out ${DOMAIN}.crt \ | ||
-days 365 \ | ||
-sha256 -extfile cert.conf |