swanctl.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. 'use strict';
  2. 'require view';
  3. 'require form';
  4. 'require uci';
  5. 'require tools.widgets as widgets';
  6. 'require strongswan_algorithms';
  7. function validateTimeFormat(section_id, value) {
  8. if (value && !value.match(/^\d+[smhd]$/)) {
  9. return _('Number must have suffix s, m, h or d');
  10. }
  11. return true;
  12. }
  13. function addAlgorithms(o, algorithms) {
  14. algorithms.forEach(function (algorithm) {
  15. if (strongswan_algorithms.isInsecure(algorithm)) {
  16. o.value(algorithm, '%s*'.format(algorithm));
  17. } else {
  18. o.value(algorithm);
  19. }
  20. });
  21. }
  22. return view.extend({
  23. load: function () {
  24. return uci.load('network');
  25. },
  26. render: function () {
  27. let m, s, o;
  28. m = new form.Map('ipsec', _('strongSwan Configuration'),
  29. _('Configure strongSwan for secure VPN connections.'));
  30. m.tabbed = true;
  31. // strongSwan General Settings
  32. s = m.section(form.TypedSection, 'ipsec', _('General Settings'));
  33. s.anonymous = true;
  34. o = s.option(widgets.ZoneSelect, 'zone', _('Zone'),
  35. _('Firewall zone that has to match the defined firewall zone'));
  36. o.default = 'lan';
  37. o.multiple = true;
  38. o = s.option(widgets.NetworkSelect, 'listen', _('Listening Interfaces'),
  39. _('Interfaces that accept VPN traffic'));
  40. o.datatype = 'interface';
  41. o.placeholder = _('Select an interface or leave empty for all interfaces');
  42. o.default = 'wan';
  43. o.multiple = true;
  44. o.rmempty = false;
  45. o = s.option(form.Value, 'debug', _('Debug Level'),
  46. _('Trace level: 0 is least verbose, 4 is most'));
  47. o.default = '0';
  48. o.datatype = 'range(0,4)';
  49. // Remote Configuration
  50. s = m.section(form.GridSection, 'remote', _('Remote Configuration'),
  51. _('Define Remote IKE Configurations.'));
  52. s.addremove = true;
  53. s.nodescriptions = true;
  54. o = s.tab('general', _('General'));
  55. o = s.tab('authentication', _('Authentication'));
  56. o = s.tab('advanced', _('Advanced'));
  57. o = s.taboption('general', form.Flag, 'enabled', _('Enabled'),
  58. _('Configuration is enabled or not'));
  59. o.rmempty = false;
  60. o = s.taboption('general', form.Value, 'gateway', _('Gateway (Remote Endpoint)'),
  61. _('IP address or FQDN name of the tunnel remote endpoint'));
  62. o.datatype = 'or(hostname,ipaddr)';
  63. o.rmempty = false;
  64. o = s.taboption('general', form.Value, 'local_gateway', _('Local Gateway'),
  65. _('IP address or FQDN of the tunnel local endpoint'));
  66. o.datatype = 'or(hostname,ipaddr)';
  67. o.modalonly = true;
  68. o = s.taboption('general', form.Value, 'local_sourceip', _('Local Source IP'),
  69. _('Virtual IP(s) to request in IKEv2 configuration payloads requests'));
  70. o.datatype = 'ipaddr';
  71. o.modalonly = true;
  72. o = s.taboption('general', form.Value, 'local_ip', _('Local IP'),
  73. _('Local address(es) to use in IKE negotiation'));
  74. o.datatype = 'ipaddr';
  75. o.modalonly = true;
  76. o = s.taboption('general', form.MultiValue, 'crypto_proposal', _('Crypto Proposal'),
  77. _('List of IKE (phase 1) proposals to use for authentication'));
  78. o.load = function (section_id) {
  79. this.keylist = [];
  80. this.vallist = [];
  81. var sections = uci.sections('ipsec', 'crypto_proposal');
  82. if (sections.length == 0) {
  83. this.value('', _('Please create a Proposal first'));
  84. } else {
  85. sections.forEach(L.bind(function (section) {
  86. if (section.is_esp != '1') {
  87. this.value(section['.name']);
  88. }
  89. }, this));
  90. }
  91. return this.super('load', [section_id]);
  92. };
  93. o.rmempty = false;
  94. o = s.taboption('general', form.MultiValue, 'tunnel', _('Tunnel'),
  95. _('Name of ESP (phase 2) section'));
  96. o.load = function (section_id) {
  97. this.keylist = [];
  98. this.vallist = [];
  99. var sections = uci.sections('ipsec', 'tunnel');
  100. if (sections.length == 0) {
  101. this.value('', _('Please create a Tunnel first'));
  102. } else {
  103. sections.forEach(L.bind(function (section) {
  104. this.value(section['.name']);
  105. }, this));
  106. }
  107. return this.super('load', [section_id]);
  108. };
  109. o.rmempty = false;
  110. o = s.taboption('authentication', form.ListValue, 'authentication_method',
  111. _('Authentication Method'), _('IKE authentication (phase 1)'));
  112. o.modalonly = true;
  113. o.value('psk', 'Pre-shared Key');
  114. o.value('pubkey', 'Public Key');
  115. o = s.taboption('authentication', form.Value, 'local_identifier', _('Local Identifier'),
  116. _('Local identifier for IKE (phase 1)'));
  117. o.datatype = 'string';
  118. o.placeholder = 'C=US, O=Acme Corporation, CN=headquarters';
  119. o.modalonly = true;
  120. o = s.taboption('authentication', form.Value, 'remote_identifier', _('Remote Identifier'),
  121. _('Remote identifier for IKE (phase 1)'));
  122. o.datatype = 'string';
  123. o.placeholder = 'C=US, O=Acme Corporation, CN=soho';
  124. o.modalonly = true;
  125. o = s.taboption('authentication', form.Value, 'pre_shared_key', _('Pre-Shared Key'),
  126. _('The pre-shared key for the tunnel'));
  127. o.datatype = 'string';
  128. o.password = true;
  129. o.modalonly = true;
  130. o.rmempty = false;
  131. o.depends('authentication_method', 'psk');
  132. o = s.taboption('authentication', form.Value, 'local_cert', _('Local Certificate'),
  133. _('Certificate pathname to use for authentication'));
  134. o.datatype = 'file';
  135. o.depends('authentication_method', 'pubkey');
  136. o.modalonly = true;
  137. o = s.taboption('authentication', form.Value, 'local_key', _('Local Key'),
  138. _('Private key pathname to use with above certificate'));
  139. o.datatype = 'file';
  140. o.modalonly = true;
  141. o = s.taboption('authentication', form.Value, 'ca_cert', _('CA Certificate'),
  142. _("CA certificate that need to lie in remote peer's certificate's path of trust"));
  143. o.datatype = 'file';
  144. o.depends('authentication_method', 'pubkey');
  145. o.modalonly = true;
  146. o = s.taboption('advanced', form.Flag, 'mobike', _('MOBIKE'),
  147. _('MOBIKE (IKEv2 Mobility and Multihoming Protocol)'));
  148. o.default = '1';
  149. o.modalonly = true;
  150. o = s.taboption('advanced', form.ListValue, 'fragmentation', _('IKE Fragmentation'),
  151. _('Use IKE fragmentation'));
  152. o.value('yes');
  153. o.value('no');
  154. o.value('force');
  155. o.value('accept');
  156. o.default = 'yes';
  157. o.modalonly = true;
  158. o = s.taboption('advanced', form.Value, 'keyingretries', _('Keying Retries'),
  159. _('Number of retransmissions attempts during initial negotiation'));
  160. o.datatype = 'uinteger';
  161. o.default = '3';
  162. o.modalonly = true;
  163. o = s.taboption('advanced', form.Value, 'dpddelay', _('DPD Delay'),
  164. _('Interval to check liveness of a peer'));
  165. o.validate = validateTimeFormat;
  166. o.default = '30s';
  167. o.modalonly = true;
  168. o = s.taboption('advanced', form.Value, 'inactivity', _('Inactivity'),
  169. _('Interval before closing an inactive CHILD_SA'));
  170. o.validate = validateTimeFormat;
  171. o.modalonly = true;
  172. o = s.taboption('advanced', form.Value, 'rekeytime', _('Rekey Time'),
  173. _('IKEv2 interval to refresh keying material; also used to compute lifetime'));
  174. o.validate = validateTimeFormat;
  175. o.modalonly = true;
  176. o = s.taboption('advanced', form.Value, 'overtime', _('Overtime'),
  177. _('Limit on time to complete rekeying/reauthentication'));
  178. o.validate = validateTimeFormat;
  179. o.modalonly = true;
  180. o = s.taboption('advanced', form.ListValue, 'keyexchange', _('Keyexchange'),
  181. _('Version of IKE for negotiation'));
  182. o.value('ikev1', 'IKEv1 (%s)', _('deprecated'));
  183. o.value('ikev2', 'IKEv2');
  184. o.value('ike', 'IKE (%s, %s)'.format(_('both'), _('deprecated')));
  185. o.default = 'ikev2';
  186. o.modalonly = true;
  187. // Tunnel Configuration
  188. s = m.section(form.GridSection, 'tunnel', _('Tunnel Configuration'),
  189. _('Define Connection Children to be used as Tunnels in Remote Configurations.'));
  190. s.addremove = true;
  191. s.nodescriptions = true;
  192. o = s.tab('general', _('General'));
  193. o = s.tab('advanced', _('Advanced'));
  194. o = s.taboption('general', form.DynamicList, 'local_subnet', _('Local Subnet'),
  195. _('Local network(s)'));
  196. o.datatype = 'subnet';
  197. o.placeholder = '192.168.1.1/24';
  198. o.rmempty = false;
  199. o = s.taboption('general', form.DynamicList, 'remote_subnet', _('Remote Subnet'),
  200. _('Remote network(s)'));
  201. o.datatype = 'subnet';
  202. o.placeholder = '192.168.2.1/24';
  203. o.rmempty = false;
  204. o = s.taboption('general', form.Value, 'local_nat', _('Local NAT'),
  205. _('NAT range for tunnels with overlapping IP addresses'));
  206. o.datatype = 'subnet';
  207. o.modalonly = true;
  208. o = s.taboption('general', form.ListValue, 'if_id', ('XFRM Interface ID'),
  209. _('XFRM interface ID set on input and output interfaces'));
  210. o.load = function (section_id) {
  211. this.keylist = [];
  212. this.vallist = [];
  213. var xfrmSections = uci.sections('network').filter(function (section) {
  214. return section.proto == 'xfrm';
  215. });
  216. xfrmSections.forEach(L.bind(function (section) {
  217. this.value(section.ifid,
  218. '%s (%s)'.format(section.ifid, section['.name']));
  219. }, this));
  220. return this.super('load', [section_id]);
  221. }
  222. o.optional = true;
  223. o.modalonly = true;
  224. o = s.taboption('general', form.ListValue, 'startaction', _('Start Action'),
  225. _('Action on initial configuration load'));
  226. o.value('none');
  227. o.value('trap');
  228. o.value('start');
  229. o.default = 'trap';
  230. o.modalonly = true;
  231. o = s.taboption('general', form.ListValue, 'closeaction', _('Close Action'),
  232. _('Action when CHILD_SA is closed'));
  233. o.value('none');
  234. o.value('trap');
  235. o.value('start');
  236. o.optional = true;
  237. o.modalonly = true;
  238. o = s.taboption('general', form.MultiValue, 'crypto_proposal',
  239. _('Crypto Proposal (Phase 2)'),
  240. _('List of ESP (phase two) proposals. Only Proposals with checked ESP flag are selectable'));
  241. o.load = function (section_id) {
  242. this.keylist = [];
  243. this.vallist = [];
  244. var sections = uci.sections('ipsec', 'crypto_proposal');
  245. if (sections.length == 0) {
  246. this.value('', _('Please create an ESP Proposal first'));
  247. } else {
  248. sections.forEach(L.bind(function (section) {
  249. if (section.is_esp == '1') {
  250. this.value(section['.name']);
  251. }
  252. }, this));
  253. }
  254. return this.super('load', [section_id]);
  255. };
  256. o.rmempty = false;
  257. o = s.taboption('advanced', form.Value, 'updown', _('Up/Down Script Path'),
  258. _('Path to script to run on CHILD_SA up/down events'));
  259. o.datatype = 'file';
  260. o.modalonly = true;
  261. o = s.taboption('advanced', form.Value, 'lifetime', _('Lifetime'),
  262. _('Maximum duration of the CHILD_SA before closing'));
  263. o.validate = validateTimeFormat;
  264. o.modalonly = true;
  265. o = s.taboption('advanced', form.ListValue, 'dpdaction', _('DPD Action'),
  266. _('Action when DPD timeout occurs'));
  267. o.value('none');
  268. o.value('clear');
  269. o.value('trap');
  270. o.value('start');
  271. o.optional = true;
  272. o.modalonly = true;
  273. o = s.taboption('advanced', form.Value, 'rekeytime', _('Rekey Time'),
  274. _('Duration of the CHILD_SA before rekeying'));
  275. o.validate = validateTimeFormat;
  276. o.modalonly = true;
  277. o = s.taboption('advanced', form.Flag, 'ipcomp', _('IPComp'),
  278. _('Enable ipcomp compression'));
  279. o.default = '0';
  280. o.modalonly = true;
  281. o = s.taboption('advanced', form.ListValue, 'hw_offload', _('H/W Offload'),
  282. _('Enable Hardware offload'));
  283. o.value('yes');
  284. o.value('no');
  285. o.value('auto');
  286. o.optional = true;
  287. o.modalonly = true;
  288. o = s.taboption('advanced', form.Value, 'priority', _('Priority'),
  289. _('Priority of the CHILD_SA'));
  290. o.datatype = 'uinteger';
  291. o.modalonly = true;
  292. o = s.taboption('advanced', form.Value, 'replay_window', _('Replay Window'),
  293. '%s; %s'.format(_('Replay Window of the CHILD_SA'),
  294. _('Values larger than 32 are supported by the Netlink backend only')));
  295. o.datatype = 'uinteger';
  296. o.modalonly = true;
  297. // Crypto Proposals
  298. s = m.section(form.GridSection, 'crypto_proposal',
  299. _('Encryption Proposals'),
  300. _('Configure Cipher Suites to define IKE (Phase 1) or ESP (Phase 2) Proposals.'));
  301. s.addremove = true;
  302. s.nodescriptions = true;
  303. o = s.option(form.Flag, 'is_esp', _('ESP Proposal'),
  304. _('Whether this is an ESP (phase 2) proposal or not'));
  305. o = s.option(form.ListValue, 'encryption_algorithm',
  306. _('Encryption Algorithm'),
  307. _('Algorithms marked with * are considered insecure'));
  308. o.default = 'aes256gcm128';
  309. addAlgorithms(o, strongswan_algorithms.getEncryptionAlgorithms());
  310. addAlgorithms(o, strongswan_algorithms.getAuthenticatedEncryptionAlgorithms());
  311. o = s.option(form.ListValue, 'hash_algorithm', _('Hash Algorithm'),
  312. _('Algorithms marked with * are considered insecure'));
  313. strongswan_algorithms.getEncryptionAlgorithms().forEach(function (algorithm) {
  314. o.depends('encryption_algorithm', algorithm);
  315. });
  316. o.default = 'sha512';
  317. o.rmempty = false;
  318. addAlgorithms(o, strongswan_algorithms.getHashAlgorithms());
  319. o = s.option(form.ListValue, 'dh_group', _('Diffie-Hellman Group'),
  320. _('Algorithms marked with * are considered insecure'));
  321. o.default = 'modp3072';
  322. addAlgorithms(o, strongswan_algorithms.getDiffieHellmanAlgorithms());
  323. o = s.option(form.ListValue, 'prf_algorithm', _('PRF Algorithm'),
  324. _('Algorithms marked with * are considered insecure'));
  325. o.validate = function (section_id, value) {
  326. var encryptionAlgorithm = this.section.formvalue(section_id, 'encryption_algorithm');
  327. if (strongswan_algorithms.getAuthenticatedEncryptionAlgorithms().includes(
  328. encryptionAlgorithm) && !value) {
  329. return _('PRF Algorithm must be configured when using an Authenticated Encryption Algorithm');
  330. }
  331. return true;
  332. };
  333. o.optional = true;
  334. o.depends('is_esp', '0');
  335. addAlgorithms(o, strongswan_algorithms.getPrfAlgorithms());
  336. return m.render();
  337. }
  338. });