{"id":860,"date":"2020-11-21T03:02:41","date_gmt":"2020-11-21T02:02:41","guid":{"rendered":"http:\/\/www.instruyete.org\/?p=860"},"modified":"2020-11-21T14:11:20","modified_gmt":"2020-11-21T13:11:20","slug":"verlaengerung-eines-ca-zertifikats","status":"publish","type":"post","link":"https:\/\/www.instruyete.org\/?p=860","title":{"rendered":"Verl\u00e4ngerung eines CA Zertifikats"},"content":{"rendered":"\n<p>Das Auslaufen meines self-signed CA Zertifikates konfrontierte mich mal wieder mit dem openssl CLI und seinen T\u00fccken.<\/p>\n\n\n\n<p>Ausgehend von einer theoretischen Betrachtung sind nur wenige Schritte notwendig um ein CA Zertifikat zu verl\u00e4ngern,  was eigentlich bedeutet es in einer erneuerten Version herauszugeben.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Unter Ber\u00fccksichtigung des private keys der CA erstellt man ein Certificate Request.<\/li><li>Dies wird mit dem private key der CA signiert und erstellt somit ein neues CA Zertifikat.<\/li><li>Dann \u00fcberpr\u00fcft man ob schon vormals ausgestellte Server-Zertifikate vom neuen CA Zertifikat akzeptiert werden.<\/li><li>Das neue CA Zertifikat wird auf die Zielplattformen geladen.<\/li><\/ol>\n\n\n\n<!--more-->\n\n\n\n<p>Diese Punkte konnten auch ohne Schwierigkeiten mit folgender Kommandosequenz abgearbeitet werden.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl req -new -key &lt;privateKey.pem> -out &lt;certRequest.csr><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl x509 -req -in &lt;certRequest.csr> -signkey &lt;privateKey.pem> -out &lt;caCert.pem><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl verify -CAfile &lt;caCert.pem> -verbose &lt;oldServerCert.pem><\/code><\/pre>\n\n\n\n<p>Das letzte Kommando lieferte wie erwartet ein OK. Die \u00dcberraschung kam, als das neue Zertifikat auf einem Android System nicht akzeptiert wurde. Die Fehlermeldung lautete:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Privater Schl\u00fcssel zum Installieren des Zertifikats erforderlich.<\/pre>\n\n\n\n<p>Irref\u00fchrend &#8211; was Android einem eigentlich sagen wollte, dass es dieses Zertifikat nicht akzeptiert, da es nicht dem <strong>x509v3<\/strong> Standard entspricht und somit keine <strong>x509v3 Extension<\/strong> bzgl. <em>Basic Constraints<\/em> besitzt, siehe auch <a href=\"https:\/\/www.ibm.com\/support\/knowledgecenter\/SSHS8R_7.1.0\/com.ibm.worklight.installconfig.doc\/admin\/t_installing_root_CA_android.html\">Installing the root CA on Android<\/a>. Dieses Attribut klassifiziert seit x509v3 Zertifikate welche selber signieren k\u00f6nnen und somit ein Teil der <em>PKI<\/em> oder <em>Trust of Chain<\/em> sind.<\/p>\n\n\n\n<p>Dies ist der einzige Grund. Legacy requirements wie das Vorliegen des Zertifikats im bin\u00e4ren <em>DER<\/em> Format und gar Line Endings im <em>CRLF<\/em> Style spielen zumindest heute keine Rolle mehr. Pikanterweise wird das Zertifikat auf dem Linux Desktop auf <em>Chrome<\/em> Version 86 akzeptiert, obwohl &#8211; nach einer \u00dcberpr\u00fcfung mit dem Kommando<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl x509 -in &lt;caCert.pem> -text -noout<\/code><\/pre>\n\n\n\n<p>tats\u00e4chlich feststeht, dass das mit den obigen Kommando erstellte CA Zertifikat auf dem x509v1 Standard basiert, ganz im Gegensatz zum bisherigen CA Zertifikat, welches sehr wohl den x509v3 Standard hat.<\/p>\n\n\n\n<p>Dies wurde allerdings seinerzeit mit einem einzigen Kommando erzeugt, das gleichzeitig einen neuen private Key erzeugte.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl req -x509 -newkey rsa -out &lt;caCert.pem> -outform PEM<\/code><\/pre>\n\n\n\n<p>Und genau hier wird das Problem sichtbarer. Die Konfigurationsdatei <strong>openssl.cnf<\/strong> legte folgendes fest (nur auszugsweise aufgef\u00fchrt):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># OpenSSL example configuration file.\n# This is mostly being used for generation of certificate requests.\n#\n\n...\n\n# To use this configuration file with the \"-extfile\" option of the\n# \"openssl x509\" utility, name here the section containing the\n# X.509v3 extensions to use:\n# extensions            =\n# (Alternatively, use a configuration file that has only\n# X.509v3 extensions in its main [= default] section.)\n\n...\n\n[ req ]\n default_bits            = 2048\n ...\n attributes              = req_attributes\n x509_extensions = v3_ca # The extentions to add to the self signed cert\n ...\n\n[ v3_ca ]\n # Extensions for a typical CA\n # PKIX recommendation.\n subjectKeyIdentifier=hash\n authorityKeyIdentifier=keyid:always,issuer\n # This is what PKIX recommends but some broken software chokes on\n # critical extensions.\n # basicConstraints = critical,CA:true\n # So we do this instead.\n basicConstraints = CA:true\n\n...<\/pre>\n\n\n\n<p>Die extension <strong>v3_ca<\/strong> wurde nur in der Sektion <strong>[req]<\/strong> angesprochen und ist somit nur f\u00fcr Kommandos der Form:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl req ...<\/code><\/pre>\n\n\n\n<p>g\u00fcltig. Das neue CA Zertifikat wurde aber, wie oben gezeigt durch ein<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl x509 ...<\/code><\/pre>\n\n\n\n<p>Kommando erzeugt, das wie im einleitenden Kommentar in der Konfigurationsdatei angedeutet, prinzipiell die extensions nicht direkt verarbeitet, das bedeutet dass auch eine erweitertes Kommando:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl x509 -req -extensions v3_ca -in &lt;certRequest.csr> -signkey &lt;privateKey.pem> -out &lt;caCert.pem><\/code><\/pre>\n\n\n\n<p>leider nicht zu einem x509v3 Zertifikat f\u00fchrt. <br>Erfolg brachte letztendlich nur die Auslagerung der <strong>[ v3_ca ]<\/strong> Extension in ein separates File und die Ausf\u00fchrung dieses Kommandos:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl x509 -req -extensions v3_ca -extfile ssl-extensions-x509.cnf -in &lt;certRequest.csr> -signkey &lt;privateKey.pem> -out &lt;caCert.pem><\/code><\/pre>\n\n\n\n<p>wobei der Inhalt von <strong>extfile<\/strong> exakt der obige<strong> [ v3_ca ]<\/strong> Block innerhalb der <strong>openssl.cnf<\/strong> ist.<\/p>\n\n\n\n<p>Eine Diskussion dar\u00fcber wurde auf <em>stackexchange<\/em> im Thread <a href=\"https:\/\/security.stackexchange.com\/questions\/150078\/missing-x509-extensions-with-an-openssl-generated-certificate\">Missing X509 extensions with an openssl-generated certificate<\/a> gef\u00fchrt.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Das Auslaufen meines self-signed CA Zertifikates konfrontierte mich mal wieder mit dem openssl CLI und seinen T\u00fccken. Ausgehend von einer theoretischen Betrachtung sind nur wenige Schritte notwendig um ein CA Zertifikat zu verl\u00e4ngern, was eigentlich bedeutet es in einer erneuerten Version herauszugeben. Unter Ber\u00fccksichtigung des private keys der CA erstellt man ein Certificate Request. Dies &hellip; <a href=\"https:\/\/www.instruyete.org\/?p=860\" class=\"more-link\"><span class=\"screen-reader-text\">Verl\u00e4ngerung eines CA Zertifikats<\/span> weiterlesen<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,9,7],"tags":[47,24,46],"class_list":["post-860","post","type-post","status-publish","format-standard","hentry","category-android","category-linux","category-unix","tag-ca","tag-openssl","tag-pki"],"_links":{"self":[{"href":"https:\/\/www.instruyete.org\/index.php?rest_route=\/wp\/v2\/posts\/860","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.instruyete.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.instruyete.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.instruyete.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.instruyete.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=860"}],"version-history":[{"count":8,"href":"https:\/\/www.instruyete.org\/index.php?rest_route=\/wp\/v2\/posts\/860\/revisions"}],"predecessor-version":[{"id":868,"href":"https:\/\/www.instruyete.org\/index.php?rest_route=\/wp\/v2\/posts\/860\/revisions\/868"}],"wp:attachment":[{"href":"https:\/\/www.instruyete.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=860"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.instruyete.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=860"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.instruyete.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=860"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}