Dieses Howto führt euch Schritt für Schritt durch die Erzeugung eines SSL Zertifikates und zeigt dann auf wie man diverse Dienste (Apache, Courier, Postfix, ProFTPD) mit SSL schützen kann.
[Dank für den SSL-CA-Teil geht an http://fra.nksteidl.de/Erinnerungen/OpenSSL.php]
Zuerst müssen wir das openssl Paket installieren:
<cli> apt-get install openssl </cli>
Danach öffnen wir die openssl Konfigurationsdatei unter /etc/ssl/openssl.cnf und passen es wie folgt an (Das Beispiel geht von der CA (Zertifizierungsausteller) mit dem Namen “RootCA” aus. Man kann dies jedoch beliebig umbenennen):
<cli> Line 32: default_ca = RootCA Line 35: [ RootCA ] Line 37: dir = /root/RootCA Line 41: unique_subject = no # only if you need this Line 70: default_md = md5 </cli>
Wenn wir wollen können wir die Werte in dem [req_destinquished_name] Bereich an unsere Sprache anpassen.: <cli> [ req_distinguished_name ] countryName = Land (2stelliger Code) countryName_default = DE countryName_min = 2 countryName_max = 2
stateOrProvinceName = Bundesland (voller Name) stateOrProvinceName_default = MeinBundesland
localityName = Ort, Stadt localityName_default = MeineStadt
0.organizationName = Firmenname 0.organizationName_default = MeineFirma
# Dies wird normalerweise nicht gebraucht, aber wir können es trotzdem nutzen #1.organizationName = Second Organization Name (eg, company) #1.organizationName_default = World Wide Web Pty Ltd
organizationalUnitName = Abteilung #organizationalUnitName_default =
commonName = Common Name (z.B. IHR Name, die Serverdomain) commonName_max = 64
emailAddress = E-Mail-Addresse emailAddress_max = 64 </cli>
Nun müssen wir die in der openssl.cnf angegebenen Verzeichnisse und Dateien anlegen:
<cli> mkdir /root/RootCA # oder der welcher Name/ welches Verzeichniss oben ausgewählt wurde cd /root/RootCA mkdir newcerts certs crl private touch index.txt # Serialnr starts with 01 echo “01” > serial </cli>
Damit wir das Programm uuencode nutzen können, muss das sharutils Paket installiert sein.
<cli> cat /dev/urandom | uuencode -m bla | head -19 | sed “s/begin.*g”\ | tail -18 | xargs | sed “s/ g” > /root/RootCA/private/.rand chmod 770 /root/RootCA/private/.rand ls -alh /root/RootCA/private/.rand </cli>
Nun können wir das Zertifikat erzeugen…
Erzeugung des Schlüssel. Damit der Schlüssel auch noch in den nächsten Jahren eine Sicherheit darstellt sollten wir eine starke passphrase verwenden! <cli>
openssl genrsa -aes256 -out private/RootCA.key.pem -rand private/.rand 2048
</cli>
Das Zertifikat erzeugen: <cli> openssl req -new -x509 -days 1827 -key private/RootCA.key.pem -out RootCA.cert.pem </cli>
(-days 1827 erzeugt ein Zertifikat, das 5 Jahre gültig ist)
Wir überprüfne die Zertifikats-Daten: <cli> openssl x509 -in RootCA.cert.pem -text | less </cli>
Wir kopieren das Zertifikaten und den Privaten Schlüssel zu den in der openssl.cnf vorgegebene Orten: <cli> cp /root/RootCA/RootCA.cert.pem /root/RootCA/cacert.pem cp /root/RootCA/private/RootCA.key.pem /root/RootCA/private/cakey.pem </cli> Stelle das Zertifikat unter die Kontrolle der CA. Dazu muss es mit seiner Seriennummer als Dateiname in das “certs” Verzeichnis kopiert und mit seinem hash-Wert gelinkt werden:
<cli> cd /root/RootCA cp RootCA.cert.pem /root/RootCA/certs/00.pem cd /root/RootCA/certs/ ln -s 00.pem `openssl x509 -hash -noout -in 00.pem`.0 </cli>
Nun ist die CA eingerichtet und du kannst beginnen die Zertifikate zu erstellen. Dazu benennst du .cert.pem-datei in .crt-datei um, kopierst es in ein verzeichnis, das via Internet zugreifbar ist, und passt die Zugriffsrechte für die Datei entsprechend an:
<cli> cp /root/RootCA/RootCA.cert.pem /var/www/virtual/yourdomain.com/htdocs/RootCA.crt chmod 444 /var/www/virtual/yourdomain.com/htdocs/RootCA.crt </cli>
Um das Zertifikat im Browser zu importieren rufst du die abgelegte Datei mit deinem Browser auf: http://yourdomain.com/RootCA.crt
Alle Server-Zertifikate werden auf die gleiche Weise erstellte. Gebe für die Server-Zertifikate keine passphrase an - denn sonst müsstest du bei jedem Start des Servers diese passphrase eingeben! Dazu brauchst du bei der Abfrage der Passphrase nur mit “Enter” bestätigen (also keine Eingabe machen).
<cli> cd /root/RootCA openssl genrsa -out server.key.pem -rand private/.rand 2048 # Generate the key openssl req -new -key server.key.pem -out server.req.pem # Generate the certificate request openssl ca -name RootCA -in server.req.pem -out server.cert.pem # Sign the request with your CA (you have to enter the CA-passphrase) </cli>
Verschiebe das Zertifikat in das certs-Verzeichnis und verlinke es mit seinem hash-Wert: <cli> mv newcerts/01.pem certs/ # the certificate is named with its serialnumber - so its name is 01.pem only the first time, of course) cd certs ln -s 01.pem `openssl x509 -hash -noout -in 01.pem`.0 </cli>
Die orginalen Zertifikatsdateien kann man zur besseren Übersichts noch in ein separates Verzeichnis kopieren: <cli> mkdir /root/RootCA/server mv server.*.pem server/ </cli>
Erstelle ein Serverzertifikat wie unter 2.1 beschrieben (nutze apache.key.pem, apache.req.pem und apache.cert.pem als Dateinamen). Wenn du apache.req.pem erstellst, gebe folgendes ein:
<cli> Organizational Unit Name []:Apache Webserver Common Name (eg, YOUR name) []:yourdomain.com </cli>
Es ist wichtig hier den Domainnamen einzugeben, unter dem du dass ISPcp nutzen möchtest, da du sonst ein “domain mismatch”-Fehler erhältst, wenn du dich via ssl (https) verbindest.
Nachdem du das Zertifikat erstellt hast, ändere die folgenden Einstellungen in /etc/apache2/mods-available/ssl.conf (tausche 512 gegen 2048): <cli> SSLRandomSeed startup /dev/urandom 2048 SSLRandomSeed connect /dev/urandom 2048 </cli>
Dann erstelle das Verzeichnis und kopiere die Zertifikat-Dateien (mit entsprechend !!! SICHEREN !!! Dateiberechtigungen): <cli> mkdir /etc/apache2/ssl cp apache.cert.pem apache.key.pem /etc/apache2/ssl chmod 400 /etc/apache2/ssl/apache.cert.pem /etc/apache2/ssl/apache.key.pem </cli> Aktiviere die Nutzung des SSL-Ports (443) im Apache (/etc/apache2/ports.conf): <cli> Listen 443 </cli> und aktiviere das Modul mod_ssl (eingabe des Befehls in die Konsole) : <cli> a2enmod ssl </cli>
Als letzter Schritt muss ein neuer virtueller Host hinzugefügt werden, der an Port 443 lauscht und die SSL-Engine bei Anfragen aktiviert:
<cli> cp /etc/apache2/sites-available/00_master.conf /etc/apache2/sites-available/01_ssl_master.conf </cli>
Ändere die 01_ssl_master.conf wie folgt: <cli> # # SSL Master Begin #
<VirtualHost xxx.xxx.xxx.xxx:443>
# # SSL Start #
SSLEngine On SSLCertificateFile /etc/apache2/ssl/apache.cert.pem SSLCertificateKeyFile /etc/apache2/ssl/apache.key.pem
# # SSL End #
ServerAdmin admin@yourdomain.com DocumentRoot /var/www/ispcp/gui
ServerName yourdomain.com
ErrorLog /var/log/apache2/users/ssl.yourdomain.com-error.log TransferLog /var/log/apache2/users/ssl.yourdomain.com-access.log
CustomLog /var/log/apache2/ssl.yourdomain.com-traf.log traff CustomLog /var/log/apache2/ssl.yourdomain.com-combined.log combined
# # … below here, nothing has to be changed #
</VirtualHost>
# # SSL Master End # </cli>
Aktiviere die ssl-Seite über folgenden Aufruf in der Konsole: <cli> a2ensite 01_ssl_master.conf </cli>
Restarte den Apache-Server nun um die Änderungen zu übernehmeen: <cli> /etc/init.d/apache2 reload </cli>
Fertig!
Öffne deinen Broser und gebe deine Domain mit vorangestellten https: ein (https://yourdomain.com). Nun solltest du das ispCP-Login-Screen sehen. ( Übrigens, auch phpmyadmin und der Webmailer sind nun via https: erreichbar.)
At first, you have to install the ssl-packages for courier: <cli> apt-get install courier-imap-ssl courier-pop-ssl </cli>
Now you can generate the server certificate as described under 2.1 (choose courier.key.pem, courier.req.pem and courier.cert.pem as filenames). When generating the courier.req.pem, enter this:
<cli> Organizational Unit Name []:Courier Mailserver Common Name (eg, YOUR name) []:mail.yourdomain.com </cli>
The courier server needs the cert and the key-file together in one file: <cli> cd /root/RootCA/server cat courier.cert.pem courier.key.pem > courier.pem </cli>
Put the Certificates under /etc/courier:
<cli> cd /etc/courier cp /root/RootCA/server/courier.pem . chmod 400 courier.pem ln -s courier.pem imapd.pem ln -s courier.pem pop3d.pem </cli>
Now you can restart the courier-ssl servers: <cli> /etc/init.d/courier-imap-ssl restart /etc/init.d/courier-pop-ssl restart </cli> and SSL is working for your IMAP and POP3-Server!
Generate the server certificate as described under 2.1 (choose proftpd.key.pem, proftpd.req.pem and proftpd.cert.pem as filenames). When generating the proftpd.req.pem, enter this:
<cli> Organizational Unit Name []:ProFTPD FTP-Server Common Name (eg, YOUR name) []:ftp.yourdomain.com </cli>
Copy the files in /etc/proftpd: <cli> cd /etc/proftpd cp /root/RootCA/server/proftpd.cert.pem /root/RootCA/server/proftpd.key.pem . chmod 400 proftpd.cert.pem proftpd.key.pem </cli>
Activate TLS in /etc/proftpd.conf (uncomment these lines): <cli> # # SSL via TLS # <IfModule mod_tls.c>
TLSEngine on # on for use of TLS TLSLog /var/log/proftpd/ftp_ssl.log # where to log to TLSProtocol SSLv23 # SSLv23 or TLSv1 TLSOptions NoCertRequest # either to request the certificate or not TLSRSACertificateFile /etc/proftpd/proftpd.cert.pem # SSL certfile TLSRSACertificateKeyFile /etc/proftpd/proftpd.key.pem # SSL keyfile TLSVerifyClient off # client verification
</IfModule> </cli>
Restart ProFTPD: <cli> /etc/init.d/proftpd restart </cli> That's all! Now you can connect to ftp.yourdomain.com via FTP with explicit TLS/SSL.
Generate the server certificate as described under 2.1 (choose postfix.key.pem, postfix.req.pem and postfix.cert.pem as filenames). When generating the postfix.req.pem, enter this:
<cli> Organizational Unit Name []:Postfix Mailserver Common Name (eg, YOUR name) []:mail.yourdomain.com </cli>
Copy the files in /etc/postfix: <cli> cd /etc/postfix cp /root/RootCA/server/postfix.cert.pem /root/RootCA/server/postfix.key.pem . chmod 400 postfix.cert.pem postfix.key.pem </cli>
Activate TLS/SSL in /etc/postfix/main.cf (uncomment these lines): <cli> smtpd_tls_loglevel = 2 smtpd_tls_cert_file = /etc/postfix/postfix.cert.pem smtpd_tls_key_file = /etc/postfix/postfix.key.pem smtpd_use_tls = yes smtpd_tls_auth_only = no smtpd_tls_received_header = yes </cli>
Restart postfix: <cli> /etc/init.d/postfix restart </cli> And another one… You can now send your emails over an SSL-encrypted connection.
Now you have configured your webserver (for ispCP), your mailservers and your ftp-server to use a ssl-encrypted connection.
Don't forget to distribute the CA-Certificate (it's accessible via http://yourdomain.com/RootCA.crt, isn't it?) to the people who access your server, so that they don't have to accept each single server certificate.