{"id":5673,"date":"2016-04-14T15:02:10","date_gmt":"2016-04-14T07:02:10","guid":{"rendered":"http:\/\/rmohan.com\/?p=5673"},"modified":"2016-04-14T15:02:10","modified_gmt":"2016-04-14T07:02:10","slug":"a-on-apache2-4-ssl","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=5673","title":{"rendered":"A+ on apache2.4 ssl"},"content":{"rendered":"<p>Here&#8217;s my config for <strong>apache2.4<\/strong>:<\/p>\n<p><a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2016\/04\/sslas.png\" rel=\"attachment wp-att-5674\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5674\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2016\/04\/sslas.png\" alt=\"sslas\" width=\"690\" height=\"356\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2016\/04\/sslas.png 690w, https:\/\/mohan.sg\/wp-content\/uploads\/2016\/04\/sslas-300x155.png 300w, https:\/\/mohan.sg\/wp-content\/uploads\/2016\/04\/sslas-150x77.png 150w, https:\/\/mohan.sg\/wp-content\/uploads\/2016\/04\/sslas-400x206.png 400w\" sizes=\"(max-width: 690px) 100vw, 690px\" \/><\/a><\/p>\n<p>1) <strong>4096 bit key<\/strong>:<br \/>\nYou will need to generate a 4096 bit key instead of the default 2048 bit key to get the key exchange to 100%. To do this, run <code>letsencrypt-auto<\/code> with this flag: <strong><code>--rsa-key-size 4096<\/code><\/strong><\/p>\n<pre><code>.\/letsencrypt-auto --agree-dev-preview --server \\\r\nhttps:\/\/acme-v01.api.letsencrypt.org\/directory auth --rsa-key-size 4096<\/code><\/pre>\n<p>2) <strong>SSL Settings<\/strong>:<br \/>\nAdd these directives to your apache2 config in the vhost section:<\/p>\n<pre><code>SSLEngine on\r\nSSLCompression off\r\nSSLCipherSuite \"HIGH:!aNULL:!MD5:!3DES:!CAMELLIA:!AES128\"\r\nSSLHonorCipherOrder on\r\nSSLProtocol TLSv1.2\r\nSSLUseStapling on<\/code><\/pre>\n<p>3) <strong>SSL Certificate and Key File Settings<\/strong>:<br \/>\nAlso add these directives to your apache2 config in the same vhost section. Keep in mind you need to update the path to your specific certificate and key that relate to your domain (<strong>&lt;&lt;&lt; YOUR DOMAIN HERE &gt;&gt;&gt;<\/strong>):<\/p>\n<pre><code>SSLCertificateFile \"\/etc\/letsencrypt\/live\/&lt;&lt;&lt; YOUR DOMAIN HERE &gt;&gt;&gt;\/fullchain.pem\"\r\nSSLCertificateKeyFile \"\/etc\/letsencrypt\/live\/&lt;&lt;&lt; YOUR DOMAIN HERE &gt;&gt;&gt;\/privkey.pem\"<\/code><\/pre>\n<p>4) <strong>DH parameters<\/strong>:<br \/>\nGenerate &gt;=4096 dhparams using your openssl binary. This will take some time:<\/p>\n<pre><code>openssl dhparam -out \/etc\/ssl\/private\/dhparams_4096.pem 4096<\/code><\/pre>\n<p><strong>If you have openssl &gt;= 1.0.2d<\/strong> installed (type <strong><code>openssl version<\/code><\/strong> to find out), you can use the following line in your apache2 vhost config:<\/p>\n<pre><code>SSLOpenSSLConfCmd DHParameters \"\/etc\/ssl\/private\/dhparams_4096.pem\"<\/code><\/pre>\n<p><strong>If you do not have openss &gt;= 1.0.2d<\/strong>, you will need to append your dhparameters to the bottom of your certificate file:<\/p>\n<pre><code>cat \/etc\/letsencrypt\/live\/&lt;&lt;&lt; YOUR DOMAIN HERE &gt;&gt;&gt;\/fullchain.pem \\\r\n    \/etc\/ssl\/private\/dhparams_4096.pem &gt; \\\r\n    \/etc\/letsencrypt\/archive\/&lt;&lt;&lt; YOUR DOMAIN HERE &gt;&gt;&gt;\/fullchain_dhparams_4096.pem<\/code><\/pre>\n<p>Then you will use this file in place of your <strong><code>SSLCertificateFile<\/code><\/strong> above:<\/p>\n<pre><code>SSLCertificateFile \"\/etc\/letsencrypt\/archive\/&lt;&lt;&lt; YOUR DOMAIN HERE &gt;&gt;&gt;\/fullchain_dhparams_4096.pem\"<\/code><\/pre>\n<p><strong>Keep in mind that if you manipulate the certificate (issue a new one, etc), you will need to repeat this step as the dhparams will not be added to that certificate!<\/strong><\/p>\n<p>5) <strong>Headers<\/strong>:<br \/>\nYou need to set a Public-Key-Pin header. Generate the first pin against the letsencrypt chain cert with the following code (read more here: <a href=\"https:\/\/raymii.org\/s\/articles\/HTTP_Public_Key_Pinning_Extension_HPKP.html\" rel=\"nofollow\">https:\/\/raymii.org\/s\/articles\/HTTP_Public_Key_Pinning_Extension_HPKP.html<span class=\"badge badge-notification clicks\" title=\"88 clicks\">88<\/span><\/a>):<\/p>\n<pre><code>openssl x509 -noout -in \/etc\/letsencrypt\/live\/&lt;&lt;&lt;&lt; YOUR DOMAIN HERE &gt;&gt;&gt;&gt;\/chain.pem -pubkey | \\\r\nopenssl asn1parse -noout -inform pem -out \/tmp\/fingerprint.key;\r\nopenssl dgst -sha256 -binary \/tmp\/fingerprint.key | openssl enc -base64<\/code><\/pre>\n<p>The next pin comes from your private key. You should keep this key in a safe place:<\/p>\n<pre><code>openssl x509 -noout -in \/etc\/letsencrypt\/live\/&lt;&lt;&lt;&lt; YOUR DOMAIN HERE &gt;&gt;&gt;&gt;\/privkey.pem -pubkey | \\\r\nopenssl asn1parse -noout -inform pem -out \/tmp\/fingerprint.key;\r\nopenssl dgst -sha256 -binary \/tmp\/fingerprint.key | openssl enc -base64<\/code><\/pre>\n<p>You will use these fingerprints in the section below (<strong>&lt;&lt;&lt; YOUR CUSTOM PIN HERE &gt;&gt;&gt;<\/strong>).<\/p>\n<p>I haven&#8217;t figured out a good programmatic way to get the chain cert keys, but I have found that you can get them with <a href=\"https:\/\/dev.ssllabs.com\/ssltest\/analyze.html\" rel=\"nofollow\">https:\/\/dev.ssllabs.com\/ssltest\/analyze.html<span class=\"badge badge-notification clicks\" title=\"70 clicks\">70<\/span><\/a> by analyzing your own site once it&#8217;s already running.<\/p>\n<p>Also add these directives to your apache2 config in the same vhost section:<\/p>\n<pre><code>Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure\r\nHeader always set Public-Key-Pins \"pin-sha256=\\\"&lt;&lt;&lt; YOUR CHAIN PIN HERE &gt;&gt;&gt;=\\\"; pin-sha256=\\\"&lt;&lt;&lt; YOUR PRIVATE KEY PIN HERE &gt;&gt;&gt;\\\"; max-age=31536000; includeSubDomains\"\r\nHeader always set X-Frame-Options SAMEORIGIN\r\nHeader always set Strict-Transport-Security \"max-age=31536000; includeSubdomains; preload\"\r\nHeader always set X-Content-Type-Options nosniff<\/code><\/pre>\n<p>6) <strong>SSL Stapling Cache<\/strong>:<br \/>\nAdd the following line to your ssl.conf <strong><code>\/etc\/apache2\/conf-available\/ssl.conf<\/code><\/strong> file:<\/p>\n<pre><code>echo 'SSLStaplingCache shmcb:\/tmp\/stapling_cache(2097152)' &gt;&gt; \\\r\n\/etc\/apache2\/conf-available\/ssl.conf`<\/code><\/pre>\n<p>Enable your <strong><code>ssl.conf<\/code><\/strong> file:<\/p>\n<pre><code>a2enconf ssl<\/code><\/pre>\n<p>7) <strong>Restart Apache<\/strong>:<\/p>\n<pre><code>service apache2 restart<\/code><\/pre>\n<p>8) Test your site at <a href=\"https:\/\/www.ssllabs.com\/ssltest\/analyze.html\" rel=\"nofollow\">https:\/\/www.ssllabs.com\/ssltest\/analyze.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s my config for apache2.4:<\/p>\n<\/p>\n<p>1) 4096 bit key: You will need to generate a 4096 bit key instead of the default 2048 bit key to get the key exchange to 100%. To do this, run letsencrypt-auto with this flag: &#8211;rsa-key-size 4096<\/p>\n<p> .\/letsencrypt-auto &#8211;agree-dev-preview &#8211;server \\ https:\/\/acme-v01.api.letsencrypt.org\/directory auth &#8211;rsa-key-size 4096 <\/p>\n<p>2) SSL Settings: Add [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5673"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5673"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5673\/revisions"}],"predecessor-version":[{"id":5675,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5673\/revisions\/5675"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}