Blame tests/system-prio-file.c

Packit aea12f
/*
Packit aea12f
 * Copyright (C) 2016 Red Hat, Inc.
Packit aea12f
 *
Packit aea12f
 * Author: Nikos Mavrogiannopoulos
Packit aea12f
 *
Packit aea12f
 * This file is part of GnuTLS.
Packit aea12f
 *
Packit aea12f
 * GnuTLS is free software; you can redistribute it and/or modify it
Packit aea12f
 * under the terms of the GNU General Public License as published by
Packit aea12f
 * the Free Software Foundation; either version 3 of the License, or
Packit aea12f
 * (at your option) any later version.
Packit aea12f
 *
Packit aea12f
 * GnuTLS is distributed in the hope that it will be useful, but
Packit aea12f
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit aea12f
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit aea12f
 * General Public License for more details.
Packit aea12f
 *
Packit aea12f
 * You should have received a copy of the GNU General Public License
Packit aea12f
 * along with GnuTLS; if not, write to the Free Software Foundation,
Packit aea12f
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Packit aea12f
 */
Packit aea12f
Packit aea12f
#ifdef HAVE_CONFIG_H
Packit aea12f
#include <config.h>
Packit aea12f
#endif
Packit aea12f
Packit aea12f
#include <stdio.h>
Packit aea12f
#include <stdlib.h>
Packit aea12f
#include <string.h>
Packit aea12f
#include <gnutls/gnutls.h>
Packit Service 991b93
#include <assert.h>
Packit aea12f
Packit aea12f
#include "utils.h"
Packit aea12f
Packit aea12f
/* This test verifies the correct operation of system-wide priority
Packit aea12f
 * strings. The test suite sets the GNUTLS_SYSTEM_PRIORITY_FILE environment
Packit aea12f
 * variable to specify the test file (system.prio).
Packit aea12f
 */
Packit aea12f
Packit aea12f
char *_gnutls_resolve_priorities(const char* priorities);
Packit aea12f
Packit aea12f
static void
Packit aea12f
try_prio(const char *prio, const char *expected_str)
Packit aea12f
{
Packit aea12f
	char *p;
Packit aea12f
Packit aea12f
	/* this must be called once in the program
Packit aea12f
	 */
Packit aea12f
	global_init();
Packit aea12f
Packit aea12f
	p = _gnutls_resolve_priorities(prio);
Packit aea12f
	if (p == NULL && expected_str == NULL)
Packit aea12f
		goto ok;
Packit aea12f
Packit Service 991b93
	assert(strstr(gnutls_get_system_config_file(), "system.prio") != NULL);
Packit Service 991b93
Packit aea12f
	if (p == NULL || expected_str == NULL || strcmp(p, expected_str) != 0) {
Packit aea12f
		fail("test: %s: error; got: %s, expected: %s\n", prio, p, expected_str);
Packit aea12f
		exit(1);
Packit aea12f
	}
Packit aea12f
Packit aea12f
 ok:
Packit aea12f
	gnutls_free(p);
Packit aea12f
	gnutls_global_deinit();
Packit aea12f
}
Packit aea12f
Packit aea12f
void doit(void)
Packit aea12f
{
Packit aea12f
	try_prio("NORMAL", "NORMAL");
Packit aea12f
	try_prio("SUITEB192", "SUITEB192");
Packit aea12f
	try_prio("@HELLO1", "NORMAL");
Packit aea12f
	try_prio("@HELLO1:+AES-256-CBC:+AEAD", "NORMAL:+AES-256-CBC:+AEAD");
Packit aea12f
	try_prio("@HELLO2", "NORMAL:+AES-128-CBC");
Packit aea12f
	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");
Packit aea12f
	try_prio("@HELLO1,HELLO2", "NORMAL");
Packit aea12f
	try_prio("@HELLO1,HELLO2:+AES-128-CBC", "NORMAL:+AES-128-CBC");
Packit aea12f
	try_prio("@HELLO1,HELLO1", "NORMAL");
Packit aea12f
	try_prio("@HELLO1,", "NORMAL");
Packit aea12f
	try_prio("@HELLO2,HELLO1", "NORMAL:+AES-128-CBC");
Packit aea12f
	try_prio("@HELLO2,HELLO1,@HELLONO", "NORMAL:+AES-128-CBC");
Packit aea12f
	try_prio("@HELLO2,HELLO1,@HELLO3", "NORMAL:+AES-128-CBC");
Packit aea12f
	try_prio("@HELLONO,HELLO1", "NORMAL");
Packit aea12f
	try_prio("@HELLONO,HELLONO2,HELLO1", "NORMAL");
Packit aea12f
	try_prio("@HELLONO,HELLONO2,HELLO1:+AES-128-CBC", "NORMAL:+AES-128-CBC");
Packit aea12f
	try_prio("@HELLONO", NULL);
Packit aea12f
	try_prio("@HELLONO,", NULL);
Packit aea12f
	try_prio("@HELLONO:+AES-128-CBC", NULL);
Packit aea12f
	try_prio("@HELLONO,:+AES-128-CBC", NULL);
Packit aea12f
}