forked from OpenSlides/openslides-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-localhost-cert.sh
More file actions
executable file
·57 lines (44 loc) · 1.81 KB
/
make-localhost-cert.sh
File metadata and controls
executable file
·57 lines (44 loc) · 1.81 KB
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
#!/bin/bash
set -e
cd "$(dirname "$0")"
# Ensure certs directory exists
mkdir -p certs
if [[ -f "certs/key.pem" ]] || [[ -f "certs/cert.pem" ]]; then
echo "Certificate already exists."
exit 0
fi
echo "Creating certificates..."
# Check if mkcert is available
if type mkcert >/dev/null 2>&1; then
echo "Using mkcert to generate trusted certificates..."
# Install local CA if not already installed
mkcert -install >/dev/null 2>&1 || true
# Generate certificate for localhost and common local addresses
mkcert -cert-file certs/cert.pem -key-file certs/key.pem \
localhost 127.0.0.1 ::1 \
"*.localhost" \
"localhost.localdomain" \
"*.localhost.localdomain"
echo "Certificates created with mkcert."
echo "If the certs were generated on a different machine than the one running the"
echo "browser to access the endpoint, you will first have to copy mkcerts local"
echo "rootCA there and add it to the trust store."
elif type openssl >/dev/null 2>&1; then
echo "mkcert not found, falling back to openssl..."
echo "You will need to accept a security exception for the"
echo "generated certificate in your browser manually."
openssl req -x509 -newkey rsa:4096 -nodes -days 3650 \
-subj "/C=DE/O=Selfsigned Test/CN=localhost" \
-keyout certs/key.pem -out certs/cert.pem
echo "Self-signed certificate created with openssl"
else
echo >&2 "Error: Neither mkcert nor openssl found!"
echo >&2 "Please install either mkcert (recommended) or openssl."
echo >&2 ""
echo >&2 "To install mkcert:"
echo >&2 " - Linux: Check https://github.com/FiloSottile/mkcert#installation"
echo >&2 " - macOS: brew install mkcert"
echo >&2 " - Windows: choco install mkcert or scoop install mkcert"
exit 1
fi
echo "done"