{"id":15,"date":"2018-12-02T12:06:56","date_gmt":"2018-12-02T19:06:56","guid":{"rendered":"https:\/\/www.stauber.org\/?p=15"},"modified":"2018-12-05T07:59:15","modified_gmt":"2018-12-05T14:59:15","slug":"creating-a-self-signed-ssl-certificate","status":"publish","type":"post","link":"https:\/\/www.stauber.org\/index.php\/2018\/12\/02\/creating-a-self-signed-ssl-certificate\/","title":{"rendered":"Creating a Self-signed SSL Certificate"},"content":{"rendered":"<p>In this post I will explain how to create a self-signed certificate for testing purposes.\u00a0 If you have a virtual machine running on your home network (such as inside VirtualBox, Hyper-V, or inside Windows Subsystem for Linux), it will not be able to get a Certificate Authority (CA) signed SSL certificate because it isn&#8217;t accessible on a static IP address attached to a domain name.\u00a0 However, you may still want to set it up as if it was a public facing server in order to test out a configuration, e.g. Postfix, GitLab.<\/p>\n<p>You must have\u00a0<strong>openssl<\/strong>\u00a0installed.\u00a0 This will be installed on any Linux machine, but under Windows, binaries can be hard to come by.\u00a0 I recommend installing the excellent development environment MSYS2, and installing it by opening up an MSYS2 window and typing:<\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">pacman -S openssl<\/pre>\n<p>Once it&#8217;s installed, you&#8217;ll be creating a private key, a certificate request, and then you&#8217;ll sign the request with the private key to create a public certificate. You can use any names you want for the files, but I have chosen to replicate what Let&#8217;s Encrypt gives you by default.<\/p>\n<p>Generate the private key<\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">sudo openssl genrsa -out &quot;privkey.pem&quot; 2048<\/pre>\n<p>Generating RSA private key, 2048 bit long modulus<br \/>\n&#8230;..+++++<br \/>\n&#8230;+++++<br \/>\ne is 65537 (0x10001)<\/p>\n<p>Generate the certificate request<br \/>\nYou&#8217;ll be entering in some information here. The important one is the Common Name. Although you don&#8217;t have a real domain, it&#8217;s a good idea to make up one for your private network. I have seen people use the .lcl extension for it.  Do not enter anything for the challenge password.<\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">sudo openssl req -new -key &quot;privkey.pem&quot; -out &quot;certrequest.pem&quot;<\/pre>\n<pre>You are about to be asked to enter information that will be incorporated\r\ninto your certificate request.\r\nWhat you are about to enter is what is called a Distinguished Name or a DN.\r\nThere are quite a few fields but you can leave some blank\r\nFor some fields there will be a default value,\r\nIf you enter '.', the field will be left blank.\r\n-----\r\nCountry Name (2 letter code) [AU]:<strong>US<\/strong>\r\nState or Province Name (full name) [Some-State]:<strong>New Mexico<\/strong>\r\nLocality Name (eg, city) []:Albuquerque\r\nOrganization Name (eg, company) [Internet Widgits Pty Ltd]:<strong>.<\/strong>\r\nOrganizational Unit Name (eg, section) []:<strong>.<\/strong>\r\nCommon Name (e.g. server FQDN or YOUR name) []:<strong>*.example.lcl<\/strong>\r\nEmail Address []:<strong>john.doe@example.lcl<\/strong>\r\n\r\nPlease enter the following 'extra' attributes\r\nto be sent with your certificate request\r\nA challenge password []:\r\nAn optional company name []:<\/pre>\n<p>&nbsp;<\/p>\n<p>Generate the certificate by signing the certificate request with the private key<\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">sudo openssl x509 -req -days 30 -in &quot;certrequest.pem&quot; -signkey &quot;privkey.pem&quot; -out &quot;cert.pem&quot;<\/pre>\n<pre>Signature ok\r\nsubject=C = US, ST = New Mexico, L = Albuquerque, CN = *.example.lcl, emailAddress = john.doe@example.lcl\r\nGetting Private key<\/pre>\n<p>&nbsp;<\/p>\n<p>Now move them to a standard spot for certificates.<\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">\r\nsudo chmod 644 cert.pem\r\nsudo chmod 644 certrequest.pem\r\nsudo chmod 640 privkey.pem\r\nsudo mv cert.pem \/etc\/ssl\/certs\r\nsudo mv certrequest.pem \/etc\/ssl\/certs\r\nsudo mv privkey.pem \/etc\/ssl\/private\r\n<\/pre>\n<p>You may now reference them in software that uses certificates such as Apache, Nginx, or Node.js apps.  You will still get a warning saying that the certificate is invalid, but the data sent will be encrypted.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I will explain how to create a self-signed certificate for testing purposes.\u00a0 If you have a virtual machine running on your home network (such as inside VirtualBox, Hyper-V, or inside Windows Subsystem for Linux), it will not be able to get a Certificate Authority (CA) signed SSL certificate because it isn&#8217;t accessible &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.stauber.org\/index.php\/2018\/12\/02\/creating-a-self-signed-ssl-certificate\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Creating a Self-signed SSL Certificate&#8221;<\/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":[8],"tags":[],"class_list":["post-15","post","type-post","status-publish","format-standard","hentry","category-security"],"_links":{"self":[{"href":"https:\/\/www.stauber.org\/index.php\/wp-json\/wp\/v2\/posts\/15","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.stauber.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.stauber.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.stauber.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.stauber.org\/index.php\/wp-json\/wp\/v2\/comments?post=15"}],"version-history":[{"count":11,"href":"https:\/\/www.stauber.org\/index.php\/wp-json\/wp\/v2\/posts\/15\/revisions"}],"predecessor-version":[{"id":87,"href":"https:\/\/www.stauber.org\/index.php\/wp-json\/wp\/v2\/posts\/15\/revisions\/87"}],"wp:attachment":[{"href":"https:\/\/www.stauber.org\/index.php\/wp-json\/wp\/v2\/media?parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.stauber.org\/index.php\/wp-json\/wp\/v2\/categories?post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.stauber.org\/index.php\/wp-json\/wp\/v2\/tags?post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}