Skip to content

Commit 502749a

Browse files
author
Serghey Rodin
committed
fix for password protected ssl keys
1 parent 1ed58a9 commit 502749a

File tree

1 file changed

+14
-27
lines changed

1 file changed

+14
-27
lines changed

func/domain.sh

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ get_web_config_lines() {
237237
fi
238238

239239
vhost_lines=$(grep -niF "name $domain_idn" $2)
240-
vhost_lines=$(echo "$vhost_lines" |egrep "$domain_idn$|$domain_idn ")
240+
vhost_lines=$(echo "$vhost_lines" |egrep "$domain_idn($| |;)") #"
241241
vhost_lines=$(echo "$vhost_lines" |cut -f 1 -d :)
242242
if [ -z "$vhost_lines" ]; then
243243
check_result $E_PARSING "can't parse config $2"
@@ -281,29 +281,21 @@ del_web_config() {
281281
# SSL certificate verification
282282
is_web_domain_cert_valid() {
283283
if [ ! -e "$ssl_dir/$domain.crt" ]; then
284-
echo "Error: $ssl_dir/$domain.crt not found"
285-
log_event "$E_NOTEXIST" "$ARGUMENTS"
286-
exit $E_NOTEXIST
284+
check_result $E_NOTEXIST "$ssl_dir/$domain.crt not found"
287285
fi
288286

289287
if [ ! -e "$ssl_dir/$domain.key" ]; then
290-
echo "Error: $ssl_dir/$domain.key not found"
291-
log_event "$E_NOTEXIST" "$ARGUMENTS"
292-
exit $E_NOTEXIST
288+
check_result $E_NOTEXIST "$ssl_dir/$domain.key not found"
293289
fi
294290

295291
crt_vrf=$(openssl verify $ssl_dir/$domain.crt 2>&1)
296-
if [ ! -z "$(echo $crt_vrf | grep 'unable to load')" ]; then
297-
echo "Error: SSL Certificate is not valid"
298-
log_event "$E_INVALID" "$ARGUMENTS"
299-
exit $E_INVALID
292+
if [ ! -z "$(echo $crt_vrf |grep 'unable to load')" ]; then
293+
check_result $E_INVALID "SSL Certificate is not valid"
300294
fi
301295

302-
if [ ! -z "$(echo $crt_vrf | grep 'unable to get local issuer')" ]; then
296+
if [ ! -z "$(echo $crt_vrf |grep 'unable to get local issuer')" ]; then
303297
if [ ! -e "$ssl_dir/$domain.ca" ]; then
304-
echo "Error: Certificate Authority not found"
305-
log_event "$E_NOTEXIST" "$ARGUMENTS"
306-
exit $E_NOTEXIST
298+
check_result $E_NOTEXIST "Certificate Authority not found"
307299
fi
308300
fi
309301

@@ -313,17 +305,16 @@ is_web_domain_cert_valid() {
313305
s2=$(openssl x509 -text -in $ssl_dir/$domain.ca 2>/dev/null)
314306
s2=$(echo "$s2" |grep Subject |awk -F = '{print $6}' |head -n1)
315307
if [ "$s1" != "$s2" ]; then
316-
echo "Error: SSL intermediate chain is not valid"
317-
log_event "$E_NOTEXIST" "$ARGUMENTS"
318-
exit $E_NOTEXIST
308+
check_result $E_NOTEXIST "SSL intermediate chain is not valid"
319309
fi
320310
fi
321311

322-
key_vrf=$(grep 'PRIVATE KEY' $ssl_dir/$domain.key | wc -l)
312+
key_vrf=$(grep 'PRIVATE KEY' $ssl_dir/$domain.key |wc -l)
323313
if [ "$key_vrf" -ne 2 ]; then
324-
echo "Error: SSL Key is not valid"
325-
log_event "$E_INVALID" "$ARGUMENTS"
326-
exit $E_INVALID
314+
check_result $E_INVALID "SSL Key is not valid"
315+
fi
316+
if [ ! -z "$(grep 'ENCRYPTED' $ssl_dir/$domain.key)" ]; then
317+
check_result $E_FORBIDEN "SSL Key is protected (remove pass_phrase)"
327318
fi
328319

329320
openssl s_server -quiet -cert $ssl_dir/$domain.crt \
@@ -332,11 +323,7 @@ is_web_domain_cert_valid() {
332323
sleep 0.5
333324
disown &> /dev/null
334325
kill $pid &> /dev/null
335-
if [ "$?" -ne '0' ]; then
336-
echo "Error: ssl certificate key pair is not valid"
337-
log_event "$E_INVALID" "$ARGUMENTS"
338-
exit $E_INVALID
339-
fi
326+
check_result $? "ssl certificate key pair is not valid" $E_INVALID
340327
}
341328

342329

0 commit comments

Comments
 (0)