]> git.ipfire.org Git - people/ms/network.git/commitdiff
ipsec: Check PSK for a good length
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 31 Jul 2017 09:12:02 +0000 (11:12 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 31 Jul 2017 09:12:02 +0000 (11:12 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.ipsec

index c090a93d9dea27a1e6b03dbcf8833873de93a23c..ed889a648756eed98523b585beb1e738a7b131be 100644 (file)
@@ -334,12 +334,23 @@ ipsec_connection_authentication_psk() {
                log ERROR "Not enough arguments"
                return ${EXIT_ERROR}
        fi
+
        local connection=${1}
        local psk=${2}
 
-       # TODO Check if psk is valid 
+       local length=${#psk}
+
+       if [ ${length} -lt 4 ]; then
+               error "The PSK must be longer than four characters"
+               return ${EXIT_ERROR}
+       fi
+
+       if [ ${length} -gt 128 ]; then
+               error "The PSK cannot be longer than 128 characters"
+               return ${EXIT_ERROR}
+       fi
 
-       if ! ipsec_connection_write_config_key "${connection}" "PSK" ${psk}; then
+       if ! ipsec_connection_write_config_key "${connection}" "PSK" "${psk}"; then
                log ERROR "Could not write configuration settings"
                return ${EXIT_ERROR}
        fi