Product SiteDocumentation Site

10.2. X.509-Zertifikate

Zertifikate sind ein wichtiger Baustein vieler Netzwerkdienste, die auf kryptografischen Protokollen aufbauen, wenn sie eine Art zentrale Authentifizierung benötigen.
Unter diesen Protokollen wurde SSL (Secure Socket Layer) von Netscape erfunden, um Verbindungen zu Webservern abzusichern. Es wurde später von der IETF unter der Abkürzung TLS (Transport Layer Security) zum Standard erhoben. Seither wurde TLS kontinuierlich weiterentwickelt und heute wird SSL aufgrund von verschiedenen Designfehlern als überholt angesehen.
Das TLS-Protokoll zielt in erster Linie darauf ab, Datenschutz und Datenintegrität zwischen zwei oder mehr kommunizierenden Computeranwendungen zu gewährleisten. Der häufigste Fall im Internet ist die Kommunikation zwischen einem Client (z.B. einem Webbrowser) und einem Server.
Für den Informationsaustausch wird ein Schlüsselpaar benötigt, bei dem es sich um einen öffentlichen Schlüssel handelt, der Informationen über die Identität des Eigentümers enthält und mit einem privaten Schlüssel übereinstimmt. Jedoch kann jeder ein Schlüsselpaar erstellen, eine beliebige Identität in ihm ablegen und so eine andere Identität vortäuschen. Ein Lösungskonzept beruht auf einer Certification Authority (CA, Zertifizierungsstelle), das durch den Standard X.509 formalisiert ist. Dieser Begriff bezeichnet eine Organisation, die ein vertrauenswürdiges Schlüsselpaar hat, das als Stammzertifikat bezeichnet wird. Dieses Zertifikat wird nur dazu benutzt, andere Zertifikate (Schlüsselpaare) zu signieren, nachdem die erforderlichen Schritte zur Überprüfung der Identität, die auf ihm abgelegt ist, unternommen worden sind. X.509-Anwendungen können dann vorgelegte Zertifikate überprüfen, wenn sie die vertrauenswürdigen Stammzertifikate kennen.
Sie können eine CA implementieren (wie in Abschnitt 10.2.2, „Public-Key-Infrastrultur: easy-rsa beschrieben), aber wenn Sie beabsichtigen, das Zertifikat für eine Website zu verwenden, müssen Sie sich auf eine vertrauenswürdige CA verlassen. Die Preise variieren erheblich, aber es ist möglich, hohe Sicherheit einzurichten, wenn man wenig bis gar kein Geld ausgibt.

10.2.1. Erstellen kostenloser vertrauenswürdiger Zertifikate

Viele Programme erstellen und verwenden standardmäßig Schlangenölzertifikate (siehe Seitenleiste SICHERHEIT Schlangenöl SSL-Zertifikate). Glücklicherweise bringt das certbot-Paket alles mit, was wir brauchen, um unsere eigenen vertrauenswürdigen Zertifikate zu erstellen, die von der "Lets Encrypt"-Initiative (siehe Seitenleiste KULTUR Die Let's Encrypt Initiative) zur Verfügung gestellt werden und die auch für Mail-Transport-Agenten (Postfix) und Mail-Zustellungs-Agenten (Dovecot, Cyrus usw.) verwendet werden können.
Die Falcot-Administratoren wollen lediglich ein Zertifikat für ihre Website erstellen, die auf Apache läuft. Es gibt ein praktisches Apache-Plugin für certbot, das die Apache-Konfiguration automatisch bearbeitet, um das erhaltene Zertifikat auszuliefern, sodass sie es nutzen können:
# apt install python-certbot-apache
[...]
# certbot --apache
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): admin@falcot.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o:  N

No names were found in your configuration files. Please enter in your domain
name(s) (comma and/or space separated)  (Enter 'c' to cancel): falcot.com

Obtaining a new certificate
Performing the following challenges:
http-01 challenge for falcot.com
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/000-default-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/000-default-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/000-default-le-ssl.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/000-default.conf to ssl vhost in /etc/apache2/sites-available/000-default-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://falcot.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=falcot.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/falcot.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/falcot.com/privkey.pem
   Your cert will expire on 2020-06-04. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le
Wenn Sie den Server während der Zertifikatserstellung lieber laufen lassen möchten, können Sie das Webroot-Plugin verwenden, um das Zertifikat mit den Argumenten certonly und --webroot abzurufen. Sie müssten einen --webroot-path (abgekürzt -w) angeben, der die zugestellten Dateien enthalten sollte. Der Befehl sieht wie folgt aus:
# certbot certonly --webroot -w /var/www/html -d www.DOMÄNE.com -d DOMÄNE.com
Sie müssen alle Dienste neu starten, die die Zertifikate, die Sie erstellt haben, nutzen.
Die erstellten Zertifikate sind sogenannte kurzlebige Zertifikate, die 90 Tage gültig sind und daher alle drei Monate mit dem Befehl certbot renew erneuert werden müssen. Wir sollten jedoch nicht jedes Zertifikat automatisch statt manuell erneuern. Ein grundlegender Cron-Job ist durch certbot in /etc/cron.d/certbot enthalten. Um sicherzustellen, dass Zertifikate automatisch erneuert werden, können Sie certbot renew --dry-run ausführen.

10.2.2. Public-Key-Infrastrultur: easy-rsa

Es ist auch möglich, unsere eigene CA zu erstellen, wofür wir den RSA-Algorithmus verwenden werden, der in der Public-Key-Kryptografie weit verbreitet ist. Er umfasst ein "Schlüsselpaar", das aus einem privaten und einem öffentlichen Schlüssel besteht. Die beiden Schlüssel sind durch ihre mathematischen Eigenschaften derart miteinander verbunden, dass folgender Vorgang möglich ist: Eine Nachricht, die mit dem öffentlichen Schlüssel verschlüsselt wurde, kann nur von jemandem entschlüsselt werden, der den privaten Schlüssel kennt. Dies stellt Vertraulichkeit her. In umgekehrter Richtung kann eine mit dem privaten Schlüssel verschlüsselte Nachricht, von jedem entschlüsselt werden, der den öffentlichen Schlüssel kennt. Dies authentifiziert die Nachricht, da sie nur der Inhaber des privaten Schlüssels erstellt haben kann. Dies führt in Verbindung mit einer digitalen Hash-Funktion (MD5, SHA1 oder einer neueren Variante) zu einem Signaturverfahren, das auf jede Nachricht angewendet werden kann.
Da öffentliche Zertifizierungstellen Zertifikate nur gegen eine (hohe) Gebühr ausstellen, können private Zertifizierungsstellen auch innerhalb eines Unternehmens eingerichtet werden. Das easy-rsa Paket enthält Tools, die eine X.509 Zertifizierungs-Infrastruktur bereitstellen. Es besteht aus einem Satz von Skripten, die den Befehl openssl verwenden.
Die Administratoren der Falcot Corp. verwenden dieses Hilfsprogramm, um die erforderlichen Zertifikate sowohl für den Server, als auch die Clients zu erstellen. Dies ermöglicht eine ähnliche Konfiguration aller Clients, da sie nur so eingerichtet werden müssen, dass sie Zertifikaten von Falcots lokaler Zertifizierungsstelle vertrauen. Für diese Stelle wird das erste Zertifikat erstellt. Hierzu erstellen Administratoren das Verzeichnis mit den benötigten Dateien für die CA an einen passenderen Ort; vorzugsweise auf einen nicht mit dem Netzwerk verbundenen Rechner um so das Risiko des Schlüsseldiebstahls zu verringern.
$ make-cadir pki-falcot
$ cd pki-falcot
Sie speichern dann die erforderlichen Parameter in der Datei vars, die auskommentiert und editiert werden kann:
$ vim vars
$ grep EASYRSA vars
if [ -z "$EASYRSA_CALLER" ]; then
# easyrsa.  More specific variables for specific files (e.g., EASYRSA_SSL_CONF)
#set_var EASYRSA	"${0%/*}"
#set_var EASYRSA_OPENSSL	"openssl"
#set_var EASYRSA_OPENSSL	"C:/Program Files/OpenSSL-Win32/bin/openssl.exe"
#set_var EASYRSA_PKI		"$PWD/pki"
#set_var EASYRSA_DN	"cn_only"
#set_var EASYRSA_REQ_COUNTRY	"FR"
#set_var EASYRSA_REQ_PROVINCE	"Loire"
#set_var EASYRSA_REQ_CITY	"Saint-Étienne"
#set_var EASYRSA_REQ_ORG	"Falcot Corp"
#set_var EASYRSA_REQ_EMAIL	"admin@falcot.com"
#set_var EASYRSA_REQ_OU		"Certificate authority"
#set_var EASYRSA_KEY_SIZE	2048
#set_var EASYRSA_ALGO		rsa
#set_var EASYRSA_CURVE		secp384r1
#set_var EASYRSA_CA_EXPIRE	3650
#set_var EASYRSA_CERT_EXPIRE	1080
#set_var EASYRSA_CERT_RENEW	30
#set_var EASYRSA_CRL_DAYS	180
#set_var EASYRSA_NS_SUPPORT	"no"
#set_var EASYRSA_NS_COMMENT	"Easy-RSA Generated Certificate"
#set_var EASYRSA_TEMP_FILE	"$EASYRSA_PKI/extensions.temp"
# when undefined here, default behaviour is to look in $EASYRSA_PKI first, then
# fallback to $EASYRSA for the 'x509-types' dir.  You may override this
#set_var EASYRSA_EXT_DIR	"$EASYRSA/x509-types"
# EASYRSA_PKI or EASYRSA dir (in that order.) NOTE that this file is Easy-RSA
#set_var EASYRSA_SSL_CONF	"$EASYRSA/openssl-easyrsa.cnf"
#set_var EASYRSA_REQ_CN		"ChangeMe"
#set_var EASYRSA_DIGEST		"sha256"
#set_var EASYRSA_BATCH		""
$ 
Nun bereiten wir das Public-Key-Infrastrukturverzeichnis mit folgendem Befehl vor:
$ ./easyrsa init-pki

Note: using Easy-RSA configuration from: ./vars

init-pki complete; you may now create a CA or requests.
Your newly created PKI dir is: /home/roland/pki-falcot/pki
Der nächste Schritt ist die Erstellung des Schlüsselpaares der CA selbst (die beiden Teile des Schlüsselpaares werden während dieses Schrittes unter pki/ca.crt und pki/private/ca.key gespeichert). Wir können die Option nopass hinzufügen, um die Eingabe eines Passworts bei jeder Verwendung des privaten Schlüssels zu vermeiden:
$ ./easyrsa build-ca nopass

Note: using Easy-RSA configuration from: ./vars

Using SSL: openssl OpenSSL 1.1.1b  26 Feb 2019
Generating RSA private key, 2048 bit long modulus (2 primes)
......................................................................................+++++
......................+++++
e is 65537 (0x010001)
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Common Name (eg: your user, host, or server name) [Easy-RSA CA]:

CA creation complete and you may now import and sign cert requests.
Your new CA certificate file for publishing is at:
/home/roland/pki-falcot/pki/ca.crt

Das Zertifikat kann jetzt erstellt werden, ebenso wie die Diffie-Hellman-Parameter, die für die Serverseite einer SSL/TLS-Verbindung erforderlich sind. Sie wollen es für einen VPN-Server (siehe Abschnitt Abschnitt 10.3, „Virtual Private Network“) verwenden, der durch den DNS-Namen vpn.falcot.com identifiziert wird; dieser Name wird für die generierten Schlüsseldateien wiederverwendet (keys/vpn.falcot.com.crt für das öffentliche Zertifikat, keys/vpn.falcot.com.key für den privaten Schlüssel):
$ ./easyrsa gen-req vpn.falcot.com nopass
Note: using Easy-RSA configuration from: ./vars

Using SSL: openssl OpenSSL 1.1.1b  26 Feb 2019
Generating a RSA private key
.................................................................................+++++
........+++++
writing new private key to '/home/roland/pki-falcot/pki/private/vpn.falcot.com.key.E5c3RGJBUd'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Common Name (eg: your user, host, or server name) [vpn.falcot.com]:

Keypair and certificate request completed. Your files are:
req: /home/roland/pki-falcot/pki/reqs/vpn.falcot.com.req
key: /home/roland/pki-falcot/pki/private/vpn.falcot.com.key

$ ./easyrsa sign-req server vpn.falcot.com

Note: using Easy-RSA configuration from: ./vars

Using SSL: openssl OpenSSL 1.1.1b  26 Feb 2019


You are about to sign the following certificate.
Please check over the details shown below for accuracy. Note that this request
has not been cryptographically verified. Please be sure it came from a trusted
source or that you have verified the request checksum with the sender.

Request subject, to be signed as a server certificate for 1080 days:

subject=
    commonName                = vpn.falcot.com


Type the word 'yes' to continue, or any other input to abort.
  Confirm request details: yes
Using configuration from /home/roland/pki-falcot/pki/safessl-easyrsa.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName            :ASN.1 12:'vpn.falcot.com'
Certificate is to be certified until Jun 14 10:44:44 2022 GMT (1080 days)

Write out database with 1 new entries
Data Base Updated

Certificate created at: /home/roland/pki-falcot/pki/issued/vpn.falcot.com.crt

$ ./easyrsa gen-dh

Note: using Easy-RSA configuration from: ./vars

Using SSL: openssl OpenSSL 1.1.1b  26 Feb 2019
Generating DH parameters, 2048 bit long safe prime, generator 2
This is going to take a long time
[…]
DH parameters of size 2048 created at /home/roland/pki-falcot/pki/dh.pem

Der folgende Schritt erstellt Zertifikate für die VPN-Clients; für jeden Rechner oder jede Person, der das VPN nutzen darf, ist ein eigenes Zertifikat erforderlich:
$ ./easyrsa build-client-full JoeSmith nopass

Note: using Easy-RSA configuration from: ./vars

Using SSL: openssl OpenSSL 1.1.1d  10 Sep 2019
Generating a RSA private key
.......................................................+++++
...........................+++++
writing new private key to '/root/pki-falcot/pki/private/JoeSmith.key.Tgr8kk0a6a'
-----
Using configuration from /root/pki-falcot/pki/safessl-easyrsa.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName            :ASN.1 12:'JoeSmith'
Certificate is to be certified until Feb 20 04:52:43 2023 GMT (1080 days)

Write out database with 1 new entries
Data Base Updated