0017.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Setting Up DD-WRT OpenVPN Server and Certificate Creation</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  7. <script type="text/javascript">
  8. $(function(){
  9. $('textarea').each(function(i,e){
  10. theTextarea = $(this);
  11. theTextarea.height((theTextarea[0].scrollHeight-5) +'px');
  12. });
  13. $('li').each(function(i,e){
  14. if(!$(this).hasClass('noCheckbox')){
  15. var uuid = 'li_' + Math.floor(Math.random() * Math.floor(1000000)).toString() + '_' + i.toString();
  16. $(this).contents().wrap('<span id="'+ uuid +'"><label for="cb_'+ uuid +'"></label></span>');
  17. $(this).prepend('<input type="checkbox" class="completeBox" id="cb_' + uuid +'" rel="'+ uuid +'" />')
  18. }
  19. });
  20. $('code,div.codeBlock,textarea.codeBlock').each(function(i,e){
  21. theElement = $(this);
  22. var lines = theElement.html().split("\n");
  23. theElement.empty();
  24. for(l=0;l<lines.length;l++){
  25. if($.trim(lines[l]) != '' && $.trim(lines[l]).substr(0,1) != '#' && $.trim(lines[l]).indexOf(' #') == -1 && lines[l].substr(0, 4).toUpperCase() != 'REM '){
  26. theElement.append('<input type="image" src="images/clipboard.png" value="" class="copy-text" rel="copy_'+ i +'_'+ l +'" data-clipboard-text="'+ $.trim(lines[l].replace(/"/g, '&quot;')) +'" /><span id="copy_'+ i +'_'+ l +'">'+ lines[l] +'</span>');
  27. } else {
  28. theElement.append(lines[l]);
  29. }
  30. }
  31. });
  32. $(document).on('click','input.copy-text',function(){
  33. theButton = $(this);
  34. $('input.copy-text').attr('src','images/clipboard.png');
  35. $('span.copy-animation,span.copy-animation-ps').removeClass('copy-animation copy-animation-ps');
  36. try {
  37. if($('#'+ theButton.attr('rel')).parent('div').hasClass('PS')){
  38. $('#'+ theButton.attr('rel')).addClass('copy-animation-ps');
  39. } else if($('#'+ theButton.attr('rel')).parent('div').hasClass('CMD')){
  40. $('#'+ theButton.attr('rel')).addClass('copy-animation-cmd');
  41. } else {
  42. $('#'+ theButton.attr('rel')).addClass('copy-animation');
  43. }
  44. navigator.clipboard.writeText(theButton.data('clipboard-text').replace(/<[^>]*>?/gm, ''));
  45. theButton.attr('src','images/clipboard_active.png');
  46. } catch(err) {
  47. }
  48. return false;
  49. });
  50. $(document).on('click','input.completeBox',function(){
  51. theBox = $(this);
  52. $('#'+ theBox.attr('rel')).addClass('strikethrough');
  53. theBox.prop('disabled',true);
  54. theBox.parent('li').prevAll().each(function(i,e){
  55. theLI = $(this);
  56. if(theLI.find('input[type=checkbox]').not(':checked')){
  57. $('#'+ theLI.find('input[type=checkbox]').attr('rel')).addClass('strikethrough');
  58. theLI.find('input[type=checkbox]').prop('checked',true).prop('disabled',true);
  59. }
  60. });
  61. });
  62. if(window.self !== window.top){
  63. window.parent.$('iframe.stepsFrame').height((this['scrollingElement']['scrollHeight']+20) +'px');
  64. }
  65. });
  66. </script>
  67. <link href="css/steps.css" rel="stylesheet" type="text/css" />
  68. </head>
  69. <body>
  70. <div id="gridContainer">
  71. <div class="topMargin"></div>
  72. <div id="listName" class="topMargin">
  73. <h1>Setting Up DD-WRT OpenVPN Server and Certificate Creation</h1>
  74. </div>
  75. <div></div>
  76. <div id="content">
  77. <p>This is part five of a series of creating your own self-signed PKI and some ways to utilize the PKI to setup SSL for your web server or create your own OpenVPN server.</p>
  78. <p>Disclaimer: I am not a security expert. This is just demonstrating an easy way to get OpenVPN up and running to allow access to a remote network from anywhere in the world.</p>
  79. <p>For increased security, use a non-standard TCP or UDP port for your OpenVPN server, making sure to update the client &quot;remote&quot; line with the matching port number.</p>
  80. <p>In this tutorial I am running DD-WRT in a VirtualBox VM. Learn how at https://www.youtube.com/watch?v=BRLukj4dZxk</p>
  81. <h2>Create Required Certificates</h2>
  82. <ol>
  83. <li>Launch XCA</li>
  84. <li>Open the PKI database if it is not already (File &gt; Open DataBase), enter password</li>
  85. <li>Click on the Certificates tab, right click on your Intermediate CA certificate</li>
  86. <li>Select New</li>
  87. <li>On the Source tab, make sure Use this Certificate for signing is selected</li>
  88. <li>Verify your Intermediate CA certificate is selected from the drop down</li>
  89. <li>Click the Subject tab</li>
  90. <li>Complete the Distinguished Name section
  91. <p>internalName: OpenVPN Server<br />
  92. countryName: US<br />
  93. stateOrProvinceName: Virginia<br />
  94. localityName: Northern<br />
  95. organizationName: i12bretro<br />
  96. organizationUnitName: i12bretro Certificate Authority<br />
  97. commonName: vpn.i12bretro.local</p>
  98. </li>
  99. <li>Click the Generate a New Key button</li>
  100. <li>Enter a name and set the key size to at least 2048</li>
  101. <li>Click Create</li>
  102. <li>Click on the Extensions tab</li>
  103. <li>Set the Type dropdown to End Endity</li>
  104. <li>Check the box next to Subject Key Identifier</li>
  105. <li>Update the validity dates to fit your needs</li>
  106. <li>Click the Key Usage tab</li>
  107. <li>Under Key Usage select Digital Signature and Key Encipherment</li>
  108. <li>Under Extended Key Usage select TLS Web Server Authentication</li>
  109. <li>Click the Netscape tab</li>
  110. <li>Deselect all options and clear the Netscape Comment field</li>
  111. <li>Click OK to create the certificate</li>
  112. <li>Click on the Certificates tab, right click on your Intermediate CA certificate again</li>
  113. <li>Select New</li>
  114. <li>On the Source tab, make sure Use this Certificate for signing is selected</li>
  115. <li>Verify your Intermediate CA certificate is selected from the drop down</li>
  116. <li>Click the Subject tab</li>
  117. <li>Complete the Distinguished Name section
  118. <p>internalName: OpenVPN Client #1<br />
  119. countryName: US<br />
  120. stateOrProvinceName: Virginia<br />
  121. localityName: Northern<br />
  122. organizationName: i12bretro<br />
  123. organizationUnitName: i12bretro Certificate Authority<br />
  124. commonName: VPN Client 1</p>
  125. </li>
  126. <li>Click the Generate a New Key button</li>
  127. <li>Enter a name and set the key size to at least 2048</li>
  128. <li>Click Create</li>
  129. <li>Click on the Extensions tab</li>
  130. <li>Set the Type dropdown to End Endity</li>
  131. <li>Check the box next to Subject Key Identifier</li>
  132. <li>Update the validity dates to fit your needs</li>
  133. <li>Click the Key Usage tab</li>
  134. <li>Under Key Usage select Digital Signature, Key Agreement</li>
  135. <li>Under Extended Key Usage select TLS Web Client Authentication</li>
  136. <li>Click the Netscape tab</li>
  137. <li>Deselect all options and clear the Netscape Comment field</li>
  138. <li>Click OK to create the certificate</li>
  139. <li>On the Certificates tab, click the OpenVPN Server certificate</li>
  140. <li>Select Extra &gt; Generate DH Parameter</li>
  141. <li>Type 2048 for DH parameter bits</li>
  142. <li>Click OK</li>
  143. <li>Select a location for dh2048.pem and click Save</li>
  144. </ol>
  145. <h2>Exporting Required Files for OpenVPN</h2>
  146. <ol>
  147. <li>In XCA, click on the Certificates tab</li>
  148. <li>Right click the Intermediate CA certificate &gt; Export &gt; File</li>
  149. <li>Set the file name with a .pem extension and verify the export format is PEM chain (*.pem)</li>
  150. <li>Click OK</li>
  151. <li>Right click the OpenVPN Server certificate &gt; Export &gt; File</li>
  152. <li>Set the file name with a .crt extension and verify the export format is PEM (*.crt)</li>
  153. <li>Click OK</li>
  154. <li>Right click the OpenVPN Client #1 certificate &gt; Export &gt; File</li>
  155. <li>Set the file name with a .crt extension and verify the export format is PEM (*.crt)</li>
  156. <li>Click OK</li>
  157. <li>Click on the Private Keys tab</li>
  158. <li>Right click the OpenVPN Server key &gt; Export &gt; File</li>
  159. <li>Set the file name with a .pk8 extension and verify the export format is PKCS #8 (*.pk8)</li>
  160. <li>Click OK</li>
  161. <li>Right click the OpenVPN Client #1 key&gt; Export &gt; File</li>
  162. <li>Set the file name with a .pk8 extension and verify the export format is PKCS #8 (*.pk8)</li>
  163. <li>Click OK</li>
  164. </ol>
  165. <h2>Setting Up OpenVPN Server in DD-WRT</h2>
  166. <ol>
  167. <li>Open a web browser and navigate to your DD-WRT IP address</li>
  168. <li>Login when prompted</li>
  169. <li>Select the Administration tab</li>
  170. <li>Select the Backup sub tab</li>
  171. <li>Click Backup at the very bottom</li>
  172. <li>Save the nvrambak file somewhere safe</li>
  173. <li>Select the Services tab</li>
  174. <li>Select the VPN sub tab</li>
  175. <li>Scroll down and select enable next to OpenVPN under the OpenVPN Server/Daemon header</li>
  176. <li>Set the OpenVPN Settings as the following:
  177. <ol start="1" style="list-style-type: lower-alpha;">
  178. <li>Start Type: System</li>
  179. <li>Config as: Server</li>
  180. <li>Server mode: Router (TUN)</li>
  181. <li>Network: 10.10.28.0</li>
  182. <li>Netmask: 255.255.255.0</li>
  183. <li>Port: 1194</li>
  184. <li>Tunnel Protocol: TCP</li>
  185. <li>Encyption Cipher: AES-256 GCM</li>
  186. <li>Hash Algorithm: SHA256</li>
  187. <li>Advanced Options: Enable</li>
  188. <li>TLS Cipher: TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384</li>
  189. <li>Compression: Compress lz4-v2</li>
  190. <li>Redirect default Gateway: Disable</li>
  191. <li>Allow Client to Client: Enable</li>
  192. <li>Allow duplicate CN: Disable</li>
  193. <li>Tunnel MT setting: 1500</li>
  194. <li>Tunnel UDP MSS-Fix: Disable</li>
  195. </ol>
  196. </li>
  197. <li>Paste the contents of OpenVPN_Server.crt into the Public Server Cert field</li>
  198. <li>Paste the contents of CA_Chain.pem into the CA Cert field</li>
  199. <li>Paste the contents of OpenVPN_Server.pem into the Private Server Key field</li>
  200. <li>Paste the contents of dh2048.pem into the DH PEM field</li>
  201. <li>Paste the following into the Additional Config field:
  202. <p>push &quot;route-gateway 10.10.27.27&quot;<br />
  203. push &quot;route 10.10.27.0 255.255.255.0&quot;<br />
  204. push &quot;dhcp-option DNS 10.10.27.1&quot;<br />
  205. push &quot;dhcp-option DNS 208.67.222.222&quot;</p>
  206. </li>
  207. <li>Note in the above:<br />
  208. route-gateway is the IP address of the internet gateway on your local network<br />
  209. route is the subnet of your local network<br />
  210. dhcp-option DNS sets DNS servers, in my case my domain controller and an OpenDNS server</li>
  211. <li>Click Save at the bottom</li>
  212. <li>Click Apply Settings</li>
  213. <li>Click the Administration tab</li>
  214. <li>Click the Command sub tab</li>
  215. <li>Paste the following into the Commands field
  216. <p>iptables -t nat -I PREROUTING -p udp --dport 1194 -j ACCEPT<br />
  217. iptables -I INPUT -p udp --dport 1194 -j ACCEPT<br />
  218. iptables -t nat -I PREROUTING -p tcp --dport 1194 -j ACCEPT<br />
  219. iptables -I INPUT -p tcp --dport 1194 -j ACCEPT<br />
  220. iptables -I INPUT -i tun2 -j ACCEPT<br />
  221. iptables -I FORWARD -i tun2 -j ACCEPT<br />
  222. iptables -I FORWARD -o tun2 -j ACCEPT<br />
  223. iptables -t nat -A POSTROUTING -s 10.10.28.0/24 -o eth0 -j MASQUERADE</p>
  224. </li>
  225. <li>Click Save Firewall at the bottom</li>
  226. <li>Click the Management sub tab</li>
  227. <li>Click Reboot Router at the very bottom</li>
  228. </ol>
  229. <h2>Installing OpenVPN Client Software and Testing</h2>
  230. <ol>
  231. <li>Download the OpenVPN software <a href="https://openvpn.net/community-downloads/" target="_blank">Download</a></li>
  232. <li>Run the installer with all the default values</li>
  233. <li>Click the Start button and search OpenVPN GUI</li>
  234. <li>Select OpenVPN GUI from the results to start the application</li>
  235. </ol>
  236. <h2>Creating the OpenVPN Client Profile</h2>
  237. <ol>
  238. <li>Download the OVPN template <a href="https://drive.google.com/open?id=1cwgQfCoQmDOMbY1kW7JK4q07ijHdl37y" target="_blank">Download</a></li>
  239. <li>Rename the .ovpn template something meaningful</li>
  240. <li>Edit the .ovpn template replacing the following:
  241. <p>&lt;#replace with dynamic dns#&gt; with a dynamic DNS or external IP address to your server<br />
  242. &lt;#replace with CA chain#&gt; with the contents of CA_Chain.pem<br />
  243. &lt;#replace with client 1 cert #&gt; with the contents of OpenVPN_Client #1.crt<br />
  244. &lt;#replace with client 1 key #&gt; with the contents of OpenVPN_Client #1.pk8</p>
  245. </li>
  246. <li>Save your changes</li>
  247. <li>Copy the .ovpn template to OpenVPN install directory/config</li>
  248. <li>Right click OpenVPN GUI in the system tray &gt; Connect</li>
  249. </ol>
  250. </div>
  251. </div>
  252. </body>
  253. </html>