Created
January 27, 2017 02:57
-
-
Save libcrack/c69a212778c72b9e9827ae036d18a7d3 to your computer and use it in GitHub Desktop.
LetsEncrypt helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # root@libcrack.so | |
| # Fri Jan 27 03:46:04 CET 2017 | |
| error(){ printf "\e[0;31m${*}\e[0m\n"; } | |
| success(){ printf "\e[0;32m${*}\e[0m\n"; } | |
| if [ -z "$1" ]; then | |
| error "Usage: $0 host.domain.com" | |
| exit 1 | |
| fi | |
| CN="$1" | |
| CSR="/etc/ssl/acme/${CN}.csr" | |
| CRT="/etc/ssl/acme/${CN}.crt" | |
| KEY="/etc/ssl/acme/private/${CN}.key" | |
| ACCT_KEY="/etc/ssl/acme/private/letsencrypt.key" | |
| APACHE_DOCROOT="/var/apache2/htdocs" | |
| ACME_HOME="$APACHE_DOCROOT/.well-known/acme-challenge/" | |
| if [ ! -d "$APACHE_DOCROOT" ]; then | |
| error "Cannot find directory $APACHE_DOCROOT" | |
| exit 1 | |
| fi | |
| if [ ! -d "$ACME_HOME" ]; then | |
| error "Cannot find directory $ACME_HOME" | |
| exit 2 | |
| fi | |
| if [ ! -f "$ACCT_KEY" ]; then | |
| error "LetsEncrypt key not found: $ACCT_KEY" | |
| exit 3 | |
| fi | |
| if [ ! -f "$KEY" ]; then | |
| echo "[*] Creating KEY $KEY" | |
| openssl genrsa 4096 > "$KEY" | |
| else | |
| error "File already exists $KEY" | |
| exit 4 | |
| fi | |
| if [ ! -f "$CSR" ]; then | |
| echo "[*] Creating CSR $CSR" | |
| openssl req -new -sha256 -key "$KEY" -subj "/CN=$CN" > "$CSR" | |
| else | |
| error "File already exists $CSR" | |
| exit 5 | |
| fi | |
| if [ ! -f "$CRT" ]; then | |
| echo "[*] Registering CN $CN" | |
| acme-tiny --account-key "$ACCT_KEY" --csr "$CSR" --acme-dir "$ACME_ROOTDIR" > "$CRT" | |
| exit $? | |
| else | |
| error "File already exists $CRT" | |
| exit 6 | |
| fi | |
| #EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment