-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_self_signed_cert.sh
executable file
·48 lines (35 loc) · 1.09 KB
/
delete_self_signed_cert.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
#!/usr/bin/env sh
# SPDX-FileCopyrightText: © 2024 Sebastian Davids <[email protected]>
# SPDX-License-Identifier: Apache-2.0
set -eu
readonly base_dir="${1:-$PWD}"
readonly host_name="${2:-localhost}"
readonly key_path="${base_dir}/key.pem"
readonly cert_path="${base_dir}/cert.pem"
if [ "$(uname)" = 'Darwin' ]; then
set +e
# https://ss64.com/mac/security-find-cert.html
security find-certificate -c "${host_name}" 1>/dev/null 2>/dev/null
found=$?
set -e
if [ "${found}" = 0 ]; then
login_keychain="$(security login-keychain | xargs)"
readonly login_keychain
echo "Removing '${host_name}' certificate from keychain ${login_keychain} ..."
# https://ss64.com/mac/security-delete-cert.html
security delete-certificate -c "${host_name}" -t "${login_keychain}"
fi
fi
if [ -f "${key_path}" ]; then
rm -f "${key_path}"
fi
if [ -f "${cert_path}" ]; then
rm -f "${cert_path}"
fi
# delete empty certs dir if not $PWD
if [ -d "${base_dir}" ] \
&& [ "${base_dir}" != "$PWD" ] \
&& [ "${base_dir}" != '.' ] \
&& [ -z "$(ls -A "${base_dir}")" ]; then
rmdir "${base_dir}"
fi