#!/bin/bash

DEMOCA="demoCA";

if  [ -d $DEMOCA ]; then
	echo "$DEMOCA exists, remove first before setup";
else 
	echo "$DEMOCA does not exist, creating";
	mkdir $DEMOCA
	mkdir $DEMOCA/certs
	mkdir $DEMOCA/crl
	touch $DEMOCA/index.txt
	mkdir $DEMOCA/newcerts
	mkdir $DEMOCA/requests
	echo "1000" > $DEMOCA/serial
	mkdir $DEMOCA/private


	# WHAT DOES THIS DO?
	openssl genrsa -des3 -out $DEMOCA/private/cakey.pem 1024
	openssl req -config openssl.conf -new -x509 -days 1001 -key $DEMOCA/private/cakey.pem -out $DEMOCA/cacert.pem
	# Look in the $DEMOCA directories and document the files that were created
	# The above does ...
	# The following files will be created in $DEMOCA
	# $DEMOCA/private/cakey.pem
	# 	YOUR DESCRIPTION OF THIS FILE BELOW, WHAT DOES IT CONTAIN, WHAT IS ITS ROLE IN THIS GAME
	# 	...
	# $DEMOCA/cacert.pem
	# 	YOUR DESCRIPTION OF THIS FILE BELOW, WHAT DOES IT CONTAIN, WHAT IS ITS ROLE IN THIS GAME
	# 	...
	# ...
	# 

	openssl x509 -in $DEMOCA/cacert.pem -noout -text
	# DOCUMENT ITS OUTPUT, DESCRIBE THE IMPORTANT PARTS OF YOUR x509 certificate
	# 
	
fi
