2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2017 IPFire Network Development Team #
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. #
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. #
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/>. #
20 ###############################################################################
22 VPN_SECURITY_POLICIES_CONFIG_SETTINGS
="CIPHER COMPRESSION GROUP_TYPE INTEGRITY KEY_EXCHANGE LIFETIME PFS"
23 VPN_SECURITY_POLICIES_READONLY
="system"
25 VPN_DEFAULT_SECURITY_POLICY
="system"
27 declare -A VPN_SUPPORTED_CIPHERS
=(
29 [3DES-CBC
]="168 bit 3DES-EDE-CBC"
32 [AES256-CBC
]="256 bit AES-CBC"
33 [AES192-CBC
]="192 bit AES-CBC"
34 [AES128-CBC
]="128 bit AES-CBC"
37 [AES256-CTR
]="256 bit AES-COUNTER"
38 [AES192-CTR
]="192 bit AES-COUNTER"
39 [AES128-CTR
]="128 bit AES-COUNTER"
42 [AES256-GCM128
]="256 bit AES-GCM with 128 bit ICV"
43 [AES192-GCM128
]="192 bit AES-GCM with 128 bit ICV"
44 [AES128-GCM128
]="128 bit AES-GCM with 128 bit ICV"
45 [AES256-GCM96
]="256 bit AES-GCM with 96 bit ICV"
46 [AES192-GCM96
]="192 bit AES-GCM with 96 bit ICV"
47 [AES128-GCM96
]="128 bit AES-GCM with 96 bit ICV"
48 [AES256-GCM64
]="256 bit AES-GCM with 64 bit ICV"
49 [AES192-GCM64
]="192 bit AES-GCM with 64 bit ICV"
50 [AES128-GCM64
]="128 bit AES-GCM with 64 bit ICV"
53 [AES256-CCM128
]="256 bit AES-CCM with 128 bit ICV"
54 [AES192-CCM128
]="192 bit AES-CCM with 128 bit ICV"
55 [AES128-CCM128
]="128 bit AES-CCM with 128 bit ICV"
56 [AES256-CCM96
]="256 bit AES-CCM with 96 bit ICV"
57 [AES192-CCM96
]="192 bit AES-CCM with 96 bit ICV"
58 [AES128-CCM96
]="128 bit AES-CCM with 96 bit ICV"
59 [AES256-CCM64
]="256 bit AES-CCM with 64 bit ICV"
60 [AES192-CCM64
]="192 bit AES-CCM with 64 bit ICV"
61 [AES128-CCM64
]="128 bit AES-CCM with 64 bit ICV"
64 [CAMELLIA256-CBC
]="256 bit CAMELLIA-CBC"
65 [CAMELLIA192-CBC
]="192 bit CAMELLIA-CBC"
66 [CAMELLIA128-CBC
]="128 bit CAMELLIA-CBC"
69 [CAMELLIA256-CTR
]="256 bit CAMELLIA-COUNTER"
70 [CAMELLIA192-CTR
]="192 bit CAMELLIA-COUNTER"
71 [CAMELLIA128-CTR
]="128 bit CAMELLIA-COUNTER"
74 [CAMELLIA256-GCM128
]="256 bit CAMELLIA-GCM with 128 bit ICV"
75 [CAMELLIA192-GCM128
]="192 bit CAMELLIA-GCM with 128 bit ICV"
76 [CAMELLIA128-GCM128
]="128 bit CAMELLIA-GCM with 128 bit ICV"
77 [CAMELLIA256-GCM96
]="256 bit CAMELLIA-GCM with 96 bit ICV"
78 [CAMELLIA192-GCM96
]="192 bit CAMELLIA-GCM with 96 bit ICV"
79 [CAMELLIA128-GCM96
]="128 bit CAMELLIA-GCM with 96 bit ICV"
80 [CAMELLIA256-GCM64
]="256 bit CAMELLIA-GCM with 64 bit ICV"
81 [CAMELLIA192-GCM64
]="192 bit CAMELLIA-GCM with 64 bit ICV"
82 [CAMELLIA128-GCM64
]="128 bit CAMELLIA-GCM with 64 bit ICV"
85 [CAMELLIA256-CCM128
]="256 bit CAMELLIA-CCM with 128 bit ICV"
86 [CAMELLIA192-CCM128
]="192 bit CAMELLIA-CCM with 128 bit ICV"
87 [CAMELLIA128-CCM128
]="128 bit CAMELLIA-CCM with 128 bit ICV"
88 [CAMELLIA256-CCM96
]="256 bit CAMELLIA-CCM with 96 bit ICV"
89 [CAMELLIA192-CCM96
]="192 bit CAMELLIA-CCM with 96 bit ICV"
90 [CAMELLIA128-CCM96
]="128 bit CAMELLIA-CCM with 96 bit ICV"
91 [CAMELLIA256-CCM64
]="256 bit CAMELLIA-CCM with 64 bit ICV"
92 [CAMELLIA192-CCM64
]="192 bit CAMELLIA-CCM with 64 bit ICV"
93 [CAMELLIA128-CCM64
]="128 bit CAMELLIA-CCM with 64 bit ICV"
96 declare -A CIPHER_TO_STRONGSWAN
=(
101 [AES256-CBC
]="aes256"
102 [AES192-CBC
]="aes192"
103 [AES128-CBC
]="aes128"
106 [AES256-CTR
]="aes256ctr"
107 [AES192-CTR
]="aes192ctr"
108 [AES128-CTR
]="aes128ctr"
111 [AES256-GCM128
]="aes256gcm128"
112 [AES192-GCM128
]="aes192gcm128"
113 [AES128-GCM128
]="aes128gcm128"
114 [AES256-GCM96
]="aes256gcm96"
115 [AES192-GCM96
]="aes192gcm96"
116 [AES128-GCM96
]="aes128gcm96"
117 [AES256-GCM64
]="aes256gcm64"
118 [AES192-GCM64
]="aes192gcm64"
119 [AES128-GCM64
]="aes128gcm64"
122 [AES256-CCM128
]="aes256ccm128"
123 [AES192-CCM128
]="aes192ccm128"
124 [AES128-CCM128
]="aes128ccm128"
125 [AES256-CCM96
]="aes256ccm96"
126 [AES192-CCM96
]="aes192ccm96"
127 [AES128-CCM96
]="aes128ccm96"
128 [AES256-CCM64
]="aes256ccm64"
129 [AES192-CCM64
]="aes192ccm64"
130 [AES128-CCM64
]="aes128ccm64"
133 [CAMELLIA256-CBC
]="camellia256"
134 [CAMELLIA192-CBC
]="camellia192"
135 [CAMELLIA128-CBC
]="camellia128"
138 [CAMELLIA256-CTR
]="camellia256ctr"
139 [CAMELLIA192-CTR
]="camellia192ctr"
140 [CAMELLIA128-CTR
]="camellia128ctr"
143 [CAMELLIA256-GCM128
]="camellia256gcm128"
144 [CAMELLIA192-GCM128
]="camellia192gcm128"
145 [CAMELLIA128-GCM128
]="camellia128gcm128"
146 [CAMELLIA256-GCM96
]="camellia256gcm96"
147 [CAMELLIA192-GCM96
]="camellia192gcm96"
148 [CAMELLIA128-GCM96
]="camellia128gcm96"
149 [CAMELLIA256-GCM64
]="camellia256gcm64"
150 [CAMELLIA192-GCM64
]="camellia192gcm64"
151 [CAMELLIA128-GCM64
]="camellia128gcm64"
154 [CAMELLIA256-CCM128
]="camellia256ccm128"
155 [CAMELLIA192-CCM128
]="camellia192ccm128"
156 [CAMELLIA128-CCM128
]="camellia128ccm128"
157 [CAMELLIA256-CCM96
]="camellia256ccm96"
158 [CAMELLIA192-CCM96
]="camellia192ccm96"
159 [CAMELLIA128-CCM96
]="camellia128ccm96"
160 [CAMELLIA256-CCM64
]="camellia256ccm64"
161 [CAMELLIA192-CCM64
]="camellia192ccm64"
162 [CAMELLIA128-CCM64
]="camellia128ccm64"
165 declare -A VPN_SUPPORTED_INTEGRITY
=(
170 [SHA512
]="512 bit SHA2-HMAC"
171 [SHA384
]="384 bit SHA2-HMAC"
172 [SHA256
]="256 bit SHA2-HMAC"
175 [AES-XCBC
]="AES-XCBC"
176 [AES-CMAC
]="AES-CMAC"
177 [AES256-GMAC
]="256 bit AES-GMAC"
178 [AES192-GMAC
]="192 bit AES-GMAC"
179 [AES128-GMAC
]="128 bit AES-GMAC"
182 declare -A INTEGRITY_TO_STRONGSWAN
=(
194 [AES256-GMAC
]="aes256gmac"
195 [AES192-GMAC
]="aes192gmac"
196 [AES128-GMAC
]="aes128gmac"
199 declare -A VPN_SUPPORTED_GROUP_TYPES
=(
201 [MODP768
]="768 bit Modulo Prime Group"
202 [MODP1024
]="1024 bit Modulo Prime Group"
203 [MODP1536
]="1536 bit Modulo Prime Group"
204 [MODP2048
]="2048 bit Modulo Prime Group"
205 [MODP3072
]="3072 bit Modulo Prime Group"
206 [MODP4096
]="4096 bit Modulo Prime Group"
207 [MODP6144
]="6144 bit Modulo Prime Group"
208 [MODP8192
]="8192 bit Modulo Prime Group"
210 # NIST Elliptic Curve Groups
211 [ECP192
]="192 bit NIST Elliptic Curve Group"
212 [ECP224
]="224 bit NIST Elliptic Curve Group"
213 [ECP256
]="256 bit NIST Elliptic Curve Group"
214 [ECP384
]="384 bit NIST Elliptic Curve Group"
215 [ECP521
]="521 bit NIST Elliptic Curve Group"
217 # Brainpool Elliptic Curve Groups
218 [ECP224BP
]="224 bit Brainpool Elliptic Curve Group"
219 [ECP256BP
]="256 bit Brainpool Elliptic Curve Group"
220 [ECP384BP
]="384 bit Brainpool Elliptic Curve Group"
221 [ECP512BP
]="512 bit Brainpool Elliptic Curve Group"
224 [CURVE25519
]="256 bit Elliptic Curve 25519"
227 declare -A GROUP_TYPE_TO_STRONGSWAN
=(
230 [MODP1024
]="modp1024"
231 [MODP1536
]="modp1536"
232 [MODP2048
]="modp2048"
233 [MODP3072
]="modp3072"
234 [MODP4096
]="modp4096"
235 [MODP6144
]="modp6144"
236 [MODP8192
]="modp8192"
238 # NIST Elliptic Curve Groups
245 # Brainpool Elliptic Curve Groups
246 [ECP224BP
]="ecp224bp"
247 [ECP256BP
]="ecp256bp"
248 [ECP384BP
]="ecp384bp"
249 [ECP512BP
]="ecp512bp"
252 [CURVE25519
]="curve25519"
255 # This functions checks if a policy is readonly
256 # returns true when yes and false when no
257 vpn_security_policies_check_readonly
() {
258 if isoneof name
${VPN_SECURITY_POLICIES_READONLY}; then
265 # This function writes all values to a via ${name} specificated vpn security policy configuration file
266 vpn_security_policies_write_config
() {
271 if ! vpn_security_policy_exists
"${name}"; then
272 log ERROR
"No such vpn security policy: ${name}"
276 if vpn_security_policies_check_readonly
"${name}"; then
277 log ERROR
"The ${name} vpn security policy cannot be changed."
281 local path
="$(vpn_security_policies_path "${name}")"
282 if [ ! -w ${path} ]; then
283 log ERROR
"${path} is not writeable"
287 if ! settings_write
"${path}" ${VPN_SECURITY_POLICIES_CONFIG_SETTINGS}; then
288 log ERROR
"Could not write configuration settings for vpn security policy ${name}"
292 # TODO everytime we successfully write a config we should call some trigger to take the changes into effect
295 # This funtion writes the value for one key to a via ${name} specificated vpn security policy configuration file
296 vpn_security_policies_write_config_key
() {
305 if ! vpn_security_policy_exists
"${name}"; then
306 log ERROR
"No such vpn security policy: ${name}"
310 log DEBUG
"Set '${key}' to new value '${value}' in vpn security policy ${name}"
312 local ${VPN_SECURITY_POLICIES_CONFIG_SETTINGS}
314 # Read the config settings
315 if ! vpn_security_policies_read_config
"${name}"; then
319 # Set the key to a new value
320 assign
"${key}" "${value}"
322 if ! vpn_security_policies_write_config
"${name}"; then
329 # Reads one or more keys out of a settings file or all if no key is provided.
330 vpn_security_policies_read_config
() {
336 if ! vpn_security_policy_exists
"${name}"; then
337 log ERROR
"No such vpn security policy: ${name}"
343 if [ $# -eq 0 ] && [ -n "${VPN_SECURITY_POLICIES_CONFIG_SETTINGS}" ]; then
344 list_append args
${VPN_SECURITY_POLICIES_CONFIG_SETTINGS}
349 local path
="$(vpn_security_policies_path ${name})"
351 if ! settings_read
"${path}" ${args}; then
352 log ERROR
"Could not read settings for vpn security policy ${name}"
357 # Returns the path to a the configuration fora given name
358 vpn_security_policies_path
() {
363 if vpn_security_policies_check_readonly
"${name}"; then
364 echo "${NETWORK_SHARE_DIR}/vpn/security-policies/${name}"
366 echo "${NETWORK_CONFIG_DIR}/vpn/security-policies/${name}"
370 # Print the content of a vpn security policy configuration file in a nice way
371 vpn_security_policies_show
() {
376 local ${VPN_SECURITY_POLICIES_CONFIG_SETTINGS}
377 if ! vpn_security_policies_read_config
${name}; then
381 cli_print_fmt1
0 "Security Policy: ${name}"
384 # This could be done in a loop but a loop is much more complicated
385 # because we print 'Group Types' but the variable is named 'GROUP_TYPES'
386 cli_print_fmt1
1 "Ciphers:"
388 for cipher
in ${CIPHER}; do
389 cli_print_fmt1
2 "${VPN_SUPPORTED_CIPHERS[${cipher}]-${cipher}}"
393 cli_print_fmt1
1 "Integrity:"
395 for integrity
in ${INTEGRITY}; do
396 cli_print_fmt1
2 "${VPN_SUPPORTED_INTEGRITY[${integrity}]-${integrity}}"
400 cli_print_fmt1
1 "Group Types:"
402 for group_type
in ${GROUP_TYPE}; do
403 cli_print_fmt1
2 "${VPN_SUPPORTED_GROUP_TYPES[${group_type}]-${group_type}}"
407 cli_print_fmt1
1 "Key Exchange:" "${KEY_EXCHANGE}"
410 if isinteger LIFETIME
&& [ ${LIFETIME} -gt 0 ]; then
411 cli_print_fmt1
1 "Key Lifetime:" "$(format_time ${LIFETIME})"
413 log ERROR
"The value for Key Lifetime is not a valid integer greater zero."
418 cli_print_fmt1
1 "Perfect Forward Secrecy:" "enabled"
420 cli_print_fmt1
1 "Perfect Forward Secrecy:" "disabled"
425 if enabled COMPRESSION
; then
426 cli_print_fmt1
1 "Compression:" "enabled"
428 cli_print_fmt1
1 "Compression:" "disabled"
433 # This function checks if a vpn security policy exists
434 # Returns True when yes and false when not
435 vpn_security_policy_exists
() {
440 local path
=$
(vpn_security_policies_path
"${name}")
442 [ -f ${path} ] && return ${EXIT_TRUE} || return ${EXIT_FALSE}
446 # This function parses the parameters for the 'cipher' command
447 vpn_security_policies_cipher
(){
451 if [ $# -eq 0 ]; then
452 log ERROR
"You must pass at least one value after cipher"
457 if ! vpn_security_policies_read_config
${name} "CIPHER"; then
461 # Remove duplicated entries to proceed the list safely
462 CIPHER
="$(list_unique ${CIPHER})"
465 local ciphers_removed
468 while [ $# -gt 0 ]; do
473 list_append ciphers_added
"${arg:1}"
476 list_append ciphers_removed
"${arg:1}"
479 list_append ciphers_set
"${arg}"
482 error
"Invalid argument: ${arg}"
489 # Check if the user is trying a mixed operation
490 if ! list_is_empty ciphers_set
&& (! list_is_empty ciphers_added ||
! list_is_empty ciphers_removed
); then
491 error
"You cannot reset the cipher list and add or remove ciphers at the same time"
495 # Set new cipher list
496 if ! list_is_empty ciphers_set
; then
497 # Check if all ciphers are valid
499 for cipher
in ${ciphers_set}; do
500 if ! vpn_security_policies_cipher_supported
${cipher}; then
501 error
"Unsupported cipher: ${cipher}"
506 list_set CIPHER
${ciphers_set}
508 # Perform incremental updates
512 # Perform all removals
513 for cipher
in ${ciphers_removed}; do
514 if ! list_remove CIPHER
${cipher}; then
515 warning
"${cipher} was not on the list and could not be removed"
519 for cipher
in ${ciphers_added}; do
520 if vpn_security_policies_cipher_supported
${cipher}; then
521 if ! list_append_unique CIPHER
${cipher}; then
522 warning
"${cipher} is already on the cipher list"
525 warning
"${cipher} is unknown or unsupported and could not be added"
530 # Check if the list contain at least one valid cipher
531 if list_is_empty CIPHER
; then
532 error
"Cannot save an empty cipher list"
537 if ! vpn_security_policies_write_config_key
${name} "CIPHER" ${CIPHER}; then
538 log ERROR
"The changes for the vpn security policy ${name} could not be written."
541 cli_headline
1 "Current cipher list for ${name}:"
542 for cipher
in ${CIPHER}; do
543 cli_print_fmt1
1 "${cipher}" "${VPN_SUPPORTED_CIPHERS[${cipher}]}"
547 # This function parses the parameters for the 'compression' command
548 vpn_security_policies_compression
(){
552 # Check if we get only one argument after compression <name>
553 if [ ! $# -eq 2 ]; then
554 log ERROR
"The number of arguments do not match. Only one argument after compression is allowed."
558 if ! isbool value
; then
559 # We suggest only two values to avoid overburding the user.
560 log ERROR
"Invalid Argument ${value}"
564 vpn_security_policies_write_config_key
"${name}" "COMPRESSION" "${value}"
567 # This function parses the parameters for the 'group-type' command
568 vpn_security_policies_group_type
(){
572 if [ $# -eq 0 ]; then
573 log ERROR
"You must pass at least one value after group-type"
578 if ! vpn_security_policies_read_config
${name} "GROUP_TYPE"; then
582 # Remove duplicated entries to proceed the list safely
583 GROUP_TYPE
="$(list_unique ${GROUP_TYPE})"
585 while [ $# -gt 0 ]; do
589 # Check if the group type is in the list of group types and
590 # check if the list has after removing this group type at leatst one valid value
591 if list_match
${value} ${GROUP_TYPE}; then
592 list_remove GROUP_TYPE
${value}
594 # We do not break here because this error does not break the processing of the next maybe valid values.
595 log ERROR
"Can not remove ${value} from the list of group types because ${value} is not in the list."
600 # Check if the group type is in the list of supported group types.
601 if ! isoneof value
${!VPN_SUPPORTED_GROUP_TYPES[@]}; then
602 # We do not break here because the processing of other maybe valid values are indepent from this error.
603 log ERROR
"${value} is not a supported group type and can thats why not added to the list of group types."
605 if list_match
${value} ${GROUP_TYPE}; then
606 log WARNING
"${value} is already in the list of group-types of this policy."
608 list_append GROUP_TYPE
${value}
616 # Check if the list contain at least one valid group-type
617 if [ $
(list_length
${GROUP_TYPE}) -ge 1 ]; then
618 if ! vpn_security_policies_write_config_key
${name} "GROUP_TYPE" ${GROUP_TYPE}; then
619 log ERROR
"The changes for the vpn security policy ${name} could not be written."
622 log ERROR
"After proceding all group types the list is empty and thats why no changes are written."
627 # This function parses the parameters for the 'integrity' command
628 vpn_security_policies_integrity
(){
632 if [ $# -eq 0 ]; then
633 log ERROR
"You must pass at least one value after integrity."
638 if ! vpn_security_policies_read_config
${name} "INTEGRITY"; then
642 # Remove duplicated entries to proceed the list safely
643 INTEGRITY
="$(list_unique ${INTEGRITY})"
645 while [ $# -gt 0 ]; do
649 # Check if the integrity hash is in the list of integrity hashes and
650 # check if the list has after removing this integrity hash at least one valid value
651 if list_match
${value} ${INTEGRITY}; then
652 list_remove INTEGRITY
${value}
654 # We do not break here because the processing of other maybe valid values are indepent from this error.
655 log ERROR
"Can not remove ${value} from the list of integrity hashes because ${value} is not in the list."
660 # Check if the Ciphers is in the list of supported integrity hashes.
661 if ! isoneof value
${!VPN_SUPPORTED_INTEGRITY[@]}; then
662 # We do not break here because the processing of other maybe valid values are indepent from this error.
663 log ERROR
"${value} is not a supported integrity hash and can thats why not added to the list of integrity hashes."
665 if list_match
${value} ${INTEGRITY}; then
666 log WARNING
"${value} is already in the list of integrety hashes of this policy."
668 list_append INTEGRITY
${value}
676 # Check if the list contain at least one valid group-type
677 if [ $
(list_length
${INTEGRITY}) -ge 1 ]; then
678 if ! vpn_security_policies_write_config_key
${name} "INTEGRITY" ${INTEGRITY}; then
679 log ERROR
"The changes for the vpn security policy ${name} could not be written."
682 log ERROR
"After proceding all integrity hashes the list is empty and thats why no changes are written."
687 # This function parses the parameters for the 'key-exchange' command
688 vpn_security_policies_key_exchange
() {
692 # Check if we get only one argument after key-exchange <name>
693 if [ ! $# -eq 2 ]; then
694 log ERROR
"The number of arguments do not match. Only argument after key-exchange is allowed."
698 if ! isoneof value
"ikev1" "ikev2" "IKEV1" "IKEV2"; then
699 log ERROR
"Invalid Argument ${value}"
703 vpn_security_policies_write_config_key
"${name}" "KEY_EXCHANGE" "${value,,}"
706 # This function parses the parameters for the 'lifetime' command.
707 vpn_security_policies_lifetime
(){
713 # Check if we get only one argument after lifetime <name>
714 if [ ! $# -ge 1 ]; then
715 log ERROR
"The number of arguments do not match you must provide at least one integer value or a valid time with the format <hours>h <minutes>m <seconds>s"
719 if ! isinteger value
; then
720 value
=$
(parse_time $@
)
721 if [ ! $?
-eq 0 ]; then
722 log ERROR
"Parsing the passed time was not sucessful please check the passed values."
727 if [ ${value} -le 0 ]; then
728 log ERROR
"The passed time value must be in the sum greater zero seconds."
732 vpn_security_policies_write_config_key
"${name}" "LIFETIME" "${value}"
735 # This function parses the parameters for the 'pfs' command
736 vpn_security_policies_pfs
(){
740 # Check if we get only one argument after pfs <name>
741 if [ ! $# -eq 2 ]; then
742 log ERROR
"The number of arguments do not match. Only argument after pfs is allowed."
746 if [ ! $# -eq 2 ] ||
! isbool value
; then
747 # We suggest only two values to avoid overburding the user.
748 log ERROR
"Invalid Argument ${value}"
752 vpn_security_policies_write_config_key
"${name}" "PFS" "${value}"
755 # This function checks if a vpn security policy name is valid
756 # Allowed are only A-Za-z0-9
757 vpn_security_policies_check_name
() {
762 [[ ${name} =~
[^
[:alnum
:]$
] ]]
765 # Function that creates based on the paramters one ore more new vpn security policies
766 vpn_security_policies_new
() {
767 if [ $# -gt 1 ]; then
768 error
"Too many arguments"
773 if ! isset name
; then
774 error
"Please provide a name"
778 # Check for duplicates
779 if vpn_security_policy_exists
"${name}"; then
780 error
"The VPN security policy with name ${name} already exists"
784 # Check if name is valid
785 if vpn_security_policies_check_name
"${name}"; then
786 error
"'${name}' contains illegal characters"
790 # Check if we have a read-only policy with the same name
791 if vpn_security_policies_check_readonly
"${name}"; then
792 error
"The VPN security policy ${name} is read-only"
796 # Check if our source policy exists
797 if ! vpn_security_policy_exists
"${VPN_DEFAULT_SECURITY_POLICY}"; then
798 error
"Default VPN Security Policy '${VPN_DEFAULT_SECURITY_POLICY}' does not exist"
802 log DEBUG
"Creating VPN Security Policy ${name}"
804 if copy
"$(vpn_security_policies_path "${VPN_DEFAULT_SECURITY_POLICY}")" \
805 "$(vpn_security_policies_path ${name})"; then
806 log INFO
"VPN Security Policy ${name} successfully created"
808 log ERROR
"Could not create VPN Security Policy ${name}"
812 # Show the newly created policy
813 vpn_security_policies_show
"${name}"
816 # Function that deletes based on the passed parameters one ore more vpn security policies
817 vpn_security_policies_destroy
() {
820 if ! vpn_security_policy_exists
${name}; then
821 log ERROR
"The vpn security policy ${name} does not exist."
825 if vpn_security_policies_check_readonly
${name}; then
826 log ERROR
"The vpn security policy ${name} cannot be deleted."
830 log DEBUG
"Deleting vpn security policy ${name}"
831 settings_remove $
(vpn_security_policies_path
${name})
835 vpn_security_policies_cipher_supported
() {
838 list_match
${cipher} ${!VPN_SUPPORTED_CIPHERS[@]}
841 vpn_security_policies_cipher_is_aead
() {
844 # All CCM and GCM ciphers are AEAD
845 string_match
"[CG]CM" "${cipher}"
848 vpn_security_policies_make_ah_proposal
() {
851 # Read the config settings
852 local ${VPN_SECURITY_POLICIES_CONFIG_SETTINGS}
853 if ! vpn_security_policies_read_config
"${name}"; then
860 for cipher
in ${CIPHER}; do
862 local _cipher
=${CIPHER_TO_STRONGSWAN[${cipher}]}
864 if ! isset _cipher
; then
865 log WARN
"Unsupported cipher: ${cipher}"
870 for integrity
in ${INTEGRITY}; do
871 local _integrity
=${INTEGRITY_TO_STRONGSWAN[${integrity}]}
873 if ! isset _integrity
; then
874 log WARN
"Unsupported integrity: ${integrity}"
879 for group_type
in ${GROUP_TYPE}; do
880 local _group_type
=${GROUP_TYPE_TO_STRONGSWAN[${group_type}]}
882 if ! isset _group_type
; then
883 log WARN
"Unsupported group-type: ${group_type}"
887 # Put everything together
888 list_append proposals
"${_cipher}-${_integrity}-${_group_type}"
893 # Returns as a comma-separated list
894 list_join proposals
,
897 vpn_security_policies_make_esp_proposal
() {
900 # Read the config settings
901 local ${VPN_SECURITY_POLICIES_CONFIG_SETTINGS}
902 if ! vpn_security_policies_read_config
"${name}"; then
909 for cipher
in ${CIPHER}; do
911 local _cipher
=${CIPHER_TO_STRONGSWAN[${cipher}]}
913 if ! isset _cipher
; then
914 log WARN
"Unsupported cipher: ${cipher}"
918 if vpn_security_policies_cipher_is_aead
${cipher}; then
920 for group_type
in ${GROUP_TYPE}; do
921 local _group_type
=${GROUP_TYPE_TO_STRONGSWAN[${group_type}]}
923 if ! isset _group_type
; then
924 log WARN
"Unsupported group-type: ${group_type}"
928 # Put everything together
929 list_append proposals
"${_cipher}-${_group_type}"
933 for integrity
in ${INTEGRITY}; do
934 local _integrity
=${INTEGRITY_TO_STRONGSWAN[${integrity}]}
936 if ! isset _integrity
; then
937 log WARN
"Unsupported integrity: ${integrity}"
942 for group_type
in ${GROUP_TYPE}; do
943 local _group_type
=${GROUP_TYPE_TO_STRONGSWAN[${group_type}]}
945 if ! isset _group_type
; then
946 log WARN
"Unsupported group-type: ${group_type}"
950 # Put everything together
951 list_append proposals
"${_cipher}-${_integrity}-${_group_type}"
957 # Returns as a comma-separated list
958 list_join proposals
,