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>
24 #include "config-host.h"
25 #include "crypto-tls-x509-helpers.h"
26 #include "crypto/tlscredsx509.h"
28 #ifdef QCRYPTO_HAVE_TLS_TEST_SUPPORT
30 #define WORKDIR "tests/test-crypto-tlscredsx509-work/"
31 #define KEYFILE WORKDIR "key-ctx.pem"
33 struct QCryptoTLSCredsTestData
{
41 static QCryptoTLSCreds
*test_tls_creds_create(QCryptoTLSCredsEndpoint endpoint
,
45 Object
*parent
= object_get_objects_root();
46 Object
*creds
= object_new_with_props(
47 TYPE_QCRYPTO_TLS_CREDS_X509
,
51 "endpoint", (endpoint
== QCRYPTO_TLS_CREDS_ENDPOINT_SERVER
?
55 "sanity-check", "yes",
61 return QCRYPTO_TLS_CREDS(creds
);
65 * This tests sanity checking of our own certificates
67 * The code being tested is used when TLS creds are created,
68 * and aim to ensure QMEU has been configured with sane
69 * certificates. This allows us to give much much much
70 * clearer error messages to the admin when they misconfigure
73 static void test_tls_creds(const void *opaque
)
75 struct QCryptoTLSCredsTestData
*data
=
76 (struct QCryptoTLSCredsTestData
*)opaque
;
77 QCryptoTLSCreds
*creds
;
80 #define CERT_DIR "tests/test-crypto-tlscredsx509-certs/"
81 mkdir(CERT_DIR
, 0700);
83 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT
);
85 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT
);
86 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_KEY
);
88 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CLIENT_CERT
);
89 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CLIENT_KEY
);
92 if (access(data
->cacrt
, R_OK
) == 0) {
93 g_assert(link(data
->cacrt
,
94 CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT
) == 0);
97 if (access(data
->crt
, R_OK
) == 0) {
98 g_assert(link(data
->crt
,
99 CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT
) == 0);
101 g_assert(link(KEYFILE
,
102 CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_KEY
) == 0);
104 if (access(data
->crt
, R_OK
) == 0) {
105 g_assert(link(data
->crt
,
106 CERT_DIR QCRYPTO_TLS_CREDS_X509_CLIENT_CERT
) == 0);
108 g_assert(link(KEYFILE
,
109 CERT_DIR QCRYPTO_TLS_CREDS_X509_CLIENT_KEY
) == 0);
112 creds
= test_tls_creds_create(
114 QCRYPTO_TLS_CREDS_ENDPOINT_SERVER
:
115 QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT
),
119 if (data
->expectFail
) {
121 g_assert(creds
== NULL
);
124 g_printerr("Failed to generate creds: %s\n",
125 error_get_pretty(err
));
128 g_assert(creds
!= NULL
);
131 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT
);
132 if (data
->isServer
) {
133 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT
);
134 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_KEY
);
136 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CLIENT_CERT
);
137 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CLIENT_KEY
);
141 object_unparent(OBJECT(creds
));
145 int main(int argc
, char **argv
)
149 module_call_init(MODULE_INIT_QOM
);
150 g_test_init(&argc
, &argv
, NULL
);
151 setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
153 mkdir(WORKDIR
, 0700);
155 test_tls_init(KEYFILE
);
157 # define TLS_TEST_REG(name, isServer, caCrt, crt, expectFail) \
158 struct QCryptoTLSCredsTestData name = { \
159 isServer, caCrt, crt, expectFail \
161 g_test_add_data_func("/qcrypto/tlscredsx509/" # name, \
162 &name, test_tls_creds); \
164 /* A perfect CA, perfect client & perfect server */
166 /* Basic:CA:critical */
167 TLS_ROOT_REQ(cacertreq
,
168 "UK", "qemu CA", NULL
, NULL
, NULL
, NULL
,
170 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
171 false, false, NULL
, NULL
,
174 TLS_CERT_REQ(servercertreq
, cacertreq
,
175 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
178 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
179 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
181 TLS_CERT_REQ(clientcertreq
, cacertreq
,
182 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
185 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
186 true, true, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
189 TLS_TEST_REG(perfectserver
, true,
190 cacertreq
.filename
, servercertreq
.filename
, false);
191 TLS_TEST_REG(perfectclient
, false,
192 cacertreq
.filename
, clientcertreq
.filename
, false);
195 /* Some other CAs which are good */
197 /* Basic:CA:critical */
198 TLS_ROOT_REQ(cacert1req
,
199 "UK", "qemu CA 1", NULL
, NULL
, NULL
, NULL
,
202 false, false, NULL
, NULL
,
204 TLS_CERT_REQ(servercert1req
, cacert1req
,
205 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
208 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
209 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
212 /* Basic:CA:not-critical */
213 TLS_ROOT_REQ(cacert2req
,
214 "UK", "qemu CA 2", NULL
, NULL
, NULL
, NULL
,
217 false, false, NULL
, NULL
,
219 TLS_CERT_REQ(servercert2req
, cacert2req
,
220 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
223 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
224 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
227 /* Key usage:cert-sign:critical */
228 TLS_ROOT_REQ(cacert3req
,
229 "UK", "qemu CA 3", NULL
, NULL
, NULL
, NULL
,
231 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
232 false, false, NULL
, NULL
,
234 TLS_CERT_REQ(servercert3req
, cacert3req
,
235 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
238 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
239 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
242 TLS_TEST_REG(goodca1
, true,
243 cacert1req
.filename
, servercert1req
.filename
, false);
244 TLS_TEST_REG(goodca2
, true,
245 cacert2req
.filename
, servercert2req
.filename
, false);
246 TLS_TEST_REG(goodca3
, true,
247 cacert3req
.filename
, servercert3req
.filename
, false);
249 /* Now some bad certs */
251 /* Key usage:dig-sig:not-critical */
252 TLS_ROOT_REQ(cacert4req
,
253 "UK", "qemu CA 4", NULL
, NULL
, NULL
, NULL
,
255 true, false, GNUTLS_KEY_DIGITAL_SIGNATURE
,
256 false, false, NULL
, NULL
,
258 TLS_CERT_REQ(servercert4req
, cacert4req
,
259 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
262 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
263 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
266 TLS_ROOT_REQ(cacert5req
,
267 "UK", "qemu CA 5", NULL
, NULL
, NULL
, NULL
,
270 false, false, NULL
, NULL
,
272 TLS_CERT_REQ(servercert5req
, cacert5req
,
273 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
276 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
277 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
279 /* Key usage:dig-sig:critical */
280 TLS_ROOT_REQ(cacert6req
,
281 "UK", "qemu CA 6", NULL
, NULL
, NULL
, NULL
,
283 true, true, GNUTLS_KEY_DIGITAL_SIGNATURE
,
284 false, false, NULL
, NULL
,
286 TLS_CERT_REQ(servercert6req
, cacert6req
,
287 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
290 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
291 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
294 /* Technically a CA cert with basic constraints
295 * key purpose == key signing + non-critical should
296 * be rejected. GNUTLS < 3.1 does not reject it and
297 * we don't anticipate them changing this behaviour
299 TLS_TEST_REG(badca1
, true, cacert4req
.filename
, servercert4req
.filename
,
300 (GNUTLS_VERSION_MAJOR
== 3 && GNUTLS_VERSION_MINOR
>= 1) ||
301 GNUTLS_VERSION_MAJOR
> 3);
302 TLS_TEST_REG(badca2
, true,
303 cacert5req
.filename
, servercert5req
.filename
, true);
304 TLS_TEST_REG(badca3
, true,
305 cacert6req
.filename
, servercert6req
.filename
, true);
308 /* Various good servers */
309 /* no usage or purpose */
310 TLS_CERT_REQ(servercert7req
, cacertreq
,
311 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
314 false, false, NULL
, NULL
,
316 /* usage:cert-sign+dig-sig+encipher:critical */
317 TLS_CERT_REQ(servercert8req
, cacertreq
,
318 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
321 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
|
322 GNUTLS_KEY_KEY_CERT_SIGN
,
323 false, false, NULL
, NULL
,
325 /* usage:cert-sign:not-critical */
326 TLS_CERT_REQ(servercert9req
, cacertreq
,
327 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
329 true, false, GNUTLS_KEY_KEY_CERT_SIGN
,
330 false, false, NULL
, NULL
,
332 /* purpose:server:critical */
333 TLS_CERT_REQ(servercert10req
, cacertreq
,
334 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
337 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
339 /* purpose:server:not-critical */
340 TLS_CERT_REQ(servercert11req
, cacertreq
,
341 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
344 true, false, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
346 /* purpose:client+server:critical */
347 TLS_CERT_REQ(servercert12req
, cacertreq
,
348 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
352 GNUTLS_KP_TLS_WWW_CLIENT
, GNUTLS_KP_TLS_WWW_SERVER
,
354 /* purpose:client+server:not-critical */
355 TLS_CERT_REQ(servercert13req
, cacertreq
,
356 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
360 GNUTLS_KP_TLS_WWW_CLIENT
, GNUTLS_KP_TLS_WWW_SERVER
,
363 TLS_TEST_REG(goodserver1
, true,
364 cacertreq
.filename
, servercert7req
.filename
, false);
365 TLS_TEST_REG(goodserver2
, true,
366 cacertreq
.filename
, servercert8req
.filename
, false);
367 TLS_TEST_REG(goodserver3
, true,
368 cacertreq
.filename
, servercert9req
.filename
, false);
369 TLS_TEST_REG(goodserver4
, true,
370 cacertreq
.filename
, servercert10req
.filename
, false);
371 TLS_TEST_REG(goodserver5
, true,
372 cacertreq
.filename
, servercert11req
.filename
, false);
373 TLS_TEST_REG(goodserver6
, true,
374 cacertreq
.filename
, servercert12req
.filename
, false);
375 TLS_TEST_REG(goodserver7
, true,
376 cacertreq
.filename
, servercert13req
.filename
, false);
380 /* usage:cert-sign:critical */
381 TLS_CERT_REQ(servercert14req
, cacertreq
,
382 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
384 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
385 false, false, NULL
, NULL
,
387 /* purpose:client:critical */
388 TLS_CERT_REQ(servercert15req
, cacertreq
,
389 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
392 true, true, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
394 /* usage: none:critical */
395 TLS_CERT_REQ(servercert16req
, cacertreq
,
396 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
399 false, false, NULL
, NULL
,
402 TLS_TEST_REG(badserver1
, true,
403 cacertreq
.filename
, servercert14req
.filename
, true);
404 TLS_TEST_REG(badserver2
, true,
405 cacertreq
.filename
, servercert15req
.filename
, true);
406 TLS_TEST_REG(badserver3
, true,
407 cacertreq
.filename
, servercert16req
.filename
, true);
411 /* Various good clients */
412 /* no usage or purpose */
413 TLS_CERT_REQ(clientcert1req
, cacertreq
,
414 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
417 false, false, NULL
, NULL
,
419 /* usage:cert-sign+dig-sig+encipher:critical */
420 TLS_CERT_REQ(clientcert2req
, cacertreq
,
421 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
424 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
|
425 GNUTLS_KEY_KEY_CERT_SIGN
,
426 false, false, NULL
, NULL
,
428 /* usage:cert-sign:not-critical */
429 TLS_CERT_REQ(clientcert3req
, cacertreq
,
430 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
432 true, false, GNUTLS_KEY_KEY_CERT_SIGN
,
433 false, false, NULL
, NULL
,
435 /* purpose:client:critical */
436 TLS_CERT_REQ(clientcert4req
, cacertreq
,
437 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
440 true, true, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
442 /* purpose:client:not-critical */
443 TLS_CERT_REQ(clientcert5req
, cacertreq
,
444 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
447 true, false, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
449 /* purpose:client+client:critical */
450 TLS_CERT_REQ(clientcert6req
, cacertreq
,
451 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
455 GNUTLS_KP_TLS_WWW_CLIENT
, GNUTLS_KP_TLS_WWW_SERVER
,
457 /* purpose:client+client:not-critical */
458 TLS_CERT_REQ(clientcert7req
, cacertreq
,
459 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
463 GNUTLS_KP_TLS_WWW_CLIENT
, GNUTLS_KP_TLS_WWW_SERVER
,
466 TLS_TEST_REG(goodclient1
, false,
467 cacertreq
.filename
, clientcert1req
.filename
, false);
468 TLS_TEST_REG(goodclient2
, false,
469 cacertreq
.filename
, clientcert2req
.filename
, false);
470 TLS_TEST_REG(goodclient3
, false,
471 cacertreq
.filename
, clientcert3req
.filename
, false);
472 TLS_TEST_REG(goodclient4
, false,
473 cacertreq
.filename
, clientcert4req
.filename
, false);
474 TLS_TEST_REG(goodclient5
, false,
475 cacertreq
.filename
, clientcert5req
.filename
, false);
476 TLS_TEST_REG(goodclient6
, false,
477 cacertreq
.filename
, clientcert6req
.filename
, false);
478 TLS_TEST_REG(goodclient7
, false,
479 cacertreq
.filename
, clientcert7req
.filename
, false);
483 /* usage:cert-sign:critical */
484 TLS_CERT_REQ(clientcert8req
, cacertreq
,
485 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
487 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
488 false, false, NULL
, NULL
,
490 /* purpose:client:critical */
491 TLS_CERT_REQ(clientcert9req
, cacertreq
,
492 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
495 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
497 /* usage: none:critical */
498 TLS_CERT_REQ(clientcert10req
, cacertreq
,
499 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
502 false, false, NULL
, NULL
,
505 TLS_TEST_REG(badclient1
, false,
506 cacertreq
.filename
, clientcert8req
.filename
, true);
507 TLS_TEST_REG(badclient2
, false,
508 cacertreq
.filename
, clientcert9req
.filename
, true);
509 TLS_TEST_REG(badclient3
, false,
510 cacertreq
.filename
, clientcert10req
.filename
, true);
516 TLS_ROOT_REQ(cacertexpreq
,
517 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
519 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
520 false, false, NULL
, NULL
,
522 TLS_CERT_REQ(servercertexpreq
, cacertexpreq
,
523 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
526 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
527 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
529 TLS_CERT_REQ(servercertexp1req
, cacertreq
,
530 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
533 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
534 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
536 TLS_CERT_REQ(clientcertexp1req
, cacertreq
,
537 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
540 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
541 true, true, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
544 TLS_TEST_REG(expired1
, true,
545 cacertexpreq
.filename
, servercertexpreq
.filename
, true);
546 TLS_TEST_REG(expired2
, true,
547 cacertreq
.filename
, servercertexp1req
.filename
, true);
548 TLS_TEST_REG(expired3
, false,
549 cacertreq
.filename
, clientcertexp1req
.filename
, true);
552 /* Not activated stuff */
554 TLS_ROOT_REQ(cacertnewreq
,
555 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
557 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
558 false, false, NULL
, NULL
,
560 TLS_CERT_REQ(servercertnewreq
, cacertnewreq
,
561 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
564 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
565 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
567 TLS_CERT_REQ(servercertnew1req
, cacertreq
,
568 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
571 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
572 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
574 TLS_CERT_REQ(clientcertnew1req
, cacertreq
,
575 "UK", "qemu", NULL
, NULL
, NULL
, NULL
,
578 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
579 true, true, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
582 TLS_TEST_REG(inactive1
, true,
583 cacertnewreq
.filename
, servercertnewreq
.filename
, true);
584 TLS_TEST_REG(inactive2
, true,
585 cacertreq
.filename
, servercertnew1req
.filename
, true);
586 TLS_TEST_REG(inactive3
, false,
587 cacertreq
.filename
, clientcertnew1req
.filename
, true);
589 TLS_ROOT_REQ(cacertrootreq
,
590 "UK", "qemu root", NULL
, NULL
, NULL
, NULL
,
592 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
593 false, false, NULL
, NULL
,
595 TLS_CERT_REQ(cacertlevel1areq
, cacertrootreq
,
596 "UK", "qemu level 1a", NULL
, NULL
, NULL
, NULL
,
598 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
599 false, false, NULL
, NULL
,
601 TLS_CERT_REQ(cacertlevel1breq
, cacertrootreq
,
602 "UK", "qemu level 1b", NULL
, NULL
, NULL
, NULL
,
604 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
605 false, false, NULL
, NULL
,
607 TLS_CERT_REQ(cacertlevel2areq
, cacertlevel1areq
,
608 "UK", "qemu level 2a", NULL
, NULL
, NULL
, NULL
,
610 true, true, GNUTLS_KEY_KEY_CERT_SIGN
,
611 false, false, NULL
, NULL
,
613 TLS_CERT_REQ(servercertlevel3areq
, cacertlevel2areq
,
614 "UK", "qemu.org", NULL
, NULL
, NULL
, NULL
,
617 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
618 true, true, GNUTLS_KP_TLS_WWW_SERVER
, NULL
,
620 TLS_CERT_REQ(clientcertlevel2breq
, cacertlevel1breq
,
621 "UK", "qemu client level 2b", NULL
, NULL
, NULL
, NULL
,
624 GNUTLS_KEY_DIGITAL_SIGNATURE
| GNUTLS_KEY_KEY_ENCIPHERMENT
,
625 true, true, GNUTLS_KP_TLS_WWW_CLIENT
, NULL
,
628 gnutls_x509_crt_t certchain
[] = {
630 cacertlevel1areq
.crt
,
631 cacertlevel1breq
.crt
,
632 cacertlevel2areq
.crt
,
635 test_tls_write_cert_chain(WORKDIR
"cacertchain-ctx.pem",
637 G_N_ELEMENTS(certchain
));
639 TLS_TEST_REG(chain1
, true,
640 WORKDIR
"cacertchain-ctx.pem",
641 servercertlevel3areq
.filename
, false);
642 TLS_TEST_REG(chain2
, false,
643 WORKDIR
"cacertchain-ctx.pem",
644 clientcertlevel2breq
.filename
, false);
646 /* Some missing certs - first two are fatal, the last
649 TLS_TEST_REG(missingca
, true,
650 "cacertdoesnotexist.pem",
651 servercert1req
.filename
, true);
652 TLS_TEST_REG(missingserver
, true,
654 "servercertdoesnotexist.pem", true);
655 TLS_TEST_REG(missingclient
, false,
657 "clientcertdoesnotexist.pem", false);
661 test_tls_discard_cert(&cacertreq
);
662 test_tls_discard_cert(&cacert1req
);
663 test_tls_discard_cert(&cacert2req
);
664 test_tls_discard_cert(&cacert3req
);
665 test_tls_discard_cert(&cacert4req
);
666 test_tls_discard_cert(&cacert5req
);
667 test_tls_discard_cert(&cacert6req
);
669 test_tls_discard_cert(&servercertreq
);
670 test_tls_discard_cert(&servercert1req
);
671 test_tls_discard_cert(&servercert2req
);
672 test_tls_discard_cert(&servercert3req
);
673 test_tls_discard_cert(&servercert4req
);
674 test_tls_discard_cert(&servercert5req
);
675 test_tls_discard_cert(&servercert6req
);
676 test_tls_discard_cert(&servercert7req
);
677 test_tls_discard_cert(&servercert8req
);
678 test_tls_discard_cert(&servercert9req
);
679 test_tls_discard_cert(&servercert10req
);
680 test_tls_discard_cert(&servercert11req
);
681 test_tls_discard_cert(&servercert12req
);
682 test_tls_discard_cert(&servercert13req
);
683 test_tls_discard_cert(&servercert14req
);
684 test_tls_discard_cert(&servercert15req
);
685 test_tls_discard_cert(&servercert16req
);
687 test_tls_discard_cert(&clientcertreq
);
688 test_tls_discard_cert(&clientcert1req
);
689 test_tls_discard_cert(&clientcert2req
);
690 test_tls_discard_cert(&clientcert3req
);
691 test_tls_discard_cert(&clientcert4req
);
692 test_tls_discard_cert(&clientcert5req
);
693 test_tls_discard_cert(&clientcert6req
);
694 test_tls_discard_cert(&clientcert7req
);
695 test_tls_discard_cert(&clientcert8req
);
696 test_tls_discard_cert(&clientcert9req
);
697 test_tls_discard_cert(&clientcert10req
);
699 test_tls_discard_cert(&cacertexpreq
);
700 test_tls_discard_cert(&servercertexpreq
);
701 test_tls_discard_cert(&servercertexp1req
);
702 test_tls_discard_cert(&clientcertexp1req
);
704 test_tls_discard_cert(&cacertnewreq
);
705 test_tls_discard_cert(&servercertnewreq
);
706 test_tls_discard_cert(&servercertnew1req
);
707 test_tls_discard_cert(&clientcertnew1req
);
709 test_tls_discard_cert(&cacertrootreq
);
710 test_tls_discard_cert(&cacertlevel1areq
);
711 test_tls_discard_cert(&cacertlevel1breq
);
712 test_tls_discard_cert(&cacertlevel2areq
);
713 test_tls_discard_cert(&servercertlevel3areq
);
714 test_tls_discard_cert(&clientcertlevel2breq
);
715 unlink(WORKDIR
"cacertchain-ctx.pem");
717 test_tls_cleanup(KEYFILE
);
720 return ret
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;
723 #else /* ! QCRYPTO_HAVE_TLS_TEST_SUPPORT */
731 #endif /* ! QCRYPTO_HAVE_TLS_TEST_SUPPORT */