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"
25 #include "qapi/error.h"
27 #ifdef QCRYPTO_HAVE_TLS_TEST_SUPPORT
29 #define WORKDIR "tests/test-crypto-tlscredsx509-work/"
30 #define KEYFILE WORKDIR "key-ctx.pem"
32 struct QCryptoTLSCredsTestData
{
40 static QCryptoTLSCreds
*test_tls_creds_create(QCryptoTLSCredsEndpoint endpoint
,
44 Object
*parent
= object_get_objects_root();
45 Object
*creds
= object_new_with_props(
46 TYPE_QCRYPTO_TLS_CREDS_X509
,
50 "endpoint", (endpoint
== QCRYPTO_TLS_CREDS_ENDPOINT_SERVER
?
54 "sanity-check", "yes",
60 return QCRYPTO_TLS_CREDS(creds
);
64 * This tests sanity checking of our own certificates
66 * The code being tested is used when TLS creds are created,
67 * and aim to ensure QMEU has been configured with sane
68 * certificates. This allows us to give much much much
69 * clearer error messages to the admin when they misconfigure
72 static void test_tls_creds(const void *opaque
)
74 struct QCryptoTLSCredsTestData
*data
=
75 (struct QCryptoTLSCredsTestData
*)opaque
;
76 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
),
115 data
->expectFail
? NULL
: &error_abort
);
117 if (data
->expectFail
) {
118 g_assert(creds
== NULL
);
120 g_assert(creds
!= NULL
);
123 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT
);
124 if (data
->isServer
) {
125 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT
);
126 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_KEY
);
128 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CLIENT_CERT
);
129 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CLIENT_KEY
);
133 object_unparent(OBJECT(creds
));
137 int main(int argc
, char **argv
)
141 module_call_init(MODULE_INIT_QOM
);
142 g_test_init(&argc
, &argv
, NULL
);
143 setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
145 mkdir(WORKDIR
, 0700);
147 test_tls_init(KEYFILE
);
149 # define TLS_TEST_REG(name, isServer, caCrt, crt, expectFail) \
150 struct QCryptoTLSCredsTestData name = { \
151 isServer, caCrt, crt, expectFail \
153 g_test_add_data_func("/qcrypto/tlscredsx509/" # name, \
154 &name, test_tls_creds); \
156 /* A perfect CA, perfect client & perfect server */
158 /* Basic:CA:critical */
159 TLS_ROOT_REQ(cacertreq
,
160 "UK", "qemu CA", NULL
, NULL
, NULL
, NULL
,
162 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
163 false, false, NULL
, NULL
,
166 TLS_CERT_REQ(servercertreq
, cacertreq
,
167 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
170 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
171 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
173 TLS_CERT_REQ(clientcertreq
, cacertreq
,
174 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
177 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
178 true, true, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
181 TLS_TEST_REG(perfectserver
, true,
182 cacertreq
.filename
, servercertreq
.filename
, false);
183 TLS_TEST_REG(perfectclient
, false,
184 cacertreq
.filename
, clientcertreq
.filename
, false);
187 /* Some other CAs which are good */
189 /* Basic:CA:critical */
190 TLS_ROOT_REQ(cacert1req
,
191 "UK", "qemu CA 1", NULL
, NULL
, NULL
, NULL
,
194 false, false, NULL
, NULL
,
196 TLS_CERT_REQ(servercert1req
, cacert1req
,
197 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
200 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
201 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
204 /* Basic:CA:not-critical */
205 TLS_ROOT_REQ(cacert2req
,
206 "UK", "qemu CA 2", NULL
, NULL
, NULL
, NULL
,
209 false, false, NULL
, NULL
,
211 TLS_CERT_REQ(servercert2req
, cacert2req
,
212 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
215 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
216 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
219 /* Key usage:cert-sign:critical */
220 TLS_ROOT_REQ(cacert3req
,
221 "UK", "qemu CA 3", NULL
, NULL
, NULL
, NULL
,
223 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
224 false, false, NULL
, NULL
,
226 TLS_CERT_REQ(servercert3req
, cacert3req
,
227 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
230 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
231 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
234 TLS_TEST_REG(goodca1
, true,
235 cacert1req
.filename
, servercert1req
.filename
, false);
236 TLS_TEST_REG(goodca2
, true,
237 cacert2req
.filename
, servercert2req
.filename
, false);
238 TLS_TEST_REG(goodca3
, true,
239 cacert3req
.filename
, servercert3req
.filename
, false);
241 /* Now some bad certs */
243 /* Key usage:dig-sig:not-critical */
244 TLS_ROOT_REQ(cacert4req
,
245 "UK", "qemu CA 4", NULL
, NULL
, NULL
, NULL
,
247 true, false, GNUTLS_KEY_DIGITAL_SIGNATURE
,
248 false, false, NULL
, NULL
,
250 TLS_CERT_REQ(servercert4req
, cacert4req
,
251 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
254 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
255 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
258 TLS_ROOT_REQ(cacert5req
,
259 "UK", "qemu CA 5", NULL
, NULL
, NULL
, NULL
,
262 false, false, NULL
, NULL
,
264 TLS_CERT_REQ(servercert5req
, cacert5req
,
265 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
268 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
269 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
271 /* Key usage:dig-sig:critical */
272 TLS_ROOT_REQ(cacert6req
,
273 "UK", "qemu CA 6", NULL
, NULL
, NULL
, NULL
,
275 true, true, GNUTLS_KEY_DIGITAL_SIGNATURE
,
276 false, false, NULL
, NULL
,
278 TLS_CERT_REQ(servercert6req
, cacert6req
,
279 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
282 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
283 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
286 TLS_TEST_REG(badca1
, true, cacert4req
.filename
, servercert4req
.filename
,
288 TLS_TEST_REG(badca2
, true,
289 cacert5req
.filename
, servercert5req
.filename
, true);
290 TLS_TEST_REG(badca3
, true,
291 cacert6req
.filename
, servercert6req
.filename
, true);
294 /* Various good servers */
295 /* no usage or purpose */
296 TLS_CERT_REQ(servercert7req
, cacertreq
,
297 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
300 false, false, NULL
, NULL
,
302 /* usage:cert-sign+dig-sig+encipher:critical */
303 TLS_CERT_REQ(servercert8req
, cacertreq
,
304 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
307 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
|
308 GNUTLS_KEY_KEY_CERT_SIGN
,
309 false, false, NULL
, NULL
,
311 /* usage:cert-sign:not-critical */
312 TLS_CERT_REQ(servercert9req
, cacertreq
,
313 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
315 true, false, GNUTLS_KEY_KEY_CERT_SIGN
,
316 false, false, NULL
, NULL
,
318 /* purpose:server:critical */
319 TLS_CERT_REQ(servercert10req
, cacertreq
,
320 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
323 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
325 /* purpose:server:not-critical */
326 TLS_CERT_REQ(servercert11req
, cacertreq
,
327 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
330 true, false, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
332 /* purpose:client+server:critical */
333 TLS_CERT_REQ(servercert12req
, cacertreq
,
334 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
338 GNUTLS_KP_TLS_WWW_CLIENT
, GNUTLS_KP_TLS_WWW_SERVER
,
340 /* purpose:client+server:not-critical */
341 TLS_CERT_REQ(servercert13req
, cacertreq
,
342 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
346 GNUTLS_KP_TLS_WWW_CLIENT
, GNUTLS_KP_TLS_WWW_SERVER
,
349 TLS_TEST_REG(goodserver1
, true,
350 cacertreq
.filename
, servercert7req
.filename
, false);
351 TLS_TEST_REG(goodserver2
, true,
352 cacertreq
.filename
, servercert8req
.filename
, false);
353 TLS_TEST_REG(goodserver3
, true,
354 cacertreq
.filename
, servercert9req
.filename
, false);
355 TLS_TEST_REG(goodserver4
, true,
356 cacertreq
.filename
, servercert10req
.filename
, false);
357 TLS_TEST_REG(goodserver5
, true,
358 cacertreq
.filename
, servercert11req
.filename
, false);
359 TLS_TEST_REG(goodserver6
, true,
360 cacertreq
.filename
, servercert12req
.filename
, false);
361 TLS_TEST_REG(goodserver7
, true,
362 cacertreq
.filename
, servercert13req
.filename
, false);
366 /* usage:cert-sign:critical */
367 TLS_CERT_REQ(servercert14req
, cacertreq
,
368 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
370 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
371 false, false, NULL
, NULL
,
373 /* purpose:client:critical */
374 TLS_CERT_REQ(servercert15req
, cacertreq
,
375 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
378 true, true, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
380 /* usage: none:critical */
381 TLS_CERT_REQ(servercert16req
, cacertreq
,
382 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
385 false, false, NULL
, NULL
,
388 TLS_TEST_REG(badserver1
, true,
389 cacertreq
.filename
, servercert14req
.filename
, true);
390 TLS_TEST_REG(badserver2
, true,
391 cacertreq
.filename
, servercert15req
.filename
, true);
392 TLS_TEST_REG(badserver3
, true,
393 cacertreq
.filename
, servercert16req
.filename
, true);
397 /* Various good clients */
398 /* no usage or purpose */
399 TLS_CERT_REQ(clientcert1req
, cacertreq
,
400 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
403 false, false, NULL
, NULL
,
405 /* usage:cert-sign+dig-sig+encipher:critical */
406 TLS_CERT_REQ(clientcert2req
, cacertreq
,
407 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
410 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
|
411 GNUTLS_KEY_KEY_CERT_SIGN
,
412 false, false, NULL
, NULL
,
414 /* usage:cert-sign:not-critical */
415 TLS_CERT_REQ(clientcert3req
, cacertreq
,
416 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
418 true, false, GNUTLS_KEY_KEY_CERT_SIGN
,
419 false, false, NULL
, NULL
,
421 /* purpose:client:critical */
422 TLS_CERT_REQ(clientcert4req
, cacertreq
,
423 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
426 true, true, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
428 /* purpose:client:not-critical */
429 TLS_CERT_REQ(clientcert5req
, cacertreq
,
430 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
433 true, false, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
435 /* purpose:client+client:critical */
436 TLS_CERT_REQ(clientcert6req
, cacertreq
,
437 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
441 GNUTLS_KP_TLS_WWW_CLIENT
, GNUTLS_KP_TLS_WWW_SERVER
,
443 /* purpose:client+client:not-critical */
444 TLS_CERT_REQ(clientcert7req
, cacertreq
,
445 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
449 GNUTLS_KP_TLS_WWW_CLIENT
, GNUTLS_KP_TLS_WWW_SERVER
,
452 TLS_TEST_REG(goodclient1
, false,
453 cacertreq
.filename
, clientcert1req
.filename
, false);
454 TLS_TEST_REG(goodclient2
, false,
455 cacertreq
.filename
, clientcert2req
.filename
, false);
456 TLS_TEST_REG(goodclient3
, false,
457 cacertreq
.filename
, clientcert3req
.filename
, false);
458 TLS_TEST_REG(goodclient4
, false,
459 cacertreq
.filename
, clientcert4req
.filename
, false);
460 TLS_TEST_REG(goodclient5
, false,
461 cacertreq
.filename
, clientcert5req
.filename
, false);
462 TLS_TEST_REG(goodclient6
, false,
463 cacertreq
.filename
, clientcert6req
.filename
, false);
464 TLS_TEST_REG(goodclient7
, false,
465 cacertreq
.filename
, clientcert7req
.filename
, false);
469 /* usage:cert-sign:critical */
470 TLS_CERT_REQ(clientcert8req
, cacertreq
,
471 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
473 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
474 false, false, NULL
, NULL
,
476 /* purpose:client:critical */
477 TLS_CERT_REQ(clientcert9req
, cacertreq
,
478 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
481 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
483 /* usage: none:critical */
484 TLS_CERT_REQ(clientcert10req
, cacertreq
,
485 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
488 false, false, NULL
, NULL
,
491 TLS_TEST_REG(badclient1
, false,
492 cacertreq
.filename
, clientcert8req
.filename
, true);
493 TLS_TEST_REG(badclient2
, false,
494 cacertreq
.filename
, clientcert9req
.filename
, true);
495 TLS_TEST_REG(badclient3
, false,
496 cacertreq
.filename
, clientcert10req
.filename
, true);
502 TLS_ROOT_REQ(cacertexpreq
,
503 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
505 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
506 false, false, NULL
, NULL
,
508 TLS_CERT_REQ(servercertexpreq
, cacertexpreq
,
509 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
512 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
513 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
515 TLS_CERT_REQ(servercertexp1req
, cacertreq
,
516 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
519 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
520 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
522 TLS_CERT_REQ(clientcertexp1req
, cacertreq
,
523 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
526 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
527 true, true, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
530 TLS_TEST_REG(expired1
, true,
531 cacertexpreq
.filename
, servercertexpreq
.filename
, true);
532 TLS_TEST_REG(expired2
, true,
533 cacertreq
.filename
, servercertexp1req
.filename
, true);
534 TLS_TEST_REG(expired3
, false,
535 cacertreq
.filename
, clientcertexp1req
.filename
, true);
538 /* Not activated stuff */
540 TLS_ROOT_REQ(cacertnewreq
,
541 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
543 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
544 false, false, NULL
, NULL
,
546 TLS_CERT_REQ(servercertnewreq
, cacertnewreq
,
547 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
550 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
551 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
553 TLS_CERT_REQ(servercertnew1req
, cacertreq
,
554 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
557 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
558 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
560 TLS_CERT_REQ(clientcertnew1req
, cacertreq
,
561 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
564 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
565 true, true, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
568 TLS_TEST_REG(inactive1
, true,
569 cacertnewreq
.filename
, servercertnewreq
.filename
, true);
570 TLS_TEST_REG(inactive2
, true,
571 cacertreq
.filename
, servercertnew1req
.filename
, true);
572 TLS_TEST_REG(inactive3
, false,
573 cacertreq
.filename
, clientcertnew1req
.filename
, true);
575 TLS_ROOT_REQ(cacertrootreq
,
576 "UK", "qemu root", NULL
, NULL
, NULL
, NULL
,
578 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
579 false, false, NULL
, NULL
,
581 TLS_CERT_REQ(cacertlevel1areq
, cacertrootreq
,
582 "UK", "qemu level 1a", NULL
, NULL
, NULL
, NULL
,
584 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
585 false, false, NULL
, NULL
,
587 TLS_CERT_REQ(cacertlevel1breq
, cacertrootreq
,
588 "UK", "qemu level 1b", NULL
, NULL
, NULL
, NULL
,
590 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
591 false, false, NULL
, NULL
,
593 TLS_CERT_REQ(cacertlevel2areq
, cacertlevel1areq
,
594 "UK", "qemu level 2a", NULL
, NULL
, NULL
, NULL
,
596 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
597 false, false, NULL
, NULL
,
599 TLS_CERT_REQ(servercertlevel3areq
, cacertlevel2areq
,
600 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
603 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
604 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
606 TLS_CERT_REQ(clientcertlevel2breq
, cacertlevel1breq
,
607 "UK", "qemu client level 2b", NULL
, NULL
, NULL
, NULL
,
610 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
611 true, true, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
614 gnutls_x509_crt_t certchain
[] = {
616 cacertlevel1areq
.crt
,
617 cacertlevel1breq
.crt
,
618 cacertlevel2areq
.crt
,
621 test_tls_write_cert_chain(WORKDIR
"cacertchain-ctx.pem",
623 G_N_ELEMENTS(certchain
));
625 TLS_TEST_REG(chain1
, true,
626 WORKDIR
"cacertchain-ctx.pem",
627 servercertlevel3areq
.filename
, false);
628 TLS_TEST_REG(chain2
, false,
629 WORKDIR
"cacertchain-ctx.pem",
630 clientcertlevel2breq
.filename
, false);
632 /* Some missing certs - first two are fatal, the last
635 TLS_TEST_REG(missingca
, true,
636 "cacertdoesnotexist.pem",
637 servercert1req
.filename
, true);
638 TLS_TEST_REG(missingserver
, true,
640 "servercertdoesnotexist.pem", true);
641 TLS_TEST_REG(missingclient
, false,
643 "clientcertdoesnotexist.pem", false);
647 test_tls_discard_cert(&cacertreq
);
648 test_tls_discard_cert(&cacert1req
);
649 test_tls_discard_cert(&cacert2req
);
650 test_tls_discard_cert(&cacert3req
);
651 test_tls_discard_cert(&cacert4req
);
652 test_tls_discard_cert(&cacert5req
);
653 test_tls_discard_cert(&cacert6req
);
655 test_tls_discard_cert(&servercertreq
);
656 test_tls_discard_cert(&servercert1req
);
657 test_tls_discard_cert(&servercert2req
);
658 test_tls_discard_cert(&servercert3req
);
659 test_tls_discard_cert(&servercert4req
);
660 test_tls_discard_cert(&servercert5req
);
661 test_tls_discard_cert(&servercert6req
);
662 test_tls_discard_cert(&servercert7req
);
663 test_tls_discard_cert(&servercert8req
);
664 test_tls_discard_cert(&servercert9req
);
665 test_tls_discard_cert(&servercert10req
);
666 test_tls_discard_cert(&servercert11req
);
667 test_tls_discard_cert(&servercert12req
);
668 test_tls_discard_cert(&servercert13req
);
669 test_tls_discard_cert(&servercert14req
);
670 test_tls_discard_cert(&servercert15req
);
671 test_tls_discard_cert(&servercert16req
);
673 test_tls_discard_cert(&clientcertreq
);
674 test_tls_discard_cert(&clientcert1req
);
675 test_tls_discard_cert(&clientcert2req
);
676 test_tls_discard_cert(&clientcert3req
);
677 test_tls_discard_cert(&clientcert4req
);
678 test_tls_discard_cert(&clientcert5req
);
679 test_tls_discard_cert(&clientcert6req
);
680 test_tls_discard_cert(&clientcert7req
);
681 test_tls_discard_cert(&clientcert8req
);
682 test_tls_discard_cert(&clientcert9req
);
683 test_tls_discard_cert(&clientcert10req
);
685 test_tls_discard_cert(&cacertexpreq
);
686 test_tls_discard_cert(&servercertexpreq
);
687 test_tls_discard_cert(&servercertexp1req
);
688 test_tls_discard_cert(&clientcertexp1req
);
690 test_tls_discard_cert(&cacertnewreq
);
691 test_tls_discard_cert(&servercertnewreq
);
692 test_tls_discard_cert(&servercertnew1req
);
693 test_tls_discard_cert(&clientcertnew1req
);
695 test_tls_discard_cert(&cacertrootreq
);
696 test_tls_discard_cert(&cacertlevel1areq
);
697 test_tls_discard_cert(&cacertlevel1breq
);
698 test_tls_discard_cert(&cacertlevel2areq
);
699 test_tls_discard_cert(&servercertlevel3areq
);
700 test_tls_discard_cert(&clientcertlevel2breq
);
701 unlink(WORKDIR
"cacertchain-ctx.pem");
703 test_tls_cleanup(KEYFILE
);
706 return ret
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;
709 #else /* ! QCRYPTO_HAVE_TLS_TEST_SUPPORT */
717 #endif /* ! QCRYPTO_HAVE_TLS_TEST_SUPPORT */