Benutzer-Werkzeuge

Webseiten-Werkzeuge


tachtler:let_s_encrypt_-_wildcard_zertifikat

Dies ist eine alte Version des Dokuments!


Let's Encrypt - Wildcard Zertifikat

Let's Encrypt ist eine kostenlose, automatisierte und offene Zertifizierungsstelle (CA), welche offiziell dem Nutzen der Öffentlichkeit dienen soll. Let's Encrypt ist ein Service der von der Internet Security Research Group (ISRG) zur Verfügung gestellt wird.

Let's Encrypt bietet öffentlich, jedermann digitalen Zertifikate an, um HTTPS (SSL / TLS) Verschlüsselung für Websites zu ermöglichen. Dies wird kostenlos und in einer möglichst benutzerfreundlichen Art und Weise angeboten. Let's Encrypt tut dies, weil Let's Encrypt offiziell ein sichereres und die Privatsphäre respektierendes Internet fördern möchte.

:!: WICHTIG - Das Ausstellen von Wildcard-Zertifikaten durch Let's Encrypt ist nur möglich, wenn Sie zeitnah DNS-Einträge auf dem für Ihre Domain zuständigen DNS-Server durchführen können !!!

Vorbereitung

Nachfolgend soll die Erstellung eines

  • privaten Schlüssels
  • Zertifikast-Requests
  • Zertifikats

für die Verwendung mit einem Web-Server durchgeführt werden.

Dabei soll das Zertifikat auch Aliase enthalten, so das dieses auch in mehreren virtuellen Hosts eingesetzt werden kann.

Die Erstellung soll durch Verwendung von nachfolgendem Skript durchgeführt werden:

welches unter oben stehendem externen Link heruntergeladen werden kann.

Herunterladen

Nachfolgendes Skript von Lukas Schauer soll dazu verwendet werden, um ohne Unterbrechung des Web-Server Betriebs Zertifikate ausstellen und verlängern zu können.

:!: HINWEIS - Beim Einsatz des Standard-Clients von Let's Encrypt mit dem Namen certbot sind gewisse Einschränkungen gegeben, bzw. dessen Konfiguration ist nicht so komfortabel.

Nachfolgender Befehl, wechselt in das Verzeichnis /opt, in dem auch hier alle weiteren Konfigurationen und Aktionen durchgeführt werden sollen, damit alle benötigten Komponenten später, zentral an einem Speicherort zu finden sind, was meiner Meinung nach die Handhabung insgesamt vereinfacht.

# cd /opt

Anschliessend kann mit nachfolgendem Befehl das Skript dehydrated unter Angabe eines Ziel-Verzeichnisses und eines abweichenden Namen, unter dem die heruntergeladene Datei gespeichert werden soll, heruntergeladen werden:

# wget -P /opt -O dehydrated.zip https://github.com/lukas2511/dehydrated/archive/master.zip
--2016-09-16 06:27:03--  https://github.com/lukas2511/dehydrated/archive/master.zip
Resolving github.com (github.com)... 192.30.253.113
Connecting to github.com (github.com)|192.30.253.113|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/lukas2511/dehydrated/zip/master [following]
--2016-09-16 06:27:03--  https://codeload.github.com/lukas2511/dehydrated/zip/master
Resolving codeload.github.com (codeload.github.com)... 192.30.253.120
Connecting to codeload.github.com (codeload.github.com)|192.30.253.120|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 75042 (73K) [application/zip]
Saving to: ‘dehydrated.zip’

100%[======================================>] 75,042       233KB/s   in 0.3s   

2016-09-16 06:27:04 (233 KB/s) - ‘dehydrated.zip’ saved [75042/75042]

Installation

Ab hier werden root-Rechte zur Ausführung der nachfolgenden Befehle benötigt. Um root zu werden geben Sie bitte folgenden Befehl ein:

$ su -
Password: 

Mit nachfolgendem Befehl, kann nun die zuvor heruntergeladene Archivdatei dehydrated.zip in das Verzeichnis /opt entpackt werden:

# unzip -d /opt dehydrated.zip 
Archive:  dehydrated.zip
caeed7d5e306c339e80b7e242db1b1ee98f9a6ca
   creating: /opt/dehydrated-master/
  inflating: /opt/dehydrated-master/.gitignore  
  inflating: /opt/dehydrated-master/.travis.yml  
  inflating: /opt/dehydrated-master/CHANGELOG  
  inflating: /opt/dehydrated-master/LICENSE  
  inflating: /opt/dehydrated-master/README.md  
  inflating: /opt/dehydrated-master/dehydrated  
   creating: /opt/dehydrated-master/docs/
  inflating: /opt/dehydrated-master/docs/dns-verification.md  
  inflating: /opt/dehydrated-master/docs/domains_txt.md  
  inflating: /opt/dehydrated-master/docs/ecc.md  
   creating: /opt/dehydrated-master/docs/examples/
  inflating: /opt/dehydrated-master/docs/examples/config  
  inflating: /opt/dehydrated-master/docs/examples/domains.txt  
  inflating: /opt/dehydrated-master/docs/examples/hook.sh  
  inflating: /opt/dehydrated-master/docs/hook_chain.md  
  inflating: /opt/dehydrated-master/docs/import-from-official-client.md  
  inflating: /opt/dehydrated-master/docs/logo.jpg  
  inflating: /opt/dehydrated-master/docs/per-certificate-config.md  
  inflating: /opt/dehydrated-master/docs/staging.md  
  inflating: /opt/dehydrated-master/docs/troubleshooting.md  
  inflating: /opt/dehydrated-master/docs/wellknown.md  
  inflating: /opt/dehydrated-master/test.sh

Anschliessend sollten nun nachfolgende Verzeichnisse und Dateien entstanden sein, was mit folgendem Befehl überprüft werden kann und in etwa die folgende Ausgabe erzeugen sollte:

# ls -l *
-rw-r--r-- 1 root root 75042 Sep 16 06:27 dehydrated.zip

dehydrated-master:
total 64
-rw-r--r-- 1 root root  1898 Sep 14 15:11 CHANGELOG
-rwxr-xr-x 1 root root 39373 Sep 14 15:11 dehydrated
drwxr-xr-x 3 root root  4096 Sep 14 15:11 docs
-rw-r--r-- 1 root root  1085 Sep 14 15:11 LICENSE
-rw-r--r-- 1 root root  3690 Sep 14 15:11 README.md
-rwxr-xr-x 1 root root  8004 Sep 14 15:11 test.sh

Als abschliessenden Schritt der Installation, soll nun ebenfalls unter dem Verzeichnis /opt eine Ordnerstruktur mit nachfolgendem Befehl angelegt werden:

# mkdir -p /opt/dehydrated-master/{alpn-certs,accounts,certs,etc,hook,work,www}

Abschliessend ist noch eine Änderung der Besitzrechte für eines der eben neu angelegten Verzeichnisse erforderlich, was mit nachfolgendem Befehl durchgeführt werden kann:

# chown -R apache:apache /opt/dehydrated-master/www

Mit nachfolgendem Befehl, kann nun überprüft werden, ob alle benötigten Verzeichnisse erstellt worden sind. Dies sollte in etwa wie folgt aussehen:

# ls -l *
-rw-r--r-- 1 root root 75042 Sep 16 06:27 dehydrated.zip

dehydrated-master:
total 64
drwxr-xr-x 2 root   root       6 Sep 16 08:21 accounts
drwxr-xr-x 2 root   root       6 Sep 16 08:21 alpn-certs
drwxr-xr-x 2 root   root       6 Sep 16 08:21 certs
drwxr-xr-x 2 root   root       6 Sep 16 08:21 chains
-rw-r--r-- 1 root   root    1898 Sep 14 15:11 CHANGELOG
-rwxr-xr-x 1 root   root   39373 Sep 14 15:11 dehydrated
drwxr-xr-x 3 root   root    4096 Sep 14 15:11 docs
drwxr-xr-x 2 root   root       6 Sep 16 08:21 etc
drwxr-xr-x 2 root   root       6 Sep 16 08:21 hook
-rw-r--r-- 1 root   root    1085 Sep 14 15:11 LICENSE
-rw-r--r-- 1 root   root    3690 Sep 14 15:11 README.md
-rwxr-xr-x 1 root   root    8004 Sep 14 15:11 test.sh
drwxr-xr-x 2 root   root       6 Sep 16 08:21 work
drwxr-xr-x 2 apache apache     6 Sep 16 08:21 www

Konfiguration: dehydrated

/opt/dehydrated-master/hook/hook.sh

Nachfolgendes shell-Script muss durch kopieren einer der in der Installation mitgelieferten Beispiel shell-Skript-Datei erstellt werden, was mit nachfolgendem Befehl durchgeführt werden kann:

# cp -a /opt/dehydrated-master/docs/examples/hook.sh /opt/dehydrated-master/etc/hook.sh

Anschließend muss das shell-Skript wie folgt angepasst werden, damit dieses, wie hier beschriebene shell-Skript und dessen Anpassungen bzw. Konfiguration, funktionsfähig ist:

(Komplette Konfigurationsdatei)

#!/usr/bin/env bash
 
deploy_challenge() {
    local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}"
 
    # This hook is called once for every domain that needs to be
    # validated, including any alternative names you may have listed.
    #
    # Parameters:
    # - DOMAIN
    #   The domain name (CN or subject alternative name) being
    #   validated.
    # - TOKEN_FILENAME
    #   The name of the file containing the token to be served for HTTP
    #   validation. Should be served by your web server as
    #   /.well-known/acme-challenge/${TOKEN_FILENAME}.
    # - TOKEN_VALUE
    #   The token value that needs to be served for validation. For DNS
    #   validation, this is what you want to put in the _acme-challenge
    #   TXT record. For HTTP validation it is the value that is expected
    #   be found in the $TOKEN_FILENAME file.
 
    # Simple example: Use nsupdate with local named
    # printf 'server 127.0.0.1\nupdate add _acme-challenge.%s 300 IN TXT "%s"\nsend\n' "${DOMAIN}" "${TOKEN_VALUE}" | nsupdate -k /var/run/named/session.key
 
    # Tachtler
    echo ""
    echo "Add the following to the zone definition of ${DOMAIN}:"
    echo "_acme-challenge.${DOMAIN}. 60 IN TXT \"${TOKEN_VALUE}\""
    echo ""
    echo -n "Press enter to continue..."
    read tmp
    echo ""
}
 
clean_challenge() {
    local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}"
 
    # This hook is called after attempting to validate each domain,
    # whether or not validation was successful. Here you can delete
    # files or DNS records that are no longer needed.
    #
    # The parameters are the same as for deploy_challenge.
 
    # Simple example: Use nsupdate with local named
    # printf 'server 127.0.0.1\nupdate delete _acme-challenge.%s TXT "%s"\nsend\n' "${DOMAIN}" "${TOKEN_VALUE}" | nsupdate -k /var/run/named/session.key
 
    # Tachtler
    echo ""
    echo "Now you can remove the following from the zone definition of ${DOMAIN}:"
    echo "_acme-challenge.${DOMAIN}. 60 IN TXT \"${TOKEN_VALUE}\""
    echo ""
    echo -n "Press enter to continue..."
    read tmp
    echo ""
}
 
deploy_cert() {
    local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}" TIMESTAMP="${6}"
 
    # This hook is called once for each certificate that has been
    # produced. Here you might, for instance, copy your new certificates
    # to service-specific locations and reload the service.
    #
    # Parameters:
    # - DOMAIN
    #   The primary domain name, i.e. the certificate common
    #   name (CN).
    # - KEYFILE
    #   The path of the file containing the private key.
    # - CERTFILE
    #   The path of the file containing the signed certificate.
    # - FULLCHAINFILE
    #   The path of the file containing the full certificate chain.
    # - CHAINFILE
    #   The path of the file containing the intermediate certificate(s).
    # - TIMESTAMP
    #   Timestamp when the specified certificate was created.
 
    # Simple example: Copy file to nginx config
    # cp "${KEYFILE}" "${FULLCHAINFILE}" /etc/nginx/ssl/; chown -R nginx: /etc/nginx/ssl
    # systemctl reload nginx
}
 
deploy_ocsp() {
    local DOMAIN="${1}" OCSPFILE="${2}" TIMESTAMP="${3}"
 
    # This hook is called once for each updated ocsp stapling file that has
    # been produced. Here you might, for instance, copy your new ocsp stapling
    # files to service-specific locations and reload the service.
    #
    # Parameters:
    # - DOMAIN
    #   The primary domain name, i.e. the certificate common
    #   name (CN).
    # - OCSPFILE
    #   The path of the ocsp stapling file
    # - TIMESTAMP
    #   Timestamp when the specified ocsp stapling file was created.
 
    # Simple example: Copy file to nginx config
    # cp "${OCSPFILE}" /etc/nginx/ssl/; chown -R nginx: /etc/nginx/ssl
    # systemctl reload nginx
}
 
 
unchanged_cert() {
    local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}"
 
    # This hook is called once for each certificate that is still
    # valid and therefore wasn't reissued.
    #
    # Parameters:
    # - DOMAIN
    #   The primary domain name, i.e. the certificate common
    #   name (CN).
    # - KEYFILE
    #   The path of the file containing the private key.
    # - CERTFILE
    #   The path of the file containing the signed certificate.
    # - FULLCHAINFILE
    #   The path of the file containing the full certificate chain.
    # - CHAINFILE
    #   The path of the file containing the intermediate certificate(s).
}
 
invalid_challenge() {
    local DOMAIN="${1}" RESPONSE="${2}"
 
    # This hook is called if the challenge response has failed, so domain
    # owners can be aware and act accordingly.
    #
    # Parameters:
    # - DOMAIN
    #   The primary domain name, i.e. the certificate common
    #   name (CN).
    # - RESPONSE
    #   The response that the verification server returned
 
    # Simple example: Send mail to root
    # printf "Subject: Validation of ${DOMAIN} failed!\n\nOh noez!" | sendmail root
}
 
request_failure() {
    local STATUSCODE="${1}" REASON="${2}" REQTYPE="${3}" HEADERS="${4}"
 
    # This hook is called when an HTTP request fails (e.g., when the ACME
    # server is busy, returns an error, etc). It will be called upon any
    # response code that does not start with '2'. Useful to alert admins
    # about problems with requests.
    #
    # Parameters:
    # - STATUSCODE
    #   The HTML status code that originated the error.
    # - REASON
    #   The specified reason for the error.
    # - REQTYPE
    #   The kind of request that was made (GET, POST...)
    # - HEADERS
    #   HTTP headers returned by the CA
 
    # Simple example: Send mail to root
    # printf "Subject: HTTP request failed failed!\n\nA http request failed with status ${STATUSCODE}!" | sendmail root
}
 
generate_csr() {
    local DOMAIN="${1}" CERTDIR="${2}" ALTNAMES="${3}"
 
    # This hook is called before any certificate signing operation takes place.
    # It can be used to generate or fetch a certificate signing request with external
    # tools.
    # The output should be just the cerificate signing request formatted as PEM.
    #
    # Parameters:
    # - DOMAIN
    #   The primary domain as specified in domains.txt. This does not need to
    #   match with the domains in the CSR, it's basically just the directory name.
    # - CERTDIR
    #   Certificate output directory for this particular certificate. Can be used
    #   for storing additional files.
    # - ALTNAMES
    #   All domain names for the current certificate as specified in domains.txt.
    #   Again, this doesn't need to match with the CSR, it's just there for convenience.
 
    # Simple example: Look for pre-generated CSRs
    # if [ -e "${CERTDIR}/pre-generated.csr" ]; then
    #   cat "${CERTDIR}/pre-generated.csr"
    # fi
}
 
startup_hook() {
  # This hook is called before the cron command to do some initial tasks
  # (e.g. starting a webserver).
 
  :
}
 
exit_hook() {
  # This hook is called at the end of the cron command and can be used to
  # do some final (cleanup or other) tasks.
 
  :
}
 
HANDLER="$1"; shift
if [[ "${HANDLER}" =~ ^(deploy_challenge|clean_challenge|deploy_cert|deploy_ocsp|unchanged_cert|invalid_challenge|request_failure|generate_csr|startup_hook|exit_hook)$ ]]; then
  "$HANDLER" "$@"
fi

Erklärungen:

Diese Website verwendet Cookies. Durch die Nutzung der Website stimmen Sie dem Speichern von Cookies auf Ihrem Computer zu. Außerdem bestätigen Sie, dass Sie unsere Datenschutzbestimmungen gelesen und verstanden haben. Wenn Sie nicht einverstanden sind, verlassen Sie die Website.Weitere Information
tachtler/let_s_encrypt_-_wildcard_zertifikat.1535611939.txt.gz · Zuletzt geändert: 2018/08/30 08:52 von klaus