| 1 |
#!/bin/bash |
| 2 |
# Generate self-signed certificates for ejabberd TLS testing. |
| 3 |
# These certificates are for testing only. |
| 4 |
|
| 5 |
set -euo pipefail |
| 6 |
|
| 7 |
CERTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 8 |
|
| 9 |
echo "Generating self-signed certificates for XMPP TLS testing..." |
| 10 |
|
| 11 |
openssl genrsa -out "$CERTS_DIR/ca.key" 2048 |
| 12 |
openssl req -new -x509 -days 3650 -key "$CERTS_DIR/ca.key" \ |
| 13 |
-out "$CERTS_DIR/ca.pem" \ |
| 14 |
-subj "/CN=shoutrrr-xmpp-test-ca/O=Shoutrrr/C=US" |
| 15 |
|
| 16 |
openssl genrsa -out "$CERTS_DIR/key.pem" 2048 |
| 17 |
|
| 18 |
cat > "$CERTS_DIR/server.cnf" <<EOF |
| 19 |
[req] |
| 20 |
default_bits = 2048 |
| 21 |
prompt = no |
| 22 |
default_md = sha256 |
| 23 |
distinguished_name = dn |
| 24 |
req_extensions = v3_req |
| 25 |
|
| 26 |
[dn] |
| 27 |
C = US |
| 28 |
O = Shoutrrr |
| 29 |
CN = localhost |
| 30 |
|
| 31 |
[v3_req] |
| 32 |
subjectAltName = @alt_names |
| 33 |
|
| 34 |
[alt_names] |
| 35 |
DNS.1 = localhost |
| 36 |
DNS.2 = ejabberd |
| 37 |
IP.1 = 127.0.0.1 |
| 38 |
IP.2 = 0.0.0.0 |
| 39 |
EOF |
| 40 |
|
| 41 |
openssl req -new -key "$CERTS_DIR/key.pem" \ |
| 42 |
-out "$CERTS_DIR/server.csr" \ |
| 43 |
-config "$CERTS_DIR/server.cnf" |
| 44 |
|
| 45 |
openssl x509 -req -days 3650 \ |
| 46 |
-in "$CERTS_DIR/server.csr" \ |
| 47 |
-CA "$CERTS_DIR/ca.pem" \ |
| 48 |
-CAkey "$CERTS_DIR/ca.key" \ |
| 49 |
-CAcreateserial \ |
| 50 |
-out "$CERTS_DIR/cert.pem" \ |
| 51 |
-extensions v3_req \ |
| 52 |
-extfile "$CERTS_DIR/server.cnf" |
| 53 |
|
| 54 |
cat "$CERTS_DIR/cert.pem" "$CERTS_DIR/key.pem" > "$CERTS_DIR/server.pem" |
| 55 |
|
| 56 |
chmod 644 "$CERTS_DIR/ca.pem" "$CERTS_DIR/cert.pem" |
| 57 |
chmod 600 "$CERTS_DIR/key.pem" "$CERTS_DIR/server.pem" |
| 58 |
rm -f "$CERTS_DIR/ca.key" "$CERTS_DIR/server.csr" "$CERTS_DIR/server.cnf" "$CERTS_DIR/ca.srl" |
| 59 |
|
| 60 |
echo "Certificates generated successfully." |