5 'require tools.widgets as widgets';
6 'require strongswan_algorithms';
8 function validateTimeFormat(section_id, value) {
9 if (value && !value.match(/^\d+[smhd]$/)) {
10 return _('Number must have suffix s, m, h or d');
16 function addAlgorithms(o, algorithms) {
17 algorithms.forEach(function (algorithm) {
18 if (strongswan_algorithms.isInsecure(algorithm)) {
19 o.value(algorithm, '%s*'.format(algorithm));
28 return uci.load('network');
34 m = new form.Map('ipsec', _('strongSwan Configuration'),
35 _('Configure strongSwan for secure VPN connections.'));
38 // strongSwan General Settings
39 s = m.section(form.TypedSection, 'ipsec', _('General Settings'));
42 o = s.option(widgets.ZoneSelect, 'zone', _('Zone'),
43 _('Firewall zone that has to match the defined firewall zone'));
47 o = s.option(widgets.NetworkSelect, 'listen', _('Listening Interfaces'),
48 _('Interfaces that accept VPN traffic'));
49 o.datatype = 'interface';
50 o.placeholder = _('Select an interface or leave empty for all interfaces');
55 o = s.option(form.Value, 'debug', _('Debug Level'),
56 _('Trace level: 0 is least verbose, 4 is most'));
58 o.datatype = 'range(0,4)';
60 // Remote Configuration
61 s = m.section(form.GridSection, 'remote', _('Remote Configuration'),
62 _('Define Remote IKE Configurations.'));
64 s.nodescriptions = true;
66 o = s.tab('general', _('General'));
67 o = s.tab('authentication', _('Authentication'));
68 o = s.tab('advanced', _('Advanced'));
70 o = s.taboption('general', form.Flag, 'enabled', _('Enabled'),
71 _('Configuration is enabled or not'));
74 o = s.taboption('general', form.Value, 'gateway', _('Gateway (Remote Endpoint)'),
75 _('IP address or FQDN name of the tunnel remote endpoint'));
76 o.datatype = 'or(hostname,ipaddr)';
79 o = s.taboption('general', form.Value, 'local_gateway', _('Local Gateway'),
80 _('IP address or FQDN of the tunnel local endpoint'));
81 o.datatype = 'or(hostname,ipaddr)';
84 o = s.taboption('general', form.Value, 'local_sourceip', _('Local Source IP'),
85 _('Virtual IP(s) to request in IKEv2 configuration payloads requests'));
86 o.datatype = 'ipaddr';
89 o = s.taboption('general', form.Value, 'local_ip', _('Local IP'),
90 _('Local address(es) to use in IKE negotiation'));
91 o.datatype = 'ipaddr';
94 o = s.taboption('general', form.MultiValue, 'crypto_proposal', _('Crypto Proposal'),
95 _('List of IKE (phase 1) proposals to use for authentication'));
96 o.load = function (section_id) {
100 var sections = uci.sections('ipsec', 'crypto_proposal');
101 if (sections.length == 0) {
102 this.value('', _('Please create a Proposal first'));
104 sections.forEach(L.bind(function (section) {
105 if (section.is_esp != '1') {
106 this.value(section['.name']);
111 return this.super('load', [section_id]);
115 o = s.taboption('general', form.MultiValue, 'tunnel', _('Tunnel'),
116 _('Name of ESP (phase 2) section'));
117 o.load = function (section_id) {
121 var sections = uci.sections('ipsec', 'tunnel');
122 if (sections.length == 0) {
123 this.value('', _('Please create a Tunnel first'));
125 sections.forEach(L.bind(function (section) {
126 this.value(section['.name']);
130 return this.super('load', [section_id]);
134 o = s.taboption('authentication', form.ListValue, 'authentication_method',
135 _('Authentication Method'), _('IKE authentication (phase 1)'));
137 o.value('psk', 'Pre-shared Key');
138 o.value('pubkey', 'Public Key');
140 o = s.taboption('authentication', form.Value, 'local_identifier', _('Local Identifier'),
141 _('Local identifier for IKE (phase 1)'));
142 o.datatype = 'string';
143 o.placeholder = 'C=US, O=Acme Corporation, CN=headquarters';
146 o = s.taboption('authentication', form.Value, 'remote_identifier', _('Remote Identifier'),
147 _('Remote identifier for IKE (phase 1)'));
148 o.datatype = 'string';
149 o.placeholder = 'C=US, O=Acme Corporation, CN=soho';
152 o = s.taboption('authentication', form.Value, 'pre_shared_key', _('Pre-Shared Key'),
153 _('The pre-shared key for the tunnel'));
154 o.datatype = 'string';
158 o.depends('authentication_method', 'psk');
160 o = s.taboption('authentication', form.Value, 'local_cert', _('Local Certificate'),
161 _('Certificate pathname to use for authentication'));
163 o.depends('authentication_method', 'pubkey');
166 o = s.taboption('authentication', form.Value, 'local_key', _('Local Key'),
167 _('Private key pathname to use with above certificate'));
171 o = s.taboption('authentication', form.Value, 'ca_cert', _('CA Certificate'),
172 _("CA certificate that need to lie in remote peer's certificate's path of trust"));
174 o.depends('authentication_method', 'pubkey');
178 o = s.taboption('advanced', form.Flag, 'mobike', _('MOBIKE'),
179 _('MOBIKE (IKEv2 Mobility and Multihoming Protocol)'));
183 o = s.taboption('advanced', form.ListValue, 'fragmentation', _('IKE Fragmentation'),
184 _('Use IKE fragmentation'));
192 o = s.taboption('advanced', form.Value, 'keyingretries', _('Keying Retries'),
193 _('Number of retransmissions attempts during initial negotiation'));
194 o.datatype = 'uinteger';
198 o = s.taboption('advanced', form.Value, 'dpddelay', _('DPD Delay'),
199 _('Interval to check liveness of a peer'));
200 o.validate = validateTimeFormat;
204 o = s.taboption('advanced', form.Value, 'inactivity', _('Inactivity'),
205 _('Interval before closing an inactive CHILD_SA'));
206 o.validate = validateTimeFormat;
209 o = s.taboption('advanced', form.Value, 'rekeytime', _('Rekey Time'),
210 _('IKEv2 interval to refresh keying material; also used to compute lifetime'));
211 o.validate = validateTimeFormat;
214 o = s.taboption('advanced', form.Value, 'overtime', _('Overtime'),
215 _('Limit on time to complete rekeying/reauthentication'));
216 o.validate = validateTimeFormat;
219 o = s.taboption('advanced', form.ListValue, 'keyexchange', _('Keyexchange'),
220 _('Version of IKE for negotiation'));
221 o.value('ikev1', 'IKEv1 (%s)', _('deprecated'));
222 o.value('ikev2', 'IKEv2');
223 o.value('ike', 'IKE (%s, %s)'.format(_('both'), _('deprecated')));
227 // Tunnel Configuration
228 s = m.section(form.GridSection, 'tunnel', _('Tunnel Configuration'),
229 _('Define Connection Children to be used as Tunnels in Remote Configurations.'));
231 s.nodescriptions = true;
233 o = s.tab('general', _('General'));
234 o = s.tab('advanced', _('Advanced'));
236 o = s.taboption('general', form.DynamicList, 'local_subnet', _('Local Subnet'),
237 _('Local network(s)'));
238 o.datatype = 'subnet';
239 o.placeholder = '192.168.1.1/24';
242 o = s.taboption('general', form.DynamicList, 'remote_subnet', _('Remote Subnet'),
243 _('Remote network(s)'));
244 o.datatype = 'subnet';
245 o.placeholder = '192.168.2.1/24';
248 o = s.taboption('general', form.Value, 'local_nat', _('Local NAT'),
249 _('NAT range for tunnels with overlapping IP addresses'));
250 o.datatype = 'subnet';
253 o = s.taboption('general', form.ListValue, 'if_id', ('XFRM Interface ID'),
254 _('XFRM interface ID set on input and output interfaces'));
255 o.load = function (section_id) {
259 var xfrmSections = uci.sections('network').filter(function (section) {
260 return section.proto == 'xfrm';
263 xfrmSections.forEach(L.bind(function (section) {
264 this.value(section.ifid,
265 '%s (%s)'.format(section.ifid, section['.name']));
268 return this.super('load', [section_id]);
273 o = s.taboption('general', form.ListValue, 'startaction', _('Start Action'),
274 _('Action on initial configuration load'));
281 o = s.taboption('general', form.ListValue, 'closeaction', _('Close Action'),
282 _('Action when CHILD_SA is closed'));
289 o = s.taboption('general', form.MultiValue, 'crypto_proposal',
290 _('Crypto Proposal (Phase 2)'),
291 _('List of ESP (phase two) proposals. Only Proposals with checked ESP flag are selectable'));
292 o.load = function (section_id) {
296 var sections = uci.sections('ipsec', 'crypto_proposal');
297 if (sections.length == 0) {
298 this.value('', _('Please create an ESP Proposal first'));
300 sections.forEach(L.bind(function (section) {
301 if (section.is_esp == '1') {
302 this.value(section['.name']);
307 return this.super('load', [section_id]);
311 o = s.taboption('advanced', form.Value, 'updown', _('Up/Down Script Path'),
312 _('Path to script to run on CHILD_SA up/down events'));
316 o = s.taboption('advanced', form.Value, 'lifetime', _('Lifetime'),
317 _('Maximum duration of the CHILD_SA before closing'));
318 o.validate = validateTimeFormat;
321 o = s.taboption('advanced', form.ListValue, 'dpdaction', _('DPD Action'),
322 _('Action when DPD timeout occurs'));
330 o = s.taboption('advanced', form.Value, 'rekeytime', _('Rekey Time'),
331 _('Duration of the CHILD_SA before rekeying'));
332 o.validate = validateTimeFormat;
335 o = s.taboption('advanced', form.Flag, 'ipcomp', _('IPComp'),
336 _('Enable ipcomp compression'));
340 o = s.taboption('advanced', form.ListValue, 'hw_offload', _('H/W Offload'),
341 _('Enable Hardware offload'));
348 o = s.taboption('advanced', form.Value, 'priority', _('Priority'),
349 _('Priority of the CHILD_SA'));
350 o.datatype = 'uinteger';
353 o = s.taboption('advanced', form.Value, 'replay_window', _('Replay Window'),
354 '%s; %s'.format(_('Replay Window of the CHILD_SA'),
355 _('Values larger than 32 are supported by the Netlink backend only')));
356 o.datatype = 'uinteger';
360 s = m.section(form.GridSection, 'crypto_proposal',
361 _('Encryption Proposals'),
362 _('Configure Cipher Suites to define IKE (Phase 1) or ESP (Phase 2) Proposals.'));
364 s.nodescriptions = true;
366 o = s.option(form.Flag, 'is_esp', _('ESP Proposal'),
367 _('Whether this is an ESP (phase 2) proposal or not'));
369 o = s.option(form.ListValue, 'encryption_algorithm',
370 _('Encryption Algorithm'),
371 _('Algorithms marked with * are considered insecure'));
372 o.default = 'aes256gcm128';
373 addAlgorithms(o, strongswan_algorithms.getEncryptionAlgorithms());
374 addAlgorithms(o, strongswan_algorithms.getAuthenticatedEncryptionAlgorithms());
377 o = s.option(form.ListValue, 'hash_algorithm', _('Hash Algorithm'),
378 _('Algorithms marked with * are considered insecure'));
379 strongswan_algorithms.getEncryptionAlgorithms().forEach(function (algorithm) {
380 o.depends('encryption_algorithm', algorithm);
382 o.default = 'sha512';
384 addAlgorithms(o, strongswan_algorithms.getHashAlgorithms());
386 o = s.option(form.ListValue, 'dh_group', _('Diffie-Hellman Group'),
387 _('Algorithms marked with * are considered insecure'));
388 o.default = 'modp3072';
389 addAlgorithms(o, strongswan_algorithms.getDiffieHellmanAlgorithms());
391 o = s.option(form.ListValue, 'prf_algorithm', _('PRF Algorithm'),
392 _('Algorithms marked with * are considered insecure'));
393 o.validate = function (section_id, value) {
394 var encryptionAlgorithm = this.section.formvalue(section_id, 'encryption_algorithm');
396 if (strongswan_algorithms.getAuthenticatedEncryptionAlgorithms().includes(
397 encryptionAlgorithm) && !value) {
398 return _('PRF Algorithm must be configured when using an Authenticated Encryption Algorithm');
404 o.depends('is_esp', '0');
405 addAlgorithms(o, strongswan_algorithms.getPrfAlgorithms());