-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcert.sh
31 lines (25 loc) · 780 Bytes
/
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
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
# Creates a self-signed wildcard cert for local test and dev
# EXAMPLE: ./cert.sh something.com
# three files are created:
# something.com.key - Secret key good for proxy configs
# something.com.crt - Public cert good for proxy configs
# something.com.pem - Combo of those two good for browser/OS import
DOMAIN_NAME=$1
openssl req \
-newkey rsa:2048 \
-x509 \
-nodes \
-keyout "$DOMAIN_NAME.key" \
-new \
-out "$DOMAIN_NAME.crt" \
-subj "/CN=*.$DOMAIN_NAME" \
-reqexts SAN \
-extensions SAN \
-config <(cat /etc/ssl/openssl.cnf \
<(printf "[SAN]\nsubjectAltName=DNS:*.%s, DNS:%s" "$DOMAIN_NAME" "$DOMAIN_NAME")) \
-sha256 \
-days 3650
cat "$DOMAIN_NAME.crt" "$DOMAIN_NAME.key" > "$DOMAIN_NAME.pem"