From: Nikos Mavrogiannopoulos Date: Fri, 1 Apr 2016 09:08:38 +0000 (+0200) Subject: tests: added check for system priority file loading and parsing X-Git-Tag: gnutls_3_5_0~210 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=22903e356ca78ef3113fe1b778d561b72eb910b4;p=thirdparty%2Fgnutls.git tests: added check for system priority file loading and parsing This checks whether the file is properly loaded and its contents are parsed as expected. --- diff --git a/tests/Makefile.am b/tests/Makefile.am index f3a3fe9212..7e96317173 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -35,7 +35,8 @@ EXTRA_DIST = suppressions.valgrind eagain-common.h cert-common.h test-chains.h \ certs/ca-cert-ecc.pem certs/cert-ecc256.pem certs/cert-ecc521.pem \ certs/cert-rsa-2432.pem certs/ecc384.pem certs/ecc.pem \ certs/ca-ecc.pem certs/cert-ecc384.pem certs/cert-ecc.pem certs/ecc256.pem \ - certs/ecc521.pem certs/rsa-2432.pem x509cert-dir/ca.pem psk.passwd + certs/ecc521.pem certs/rsa-2432.pem x509cert-dir/ca.pem psk.passwd \ + system.prio AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS) AM_CPPFLAGS = \ @@ -96,7 +97,8 @@ ctests = mini-record-2 simple gc set_pkcs12_cred certder certuniqueid \ rehandshake-switch-cert-client-allow handshake-versions dtls-handshake-versions \ dtls-max-record tls-max-record alpn-server-prec ocsp-filename-memleak \ dh-params rehandshake-ext-secret pcert-list session-export-funcs \ - handshake-false-start version-checks key-material-dtls key-material-set-dtls + handshake-false-start version-checks key-material-dtls key-material-set-dtls \ + system-prio-file if HAVE_SECCOMP_TESTS ctests += dtls-with-seccomp tls-with-seccomp dtls-client-with-seccomp tls-client-with-seccomp @@ -183,6 +185,7 @@ TESTS_ENVIRONMENT = \ PKCS12PASSWORD_2="" \ PKCS12PATH=$(srcdir)/pkcs12-decode/ \ X509CERTDIR=$(srcdir)/x509cert-dir/ \ + GNUTLS_SYSTEM_PRIORITY_FILE=$(srcdir)/system.prio \ PSK_FILE=$(srcdir)/psk.passwd \ EXEEXT=$(EXEEXT) \ top_builddir="$(top_builddir)" \ diff --git a/tests/system-prio-file.c b/tests/system-prio-file.c new file mode 100644 index 0000000000..261dc4502b --- /dev/null +++ b/tests/system-prio-file.c @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2016 Red Hat, Inc. + * + * Author: Nikos Mavrogiannopoulos + * + * This file is part of GnuTLS. + * + * GnuTLS is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * GnuTLS 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 GnuTLS; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include + +#include "utils.h" + +char *_gnutls_resolve_priorities(const char* priorities); + +static void +try_prio(const char *prio, const char *expected_str) +{ + char *p; + + /* this must be called once in the program + */ + global_init(); + + p = _gnutls_resolve_priorities(prio); + if (p == NULL && expected_str == NULL) + goto ok; + + if (p == NULL || strcmp(p, expected_str) != 0) { + fail("error; got: %s, expected: %s\n", p, expected_str); + exit(1); + } + + ok: + free(p); + gnutls_global_deinit(); +} + +void doit(void) +{ + try_prio("NORMAL", "NORMAL"); + try_prio("SUITEB192", "SUITEB192"); + try_prio("@HELLO1", "NORMAL"); + try_prio("@HELLO2", "NORMAL:+AES-128-CBC"); + try_prio("@HELLO3", "NONE:+VERS-TLS-ALL:-VERS-SSL3.0:+AEAD:+SHA1:+SHA256:+SHA384:+ECDHE-RSA:+ECDHE-ECDSA:+RSA:+DHE-RSA:+DHE-DSS:+AES-256-GCM:+AES-256-CBC:+CAMELLIA-256-GCM:+CAMELLIA-256-CBC:+AES-128-GCM:+AES-128-CBC:+CAMELLIA-128-GCM:+CAMELLIA-128-CBC:+3DES-CBC:+SIGN-ALL:-SIGN-RSA-MD5:+CURVE-ALL:+COMP-NULL:%PROFILE_LOW"); + try_prio("@HELLONO", NULL); +} + diff --git a/tests/system.prio b/tests/system.prio new file mode 100644 index 0000000000..ef69f6a3f4 --- /dev/null +++ b/tests/system.prio @@ -0,0 +1,3 @@ +HELLO1=NORMAL +HELLO2=NORMAL:+AES-128-CBC +HELLO3=NONE:+VERS-TLS-ALL:-VERS-SSL3.0:+AEAD:+SHA1:+SHA256:+SHA384:+ECDHE-RSA:+ECDHE-ECDSA:+RSA:+DHE-RSA:+DHE-DSS:+AES-256-GCM:+AES-256-CBC:+CAMELLIA-256-GCM:+CAMELLIA-256-CBC:+AES-128-GCM:+AES-128-CBC:+CAMELLIA-128-GCM:+CAMELLIA-128-CBC:+3DES-CBC:+SIGN-ALL:-SIGN-RSA-MD5:+CURVE-ALL:+COMP-NULL:%PROFILE_LOW