{"id":33,"date":"2011-06-27T15:10:25","date_gmt":"2011-06-27T13:10:25","guid":{"rendered":"http:\/\/www.zerfallskonstante.de\/?p=33"},"modified":"2015-03-09T14:13:48","modified_gmt":"2015-03-09T13:13:48","slug":"rootca-unter-debian","status":"publish","type":"post","link":"https:\/\/www.zerfallskonstante.de\/?p=33","title":{"rendered":"rootCA unter debian"},"content":{"rendered":"<p>In diesem Beispiel soll mit Hilfe von openssl eine rootCA erzeugt werden, die den \u00f6ffentlichen Schl\u00fcssel f\u00fcr eine ServerCA signiert. Diese wiederrum soll den \u00f6ffentlichen Schl\u00fcssel, der beispielsweise in einem IIS-Webserver verwendet werden kann, signieren.<\/p>\n<p>Unter lenny sind die Pakete openssl und sharutils installiert.<br \/>\n<!--more--><br \/>\nDer Ablauf ist dabei wie folgt:<\/p>\n<pre>     1. Verzeichnisstruktur f\u00fcr rootCA und serverCA erstellen\r\n        1.1 .rand-Dateien erzeugen\r\n\r\n     2. rootCA anlegen\r\n        2.1 RCAkey.pem generieren\r\n        2.2 RCAcert.pem erzeugen\r\n\r\n     3. ServerCA anlegen\r\n        3.1 SCAkey.pem generieren\r\n        3.2 SCAcert.pem erzeugen\r\n\r\n     4. Werbserver Zertifikat erzeugen\r\n        4.1 Zertifikatsrequest im IIS erzeugen\r\n        4.2 Zertifikatsrequest SCAkey.pem signieren\r\n\r\n     5. PEM in cer konvertieren\r\n\r\n     6. Zertifikatskette exportieren\r\n<\/pre>\n<h5><strong>1. Verzeichnisstruktur f\u00fcr rootCA und serverCA erstellen<\/strong><\/h5>\n<p>Mit folgenden Befehlen wird die gew\u00fcnschte Struktur inklusive der Dateien angelegt.<\/p>\n<p>[bash]<br \/>\nmkdir \/root\/CA\/certs \/root\/CA\/private \/root\/CA\/rootCA \/root\/CA\/serverCA<br \/>\ncd \/root\/CA\/rootCA<br \/>\nmkdir certs newcerts private crl<br \/>\nchmod go-rwx private<br \/>\necho &#8222;01&#8220; > serial<br \/>\necho &#8222;01&#8220; > crlnumber<br \/>\ntouch index.txt<br \/>\ncd ..\/serverCA<br \/>\nmkdir certs newcerts private crl<br \/>\nchmod go-rwx private<br \/>\necho &#8222;01&#8220; > serial<br \/>\necho &#8222;01&#8220; > crlnumber<br \/>\ntouch index.txt<br \/>\ncd ..<br \/>\n[\/bash]<\/p>\n<p>In der Datei <em>serial<\/em> wird die Seriennummer in hexadezimaler Codierung, des Zertifikats hinterlegt das als n\u00e4chste von der jeweiligen CA herausgegeben wird. In der Datei <em>index.txt<\/em> sind die bereits signierten Zertifikate aufgelistet.<\/p>\n<h6><strong>1.1 .rand-Dateien erzeugen<\/strong><\/h6>\n<p>Der Verzeichnispfad \/root\/CA\/.. muss entsprechend der CA angepasst werden.<\/p>\n<p>[bash]<br \/>\nfor i in `find \/root\/CA\/serverCA\/ -name private`<br \/>\n   do cat \/dev\/urandom |<br \/>\n      uuencode -m bla |<br \/>\n      head -19 |<br \/>\n      sed &#8222;s\/begin.*\/\/g&#8220; |<br \/>\n      tail -18 | xargs |<br \/>\n      sed &#8222;s\/ \/\/g&#8220; > $i\/.rand<br \/>\n   chmod 770 $i\/.rand<br \/>\n   ls -l  $i\/.rand<br \/>\ndone<br \/>\n[\/bash]<\/p>\n<p>Die Verzeichnisstruktur inlusive der ben\u00f6tigten Dateien sieht nun wie folgt aus:<\/p>\n<p>[bash]<br \/>\n\/root\/CA\/<br \/>\n|&#8211; certs<br \/>\n|&#8211; openssl.cnf<br \/>\n|&#8211; private<br \/>\n\t`&#8211; .random<br \/>\n|&#8211; rootCA<br \/>\n|   |&#8211; certs<br \/>\n|   |&#8211; crl<br \/>\n|   |&#8211; crlnumber<br \/>\n|   |&#8211; index.txt<br \/>\n|   |&#8211; newcerts<br \/>\n|   |&#8211; private<br \/>\n\t\t`&#8211; .random<br \/>\n|   |&#8211; serial<br \/>\n`&#8211; serverCA<br \/>\n    |&#8211; certs<br \/>\n    |&#8211; crl<br \/>\n    |&#8211; crlnumber<br \/>\n    |&#8211; index.txt<br \/>\n    |&#8211; newcerts<br \/>\n    |&#8211; private<br \/>\n\t\t`&#8211; .random<br \/>\n    `&#8211; serial<br \/>\n[\/bash]<\/p>\n<h5><strong>2. rootCA anlegen<\/strong><\/h5>\n<h6><strong>2.1 RCAkey.pem generieren<\/strong><\/h6>\n<p>Mit folgendem Aufruf wird mit Hilfe einer zufallsgenerierten Zahl (.rand) eine 2048-Bit lange RSA-Schl\u00fcsseldatei (RCAkey.pem) erzeugt in der sowohl der private als auch der \u00f6ffentliche Schl\u00fcssel hinterlegt sind. Die Schl\u00fcsseldatei ist durch den Parameter aes256 passwortgesch\u00fctzt.<\/p>\n<p>Das Passwort (Passphrase) sollte den Anforderungen f\u00fcr sichere <a title=\"Passw\u00f6rtern\" href=\"http:\/\/de.wikipedia.org\/wiki\/Passwort\" target=\"_blank\">Passw\u00f6rtern<\/a> gen\u00fcgen, also am Besten eine Mischung aus Zahlen, Buchstaben und Sonderzeichen und mindestens 8 Zeichen lang sein. Bei nicht-Benutzerzertifikaten sollte\/muss der Parameter aes256 weggelassen werden, so ist der private Schl\u00fcssel passwortlos und ein Dienst oder \u00e4hnliches ben\u00f6tigt zum Starten kein Passwort. Der Zugriff auf den ohne Passwortschutz vorliegenden privaten Schl\u00fcssel muss \u00fcber ACL&#8217;s im Dateisystem entsprechend geregelt werden.<\/p>\n<p>[bash]<br \/>\nopenssl genrsa -aes256 -out .\/rootCA\/private\/RCAkey.pem -rand .\/rootCA\/private\/.rand 2048<\/p>\n<p>246 semi-random bytes loaded<br \/>\nGenerating RSA private key, 2048 bit long modulus<br \/>\n&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..+++<br \/>\n&#8230;.+++<br \/>\ne is 65537 (0x10001)<br \/>\nEnter pass phrase for .\/rootCA\/private\/RCAkey.pem: *****<br \/>\nVerifying &#8211; Enter pass phrase for .\/rootCA\/private\/RCAkey.pem: *****<br \/>\n[\/bash]<\/p>\n<h6><strong>2.2 RCAcert.pem erzeugen<\/strong><\/h6>\n<p>Mit der zuvor erzeugten Schl\u00fcsseldatei (RCAkey.pem) wird nun ein selbstsigniertes Zertifikat (RCAcert.pem) erzeugt, das f\u00fcr 50 Jahre (18530 Tage) g\u00fcltig ist. Die default-Werte der Attribute des Requests sind in der Sektion req_distinguished_name in der openssl.cnf hinterlegt. Das eindeutige Merkmal des Request ist das Attribut &#8222;hostname, IP or your name&#8220;.<\/p>\n<p>[bash]<br \/>\nopenssl req -new -x509 -set_serial 0 -days 18250 -config .\/openssl.cnf -key .\/rootCA\/private\/RCAkey.pem -out .\/rootCA\/certs\/RCAcert.pem<br \/>\nEnter pass phrase for .\/rootCA\/private\/RCAkey.pem: *****<\/p>\n<p>You are about to be asked to enter information that will be incorporated<br \/>\ninto your certificate request.<br \/>\nWhat you are about to enter is what is called a Distinguished Name or a DN.<br \/>\nThere are quite a few fields but you can leave some blank<br \/>\nFor some fields there will be a default value,<br \/>\nIf you enter &#8218;.&#8216;, the field will be left blank.<br \/>\n&#8212;&#8211;<br \/>\nOrganization Name (company) [xyz]:<br \/>\nOrganizational Unit Name (department, division) [xyz]:<br \/>\nEmail Address xyz@zerfallskonstante.de]:<br \/>\nLocality Name (city, district) [xyz]:<br \/>\nState or Province Name (full name) [xyz]:<br \/>\nCountry Name (2 letter code) [DE]:<br \/>\nCommon Name (hostname, IP, or your name) []:caroot.zerfallskonstante.de<br \/>\n[\/bash]<\/p>\n<p>Im Verzeichnis \/root\/CA\/rootCA\/private befinden sich nun die RSA-Schl\u00fcsseldatei (RCAkey.pem) und im Verzeichnis \/root\/CA\/rootCA\/certs das selbstsignierte Zertifikat (RCAcert.pem) der rootCA.<\/p>\n<p>selbstsigniertes Zertifikat der rootCA ver\u00f6ffentlichen:<\/p>\n<p>[bash]<br \/>\ncp \/root\/CA\/rootCA\/certs\/RCAcert.pem \/root\/CA\/rootCA\/certs\/00.pem<br \/>\ncd \/root\/CA\/rootCA\/certs<br \/>\nln -s 00.pem `openssl x509 -in 00.pem -hash -noout`.0<br \/>\n[\/bash]<\/p>\n<p>Inhalt des RSA-Schl\u00fcssels anzeigen:<\/p>\n<p>[bash]<br \/>\nopenssl rsa -in \/root\/CA\/rootCA\/private\/RCAkey.pem -text | less<br \/>\n[\/bash]<\/p>\n<p>Inhalt des Zertifikats anzeigen:<\/p>\n<p>[bash]<br \/>\nopenssl x509 -in \/root\/CA\/rootCA\/certs\/00.pem -noout -text<br \/>\nopenssl x509 -in \/root\/CA\/rootCA\/certs\/00.pem -noout -dates<br \/>\nopenssl x509 -in \/root\/CA\/rootCA\/certs\/00.pem -noout -purpose<br \/>\n[\/bash]<\/p>\n<h5><strong>3. ServerCA anlegen<\/strong><\/h5>\n<p>Bei der ServerCA wird ebenfalls zuerst mit Hilfe einer zufallsgenerierten Zahl (.rand) eine 2048-Bit lange RSA-Schl\u00fcsseldatei (SCAkey.pem) erzeugt. Die Schl\u00fcsseldatei ist ebenfalls durch ein Passwort gesch\u00fctzt.<\/p>\n<h6><strong>3.1 SCAkey.pem generieren<\/strong><\/h6>\n<p>[bash]<br \/>\nopenssl genrsa -aes256 -out .\/serverCA\/private\/SCAkey.pem -rand .\/serverCA\/private\/.rand 2048<br \/>\n248 semi-random bytes loaded<br \/>\nGenerating RSA private key, 2048 bit long modulus<br \/>\n&#8230;..+++<br \/>\n&#8230;+++<br \/>\ne is 65537 (0x10001)<br \/>\nEnter pass phrase for .\/serverCA\/private\/SCAkey.pem:<br \/>\nVerifying &#8211; Enter pass phrase for .\/serverCA\/private\/SCAkey.pem:<br \/>\n[\/bash]<\/p>\n<p>Nun wird ein Zertifikatsrequest (SCAreq.pem) mit der zuvor erstellten Schl\u00fcsseldatei (SCAkey.pem) erzeugt.<\/p>\n<p>[bash]<br \/>\nopenssl req -config .\/openssl.cnf -new -key .\/serverCA\/private\/SCAkey.pem -out .\/serverCA\/SCAreq.pem<br \/>\nEnter pass phrase for .\/serverCA\/private\/SCAkey.pem:<br \/>\nYou are about to be asked to enter information that will be incorporated<br \/>\ninto your certificate request.<br \/>\nWhat you are about to enter is what is called a Distinguished Name or a DN.<br \/>\nThere are quite a few fields but you can leave some blank<br \/>\nFor some fields there will be a default value,<br \/>\nIf you enter &#8218;.&#8216;, the field will be left blank.<br \/>\n&#8212;&#8211;<br \/>\nOrganization Name (company) [xyz]:<br \/>\nOrganizational Unit Name (department, division) [xyz]:<br \/>\nEmail Address xyz@zerfallskonstante.de]:<br \/>\nLocality Name (city, district) [xyz]:<br \/>\nState or Province Name (full name) [xyz]:<br \/>\nCountry Name (2 letter code) [DE]:<br \/>\nCommon Name (hostname, IP, or your name) []:casrv.zerfallskonstante.de<\/p>\n<p>Please enter the following &#8218;extra&#8216; attributes<br \/>\nto be sent with your certificate request<br \/>\nA Challenge Password []: *****GEHEIM*****<br \/>\n[\/bash]<\/p>\n<h6><strong>3.2 SCAcert.pem erzeugen<\/strong><\/h6>\n<p>Der Zertifikatsrequest (SCAreq.pem) wird nun mit dem RSA-Schl\u00fcssels (RCAkey.pem) der \u00fcbergeordneten CA signiert. Die Schl\u00fcsseldatei der rootCA wird \u00fcber die Parameter private_key in der Sektion Root_CA der openssl.cnf-Datei in den Aufruf eingebunden.<\/p>\n<p>[bash]<br \/>\nopenssl ca -config .\/openssl.cnf -name Root_CA -in .\/serverCA\/SCAreq.pem -out .\/serverCA\/certs\/SCAcert.pem<\/p>\n<p>Using configuration from openssl.cnf<br \/>\nEnter pass phrase for \/root\/CA\/rootCA\/private\/RCAkey.pem:<br \/>\nCheck that the request matches the signature<br \/>\nSignature ok<br \/>\nThe Subject&#8217;s Distinguished Name is as follows<br \/>\norganizationName      :PRINTABLE:&#8217;xyz&#8216;<br \/>\norganizationalUnitName:PRINTABLE:&#8217;xyz&#8216;<br \/>\nemailAddress          :IA5STRING:&#8217;xyz@zerfallskonstante.de&#8216;<br \/>\nlocalityName          :PRINTABLE:&#8217;xyz&#8216;<br \/>\nstateOrProvinceName   :PRINTABLE:&#8217;xyz&#8216;<br \/>\ncountryName           :PRINTABLE:&#8217;DE&#8216;<br \/>\ncommonName            :PRINTABLE:&#8217;casrv.zerfallskonstante.de&#8216;<br \/>\nCertificate is to be certified until Jun 26 11:07:05 2016 GMT (1825 days)<br \/>\nSign the certificate? [y\/n]:y<\/p>\n<p>1 out of 1 certificate requests certified, commit? [y\/n]y<br \/>\nWrite out database with 1 new entries<br \/>\nData Base Updated<br \/>\n[\/bash]<\/p>\n<p>Das signierte Zertifikat der ServerCA (SCAcert.pem) liegt in \/root\/CA\/serverCA\/certs sowie als 01.pem in \/root\/CA\/rootCA\/newcerts (durch den Parameter new_cert_dir in der Sektion Root_CA in der openssl.cnf).<\/p>\n<p>signiertes Zertifikat der ServerCA ver\u00f6ffentlichen:<\/p>\n<p>[bash]<br \/>\nmv .\/rootCA\/newcerts\/01.pem .\/rootCA\/certs\/<br \/>\ncd .\/rootCA\/certs<br \/>\nln -s 01.pem `openssl x509 -in 01.pem -hash -noout`.0<br \/>\n[\/bash]<\/p>\n<p>Das Verzeichnis \/root\/CA\/rootCA\/certs sieht nun wie folgt aus:<\/p>\n<p>[bash]<br \/>\ndrwxr-xr-x 2 root root 4096  7. Sep 10:22 .<br \/>\ndrwxr-xr-x 5 root root 4096  7. Sep 10:11 ..<br \/>\n-rw-r&#8211;r&#8211; 1 root root 1533  6. Sep 13:55 00.pem<br \/>\n-rw-r&#8211;r&#8211; 1 root root 5108  7. Sep 10:11 01.pem<br \/>\nlrwxrwxrwx 1 root root    6  7. Sep 10:22 a155d062.0 -> 01.pem<br \/>\nlrwxrwxrwx 1 root root    6  7. Sep 10:22 d7b91c41.0 -> 00.pem<br \/>\n[\/bash]<\/p>\n<p>Die SCAcert.pem sollte nun auch in den oben genannten Kontainer in Windows importiert werden um die G\u00fcltigkeit von Zertifikaten, die von der Server_CA ausgestellt werden sicherzustellen.<\/p>\n<h5><strong>4. Werbserver Zertifikat erzeugen<\/strong><\/h5>\n<h6><strong>4.1 Zertifikatsrequest im IIS erzeugen<\/strong><\/h6>\n<p>\u00dcber die Eigenschaften der Standardwebseite im IIS-Manager wird auf dem Karteikartenreiter Verzeichnissicherheit, Serverzertifikat ausgew\u00e4hlt und ggf. ein bestehendes Zertifikat entfernt und dann ein neues Zertifikat beantragt.<\/p>\n<p>Der Inhalt des erzeugten CSR.txt wird \u00fcber die Zwischenablage (STRG+C) in die Datei wwwreq.csr kopiert. Die letzte Zeile ist u.U. eine leer Zeile, die entfernt werden muss.<\/p>\n<h6><strong>4.2 Zertifikatsrequest SCAkey.pem signieren<\/strong><\/h6>\n<p>[bash]<br \/>\nopenssl ca -config ..\/openssl.cnf -name Server_CA -policy policy_anything -in .\/serverCA\/wwwreq.csr -out .\/serverCA\/certs\/wwwcert.pem<br \/>\nUsing configuration from ..\/openssl.cnf<br \/>\nEnter pass phrase for \/root\/CA\/serverCA\/private\/SCAkey.pem:<br \/>\nCheck that the request matches the signature<br \/>\nSignature ok<br \/>\nThe Subject&#8217;s Distinguished Name is as follows<br \/>\nOrganization Name (company) [xyz]:<br \/>\nOrganizational Unit Name (department, division) [xyz]:<br \/>\nEmail Address [xyz@zerfallskonstante.de]:<br \/>\nLocality Name (city, district) [xyz]:<br \/>\nState or Province Name (full name) [xyz]:<br \/>\nCountry Name (2 letter code) [DE]:<br \/>\nCommon Name (hostname, IP, or your name) []:www.zerfallskonstante.de<br \/>\nCertificate is to be certified until Sep  5 09:44:15 2016 GMT (1825 days)<br \/>\nSign the certificate? [y\/n]:y<\/p>\n<p>1 out of 1 certificate requests certified, commit? [y\/n]y<br \/>\nWrite out database with 1 new entries<\/p>\n<p>Data Base Updated<br \/>\n[\/bash]<\/p>\n<h5><strong>5. PEM in cer konvertieren<\/strong><\/h5>\n<p>Das wwwcert.pem wird, damit es in den IIS importiert werden kann, DER-Kodiert.<\/p>\n<p>[bash]<br \/>\nopenssl x509 -in wwwcert.pem -inform PEM -out wwwcert.cer -outform DER<br \/>\n[\/bash]<\/p>\n<h5><strong>6. Zertifikatskette exportieren<\/strong><\/h5>\n<p>Die Zertifikatskette ist in der wwwcert.cer NICHT enthalten. Mit folgendem Aufruf wird das Zertifikat (01.pem) der ServerCA und das der rootCA (00.pem) unter Verwendung des privaten Schl\u00fcssels (SCAkey.pem) in eine pkcs12-Codierte Datei exportiert, die auf Windows Systemen in den Container der Vertrauensw\u00fcrdigen Stammzertifizierungsstellen importiert werden muss. Der Parameter chain ist hierbei wichtig.<\/p>\n<p>[bash]<br \/>\nopenssl pkcs12 -export -chain -in .\/rootCA\/certs\/01.pem -inkey .\/serverCA\/private\/SCAkey.pem -out .\/serverCA\/certs\/certChain.p12 -CAfile .\/rootCA\/certs\/00.pem<br \/>\nEnter pass phrase for .\/serverCA\/private\/SCAkey.pem:<br \/>\nEnter Export Password:<br \/>\nVerifying &#8211; Enter Export Password:<br \/>\n[\/bash]<\/p>\n<p><strong>verwendete openssl.cnf<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In diesem Beispiel soll mit Hilfe von openssl eine rootCA erzeugt werden, die den \u00f6ffentlichen Schl\u00fcssel f\u00fcr eine ServerCA signiert. Diese wiederrum soll den \u00f6ffentlichen Schl\u00fcssel, der beispielsweise in einem IIS-Webserver verwendet werden kann, signieren. Unter lenny sind die Pakete &hellip; <a href=\"https:\/\/www.zerfallskonstante.de\/?p=33\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,13],"tags":[5,6,4,7],"class_list":["post-33","post","type-post","status-publish","format-standard","hentry","category-linux","category-openssl","tag-bash","tag-ca","tag-linux","tag-openssl"],"_links":{"self":[{"href":"https:\/\/www.zerfallskonstante.de\/index.php?rest_route=\/wp\/v2\/posts\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zerfallskonstante.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zerfallskonstante.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zerfallskonstante.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zerfallskonstante.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=33"}],"version-history":[{"count":114,"href":"https:\/\/www.zerfallskonstante.de\/index.php?rest_route=\/wp\/v2\/posts\/33\/revisions"}],"predecessor-version":[{"id":665,"href":"https:\/\/www.zerfallskonstante.de\/index.php?rest_route=\/wp\/v2\/posts\/33\/revisions\/665"}],"wp:attachment":[{"href":"https:\/\/www.zerfallskonstante.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zerfallskonstante.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zerfallskonstante.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}