0017.html 13 KB

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