2 * Copyright (C) 2015 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see
16 * <http://www.gnu.org/licenses/>.
18 * Author: Daniel P. Berrange <berrange@redhat.com>
21 #include "qemu/osdep.h"
23 #include "crypto-tls-x509-helpers.h"
24 #include "crypto/tlscredsx509.h"
26 #ifdef QCRYPTO_HAVE_TLS_TEST_SUPPORT
28 #define WORKDIR "tests/test-crypto-tlscredsx509-work/"
29 #define KEYFILE WORKDIR "key-ctx.pem"
31 struct QCryptoTLSCredsTestData
{
39 static QCryptoTLSCreds
*test_tls_creds_create(QCryptoTLSCredsEndpoint endpoint
,
43 Object
*parent
= object_get_objects_root();
44 Object
*creds
= object_new_with_props(
45 TYPE_QCRYPTO_TLS_CREDS_X509
,
49 "endpoint", (endpoint
== QCRYPTO_TLS_CREDS_ENDPOINT_SERVER
?
53 "sanity-check", "yes",
59 return QCRYPTO_TLS_CREDS(creds
);
63 * This tests sanity checking of our own certificates
65 * The code being tested is used when TLS creds are created,
66 * and aim to ensure QMEU has been configured with sane
67 * certificates. This allows us to give much much much
68 * clearer error messages to the admin when they misconfigure
71 static void test_tls_creds(const void *opaque
)
73 struct QCryptoTLSCredsTestData
*data
=
74 (struct QCryptoTLSCredsTestData
*)opaque
;
75 QCryptoTLSCreds
*creds
;
78 #define CERT_DIR "tests/test-crypto-tlscredsx509-certs/"
79 mkdir(CERT_DIR
, 0700);
81 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT
);
83 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT
);
84 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_KEY
);
86 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CLIENT_CERT
);
87 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CLIENT_KEY
);
90 if (access(data
->cacrt
, R_OK
) == 0) {
91 g_assert(link(data
->cacrt
,
92 CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT
) == 0);
95 if (access(data
->crt
, R_OK
) == 0) {
96 g_assert(link(data
->crt
,
97 CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT
) == 0);
99 g_assert(link(KEYFILE
,
100 CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_KEY
) == 0);
102 if (access(data
->crt
, R_OK
) == 0) {
103 g_assert(link(data
->crt
,
104 CERT_DIR QCRYPTO_TLS_CREDS_X509_CLIENT_CERT
) == 0);
106 g_assert(link(KEYFILE
,
107 CERT_DIR QCRYPTO_TLS_CREDS_X509_CLIENT_KEY
) == 0);
110 creds
= test_tls_creds_create(
112 QCRYPTO_TLS_CREDS_ENDPOINT_SERVER
:
113 QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT
),
117 if (data
->expectFail
) {
119 g_assert(creds
== NULL
);
122 g_printerr("Failed to generate creds: %s\n",
123 error_get_pretty(err
));
126 g_assert(creds
!= NULL
);
129 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT
);
130 if (data
->isServer
) {
131 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT
);
132 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_KEY
);
134 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CLIENT_CERT
);
135 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CLIENT_KEY
);
139 object_unparent(OBJECT(creds
));
143 int main(int argc
, char **argv
)
147 module_call_init(MODULE_INIT_QOM
);
148 g_test_init(&argc
, &argv
, NULL
);
149 setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
151 mkdir(WORKDIR
, 0700);
153 test_tls_init(KEYFILE
);
155 # define TLS_TEST_REG(name, isServer, caCrt, crt, expectFail) \
156 struct QCryptoTLSCredsTestData name = { \
157 isServer, caCrt, crt, expectFail \
159 g_test_add_data_func("/qcrypto/tlscredsx509/" # name, \
160 &name, test_tls_creds); \
162 /* A perfect CA, perfect client & perfect server */
164 /* Basic:CA:critical */
165 TLS_ROOT_REQ(cacertreq
,
166 "UK", "qemu CA", NULL
, NULL
, NULL
, NULL
,
168 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
169 false, false, NULL
, NULL
,
172 TLS_CERT_REQ(servercertreq
, cacertreq
,
173 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
176 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
177 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
179 TLS_CERT_REQ(clientcertreq
, cacertreq
,
180 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
183 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
184 true, true, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
187 TLS_TEST_REG(perfectserver
, true,
188 cacertreq
.filename
, servercertreq
.filename
, false);
189 TLS_TEST_REG(perfectclient
, false,
190 cacertreq
.filename
, clientcertreq
.filename
, false);
193 /* Some other CAs which are good */
195 /* Basic:CA:critical */
196 TLS_ROOT_REQ(cacert1req
,
197 "UK", "qemu CA 1", NULL
, NULL
, NULL
, NULL
,
200 false, false, NULL
, NULL
,
202 TLS_CERT_REQ(servercert1req
, cacert1req
,
203 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
206 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
207 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
210 /* Basic:CA:not-critical */
211 TLS_ROOT_REQ(cacert2req
,
212 "UK", "qemu CA 2", NULL
, NULL
, NULL
, NULL
,
215 false, false, NULL
, NULL
,
217 TLS_CERT_REQ(servercert2req
, cacert2req
,
218 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
221 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
222 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
225 /* Key usage:cert-sign:critical */
226 TLS_ROOT_REQ(cacert3req
,
227 "UK", "qemu CA 3", NULL
, NULL
, NULL
, NULL
,
229 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
230 false, false, NULL
, NULL
,
232 TLS_CERT_REQ(servercert3req
, cacert3req
,
233 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
236 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
237 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
240 TLS_TEST_REG(goodca1
, true,
241 cacert1req
.filename
, servercert1req
.filename
, false);
242 TLS_TEST_REG(goodca2
, true,
243 cacert2req
.filename
, servercert2req
.filename
, false);
244 TLS_TEST_REG(goodca3
, true,
245 cacert3req
.filename
, servercert3req
.filename
, false);
247 /* Now some bad certs */
249 /* Key usage:dig-sig:not-critical */
250 TLS_ROOT_REQ(cacert4req
,
251 "UK", "qemu CA 4", NULL
, NULL
, NULL
, NULL
,
253 true, false, GNUTLS_KEY_DIGITAL_SIGNATURE
,
254 false, false, NULL
, NULL
,
256 TLS_CERT_REQ(servercert4req
, cacert4req
,
257 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
260 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
261 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
264 TLS_ROOT_REQ(cacert5req
,
265 "UK", "qemu CA 5", NULL
, NULL
, NULL
, NULL
,
268 false, false, NULL
, NULL
,
270 TLS_CERT_REQ(servercert5req
, cacert5req
,
271 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
274 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
275 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
277 /* Key usage:dig-sig:critical */
278 TLS_ROOT_REQ(cacert6req
,
279 "UK", "qemu CA 6", NULL
, NULL
, NULL
, NULL
,
281 true, true, GNUTLS_KEY_DIGITAL_SIGNATURE
,
282 false, false, NULL
, NULL
,
284 TLS_CERT_REQ(servercert6req
, cacert6req
,
285 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
288 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
289 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
292 /* Technically a CA cert with basic constraints
293 * key purpose == key signing + non-critical should
294 * be rejected. GNUTLS < 3.1 does not reject it and
295 * we don't anticipate them changing this behaviour
297 TLS_TEST_REG(badca1
, true, cacert4req
.filename
, servercert4req
.filename
,
298 (GNUTLS_VERSION_MAJOR
== 3 && GNUTLS_VERSION_MINOR
>= 1) ||
299 GNUTLS_VERSION_MAJOR
> 3);
300 TLS_TEST_REG(badca2
, true,
301 cacert5req
.filename
, servercert5req
.filename
, true);
302 TLS_TEST_REG(badca3
, true,
303 cacert6req
.filename
, servercert6req
.filename
, true);
306 /* Various good servers */
307 /* no usage or purpose */
308 TLS_CERT_REQ(servercert7req
, cacertreq
,
309 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
312 false, false, NULL
, NULL
,
314 /* usage:cert-sign+dig-sig+encipher:critical */
315 TLS_CERT_REQ(servercert8req
, cacertreq
,
316 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
319 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
|
320 GNUTLS_KEY_KEY_CERT_SIGN
,
321 false, false, NULL
, NULL
,
323 /* usage:cert-sign:not-critical */
324 TLS_CERT_REQ(servercert9req
, cacertreq
,
325 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
327 true, false, GNUTLS_KEY_KEY_CERT_SIGN
,
328 false, false, NULL
, NULL
,
330 /* purpose:server:critical */
331 TLS_CERT_REQ(servercert10req
, cacertreq
,
332 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
335 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
337 /* purpose:server:not-critical */
338 TLS_CERT_REQ(servercert11req
, cacertreq
,
339 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
342 true, false, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
344 /* purpose:client+server:critical */
345 TLS_CERT_REQ(servercert12req
, cacertreq
,
346 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
350 GNUTLS_KP_TLS_WWW_CLIENT
, GNUTLS_KP_TLS_WWW_SERVER
,
352 /* purpose:client+server:not-critical */
353 TLS_CERT_REQ(servercert13req
, cacertreq
,
354 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
358 GNUTLS_KP_TLS_WWW_CLIENT
, GNUTLS_KP_TLS_WWW_SERVER
,
361 TLS_TEST_REG(goodserver1
, true,
362 cacertreq
.filename
, servercert7req
.filename
, false);
363 TLS_TEST_REG(goodserver2
, true,
364 cacertreq
.filename
, servercert8req
.filename
, false);
365 TLS_TEST_REG(goodserver3
, true,
366 cacertreq
.filename
, servercert9req
.filename
, false);
367 TLS_TEST_REG(goodserver4
, true,
368 cacertreq
.filename
, servercert10req
.filename
, false);
369 TLS_TEST_REG(goodserver5
, true,
370 cacertreq
.filename
, servercert11req
.filename
, false);
371 TLS_TEST_REG(goodserver6
, true,
372 cacertreq
.filename
, servercert12req
.filename
, false);
373 TLS_TEST_REG(goodserver7
, true,
374 cacertreq
.filename
, servercert13req
.filename
, false);
378 /* usage:cert-sign:critical */
379 TLS_CERT_REQ(servercert14req
, cacertreq
,
380 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
382 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
383 false, false, NULL
, NULL
,
385 /* purpose:client:critical */
386 TLS_CERT_REQ(servercert15req
, cacertreq
,
387 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
390 true, true, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
392 /* usage: none:critical */
393 TLS_CERT_REQ(servercert16req
, cacertreq
,
394 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
397 false, false, NULL
, NULL
,
400 TLS_TEST_REG(badserver1
, true,
401 cacertreq
.filename
, servercert14req
.filename
, true);
402 TLS_TEST_REG(badserver2
, true,
403 cacertreq
.filename
, servercert15req
.filename
, true);
404 TLS_TEST_REG(badserver3
, true,
405 cacertreq
.filename
, servercert16req
.filename
, true);
409 /* Various good clients */
410 /* no usage or purpose */
411 TLS_CERT_REQ(clientcert1req
, cacertreq
,
412 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
415 false, false, NULL
, NULL
,
417 /* usage:cert-sign+dig-sig+encipher:critical */
418 TLS_CERT_REQ(clientcert2req
, cacertreq
,
419 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
422 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
|
423 GNUTLS_KEY_KEY_CERT_SIGN
,
424 false, false, NULL
, NULL
,
426 /* usage:cert-sign:not-critical */
427 TLS_CERT_REQ(clientcert3req
, cacertreq
,
428 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
430 true, false, GNUTLS_KEY_KEY_CERT_SIGN
,
431 false, false, NULL
, NULL
,
433 /* purpose:client:critical */
434 TLS_CERT_REQ(clientcert4req
, cacertreq
,
435 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
438 true, true, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
440 /* purpose:client:not-critical */
441 TLS_CERT_REQ(clientcert5req
, cacertreq
,
442 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
445 true, false, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
447 /* purpose:client+client:critical */
448 TLS_CERT_REQ(clientcert6req
, cacertreq
,
449 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
453 GNUTLS_KP_TLS_WWW_CLIENT
, GNUTLS_KP_TLS_WWW_SERVER
,
455 /* purpose:client+client:not-critical */
456 TLS_CERT_REQ(clientcert7req
, cacertreq
,
457 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
461 GNUTLS_KP_TLS_WWW_CLIENT
, GNUTLS_KP_TLS_WWW_SERVER
,
464 TLS_TEST_REG(goodclient1
, false,
465 cacertreq
.filename
, clientcert1req
.filename
, false);
466 TLS_TEST_REG(goodclient2
, false,
467 cacertreq
.filename
, clientcert2req
.filename
, false);
468 TLS_TEST_REG(goodclient3
, false,
469 cacertreq
.filename
, clientcert3req
.filename
, false);
470 TLS_TEST_REG(goodclient4
, false,
471 cacertreq
.filename
, clientcert4req
.filename
, false);
472 TLS_TEST_REG(goodclient5
, false,
473 cacertreq
.filename
, clientcert5req
.filename
, false);
474 TLS_TEST_REG(goodclient6
, false,
475 cacertreq
.filename
, clientcert6req
.filename
, false);
476 TLS_TEST_REG(goodclient7
, false,
477 cacertreq
.filename
, clientcert7req
.filename
, false);
481 /* usage:cert-sign:critical */
482 TLS_CERT_REQ(clientcert8req
, cacertreq
,
483 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
485 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
486 false, false, NULL
, NULL
,
488 /* purpose:client:critical */
489 TLS_CERT_REQ(clientcert9req
, cacertreq
,
490 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
493 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
495 /* usage: none:critical */
496 TLS_CERT_REQ(clientcert10req
, cacertreq
,
497 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
500 false, false, NULL
, NULL
,
503 TLS_TEST_REG(badclient1
, false,
504 cacertreq
.filename
, clientcert8req
.filename
, true);
505 TLS_TEST_REG(badclient2
, false,
506 cacertreq
.filename
, clientcert9req
.filename
, true);
507 TLS_TEST_REG(badclient3
, false,
508 cacertreq
.filename
, clientcert10req
.filename
, true);
514 TLS_ROOT_REQ(cacertexpreq
,
515 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
517 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
518 false, false, NULL
, NULL
,
520 TLS_CERT_REQ(servercertexpreq
, cacertexpreq
,
521 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
524 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
525 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
527 TLS_CERT_REQ(servercertexp1req
, cacertreq
,
528 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
531 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
532 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
534 TLS_CERT_REQ(clientcertexp1req
, cacertreq
,
535 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
538 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
539 true, true, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
542 TLS_TEST_REG(expired1
, true,
543 cacertexpreq
.filename
, servercertexpreq
.filename
, true);
544 TLS_TEST_REG(expired2
, true,
545 cacertreq
.filename
, servercertexp1req
.filename
, true);
546 TLS_TEST_REG(expired3
, false,
547 cacertreq
.filename
, clientcertexp1req
.filename
, true);
550 /* Not activated stuff */
552 TLS_ROOT_REQ(cacertnewreq
,
553 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
555 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
556 false, false, NULL
, NULL
,
558 TLS_CERT_REQ(servercertnewreq
, cacertnewreq
,
559 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
562 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
563 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
565 TLS_CERT_REQ(servercertnew1req
, cacertreq
,
566 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
569 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
570 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
572 TLS_CERT_REQ(clientcertnew1req
, cacertreq
,
573 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
576 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
577 true, true, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
580 TLS_TEST_REG(inactive1
, true,
581 cacertnewreq
.filename
, servercertnewreq
.filename
, true);
582 TLS_TEST_REG(inactive2
, true,
583 cacertreq
.filename
, servercertnew1req
.filename
, true);
584 TLS_TEST_REG(inactive3
, false,
585 cacertreq
.filename
, clientcertnew1req
.filename
, true);
587 TLS_ROOT_REQ(cacertrootreq
,
588 "UK", "qemu root", NULL
, NULL
, NULL
, NULL
,
590 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
591 false, false, NULL
, NULL
,
593 TLS_CERT_REQ(cacertlevel1areq
, cacertrootreq
,
594 "UK", "qemu level 1a", NULL
, NULL
, NULL
, NULL
,
596 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
597 false, false, NULL
, NULL
,
599 TLS_CERT_REQ(cacertlevel1breq
, cacertrootreq
,
600 "UK", "qemu level 1b", NULL
, NULL
, NULL
, NULL
,
602 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
603 false, false, NULL
, NULL
,
605 TLS_CERT_REQ(cacertlevel2areq
, cacertlevel1areq
,
606 "UK", "qemu level 2a", NULL
, NULL
, NULL
, NULL
,
608 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
609 false, false, NULL
, NULL
,
611 TLS_CERT_REQ(servercertlevel3areq
, cacertlevel2areq
,
612 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
615 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
616 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
618 TLS_CERT_REQ(clientcertlevel2breq
, cacertlevel1breq
,
619 "UK", "qemu client level 2b", NULL
, NULL
, NULL
, NULL
,
622 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
623 true, true, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
626 gnutls_x509_crt_t certchain
[] = {
628 cacertlevel1areq
.crt
,
629 cacertlevel1breq
.crt
,
630 cacertlevel2areq
.crt
,
633 test_tls_write_cert_chain(WORKDIR
"cacertchain-ctx.pem",
635 G_N_ELEMENTS(certchain
));
637 TLS_TEST_REG(chain1
, true,
638 WORKDIR
"cacertchain-ctx.pem",
639 servercertlevel3areq
.filename
, false);
640 TLS_TEST_REG(chain2
, false,
641 WORKDIR
"cacertchain-ctx.pem",
642 clientcertlevel2breq
.filename
, false);
644 /* Some missing certs - first two are fatal, the last
647 TLS_TEST_REG(missingca
, true,
648 "cacertdoesnotexist.pem",
649 servercert1req
.filename
, true);
650 TLS_TEST_REG(missingserver
, true,
652 "servercertdoesnotexist.pem", true);
653 TLS_TEST_REG(missingclient
, false,
655 "clientcertdoesnotexist.pem", false);
659 test_tls_discard_cert(&cacertreq
);
660 test_tls_discard_cert(&cacert1req
);
661 test_tls_discard_cert(&cacert2req
);
662 test_tls_discard_cert(&cacert3req
);
663 test_tls_discard_cert(&cacert4req
);
664 test_tls_discard_cert(&cacert5req
);
665 test_tls_discard_cert(&cacert6req
);
667 test_tls_discard_cert(&servercertreq
);
668 test_tls_discard_cert(&servercert1req
);
669 test_tls_discard_cert(&servercert2req
);
670 test_tls_discard_cert(&servercert3req
);
671 test_tls_discard_cert(&servercert4req
);
672 test_tls_discard_cert(&servercert5req
);
673 test_tls_discard_cert(&servercert6req
);
674 test_tls_discard_cert(&servercert7req
);
675 test_tls_discard_cert(&servercert8req
);
676 test_tls_discard_cert(&servercert9req
);
677 test_tls_discard_cert(&servercert10req
);
678 test_tls_discard_cert(&servercert11req
);
679 test_tls_discard_cert(&servercert12req
);
680 test_tls_discard_cert(&servercert13req
);
681 test_tls_discard_cert(&servercert14req
);
682 test_tls_discard_cert(&servercert15req
);
683 test_tls_discard_cert(&servercert16req
);
685 test_tls_discard_cert(&clientcertreq
);
686 test_tls_discard_cert(&clientcert1req
);
687 test_tls_discard_cert(&clientcert2req
);
688 test_tls_discard_cert(&clientcert3req
);
689 test_tls_discard_cert(&clientcert4req
);
690 test_tls_discard_cert(&clientcert5req
);
691 test_tls_discard_cert(&clientcert6req
);
692 test_tls_discard_cert(&clientcert7req
);
693 test_tls_discard_cert(&clientcert8req
);
694 test_tls_discard_cert(&clientcert9req
);
695 test_tls_discard_cert(&clientcert10req
);
697 test_tls_discard_cert(&cacertexpreq
);
698 test_tls_discard_cert(&servercertexpreq
);
699 test_tls_discard_cert(&servercertexp1req
);
700 test_tls_discard_cert(&clientcertexp1req
);
702 test_tls_discard_cert(&cacertnewreq
);
703 test_tls_discard_cert(&servercertnewreq
);
704 test_tls_discard_cert(&servercertnew1req
);
705 test_tls_discard_cert(&clientcertnew1req
);
707 test_tls_discard_cert(&cacertrootreq
);
708 test_tls_discard_cert(&cacertlevel1areq
);
709 test_tls_discard_cert(&cacertlevel1breq
);
710 test_tls_discard_cert(&cacertlevel2areq
);
711 test_tls_discard_cert(&servercertlevel3areq
);
712 test_tls_discard_cert(&clientcertlevel2breq
);
713 unlink(WORKDIR
"cacertchain-ctx.pem");
715 test_tls_cleanup(KEYFILE
);
718 return ret
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;
721 #else /* ! QCRYPTO_HAVE_TLS_TEST_SUPPORT */
729 #endif /* ! QCRYPTO_HAVE_TLS_TEST_SUPPORT */