diff options
author | Steffan Karger | 2016-12-15 22:46:06 +0100 |
---|---|---|
committer | David Sommerseth | 2016-12-16 11:51:35 +0100 |
commit | ec4dff3bbdcc9fedf7844701dc5aa2679d503667 (patch) | |
tree | 2f97160eb3f56470d588d1e3db7d74ed11ddfeeb /tests | |
parent | 1f004b2f06e987d73e48f7fd7b96b0b248274f58 (diff) | |
download | openvpn-ec4dff3bbdcc9fedf7844701dc5aa2679d503667.zip openvpn-ec4dff3bbdcc9fedf7844701dc5aa2679d503667.tar.gz |
Don't reopen tun if cipher changes
When the pulled options change, OpenVPN will attempt to reopen the tun
device. That might fail if the process has already dropper privileges,
and is not needed unless the tun MTU is changed. This patch therefore
ignores the cipher value for the digest if a fixed tun-mtu is used.
Additionally, this patch changes the md_ctx_update() call to include the
trailing zero byte of each option, to make sure that parsing "foo,bar"
results in a different hash than "foobar". (Sorry for not catching that
during the review...)
The unit tests are a bit lame, but it secretly serves as a way to lower
the bar for adding more buffer.c unit tests.
Trac: #761
Signed-off-by: Steffan Karger <steffan@karger.me>
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <1481838366-32335-1-git-send-email-steffan@karger.me>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg13579.html
Signed-off-by: David Sommerseth <davids@openvpn.net>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit_tests/openvpn/Makefile.am | 8 | ||||
-rw-r--r-- | tests/unit_tests/openvpn/test_buffer.c | 56 |
2 files changed, 63 insertions, 1 deletions
diff --git a/tests/unit_tests/openvpn/Makefile.am b/tests/unit_tests/openvpn/Makefile.am index 632ff58..fafe6b2 100644 --- a/tests/unit_tests/openvpn/Makefile.am +++ b/tests/unit_tests/openvpn/Makefile.am @@ -1,6 +1,6 @@ AUTOMAKE_OPTIONS = foreign -check_PROGRAMS = argv_testdriver +check_PROGRAMS = argv_testdriver buffer_testdriver if ENABLE_CRYPTO check_PROGRAMS += tls_crypt_testdriver @@ -21,6 +21,12 @@ argv_testdriver_SOURCES = test_argv.c mock_msg.c \ $(openvpn_srcdir)/buffer.c \ $(openvpn_srcdir)/argv.c +buffer_testdriver_CFLAGS = @TEST_CFLAGS@ -I$(openvpn_srcdir) -I$(compat_srcdir) +buffer_testdriver_LDFLAGS = @TEST_LDFLAGS@ -L$(openvpn_srcdir) -Wl,--wrap=parse_line +buffer_testdriver_SOURCES = test_buffer.c mock_msg.c \ + $(openvpn_srcdir)/buffer.c \ + $(openvpn_srcdir)/platform.c + tls_crypt_testdriver_CFLAGS = @TEST_CFLAGS@ \ -I$(openvpn_includedir) -I$(compat_srcdir) -I$(openvpn_srcdir) \ $(OPTIONAL_CRYPTO_CFLAGS) diff --git a/tests/unit_tests/openvpn/test_buffer.c b/tests/unit_tests/openvpn/test_buffer.c new file mode 100644 index 0000000..5d25437 --- /dev/null +++ b/tests/unit_tests/openvpn/test_buffer.c @@ -0,0 +1,56 @@ +/* + * OpenVPN -- An application to securely tunnel IP networks + * over a single UDP port, with support for SSL/TLS-based + * session authentication and key exchange, + * packet encryption, packet authentication, and + * packet compression. + * + * Copyright (C) 2016 Fox Crypto B.V. <openvpn@fox-it.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (see the file COPYING included with this + * distribution); if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#elif defined(_MSC_VER) +#include "config-msvc.h" +#endif + +#include "syshead.h" + +#include <setjmp.h> +#include <cmocka.h> + +#include "buffer.h" + +static void +buffer_strprefix(void **state) +{ + assert_true(strprefix("123456", "123456")); + assert_true(strprefix("123456", "123")); + assert_true(strprefix("123456", "")); + assert_false(strprefix("123456", "456")); + assert_false(strprefix("12", "123")); +} + +int +main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(buffer_strprefix), + }; + + return cmocka_run_group_tests_name("buffer", tests, NULL, NULL); +} |