|
3 | 3 | set -e |
4 | 4 | cd "$(dirname "$0")" |
5 | 5 |
|
| 6 | +# Ensure certs directory exists |
| 7 | +mkdir -p certs |
| 8 | + |
6 | 9 | if [[ -f "certs/key.pem" ]] || [[ -f "certs/cert.pem" ]]; then |
7 | 10 | echo "Certificate already exists." |
8 | 11 | exit 0 |
9 | 12 | fi |
10 | 13 |
|
11 | | -if ! type 2>&1 >/dev/null openssl ; then |
12 | | - echo >&2 "Error: openssl not found!" |
| 14 | +echo "Creating certificates..." |
| 15 | + |
| 16 | +# Check if mkcert is available |
| 17 | +if type mkcert >/dev/null 2>&1; then |
| 18 | + echo "Using mkcert to generate trusted certificates..." |
| 19 | + |
| 20 | + # Install local CA if not already installed |
| 21 | + mkcert -install >/dev/null 2>&1 || true |
| 22 | + |
| 23 | + # Generate certificate for localhost and common local addresses |
| 24 | + mkcert -cert-file certs/cert.pem -key-file certs/key.pem \ |
| 25 | + localhost 127.0.0.1 ::1 \ |
| 26 | + "*.localhost" \ |
| 27 | + "localhost.localdomain" \ |
| 28 | + "*.localhost.localdomain" |
| 29 | + |
| 30 | + echo "Certificates created with mkcert (automatically trusted in browsers)" |
| 31 | + |
| 32 | +elif type openssl >/dev/null 2>&1; then |
| 33 | + echo "mkcert not found, falling back to openssl..." |
| 34 | + echo "You will need to accept a security exception for the" |
| 35 | + echo "generated certificate in your browser manually." |
| 36 | + |
| 37 | + openssl req -x509 -newkey rsa:4096 -nodes -days 3650 \ |
| 38 | + -subj "/C=DE/O=Selfsigned Test/CN=localhost" \ |
| 39 | + -keyout certs/key.pem -out certs/cert.pem |
| 40 | + |
| 41 | + echo "Self-signed certificate created with openssl" |
| 42 | + |
| 43 | +else |
| 44 | + echo >&2 "Error: Neither mkcert nor openssl found!" |
| 45 | + echo >&2 "Please install either mkcert (recommended) or openssl." |
| 46 | + echo >&2 "" |
| 47 | + echo >&2 "To install mkcert:" |
| 48 | + echo >&2 " - macOS: brew install mkcert" |
| 49 | + echo >&2 " - Linux: Check https://github.com/FiloSottile/mkcert#installation" |
| 50 | + echo >&2 " - Windows: choco install mkcert or scoop install mkcert" |
13 | 51 | exit 1 |
14 | 52 | fi |
15 | 53 |
|
16 | | -echo "Creating certificates..." |
17 | | -echo "You will need to accept an security exception for the" |
18 | | -echo "generated certificate in your browser manually." |
19 | | -openssl req -x509 -newkey rsa:4096 -nodes -days 3650 \ |
20 | | - -subj "/C=DE/O=Selfsigned Test/CN=localhost" \ |
21 | | - -keyout certs/key.pem -out certs/cert.pem |
22 | 54 | echo "done" |
0 commit comments