@@ -43,7 +43,7 @@ SERVERNAME=nsd
43
43
CLIENTNAME=nsd-control
44
44
45
45
# validity period for certificates
46
- DAYS=3650
46
+ DAYS=7200
47
47
48
48
# size of keys in bits
49
49
BITS=3072
@@ -86,9 +86,7 @@ fatal() {
86
86
usage () {
87
87
cat << EOF
88
88
usage: $0 OPTIONS
89
-
90
89
OPTIONS
91
-
92
90
-d <dir> used directory to store keys and certificates (default: $DESTDIR )
93
91
-h show help notice
94
92
-r recreate certificates
@@ -99,7 +97,7 @@ OPTIND=1
99
97
while getopts ' d:hr' arg; do
100
98
case " $arg " in
101
99
d) DESTDIR=" $OPTARG " ;;
102
- h) usage; exit 0 ;;
100
+ h) usage; exit 1 ;;
103
101
r) RECREATE=1 ;;
104
102
? ) fatal " '$arg ' unknown option" ;;
105
103
esac
@@ -122,13 +120,19 @@ if [ ! -f "$SVR_BASE.key" ]; then
122
120
fi
123
121
124
122
cat > server.cnf << EOF
123
+ [req]
125
124
default_bits=$BITS
126
125
default_md=$HASH
127
126
prompt=no
128
127
distinguished_name=req_distinguished_name
129
-
128
+ x509_extensions=v3_ca
130
129
[req_distinguished_name]
131
130
commonName=$SERVERNAME
131
+ [v3_ca]
132
+ subjectKeyIdentifier=hash
133
+ authorityKeyIdentifier=keyid:always,issuer:always
134
+ basicConstraints=critical,CA:TRUE,pathlen:0
135
+ subjectAltName=DNS:$SERVERNAME
132
136
EOF
133
137
134
138
[ -f server.cnf ] || fatal " cannot create openssl configuration"
@@ -159,9 +163,12 @@ default_bits=$BITS
159
163
default_md=$HASH
160
164
prompt=no
161
165
distinguished_name=req_distinguished_name
162
-
166
+ req_extensions=v3_req
163
167
[req_distinguished_name]
164
168
commonName=$CLIENTNAME
169
+ [v3_req]
170
+ basicConstraints=critical,CA:FALSE
171
+ subjectAltName=DNS:$CLIENTNAME
165
172
EOF
166
173
167
174
[ -f client.cnf ] || fatal " cannot create openssl configuration"
@@ -183,6 +190,8 @@ if [ ! -f "$CTL_BASE.pem" -o $RECREATE -eq 1 ]; then
183
190
-CAkey " $SVR_BASE .key" \
184
191
-CAcreateserial \
185
192
-$HASH \
193
+ -extfile client.cnf \
194
+ -extensions v3_req \
186
195
-out " $CTL_BASE .pem"
187
196
188
197
[ ! -f " CTL_BASE.pem" ] || fatal " cannot create signed client certificate"
@@ -199,7 +208,6 @@ cleanup
199
208
200
209
echo " Setup success. Certificates created. Enable in nsd.conf file to use"
201
210
202
-
203
211
# create trusted usage pem
204
212
# openssl x509 -in $CTL_BASE.pem -addtrust clientAuth -out $CTL_BASE"_trust.pem"
205
213
0 commit comments