-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path01_generate_CA.sh
More file actions
executable file
·44 lines (33 loc) · 951 Bytes
/
Copy path01_generate_CA.sh
File metadata and controls
executable file
·44 lines (33 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
set -u
{
export LC_CTYPE=C
while getopts p:h opt
do
case "$opt" in
p) PROJECT_NAME="$OPTARG" ;; # Project Name
*)
echo >&2 "Usage: $0 -p projectname"
exit 1
;;
esac
done
: $PROJECT_NAME
[ -d "$PROJECT_NAME" ] && echo >&2 "FATAL: The project already exist" && exit 1
mkdir -p "$PROJECT_NAME"
cd "$PROJECT_NAME"
umask 377
< /dev/urandom tr -dc "+=\-%*\!&#':;{}()[]|^~\$_2-9T-Z" | head -c65 > ca.pass
# ca.key / ca.crt
openssl req \
-new -x509 -days ${CA_EXPIRE_DAYS:-"365"} \
-newkey rsa:4096 -keyout ca.key -passout file:ca.pass \
-out ca.crt -subj "/C=${CA_C:-"FR"}/L=${CA_L:-"Paris"}/O=${CA_O:-"Ekino"}/OU=${CA_OU:-"DevOps"}/CN=${CA_CN:-"$PROJECT_NAME"}"
umask 022
chmod 400 ca.key
chmod 444 ca.crt
echo
echo "The Certificate Authority files have been generated :"
echo " - key : '$PWD/ca.key'"
echo " - certificate : '$PWD/ca.crt' (self-signed) "
}