2011-07-20 13:04:18 -05:00
|
|
|
/*
|
2012-01-30 11:44:13 -06:00
|
|
|
* Copyright (C) 2011-2012 Red Hat, Inc.
|
2011-07-20 13:04:18 -05:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 17:30:55 -05:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 05:06:23 -05:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2011-07-20 13:04:18 -05:00
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include "testutils.h"
|
2013-08-05 10:49:24 -05:00
|
|
|
#include "virnettlshelpers.h"
|
2012-12-13 11:44:57 -06:00
|
|
|
#include "virutil.h"
|
2012-12-13 12:21:53 -06:00
|
|
|
#include "virerror.h"
|
2012-12-12 12:06:53 -06:00
|
|
|
#include "viralloc.h"
|
2012-12-12 11:59:27 -06:00
|
|
|
#include "virlog.h"
|
2011-07-20 13:04:18 -05:00
|
|
|
#include "virfile.h"
|
2012-12-12 10:27:01 -06:00
|
|
|
#include "vircommand.h"
|
Split src/util/network.{c,h} into 5 pieces
The src/util/network.c file is a dumping ground for many different
APIs. Split it up into 5 pieces, along functional lines
- src/util/virnetdevbandwidth.c: virNetDevBandwidth type & helper APIs
- src/util/virnetdevvportprofile.c: virNetDevVPortProfile type & helper APIs
- src/util/virsocketaddr.c: virSocketAddr and APIs
- src/conf/netdev_bandwidth_conf.c: XML parsing / formatting
for virNetDevBandwidth
- src/conf/netdev_vport_profile_conf.c: XML parsing / formatting
for virNetDevVPortProfile
* src/util/network.c, src/util/network.h: Split into 5 pieces
* src/conf/netdev_bandwidth_conf.c, src/conf/netdev_bandwidth_conf.h,
src/conf/netdev_vport_profile_conf.c, src/conf/netdev_vport_profile_conf.h,
src/util/virnetdevbandwidth.c, src/util/virnetdevbandwidth.h,
src/util/virnetdevvportprofile.c, src/util/virnetdevvportprofile.h,
src/util/virsocketaddr.c, src/util/virsocketaddr.h: New pieces
* daemon/libvirtd.h, daemon/remote.c, src/conf/domain_conf.c,
src/conf/domain_conf.h, src/conf/network_conf.c,
src/conf/network_conf.h, src/conf/nwfilter_conf.h,
src/esx/esx_util.h, src/network/bridge_driver.c,
src/qemu/qemu_conf.c, src/rpc/virnetsocket.c,
src/rpc/virnetsocket.h, src/util/dnsmasq.h, src/util/interface.h,
src/util/iptables.h, src/util/macvtap.c, src/util/macvtap.h,
src/util/virnetdev.h, src/util/virnetdevtap.c,
tools/virsh.c: Update include files
2011-11-02 10:40:08 -05:00
|
|
|
#include "virsocketaddr.h"
|
2011-07-20 13:04:18 -05:00
|
|
|
|
2012-01-30 11:44:13 -06:00
|
|
|
#if !defined WIN32 && HAVE_LIBTASN1_H && LIBGNUTLS_VERSION_NUMBER >= 0x020600
|
2011-07-20 13:04:18 -05:00
|
|
|
|
|
|
|
# include "rpc/virnettlscontext.h"
|
|
|
|
|
|
|
|
# define VIR_FROM_THIS VIR_FROM_RPC
|
|
|
|
|
|
|
|
struct testTLSContextData {
|
|
|
|
bool isServer;
|
|
|
|
struct testTLSCertReq careq;
|
|
|
|
struct testTLSCertReq certreq;
|
|
|
|
bool expectFail;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This tests sanity checking of our own certificates
|
|
|
|
*
|
|
|
|
* This code is done when libvirtd starts up, or before
|
|
|
|
* a libvirt client connects. The test is ensuring that
|
|
|
|
* the creation of virNetTLSContextPtr fails if we
|
2012-10-11 11:31:20 -05:00
|
|
|
* give bogus certs, or succeeds for good certs
|
2011-07-20 13:04:18 -05:00
|
|
|
*/
|
|
|
|
static int testTLSContextInit(const void *opaque)
|
|
|
|
{
|
|
|
|
struct testTLSContextData *data = (struct testTLSContextData *)opaque;
|
|
|
|
virNetTLSContextPtr ctxt = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
testTLSGenerateCert(&data->careq);
|
|
|
|
data->certreq.cacrt = data->careq.crt;
|
|
|
|
testTLSGenerateCert(&data->certreq);
|
|
|
|
|
|
|
|
if (data->isServer) {
|
|
|
|
ctxt = virNetTLSContextNewServer(data->careq.filename,
|
|
|
|
NULL,
|
|
|
|
data->certreq.filename,
|
|
|
|
keyfile,
|
|
|
|
NULL,
|
|
|
|
true,
|
|
|
|
true);
|
|
|
|
} else {
|
|
|
|
ctxt = virNetTLSContextNewClient(data->careq.filename,
|
|
|
|
NULL,
|
|
|
|
data->certreq.filename,
|
|
|
|
keyfile,
|
|
|
|
true,
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctxt) {
|
|
|
|
if (data->expectFail) {
|
|
|
|
VIR_WARN("Expected failure %s against %s",
|
|
|
|
data->careq.filename, data->certreq.filename);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
virErrorPtr err = virGetLastError();
|
|
|
|
if (!data->expectFail) {
|
|
|
|
VIR_WARN("Unexpected failure %s against %s",
|
|
|
|
data->careq.filename, data->certreq.filename);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
VIR_DEBUG("Got error %s", err ? err->message : "<unknown>");
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
2012-07-11 08:35:48 -05:00
|
|
|
virObjectUnref(ctxt);
|
2013-08-05 10:49:24 -05:00
|
|
|
testTLSDiscardCert(&data->careq);
|
|
|
|
testTLSDiscardCert(&data->certreq);
|
2011-07-20 13:04:18 -05:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2013-08-05 10:49:24 -05:00
|
|
|
testTLSInit();
|
2011-07-20 13:04:18 -05:00
|
|
|
|
test: fix build errors with gcc 4.7.0 and -O0
When building on Fedora 17 (which uses gcc 4.7.0) with -O0 in CFLAGS,
three of the tests failed to compile.
cputest.c and qemuxml2argvtest.c had non-static structs defined
inside the macro that was being repeatedly invoked. Due to some so-far
unidentified change in gcc, the stack space used by variables defined
inside { } is not recovered/re-used when the block ends, so all these
structs have become additive (this is the same problem worked around
in commit cf57d345b). Fortunately, these two files could be fixed with
a single line addition of "static" to the struct definition in the
macro.
virnettlscontexttest.c was a bit different, though. The problem structs
in the do/while loop of macros had non-constant initializers, so it
took a bit more work and piecemeal initialization instead of member
initialization to get things to be happy.
In an ideal world, none of these changes should be necessary, but not
knowing how long it will be until the gcc regressions are fixed, and
since the code is just as correct after this patch as before, it makes
sense to fix libvirt's build for -O0 while also reporting the gcc
problem.
2012-04-05 15:31:36 -05:00
|
|
|
# define DO_CTX_TEST(_isServer, _caReq, _certReq, _expectFail) \
|
2011-07-20 13:04:18 -05:00
|
|
|
do { \
|
test: fix build errors with gcc 4.7.0 and -O0
When building on Fedora 17 (which uses gcc 4.7.0) with -O0 in CFLAGS,
three of the tests failed to compile.
cputest.c and qemuxml2argvtest.c had non-static structs defined
inside the macro that was being repeatedly invoked. Due to some so-far
unidentified change in gcc, the stack space used by variables defined
inside { } is not recovered/re-used when the block ends, so all these
structs have become additive (this is the same problem worked around
in commit cf57d345b). Fortunately, these two files could be fixed with
a single line addition of "static" to the struct definition in the
macro.
virnettlscontexttest.c was a bit different, though. The problem structs
in the do/while loop of macros had non-constant initializers, so it
took a bit more work and piecemeal initialization instead of member
initialization to get things to be happy.
In an ideal world, none of these changes should be necessary, but not
knowing how long it will be until the gcc regressions are fixed, and
since the code is just as correct after this patch as before, it makes
sense to fix libvirt's build for -O0 while also reporting the gcc
problem.
2012-04-05 15:31:36 -05:00
|
|
|
static struct testTLSContextData data; \
|
|
|
|
data.isServer = _isServer; \
|
|
|
|
data.careq = _caReq; \
|
|
|
|
data.certreq = _certReq; \
|
|
|
|
data.expectFail = _expectFail; \
|
2011-07-20 13:04:18 -05:00
|
|
|
if (virtTestRun("TLS Context", 1, testTLSContextInit, &data) < 0) \
|
|
|
|
ret = -1; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* A perfect CA, perfect client & perfect server */
|
|
|
|
|
|
|
|
/* Basic:CA:critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq cacertreq = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "cacert.pem", "UK",
|
|
|
|
"libvirt CA", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, true,
|
|
|
|
true, true, GNUTLS_KEY_KEY_CERT_SIGN,
|
|
|
|
false, false, NULL, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq servercertreq = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "servercert.pem", "UK",
|
|
|
|
"libvirt.org", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
true, true, GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
|
|
|
|
true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq clientcertreq = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "clientcert.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
true, true, GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
|
|
|
|
true, true, GNUTLS_KP_TLS_WWW_CLIENT, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
DO_CTX_TEST(true, cacertreq, servercertreq, false);
|
|
|
|
DO_CTX_TEST(false, cacertreq, clientcertreq, false);
|
|
|
|
|
|
|
|
|
|
|
|
/* Some other CAs which are good */
|
|
|
|
|
|
|
|
/* Basic:CA:critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq cacert1req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "cacert1.pem", "UK",
|
|
|
|
"libvirt CA 1", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, true,
|
|
|
|
false, false, 0,
|
|
|
|
false, false, NULL, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
/* Basic:CA:not-critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq cacert2req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "cacert2.pem", "UK",
|
|
|
|
"libvirt CA 2", NULL, NULL, NULL, NULL,
|
|
|
|
true, false, true,
|
|
|
|
false, false, 0,
|
|
|
|
false, false, NULL, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
2013-08-05 10:49:24 -05:00
|
|
|
/* Key usage:cert-sign:critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq cacert3req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "cacert3.pem", "UK",
|
|
|
|
"libvirt CA 3", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, true,
|
|
|
|
true, true, GNUTLS_KEY_KEY_CERT_SIGN,
|
|
|
|
false, false, NULL, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
DO_CTX_TEST(true, cacert1req, servercertreq, false);
|
|
|
|
DO_CTX_TEST(true, cacert2req, servercertreq, false);
|
|
|
|
DO_CTX_TEST(true, cacert3req, servercertreq, false);
|
|
|
|
|
|
|
|
/* Now some bad certs */
|
|
|
|
|
2013-03-04 11:27:38 -06:00
|
|
|
/* Key usage:dig-sig:not-critical */
|
2013-08-05 10:49:24 -05:00
|
|
|
static struct testTLSCertReq cacert4req = {
|
|
|
|
NULL, NULL, "cacert4.pem", "UK",
|
|
|
|
"libvirt CA 4", NULL, NULL, NULL, NULL,
|
2013-03-04 11:27:38 -06:00
|
|
|
true, true, true,
|
|
|
|
true, false, GNUTLS_KEY_DIGITAL_SIGNATURE,
|
|
|
|
false, false, NULL, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
2011-07-20 13:04:18 -05:00
|
|
|
/* no-basic */
|
2013-08-05 10:49:24 -05:00
|
|
|
static struct testTLSCertReq cacert5req = {
|
|
|
|
NULL, NULL, "cacert5.pem", "UK",
|
|
|
|
"libvirt CA 5", NULL, NULL, NULL, NULL,
|
2011-07-20 13:04:18 -05:00
|
|
|
false, false, false,
|
|
|
|
false, false, 0,
|
|
|
|
false, false, NULL, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
/* Key usage:dig-sig:critical */
|
2013-08-05 10:49:24 -05:00
|
|
|
static struct testTLSCertReq cacert6req = {
|
|
|
|
NULL, NULL, "cacert6.pem", "UK",
|
|
|
|
"libvirt CA 6", NULL, NULL, NULL, NULL,
|
2011-07-20 13:04:18 -05:00
|
|
|
true, true, true,
|
|
|
|
true, true, GNUTLS_KEY_DIGITAL_SIGNATURE,
|
|
|
|
false, false, NULL, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
|
2013-03-04 11:27:38 -06:00
|
|
|
/* Technically a CA cert with basic constraints
|
|
|
|
* key purpose == key signing + non-critical should
|
|
|
|
* be rejected. GNUTLS < 3 does not reject it and
|
|
|
|
* we don't anticipate them changing this behaviour
|
|
|
|
*/
|
2013-08-05 10:49:24 -05:00
|
|
|
DO_CTX_TEST(true, cacert4req, servercertreq, GNUTLS_VERSION_MAJOR >= 3);
|
|
|
|
DO_CTX_TEST(true, cacert5req, servercertreq, true);
|
2011-07-20 13:04:18 -05:00
|
|
|
DO_CTX_TEST(true, cacert6req, servercertreq, true);
|
|
|
|
|
|
|
|
|
|
|
|
/* Various good servers */
|
|
|
|
/* no usage or purpose */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq servercert1req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "servercert1.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
false, false, 0,
|
|
|
|
false, false, NULL, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
/* usage:cert-sign+dig-sig+encipher:critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq servercert2req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "servercert2.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
true, true, GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT | GNUTLS_KEY_KEY_CERT_SIGN,
|
|
|
|
false, false, NULL, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
/* usage:cert-sign:not-critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq servercert3req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "servercert3.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
true, false, GNUTLS_KEY_KEY_CERT_SIGN,
|
|
|
|
false, false, NULL, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
/* purpose:server:critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq servercert4req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "servercert4.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
false, false, 0,
|
|
|
|
true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
/* purpose:server:not-critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq servercert5req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "servercert5.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
false, false, 0,
|
|
|
|
true, false, GNUTLS_KP_TLS_WWW_SERVER, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
/* purpose:client+server:critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq servercert6req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "servercert6.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
false, false, 0,
|
|
|
|
true, true, GNUTLS_KP_TLS_WWW_CLIENT, GNUTLS_KP_TLS_WWW_SERVER,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
/* purpose:client+server:not-critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq servercert7req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "servercert7.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
false, false, 0,
|
|
|
|
true, false, GNUTLS_KP_TLS_WWW_CLIENT, GNUTLS_KP_TLS_WWW_SERVER,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
DO_CTX_TEST(true, cacertreq, servercert1req, false);
|
|
|
|
DO_CTX_TEST(true, cacertreq, servercert2req, false);
|
|
|
|
DO_CTX_TEST(true, cacertreq, servercert3req, false);
|
|
|
|
DO_CTX_TEST(true, cacertreq, servercert4req, false);
|
|
|
|
DO_CTX_TEST(true, cacertreq, servercert5req, false);
|
|
|
|
DO_CTX_TEST(true, cacertreq, servercert6req, false);
|
|
|
|
DO_CTX_TEST(true, cacertreq, servercert7req, false);
|
|
|
|
/* Bad servers */
|
|
|
|
|
|
|
|
/* usage:cert-sign:critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq servercert8req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "servercert8.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
true, true, GNUTLS_KEY_KEY_CERT_SIGN,
|
|
|
|
false, false, NULL, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
/* purpose:client:critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq servercert9req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "servercert9.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
false, false, 0,
|
|
|
|
true, true, GNUTLS_KP_TLS_WWW_CLIENT, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
/* usage: none:critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq servercert10req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "servercert10.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
true, true, 0,
|
|
|
|
false, false, NULL, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
DO_CTX_TEST(true, cacertreq, servercert8req, true);
|
|
|
|
DO_CTX_TEST(true, cacertreq, servercert9req, true);
|
|
|
|
DO_CTX_TEST(true, cacertreq, servercert10req, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Various good clients */
|
|
|
|
/* no usage or purpose */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq clientcert1req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "clientcert1.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
false, false, 0,
|
|
|
|
false, false, NULL, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
/* usage:cert-sign+dig-sig+encipher:critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq clientcert2req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "clientcert2.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
true, true, GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT | GNUTLS_KEY_KEY_CERT_SIGN,
|
|
|
|
false, false, NULL, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
/* usage:cert-sign:not-critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq clientcert3req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "clientcert3.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
true, false, GNUTLS_KEY_KEY_CERT_SIGN,
|
|
|
|
false, false, NULL, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
/* purpose:client:critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq clientcert4req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "clientcert4.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
false, false, 0,
|
|
|
|
true, true, GNUTLS_KP_TLS_WWW_CLIENT, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
/* purpose:client:not-critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq clientcert5req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "clientcert5.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
false, false, 0,
|
|
|
|
true, false, GNUTLS_KP_TLS_WWW_CLIENT, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
/* purpose:client+client:critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq clientcert6req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "clientcert6.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
false, false, 0,
|
|
|
|
true, true, GNUTLS_KP_TLS_WWW_CLIENT, GNUTLS_KP_TLS_WWW_SERVER,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
/* purpose:client+client:not-critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq clientcert7req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "clientcert7.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
false, false, 0,
|
|
|
|
true, false, GNUTLS_KP_TLS_WWW_CLIENT, GNUTLS_KP_TLS_WWW_SERVER,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
DO_CTX_TEST(false, cacertreq, clientcert1req, false);
|
|
|
|
DO_CTX_TEST(false, cacertreq, clientcert2req, false);
|
|
|
|
DO_CTX_TEST(false, cacertreq, clientcert3req, false);
|
|
|
|
DO_CTX_TEST(false, cacertreq, clientcert4req, false);
|
|
|
|
DO_CTX_TEST(false, cacertreq, clientcert5req, false);
|
|
|
|
DO_CTX_TEST(false, cacertreq, clientcert6req, false);
|
|
|
|
DO_CTX_TEST(false, cacertreq, clientcert7req, false);
|
|
|
|
/* Bad clients */
|
|
|
|
|
|
|
|
/* usage:cert-sign:critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq clientcert8req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "clientcert8.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
true, true, GNUTLS_KEY_KEY_CERT_SIGN,
|
|
|
|
false, false, NULL, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
/* purpose:client:critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq clientcert9req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "clientcert9.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
false, false, 0,
|
|
|
|
true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
/* usage: none:critical */
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq clientcert10req = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "clientcert10.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
true, true, 0,
|
|
|
|
false, false, NULL, NULL,
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
DO_CTX_TEST(false, cacertreq, clientcert8req, true);
|
|
|
|
DO_CTX_TEST(false, cacertreq, clientcert9req, true);
|
|
|
|
DO_CTX_TEST(false, cacertreq, clientcert10req, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Expired stuff */
|
|
|
|
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq cacertexpreq = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "cacert.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, true,
|
|
|
|
true, true, GNUTLS_KEY_KEY_CERT_SIGN,
|
|
|
|
false, false, NULL, NULL,
|
2011-07-25 10:18:56 -05:00
|
|
|
0, -1,
|
2011-07-20 13:04:18 -05:00
|
|
|
};
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq servercertexpreq = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "servercert.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
true, true, GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
|
|
|
|
true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
|
2011-07-25 10:18:56 -05:00
|
|
|
0, -1,
|
2011-07-20 13:04:18 -05:00
|
|
|
};
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq clientcertexpreq = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "clientcert.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
true, true, GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
|
|
|
|
true, true, GNUTLS_KP_TLS_WWW_CLIENT, NULL,
|
2011-07-25 10:18:56 -05:00
|
|
|
0, -1,
|
2011-07-20 13:04:18 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
DO_CTX_TEST(true, cacertexpreq, servercertreq, true);
|
|
|
|
DO_CTX_TEST(true, cacertreq, servercertexpreq, true);
|
|
|
|
DO_CTX_TEST(false, cacertreq, clientcertexpreq, true);
|
|
|
|
|
|
|
|
|
|
|
|
/* Not activated stuff */
|
|
|
|
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq cacertnewreq = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "cacert.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, true,
|
|
|
|
true, true, GNUTLS_KEY_KEY_CERT_SIGN,
|
|
|
|
false, false, NULL, NULL,
|
2011-07-22 12:59:37 -05:00
|
|
|
1, 2,
|
2011-07-20 13:04:18 -05:00
|
|
|
};
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq servercertnewreq = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "servercert.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
true, true, GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
|
|
|
|
true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
|
2011-07-22 12:59:37 -05:00
|
|
|
1, 2,
|
2011-07-20 13:04:18 -05:00
|
|
|
};
|
2011-07-22 12:59:37 -05:00
|
|
|
static struct testTLSCertReq clientcertnewreq = {
|
2011-07-20 13:04:18 -05:00
|
|
|
NULL, NULL, "clientcert.pem", "UK",
|
|
|
|
"libvirt", NULL, NULL, NULL, NULL,
|
|
|
|
true, true, false,
|
|
|
|
true, true, GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
|
|
|
|
true, true, GNUTLS_KP_TLS_WWW_CLIENT, NULL,
|
2011-07-22 12:59:37 -05:00
|
|
|
1, 2,
|
2011-07-20 13:04:18 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
DO_CTX_TEST(true, cacertnewreq, servercertreq, true);
|
|
|
|
DO_CTX_TEST(true, cacertreq, servercertnewreq, true);
|
|
|
|
DO_CTX_TEST(false, cacertreq, clientcertnewreq, true);
|
|
|
|
|
2013-08-05 10:49:24 -05:00
|
|
|
testTLSCleanup();
|
2011-07-20 13:04:18 -05:00
|
|
|
|
2012-03-22 06:33:35 -05:00
|
|
|
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
2011-07-20 13:04:18 -05:00
|
|
|
}
|
|
|
|
|
2011-07-22 12:59:37 -05:00
|
|
|
VIRT_TEST_MAIN(mymain)
|
|
|
|
|
2011-07-20 13:04:18 -05:00
|
|
|
#else
|
2011-07-28 10:48:12 -05:00
|
|
|
|
2011-07-22 12:59:37 -05:00
|
|
|
int
|
2011-07-28 10:48:12 -05:00
|
|
|
main(void)
|
2011-07-20 13:04:18 -05:00
|
|
|
{
|
2011-07-28 10:48:12 -05:00
|
|
|
return EXIT_AM_SKIP;
|
2011-07-20 13:04:18 -05:00
|
|
|
}
|
2011-07-28 10:48:12 -05:00
|
|
|
|
2011-07-20 13:04:18 -05:00
|
|
|
#endif
|