{"id":83,"date":"2018-10-19T15:30:43","date_gmt":"2018-10-19T18:30:43","guid":{"rendered":"http:\/\/www.joontech.nl\/wordpress\/?p=83"},"modified":"2018-10-19T15:30:43","modified_gmt":"2018-10-19T18:30:43","slug":"certificates-keys-ssl-and-openvpn-on-synology","status":"publish","type":"post","link":"http:\/\/wordpress.joontech.nl\/?p=83","title":{"rendered":"Certificates, keys, SSL and Openvpn on Synology"},"content":{"rendered":"<h1>Crypto-systems and keys<\/h1>\n<p>Nice article here about safer key usage:<br \/>\n<a href=\"https:\/\/blog.g3rt.nl\/upgrade-your-ssh-keys.html\">https:\/\/blog.g3rt.nl\/upgrade-your-ssh-keys.html<\/a><\/p>\n<p>Generate your new sexy Ed25519 key (EdDSA using Twisted Edward curves) and a robust RSA key (Rivest\u2013Shamir\u2013Adleman).<\/p>\n<pre>ssh-keygen -o -a 100 -t ed25519\r\nssh-keygen -t rsa -b 4096 -o -a 100<\/pre>\n<p>Add these to the SSH agent via ssh-add:<\/p>\n<pre>\u00a0ssh-add<\/pre>\n<h1>OpenVPN<\/h1>\n<p>Important reading:<br \/>\n<a href=\"https:\/\/blog.g3rt.nl\/openvpn-security-tips.html\">https:\/\/blog.g3rt.nl\/openvpn-security-tips.html<\/a><\/p>\n<p><a href=\"https:\/\/community.openvpn.net\/openvpn\/wiki\/Concepts-Authentication\">https:\/\/community.openvpn.net\/openvpn\/wiki\/Concepts-Authentication<\/a><\/p>\n<p>There is a good tool that helps you create your key pairs and certificates for\u00a0OpenVPN with Client Certificates called <em>easy-rsa<\/em>. But it does rely on the fact that you are your own Certificate Authority.<\/p>\n<p>We want to use <a href=\"https:\/\/www.cacert.org\/\">CA-Cert<\/a>\u00a0to sign our certificates, so we must make a Certificate Signing Request<\/p>\n<p>Note that OpenSSL and OpenSSH use different formats for there keys. OpenSSH uses a propriety format PKCS#1 PEM-encoded for its private key, OpenSSL uses a standard format IIUC.<\/p>\n<p>For OpenVPN (SSL) we use the OpenSSL toolset to generate the certificates.<br \/>\nI could not find how to convert the private OpenSSH key to a OpenSSL format. So we will regenerate the keys with OpenSSL. (PEM format)<\/p>\n<p>OpenSSL command line cannot create\u00a0Ed25519 keys (not yet, anyway).<\/p>\n<pre>openssl genpkey -algorithm RSA \\\r\n   -pkeyopt rsa_keygen_bits:4096\\\r\n   -pkeyopt rsa_keygen_pubexp:65537 | \\\r\n   openssl pkcs8 -topk8 -nocrypt -outform pem &gt; rsa-4096-private-key.pem\r\n\r\nopenssl pkey -pubout -inform pem -outform pem \\\r\n -in rsa-4096-private-key.pem \\\r\n -out rsa-4096-private-key.spki<\/pre>\n<p>Some interesting readings on OpenSSL:<br \/>\n<a href=\"https:\/\/www.sslshopper.com\/article-most-common-openssl-commands.html\">https:\/\/www.sslshopper.com\/article-most-common-openssl-commands.html<\/a><\/p>\n<p>Generate the CSR, fill in the details as required. You could leave everything empty if the certificate will only be used by OpenVPN. As your email address is not in the certificate, the certificate cannot be used to track you.<\/p>\n<pre>openssl req -new -sha256 -key rsa-4096-private-key.pem -out rsa-4096-private-key.csr<\/pre>\n<p>Send this to\u00a0<a href=\"https:\/\/www.cacert.org\/\">CA-Cert<\/a>, and receive a signed certificate from them by email.<\/p>\n<p>Information from certificates and CSRs can be obtained with this:<\/p>\n<pre>openssl x509 -noout -subject -in\u00a0&lt;certificate&gt;.crt\r\nopenssl req -in &lt;request&gt;.csr -noout -text<\/pre>\n<p>The big question that now pops-up is if we trust\u00a0<a href=\"https:\/\/www.cacert.org\/\">CA-Cert<\/a> enough to let them sign the certificates. If we would be our own Certificate Authority, we would know exactly which certificates we have signed.<\/p>\n<p>If you are using OpenVPN for your organisation it is probably better not to use any public certificates for OpenVPN but create your own CA and only accept certificates issued by this CA. This is actually the way proposed in the\u00a0<a href=\"https:\/\/openvpn.net\/index.php\/open-source\/documentation\/howto.html\" rel=\"nofollow\">OpenVPN Howto<\/a>. This way you are in full control of the certificates and even if some of the public CA&#8217;s gets compromised and issues certificates in your name then none of your OpenVPN endpoints will accept these, because only certificates issued by your own CA gets accepted.<\/p>\n<p>Apart from that: Using a self-signed certificate does not impose a risk by itself, not for VPN and not for HTTPS. The risk is only if the certificate is not fully validated. A self-signed certificate can not be validated without additional information. So if a client connects to a server,\u00a0the connection is\u00a0 encrypted, but the server is not verified.<\/p>\n<p>If the server is not verified a man in the middle attack is possible. This not only includes stealing the VPN credentials but intercepting the traffic or modifying the traffic. Since VPN connections are often considered as safe as internal connections inside the company the attacker can thus get access to interesting data or mount attacks against internal clients.<\/p>\n<p>Knowing this, we will need to add some extra security measures.<\/p>\n<ul>\n<li>Besides certificates, also make use of a Username\/Password combination for the clients.<\/li>\n<li>Get a server certificate for a full domain name. This would make it more difficult for a MitM attach, where you would need to spoof the VPN server.<\/li>\n<li>Let the server verify if the common name used in the client certificate matches the username, and disconnect if not.<br \/>\n<a href=\"https:\/\/github.com\/OpenVPN\/openvpn\/blob\/master\/sample\/sample-scripts\/ucn.pl\">https:\/\/github.com\/OpenVPN\/openvpn\/blob\/master\/sample\/sample-scripts\/ucn.pl<br \/>\n<\/a>Unfortunatly, CaCert does not put the CN in their certificates if you are not a &#8220;Trusted User (WoT)&#8221;.<\/li>\n<\/ul>\n<p>Generate a private key for the VPN server, and a Certificate Signing request. No need for a public key.<\/p>\n<pre>openssl genpkey -algorithm RSA \\\r\n -pkeyopt rsa_keygen_bits:4096\\\r\n -pkeyopt rsa_keygen_pubexp:65537 | \\\r\n openssl pkcs8 -topk8 -nocrypt -outform pem &gt; rsa-4096-server-key.pem\r\n\r\nopenssl req -new -sha256 -key rsa-4096-server-key.pem -extensions server -out rsa-4096-server-key.csr<\/pre>\n<p>If you get the error:<\/p>\n<pre>openssl req -new -sha256 -key rsa-4096-server-key.pem -extensions server -out rsa-4096-server-key.csr \r\nError Loading extension section server<\/pre>\n<p>It means the openssl configuration file ( normally at \u200b<em>\/etc\/ssl\/openssl.cnf<\/em>) is missing this extension. So add it:<\/p>\n<pre>[ server ]\r\n# comment that this section was added manually by myself \r\nnsCertType = server<\/pre>\n<p>Generate the DH parameters<\/p>\n<pre>openssl dhparam 2048 &gt; dh2048.pem<\/pre>\n<p>If you want to harden the security, you could have a look at the openVPN server options:<\/p>\n<pre>username-as-common-name\r\nclient-config-dir &lt;dir&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>openssl x509 -noout -subject -in<\/p>\n<p>Convert one to another with:<\/p>\n<p>openssl pkcs8 -topk8 -in &lt;server.key&gt; -out server-pkcs8.key \u2013nocrypt<\/p>\n<p>&nbsp;<\/p>\n<p>ssh-keygen -o -a 100 -t ed25519 -f &lt;username&gt;.key<\/p>\n<p>openssl req\u00a0-key &lt;username&gt;.key -new -out &lt;username&gt;.csr<\/p>\n<p>&nbsp;<\/p>\n<p>sssh-keygen -f &lt;input&gt;.key -e -m pem<\/p>\n<p>But these are SSH k<\/p>\n<p>&nbsp;<\/p>\n<p>openssl genrsa -des3 -out private.pem 4096<\/p>\n<p>openssl genpkey -algorithm Ed25519 -out ed25519key.pem<\/p>\n<p>openssl req -new -sha256 -key za -out za.csr<\/p>\n<p>\/usr\/syno\/etc\/packages\/VPNCenter\/openvpn<\/p>\n<p>&nbsp;<\/p>\n<p>\/opt\/share\/easy-rsa#<\/p>\n<p>\/var\/packages\/VPNCenter\/target\/scripts\/openvpn.sh {start|stop|restart}<\/p>\n<p>Now, we need to build a router key\/certificate pair:<\/p>\n<p><code>.\/build-key-server server1<\/code><\/p>\n<p>&nbsp;<\/p>\n<p>Generate a private key for the VPN server, and a Certificate Signing request. No need for a public key.<\/p>\n<pre>openssl genpkey -algorithm RSA \\\r\n   -pkeyopt rsa_keygen_bits:4096\\\r\n   -pkeyopt rsa_keygen_pubexp:65537 | \\\r\n   openssl pkcs8 -topk8 -nocrypt -outform pem &gt; rsa-4096-server-key.pem\r\n\r\nopenssl pkey -pubout -inform pem -outform pem \\\r\n -in rsa-4096-server-key.pem \\\r\n -out rsa-4096-server-key.spki\r\n\r\nopenssl req -new -sha256 -key rsa-4096-server-key.pem -extensions server -out rsa-4096-server-key.csr<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Crypto-systems and keys Nice article here about safer key usage: https:\/\/blog.g3rt.nl\/upgrade-your-ssh-keys.html Generate your new sexy Ed25519 key (EdDSA using Twisted Edward curves) and a robust RSA key (Rivest\u2013Shamir\u2013Adleman). ssh-keygen -o -a 100 -t ed25519 ssh-keygen -t rsa -b 4096 -o -a 100 Add these to the SSH agent via ssh-add: \u00a0ssh-add OpenVPN Important reading: https:\/\/blog.g3rt.nl\/openvpn-security-tips.html &hellip; <a href=\"http:\/\/wordpress.joontech.nl\/?p=83\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Certificates, keys, SSL and Openvpn on Synology&#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":[1],"tags":[],"class_list":["post-83","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/wordpress.joontech.nl\/index.php?rest_route=\/wp\/v2\/posts\/83","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wordpress.joontech.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wordpress.joontech.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wordpress.joontech.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/wordpress.joontech.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=83"}],"version-history":[{"count":14,"href":"http:\/\/wordpress.joontech.nl\/index.php?rest_route=\/wp\/v2\/posts\/83\/revisions"}],"predecessor-version":[{"id":97,"href":"http:\/\/wordpress.joontech.nl\/index.php?rest_route=\/wp\/v2\/posts\/83\/revisions\/97"}],"wp:attachment":[{"href":"http:\/\/wordpress.joontech.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=83"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wordpress.joontech.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=83"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wordpress.joontech.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}