]> git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/vpnmain.cgi
ipsec: Support using multiple subnets per tunnel
[ipfire-2.x.git] / html / cgi-bin / vpnmain.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2013 IPFire Team info@ipfire.org #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 use Net::DNS;
23 use File::Copy;
24 use File::Temp qw/ tempfile tempdir /;
25 use strict;
26 use Sort::Naturally;
27 # enable only the following on debugging purpose
28 #use warnings;
29 #use CGI::Carp 'fatalsToBrowser';
30
31 require '/var/ipfire/general-functions.pl';
32 require "${General::swroot}/lang.pl";
33 require "${General::swroot}/header.pl";
34 require "${General::swroot}/countries.pl";
35
36 #workaround to suppress a warning when a variable is used only once
37 my @dummy = ( ${Header::colourgreen}, ${Header::colourblue} );
38 undef (@dummy);
39
40 ###
41 ### Initialize variables
42 ###
43 my $sleepDelay = 4; # after a call to ipsecctrl S or R, wait this delay (seconds) before reading status
44 # (let the ipsec do its job)
45 my %netsettings=();
46 our %cgiparams=();
47 our %vpnsettings=();
48 my %checked=();
49 my %confighash=();
50 my %cahash=();
51 my %selected=();
52 my $warnmessage = '';
53 my $errormessage = '';
54
55 my %color = ();
56 my %mainsettings = ();
57 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
58 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
59
60 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
61
62 my $green_cidr = &General::ipcidr("$netsettings{'GREEN_NETADDRESS'}/$netsettings{'GREEN_NETMASK'}");
63 my $blue_cidr = "# Blue not defined";
64 if (&Header::blue_used() && $netsettings{'BLUE_DEV'}) {
65 $blue_cidr = &General::ipcidr("$netsettings{'BLUE_NETADDRESS'}/$netsettings{'BLUE_NETMASK'}");
66 }
67 my $orange_cidr = "# Orange not defined";
68 if (&Header::orange_used() && $netsettings{'ORANGE_DEV'}) {
69 $orange_cidr = &General::ipcidr("$netsettings{'ORANGE_NETADDRESS'}/$netsettings{'ORANGE_NETMASK'}");
70 }
71
72 my $col="";
73
74 $cgiparams{'ENABLED'} = 'off';
75 $cgiparams{'EDIT_ADVANCED'} = 'off';
76 $cgiparams{'ACTION'} = '';
77 $cgiparams{'CA_NAME'} = '';
78 $cgiparams{'KEY'} = '';
79 $cgiparams{'TYPE'} = '';
80 $cgiparams{'ADVANCED'} = '';
81 $cgiparams{'NAME'} = '';
82 $cgiparams{'LOCAL_SUBNET'} = '';
83 $cgiparams{'REMOTE_SUBNET'} = '';
84 $cgiparams{'REMOTE'} = '';
85 $cgiparams{'LOCAL_ID'} = '';
86 $cgiparams{'REMOTE_ID'} = '';
87 $cgiparams{'REMARK'} = '';
88 $cgiparams{'PSK'} = '';
89 $cgiparams{'CERT_NAME'} = '';
90 $cgiparams{'CERT_EMAIL'} = '';
91 $cgiparams{'CERT_OU'} = '';
92 $cgiparams{'CERT_ORGANIZATION'} = '';
93 $cgiparams{'CERT_CITY'} = '';
94 $cgiparams{'CERT_STATE'} = '';
95 $cgiparams{'CERT_COUNTRY'} = '';
96 $cgiparams{'SUBJECTALTNAME'} = '';
97 $cgiparams{'CERT_PASS1'} = '';
98 $cgiparams{'CERT_PASS2'} = '';
99 $cgiparams{'ROOTCERT_HOSTNAME'} = '';
100 $cgiparams{'ROOTCERT_COUNTRY'} = '';
101 $cgiparams{'P12_PASS'} = '';
102 $cgiparams{'ROOTCERT_ORGANIZATION'} = '';
103 $cgiparams{'ROOTCERT_HOSTNAME'} = '';
104 $cgiparams{'ROOTCERT_EMAIL'} = '';
105 $cgiparams{'ROOTCERT_OU'} = '';
106 $cgiparams{'ROOTCERT_CITY'} = '';
107 $cgiparams{'ROOTCERT_STATE'} = '';
108 $cgiparams{'RW_NET'} = '';
109 $cgiparams{'DPD_DELAY'} = '30';
110 $cgiparams{'DPD_TIMEOUT'} = '120';
111 &Header::getcgihash(\%cgiparams, {'wantfile' => 1, 'filevar' => 'FH'});
112
113 ###
114 ### Useful functions
115 ###
116 sub valid_dns_host {
117 my $hostname = $_[0];
118 unless ($hostname) { return "No hostname"};
119 my $res = new Net::DNS::Resolver;
120 my $query = $res->search("$hostname");
121 if ($query) {
122 foreach my $rr ($query->answer) {
123 ## Potential bug - we are only looking at A records:
124 return 0 if $rr->type eq "A";
125 }
126 } else {
127 return $res->errorstring;
128 }
129 }
130 ###
131 ### Just return true is one interface is vpn enabled
132 ###
133 sub vpnenabled {
134 return ($vpnsettings{'ENABLED'} eq 'on');
135 }
136 ###
137 ### old version: maintain serial number to one, without explication.
138 ### this : let the counter go, so that each cert is numbered.
139 ###
140 sub cleanssldatabase
141 {
142 if (open(FILE, ">${General::swroot}/certs/serial")) {
143 print FILE "01";
144 close FILE;
145 }
146 if (open(FILE, ">${General::swroot}/certs/index.txt")) {
147 print FILE "";
148 close FILE;
149 }
150 unlink ("${General::swroot}/certs/index.txt.old");
151 unlink ("${General::swroot}/certs/serial.old");
152 unlink ("${General::swroot}/certs/01.pem");
153 }
154 sub newcleanssldatabase
155 {
156 if (! -s "${General::swroot}/certs/serial" ) {
157 open(FILE, ">${General::swroot}/certs/serial");
158 print FILE "01";
159 close FILE;
160 }
161 if (! -s ">${General::swroot}/certs/index.txt") {
162 system ("touch ${General::swroot}/certs/index.txt");
163 }
164 unlink ("${General::swroot}/certs/index.txt.old");
165 unlink ("${General::swroot}/certs/serial.old");
166 # unlink ("${General::swroot}/certs/01.pem"); numbering evolves. Wrong place to delete
167 }
168
169 ###
170 ### Call openssl and return errormessage if any
171 ###
172 sub callssl ($) {
173 my $opt = shift;
174 my $retssl = `/usr/bin/openssl $opt 2>&1`; #redirect stderr
175 my $ret = '';
176 foreach my $line (split (/\n/, $retssl)) {
177 &General::log("ipsec", "$line") if (0); # 1 for verbose logging
178 $ret .= '<br>'.$line if ( $line =~ /error|unknown/ );
179 }
180 if ($ret) {
181 $ret= &Header::cleanhtml($ret);
182 }
183 return $ret ? "$Lang::tr{'openssl produced an error'}: $ret" : '' ;
184 }
185 ###
186 ### Obtain a CN from given cert
187 ###
188 sub getCNfromcert ($) {
189 #&General::log("ipsec", "Extracting name from $_[0]...");
190 my $temp = `/usr/bin/openssl x509 -text -in $_[0]`;
191 $temp =~ /Subject:.*CN=(.*)[\n]/;
192 $temp = $1;
193 $temp =~ s+/Email+, E+;
194 $temp =~ s/ ST=/ S=/;
195 $temp =~ s/,//g;
196 $temp =~ s/\'//g;
197 return $temp;
198 }
199 ###
200 ### Obtain Subject from given cert
201 ###
202 sub getsubjectfromcert ($) {
203 #&General::log("ipsec", "Extracting subject from $_[0]...");
204 my $temp = `/usr/bin/openssl x509 -text -in $_[0]`;
205 $temp =~ /Subject: (.*)[\n]/;
206 $temp = $1;
207 $temp =~ s+/Email+, E+;
208 $temp =~ s/ ST=/ S=/;
209 return $temp;
210 }
211 ###
212 ### Combine local subnet and connection name to make a unique name for each connection section
213 ### (this sub is not used now)
214 ###
215 sub makeconnname ($) {
216 my $conn = shift;
217 my $subnet = shift;
218
219 $subnet =~ /^(.*?)\/(.*?)$/; # $1=IP $2=mask
220 my $ip = unpack('N', &Socket::inet_aton($1));
221 if (length ($2) > 2) {
222 my $mm = unpack('N', &Socket::inet_aton($2));
223 while ( ($mm & 1)==0 ) {
224 $ip >>= 1;
225 $mm >>= 1;
226 };
227 } else {
228 $ip >>= (32 - $2);
229 }
230 return sprintf ("%s-%X", $conn, $ip);
231 }
232 ###
233 ### Write a config file.
234 ###
235 ###Type=Host : GUI can choose the interface used (RED,GREEN,BLUE) and
236 ### the side is always defined as 'left'.
237 ### configihash[14]: 'VHOST' is allowed
238 ###
239
240 sub writeipsecfiles {
241 my %lconfighash = ();
242 my %lvpnsettings = ();
243 &General::readhasharray("${General::swroot}/vpn/config", \%lconfighash);
244 &General::readhash("${General::swroot}/vpn/settings", \%lvpnsettings);
245
246 open(CONF, ">${General::swroot}/vpn/ipsec.conf") or die "Unable to open ${General::swroot}/vpn/ipsec.conf: $!";
247 open(SECRETS, ">${General::swroot}/vpn/ipsec.secrets") or die "Unable to open ${General::swroot}/vpn/ipsec.secrets: $!";
248 flock CONF, 2;
249 flock SECRETS, 2;
250 print CONF "version 2\n\n";
251 print CONF "conn %default\n";
252 print CONF "\tkeyingtries=%forever\n";
253 print CONF "\n";
254
255 # Add user includes to config file
256 if (-e "/etc/ipsec.user.conf") {
257 print CONF "include /etc/ipsec.user.conf\n";
258 print CONF "\n";
259 }
260
261 print SECRETS "include /etc/ipsec.user.secrets\n";
262
263 if (-f "${General::swroot}/certs/hostkey.pem") {
264 print SECRETS ": RSA ${General::swroot}/certs/hostkey.pem\n"
265 }
266 my $last_secrets = ''; # old the less specifics connections
267
268 foreach my $key (keys %lconfighash) {
269 next if ($lconfighash{$key}[0] ne 'on');
270
271 #remote peer is not set? => use '%any'
272 $lconfighash{$key}[10] = '%any' if ($lconfighash{$key}[10] eq '');
273
274 my $localside;
275 if ($lconfighash{$key}[26] eq 'BLUE') {
276 $localside = $netsettings{'BLUE_ADDRESS'};
277 } elsif ($lconfighash{$key}[26] eq 'GREEN') {
278 $localside = $netsettings{'GREEN_ADDRESS'};
279 } elsif ($lconfighash{$key}[26] eq 'ORANGE') {
280 $localside = $netsettings{'ORANGE_ADDRESS'};
281 } else { # it is RED
282 $localside = $lvpnsettings{'VPN_IP'};
283 }
284
285 print CONF "conn $lconfighash{$key}[1]\n";
286 print CONF "\tleft=$localside\n";
287 print CONF "\tleftsubnet=" . &make_subnets($lconfighash{$key}[8]) . "\n";
288 print CONF "\tleftfirewall=yes\n";
289 print CONF "\tlefthostaccess=yes\n";
290
291 print CONF "\tright=$lconfighash{$key}[10]\n";
292 if ($lconfighash{$key}[3] eq 'net') {
293 print CONF "\trightsubnet=" . &make_subnets($lconfighash{$key}[11]) . "\n";
294 } elsif ($lconfighash{$key}[10] eq '%any' && $lconfighash{$key}[14] eq 'on') { #vhost allowed for roadwarriors?
295 print CONF "\trightsubnet=vhost:%no,%priv\n";
296 }
297
298 # Local Cert and Remote Cert (unless auth is DN dn-auth)
299 if ($lconfighash{$key}[4] eq 'cert') {
300 print CONF "\tleftcert=${General::swroot}/certs/hostcert.pem\n";
301 print CONF "\trightcert=${General::swroot}/certs/$lconfighash{$key}[1]cert.pem\n" if ($lconfighash{$key}[2] ne '%auth-dn');
302 }
303
304 # Local and Remote IDs
305 print CONF "\tleftid=\"$lconfighash{$key}[7]\"\n" if ($lconfighash{$key}[7]);
306 print CONF "\trightid=\"$lconfighash{$key}[9]\"\n" if ($lconfighash{$key}[9]);
307
308 # Is PFS enabled?
309 my $pfs = $lconfighash{$key}[28] eq 'on' ? 'on' : 'off';
310
311 # Algorithms
312 if ($lconfighash{$key}[18] && $lconfighash{$key}[19] && $lconfighash{$key}[20]) {
313 my @encs = split('\|', $lconfighash{$key}[18]);
314 my @ints = split('\|', $lconfighash{$key}[19]);
315 my @groups = split('\|', $lconfighash{$key}[20]);
316
317 my @algos = &make_algos("ike", \@encs, \@ints, \@groups, 1);
318 print CONF "\tike=" . join(",", @algos);
319
320 if ($lconfighash{$key}[24] eq 'on') { #only proposed algorythms?
321 print CONF "!\n";
322 } else {
323 print CONF "\n";
324 }
325 }
326
327 if ($lconfighash{$key}[21] && $lconfighash{$key}[22]) {
328 my @encs = split('\|', $lconfighash{$key}[21]);
329 my @ints = split('\|', $lconfighash{$key}[22]);
330 my @groups = split('\|', $lconfighash{$key}[23]);
331
332 # Use IKE grouptype if no ESP group type has been selected
333 # (for backwards compatibility)
334 if ($lconfighash{$key}[23] eq "") {
335 @groups = split('\|', $lconfighash{$key}[20]);
336 }
337
338 my @algos = &make_algos("esp", \@encs, \@ints, \@groups, ($pfs eq "on"));
339 print CONF "\tesp=" . join(",", @algos);
340
341 if ($lconfighash{$key}[24] eq 'on') { #only proposed algorythms?
342 print CONF "!\n";
343 } else {
344 print CONF "\n";
345 }
346 }
347
348 # IKE V1 or V2
349 if (! $lconfighash{$key}[29]) {
350 $lconfighash{$key}[29] = "ikev1";
351 }
352 print CONF "\tkeyexchange=$lconfighash{$key}[29]\n";
353
354 # Lifetimes
355 print CONF "\tikelifetime=$lconfighash{$key}[16]h\n" if ($lconfighash{$key}[16]);
356 print CONF "\tkeylife=$lconfighash{$key}[17]h\n" if ($lconfighash{$key}[17]);
357
358 # Compression
359 print CONF "\tcompress=yes\n" if ($lconfighash{$key}[13] eq 'on');
360
361 # Dead Peer Detection
362 my $dpdaction = $lconfighash{$key}[27];
363 print CONF "\tdpdaction=$dpdaction\n";
364
365 # If the dead peer detection is disabled and IKEv2 is used,
366 # dpddelay must be set to zero, too.
367 if ($dpdaction eq "none") {
368 if ($lconfighash{$key}[29] eq "ikev2") {
369 print CONF "\tdpddelay=0\n";
370 }
371 } else {
372 my $dpddelay = $lconfighash{$key}[31];
373 if (!$dpddelay) {
374 $dpddelay = 30;
375 }
376 print CONF "\tdpddelay=$dpddelay\n";
377 my $dpdtimeout = $lconfighash{$key}[30];
378 if (!$dpdtimeout) {
379 $dpdtimeout = 120;
380 }
381 print CONF "\tdpdtimeout=$dpdtimeout\n";
382 }
383
384 # Build Authentication details: LEFTid RIGHTid : PSK psk
385 my $psk_line;
386 if ($lconfighash{$key}[4] eq 'psk') {
387 $psk_line = ($lconfighash{$key}[7] ? $lconfighash{$key}[7] : $localside) . " " ;
388 $psk_line .= $lconfighash{$key}[9] ? $lconfighash{$key}[9] : $lconfighash{$key}[10]; #remoteid or remote address?
389 $psk_line .= " : PSK '$lconfighash{$key}[5]'\n";
390 # if the line contains %any, it is less specific than two IP or ID, so move it at end of file.
391 if ($psk_line =~ /%any/) {
392 $last_secrets .= $psk_line;
393 } else {
394 print SECRETS $psk_line;
395 }
396 print CONF "\tauthby=secret\n";
397 } else {
398 print CONF "\tauthby=rsasig\n";
399 print CONF "\tleftrsasigkey=%cert\n";
400 print CONF "\trightrsasigkey=%cert\n";
401 }
402
403 # Automatically start only if a net-to-net connection
404 if ($lconfighash{$key}[3] eq 'host') {
405 print CONF "\tauto=add\n";
406 print CONF "\trightsourceip=$lvpnsettings{'RW_NET'}\n";
407 } else {
408 print CONF "\tauto=start\n";
409 }
410
411 # Fragmentation
412 print CONF "\tfragmentation=yes\n";
413
414 print CONF "\n";
415 }#foreach key
416
417 # Add post user includes to config file
418 # After the GUI-connections allows to patch connections.
419 if (-e "/etc/ipsec.user-post.conf") {
420 print CONF "include /etc/ipsec.user-post.conf\n";
421 print CONF "\n";
422 }
423
424 print SECRETS $last_secrets if ($last_secrets);
425 close(CONF);
426 close(SECRETS);
427 }
428
429 # Hook to regenerate the configuration files.
430 if ($ENV{"REMOTE_ADDR"} eq "") {
431 writeipsecfiles();
432 exit(0);
433 }
434
435 ###
436 ### Save main settings
437 ###
438 if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq '' && $cgiparams{'KEY'} eq '') {
439 &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings);
440 unless (&General::validfqdn($cgiparams{'VPN_IP'}) || &General::validip($cgiparams{'VPN_IP'})
441 || $cgiparams{'VPN_IP'} eq '%defaultroute' ) {
442 $errormessage = $Lang::tr{'invalid input for hostname'};
443 goto SAVE_ERROR;
444 }
445
446 unless ($cgiparams{'VPN_DELAYED_START'} =~ /^[0-9]{1,3}$/ ) { #allow 0-999 seconds !
447 $errormessage = $Lang::tr{'invalid time period'};
448 goto SAVE_ERROR;
449 }
450
451 if ( $cgiparams{'RW_NET'} ne '' and !&General::validipandmask($cgiparams{'RW_NET'}) ) {
452 $errormessage = $Lang::tr{'urlfilter invalid ip or mask error'};
453 goto SAVE_ERROR;
454 }
455
456 $vpnsettings{'ENABLED'} = $cgiparams{'ENABLED'};
457 $vpnsettings{'VPN_IP'} = $cgiparams{'VPN_IP'};
458 $vpnsettings{'VPN_DELAYED_START'} = $cgiparams{'VPN_DELAYED_START'};
459 $vpnsettings{'RW_NET'} = $cgiparams{'RW_NET'};
460 &General::writehash("${General::swroot}/vpn/settings", \%vpnsettings);
461 &writeipsecfiles();
462 if (&vpnenabled) {
463 system('/usr/local/bin/ipsecctrl', 'S');
464 } else {
465 system('/usr/local/bin/ipsecctrl', 'D');
466 }
467 sleep $sleepDelay;
468 SAVE_ERROR:
469 ###
470 ### Reset all step 2
471 ###
472 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove x509'} && $cgiparams{'AREUSURE'} eq 'yes') {
473 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
474
475 foreach my $key (keys %confighash) {
476 if ($confighash{$key}[4] eq 'cert') {
477 delete $confighash{$key};
478 }
479 }
480 while (my $file = glob("${General::swroot}/{ca,certs,crls,private}/*")) {
481 unlink $file
482 }
483 &cleanssldatabase();
484 if (open(FILE, ">${General::swroot}/vpn/caconfig")) {
485 print FILE "";
486 close FILE;
487 }
488 &General::writehasharray("${General::swroot}/vpn/config", \%confighash);
489 &writeipsecfiles();
490 system('/usr/local/bin/ipsecctrl', 'R');
491 sleep $sleepDelay;
492
493 ###
494 ### Reset all step 1
495 ###
496 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove x509'}) {
497 &Header::showhttpheaders();
498 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
499 &Header::openbigbox('100%', 'left', '', '');
500 &Header::openbox('100%', 'left', $Lang::tr{'are you sure'});
501 print <<END
502 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
503 <table width='100%'>
504 <tr>
505 <td align='center'>
506 <input type='hidden' name='AREUSURE' value='yes' />
507 <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>:
508 $Lang::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}</td>
509 </tr><tr>
510 <td align='center'>
511 <input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' />
512 <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td>
513 </tr>
514 </table>
515 </form>
516 END
517 ;
518 &Header::closebox();
519 &Header::closebigbox();
520 &Header::closepage();
521 exit (0);
522
523 ###
524 ### Upload CA Certificate
525 ###
526 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload ca certificate'}) {
527 &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash);
528
529 if ($cgiparams{'CA_NAME'} !~ /^[a-zA-Z0-9]+$/) {
530 $errormessage = $Lang::tr{'name must only contain characters'};
531 goto UPLOADCA_ERROR;
532 }
533
534 if (length($cgiparams{'CA_NAME'}) >60) {
535 $errormessage = $Lang::tr{'name too long'};
536 goto VPNCONF_ERROR;
537 }
538
539 if ($cgiparams{'CA_NAME'} eq 'ca') {
540 $errormessage = $Lang::tr{'name is invalid'};
541 goto UPLOAD_CA_ERROR;
542 }
543
544 # Check if there is no other entry with this name
545 foreach my $key (keys %cahash) {
546 if ($cahash{$key}[0] eq $cgiparams{'CA_NAME'}) {
547 $errormessage = $Lang::tr{'a ca certificate with this name already exists'};
548 goto UPLOADCA_ERROR;
549 }
550 }
551
552 if (ref ($cgiparams{'FH'}) ne 'Fh') {
553 $errormessage = $Lang::tr{'there was no file upload'};
554 goto UPLOADCA_ERROR;
555 }
556 # Move uploaded ca to a temporary file
557 (my $fh, my $filename) = tempfile( );
558 if (copy ($cgiparams{'FH'}, $fh) != 1) {
559 $errormessage = $!;
560 goto UPLOADCA_ERROR;
561 }
562 my $temp = `/usr/bin/openssl x509 -text -in $filename`;
563 if ($temp !~ /CA:TRUE/i) {
564 $errormessage = $Lang::tr{'not a valid ca certificate'};
565 unlink ($filename);
566 goto UPLOADCA_ERROR;
567 } else {
568 move($filename, "${General::swroot}/ca/$cgiparams{'CA_NAME'}cert.pem");
569 if ($? ne 0) {
570 $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
571 unlink ($filename);
572 goto UPLOADCA_ERROR;
573 }
574 }
575
576 my $key = &General::findhasharraykey (\%cahash);
577 $cahash{$key}[0] = $cgiparams{'CA_NAME'};
578 $cahash{$key}[1] = &Header::cleanhtml(getsubjectfromcert ("${General::swroot}/ca/$cgiparams{'CA_NAME'}cert.pem"));
579 &General::writehasharray("${General::swroot}/vpn/caconfig", \%cahash);
580
581 system('/usr/local/bin/ipsecctrl', 'R');
582 sleep $sleepDelay;
583
584 UPLOADCA_ERROR:
585
586 ###
587 ### Display ca certificate
588 ###
589 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show ca certificate'}) {
590 &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash);
591
592 if ( -f "${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem") {
593 &Header::showhttpheaders();
594 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
595 &Header::openbigbox('100%', 'left', '', '');
596 &Header::openbox('100%', 'left', "$Lang::tr{'ca certificate'}:");
597 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`;
598 $output = &Header::cleanhtml($output,"y");
599 print "<pre>$output</pre>\n";
600 &Header::closebox();
601 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'>$Lang::tr{'back'}</a></div>";
602 &Header::closebigbox();
603 &Header::closepage();
604 exit(0);
605 } else {
606 $errormessage = $Lang::tr{'invalid key'};
607 }
608
609 ###
610 ### Export ca certificate to browser
611 ###
612 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download ca certificate'}) {
613 &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash);
614
615 if ( -f "${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) {
616 print "Content-Type: application/force-download\n";
617 print "Content-Type: application/octet-stream\r\n";
618 print "Content-Disposition: attachment; filename=$cahash{$cgiparams{'KEY'}}[0]cert.pem\r\n\r\n";
619 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`;
620 exit(0);
621 } else {
622 $errormessage = $Lang::tr{'invalid key'};
623 }
624
625 ###
626 ### Remove ca certificate (step 2)
627 ###
628 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'} && $cgiparams{'AREUSURE'} eq 'yes') {
629 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
630 &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash);
631
632 if ( -f "${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) {
633 foreach my $key (keys %confighash) {
634 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem ${General::swroot}/certs/$confighash{$key}[1]cert.pem`;
635 if ($test =~ /: OK/) {
636 # Delete connection
637 system('/usr/local/bin/ipsecctrl', 'D', $key) if (&vpnenabled);
638 unlink ("${General::swroot}/certs/$confighash{$key}[1]cert.pem");
639 unlink ("${General::swroot}/certs/$confighash{$key}[1].p12");
640 delete $confighash{$key};
641 &General::writehasharray("${General::swroot}/vpn/config", \%confighash);
642 &writeipsecfiles();
643 }
644 }
645 unlink ("${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem");
646 delete $cahash{$cgiparams{'KEY'}};
647 &General::writehasharray("${General::swroot}/vpn/caconfig", \%cahash);
648 system('/usr/local/bin/ipsecctrl', 'R');
649 sleep $sleepDelay;
650 } else {
651 $errormessage = $Lang::tr{'invalid key'};
652 }
653 ###
654 ### Remove ca certificate (step 1)
655 ###
656 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'}) {
657 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
658 &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash);
659
660 my $assignedcerts = 0;
661 if ( -f "${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) {
662 foreach my $key (keys %confighash) {
663 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem ${General::swroot}/certs/$confighash{$key}[1]cert.pem`;
664 if ($test =~ /: OK/) {
665 $assignedcerts++;
666 }
667 }
668 if ($assignedcerts) {
669 &Header::showhttpheaders();
670 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
671 &Header::openbigbox('100%', 'left', '', '');
672 &Header::openbox('100%', 'left', $Lang::tr{'are you sure'});
673 print <<END
674 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
675 <table width='100%'>
676 <tr>
677 <td align='center'>
678 <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />
679 <input type='hidden' name='AREUSURE' value='yes' /></td>
680 </tr><tr>
681 <td align='center'>
682 <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>
683 $Lang::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}</td>
684 </tr><tr>
685 <td align='center'>
686 <input type='submit' name='ACTION' value='$Lang::tr{'remove ca certificate'}' />
687 <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td>
688 </tr>
689 </table>
690 </form>
691 END
692 ;
693 &Header::closebox();
694 &Header::closebigbox();
695 &Header::closepage();
696 exit (0);
697 } else {
698 unlink ("${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem");
699 delete $cahash{$cgiparams{'KEY'}};
700 &General::writehasharray("${General::swroot}/vpn/caconfig", \%cahash);
701 system('/usr/local/bin/ipsecctrl', 'R');
702 sleep $sleepDelay;
703 }
704 } else {
705 $errormessage = $Lang::tr{'invalid key'};
706 }
707
708 ###
709 ### Display root certificate
710 ###
711 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'} ||
712 $cgiparams{'ACTION'} eq $Lang::tr{'show host certificate'}) {
713 my $output;
714 &Header::showhttpheaders();
715 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
716 &Header::openbigbox('100%', 'left', '', '');
717 if ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'}) {
718 &Header::openbox('100%', 'left', "$Lang::tr{'root certificate'}:");
719 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/cacert.pem`;
720 } else {
721 &Header::openbox('100%', 'left', "$Lang::tr{'host certificate'}:");
722 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/hostcert.pem`;
723 }
724 $output = &Header::cleanhtml($output,"y");
725 print "<pre>$output</pre>\n";
726 &Header::closebox();
727 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'>$Lang::tr{'back'}</a></div>";
728 &Header::closebigbox();
729 &Header::closepage();
730 exit(0);
731
732 ###
733 ### Export root certificate to browser
734 ###
735 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download root certificate'}) {
736 if ( -f "${General::swroot}/ca/cacert.pem" ) {
737 print "Content-Type: application/force-download\n";
738 print "Content-Disposition: attachment; filename=cacert.pem\r\n\r\n";
739 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/cacert.pem`;
740 exit(0);
741 }
742 ###
743 ### Export host certificate to browser
744 ###
745 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download host certificate'}) {
746 if ( -f "${General::swroot}/certs/hostcert.pem" ) {
747 print "Content-Type: application/force-download\n";
748 print "Content-Disposition: attachment; filename=hostcert.pem\r\n\r\n";
749 print `/usr/bin/openssl x509 -in ${General::swroot}/certs/hostcert.pem`;
750 exit(0);
751 }
752 ###
753 ### Form for generating/importing the caroot+host certificate
754 ###
755 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate root/host certificates'} ||
756 $cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) {
757
758 if (-f "${General::swroot}/ca/cacert.pem") {
759 $errormessage = $Lang::tr{'valid root certificate already exists'};
760 goto ROOTCERT_SKIP;
761 }
762
763 &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings);
764 # fill in initial values
765 if ($cgiparams{'ROOTCERT_HOSTNAME'} eq '') {
766 if (-e "${General::swroot}/red/active" && open(IPADDR, "${General::swroot}/red/local-ipaddress")) {
767 my $ipaddr = <IPADDR>;
768 close IPADDR;
769 chomp ($ipaddr);
770 $cgiparams{'ROOTCERT_HOSTNAME'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0];
771 if ($cgiparams{'ROOTCERT_HOSTNAME'} eq '') {
772 $cgiparams{'ROOTCERT_HOSTNAME'} = $ipaddr;
773 }
774 }
775 $cgiparams{'ROOTCERT_COUNTRY'} = $vpnsettings{'ROOTCERT_COUNTRY'} if (!$cgiparams{'ROOTCERT_COUNTRY'});
776 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) {
777 &General::log("ipsec", "Importing from p12...");
778
779 if (ref ($cgiparams{'FH'}) ne 'Fh') {
780 $errormessage = $Lang::tr{'there was no file upload'};
781 goto ROOTCERT_ERROR;
782 }
783
784 # Move uploaded certificate request to a temporary file
785 (my $fh, my $filename) = tempfile( );
786 if (copy ($cgiparams{'FH'}, $fh) != 1) {
787 $errormessage = $!;
788 goto ROOTCERT_ERROR;
789 }
790
791 # Extract the CA certificate from the file
792 &General::log("ipsec", "Extracting caroot from p12...");
793 if (open(STDIN, "-|")) {
794 my $opt = " pkcs12 -cacerts -nokeys";
795 $opt .= " -in $filename";
796 $opt .= " -out /tmp/newcacert";
797 $errormessage = &callssl ($opt);
798 } else { #child
799 print "$cgiparams{'P12_PASS'}\n";
800 exit (0);
801 }
802
803 # Extract the Host certificate from the file
804 if (!$errormessage) {
805 &General::log("ipsec", "Extracting host cert from p12...");
806 if (open(STDIN, "-|")) {
807 my $opt = " pkcs12 -clcerts -nokeys";
808 $opt .= " -in $filename";
809 $opt .= " -out /tmp/newhostcert";
810 $errormessage = &callssl ($opt);
811 } else { #child
812 print "$cgiparams{'P12_PASS'}\n";
813 exit (0);
814 }
815 }
816
817 # Extract the Host key from the file
818 if (!$errormessage) {
819 &General::log("ipsec", "Extracting private key from p12...");
820 if (open(STDIN, "-|")) {
821 my $opt = " pkcs12 -nocerts -nodes";
822 $opt .= " -in $filename";
823 $opt .= " -out /tmp/newhostkey";
824 $errormessage = &callssl ($opt);
825 } else { #child
826 print "$cgiparams{'P12_PASS'}\n";
827 exit (0);
828 }
829 }
830
831 if (!$errormessage) {
832 &General::log("ipsec", "Moving cacert...");
833 move("/tmp/newcacert", "${General::swroot}/ca/cacert.pem");
834 $errormessage = "$Lang::tr{'certificate file move failed'}: $!" if ($? ne 0);
835 }
836
837 if (!$errormessage) {
838 &General::log("ipsec", "Moving host cert...");
839 move("/tmp/newhostcert", "${General::swroot}/certs/hostcert.pem");
840 $errormessage = "$Lang::tr{'certificate file move failed'}: $!" if ($? ne 0);
841 }
842
843 if (!$errormessage) {
844 &General::log("ipsec", "Moving private key...");
845 move("/tmp/newhostkey", "${General::swroot}/certs/hostkey.pem");
846 $errormessage = "$Lang::tr{'certificate file move failed'}: $!" if ($? ne 0);
847 }
848
849 #cleanup temp files
850 unlink ($filename);
851 unlink ('/tmp/newcacert');
852 unlink ('/tmp/newhostcert');
853 unlink ('/tmp/newhostkey');
854 if ($errormessage) {
855 unlink ("${General::swroot}/ca/cacert.pem");
856 unlink ("${General::swroot}/certs/hostcert.pem");
857 unlink ("${General::swroot}/certs/hostkey.pem");
858 goto ROOTCERT_ERROR;
859 }
860
861 # Create empty CRL cannot be done because we don't have
862 # the private key for this CAROOT
863 # IPFire can only import certificates
864
865 &General::log("ipsec", "p12 import completed!");
866 &cleanssldatabase();
867 goto ROOTCERT_SUCCESS;
868
869 } elsif ($cgiparams{'ROOTCERT_COUNTRY'} ne '') {
870
871 # Validate input since the form was submitted
872 if ($cgiparams{'ROOTCERT_ORGANIZATION'} eq ''){
873 $errormessage = $Lang::tr{'organization cant be empty'};
874 goto ROOTCERT_ERROR;
875 }
876 if (length($cgiparams{'ROOTCERT_ORGANIZATION'}) >60) {
877 $errormessage = $Lang::tr{'organization too long'};
878 goto ROOTCERT_ERROR;
879 }
880 if ($cgiparams{'ROOTCERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
881 $errormessage = $Lang::tr{'invalid input for organization'};
882 goto ROOTCERT_ERROR;
883 }
884 if ($cgiparams{'ROOTCERT_HOSTNAME'} eq ''){
885 $errormessage = $Lang::tr{'hostname cant be empty'};
886 goto ROOTCERT_ERROR;
887 }
888 unless (&General::validfqdn($cgiparams{'ROOTCERT_HOSTNAME'}) || &General::validip($cgiparams{'ROOTCERT_HOSTNAME'})) {
889 $errormessage = $Lang::tr{'invalid input for hostname'};
890 goto ROOTCERT_ERROR;
891 }
892 if ($cgiparams{'ROOTCERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'ROOTCERT_EMAIL'}))) {
893 $errormessage = $Lang::tr{'invalid input for e-mail address'};
894 goto ROOTCERT_ERROR;
895 }
896 if (length($cgiparams{'ROOTCERT_EMAIL'}) > 40) {
897 $errormessage = $Lang::tr{'e-mail address too long'};
898 goto ROOTCERT_ERROR;
899 }
900 if ($cgiparams{'ROOTCERT_OU'} ne '' && $cgiparams{'ROOTCERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
901 $errormessage = $Lang::tr{'invalid input for department'};
902 goto ROOTCERT_ERROR;
903 }
904 if ($cgiparams{'ROOTCERT_CITY'} ne '' && $cgiparams{'ROOTCERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
905 $errormessage = $Lang::tr{'invalid input for city'};
906 goto ROOTCERT_ERROR;
907 }
908 if ($cgiparams{'ROOTCERT_STATE'} ne '' && $cgiparams{'ROOTCERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
909 $errormessage = $Lang::tr{'invalid input for state or province'};
910 goto ROOTCERT_ERROR;
911 }
912 if ($cgiparams{'ROOTCERT_COUNTRY'} !~ /^[A-Z]*$/) {
913 $errormessage = $Lang::tr{'invalid input for country'};
914 goto ROOTCERT_ERROR;
915 }
916 #the exact syntax is a list comma separated of
917 # email:any-validemail
918 # URI: a uniform resource indicator
919 # DNS: a DNS domain name
920 # RID: a registered OBJECT IDENTIFIER
921 # IP: an IP address
922 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
923
924 if ($cgiparams{'SUBJECTALTNAME'} ne '' && $cgiparams{'SUBJECTALTNAME'} !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/,\.\-_@]*$/) {
925 $errormessage = $Lang::tr{'vpn altname syntax'};
926 goto VPNCONF_ERROR;
927 }
928
929 # Copy the cgisettings to vpnsettings and save the configfile
930 $vpnsettings{'ROOTCERT_ORGANIZATION'} = $cgiparams{'ROOTCERT_ORGANIZATION'};
931 $vpnsettings{'ROOTCERT_HOSTNAME'} = $cgiparams{'ROOTCERT_HOSTNAME'};
932 $vpnsettings{'ROOTCERT_EMAIL'} = $cgiparams{'ROOTCERT_EMAIL'};
933 $vpnsettings{'ROOTCERT_OU'} = $cgiparams{'ROOTCERT_OU'};
934 $vpnsettings{'ROOTCERT_CITY'} = $cgiparams{'ROOTCERT_CITY'};
935 $vpnsettings{'ROOTCERT_STATE'} = $cgiparams{'ROOTCERT_STATE'};
936 $vpnsettings{'ROOTCERT_COUNTRY'} = $cgiparams{'ROOTCERT_COUNTRY'};
937 &General::writehash("${General::swroot}/vpn/settings", \%vpnsettings);
938
939 # Replace empty strings with a .
940 (my $ou = $cgiparams{'ROOTCERT_OU'}) =~ s/^\s*$/\./;
941 (my $city = $cgiparams{'ROOTCERT_CITY'}) =~ s/^\s*$/\./;
942 (my $state = $cgiparams{'ROOTCERT_STATE'}) =~ s/^\s*$/\./;
943
944 # Create the CA certificate
945 if (!$errormessage) {
946 &General::log("ipsec", "Creating cacert...");
947 if (open(STDIN, "-|")) {
948 my $opt = " req -x509 -sha256 -nodes";
949 $opt .= " -days 999999";
950 $opt .= " -newkey rsa:4096";
951 $opt .= " -keyout ${General::swroot}/private/cakey.pem";
952 $opt .= " -out ${General::swroot}/ca/cacert.pem";
953
954 $errormessage = &callssl ($opt);
955 } else { #child
956 print "$cgiparams{'ROOTCERT_COUNTRY'}\n";
957 print "$state\n";
958 print "$city\n";
959 print "$cgiparams{'ROOTCERT_ORGANIZATION'}\n";
960 print "$ou\n";
961 print "$cgiparams{'ROOTCERT_ORGANIZATION'} CA\n";
962 print "$cgiparams{'ROOTCERT_EMAIL'}\n";
963 exit (0);
964 }
965 }
966
967 # Create the Host certificate request
968 if (!$errormessage) {
969 &General::log("ipsec", "Creating host cert...");
970 if (open(STDIN, "-|")) {
971 my $opt = " req -sha256 -nodes";
972 $opt .= " -newkey rsa:2048";
973 $opt .= " -keyout ${General::swroot}/certs/hostkey.pem";
974 $opt .= " -out ${General::swroot}/certs/hostreq.pem";
975 $errormessage = &callssl ($opt);
976 } else { #child
977 print "$cgiparams{'ROOTCERT_COUNTRY'}\n";
978 print "$state\n";
979 print "$city\n";
980 print "$cgiparams{'ROOTCERT_ORGANIZATION'}\n";
981 print "$ou\n";
982 print "$cgiparams{'ROOTCERT_HOSTNAME'}\n";
983 print "$cgiparams{'ROOTCERT_EMAIL'}\n";
984 print ".\n";
985 print ".\n";
986 exit (0);
987 }
988 }
989
990 # Sign the host certificate request
991 if (!$errormessage) {
992 &General::log("ipsec", "Self signing host cert...");
993
994 #No easy way for specifying the contain of subjectAltName without writing a config file...
995 my ($fh, $v3extname) = tempfile ('/tmp/XXXXXXXX');
996 print $fh <<END
997 basicConstraints=CA:FALSE
998 nsComment="OpenSSL Generated Certificate"
999 subjectKeyIdentifier=hash
1000 authorityKeyIdentifier=keyid,issuer:always
1001 extendedKeyUsage = serverAuth
1002 END
1003 ;
1004 print $fh "subjectAltName=$cgiparams{'SUBJECTALTNAME'}" if ($cgiparams{'SUBJECTALTNAME'});
1005 close ($fh);
1006
1007 my $opt = " ca -md sha256 -days 999999";
1008 $opt .= " -batch -notext";
1009 $opt .= " -in ${General::swroot}/certs/hostreq.pem";
1010 $opt .= " -out ${General::swroot}/certs/hostcert.pem";
1011 $opt .= " -extfile $v3extname";
1012 $errormessage = &callssl ($opt);
1013 unlink ("${General::swroot}/certs/hostreq.pem"); #no more needed
1014 unlink ($v3extname);
1015 }
1016
1017 # Create an empty CRL
1018 if (!$errormessage) {
1019 &General::log("ipsec", "Creating emptycrl...");
1020 my $opt = " ca -gencrl";
1021 $opt .= " -out ${General::swroot}/crls/cacrl.pem";
1022 $errormessage = &callssl ($opt);
1023 }
1024
1025 # Successfully build CA / CERT!
1026 if (!$errormessage) {
1027 &cleanssldatabase();
1028 goto ROOTCERT_SUCCESS;
1029 }
1030
1031 #Cleanup
1032 unlink ("${General::swroot}/ca/cacert.pem");
1033 unlink ("${General::swroot}/certs/hostkey.pem");
1034 unlink ("${General::swroot}/certs/hostcert.pem");
1035 unlink ("${General::swroot}/crls/cacrl.pem");
1036 &cleanssldatabase();
1037 }
1038
1039 ROOTCERT_ERROR:
1040 &Header::showhttpheaders();
1041 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
1042 &Header::openbigbox('100%', 'left', '', $errormessage);
1043 if ($errormessage) {
1044 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
1045 print "<class name='base'>$errormessage";
1046 print "&nbsp;</class>";
1047 &Header::closebox();
1048 }
1049 &Header::openbox('100%', 'left', "$Lang::tr{'generate root/host certificates'}:");
1050 print <<END
1051 <form method='post' enctype='multipart/form-data' action='$ENV{'SCRIPT_NAME'}'>
1052 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1053 <tr><td width='40%' class='base'>$Lang::tr{'organization name'}:</td>
1054 <td width='60%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value='$cgiparams{'ROOTCERT_ORGANIZATION'}' size='32' /></td></tr>
1055 <tr><td class='base'>$Lang::tr{'ipfires hostname'}:</td>
1056 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value='$cgiparams{'ROOTCERT_HOSTNAME'}' size='32' /></td></tr>
1057 <tr><td class='base'>$Lang::tr{'your e-mail'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1058 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value='$cgiparams{'ROOTCERT_EMAIL'}' size='32' /></td></tr>
1059 <tr><td class='base'>$Lang::tr{'your department'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1060 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value='$cgiparams{'ROOTCERT_OU'}' size='32' /></td></tr>
1061 <tr><td class='base'>$Lang::tr{'city'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1062 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value='$cgiparams{'ROOTCERT_CITY'}' size='32' /></td></tr>
1063 <tr><td class='base'>$Lang::tr{'state or province'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1064 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value='$cgiparams{'ROOTCERT_STATE'}' size='32' /></td></tr>
1065 <tr><td class='base'>$Lang::tr{'country'}:</td>
1066 <td class='base'><select name='ROOTCERT_COUNTRY'>
1067 END
1068 ;
1069 foreach my $country (sort keys %{Countries::countries}) {
1070 print "<option value='$Countries::countries{$country}'";
1071 if ( $Countries::countries{$country} eq $cgiparams{'ROOTCERT_COUNTRY'} ) {
1072 print " selected='selected'";
1073 }
1074 print ">$country</option>";
1075 }
1076 print <<END
1077 </select></td></tr>
1078 <tr><td class='base'>$Lang::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*) <img src='/blob.gif' alt='*' /></td>
1079 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value='$cgiparams{'SUBJECTALTNAME'}' size='32' /></td></tr>
1080 <tr><td>&nbsp;</td>
1081 <td><br /><input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' /><br /><br /></td></tr>
1082 <tr><td class='base' colspan='2' align='left'>
1083 <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>:
1084 $Lang::tr{'generating the root and host certificates may take a long time. it can take up to several minutes on older hardware. please be patient'}
1085 </td></tr>
1086 <tr><td colspan='2'><hr></td></tr>
1087 <tr><td class='base' nowrap='nowrap'>$Lang::tr{'upload p12 file'}:</td>
1088 <td nowrap='nowrap'><input type='file' name='FH' size='32' /></td></tr>
1089 <tr><td class='base'>$Lang::tr{'pkcs12 file password'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1090 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value='$cgiparams{'P12_PASS'}' size='32' /></td></tr>
1091 <tr><td>&nbsp;</td>
1092 <td><input type='submit' name='ACTION' value='$Lang::tr{'upload p12 file'}' /></td></tr>
1093 <tr><td class='base' colspan='2' align='left'>
1094 <img src='/blob.gif' alt='*' />&nbsp;$Lang::tr{'this field may be blank'}</td></tr>
1095 </table></form>
1096 END
1097 ;
1098 &Header::closebox();
1099 &Header::closebigbox();
1100 &Header::closepage();
1101 exit(0);
1102
1103 ROOTCERT_SUCCESS:
1104 if (&vpnenabled) {
1105 system('/usr/local/bin/ipsecctrl', 'S');
1106 sleep $sleepDelay;
1107 }
1108 ROOTCERT_SKIP:
1109 ###
1110 ### Export PKCS12 file to browser
1111 ###
1112 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download pkcs12 file'}) {
1113 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
1114 print "Content-Type: application/force-download\n";
1115 print "Content-Disposition: attachment; filename=" . $confighash{$cgiparams{'KEY'}}[1] . ".p12\r\n";
1116 print "Content-Type: application/octet-stream\r\n\r\n";
1117 print `/bin/cat ${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1].p12`;
1118 exit (0);
1119
1120 ###
1121 ### Display certificate
1122 ###
1123 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show certificate'}) {
1124 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
1125
1126 if ( -f "${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") {
1127 &Header::showhttpheaders();
1128 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
1129 &Header::openbigbox('100%', 'left', '', '');
1130 &Header::openbox('100%', 'left', "$Lang::tr{'cert'}:");
1131 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`;
1132 $output = &Header::cleanhtml($output,"y");
1133 print "<pre>$output</pre>\n";
1134 &Header::closebox();
1135 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'>$Lang::tr{'back'}</a></div>";
1136 &Header::closebigbox();
1137 &Header::closepage();
1138 exit(0);
1139 }
1140
1141 ###
1142 ### Export Certificate to browser
1143 ###
1144 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download certificate'}) {
1145 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
1146
1147 if ( -f "${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") {
1148 print "Content-Type: application/force-download\n";
1149 print "Content-Disposition: attachment; filename=" . $confighash{$cgiparams{'KEY'}}[1] . "cert.pem\n\n";
1150 print `/bin/cat ${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`;
1151 exit (0);
1152 }
1153
1154 ###
1155 ### Enable/Disable connection
1156 ###
1157 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) {
1158
1159 &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings);
1160 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
1161
1162 if ($confighash{$cgiparams{'KEY'}}) {
1163 if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') {
1164 $confighash{$cgiparams{'KEY'}}[0] = 'on';
1165 &General::writehasharray("${General::swroot}/vpn/config", \%confighash);
1166 &writeipsecfiles();
1167 system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}) if (&vpnenabled);
1168 } else {
1169 system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}) if (&vpnenabled);
1170 $confighash{$cgiparams{'KEY'}}[0] = 'off';
1171 &General::writehasharray("${General::swroot}/vpn/config", \%confighash);
1172 &writeipsecfiles();
1173 }
1174 sleep $sleepDelay;
1175 } else {
1176 $errormessage = $Lang::tr{'invalid key'};
1177 }
1178
1179 ###
1180 ### Restart connection
1181 ###
1182 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'restart'}) {
1183 &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings);
1184 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
1185
1186 if ($confighash{$cgiparams{'KEY'}}) {
1187 if (&vpnenabled) {
1188 system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
1189 sleep $sleepDelay;
1190 }
1191 } else {
1192 $errormessage = $Lang::tr{'invalid key'};
1193 }
1194
1195 ###
1196 ### Remove connection
1197 ###
1198 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) {
1199 &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings);
1200 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
1201
1202 if ($confighash{$cgiparams{'KEY'}}) {
1203 system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}) if (&vpnenabled);
1204 unlink ("${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem");
1205 unlink ("${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1].p12");
1206 delete $confighash{$cgiparams{'KEY'}};
1207 &General::writehasharray("${General::swroot}/vpn/config", \%confighash);
1208 &writeipsecfiles();
1209 } else {
1210 $errormessage = $Lang::tr{'invalid key'};
1211 }
1212 &General::firewall_reload();
1213 ###
1214 ### Choose between adding a host-net or net-net connection
1215 ###
1216 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'add'} && $cgiparams{'TYPE'} eq '') {
1217 &Header::showhttpheaders();
1218 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
1219 &Header::openbigbox('100%', 'left', '', '');
1220 &Header::openbox('100%', 'left', $Lang::tr{'connection type'});
1221 print <<END
1222 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1223 <b>$Lang::tr{'connection type'}:</b><br />
1224 <table>
1225 <tr><td><input type='radio' name='TYPE' value='host' checked='checked' /></td>
1226 <td class='base'>$Lang::tr{'host to net vpn'}</td>
1227 </tr><tr>
1228 <td><input type='radio' name='TYPE' value='net' /></td>
1229 <td class='base'>$Lang::tr{'net to net vpn'}</td>
1230 </tr><tr>
1231 <td align='center' colspan='2'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td>
1232 </tr>
1233 </table></form>
1234 END
1235 ;
1236 &Header::closebox();
1237 &Header::closebigbox();
1238 &Header::closepage();
1239 exit (0);
1240 ###
1241 ### Adding/Editing/Saving a connection
1242 ###
1243 } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) ||
1244 ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) ||
1245 ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'ADVANCED'} eq '')) {
1246
1247 &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings);
1248 &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash);
1249 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
1250
1251 if ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) {
1252 if (! $confighash{$cgiparams{'KEY'}}[0]) {
1253 $errormessage = $Lang::tr{'invalid key'};
1254 goto VPNCONF_END;
1255 }
1256 $cgiparams{'ENABLED'} = $confighash{$cgiparams{'KEY'}}[0];
1257 $cgiparams{'NAME'} = $confighash{$cgiparams{'KEY'}}[1];
1258 $cgiparams{'TYPE'} = $confighash{$cgiparams{'KEY'}}[3];
1259 $cgiparams{'AUTH'} = $confighash{$cgiparams{'KEY'}}[4];
1260 $cgiparams{'PSK'} = $confighash{$cgiparams{'KEY'}}[5];
1261 #$cgiparams{'free'} = $confighash{$cgiparams{'KEY'}}[6];
1262 $cgiparams{'LOCAL_ID'} = $confighash{$cgiparams{'KEY'}}[7];
1263 my @local_subnets = split(",", $confighash{$cgiparams{'KEY'}}[8]);
1264 $cgiparams{'LOCAL_SUBNET'} = join(/\|/, @local_subnets);
1265 $cgiparams{'REMOTE_ID'} = $confighash{$cgiparams{'KEY'}}[9];
1266 $cgiparams{'REMOTE'} = $confighash{$cgiparams{'KEY'}}[10];
1267 my @remote_subnets = split(",", $confighash{$cgiparams{'KEY'}}[11]);
1268 $cgiparams{'REMOTE_SUBNET'} = join(/\|/, @remote_subnets);
1269 $cgiparams{'REMARK'} = $confighash{$cgiparams{'KEY'}}[25];
1270 $cgiparams{'DPD_ACTION'} = $confighash{$cgiparams{'KEY'}}[27];
1271 $cgiparams{'IKE_VERSION'} = $confighash{$cgiparams{'KEY'}}[29];
1272 $cgiparams{'IKE_ENCRYPTION'} = $confighash{$cgiparams{'KEY'}}[18];
1273 $cgiparams{'IKE_INTEGRITY'} = $confighash{$cgiparams{'KEY'}}[19];
1274 $cgiparams{'IKE_GROUPTYPE'} = $confighash{$cgiparams{'KEY'}}[20];
1275 $cgiparams{'IKE_LIFETIME'} = $confighash{$cgiparams{'KEY'}}[16];
1276 $cgiparams{'ESP_ENCRYPTION'} = $confighash{$cgiparams{'KEY'}}[21];
1277 $cgiparams{'ESP_INTEGRITY'} = $confighash{$cgiparams{'KEY'}}[22];
1278 $cgiparams{'ESP_GROUPTYPE'} = $confighash{$cgiparams{'KEY'}}[23];
1279 if ($cgiparams{'ESP_GROUPTYPE'} eq "") {
1280 $cgiparams{'ESP_GROUPTYPE'} = $cgiparams{'IKE_GROUPTYPE'};
1281 }
1282 $cgiparams{'ESP_KEYLIFE'} = $confighash{$cgiparams{'KEY'}}[17];
1283 $cgiparams{'COMPRESSION'} = $confighash{$cgiparams{'KEY'}}[13];
1284 $cgiparams{'ONLY_PROPOSED'} = $confighash{$cgiparams{'KEY'}}[24];
1285 $cgiparams{'PFS'} = $confighash{$cgiparams{'KEY'}}[28];
1286 $cgiparams{'VHOST'} = $confighash{$cgiparams{'KEY'}}[14];
1287 $cgiparams{'DPD_TIMEOUT'} = $confighash{$cgiparams{'KEY'}}[30];
1288 $cgiparams{'DPD_DELAY'} = $confighash{$cgiparams{'KEY'}}[31];
1289
1290 if (!$cgiparams{'DPD_DELAY'}) {
1291 $cgiparams{'DPD_DELAY'} = 30;
1292 }
1293
1294 if (!$cgiparams{'DPD_TIMEOUT'}) {
1295 $cgiparams{'DPD_TIMEOUT'} = 120;
1296 }
1297
1298 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) {
1299 $cgiparams{'REMARK'} = &Header::cleanhtml($cgiparams{'REMARK'});
1300 if ($cgiparams{'TYPE'} !~ /^(host|net)$/) {
1301 $errormessage = $Lang::tr{'connection type is invalid'};
1302 goto VPNCONF_ERROR;
1303 }
1304
1305 if ($cgiparams{'NAME'} !~ /^[a-zA-Z0-9]+$/) {
1306 $errormessage = $Lang::tr{'name must only contain characters'};
1307 goto VPNCONF_ERROR;
1308 }
1309
1310 if ($cgiparams{'NAME'} =~ /^(host|01|block|private|clear|packetdefault)$/) {
1311 $errormessage = $Lang::tr{'name is invalid'};
1312 goto VPNCONF_ERROR;
1313 }
1314
1315 if (length($cgiparams{'NAME'}) >60) {
1316 $errormessage = $Lang::tr{'name too long'};
1317 goto VPNCONF_ERROR;
1318 }
1319
1320 # Check if there is no other entry with this name
1321 if (! $cgiparams{'KEY'}) { #only for add
1322 foreach my $key (keys %confighash) {
1323 if ($confighash{$key}[1] eq $cgiparams{'NAME'}) {
1324 $errormessage = $Lang::tr{'a connection with this name already exists'};
1325 goto VPNCONF_ERROR;
1326 }
1327 }
1328 }
1329
1330 if (($cgiparams{'TYPE'} eq 'net') && (! $cgiparams{'REMOTE'})) {
1331 $errormessage = $Lang::tr{'invalid input for remote host/ip'};
1332 goto VPNCONF_ERROR;
1333 }
1334
1335 if ($cgiparams{'REMOTE'}) {
1336 if (($cgiparams{'REMOTE'} ne '%any') && (! &General::validip($cgiparams{'REMOTE'}))) {
1337 if (! &General::validfqdn ($cgiparams{'REMOTE'})) {
1338 $errormessage = $Lang::tr{'invalid input for remote host/ip'};
1339 goto VPNCONF_ERROR;
1340 } else {
1341 if (&valid_dns_host($cgiparams{'REMOTE'})) {
1342 $warnmessage = "$Lang::tr{'check vpn lr'} $cgiparams{'REMOTE'}. $Lang::tr{'dns check failed'}";
1343 }
1344 }
1345 }
1346 }
1347
1348 my @local_subnets = split(",", $cgiparams{'LOCAL_SUBNET'});
1349 foreach my $subnet (@local_subnets) {
1350 unless (&Network::check_subnet($subnet)) {
1351 $errormessage = $Lang::tr{'local subnet is invalid'};
1352 goto VPNCONF_ERROR;
1353 }
1354 }
1355
1356 # Allow only one roadwarrior/psk without remote IP-address
1357 if ($cgiparams{'REMOTE'} eq '' && $cgiparams{'AUTH'} eq 'psk') {
1358 foreach my $key (keys %confighash) {
1359 if ( ($cgiparams{'KEY'} ne $key) &&
1360 ($confighash{$key}[4] eq 'psk') &&
1361 ($confighash{$key}[10] eq '') ) {
1362 $errormessage = $Lang::tr{'you can only define one roadwarrior connection when using pre-shared key authentication'};
1363 goto VPNCONF_ERROR;
1364 }
1365 }
1366 }
1367
1368 if ($cgiparams{'TYPE'} eq 'net') {
1369 my @remote_subnets = split(",", $cgiparams{'REMOTE_SUBNET'});
1370 foreach my $subnet (@remote_subnets) {
1371 unless (&Network::check_subnet($subnet)) {
1372 $errormessage = $Lang::tr{'remote subnet is invalid'};
1373 goto VPNCONF_ERROR;
1374 }
1375 }
1376 }
1377
1378 if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) {
1379 $errormessage = $Lang::tr{'invalid input'};
1380 goto VPNCONF_ERROR;
1381 }
1382 if ($cgiparams{'EDIT_ADVANCED'} !~ /^(on|off)$/) {
1383 $errormessage = $Lang::tr{'invalid input'};
1384 goto VPNCONF_ERROR;
1385 }
1386
1387 # Allow nothing or a string (DN,FDQN,) beginning with @
1388 # with no comma but slashes between RID eg @O=FR/C=Paris/OU=myhome/CN=franck
1389 if ( ($cgiparams{'LOCAL_ID'} !~ /^(|[\w.-]*@[\w. =*\/-]+|\d+\.\d+\.\d+\.\d+)$/) ||
1390 ($cgiparams{'REMOTE_ID'} !~ /^(|[\w.-]*@[\w. =*\/-]+|\d+\.\d+\.\d+\.\d+)$/) ||
1391 (($cgiparams{'REMOTE_ID'} eq $cgiparams{'LOCAL_ID'}) && ($cgiparams{'LOCAL_ID'} ne ''))
1392 ) {
1393 $errormessage = $Lang::tr{'invalid local-remote id'} . '<br />' .
1394 'DER_ASN1_DN: @c=FR/ou=Paris/ou=Home/cn=*<br />' .
1395 'FQDN: @ipfire.org<br />' .
1396 'USER_FQDN: info@ipfire.org<br />' .
1397 'IPV4_ADDR: 123.123.123.123';
1398 goto VPNCONF_ERROR;
1399 }
1400 # If Auth is DN, verify existance of Remote ID.
1401 if ( $cgiparams{'REMOTE_ID'} eq '' && (
1402 $cgiparams{'AUTH'} eq 'auth-dn'|| # while creation
1403 $confighash{$cgiparams{'KEY'}}[2] eq '%auth-dn')){ # while editing
1404 $errormessage = $Lang::tr{'vpn missing remote id'};
1405 goto VPNCONF_ERROR;
1406 }
1407
1408 if ($cgiparams{'TYPE'} eq 'net'){
1409 $warnmessage=&General::checksubnets('',$cgiparams{'REMOTE_SUBNET'},'ipsec');
1410 if ($warnmessage ne ''){
1411 $warnmessage=$Lang::tr{'remote subnet'}." ($cgiparams{'REMOTE_SUBNET'}) <br>".$warnmessage;
1412 }
1413 }
1414
1415 if ($cgiparams{'AUTH'} eq 'psk') {
1416 if (! length($cgiparams{'PSK'}) ) {
1417 $errormessage = $Lang::tr{'pre-shared key is too short'};
1418 goto VPNCONF_ERROR;
1419 }
1420 if ($cgiparams{'PSK'} =~ /'/) {
1421 $cgiparams{'PSK'} =~ tr/'/ /;
1422 $errormessage = $Lang::tr{'invalid characters found in pre-shared key'};
1423 goto VPNCONF_ERROR;
1424 }
1425 } elsif ($cgiparams{'AUTH'} eq 'certreq') {
1426 if ($cgiparams{'KEY'}) {
1427 $errormessage = $Lang::tr{'cant change certificates'};
1428 goto VPNCONF_ERROR;
1429 }
1430 if (ref ($cgiparams{'FH'}) ne 'Fh') {
1431 $errormessage = $Lang::tr{'there was no file upload'};
1432 goto VPNCONF_ERROR;
1433 }
1434
1435 # Move uploaded certificate request to a temporary file
1436 (my $fh, my $filename) = tempfile( );
1437 if (copy ($cgiparams{'FH'}, $fh) != 1) {
1438 $errormessage = $!;
1439 goto VPNCONF_ERROR;
1440 }
1441
1442 # Sign the certificate request
1443 &General::log("ipsec", "Signing your cert $cgiparams{'NAME'}...");
1444 my $opt = " ca -md sha256 -days 999999";
1445 $opt .= " -batch -notext";
1446 $opt .= " -in $filename";
1447 $opt .= " -out ${General::swroot}/certs/$cgiparams{'NAME'}cert.pem";
1448
1449 if ( $errormessage = &callssl ($opt) ) {
1450 unlink ($filename);
1451 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1452 &cleanssldatabase();
1453 goto VPNCONF_ERROR;
1454 } else {
1455 unlink ($filename);
1456 &cleanssldatabase();
1457 }
1458
1459 $cgiparams{'CERT_NAME'} = getCNfromcert ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1460 if ($cgiparams{'CERT_NAME'} eq '') {
1461 $errormessage = $Lang::tr{'could not retrieve common name from certificate'};
1462 goto VPNCONF_ERROR;
1463 }
1464 } elsif ($cgiparams{'AUTH'} eq 'pkcs12') {
1465 &General::log("ipsec", "Importing from p12...");
1466
1467 if (ref ($cgiparams{'FH'}) ne 'Fh') {
1468 $errormessage = $Lang::tr{'there was no file upload'};
1469 goto ROOTCERT_ERROR;
1470 }
1471
1472 # Move uploaded certificate request to a temporary file
1473 (my $fh, my $filename) = tempfile( );
1474 if (copy ($cgiparams{'FH'}, $fh) != 1) {
1475 $errormessage = $!;
1476 goto ROOTCERT_ERROR;
1477 }
1478
1479 # Extract the CA certificate from the file
1480 &General::log("ipsec", "Extracting caroot from p12...");
1481 if (open(STDIN, "-|")) {
1482 my $opt = " pkcs12 -cacerts -nokeys";
1483 $opt .= " -in $filename";
1484 $opt .= " -out /tmp/newcacert";
1485 $errormessage = &callssl ($opt);
1486 } else { #child
1487 print "$cgiparams{'P12_PASS'}\n";
1488 exit (0);
1489 }
1490
1491 # Extract the Host certificate from the file
1492 if (!$errormessage) {
1493 &General::log("ipsec", "Extracting host cert from p12...");
1494 if (open(STDIN, "-|")) {
1495 my $opt = " pkcs12 -clcerts -nokeys";
1496 $opt .= " -in $filename";
1497 $opt .= " -out /tmp/newhostcert";
1498 $errormessage = &callssl ($opt);
1499 } else { #child
1500 print "$cgiparams{'P12_PASS'}\n";
1501 exit (0);
1502 }
1503 }
1504
1505 if (!$errormessage) {
1506 &General::log("ipsec", "Moving cacert...");
1507 #If CA have new subject, add it to our list of CA
1508 my $casubject = &Header::cleanhtml(getsubjectfromcert ('/tmp/newcacert'));
1509 my @names;
1510 foreach my $x (keys %cahash) {
1511 $casubject='' if ($cahash{$x}[1] eq $casubject);
1512 unshift (@names,$cahash{$x}[0]);
1513 }
1514 if ($casubject) { # a new one!
1515 my $temp = `/usr/bin/openssl x509 -text -in /tmp/newcacert`;
1516 if ($temp !~ /CA:TRUE/i) {
1517 $errormessage = $Lang::tr{'not a valid ca certificate'};
1518 } else {
1519 #compute a name for it
1520 my $idx=0;
1521 while (grep(/Imported-$idx/, @names) ) {$idx++};
1522 $cgiparams{'CA_NAME'}="Imported-$idx";
1523 $cgiparams{'CERT_NAME'}=&Header::cleanhtml(getCNfromcert ('/tmp/newhostcert'));
1524 move("/tmp/newcacert", "${General::swroot}/ca/$cgiparams{'CA_NAME'}cert.pem");
1525 $errormessage = "$Lang::tr{'certificate file move failed'}: $!" if ($? ne 0);
1526 if (!$errormessage) {
1527 my $key = &General::findhasharraykey (\%cahash);
1528 $cahash{$key}[0] = $cgiparams{'CA_NAME'};
1529 $cahash{$key}[1] = $casubject;
1530 &General::writehasharray("${General::swroot}/vpn/caconfig", \%cahash);
1531 system('/usr/local/bin/ipsecctrl', 'R');
1532 }
1533 }
1534 }
1535 }
1536 if (!$errormessage) {
1537 &General::log("ipsec", "Moving host cert...");
1538 move("/tmp/newhostcert", "${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1539 $errormessage = "$Lang::tr{'certificate file move failed'}: $!" if ($? ne 0);
1540 }
1541
1542 #cleanup temp files
1543 unlink ($filename);
1544 unlink ('/tmp/newcacert');
1545 unlink ('/tmp/newhostcert');
1546 if ($errormessage) {
1547 unlink ("${General::swroot}/ca/$cgiparams{'CA_NAME'}cert.pem");
1548 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1549 goto VPNCONF_ERROR;
1550 }
1551 &General::log("ipsec", "p12 import completed!");
1552 } elsif ($cgiparams{'AUTH'} eq 'certfile') {
1553 if ($cgiparams{'KEY'}) {
1554 $errormessage = $Lang::tr{'cant change certificates'};
1555 goto VPNCONF_ERROR;
1556 }
1557 if (ref ($cgiparams{'FH'}) ne 'Fh') {
1558 $errormessage = $Lang::tr{'there was no file upload'};
1559 goto VPNCONF_ERROR;
1560 }
1561 # Move uploaded certificate to a temporary file
1562 (my $fh, my $filename) = tempfile( );
1563 if (copy ($cgiparams{'FH'}, $fh) != 1) {
1564 $errormessage = $!;
1565 goto VPNCONF_ERROR;
1566 }
1567
1568 # Verify the certificate has a valid CA and move it
1569 &General::log("ipsec", "Validating imported cert against our known CA...");
1570 my $validca = 1; #assume ok
1571 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/cacert.pem $filename`;
1572 if ($test !~ /: OK/) {
1573 my $validca = 0;
1574 foreach my $key (keys %cahash) {
1575 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/$cahash{$key}[0]cert.pem $filename`;
1576 if ($test =~ /: OK/) {
1577 $validca = 1;
1578 last;
1579 }
1580 }
1581 }
1582 if (! $validca) {
1583 $errormessage = $Lang::tr{'certificate does not have a valid ca associated with it'};
1584 unlink ($filename);
1585 goto VPNCONF_ERROR;
1586 } else {
1587 move($filename, "${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1588 if ($? ne 0) {
1589 $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
1590 unlink ($filename);
1591 goto VPNCONF_ERROR;
1592 }
1593 }
1594
1595 $cgiparams{'CERT_NAME'} = getCNfromcert ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1596 if ($cgiparams{'CERT_NAME'} eq '') {
1597 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1598 $errormessage = $Lang::tr{'could not retrieve common name from certificate'};
1599 goto VPNCONF_ERROR;
1600 }
1601 } elsif ($cgiparams{'AUTH'} eq 'certgen') {
1602 if ($cgiparams{'KEY'}) {
1603 $errormessage = $Lang::tr{'cant change certificates'};
1604 goto VPNCONF_ERROR;
1605 }
1606 # Validate input since the form was submitted
1607 if (length($cgiparams{'CERT_NAME'}) >60) {
1608 $errormessage = $Lang::tr{'name too long'};
1609 goto VPNCONF_ERROR;
1610 }
1611 if ($cgiparams{'CERT_NAME'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) {
1612 $errormessage = $Lang::tr{'invalid input for name'};
1613 goto VPNCONF_ERROR;
1614 }
1615 if ($cgiparams{'CERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'CERT_EMAIL'}))) {
1616 $errormessage = $Lang::tr{'invalid input for e-mail address'};
1617 goto VPNCONF_ERROR;
1618 }
1619 if (length($cgiparams{'CERT_EMAIL'}) > 40) {
1620 $errormessage = $Lang::tr{'e-mail address too long'};
1621 goto VPNCONF_ERROR;
1622 }
1623 if ($cgiparams{'CERT_OU'} ne '' && $cgiparams{'CERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1624 $errormessage = $Lang::tr{'invalid input for department'};
1625 goto VPNCONF_ERROR;
1626 }
1627 if (length($cgiparams{'CERT_ORGANIZATION'}) >60) {
1628 $errormessage = $Lang::tr{'organization too long'};
1629 goto VPNCONF_ERROR;
1630 }
1631 if ($cgiparams{'CERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) {
1632 $errormessage = $Lang::tr{'invalid input for organization'};
1633 goto VPNCONF_ERROR;
1634 }
1635 if ($cgiparams{'CERT_CITY'} ne '' && $cgiparams{'CERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1636 $errormessage = $Lang::tr{'invalid input for city'};
1637 goto VPNCONF_ERROR;
1638 }
1639 if ($cgiparams{'CERT_STATE'} ne '' && $cgiparams{'CERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1640 $errormessage = $Lang::tr{'invalid input for state or province'};
1641 goto VPNCONF_ERROR;
1642 }
1643 if ($cgiparams{'CERT_COUNTRY'} !~ /^[A-Z]*$/) {
1644 $errormessage = $Lang::tr{'invalid input for country'};
1645 goto VPNCONF_ERROR;
1646 }
1647 #the exact syntax is a list comma separated of
1648 # email:any-validemail
1649 # URI: a uniform resource indicator
1650 # DNS: a DNS domain name
1651 # RID: a registered OBJECT IDENTIFIER
1652 # IP: an IP address
1653 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
1654
1655 if ($cgiparams{'SUBJECTALTNAME'} ne '' && $cgiparams{'SUBJECTALTNAME'} !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/,\.\-_@]*$/) {
1656 $errormessage = $Lang::tr{'vpn altname syntax'};
1657 goto VPNCONF_ERROR;
1658 }
1659
1660 if (length($cgiparams{'CERT_PASS1'}) < 5) {
1661 $errormessage = $Lang::tr{'password too short'};
1662 goto VPNCONF_ERROR;
1663 }
1664 if ($cgiparams{'CERT_PASS1'} ne $cgiparams{'CERT_PASS2'}) {
1665 $errormessage = $Lang::tr{'passwords do not match'};
1666 goto VPNCONF_ERROR;
1667 }
1668
1669 # Replace empty strings with a .
1670 (my $ou = $cgiparams{'CERT_OU'}) =~ s/^\s*$/\./;
1671 (my $city = $cgiparams{'CERT_CITY'}) =~ s/^\s*$/\./;
1672 (my $state = $cgiparams{'CERT_STATE'}) =~ s/^\s*$/\./;
1673
1674 # Create the Client certificate request
1675 &General::log("ipsec", "Creating a cert...");
1676
1677 if (open(STDIN, "-|")) {
1678 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache";
1679 $opt .= " -newkey rsa:2048";
1680 $opt .= " -keyout ${General::swroot}/certs/$cgiparams{'NAME'}key.pem";
1681 $opt .= " -out ${General::swroot}/certs/$cgiparams{'NAME'}req.pem";
1682
1683 if ( $errormessage = &callssl ($opt) ) {
1684 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}key.pem");
1685 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}req.pem");
1686 goto VPNCONF_ERROR;
1687 }
1688 } else { #child
1689 print "$cgiparams{'CERT_COUNTRY'}\n";
1690 print "$state\n";
1691 print "$city\n";
1692 print "$cgiparams{'CERT_ORGANIZATION'}\n";
1693 print "$ou\n";
1694 print "$cgiparams{'CERT_NAME'}\n";
1695 print "$cgiparams{'CERT_EMAIL'}\n";
1696 print ".\n";
1697 print ".\n";
1698 exit (0);
1699 }
1700
1701 # Sign the client certificate request
1702 &General::log("ipsec", "Signing the cert $cgiparams{'NAME'}...");
1703
1704 #No easy way for specifying the contain of subjectAltName without writing a config file...
1705 my ($fh, $v3extname) = tempfile ('/tmp/XXXXXXXX');
1706 print $fh <<END
1707 basicConstraints=CA:FALSE
1708 nsComment="OpenSSL Generated Certificate"
1709 subjectKeyIdentifier=hash
1710 extendedKeyUsage=clientAuth
1711 authorityKeyIdentifier=keyid,issuer:always
1712 END
1713 ;
1714 print $fh "subjectAltName=$cgiparams{'SUBJECTALTNAME'}" if ($cgiparams{'SUBJECTALTNAME'});
1715 close ($fh);
1716
1717 my $opt = " ca -md sha256 -days 999999 -batch -notext";
1718 $opt .= " -in ${General::swroot}/certs/$cgiparams{'NAME'}req.pem";
1719 $opt .= " -out ${General::swroot}/certs/$cgiparams{'NAME'}cert.pem";
1720 $opt .= " -extfile $v3extname";
1721
1722 if ( $errormessage = &callssl ($opt) ) {
1723 unlink ($v3extname);
1724 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}key.pem");
1725 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}req.pem");
1726 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1727 &cleanssldatabase();
1728 goto VPNCONF_ERROR;
1729 } else {
1730 unlink ($v3extname);
1731 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}req.pem");
1732 &cleanssldatabase();
1733 }
1734
1735 # Create the pkcs12 file
1736 &General::log("ipsec", "Packing a pkcs12 file...");
1737 $opt = " pkcs12 -export";
1738 $opt .= " -inkey ${General::swroot}/certs/$cgiparams{'NAME'}key.pem";
1739 $opt .= " -in ${General::swroot}/certs/$cgiparams{'NAME'}cert.pem";
1740 $opt .= " -name \"$cgiparams{'NAME'}\"";
1741 $opt .= " -passout pass:$cgiparams{'CERT_PASS1'}";
1742 $opt .= " -certfile ${General::swroot}/ca/cacert.pem";
1743 $opt .= " -caname \"$vpnsettings{'ROOTCERT_ORGANIZATION'} CA\"";
1744 $opt .= " -out ${General::swroot}/certs/$cgiparams{'NAME'}.p12";
1745
1746 if ( $errormessage = &callssl ($opt) ) {
1747 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}key.pem");
1748 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1749 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}.p12");
1750 goto VPNCONF_ERROR;
1751 } else {
1752 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}key.pem");
1753 }
1754 } elsif ($cgiparams{'AUTH'} eq 'cert') {
1755 ;# Nothing, just editing
1756 } elsif ($cgiparams{'AUTH'} eq 'auth-dn') {
1757 $cgiparams{'CERT_NAME'} = '%auth-dn'; # a special value saying 'no cert file'
1758 } else {
1759 $errormessage = $Lang::tr{'invalid input for authentication method'};
1760 goto VPNCONF_ERROR;
1761 }
1762
1763 # 1)Error message here is not accurate.
1764 # 2)Test is superfluous, openswan can reference same cert multiple times
1765 # 3)Present since initial version (1.3.2.11), it isn't a bug correction
1766 # Check if there is no other entry with this certificate name
1767 #if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk') && ($cgiparams{'AUTH'} ne 'auth-dn')) {
1768 # foreach my $key (keys %confighash) {
1769 # if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) {
1770 # $errormessage = $Lang::tr{'a connection with this common name already exists'};
1771 # goto VPNCONF_ERROR;
1772 # }
1773 # }
1774 #}
1775 # Save the config
1776
1777 my $key = $cgiparams{'KEY'};
1778 if (! $key) {
1779 $key = &General::findhasharraykey (\%confighash);
1780 foreach my $i (0 .. 31) { $confighash{$key}[$i] = "";}
1781 }
1782 $confighash{$key}[0] = $cgiparams{'ENABLED'};
1783 $confighash{$key}[1] = $cgiparams{'NAME'};
1784 if ((! $cgiparams{'KEY'}) && $cgiparams{'AUTH'} ne 'psk') {
1785 $confighash{$key}[2] = $cgiparams{'CERT_NAME'};
1786 }
1787 $confighash{$key}[3] = $cgiparams{'TYPE'};
1788 if ($cgiparams{'AUTH'} eq 'psk') {
1789 $confighash{$key}[4] = 'psk';
1790 $confighash{$key}[5] = $cgiparams{'PSK'};
1791 } else {
1792 $confighash{$key}[4] = 'cert';
1793 }
1794 if ($cgiparams{'TYPE'} eq 'net') {
1795 my @remote_subnets = split(",", $cgiparams{'REMOTE_SUBNET'});
1796 $confighash{$key}[11] = join('|', @remote_subnets);
1797 }
1798 $confighash{$key}[7] = $cgiparams{'LOCAL_ID'};
1799 my @local_subnets = split(",", $cgiparams{'LOCAL_SUBNET'});
1800 $confighash{$key}[8] = join('|', @local_subnets);
1801 $confighash{$key}[9] = $cgiparams{'REMOTE_ID'};
1802 $confighash{$key}[10] = $cgiparams{'REMOTE'};
1803 $confighash{$key}[25] = $cgiparams{'REMARK'};
1804 $confighash{$key}[26] = ""; # Formerly INTERFACE
1805 $confighash{$key}[27] = $cgiparams{'DPD_ACTION'};
1806 $confighash{$key}[29] = $cgiparams{'IKE_VERSION'};
1807
1808 #dont forget advanced value
1809 $confighash{$key}[18] = $cgiparams{'IKE_ENCRYPTION'};
1810 $confighash{$key}[19] = $cgiparams{'IKE_INTEGRITY'};
1811 $confighash{$key}[20] = $cgiparams{'IKE_GROUPTYPE'};
1812 $confighash{$key}[16] = $cgiparams{'IKE_LIFETIME'};
1813 $confighash{$key}[21] = $cgiparams{'ESP_ENCRYPTION'};
1814 $confighash{$key}[22] = $cgiparams{'ESP_INTEGRITY'};
1815 $confighash{$key}[23] = $cgiparams{'ESP_GROUPTYPE'};
1816 $confighash{$key}[17] = $cgiparams{'ESP_KEYLIFE'};
1817 $confighash{$key}[12] = 'off'; # $cgiparams{'AGGRMODE'};
1818 $confighash{$key}[13] = $cgiparams{'COMPRESSION'};
1819 $confighash{$key}[24] = $cgiparams{'ONLY_PROPOSED'};
1820 $confighash{$key}[28] = $cgiparams{'PFS'};
1821 $confighash{$key}[14] = $cgiparams{'VHOST'};
1822 $confighash{$key}[30] = $cgiparams{'DPD_TIMEOUT'};
1823 $confighash{$key}[31] = $cgiparams{'DPD_DELAY'};
1824
1825 #free unused fields!
1826 $confighash{$key}[6] = 'off';
1827 $confighash{$key}[15] = 'off';
1828
1829 &General::writehasharray("${General::swroot}/vpn/config", \%confighash);
1830 &writeipsecfiles();
1831 if (&vpnenabled) {
1832 system('/usr/local/bin/ipsecctrl', 'S', $key);
1833 sleep $sleepDelay;
1834 }
1835 if ($cgiparams{'EDIT_ADVANCED'} eq 'on') {
1836 $cgiparams{'KEY'} = $key;
1837 $cgiparams{'ACTION'} = $Lang::tr{'advanced'};
1838 }
1839 goto VPNCONF_END;
1840 } else { # add new connection
1841 $cgiparams{'ENABLED'} = 'on';
1842 if ( ! -f "${General::swroot}/private/cakey.pem" ) {
1843 $cgiparams{'AUTH'} = 'psk';
1844 } elsif ( ! -f "${General::swroot}/ca/cacert.pem") {
1845 $cgiparams{'AUTH'} = 'certfile';
1846 } else {
1847 $cgiparams{'AUTH'} = 'certgen';
1848 }
1849 $cgiparams{'LOCAL_SUBNET'} ="$netsettings{'GREEN_NETADDRESS'}/$netsettings{'GREEN_NETMASK'}";
1850 $cgiparams{'CERT_EMAIL'} = $vpnsettings{'ROOTCERT_EMAIL'};
1851 $cgiparams{'CERT_OU'} = $vpnsettings{'ROOTCERT_OU'};
1852 $cgiparams{'CERT_ORGANIZATION'} = $vpnsettings{'ROOTCERT_ORGANIZATION'};
1853 $cgiparams{'CERT_CITY'} = $vpnsettings{'ROOTCERT_CITY'};
1854 $cgiparams{'CERT_STATE'} = $vpnsettings{'ROOTCERT_STATE'};
1855 $cgiparams{'CERT_COUNTRY'} = $vpnsettings{'ROOTCERT_COUNTRY'};
1856
1857 # choose appropriate dpd action
1858 if ($cgiparams{'TYPE'} eq 'host') {
1859 $cgiparams{'DPD_ACTION'} = 'clear';
1860 } else {
1861 $cgiparams{'DPD_ACTION'} = 'restart';
1862 }
1863
1864 if (!$cgiparams{'DPD_DELAY'}) {
1865 $cgiparams{'DPD_DELAY'} = 30;
1866 }
1867
1868 if (!$cgiparams{'DPD_TIMEOUT'}) {
1869 $cgiparams{'DPD_TIMEOUT'} = 120;
1870 }
1871
1872 # Default IKE Version to v2
1873 if (!$cgiparams{'IKE_VERSION'}) {
1874 $cgiparams{'IKE_VERSION'} = 'ikev2';
1875 }
1876
1877 # ID are empty
1878 $cgiparams{'LOCAL_ID'} = '';
1879 $cgiparams{'REMOTE_ID'} = '';
1880
1881 #use default advanced value
1882 $cgiparams{'IKE_ENCRYPTION'} = 'aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128'; #[18];
1883 $cgiparams{'IKE_INTEGRITY'} = 'sha2_512|sha2_256|sha'; #[19];
1884 $cgiparams{'IKE_GROUPTYPE'} = '4096|3072|2048|1536|1024'; #[20];
1885 $cgiparams{'IKE_LIFETIME'} = '3'; #[16];
1886 $cgiparams{'ESP_ENCRYPTION'} = 'aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128'; #[21];
1887 $cgiparams{'ESP_INTEGRITY'} = 'sha2_512|sha2_256|sha1'; #[22];
1888 $cgiparams{'ESP_GROUPTYPE'} = '4096|3072|2048|1536|1024'; #[23];
1889 $cgiparams{'ESP_KEYLIFE'} = '1'; #[17];
1890 $cgiparams{'COMPRESSION'} = 'on'; #[13];
1891 $cgiparams{'ONLY_PROPOSED'} = 'off'; #[24];
1892 $cgiparams{'PFS'} = 'on'; #[28];
1893 $cgiparams{'VHOST'} = 'on'; #[14];
1894 }
1895
1896 VPNCONF_ERROR:
1897 $checked{'ENABLED'}{'off'} = '';
1898 $checked{'ENABLED'}{'on'} = '';
1899 $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = "checked='checked'";
1900
1901 $checked{'EDIT_ADVANCED'}{'off'} = '';
1902 $checked{'EDIT_ADVANCED'}{'on'} = '';
1903 $checked{'EDIT_ADVANCED'}{$cgiparams{'EDIT_ADVANCED'}} = "checked='checked'";
1904
1905 $checked{'AUTH'}{'psk'} = '';
1906 $checked{'AUTH'}{'certreq'} = '';
1907 $checked{'AUTH'}{'certgen'} = '';
1908 $checked{'AUTH'}{'certfile'} = '';
1909 $checked{'AUTH'}{'pkcs12'} = '';
1910 $checked{'AUTH'}{'auth-dn'} = '';
1911 $checked{'AUTH'}{$cgiparams{'AUTH'}} = "checked='checked'";
1912
1913 &Header::showhttpheaders();
1914 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
1915 &Header::openbigbox('100%', 'left', '', $errormessage);
1916 if ($errormessage) {
1917 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
1918 print "<class name='base'>$errormessage";
1919 print "&nbsp;</class>";
1920 &Header::closebox();
1921 }
1922
1923 if ($warnmessage) {
1924 &Header::openbox('100%', 'left', "$Lang::tr{'warning messages'}:");
1925 print "<class name='base'>$warnmessage";
1926 print "&nbsp;</class>";
1927 &Header::closebox();
1928 }
1929
1930 print "<form method='post' enctype='multipart/form-data' action='$ENV{'SCRIPT_NAME'}'>";
1931 print<<END
1932 <input type='hidden' name='TYPE' value='$cgiparams{'TYPE'}' />
1933 <input type='hidden' name='IKE_VERSION' value='$cgiparams{'IKE_VERSION'}' />
1934 <input type='hidden' name='IKE_ENCRYPTION' value='$cgiparams{'IKE_ENCRYPTION'}' />
1935 <input type='hidden' name='IKE_INTEGRITY' value='$cgiparams{'IKE_INTEGRITY'}' />
1936 <input type='hidden' name='IKE_GROUPTYPE' value='$cgiparams{'IKE_GROUPTYPE'}' />
1937 <input type='hidden' name='IKE_LIFETIME' value='$cgiparams{'IKE_LIFETIME'}' />
1938 <input type='hidden' name='ESP_ENCRYPTION' value='$cgiparams{'ESP_ENCRYPTION'}' />
1939 <input type='hidden' name='ESP_INTEGRITY' value='$cgiparams{'ESP_INTEGRITY'}' />
1940 <input type='hidden' name='ESP_GROUPTYPE' value='$cgiparams{'ESP_GROUPTYPE'}' />
1941 <input type='hidden' name='ESP_KEYLIFE' value='$cgiparams{'ESP_KEYLIFE'}' />
1942 <input type='hidden' name='COMPRESSION' value='$cgiparams{'COMPRESSION'}' />
1943 <input type='hidden' name='ONLY_PROPOSED' value='$cgiparams{'ONLY_PROPOSED'}' />
1944 <input type='hidden' name='PFS' value='$cgiparams{'PFS'}' />
1945 <input type='hidden' name='VHOST' value='$cgiparams{'VHOST'}' />
1946 <input type='hidden' name='DPD_ACTION' value='$cgiparams{'DPD_ACTION'}' />
1947 <input type='hidden' name='DPD_DELAY' value='$cgiparams{'DPD_DELAY'}' />
1948 <input type='hidden' name='DPD_TIMEOUT' value='$cgiparams{'DPD_TIMEOUT'}' />
1949 END
1950 ;
1951 if ($cgiparams{'KEY'}) {
1952 print "<input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />";
1953 print "<input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />";
1954 print "<input type='hidden' name='AUTH' value='$cgiparams{'AUTH'}' />";
1955 }
1956
1957 &Header::openbox('100%', 'left', "$Lang::tr{'connection'}: $cgiparams{'NAME'}");
1958 print "<table width='100%'>";
1959 if (!$cgiparams{'KEY'}) {
1960 print <<EOF;
1961 <tr>
1962 <td width='20%'>$Lang::tr{'name'}:</td>
1963 <td width='30%'>
1964 <input type='text' name='NAME' value='$cgiparams{'NAME'}' size='25' />
1965 </td>
1966 <td colspan="2"></td>
1967 </tr>
1968 EOF
1969 }
1970
1971 my $disabled;
1972 my $blob;
1973 if ($cgiparams{'TYPE'} eq 'host') {
1974 $disabled = "disabled='disabled'";
1975 $blob = "<img src='/blob.gif' alt='*' />";
1976 };
1977
1978 my @local_subnets = split(/\|/, $cgiparams{'LOCAL_SUBNET'});
1979 my $local_subnets = join(",", @local_subnets);
1980
1981 my @remote_subnets = split(/\|/, $cgiparams{'REMOTE_SUBNET'});
1982 my $remote_subnets = join(",", @remote_subnets);
1983
1984 print <<END
1985 <tr>
1986 <td width='20%'>$Lang::tr{'enabled'}</td>
1987 <td width='30%'>
1988 <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} />
1989 </td>
1990 <td class='boldbase' nowrap='nowrap' width='20%'>$Lang::tr{'local subnet'}</td>
1991 <td width='30%'>
1992 <input type='text' name='LOCAL_SUBNET' value='$local_subnets' />
1993 </td>
1994 </tr>
1995 <tr>
1996 <td class='boldbase' width='20%'>$Lang::tr{'remote host/ip'}:&nbsp;$blob</td>
1997 <td width='30%'>
1998 <input type='text' name='REMOTE' value='$cgiparams{'REMOTE'}' size="25" />
1999 </td>
2000 <td class='boldbase' nowrap='nowrap' width='20%'>$Lang::tr{'remote subnet'}</td>
2001 <td width='30%'>
2002 <input $disabled type='text' name='REMOTE_SUBNET' value='$remote_subnets' />
2003 </td>
2004 </tr>
2005 <tr>
2006 <td class='boldbase' width='20%'>$Lang::tr{'vpn local id'}:</td>
2007 <td width='30%'>
2008 <input type='text' name='LOCAL_ID' value='$cgiparams{'LOCAL_ID'}' size="25" />
2009 </td>
2010 <td class='boldbase' width='20%'>$Lang::tr{'vpn remote id'}:</td>
2011 <td width='30%'>
2012 <input type='text' name='REMOTE_ID' value='$cgiparams{'REMOTE_ID'}' size="25" />
2013 </td>
2014 </tr>
2015 <tr><td colspan="4"><br /></td></tr>
2016 <tr>
2017 <td class='boldbase' width='20%'>$Lang::tr{'remark title'}&nbsp;<img src='/blob.gif' alt='*' /></td>
2018 <td colspan='3'>
2019 <input type='text' name='REMARK' value='$cgiparams{'REMARK'}' maxlength='50' size="73" />
2020 </td>
2021 </tr>
2022 END
2023 ;
2024 if (!$cgiparams{'KEY'}) {
2025 print "<tr><td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked{'EDIT_ADVANCED'}{'on'} /> $Lang::tr{'edit advanced settings when done'}</td></tr>";
2026 }
2027 print "</table>";
2028 &Header::closebox();
2029
2030 if ($cgiparams{'KEY'} && $cgiparams{'AUTH'} eq 'psk') {
2031 &Header::openbox('100%', 'left', $Lang::tr{'authentication'});
2032 print <<END
2033 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2034 <tr><td class='base' width='50%'>$Lang::tr{'use a pre-shared key'}</td>
2035 <td class='base' width='50%'><input type='password' name='PSK' size='30' value='$cgiparams{'PSK'}' /></td>
2036 </tr>
2037 </table>
2038 END
2039 ;
2040 &Header::closebox();
2041 } elsif (! $cgiparams{'KEY'}) {
2042 my $cakeydisabled = ( ! -f "${General::swroot}/private/cakey.pem" ) ? "disabled='disabled'" : '';
2043 $cgiparams{'CERT_NAME'} = $Lang::tr{'vpn no full pki'} if ($cakeydisabled);
2044 my $cacrtdisabled = ( ! -f "${General::swroot}/ca/cacert.pem" ) ? "disabled='disabled'" : '';
2045
2046 &Header::openbox('100%', 'left', $Lang::tr{'authentication'});
2047 print <<END
2048 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2049 <tr><td width='5%'><input type='radio' name='AUTH' value='psk' $checked{'AUTH'}{'psk'} /></td>
2050 <td class='base' width='55%'>$Lang::tr{'use a pre-shared key'}</td>
2051 <td class='base' width='40%'><input type='password' name='PSK' size='30' value='$cgiparams{'PSK'}' /></td></tr>
2052 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2053 <tr><td><input type='radio' name='AUTH' value='certreq' $checked{'AUTH'}{'certreq'} $cakeydisabled /></td>
2054 <td class='base'><hr />$Lang::tr{'upload a certificate request'}</td>
2055 <td class='base' rowspan='3' valign='middle'><input type='file' name='FH' size='30' $cacrtdisabled /></td></tr>
2056 <tr><td><input type='radio' name='AUTH' value='certfile' $checked{'AUTH'}{'certfile'} $cacrtdisabled /></td>
2057 <td class='base'>$Lang::tr{'upload a certificate'}</td></tr>
2058 <tr><td><input type='radio' name='AUTH' value='pkcs12' $cacrtdisabled /></td>
2059 <td class='base'>$Lang::tr{'upload p12 file'} $Lang::tr{'pkcs12 file password'}:<input type='password' name='P12_PASS'/></td></tr>
2060 <tr><td><input type='radio' name='AUTH' value='auth-dn' $checked{'AUTH'}{'auth-dn'} $cacrtdisabled /></td>
2061 <td class='base'><hr />$Lang::tr{'vpn auth-dn'}</td></tr>
2062 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2063 <tr><td><input type='radio' name='AUTH' value='certgen' $checked{'AUTH'}{'certgen'} $cakeydisabled /></td>
2064 <td class='base'><hr />$Lang::tr{'generate a certificate'}</td><td>&nbsp;</td></tr>
2065 <tr><td>&nbsp;</td>
2066 <td class='base'>$Lang::tr{'users fullname or system hostname'}:</td>
2067 <td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value='$cgiparams{'CERT_NAME'}' size='32' $cakeydisabled /></td></tr>
2068 <tr><td>&nbsp;</td>
2069 <td class='base'>$Lang::tr{'users email'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
2070 <td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value='$cgiparams{'CERT_EMAIL'}' size='32' $cakeydisabled /></td></tr>
2071 <tr><td>&nbsp;</td>
2072 <td class='base'>$Lang::tr{'users department'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
2073 <td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value='$cgiparams{'CERT_OU'}' size='32' $cakeydisabled /></td></tr>
2074 <tr><td>&nbsp;</td>
2075 <td class='base'>$Lang::tr{'organization name'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
2076 <td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value='$cgiparams{'CERT_ORGANIZATION'}' size='32' $cakeydisabled /></td></tr>
2077 <tr><td>&nbsp;</td>
2078 <td class='base'>$Lang::tr{'city'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
2079 <td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value='$cgiparams{'CERT_CITY'}' size='32' $cakeydisabled /></td></tr>
2080 <tr><td>&nbsp;</td>
2081 <td class='base'>$Lang::tr{'state or province'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
2082 <td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value='$cgiparams{'CERT_STATE'}' size='32' $cakeydisabled /></td></tr>
2083 <tr><td>&nbsp;</td>
2084 <td class='base'>$Lang::tr{'country'}:</td>
2085 <td class='base'><select name='CERT_COUNTRY' $cakeydisabled>
2086 END
2087 ;
2088 foreach my $country (sort keys %{Countries::countries}) {
2089 print "\t\t\t<option value='$Countries::countries{$country}'";
2090 if ( $Countries::countries{$country} eq $cgiparams{'CERT_COUNTRY'} ) {
2091 print " selected='selected'";
2092 }
2093 print ">$country</option>\n";
2094 }
2095 print <<END
2096 </select></td></tr>
2097
2098 <tr><td>&nbsp;</td><td class='base'>$Lang::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)<img src='/blob.gif' alt='*' /></td>
2099 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value='$cgiparams{'SUBJECTALTNAME'}' size='32' $cakeydisabled /></td></tr>
2100 <tr><td>&nbsp;</td>
2101 <td class='base'>$Lang::tr{'pkcs12 file password'}:</td>
2102 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value='$cgiparams{'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
2103 <tr><td>&nbsp;</td><td class='base'>$Lang::tr{'pkcs12 file password'}:($Lang::tr{'confirmation'})</td>
2104 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value='$cgiparams{'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
2105 </table>
2106 END
2107 ;
2108 &Header::closebox();
2109 }
2110
2111 print "<div align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />";
2112 if ($cgiparams{'KEY'}) {
2113 print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />";
2114 }
2115 print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>";
2116 &Header::closebigbox();
2117 &Header::closepage();
2118 exit (0);
2119
2120 VPNCONF_END:
2121 }
2122
2123 ###
2124 ### Advanced settings
2125 ###
2126 if(($cgiparams{'ACTION'} eq $Lang::tr{'advanced'}) ||
2127 ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'ADVANCED'} eq 'yes')) {
2128 &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings);
2129 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
2130 if (! $confighash{$cgiparams{'KEY'}}) {
2131 $errormessage = $Lang::tr{'invalid key'};
2132 goto ADVANCED_END;
2133 }
2134
2135 if ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) {
2136 # I didn't read any incompatibilities here....
2137 #if ($cgiparams{'VHOST'} eq 'on' && $cgiparams{'COMPRESSION'} eq 'on') {
2138 # $errormessage = $Lang::tr{'cannot enable both nat traversal and compression'};
2139 # goto ADVANCED_ERROR;
2140 #}
2141 my @temp = split('\|', $cgiparams{'IKE_ENCRYPTION'});
2142 if ($#temp < 0) {
2143 $errormessage = $Lang::tr{'invalid input'};
2144 goto ADVANCED_ERROR;
2145 }
2146 foreach my $val (@temp) {
2147 if ($val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|camellia(256|192|128))$/) {
2148 $errormessage = $Lang::tr{'invalid input'};
2149 goto ADVANCED_ERROR;
2150 }
2151 }
2152 @temp = split('\|', $cgiparams{'IKE_INTEGRITY'});
2153 if ($#temp < 0) {
2154 $errormessage = $Lang::tr{'invalid input'};
2155 goto ADVANCED_ERROR;
2156 }
2157 foreach my $val (@temp) {
2158 if ($val !~ /^(sha2_(512|384|256)|sha|md5|aesxcbc)$/) {
2159 $errormessage = $Lang::tr{'invalid input'};
2160 goto ADVANCED_ERROR;
2161 }
2162 }
2163 @temp = split('\|', $cgiparams{'IKE_GROUPTYPE'});
2164 if ($#temp < 0) {
2165 $errormessage = $Lang::tr{'invalid input'};
2166 goto ADVANCED_ERROR;
2167 }
2168 foreach my $val (@temp) {
2169 if ($val !~ /^(e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|1024|1536|2048|2048s256|2048s224|2048s160|3072|4096|6144|8192)$/) {
2170 $errormessage = $Lang::tr{'invalid input'};
2171 goto ADVANCED_ERROR;
2172 }
2173 }
2174 if ($cgiparams{'IKE_LIFETIME'} !~ /^\d+$/) {
2175 $errormessage = $Lang::tr{'invalid input for ike lifetime'};
2176 goto ADVANCED_ERROR;
2177 }
2178 if ($cgiparams{'IKE_LIFETIME'} < 1 || $cgiparams{'IKE_LIFETIME'} > 8) {
2179 $errormessage = $Lang::tr{'ike lifetime should be between 1 and 8 hours'};
2180 goto ADVANCED_ERROR;
2181 }
2182 @temp = split('\|', $cgiparams{'ESP_ENCRYPTION'});
2183 if ($#temp < 0) {
2184 $errormessage = $Lang::tr{'invalid input'};
2185 goto ADVANCED_ERROR;
2186 }
2187 foreach my $val (@temp) {
2188 if ($val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|camellia(256|192|128))$/) {
2189 $errormessage = $Lang::tr{'invalid input'};
2190 goto ADVANCED_ERROR;
2191 }
2192 }
2193 @temp = split('\|', $cgiparams{'ESP_INTEGRITY'});
2194 if ($#temp < 0) {
2195 $errormessage = $Lang::tr{'invalid input'};
2196 goto ADVANCED_ERROR;
2197 }
2198 foreach my $val (@temp) {
2199 if ($val !~ /^(sha2_(512|384|256)|sha1|md5|aesxcbc)$/) {
2200 $errormessage = $Lang::tr{'invalid input'};
2201 goto ADVANCED_ERROR;
2202 }
2203 }
2204 @temp = split('\|', $cgiparams{'ESP_GROUPTYPE'});
2205 if ($#temp < 0) {
2206 $errormessage = $Lang::tr{'invalid input'};
2207 goto ADVANCED_ERROR;
2208 }
2209 foreach my $val (@temp) {
2210 if ($val !~ /^(e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|1024|1536|2048|2048s256|2048s224|2048s160|3072|4096|6144|8192|none)$/) {
2211 $errormessage = $Lang::tr{'invalid input'};
2212 goto ADVANCED_ERROR;
2213 }
2214 }
2215 if ($cgiparams{'ESP_KEYLIFE'} !~ /^\d+$/) {
2216 $errormessage = $Lang::tr{'invalid input for esp keylife'};
2217 goto ADVANCED_ERROR;
2218 }
2219 if ($cgiparams{'ESP_KEYLIFE'} < 1 || $cgiparams{'ESP_KEYLIFE'} > 24) {
2220 $errormessage = $Lang::tr{'esp keylife should be between 1 and 24 hours'};
2221 goto ADVANCED_ERROR;
2222 }
2223
2224 if (
2225 ($cgiparams{'COMPRESSION'} !~ /^(|on|off)$/) ||
2226 ($cgiparams{'ONLY_PROPOSED'} !~ /^(|on|off)$/) ||
2227 ($cgiparams{'PFS'} !~ /^(|on|off)$/) ||
2228 ($cgiparams{'VHOST'} !~ /^(|on|off)$/)
2229 ){
2230 $errormessage = $Lang::tr{'invalid input'};
2231 goto ADVANCED_ERROR;
2232 }
2233
2234 if ($cgiparams{'DPD_DELAY'} !~ /^\d+$/) {
2235 $errormessage = $Lang::tr{'invalid input for dpd delay'};
2236 goto ADVANCED_ERROR;
2237 }
2238
2239 if ($cgiparams{'DPD_TIMEOUT'} !~ /^\d+$/) {
2240 $errormessage = $Lang::tr{'invalid input for dpd timeout'};
2241 goto ADVANCED_ERROR;
2242 }
2243
2244 $confighash{$cgiparams{'KEY'}}[29] = $cgiparams{'IKE_VERSION'};
2245 $confighash{$cgiparams{'KEY'}}[18] = $cgiparams{'IKE_ENCRYPTION'};
2246 $confighash{$cgiparams{'KEY'}}[19] = $cgiparams{'IKE_INTEGRITY'};
2247 $confighash{$cgiparams{'KEY'}}[20] = $cgiparams{'IKE_GROUPTYPE'};
2248 $confighash{$cgiparams{'KEY'}}[16] = $cgiparams{'IKE_LIFETIME'};
2249 $confighash{$cgiparams{'KEY'}}[21] = $cgiparams{'ESP_ENCRYPTION'};
2250 $confighash{$cgiparams{'KEY'}}[22] = $cgiparams{'ESP_INTEGRITY'};
2251 $confighash{$cgiparams{'KEY'}}[23] = $cgiparams{'ESP_GROUPTYPE'};
2252 $confighash{$cgiparams{'KEY'}}[17] = $cgiparams{'ESP_KEYLIFE'};
2253 $confighash{$cgiparams{'KEY'}}[12] = 'off'; #$cgiparams{'AGGRMODE'};
2254 $confighash{$cgiparams{'KEY'}}[13] = $cgiparams{'COMPRESSION'};
2255 $confighash{$cgiparams{'KEY'}}[24] = $cgiparams{'ONLY_PROPOSED'};
2256 $confighash{$cgiparams{'KEY'}}[28] = $cgiparams{'PFS'};
2257 $confighash{$cgiparams{'KEY'}}[14] = $cgiparams{'VHOST'};
2258 $confighash{$cgiparams{'KEY'}}[27] = $cgiparams{'DPD_ACTION'};
2259 $confighash{$cgiparams{'KEY'}}[30] = $cgiparams{'DPD_TIMEOUT'};
2260 $confighash{$cgiparams{'KEY'}}[31] = $cgiparams{'DPD_DELAY'};
2261 &General::writehasharray("${General::swroot}/vpn/config", \%confighash);
2262 &writeipsecfiles();
2263 if (&vpnenabled) {
2264 system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
2265 sleep $sleepDelay;
2266 }
2267 goto ADVANCED_END;
2268 } else {
2269 $cgiparams{'IKE_VERSION'} = $confighash{$cgiparams{'KEY'}}[29];
2270 $cgiparams{'IKE_ENCRYPTION'} = $confighash{$cgiparams{'KEY'}}[18];
2271 $cgiparams{'IKE_INTEGRITY'} = $confighash{$cgiparams{'KEY'}}[19];
2272 $cgiparams{'IKE_GROUPTYPE'} = $confighash{$cgiparams{'KEY'}}[20];
2273 $cgiparams{'IKE_LIFETIME'} = $confighash{$cgiparams{'KEY'}}[16];
2274 $cgiparams{'ESP_ENCRYPTION'} = $confighash{$cgiparams{'KEY'}}[21];
2275 $cgiparams{'ESP_INTEGRITY'} = $confighash{$cgiparams{'KEY'}}[22];
2276 $cgiparams{'ESP_GROUPTYPE'} = $confighash{$cgiparams{'KEY'}}[23];
2277 if ($cgiparams{'ESP_GROUPTYPE'} eq "") {
2278 $cgiparams{'ESP_GROUPTYPE'} = $cgiparams{'IKE_GROUPTYPE'};
2279 }
2280 $cgiparams{'ESP_KEYLIFE'} = $confighash{$cgiparams{'KEY'}}[17];
2281 $cgiparams{'COMPRESSION'} = $confighash{$cgiparams{'KEY'}}[13];
2282 $cgiparams{'ONLY_PROPOSED'} = $confighash{$cgiparams{'KEY'}}[24];
2283 $cgiparams{'PFS'} = $confighash{$cgiparams{'KEY'}}[28];
2284 $cgiparams{'VHOST'} = $confighash{$cgiparams{'KEY'}}[14];
2285 $cgiparams{'DPD_ACTION'} = $confighash{$cgiparams{'KEY'}}[27];
2286 $cgiparams{'DPD_TIMEOUT'} = $confighash{$cgiparams{'KEY'}}[30];
2287 $cgiparams{'DPD_DELAY'} = $confighash{$cgiparams{'KEY'}}[31];
2288
2289 if (!$cgiparams{'DPD_DELAY'}) {
2290 $cgiparams{'DPD_DELAY'} = 30;
2291 }
2292
2293 if (!$cgiparams{'DPD_TIMEOUT'}) {
2294 $cgiparams{'DPD_TIMEOUT'} = 120;
2295 }
2296
2297 if ($confighash{$cgiparams{'KEY'}}[3] eq 'net' || $confighash{$cgiparams{'KEY'}}[10]) {
2298 $cgiparams{'VHOST'} = 'off';
2299 }
2300 }
2301
2302 ADVANCED_ERROR:
2303 $checked{'IKE_ENCRYPTION'}{'aes256'} = '';
2304 $checked{'IKE_ENCRYPTION'}{'aes192'} = '';
2305 $checked{'IKE_ENCRYPTION'}{'aes128'} = '';
2306 $checked{'IKE_ENCRYPTION'}{'aes256gcm128'} = '';
2307 $checked{'IKE_ENCRYPTION'}{'aes192gcm128'} = '';
2308 $checked{'IKE_ENCRYPTION'}{'aes128gcm128'} = '';
2309 $checked{'IKE_ENCRYPTION'}{'aes256gcm96'} = '';
2310 $checked{'IKE_ENCRYPTION'}{'aes192gcm96'} = '';
2311 $checked{'IKE_ENCRYPTION'}{'aes128gcm96'} = '';
2312 $checked{'IKE_ENCRYPTION'}{'aes256gcm64'} = '';
2313 $checked{'IKE_ENCRYPTION'}{'aes192gcm64'} = '';
2314 $checked{'IKE_ENCRYPTION'}{'aes128gcm64'} = '';
2315 $checked{'IKE_ENCRYPTION'}{'3des'} = '';
2316 $checked{'IKE_ENCRYPTION'}{'camellia256'} = '';
2317 $checked{'IKE_ENCRYPTION'}{'camellia192'} = '';
2318 $checked{'IKE_ENCRYPTION'}{'camellia128'} = '';
2319 my @temp = split('\|', $cgiparams{'IKE_ENCRYPTION'});
2320 foreach my $key (@temp) {$checked{'IKE_ENCRYPTION'}{$key} = "selected='selected'"; }
2321 $checked{'IKE_INTEGRITY'}{'sha2_512'} = '';
2322 $checked{'IKE_INTEGRITY'}{'sha2_384'} = '';
2323 $checked{'IKE_INTEGRITY'}{'sha2_256'} = '';
2324 $checked{'IKE_INTEGRITY'}{'sha'} = '';
2325 $checked{'IKE_INTEGRITY'}{'md5'} = '';
2326 $checked{'IKE_INTEGRITY'}{'aesxcbc'} = '';
2327 @temp = split('\|', $cgiparams{'IKE_INTEGRITY'});
2328 foreach my $key (@temp) {$checked{'IKE_INTEGRITY'}{$key} = "selected='selected'"; }
2329 $checked{'IKE_GROUPTYPE'}{'768'} = '';
2330 $checked{'IKE_GROUPTYPE'}{'1024'} = '';
2331 $checked{'IKE_GROUPTYPE'}{'1536'} = '';
2332 $checked{'IKE_GROUPTYPE'}{'2048'} = '';
2333 $checked{'IKE_GROUPTYPE'}{'3072'} = '';
2334 $checked{'IKE_GROUPTYPE'}{'4096'} = '';
2335 $checked{'IKE_GROUPTYPE'}{'6144'} = '';
2336 $checked{'IKE_GROUPTYPE'}{'8192'} = '';
2337 @temp = split('\|', $cgiparams{'IKE_GROUPTYPE'});
2338 foreach my $key (@temp) {$checked{'IKE_GROUPTYPE'}{$key} = "selected='selected'"; }
2339
2340 # 768 is not supported by strongswan
2341 $checked{'IKE_GROUPTYPE'}{'768'} = '';
2342
2343 $checked{'ESP_ENCRYPTION'}{'aes256'} = '';
2344 $checked{'ESP_ENCRYPTION'}{'aes192'} = '';
2345 $checked{'ESP_ENCRYPTION'}{'aes128'} = '';
2346 $checked{'ESP_ENCRYPTION'}{'aes256gcm128'} = '';
2347 $checked{'ESP_ENCRYPTION'}{'aes192gcm128'} = '';
2348 $checked{'ESP_ENCRYPTION'}{'aes128gcm128'} = '';
2349 $checked{'ESP_ENCRYPTION'}{'aes256gcm96'} = '';
2350 $checked{'ESP_ENCRYPTION'}{'aes192gcm96'} = '';
2351 $checked{'ESP_ENCRYPTION'}{'aes128gcm96'} = '';
2352 $checked{'ESP_ENCRYPTION'}{'aes256gcm64'} = '';
2353 $checked{'ESP_ENCRYPTION'}{'aes192gcm64'} = '';
2354 $checked{'ESP_ENCRYPTION'}{'aes128gcm64'} = '';
2355 $checked{'ESP_ENCRYPTION'}{'3des'} = '';
2356 $checked{'ESP_ENCRYPTION'}{'camellia256'} = '';
2357 $checked{'ESP_ENCRYPTION'}{'camellia192'} = '';
2358 $checked{'ESP_ENCRYPTION'}{'camellia128'} = '';
2359 @temp = split('\|', $cgiparams{'ESP_ENCRYPTION'});
2360 foreach my $key (@temp) {$checked{'ESP_ENCRYPTION'}{$key} = "selected='selected'"; }
2361 $checked{'ESP_INTEGRITY'}{'sha2_512'} = '';
2362 $checked{'ESP_INTEGRITY'}{'sha2_384'} = '';
2363 $checked{'ESP_INTEGRITY'}{'sha2_256'} = '';
2364 $checked{'ESP_INTEGRITY'}{'sha1'} = '';
2365 $checked{'ESP_INTEGRITY'}{'md5'} = '';
2366 $checked{'ESP_INTEGRITY'}{'aesxcbc'} = '';
2367 @temp = split('\|', $cgiparams{'ESP_INTEGRITY'});
2368 foreach my $key (@temp) {$checked{'ESP_INTEGRITY'}{$key} = "selected='selected'"; }
2369 $checked{'ESP_GROUPTYPE'}{'768'} = '';
2370 $checked{'ESP_GROUPTYPE'}{'1024'} = '';
2371 $checked{'ESP_GROUPTYPE'}{'1536'} = '';
2372 $checked{'ESP_GROUPTYPE'}{'2048'} = '';
2373 $checked{'ESP_GROUPTYPE'}{'3072'} = '';
2374 $checked{'ESP_GROUPTYPE'}{'4096'} = '';
2375 $checked{'ESP_GROUPTYPE'}{'6144'} = '';
2376 $checked{'ESP_GROUPTYPE'}{'8192'} = '';
2377 $checked{'ESP_GROUPTYPE'}{'none'} = '';
2378 @temp = split('\|', $cgiparams{'ESP_GROUPTYPE'});
2379 foreach my $key (@temp) {$checked{'ESP_GROUPTYPE'}{$key} = "selected='selected'"; }
2380
2381 $checked{'COMPRESSION'} = $cgiparams{'COMPRESSION'} eq 'on' ? "checked='checked'" : '' ;
2382 $checked{'ONLY_PROPOSED'} = $cgiparams{'ONLY_PROPOSED'} eq 'on' ? "checked='checked'" : '' ;
2383 $checked{'PFS'} = $cgiparams{'PFS'} eq 'on' ? "checked='checked'" : '' ;
2384 $checked{'VHOST'} = $cgiparams{'VHOST'} eq 'on' ? "checked='checked'" : '' ;
2385
2386 $selected{'IKE_VERSION'}{'ikev1'} = '';
2387 $selected{'IKE_VERSION'}{'ikev2'} = '';
2388 $selected{'IKE_VERSION'}{$cgiparams{'IKE_VERSION'}} = "selected='selected'";
2389
2390 $selected{'DPD_ACTION'}{'clear'} = '';
2391 $selected{'DPD_ACTION'}{'hold'} = '';
2392 $selected{'DPD_ACTION'}{'restart'} = '';
2393 $selected{'DPD_ACTION'}{'none'} = '';
2394 $selected{'DPD_ACTION'}{$cgiparams{'DPD_ACTION'}} = "selected='selected'";
2395
2396 &Header::showhttpheaders();
2397 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
2398 &Header::openbigbox('100%', 'left', '', $errormessage);
2399
2400 if ($errormessage) {
2401 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
2402 print "<class name='base'>$errormessage";
2403 print "&nbsp;</class>";
2404 &Header::closebox();
2405 }
2406
2407 if ($warnmessage) {
2408 &Header::openbox('100%', 'left', $Lang::tr{'warning messages'});
2409 print "<class name='base'>$warnmessage";
2410 print "&nbsp;</class>";
2411 &Header::closebox();
2412 }
2413
2414 &Header::openbox('100%', 'left', "$Lang::tr{'advanced'}:");
2415 print <<EOF
2416 <form method='post' enctype='multipart/form-data' action='$ENV{'SCRIPT_NAME'}'>
2417 <input type='hidden' name='ADVANCED' value='yes' />
2418 <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />
2419
2420 <table width='100%'>
2421 <thead>
2422 <tr>
2423 <th width="15%"></th>
2424 <th>IKE</th>
2425 <th>ESP</th>
2426 </tr>
2427 </thead>
2428 <tbody>
2429 <tr>
2430 <td>$Lang::tr{'vpn keyexchange'}:</td>
2431 <td>
2432 <select name='IKE_VERSION'>
2433 <option value='ikev2' $selected{'IKE_VERSION'}{'ikev2'}>IKEv2</option>
2434 <option value='ikev1' $selected{'IKE_VERSION'}{'ikev1'}>IKEv1</option>
2435 </select>
2436 </td>
2437 <td></td>
2438 </tr>
2439 <tr>
2440 <td class='boldbase' width="15%">$Lang::tr{'encryption'}</td>
2441 <td class='boldbase'>
2442 <select name='IKE_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
2443 <option value='aes256gcm128' $checked{'IKE_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
2444 <option value='aes256gcm96' $checked{'IKE_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
2445 <option value='aes256gcm64' $checked{'IKE_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
2446 <option value='aes256' $checked{'IKE_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
2447 <option value='camellia256' $checked{'IKE_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
2448 <option value='aes192gcm128' $checked{'IKE_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
2449 <option value='aes192gcm96' $checked{'IKE_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
2450 <option value='aes192gcm64' $checked{'IKE_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
2451 <option value='aes192' $checked{'IKE_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
2452 <option value='camellia192' $checked{'IKE_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
2453 <option value='aes128gcm128' $checked{'IKE_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
2454 <option value='aes128gcm96' $checked{'IKE_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
2455 <option value='aes128gcm64' $checked{'IKE_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
2456 <option value='aes128' $checked{'IKE_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
2457 <option value='camellia128' $checked{'IKE_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
2458 <option value='3des' $checked{'IKE_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC</option>
2459 </select>
2460 </td>
2461 <td class='boldbase'>
2462 <select name='ESP_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
2463 <option value='aes256gcm128' $checked{'ESP_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
2464 <option value='aes256gcm96' $checked{'ESP_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
2465 <option value='aes256gcm64' $checked{'ESP_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
2466 <option value='aes256' $checked{'ESP_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
2467 <option value='camellia256' $checked{'ESP_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
2468 <option value='aes192gcm128' $checked{'ESP_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
2469 <option value='aes192gcm96' $checked{'ESP_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
2470 <option value='aes192gcm64' $checked{'ESP_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
2471 <option value='aes192' $checked{'ESP_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
2472 <option value='camellia192' $checked{'ESP_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
2473 <option value='aes128gcm128' $checked{'ESP_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
2474 <option value='aes128gcm96' $checked{'ESP_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
2475 <option value='aes128gcm64' $checked{'ESP_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
2476 <option value='aes128' $checked{'ESP_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
2477 <option value='camellia128' $checked{'ESP_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
2478 <option value='3des' $checked{'ESP_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC</option>
2479 </select>
2480 </td>
2481 </tr>
2482
2483 <tr>
2484 <td class='boldbase' width="15%">$Lang::tr{'integrity'}</td>
2485 <td class='boldbase'>
2486 <select name='IKE_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
2487 <option value='sha2_512' $checked{'IKE_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2488 <option value='sha2_384' $checked{'IKE_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2489 <option value='sha2_256' $checked{'IKE_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2490 <option value='aesxcbc' $checked{'IKE_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2491 <option value='sha' $checked{'IKE_INTEGRITY'}{'sha'}>SHA1</option>
2492 <option value='md5' $checked{'IKE_INTEGRITY'}{'md5'}>MD5</option>
2493 </select>
2494 </td>
2495 <td class='boldbase'>
2496 <select name='ESP_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
2497 <option value='sha2_512' $checked{'ESP_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2498 <option value='sha2_384' $checked{'ESP_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2499 <option value='sha2_256' $checked{'ESP_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2500 <option value='aesxcbc' $checked{'ESP_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2501 <option value='sha1' $checked{'ESP_INTEGRITY'}{'sha1'}>SHA1</option>
2502 <option value='md5' $checked{'ESP_INTEGRITY'}{'md5'}>MD5</option>
2503 </select>
2504 </td>
2505 </tr>
2506 <tr>
2507 <td class='boldbase' width="15%">$Lang::tr{'lifetime'}</td>
2508 <td class='boldbase'>
2509 <input type='text' name='IKE_LIFETIME' value='$cgiparams{'IKE_LIFETIME'}' size='5' /> $Lang::tr{'hours'}
2510 </td>
2511 <td class='boldbase'>
2512 <input type='text' name='ESP_KEYLIFE' value='$cgiparams{'ESP_KEYLIFE'}' size='5' /> $Lang::tr{'hours'}
2513 </td>
2514 </tr>
2515 <tr>
2516 <td class='boldbase' width="15%">$Lang::tr{'grouptype'}</td>
2517 <td class='boldbase'>
2518 <select name='IKE_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
2519 <option value='e521' $checked{'IKE_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
2520 <option value='e512bp' $checked{'IKE_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
2521 <option value='e384' $checked{'IKE_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
2522 <option value='e384bp' $checked{'IKE_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
2523 <option value='e256' $checked{'IKE_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
2524 <option value='e256bp' $checked{'IKE_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
2525 <option value='e224' $checked{'IKE_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
2526 <option value='e224bp' $checked{'IKE_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
2527 <option value='e192' $checked{'IKE_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
2528 <option value='8192' $checked{'IKE_GROUPTYPE'}{'8192'}>MODP-8192</option>
2529 <option value='6144' $checked{'IKE_GROUPTYPE'}{'6144'}>MODP-6144</option>
2530 <option value='4096' $checked{'IKE_GROUPTYPE'}{'4096'}>MODP-4096</option>
2531 <option value='3072' $checked{'IKE_GROUPTYPE'}{'3072'}>MODP-3072</option>
2532 <option value='2048s256' $checked{'IKE_GROUPTYPE'}{'2048s256'}>MODP-2048/256</option>
2533 <option value='2048s224' $checked{'IKE_GROUPTYPE'}{'2048s224'}>MODP-2048/224</option>
2534 <option value='2048s160' $checked{'IKE_GROUPTYPE'}{'2048s160'}>MODP-2048/160</option>
2535 <option value='2048' $checked{'IKE_GROUPTYPE'}{'2048'}>MODP-2048</option>
2536 <option value='1536' $checked{'IKE_GROUPTYPE'}{'1536'}>MODP-1536</option>
2537 <option value='1024' $checked{'IKE_GROUPTYPE'}{'1024'}>MODP-1024</option>
2538 </select>
2539 </td>
2540 <td class='boldbase'>
2541 <select name='ESP_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
2542 <option value='e521' $checked{'ESP_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
2543 <option value='e512bp' $checked{'ESP_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
2544 <option value='e384' $checked{'ESP_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
2545 <option value='e384bp' $checked{'ESP_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
2546 <option value='e256' $checked{'ESP_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
2547 <option value='e256bp' $checked{'ESP_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
2548 <option value='e224' $checked{'ESP_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
2549 <option value='e224bp' $checked{'ESP_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
2550 <option value='e192' $checked{'ESP_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
2551 <option value='8192' $checked{'ESP_GROUPTYPE'}{'8192'}>MODP-8192</option>
2552 <option value='6144' $checked{'ESP_GROUPTYPE'}{'6144'}>MODP-6144</option>
2553 <option value='4096' $checked{'ESP_GROUPTYPE'}{'4096'}>MODP-4096</option>
2554 <option value='3072' $checked{'ESP_GROUPTYPE'}{'3072'}>MODP-3072</option>
2555 <option value='2048s256' $checked{'ESP_GROUPTYPE'}{'2048s256'}>MODP-2048/256</option>
2556 <option value='2048s224' $checked{'ESP_GROUPTYPE'}{'2048s224'}>MODP-2048/224</option>
2557 <option value='2048s160' $checked{'ESP_GROUPTYPE'}{'2048s160'}>MODP-2048/160</option>
2558 <option value='2048' $checked{'ESP_GROUPTYPE'}{'2048'}>MODP-2048</option>
2559 <option value='1536' $checked{'ESP_GROUPTYPE'}{'1536'}>MODP-1536</option>
2560 <option value='1024' $checked{'ESP_GROUPTYPE'}{'1024'}>MODP-1024</option>
2561 <option value='none' $checked{'ESP_GROUPTYPE'}{'none'}>- $Lang::tr{'none'} -</option>
2562 </select>
2563 </td>
2564 </tr>
2565 </tbody>
2566 </table>
2567
2568 <br><br>
2569
2570 <h2>$Lang::tr{'dead peer detection'}</h2>
2571
2572 <table width="100%">
2573 <tr>
2574 <td width="15%">$Lang::tr{'dpd action'}:</td>
2575 <td>
2576 <select name='DPD_ACTION'>
2577 <option value='none' $selected{'DPD_ACTION'}{'none'}>- $Lang::tr{'disabled'} -</option>
2578 <option value='clear' $selected{'DPD_ACTION'}{'clear'}>clear</option>
2579 <option value='hold' $selected{'DPD_ACTION'}{'hold'}>hold</option>
2580 <option value='restart' $selected{'DPD_ACTION'}{'restart'}>restart</option>
2581 </select>
2582 </td>
2583 </tr>
2584 <tr>
2585 <td width="15%">$Lang::tr{'dpd timeout'}:</td>
2586 <td>
2587 <input type='text' name='DPD_TIMEOUT' size='5' value='$cgiparams{'DPD_TIMEOUT'}' />
2588 </td>
2589 </tr>
2590 <tr>
2591 <td width="15%">$Lang::tr{'dpd delay'}:</td>
2592 <td>
2593 <input type='text' name='DPD_DELAY' size='5' value='$cgiparams{'DPD_DELAY'}' />
2594 </td>
2595 </tr>
2596 </table>
2597
2598 <hr>
2599
2600 <table width="100%">
2601 <tr>
2602 <td>
2603 <label>
2604 <input type='checkbox' name='ONLY_PROPOSED' $checked{'ONLY_PROPOSED'} />
2605 IKE+ESP: $Lang::tr{'use only proposed settings'}
2606 </label>
2607 </td>
2608 </tr>
2609 <tr>
2610 <td>
2611 <label>
2612 <input type='checkbox' name='PFS' $checked{'PFS'} />
2613 $Lang::tr{'pfs yes no'}
2614 </label>
2615 </td>
2616 </tr>
2617 <tr>
2618 <td>
2619 <label>
2620 <input type='checkbox' name='COMPRESSION' $checked{'COMPRESSION'} />
2621 $Lang::tr{'vpn payload compression'}
2622 </label>
2623 </td>
2624 </tr>
2625 EOF
2626 ;
2627 if ($confighash{$cgiparams{'KEY'}}[3] eq 'net') {
2628 print "<tr><td><input type='hidden' name='VHOST' value='off' /></td></tr>";
2629 } elsif ($confighash{$cgiparams{'KEY'}}[10]) {
2630 print "<tr><td><label><input type='checkbox' name='VHOST' $checked{'VHOST'} disabled='disabled' />";
2631 print " $Lang::tr{'vpn vhost'}</label></td></tr>";
2632 } else {
2633 print "<tr><td><label><input type='checkbox' name='VHOST' $checked{'VHOST'} />";
2634 print " $Lang::tr{'vpn vhost'}</label></td></tr>";
2635 }
2636
2637 print <<EOF;
2638 <tr>
2639 <td align='right' colspan='2'>
2640 <input type='submit' name='ACTION' value='$Lang::tr{'save'}' />
2641 <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' />
2642 </td>
2643 </tr>
2644 </table></form>
2645 EOF
2646
2647 &Header::closebox();
2648 &Header::closebigbox();
2649 &Header::closepage();
2650 exit(0);
2651
2652 ADVANCED_END:
2653 }
2654
2655 ###
2656 ### Default status page
2657 ###
2658 %cgiparams = ();
2659 %cahash = ();
2660 %confighash = ();
2661 &General::readhash("${General::swroot}/vpn/settings", \%cgiparams);
2662 &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash);
2663 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
2664 $cgiparams{'CA_NAME'} = '';
2665
2666 my @status = `/usr/local/bin/ipsecctrl I 2>/dev/null`;
2667
2668 # suggest a default name for this side
2669 if ($cgiparams{'VPN_IP'} eq '' && -e "${General::swroot}/red/active") {
2670 if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) {
2671 my $ipaddr = <IPADDR>;
2672 close IPADDR;
2673 chomp ($ipaddr);
2674 $cgiparams{'VPN_IP'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0];
2675 if ($cgiparams{'VPN_IP'} eq '') {
2676 $cgiparams{'VPN_IP'} = $ipaddr;
2677 }
2678 }
2679 }
2680 # no IP found, use %defaultroute
2681 $cgiparams{'VPN_IP'} ='%defaultroute' if ($cgiparams{'VPN_IP'} eq '');
2682
2683 $cgiparams{'VPN_DELAYED_START'} = 0 if (! defined ($cgiparams{'VPN_DELAYED_START'}));
2684 $checked{'ENABLED'} = $cgiparams{'ENABLED'} eq 'on' ? "checked='checked'" : '';
2685
2686 &Header::showhttpheaders();
2687 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
2688 &Header::openbigbox('100%', 'left', '', $errormessage);
2689
2690 if ($errormessage) {
2691 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
2692 print "<class name='base'>$errormessage\n";
2693 print "&nbsp;</class>\n";
2694 &Header::closebox();
2695 }
2696
2697 if ($warnmessage) {
2698 &Header::openbox('100%', 'left', $Lang::tr{'warning messages'});
2699 print "$warnmessage<br>";
2700 print "$Lang::tr{'fwdfw warn1'}<br>";
2701 &Header::closebox();
2702 print"<center><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'ok'}' style='width: 5em;'></form>";
2703 &Header::closepage();
2704 exit 0;
2705 }
2706
2707 &Header::openbox('100%', 'left', $Lang::tr{'global settings'});
2708 print <<END
2709 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2710 <table width='100%'>
2711 <tr>
2712 <td width='20%' class='base' nowrap='nowrap'>$Lang::tr{'vpn red name'}:</td>
2713 <td width='20%'><input type='text' name='VPN_IP' value='$cgiparams{'VPN_IP'}' /></td>
2714 <td width='20%' class='base'>$Lang::tr{'enabled'}<input type='checkbox' name='ENABLED' $checked{'ENABLED'} /></td>
2715 </tr>
2716 END
2717 ;
2718 print <<END
2719 <tr>
2720 <td class='base' nowrap='nowrap'>$Lang::tr{'vpn delayed start'}:&nbsp;<img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' /></td>
2721 <td ><input type='text' name='VPN_DELAYED_START' value='$cgiparams{'VPN_DELAYED_START'}' /></td>
2722 </tr>
2723 <tr>
2724 <td class='base' nowrap='nowrap'>$Lang::tr{'host to net vpn'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
2725 <td ><input type='text' name='RW_NET' value='$cgiparams{'RW_NET'}' /></td>
2726 </tr>
2727 </table>
2728 <br>
2729 <hr />
2730 <table width='100%'>
2731 <tr>
2732 <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
2733 <td width='70%' class='base' valign='top'>$Lang::tr{'this field may be blank'}</td><td width='30%' align='right' class='base'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
2734 </tr>
2735 <tr>
2736 <td class='base' valign='top' nowrap='nowrap'><img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' />&nbsp;</td>
2737 <td class='base'> <font class='base'>$Lang::tr{'vpn delayed start help'}</font></td>
2738 <td></td>
2739 </tr>
2740 </table>
2741 END
2742 ;
2743 print "</form>";
2744 &Header::closebox();
2745
2746 &Header::openbox('100%', 'left', $Lang::tr{'connection status and controlc'});
2747 print <<END
2748 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
2749 <tr>
2750 <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th>
2751 <th width='22%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></th>
2752 <th width='23%' class='boldbase' align='center'><b>$Lang::tr{'common name'}</b></th>
2753 <th width='30%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></th>
2754 <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></th>
2755 <th class='boldbase' align='center' colspan='6'><b>$Lang::tr{'action'}</b></th>
2756 </tr>
2757 END
2758 ;
2759 my $id = 0;
2760 my $gif;
2761 foreach my $key (sort { ncmp ($confighash{$a}[1],$confighash{$b}[1]) } keys %confighash) {
2762 if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; }
2763
2764 if ($id % 2) {
2765 print "<tr>";
2766 $col="bgcolor='$color{'color20'}'";
2767 } else {
2768 print "<tr>";
2769 $col="bgcolor='$color{'color22'}'";
2770 }
2771 print "<td align='center' nowrap='nowrap' $col>$confighash{$key}[1]</td>";
2772 print "<td align='center' nowrap='nowrap' $col>" . $Lang::tr{"$confighash{$key}[3]"} . " (" . $Lang::tr{"$confighash{$key}[4]"} . ") $confighash{$key}[29]</td>";
2773 if ($confighash{$key}[2] eq '%auth-dn') {
2774 print "<td align='left' nowrap='nowrap' $col>$confighash{$key}[9]</td>";
2775 } elsif ($confighash{$key}[4] eq 'cert') {
2776 print "<td align='left' nowrap='nowrap' $col>$confighash{$key}[2]</td>";
2777 } else {
2778 print "<td align='left' $col>&nbsp;</td>";
2779 }
2780 print "<td align='center' $col>$confighash{$key}[25]</td>";
2781 my $col1="bgcolor='${Header::colourred}'";
2782 # get real state
2783 my $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b>";
2784 foreach my $line (@status) {
2785 if (($line =~ /\"$confighash{$key}[1]\".*IPsec SA established/) ||
2786 ($line =~ /$confighash{$key}[1]\{.*INSTALLED/))
2787 {
2788 $col1="bgcolor='${Header::colourgreen}'";
2789 $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsopen'}</font></b>";
2790 }
2791 }
2792 # move to blueif really down
2793 if ($confighash{$key}[0] eq 'off' && $col1 =~ /${Header::colourred}/ ) {
2794 $col1="bgcolor='${Header::colourblue}'";
2795 $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b>";
2796 }
2797 print <<END
2798 <td align='center' $col1>$active</td>
2799 <td align='center' $col>
2800 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2801 <input type='image' name='$Lang::tr{'restart'}' src='/images/reload.gif' alt='$Lang::tr{'restart'}' title='$Lang::tr{'restart'}' />
2802 <input type='hidden' name='ACTION' value='$Lang::tr{'restart'}' />
2803 <input type='hidden' name='KEY' value='$key' />
2804 </form>
2805 </td>
2806 END
2807 ;
2808 if (($confighash{$key}[4] eq 'cert') && ($confighash{$key}[2] ne '%auth-dn')) {
2809 print <<END
2810 <td align='center' $col>
2811 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2812 <input type='image' name='$Lang::tr{'show certificate'}' src='/images/info.gif' alt='$Lang::tr{'show certificate'}' title='$Lang::tr{'show certificate'}' />
2813 <input type='hidden' name='ACTION' value='$Lang::tr{'show certificate'}' />
2814 <input type='hidden' name='KEY' value='$key' />
2815 </form>
2816 </td>
2817 END
2818 ; } else {
2819 print "<td width='2%' $col>&nbsp;</td>";
2820 }
2821 if ($confighash{$key}[4] eq 'cert' && -f "${General::swroot}/certs/$confighash{$key}[1].p12") {
2822 print <<END
2823 <td align='center' $col>
2824 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2825 <input type='image' name='$Lang::tr{'download pkcs12 file'}' src='/images/floppy.gif' alt='$Lang::tr{'download pkcs12 file'}' title='$Lang::tr{'download pkcs12 file'}' />
2826 <input type='hidden' name='ACTION' value='$Lang::tr{'download pkcs12 file'}' />
2827 <input type='hidden' name='KEY' value='$key' />
2828 </form>
2829 </td>
2830 END
2831 ; } elsif (($confighash{$key}[4] eq 'cert') && ($confighash{$key}[2] ne '%auth-dn')) {
2832 print <<END
2833 <td align='center' $col>
2834 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2835 <input type='image' name='$Lang::tr{'download certificate'}' src='/images/floppy.gif' alt='$Lang::tr{'download certificate'}' title='$Lang::tr{'download certificate'}' />
2836 <input type='hidden' name='ACTION' value='$Lang::tr{'download certificate'}' />
2837 <input type='hidden' name='KEY' value='$key' />
2838 </form>
2839 </td>
2840 END
2841 ; } else {
2842 print "<td width='2%' $col>&nbsp;</td>";
2843 }
2844 print <<END
2845 <td align='center' $col>
2846 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2847 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$Lang::tr{'toggle enable disable'}' title='$Lang::tr{'toggle enable disable'}' />
2848 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
2849 <input type='hidden' name='KEY' value='$key' />
2850 </form>
2851 </td>
2852
2853 <td align='center' $col>
2854 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2855 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
2856 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
2857 <input type='hidden' name='KEY' value='$key' />
2858 </form>
2859 </td>
2860 <td align='center' $col>
2861 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2862 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
2863 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
2864 <input type='hidden' name='KEY' value='$key' />
2865 </form>
2866 </td>
2867 </tr>
2868 END
2869 ;
2870 $id++;
2871 }
2872 print "</table>";
2873
2874 # If the config file contains entries, print Key to action icons
2875 if ( $id ) {
2876 print <<END
2877 <table>
2878 <tr>
2879 <td class='boldbase'>&nbsp; <b>$Lang::tr{'legend'}:</b></td>
2880 <td>&nbsp; <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
2881 <td class='base'>$Lang::tr{'click to disable'}</td>
2882 <td>&nbsp; &nbsp; <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td>
2883 <td class='base'>$Lang::tr{'show certificate'}</td>
2884 <td>&nbsp; &nbsp; <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
2885 <td class='base'>$Lang::tr{'edit'}</td>
2886 <td>&nbsp; &nbsp; <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
2887 <td class='base'>$Lang::tr{'remove'}</td>
2888 </tr>
2889 <tr>
2890 <td>&nbsp; </td>
2891 <td>&nbsp; <img src='/images/off.gif' alt='?OFF' /></td>
2892 <td class='base'>$Lang::tr{'click to enable'}</td>
2893 <td>&nbsp; &nbsp; <img src='/images/floppy.gif' alt='?FLOPPY' /></td>
2894 <td class='base'>$Lang::tr{'download certificate'}</td>
2895 <td>&nbsp; &nbsp; <img src='/images/reload.gif' alt='?RELOAD'/></td>
2896 <td class='base'>$Lang::tr{'restart'}</td>
2897 </tr>
2898 </table>
2899 END
2900 ;
2901 }
2902
2903 print <<END
2904 <table width='100%'>
2905 <tr><td align='right' colspan='9'>
2906 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2907 <input type='submit' name='ACTION' value='$Lang::tr{'add'}' />
2908 </form>
2909 </td></tr>
2910 </table>
2911 END
2912 ;
2913 &Header::closebox();
2914
2915 &Header::openbox('100%', 'left', "$Lang::tr{'certificate authorities'}");
2916 print <<EOF
2917 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
2918 <tr>
2919 <th width='25%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th>
2920 <th width='65%' class='boldbase' align='center'><b>$Lang::tr{'subject'}</b></th>
2921 <th width='10%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></th>
2922 </tr>
2923 EOF
2924 ;
2925 my $col1="bgcolor='$color{'color22'}'";
2926 my $col2="bgcolor='$color{'color20'}'";
2927 if (-f "${General::swroot}/ca/cacert.pem") {
2928 my $casubject = &Header::cleanhtml(getsubjectfromcert ("${General::swroot}/ca/cacert.pem"));
2929 print <<END
2930 <tr>
2931 <td class='base' $col1>$Lang::tr{'root certificate'}</td>
2932 <td class='base' $col1>$casubject</td>
2933 <td width='3%' align='center' $col1>
2934 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2935 <input type='hidden' name='ACTION' value='$Lang::tr{'show root certificate'}' />
2936 <input type='image' name='$Lang::tr{'edit'}' src='/images/info.gif' alt='$Lang::tr{'show root certificate'}' title='$Lang::tr{'show root certificate'}' />
2937 </form>
2938 </td>
2939 <td width='3%' align='center' $col1>
2940 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2941 <input type='image' name='$Lang::tr{'download root certificate'}' src='/images/floppy.gif' alt='$Lang::tr{'download root certificate'}' title='$Lang::tr{'download root certificate'}' />
2942 <input type='hidden' name='ACTION' value='$Lang::tr{'download root certificate'}' />
2943 </form>
2944 </td>
2945 <td width='4%' $col1>&nbsp;</td></tr>
2946 END
2947 ;
2948 } else {
2949 # display rootcert generation buttons
2950 print <<END
2951 <tr>
2952 <td class='base' $col1>$Lang::tr{'root certificate'}:</td>
2953 <td class='base' $col1>$Lang::tr{'not present'}</td>
2954 <td colspan='3' $col1>&nbsp;</td></tr>
2955 END
2956 ;
2957 }
2958
2959 if (-f "${General::swroot}/certs/hostcert.pem") {
2960 my $hostsubject = &Header::cleanhtml(getsubjectfromcert ("${General::swroot}/certs/hostcert.pem"));
2961
2962 print <<END
2963 <tr>
2964 <td class='base' $col2>$Lang::tr{'host certificate'}</td>
2965 <td class='base' $col2>$hostsubject</td>
2966 <td width='3%' align='center' $col2>
2967 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2968 <input type='hidden' name='ACTION' value='$Lang::tr{'show host certificate'}' />
2969 <input type='image' name='$Lang::tr{'show host certificate'}' src='/images/info.gif' alt='$Lang::tr{'show host certificate'}' title='$Lang::tr{'show host certificate'}' />
2970 </form>
2971 </td>
2972 <td width='3%' align='center' $col2>
2973 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2974 <input type='image' name="$Lang::tr{'download host certificate'}" src='/images/floppy.gif' alt="$Lang::tr{'download host certificate'}" title="$Lang::tr{'download host certificate'}" />
2975 <input type='hidden' name='ACTION' value="$Lang::tr{'download host certificate'}" />
2976 </form>
2977 </td>
2978 <td width='4%' $col2>&nbsp;</td></tr>
2979 END
2980 ;
2981 } else {
2982 # Nothing
2983 print <<END
2984 <tr>
2985 <td width='25%' class='base' $col2>$Lang::tr{'host certificate'}:</td>
2986 <td class='base' $col2>$Lang::tr{'not present'}</td>
2987 <td colspan='3' $col2>&nbsp;</td></tr>
2988 END
2989 ;
2990 }
2991
2992 my $rowcolor = 0;
2993 if (keys %cahash > 0) {
2994 foreach my $key (keys %cahash) {
2995 if ($rowcolor++ % 2) {
2996 print "<tr>";
2997 $col="bgcolor='$color{'color20'}'";
2998 } else {
2999 print "<tr>";
3000 $col="bgcolor='$color{'color22'}'";
3001 }
3002 print "<td class='base' $col>$cahash{$key}[0]</td>\n";
3003 print "<td class='base' $col>$cahash{$key}[1]</td>\n";
3004 print <<END
3005 <td align='center' $col>
3006 <form method='post' name='cafrm${key}a' action='$ENV{'SCRIPT_NAME'}'>
3007 <input type='image' name='$Lang::tr{'show ca certificate'}' src='/images/info.gif' alt='$Lang::tr{'show ca certificate'}' title='$Lang::tr{'show ca certificate'}' />
3008 <input type='hidden' name='ACTION' value='$Lang::tr{'show ca certificate'}' />
3009 <input type='hidden' name='KEY' value='$key' />
3010 </form>
3011 </td>
3012 <td align='center' $col>
3013 <form method='post' name='cafrm${key}b' action='$ENV{'SCRIPT_NAME'}'>
3014 <input type='image' name='$Lang::tr{'download ca certificate'}' src='/images/floppy.gif' alt='$Lang::tr{'download ca certificate'}' title='$Lang::tr{'download ca certificate'}' />
3015 <input type='hidden' name='ACTION' value='$Lang::tr{'download ca certificate'}' />
3016 <input type='hidden' name='KEY' value='$key' />
3017 </form>
3018 </td>
3019 <td align='center' $col>
3020 <form method='post' name='cafrm${key}c' action='$ENV{'SCRIPT_NAME'}'>
3021 <input type='hidden' name='ACTION' value='$Lang::tr{'remove ca certificate'}' />
3022 <input type='image' name='$Lang::tr{'remove ca certificate'}' src='/images/delete.gif' alt='$Lang::tr{'remove ca certificate'}' title='$Lang::tr{'remove ca certificate'}' />
3023 <input type='hidden' name='KEY' value='$key' />
3024 </form>
3025 </td>
3026 </tr>
3027 END
3028 ;
3029 }
3030 }
3031 print "</table>";
3032
3033 # If the file contains entries, print Key to action icons
3034 if ( -f "${General::swroot}/ca/cacert.pem") {
3035 print <<END
3036 <table><tr>
3037 <td class='boldbase'>&nbsp; <b>$Lang::tr{'legend'}:</b></td>
3038 <td>&nbsp; &nbsp; <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td>
3039 <td class='base'>$Lang::tr{'show certificate'}</td>
3040 <td>&nbsp; &nbsp; <img src='/images/floppy.gif' alt='$Lang::tr{'download certificate'}' /></td>
3041 <td class='base'>$Lang::tr{'download certificate'}</td>
3042 </tr></table>
3043 END
3044 ;
3045 }
3046 my $createCA = -f "${General::swroot}/ca/cacert.pem" ? '' : "<tr><td colspan='3'></td><td><input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' /></td></tr>";
3047 print <<END
3048 <br>
3049 <hr />
3050 <form method='post' enctype='multipart/form-data' action='$ENV{'SCRIPT_NAME'}'>
3051 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
3052 $createCA
3053 <tr>
3054 <td class='base' nowrap='nowrap'>$Lang::tr{'ca name'}:</td>
3055 <td nowrap='nowrap'><input type='text' name='CA_NAME' value='$cgiparams{'CA_NAME'}' size='15' /> </td>
3056 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
3057 <td nowrap='nowrap'><input type='submit' name='ACTION' value='$Lang::tr{'upload ca certificate'}' /></td>
3058 </tr>
3059 <tr>
3060 <td colspan='3'>$Lang::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}:</td>
3061 <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' /></td>
3062 </tr>
3063 </table>
3064 </form>
3065 END
3066 ;
3067 &Header::closebox();
3068 &Header::closebigbox();
3069 &Header::closepage();
3070
3071 sub array_unique($) {
3072 my $array = shift;
3073 my @unique = ();
3074
3075 my %seen = ();
3076 foreach my $e (@$array) {
3077 next if $seen{$e}++;
3078 push(@unique, $e);
3079 }
3080
3081 return @unique;
3082 }
3083
3084 sub make_algos($$$$$) {
3085 my ($mode, $encs, $ints, $grps, $pfs) = @_;
3086 my @algos = ();
3087
3088 foreach my $enc (@$encs) {
3089 foreach my $int (@$ints) {
3090 foreach my $grp (@$grps) {
3091 my @algo = ($enc);
3092
3093 if ($mode eq "ike") {
3094 push(@algo, $int);
3095
3096 if ($grp =~ m/^e(.*)$/) {
3097 push(@algo, "ecp$1");
3098 } else {
3099 push(@algo, "modp$grp");
3100 }
3101
3102 } elsif ($mode eq "esp" && $pfs) {
3103 my $is_aead = ($enc =~ m/[cg]cm/);
3104
3105 if (!$is_aead) {
3106 push(@algo, $int);
3107 }
3108
3109 if ($grp eq "none") {
3110 # noop
3111 } elsif ($grp =~ m/^e(.*)$/) {
3112 push(@algo, "ecp$1");
3113 } else {
3114 push(@algo, "modp$grp");
3115 }
3116 }
3117
3118 push(@algos, join("-", @algo));
3119 }
3120 }
3121 }
3122
3123 return &array_unique(\@algos);
3124 }
3125
3126 sub make_subnets($) {
3127 my $subnets = shift;
3128
3129 my @nets = split(/\|/, $subnets);
3130 my @cidr_nets = ();
3131 foreach my $net (@nets) {
3132 my $cidr_net = &General::ipcidr($net);
3133 push(@cidr_nets, $cidr_net);
3134 }
3135
3136 return join(",", @cidr_nets);
3137 }