{"id":32,"date":"2019-05-05T22:36:29","date_gmt":"2019-05-05T22:36:29","guid":{"rendered":"http:\/\/blog.nikster.de\/wordpress\/?p=32"},"modified":"2019-05-06T22:17:31","modified_gmt":"2019-05-06T22:17:31","slug":"how-to-ssl-certificates-for-your-services","status":"publish","type":"post","link":"https:\/\/blog.nikster.de\/wordpress\/index.php\/2019\/05\/05\/how-to-ssl-certificates-for-your-services\/","title":{"rendered":"How to SSL Certificates for your services"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">What is SSL, what&#8217;s a CA and what do I need it for?<\/h4>\n\n\n\n<p>SSL or nowadays TLS is used to encrypt communication and validate the identity of a service provider.<br>The CA is what establishes the trust in a certificate. <br>In short:<br> if the certificate presented (e.g. by the server) and the CA certificate (you trust in e.g. your client) fit together, one can be sure that the servers certificate was signed by the CA. Which itself is trusted to verify at least, that the domain the (server-)certificate is for, belongs to the requester (the one who put up the csr).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">What&#8217;s this about?<\/h4>\n\n\n\n<p>I&#8217;ll cover how to set up your own CA with openssl and sign your own certificates (good for when you control all the clients) and how to use letsencrypt (which is pretty easy and trusted in all major browsers).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">openssl CA<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>apt-get install openssl\nmkdir my_ca\ncd my_ca\nopenssl genrsa -aes256 -out ca-key.pem 4096<\/code><\/pre>\n\n\n\n<p>Install openssl, create a folder for your CA and generate a private key for it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl req -x509 -new -nodes -extensions v3_ca -key ca-key.pem -days 1024 -out ca-root.pem -sha512<\/code><\/pre>\n\n\n\n<p>Fill in the questions and your password &#8211; there is your root CA Certificate. You may import this in your browser or OS cert store (debian: cp ca-root.pem  \/usr\/local\/share\/ca-certificates\/ &amp;&amp; update-ca-certificates).<br>Your CA is ready to be used.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl genrsa -out servercert-key.pem 4096<\/code><\/pre>\n\n\n\n<p>generate a key for the server you want a certificate for.<br>a good practice is to name keys and certs like &#8220;server_example_com-key.pem&#8221; and &#8220;server_example_com-cert.pem&#8221;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl req -new -key servercert-key.pem -out servercert.csr -sha512<\/code><\/pre>\n\n\n\n<p>use the key to create a csr (certificate signing request).<br>Important:<br>CommonName = your fqdn (e.g. server.example.com)<br>Also leave the password empty or you will have to manually enter it with every start of your service.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl x509 -req -in servercert.csr -CA ca-root.pem -CAkey ca-key.pem -CAcreateserial -out servercert-pub.pem -days 365 -sha512<\/code><\/pre>\n\n\n\n<p>Now create the servers certificate.<br>If you are using a webserver like apache copy the servercert-pub.pem and the servercert-key.pem (and &#8211; if not already happened &#8211; the ca-root.pem) to the appropriate folder (e.g. \/etc\/ssl), configure apache to use them and you are done<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">letsencrypt<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>wget https:\/\/dl.eff.org\/certbot-auto\nmv \/home\/user\/certbot-auto \/usr\/local\/bin\/certbot-auto\nchmod 0755 \/usr\/local\/bin\/certbot-auto<\/code><\/pre>\n\n\n\n<p>Letsencrypt is pretty easy to set up and maintain.<br>Download their certbot and move it to \/usr\/local\/bin\/ (at least under debian there is no package for it).<br>Make sure, that your firewall allows access on port 443 (or on the port your service listens? I have only used it for apache so far), otherwise letsencrypts check &#8211; if you are the domain owner &#8211; fails.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/usr\/local\/bin\/certbot-auto --apache<\/code><\/pre>\n\n\n\n<p><strong>You may want to back up your vhost configs if you are going to use the above commands!<\/strong><\/p>\n\n\n\n<p>The above command automatically requests and downloads Certificates for your server and edits your vhost config automatically (never broke anything on my systems). <br>Your SSL-Certs are now configured.<br>You may call it with &#8211;apache certonly, to only get the certificates and do the config by yourself.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/usr\/local\/bin\/certbot-auto renew --dry-run<\/code><\/pre>\n\n\n\n<p>if the above works, install a cronjob to let the autobot take care of automatic renewal of certs for you.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>crontab -e\n\n0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' &amp;&amp; \/usr\/local\/bin\/certbot-auto renew<\/code><\/pre>\n\n\n\n<p>Install a cronjob and never again worry about certificate renewal!<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is SSL, what&#8217;s a CA and what do I need it for? SSL or nowadays TLS is used to encrypt communication and validate the identity of a service provider.The CA is what establishes the trust in a certificate. In short: if the certificate presented (e.g. by the server) and the CA certificate (you trust &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.nikster.de\/wordpress\/index.php\/2019\/05\/05\/how-to-ssl-certificates-for-your-services\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to SSL Certificates for your services&#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":[7],"tags":[9,18,12,11,17,8],"class_list":["post-32","post","type-post","status-publish","format-standard","hentry","category-basics","tag-ca","tag-how-to","tag-howto","tag-letsencrypt","tag-openssl-ca","tag-ssl","entry"],"_links":{"self":[{"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/32","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=32"}],"version-history":[{"count":1,"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/32\/revisions"}],"predecessor-version":[{"id":33,"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/32\/revisions\/33"}],"wp:attachment":[{"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=32"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=32"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}