Skip to content

Instantly share code, notes, and snippets.

@Alex4386
Last active December 18, 2022 08:22
Show Gist options
  • Save Alex4386/14dd68261243c95cf03104069a27de95 to your computer and use it in GitHub Desktop.
Save Alex4386/14dd68261243c95cf03104069a27de95 to your computer and use it in GitHub Desktop.
Generate ssl-cert like snakeoil certificate
#!/bin/bash
TARGET_CERT="/etc/ssl/certs/ssl-cert-snakeoil.pem"
TARGET_KEY="/etc/ssl/private/ssl-cert-snakeoil.key"
DHPARAM="/etc/ssl/certs/dhparam.pem"
C="KR"
ST="Seoul"
L="Yeongdeungpo-gu"
O="Alex4386 Inc."
OU="Digital Cryptography Team"
# Generating snakeoil
[[ -z $CN ]] && CN=$(hostname --short)
SUBJECT_STR=""
[[ -z $C ]] || SUBJECT_STR+="/C=${C}"
[[ -z $ST ]] || SUBJECT_STR+="/ST=${ST}"
[[ -z $L ]] || SUBJECT_STR+="/L=${L}"
[[ -z $O ]] || SUBJECT_STR+="/O=${O}"
[[ -z $OU ]] || SUBJECT_STR+="/OU=${OU}"
SUBJECT_STR+="/CN=${CN}"
openssl req -x509 -newkey rsa:4096 -keyout "${TARGET_KEY}" -nodes -out "${TARGET_CERT}" -subj "${SUBJECT_STR}" -sha256 -days 365
openssl dhparam -out "${DHPARAM}" 2048
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment