-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathssl-create-self-signed-ca
executable file
·88 lines (74 loc) · 1.79 KB
/
ssl-create-self-signed-ca
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
# More safety, by turning some bugs into errors.
set -euCo pipefail
IFS=$'\n\t'
# default values
daysValid="$((10 * 365))"
# arguments parsing
options=hd:
longOptions=hdays:
! parsed=$(getopt --options=$options --longoptions=$longOptions --name "$0" -- "$@")
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
exit 2
fi
eval set -- "$parsed"
while true; do
case "$1" in
-h|--help)
echo "Create self signed certificate"
echo "$0 [-d <days>] <ca-name>"
echo ""
echo "-d | --days file - numer of days"
exit 1
;;
-d|--days)
daysValid="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "Programming error"
exit 3
;;
esac
done
if [[ $# -ne 1 ]]; then
echo "$0: CA name required"
echo ""
echo "Use -h to see more info"
exit 4
fi
caName="$1"
configFile="$caName.config"
if ! [[ -r "$configFile" ]]; then
cat > "$configFile" <<-EOF
[ req ]
default_bits = 2048
distinguished_name = req_distinguished_name
attributes = req_attributes
prompt = no
output_password =
utf8 = yes
[ req_distinguished_name ]
C = Country
ST = State or Province
L = Locality
O = Organization Name
OU = Organizational Unit Name
CN = Common Name
emailAddress = [email protected]
[ req_attributes ]
EOF
echo >&2 "Created '$configFile'. Please fill it with required values and rerun the command"
exit 0
fi
openssl req -new \
-x509 \
-config "$configFile" \
-nodes \
-days "$daysValid" \
-newkey rsa \
-keyout "$caName-key.pem" > "$caName-cert.pem"