0017.html 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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" src="includes/js/steps.js"></script>
  13. <link href="css/steps.css" rel="stylesheet" type="text/css" />
  14. </head>
  15. <body>
  16. <div id="gridContainer">
  17. <div class="topMargin"></div>
  18. <div id="listName" class="topMargin">
  19. <h1>Setting Up DD-WRT OpenVPN Server and Certificate Creation</h1>
  20. </div>
  21. <div></div>
  22. <div id="content">
  23. <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>
  24. <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>
  25. <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>
  26. <p>In this tutorial I am running DD-WRT in a VirtualBox VM. Learn how at https://www.youtube.com/watch?v=BRLukj4dZxk</p>
  27. <h2>Create Required Certificates</h2>
  28. <ol>
  29. <li>Launch XCA</li>
  30. <li>Open the PKI database if it is not already (File &gt; Open DataBase), enter password</li>
  31. <li>Click on the Certificates tab, right click on your Intermediate CA certificate</li>
  32. <li>Select New</li>
  33. <li>On the Source tab, make sure Use this Certificate for signing is selected</li>
  34. <li>Verify your Intermediate CA certificate is selected from the drop down</li>
  35. <li>Click the Subject tab</li>
  36. <li>Complete the Distinguished Name section
  37. <p>internalName: OpenVPN Server<br />
  38. countryName: US<br />
  39. stateOrProvinceName: Virginia<br />
  40. localityName: Northern<br />
  41. organizationName: i12bretro<br />
  42. organizationUnitName: i12bretro Certificate Authority<br />
  43. commonName: vpn.i12bretro.local</p>
  44. </li>
  45. <li>Click the Generate a New Key button</li>
  46. <li>Enter a name and set the key size to at least 2048</li>
  47. <li>Click Create</li>
  48. <li>Click on the Extensions tab</li>
  49. <li>Set the Type dropdown to End Endity</li>
  50. <li>Check the box next to Subject Key Identifier</li>
  51. <li>Update the validity dates to fit your needs</li>
  52. <li>Click the Key Usage tab</li>
  53. <li>Under Key Usage select Digital Signature and Key Encipherment</li>
  54. <li>Under Extended Key Usage select TLS Web Server Authentication</li>
  55. <li>Click the Netscape tab</li>
  56. <li>Deselect all options and clear the Netscape Comment field</li>
  57. <li>Click OK to create the certificate</li>
  58. <li>Click on the Certificates tab, right click on your Intermediate CA certificate again</li>
  59. <li>Select New</li>
  60. <li>On the Source tab, make sure Use this Certificate for signing is selected</li>
  61. <li>Verify your Intermediate CA certificate is selected from the drop down</li>
  62. <li>Click the Subject tab</li>
  63. <li>Complete the Distinguished Name section
  64. <p>internalName: OpenVPN Client #1<br />
  65. countryName: US<br />
  66. stateOrProvinceName: Virginia<br />
  67. localityName: Northern<br />
  68. organizationName: i12bretro<br />
  69. organizationUnitName: i12bretro Certificate Authority<br />
  70. commonName: VPN Client 1</p>
  71. </li>
  72. <li>Click the Generate a New Key button</li>
  73. <li>Enter a name and set the key size to at least 2048</li>
  74. <li>Click Create</li>
  75. <li>Click on the Extensions tab</li>
  76. <li>Set the Type dropdown to End Endity</li>
  77. <li>Check the box next to Subject Key Identifier</li>
  78. <li>Update the validity dates to fit your needs</li>
  79. <li>Click the Key Usage tab</li>
  80. <li>Under Key Usage select Digital Signature, Key Agreement</li>
  81. <li>Under Extended Key Usage select TLS Web Client Authentication</li>
  82. <li>Click the Netscape tab</li>
  83. <li>Deselect all options and clear the Netscape Comment field</li>
  84. <li>Click OK to create the certificate</li>
  85. <li>On the Certificates tab, click the OpenVPN Server certificate</li>
  86. <li>Select Extra &gt; Generate DH Parameter</li>
  87. <li>Type 2048 for DH parameter bits</li>
  88. <li>Click OK</li>
  89. <li>Select a location for dh2048.pem and click Save</li>
  90. </ol>
  91. <h2>Exporting Required Files for OpenVPN</h2>
  92. <ol>
  93. <li>In XCA, click on the Certificates tab</li>
  94. <li>Right click the Intermediate CA certificate &gt; Export &gt; File</li>
  95. <li>Set the file name with a .pem extension and verify the export format is PEM chain (*.pem)</li>
  96. <li>Click OK</li>
  97. <li>Right click the OpenVPN Server certificate &gt; Export &gt; File</li>
  98. <li>Set the file name with a .crt extension and verify the export format is PEM (*.crt)</li>
  99. <li>Click OK</li>
  100. <li>Right click the OpenVPN Client #1 certificate &gt; Export &gt; File</li>
  101. <li>Set the file name with a .crt extension and verify the export format is PEM (*.crt)</li>
  102. <li>Click OK</li>
  103. <li>Click on the Private Keys tab</li>
  104. <li>Right click the OpenVPN Server key &gt; Export &gt; File</li>
  105. <li>Set the file name with a .pk8 extension and verify the export format is PKCS #8 (*.pk8)</li>
  106. <li>Click OK</li>
  107. <li>Right click the OpenVPN Client #1 key&gt; Export &gt; File</li>
  108. <li>Set the file name with a .pk8 extension and verify the export format is PKCS #8 (*.pk8)</li>
  109. <li>Click OK</li>
  110. </ol>
  111. <h2>Setting Up OpenVPN Server in DD-WRT</h2>
  112. <ol>
  113. <li>Open a web browser and navigate to your DD-WRT IP address</li>
  114. <li>Login when prompted</li>
  115. <li>Select the Administration tab</li>
  116. <li>Select the Backup sub tab</li>
  117. <li>Click Backup at the very bottom</li>
  118. <li>Save the nvrambak file somewhere safe</li>
  119. <li>Select the Services tab</li>
  120. <li>Select the VPN sub tab</li>
  121. <li>Scroll down and select enable next to OpenVPN under the OpenVPN Server/Daemon header</li>
  122. <li>Set the OpenVPN Settings as the following:
  123. <ol start="1" style="list-style-type: lower-alpha;">
  124. <li>Start Type: System</li>
  125. <li>Config as: Server</li>
  126. <li>Server mode: Router (TUN)</li>
  127. <li>Network: 10.10.28.0</li>
  128. <li>Netmask: 255.255.255.0</li>
  129. <li>Port: 1194</li>
  130. <li>Tunnel Protocol: TCP</li>
  131. <li>Encyption Cipher: AES-256 GCM</li>
  132. <li>Hash Algorithm: SHA256</li>
  133. <li>Advanced Options: Enable</li>
  134. <li>TLS Cipher: TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384</li>
  135. <li>Compression: Compress lz4-v2</li>
  136. <li>Redirect default Gateway: Disable</li>
  137. <li>Allow Client to Client: Enable</li>
  138. <li>Allow duplicate CN: Disable</li>
  139. <li>Tunnel MT setting: 1500</li>
  140. <li>Tunnel UDP MSS-Fix: Disable</li>
  141. </ol>
  142. </li>
  143. <li>Paste the contents of OpenVPN_Server.crt into the Public Server Cert field</li>
  144. <li>Paste the contents of CA_Chain.pem into the CA Cert field</li>
  145. <li>Paste the contents of OpenVPN_Server.pem into the Private Server Key field</li>
  146. <li>Paste the contents of dh2048.pem into the DH PEM field</li>
  147. <li>Paste the following into the Additional Config field:
  148. <p>push &quot;route-gateway 10.10.27.27&quot;<br />
  149. push &quot;route 10.10.27.0 255.255.255.0&quot;<br />
  150. push &quot;dhcp-option DNS 10.10.27.1&quot;<br />
  151. push &quot;dhcp-option DNS 208.67.222.222&quot;</p>
  152. </li>
  153. <li>Note in the above:<br />
  154. route-gateway is the IP address of the internet gateway on your local network<br />
  155. route is the subnet of your local network<br />
  156. dhcp-option DNS sets DNS servers, in my case my domain controller and an OpenDNS server</li>
  157. <li>Click Save at the bottom</li>
  158. <li>Click Apply Settings</li>
  159. <li>Click the Administration tab</li>
  160. <li>Click the Command sub tab</li>
  161. <li>Paste the following into the Commands field
  162. <p>iptables -t nat -I PREROUTING -p udp --dport 1194 -j ACCEPT<br />
  163. iptables -I INPUT -p udp --dport 1194 -j ACCEPT<br />
  164. iptables -t nat -I PREROUTING -p tcp --dport 1194 -j ACCEPT<br />
  165. iptables -I INPUT -p tcp --dport 1194 -j ACCEPT<br />
  166. iptables -I INPUT -i tun2 -j ACCEPT<br />
  167. iptables -I FORWARD -i tun2 -j ACCEPT<br />
  168. iptables -I FORWARD -o tun2 -j ACCEPT<br />
  169. iptables -t nat -A POSTROUTING -s 10.10.28.0/24 -o eth0 -j MASQUERADE</p>
  170. </li>
  171. <li>Click Save Firewall at the bottom</li>
  172. <li>Click the Management sub tab</li>
  173. <li>Click Reboot Router at the very bottom</li>
  174. </ol>
  175. <h2>Installing OpenVPN Client Software and Testing</h2>
  176. <ol>
  177. <li>Download the OpenVPN software <a href="https://openvpn.net/community-downloads/" target="_blank">Download</a></li>
  178. <li>Run the installer with all the default values</li>
  179. <li>Click the Start button and search OpenVPN GUI</li>
  180. <li>Select OpenVPN GUI from the results to start the application</li>
  181. </ol>
  182. <h2>Creating the OpenVPN Client Profile</h2>
  183. <ol>
  184. <li>Download the OVPN template <a href="https://drive.google.com/open?id=1cwgQfCoQmDOMbY1kW7JK4q07ijHdl37y" target="_blank">Download</a></li>
  185. <li>Rename the .ovpn template something meaningful</li>
  186. <li>Edit the .ovpn template replacing the following:
  187. <p>&lt;#replace with dynamic dns#&gt; with a dynamic DNS or external IP address to your server<br />
  188. &lt;#replace with CA chain#&gt; with the contents of CA_Chain.pem<br />
  189. &lt;#replace with client 1 cert #&gt; with the contents of OpenVPN_Client #1.crt<br />
  190. &lt;#replace with client 1 key #&gt; with the contents of OpenVPN_Client #1.pk8</p>
  191. </li>
  192. <li>Save your changes</li>
  193. <li>Copy the .ovpn template to OpenVPN install directory/config</li>
  194. <li>Right click OpenVPN GUI in the system tray &gt; Connect</li>
  195. </ol>
  196. </div>
  197. </div>
  198. </body>
  199. </html>