{"id":1049,"date":"2012-01-12T00:09:19","date_gmt":"2012-01-12T04:09:19","guid":{"rendered":"https:\/\/lowtek.ca\/roo\/?p=1049"},"modified":"2012-01-12T00:09:19","modified_gmt":"2012-01-12T04:09:19","slug":"ubuntu-apache2-trusted-ssl-certificate-from-startssl","status":"publish","type":"post","link":"https:\/\/lowtek.ca\/roo\/2012\/ubuntu-apache2-trusted-ssl-certificate-from-startssl\/","title":{"rendered":"Ubuntu Apache2 &#8220;trusted&#8221; SSL Certificate from StartSSL"},"content":{"rendered":"<p><a href=\"https:\/\/lowtek.ca\/roo\/wp-content\/uploads\/2012\/01\/https_lowtek.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1050\" title=\"https_lowtek\" src=\"https:\/\/lowtek.ca\/roo\/wp-content\/uploads\/2012\/01\/https_lowtek.png\" alt=\"\" width=\"500\" height=\"81\" \/><\/a><\/p>\n<p>I own the domain <a href=\"https:\/\/lowtek.ca\">lowtek.ca<\/a> and host a couple of personal projects as well as this blog on it. One of the areas is behind a password and that part of the site I redirect over to <a href=\"http:\/\/en.wikipedia.org\/wiki\/Https\">https<\/a> to ensure that the communication is encrypted. While the whole Certificate Authority infrastructure has currently become questioned, the value of having a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Secure_Sockets_Layer\">SSL<\/a> connection between your browser and (hopefully) a specific destination machine still has value. I found a humorous <a href=\"http:\/\/www.youtube.com\/watch?v=SJJmoDZ3il8\">youtube video<\/a> that describes SSL basics if this is new to you.<\/p>\n<p>If you were watching the tech news, you&#8217;ll have seen several of the CA&#8217;s had\u00a0<a href=\"http:\/\/tech.slashdot.org\/story\/11\/10\/28\/1954201\/four-cas-have-been-compromised-since-june\">security breaches<\/a>. Even\u00a0<a href=\"http:\/\/en.wikipedia.org\/wiki\/StartCom\">StartSSL<\/a>\u00a0which this post will talk about using had\u00a0<a href=\"http:\/\/www.eweek.com\/c\/a\/Security\/Another-Certificate-Authority-Compromised-No-Fake-SSL-Certificates-Issued-107625\/\">some<\/a>\u00a0<a href=\"http:\/\/www.theregister.co.uk\/2011\/06\/21\/startssl_security_breach\/\">issues<\/a>, but it seems that\u00a0<a href=\"https:\/\/github.com\/diaspora\/diaspora\/issues\/2099\">it wasn&#8217;t as bad<\/a>\u00a0as the others. There has even been some\u00a0<a href=\"http:\/\/www.phreedom.org\/research\/rogue-ca\/\">research into how to attack \/ break SSL<\/a>\u00a0entirely. The web is a scary place if you think too much about this stuff. Today SSL is the most convenient web security story there is, and for the most part it works well enough.<\/p>\n<p>For most people hosting personal websites the simple path is to use a<a href=\"http:\/\/en.wikipedia.org\/wiki\/Self-signed_certificate\"> self signed certificate<\/a>. \u00a0The one downside to this is that whatever browser you are using will not recognize the certificate as valid, you&#8217;ll either be prompted to download and remember it &#8211; or just trust it for this one session. The manner in which browsers trust commercial web sites https connections is the certificates are issued by one of the root CA&#8217;s (<a href=\"http:\/\/en.wikipedia.org\/wiki\/Certificate_authority\">Certificate Authority<\/a>). The CA is a trusted 3rd party which the browser can check with to validate the certificate the website is offering up.<\/p>\n<p>Ubuntu has some guides on <a href=\"https:\/\/help.ubuntu.com\/11.10\/serverguide\/C\/certificates-and-security.html\">creating certificates<\/a>. What I&#8217;ll try to do here is provide a specific example of using StartSSL to generate a free certificate that is accepted by most web browsers. <a href=\"http:\/\/jasoncodes.com\/posts\/startssl-free-ssl\">Much of the details come from another blog<\/a> that I referenced when creating my <a href=\"http:\/\/en.wikipedia.org\/wiki\/StartCom\">StartSSL<\/a> certificate.<\/p>\n<p>You&#8217;ll probably want to use <a href=\"http:\/\/en.wikipedia.org\/wiki\/Firefox\">FireFox<\/a>. The web interface at <a href=\"http:\/\/www.startssl.com\/\">StartSSL.com<\/a> can be a bit finicky and FireFox is known to work &#8211; I used the somewhat old 3.6.25 version. Of course the first step is to sign-up and create an account on StartSSL. They use email confirmation and my <a href=\"https:\/\/lowtek.ca\/roo\/2011\/greylisting-with-postfix-and-ubuntu\/\">greylisting<\/a> caused a bit of a hiccup here, waiting a few minutes and resubmitting the sign-up succeeded just fine. Then there will be a wizard that takes you through the rest of the sign-up process.<\/p>\n<p>At the end of your account sign up you&#8217;ll be encouraged to back up the client certificate that has been installed into your browser. As I understand it, they use the client certificate as a form of authentication that it is really you they are connected to. The FAQ has details on <a href=\"https:\/\/www.startssl.com\/?app=25#4\">backing up the client certificate<\/a>. If for some reason you lose your client certificate they have a <a href=\"https:\/\/www.startssl.com\/?app=25#14\">FAQ for that too<\/a>.<\/p>\n<p>Next we want to return to the &#8220;<a href=\"https:\/\/www.startssl.com\/?app=11&amp;action=true\">Control Panel<\/a>&#8221; and use the &#8220;Validations Wizard&#8221; to do the &#8220;Domain Name Validation&#8221;. This will require another email validation to ensure that you are the owner of the domain (you&#8217;ll need to be able to receive email for that domain).<\/p>\n<p>Now we can actually create a certificate. There are pay options for certificates, but we want to use the free version. Use the &#8220;Certificates Wizard&#8221; to create a &#8220;Web Server SSL\/TLS Certificate&#8221;. Again I&#8217;ll reference the <a href=\"http:\/\/jasoncodes.com\/posts\/startssl-free-ssl\">very useful blog post from jasoncodes.com<\/a> that describes this set of steps (I will replicate here for completeness).<\/p>\n<p>The first step of creating a certificate we can skip, as we plan to create our own Certificate Signing Request (<a href=\"http:\/\/en.wikipedia.org\/wiki\/Certificate_signing_request\">CSR<\/a>) locally. Execute the follwoing on your server, obviously replacing mydomain.ca with your domain name:<\/p>\n<p><code>openssl req -new -newkey rsa:4096 -days 380 -nodes -keyout mydomain.ca.key -out mydomain.ca.csr<br \/>\n<\/code><br \/>\nThere will be several questions posed to you during this, here is a dump of the questions and some example answers:<\/p>\n<p><code>Country Name (2 letter code) [AU]:CA<br \/>\nState or Province Name (full name) [Some-State]:YourStateOrProvince<br \/>\nLocality Name (eg, city) []:YourCity<br \/>\nOrganization Name (eg, company) [Internet Widgits Pty Ltd]:SomeName<br \/>\nOrganizational Unit Name (eg, section) []:<br \/>\nCommon Name (eg, YOUR name) []:mydomain.ca<br \/>\nEmail Address []:secret_email@mydomain.ca<\/code><\/p>\n<p><code>Please enter the following 'extra' attributes<br \/>\nto be sent with your certificate request<br \/>\nA challenge password []:<br \/>\nAn optional company name []:<\/code><\/p>\n<p>Some of the answers can be blank as should be evident above. If you&#8217;re having trouble with the 2 letter country codes, <a href=\"http:\/\/en.wikipedia.org\/wiki\/ISO_3166-1_alpha-2\">check on wikipedia<\/a>. I did find a reference that suggested that the c<a href=\"http:\/\/www-uxsup.csx.cam.ac.uk\/~jw35\/courses\/using_https\/html\/x280.htm\">ommon name must exactly match the host name of your server<\/a>, you might note that I&#8217;m not using a www prefix here. This will allow me to re-use this same certificate for email and other things in theory, it also follows the <a href=\"https:\/\/lowtek.ca\/roo\/2011\/no-www\/\">no-www<\/a> approach. I opted to <a href=\"http:\/\/www.mail-archive.com\/openssl-users@openssl.org\/msg35862.html\">leave the challenge password blank<\/a>.<\/p>\n<p>The second step of the wizard on StartSSL for creating a certificate will ask for a cut &amp; paste of the <code>mydomain.ca.csr<\/code> we just created. Paste the entire contents of the file in, and move on to the next step where you should see that the request was received.<\/p>\n<p>Moving along the next step is to &#8220;Add Domains&#8221;, since we&#8217;ve only validated one domain this should be easy. As part of this process it will ask for one sub domain. I used &#8220;www&#8221; since that will still resolve correctly to the lowtek.ca domain.<\/p>\n<p>The remainder of the steps should be straight forward, you&#8217;ll arrive at the &#8220;Save Certificate&#8221; screen. You&#8217;ll want to save three things: 1)\u00a0Text box contents as mydomain.ca.crt, then save-as the 2) intermediate and 3) root CA certificates (last two should be sub.class1.server.ca.pem and\u00a0ca.pem respectively).<\/p>\n<p>Now we need to install into Apache2. I&#8217;ll assume you&#8217;re running Ubuntu.<\/p>\n<p>We&#8217;ll start by copying the <code>.crt<\/code> and <code>.pem<\/code> files we saved from the final step on StartSSL into the <code>\/etc\/apache2\/ssl<\/code> directory.\u00a0We also want the <code>.key<\/code> file that was created when we made our CSR copied to the same directory.<\/p>\n<p>Again I must credit <a href=\"http:\/\/jasoncodes.com\/posts\/startssl-free-ssl\">jasoncodes.com<\/a>, this is almost verbatim from his site. Run the following as root.<\/p>\n<p><code>cd \/etc\/apache2\/ssl<br \/>\nmv ca.pem startssl.ca.crt<br \/>\nmv sub.class1.server.ca.pem startssl.sub.class1.server.ca.crt<br \/>\ncat startssl.sub.class1.server.ca.crt startssl.ca.crt &gt; startssl.chain.class1.server.crt<br \/>\ncat mydomain.ca.{key,crt} startssl.chain.class1.server.crt &gt; mydomain.ca.pem<br \/>\nln -sf mydomain.ca.pem apache.pem<br \/>\nchown root:root *.crt *.key *.pem<br \/>\nchmod 640 *.key *.pem<br \/>\n<\/code><br \/>\nNow we need to modify the apache config file\u00a0\/etc\/apache2\/sites-available\/ssl and add the following within the &lt;VirtualHost&gt; block:<\/p>\n<p><code>SSLEngine On<br \/>\nSSLCertificateFile \/etc\/apache2\/ssl\/mydomain.ca.crt<br \/>\nSSLCertificateKeyFile \/etc\/apache2\/ssl\/mydomain.ca.key<br \/>\nSSLCertificateChainFile \/etc\/apache2\/ssl\/startssl.chain.class1.server.crt<\/code><\/p>\n<p>Check that your Apache config parses as valid:<\/p>\n<p><code>apache2ctl -t<\/code><\/p>\n<p>And then restart Apache with the new config:<\/p>\n<p><code>sudo \/etc\/init.d\/apache2 reload<\/code><\/p>\n<p>Here is the the verification process\u00a0verbatim from <a href=\"http:\/\/jasoncodes.com\/posts\/startssl-free-ssl\">jasoncodes.com<\/a>:<\/p>\n<blockquote><p>Run the following after restarting Apache to check the certificate chain:<\/p>\n<p><code>echo HEAD \/ | openssl s_client -connect localhost:443 -quiet &gt; \/dev\/null<\/code><\/p>\n<p>You should see something like:<\/p>\n<p><code>depth=2 \/C=IL\/O=StartCom Ltd.\/OU=Secure Digital Certificate Signing\/CN=StartCom Certification Authority<br \/>\nverify error:num=19:self signed certificate in certificate chain<br \/>\nverify return:0<\/code><\/p>\n<p>A depth of 2 and a return value of 0 is good. If the certificate chain is wrong, you&#8217;ll probably see something like:<\/p>\n<p><code>depth=0 \/description=12345-ABCDEF123456\/C=XX\/O=Persona Not Validated\/OU=StartCom Free Certificate Member\/CN=host.example.com\/emailAddress=hostmaster@example.com<br \/>\nverify error:num=20:unable to get local issuer certificate<br \/>\nverify return:1<br \/>\ndepth=0 \/description=12345-ABCDEF123456\/C=XX\/O=Persona Not Validated\/OU=StartCom Free Certificate Member\/CN=host.example.com\/emailAddress=hostmaster@example.com<br \/>\nverify error:num=27:certificate not trusted<br \/>\nverify return:1<br \/>\ndepth=0 \/description=12345-ABCDEF123456\/C=XX\/O=Persona Not Validated\/OU=StartCom Free Certificate Member\/CN=host.example.com\/emailAddress=hostmaster@example.com<br \/>\nverify error:num=21:unable to verify the first certificate<br \/>\nverify return:1<\/code><\/p><\/blockquote>\n<p>I was pleased to see that it all verified correctly for me. Visiting <a href=\"https:\/\/lowtek.ca\">https:\/\/lowtek.ca<\/a> resulted in a green lock icon under <a href=\"http:\/\/en.wikipedia.org\/wiki\/Google_Chrome\">Google Chrome<\/a>.<\/p>\n<p>The StartSSL certificate expires in 1 year, so next year around this time I&#8217;ll be doing the same process. There is another CA (<a href=\"http:\/\/www.affirmtrust.com\/\">AffirmTrust<\/a>)\u00a0I came across that offers free 3 year certificates, I have no experience with them but would be interested to hear if anyone tries them out. There is <a href=\"http:\/\/www.cacert.org\">CACert<\/a> as well, but it doesn&#8217;t appear to be included in any of the browsers &#8211; limiting the usefulness of a certificate from them.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I own the domain lowtek.ca and host a couple of personal projects as well as this blog on it. One of the areas is behind a password and that part of the site I redirect over to https to ensure that the communication is encrypted. While the whole Certificate Authority infrastructure has currently become questioned, &hellip; <a href=\"https:\/\/lowtek.ca\/roo\/2012\/ubuntu-apache2-trusted-ssl-certificate-from-startssl\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Ubuntu Apache2 &#8220;trusted&#8221; SSL Certificate from StartSSL&#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":[6,12],"tags":[],"class_list":["post-1049","post","type-post","status-publish","format-standard","hentry","category-computing","category-how-to"],"_links":{"self":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts\/1049","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/comments?post=1049"}],"version-history":[{"count":10,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts\/1049\/revisions"}],"predecessor-version":[{"id":1060,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts\/1049\/revisions\/1060"}],"wp:attachment":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/media?parent=1049"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/categories?post=1049"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/tags?post=1049"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}