forked from ordenull/certificate-authority
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest-generate.sh
executable file
·50 lines (39 loc) · 1.41 KB
/
request-generate.sh
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
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source lib/functions.sh
load_config
verify_ca
if [ $# -lt 1 ]; then
echo "usage: $0 example.com"
exit 1;
fi
CN="$1"; shift
generate_usrcert_config $@
generate_openssl_config
mkdir -p "$DATA/$CN"
print_info "Generating a $BITS bit private key"
rm -f "$DATA/$CN/$CN.key"
# OpenSSL doesn't seem to update the random seed file automatically
# I am not sure if it's safe to use the same seed for the CA and all
# other RSA keys, so i'll leave it out for now
# -rand $DATA/private/random_seed
openssl genrsa -out "$DATA/$CN/$CN.key" $BITS >> $LOG 2>&1 || {
print_error "Unable to create an RSA private key for $CN"
exit 1;
}
print_info "Generating a certificate signing request"
SUBJECT="/CN=$CN/O=$ORGANIZATION/C=$COUNTRY"
rm -f "$DATA/$CN/$CN.csr"
openssl req -new -config "$DATA/generated.cnf" \
-subj "$SUBJECT" \
-key "$DATA/$CN/$CN.key" \
-out "$DATA/$CN/$CN.csr" >> $LOG 2>&1
if [ ! -e "$DATA/$CN/$CN.csr" ]; then
print_error "Unable to create a certificate signing request for $CN"
exit 1
fi
print_info "Generated CSR with the filename '$DATA/$CN/$CN.csr'"
print_info "If you now wish to sign it, use:"
print_info " No aliases: ./request-sign.sh $CN"
print_info " Web server alias: ./request-sign.sh $CN www.$CN"
print_info " Wildcard: ./request-sign.sh $CN *.$CN"