aio-posix: Improve comment around marking node deleted
[qemu/ar7.git] / tests / test-crypto-tlscredsx509.c
blob30f9ac4bbf2b5e8657ff9197421b0de8b3950fa7
1 /*
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 {
33 bool isServer;
34 const char *cacrt;
35 const char *crt;
36 bool expectFail;
40 static QCryptoTLSCreds *test_tls_creds_create(QCryptoTLSCredsEndpoint endpoint,
41 const char *certdir,
42 Error **errp)
44 Object *parent = object_get_objects_root();
45 Object *creds = object_new_with_props(
46 TYPE_QCRYPTO_TLS_CREDS_X509,
47 parent,
48 "testtlscreds",
49 errp,
50 "endpoint", (endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_SERVER ?
51 "server" : "client"),
52 "dir", certdir,
53 "verify-peer", "yes",
54 "sanity-check", "yes",
55 NULL);
57 if (!creds) {
58 return NULL;
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
70 * things.
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);
82 if (data->isServer) {
83 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT);
84 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_KEY);
85 } else {
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);
94 if (data->isServer) {
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);
101 } else {
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(
111 (data->isServer ?
112 QCRYPTO_TLS_CREDS_ENDPOINT_SERVER :
113 QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT),
114 CERT_DIR,
115 data->expectFail ? NULL : &error_abort);
117 if (data->expectFail) {
118 g_assert(creds == NULL);
119 } else {
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);
127 } else {
128 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CLIENT_CERT);
129 unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CLIENT_KEY);
131 rmdir(CERT_DIR);
132 if (creds) {
133 object_unparent(OBJECT(creds));
137 int main(int argc, char **argv)
139 int ret;
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 \
152 }; \
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,
161 true, true, true,
162 true, true, GNUTLS_KEY_KEY_CERT_SIGN,
163 false, false, NULL, NULL,
164 0, 0);
166 TLS_CERT_REQ(servercertreq, cacertreq,
167 "UK", "qemu.org", NULL, NULL, NULL, NULL,
168 true, true, false,
169 true, true,
170 GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
171 true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
172 0, 0);
173 TLS_CERT_REQ(clientcertreq, cacertreq,
174 "UK", "qemu", NULL, NULL, NULL, NULL,
175 true, true, false,
176 true, true,
177 GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
178 true, true, GNUTLS_KP_TLS_WWW_CLIENT, NULL,
179 0, 0);
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,
192 true, true, true,
193 false, false, 0,
194 false, false, NULL, NULL,
195 0, 0);
196 TLS_CERT_REQ(servercert1req, cacert1req,
197 "UK", "qemu.org", NULL, NULL, NULL, NULL,
198 true, true, false,
199 true, true,
200 GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
201 true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
202 0, 0);
204 /* Basic:CA:not-critical */
205 TLS_ROOT_REQ(cacert2req,
206 "UK", "qemu CA 2", NULL, NULL, NULL, NULL,
207 true, false, true,
208 false, false, 0,
209 false, false, NULL, NULL,
210 0, 0);
211 TLS_CERT_REQ(servercert2req, cacert2req,
212 "UK", "qemu.org", NULL, NULL, NULL, NULL,
213 true, true, false,
214 true, true,
215 GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
216 true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
217 0, 0);
219 /* Key usage:cert-sign:critical */
220 TLS_ROOT_REQ(cacert3req,
221 "UK", "qemu CA 3", NULL, NULL, NULL, NULL,
222 true, true, true,
223 true, true, GNUTLS_KEY_KEY_CERT_SIGN,
224 false, false, NULL, NULL,
225 0, 0);
226 TLS_CERT_REQ(servercert3req, cacert3req,
227 "UK", "qemu.org", NULL, NULL, NULL, NULL,
228 true, true, false,
229 true, true,
230 GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
231 true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
232 0, 0);
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,
246 true, true, true,
247 true, false, GNUTLS_KEY_DIGITAL_SIGNATURE,
248 false, false, NULL, NULL,
249 0, 0);
250 TLS_CERT_REQ(servercert4req, cacert4req,
251 "UK", "qemu.org", NULL, NULL, NULL, NULL,
252 true, true, false,
253 true, true,
254 GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
255 true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
256 0, 0);
257 /* no-basic */
258 TLS_ROOT_REQ(cacert5req,
259 "UK", "qemu CA 5", NULL, NULL, NULL, NULL,
260 false, false, false,
261 false, false, 0,
262 false, false, NULL, NULL,
263 0, 0);
264 TLS_CERT_REQ(servercert5req, cacert5req,
265 "UK", "qemu.org", NULL, NULL, NULL, NULL,
266 true, true, false,
267 true, true,
268 GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
269 true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
270 0, 0);
271 /* Key usage:dig-sig:critical */
272 TLS_ROOT_REQ(cacert6req,
273 "UK", "qemu CA 6", NULL, NULL, NULL, NULL,
274 true, true, true,
275 true, true, GNUTLS_KEY_DIGITAL_SIGNATURE,
276 false, false, NULL, NULL,
277 0, 0);
278 TLS_CERT_REQ(servercert6req, cacert6req,
279 "UK", "qemu.org", NULL, NULL, NULL, NULL,
280 true, true, false,
281 true, true,
282 GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
283 true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
284 0, 0);
286 /* Technically a CA cert with basic constraints
287 * key purpose == key signing + non-critical should
288 * be rejected. GNUTLS < 3.1 does not reject it and
289 * we don't anticipate them changing this behaviour
291 TLS_TEST_REG(badca1, true, cacert4req.filename, servercert4req.filename,
292 (GNUTLS_VERSION_MAJOR == 3 && GNUTLS_VERSION_MINOR >= 1) ||
293 GNUTLS_VERSION_MAJOR > 3);
294 TLS_TEST_REG(badca2, true,
295 cacert5req.filename, servercert5req.filename, true);
296 TLS_TEST_REG(badca3, true,
297 cacert6req.filename, servercert6req.filename, true);
300 /* Various good servers */
301 /* no usage or purpose */
302 TLS_CERT_REQ(servercert7req, cacertreq,
303 "UK", "qemu", NULL, NULL, NULL, NULL,
304 true, true, false,
305 false, false, 0,
306 false, false, NULL, NULL,
307 0, 0);
308 /* usage:cert-sign+dig-sig+encipher:critical */
309 TLS_CERT_REQ(servercert8req, cacertreq,
310 "UK", "qemu", NULL, NULL, NULL, NULL,
311 true, true, false,
312 true, true,
313 GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT |
314 GNUTLS_KEY_KEY_CERT_SIGN,
315 false, false, NULL, NULL,
316 0, 0);
317 /* usage:cert-sign:not-critical */
318 TLS_CERT_REQ(servercert9req, cacertreq,
319 "UK", "qemu", NULL, NULL, NULL, NULL,
320 true, true, false,
321 true, false, GNUTLS_KEY_KEY_CERT_SIGN,
322 false, false, NULL, NULL,
323 0, 0);
324 /* purpose:server:critical */
325 TLS_CERT_REQ(servercert10req, cacertreq,
326 "UK", "qemu", NULL, NULL, NULL, NULL,
327 true, true, false,
328 false, false, 0,
329 true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
330 0, 0);
331 /* purpose:server:not-critical */
332 TLS_CERT_REQ(servercert11req, cacertreq,
333 "UK", "qemu", NULL, NULL, NULL, NULL,
334 true, true, false,
335 false, false, 0,
336 true, false, GNUTLS_KP_TLS_WWW_SERVER, NULL,
337 0, 0);
338 /* purpose:client+server:critical */
339 TLS_CERT_REQ(servercert12req, cacertreq,
340 "UK", "qemu", NULL, NULL, NULL, NULL,
341 true, true, false,
342 false, false, 0,
343 true, true,
344 GNUTLS_KP_TLS_WWW_CLIENT, GNUTLS_KP_TLS_WWW_SERVER,
345 0, 0);
346 /* purpose:client+server:not-critical */
347 TLS_CERT_REQ(servercert13req, cacertreq,
348 "UK", "qemu", NULL, NULL, NULL, NULL,
349 true, true, false,
350 false, false, 0,
351 true, false,
352 GNUTLS_KP_TLS_WWW_CLIENT, GNUTLS_KP_TLS_WWW_SERVER,
353 0, 0);
355 TLS_TEST_REG(goodserver1, true,
356 cacertreq.filename, servercert7req.filename, false);
357 TLS_TEST_REG(goodserver2, true,
358 cacertreq.filename, servercert8req.filename, false);
359 TLS_TEST_REG(goodserver3, true,
360 cacertreq.filename, servercert9req.filename, false);
361 TLS_TEST_REG(goodserver4, true,
362 cacertreq.filename, servercert10req.filename, false);
363 TLS_TEST_REG(goodserver5, true,
364 cacertreq.filename, servercert11req.filename, false);
365 TLS_TEST_REG(goodserver6, true,
366 cacertreq.filename, servercert12req.filename, false);
367 TLS_TEST_REG(goodserver7, true,
368 cacertreq.filename, servercert13req.filename, false);
370 /* Bad servers */
372 /* usage:cert-sign:critical */
373 TLS_CERT_REQ(servercert14req, cacertreq,
374 "UK", "qemu", NULL, NULL, NULL, NULL,
375 true, true, false,
376 true, true, GNUTLS_KEY_KEY_CERT_SIGN,
377 false, false, NULL, NULL,
378 0, 0);
379 /* purpose:client:critical */
380 TLS_CERT_REQ(servercert15req, cacertreq,
381 "UK", "qemu", NULL, NULL, NULL, NULL,
382 true, true, false,
383 false, false, 0,
384 true, true, GNUTLS_KP_TLS_WWW_CLIENT, NULL,
385 0, 0);
386 /* usage: none:critical */
387 TLS_CERT_REQ(servercert16req, cacertreq,
388 "UK", "qemu", NULL, NULL, NULL, NULL,
389 true, true, false,
390 true, true, 0,
391 false, false, NULL, NULL,
392 0, 0);
394 TLS_TEST_REG(badserver1, true,
395 cacertreq.filename, servercert14req.filename, true);
396 TLS_TEST_REG(badserver2, true,
397 cacertreq.filename, servercert15req.filename, true);
398 TLS_TEST_REG(badserver3, true,
399 cacertreq.filename, servercert16req.filename, true);
403 /* Various good clients */
404 /* no usage or purpose */
405 TLS_CERT_REQ(clientcert1req, cacertreq,
406 "UK", "qemu", NULL, NULL, NULL, NULL,
407 true, true, false,
408 false, false, 0,
409 false, false, NULL, NULL,
410 0, 0);
411 /* usage:cert-sign+dig-sig+encipher:critical */
412 TLS_CERT_REQ(clientcert2req, cacertreq,
413 "UK", "qemu", NULL, NULL, NULL, NULL,
414 true, true, false,
415 true, true,
416 GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT |
417 GNUTLS_KEY_KEY_CERT_SIGN,
418 false, false, NULL, NULL,
419 0, 0);
420 /* usage:cert-sign:not-critical */
421 TLS_CERT_REQ(clientcert3req, cacertreq,
422 "UK", "qemu", NULL, NULL, NULL, NULL,
423 true, true, false,
424 true, false, GNUTLS_KEY_KEY_CERT_SIGN,
425 false, false, NULL, NULL,
426 0, 0);
427 /* purpose:client:critical */
428 TLS_CERT_REQ(clientcert4req, cacertreq,
429 "UK", "qemu", NULL, NULL, NULL, NULL,
430 true, true, false,
431 false, false, 0,
432 true, true, GNUTLS_KP_TLS_WWW_CLIENT, NULL,
433 0, 0);
434 /* purpose:client:not-critical */
435 TLS_CERT_REQ(clientcert5req, cacertreq,
436 "UK", "qemu", NULL, NULL, NULL, NULL,
437 true, true, false,
438 false, false, 0,
439 true, false, GNUTLS_KP_TLS_WWW_CLIENT, NULL,
440 0, 0);
441 /* purpose:client+client:critical */
442 TLS_CERT_REQ(clientcert6req, cacertreq,
443 "UK", "qemu", NULL, NULL, NULL, NULL,
444 true, true, false,
445 false, false, 0,
446 true, true,
447 GNUTLS_KP_TLS_WWW_CLIENT, GNUTLS_KP_TLS_WWW_SERVER,
448 0, 0);
449 /* purpose:client+client:not-critical */
450 TLS_CERT_REQ(clientcert7req, cacertreq,
451 "UK", "qemu", NULL, NULL, NULL, NULL,
452 true, true, false,
453 false, false, 0,
454 true, false,
455 GNUTLS_KP_TLS_WWW_CLIENT, GNUTLS_KP_TLS_WWW_SERVER,
456 0, 0);
458 TLS_TEST_REG(goodclient1, false,
459 cacertreq.filename, clientcert1req.filename, false);
460 TLS_TEST_REG(goodclient2, false,
461 cacertreq.filename, clientcert2req.filename, false);
462 TLS_TEST_REG(goodclient3, false,
463 cacertreq.filename, clientcert3req.filename, false);
464 TLS_TEST_REG(goodclient4, false,
465 cacertreq.filename, clientcert4req.filename, false);
466 TLS_TEST_REG(goodclient5, false,
467 cacertreq.filename, clientcert5req.filename, false);
468 TLS_TEST_REG(goodclient6, false,
469 cacertreq.filename, clientcert6req.filename, false);
470 TLS_TEST_REG(goodclient7, false,
471 cacertreq.filename, clientcert7req.filename, false);
473 /* Bad clients */
475 /* usage:cert-sign:critical */
476 TLS_CERT_REQ(clientcert8req, cacertreq,
477 "UK", "qemu", NULL, NULL, NULL, NULL,
478 true, true, false,
479 true, true, GNUTLS_KEY_KEY_CERT_SIGN,
480 false, false, NULL, NULL,
481 0, 0);
482 /* purpose:client:critical */
483 TLS_CERT_REQ(clientcert9req, cacertreq,
484 "UK", "qemu", NULL, NULL, NULL, NULL,
485 true, true, false,
486 false, false, 0,
487 true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
488 0, 0);
489 /* usage: none:critical */
490 TLS_CERT_REQ(clientcert10req, cacertreq,
491 "UK", "qemu", NULL, NULL, NULL, NULL,
492 true, true, false,
493 true, true, 0,
494 false, false, NULL, NULL,
495 0, 0);
497 TLS_TEST_REG(badclient1, false,
498 cacertreq.filename, clientcert8req.filename, true);
499 TLS_TEST_REG(badclient2, false,
500 cacertreq.filename, clientcert9req.filename, true);
501 TLS_TEST_REG(badclient3, false,
502 cacertreq.filename, clientcert10req.filename, true);
506 /* Expired stuff */
508 TLS_ROOT_REQ(cacertexpreq,
509 "UK", "qemu", NULL, NULL, NULL, NULL,
510 true, true, true,
511 true, true, GNUTLS_KEY_KEY_CERT_SIGN,
512 false, false, NULL, NULL,
513 0, -1);
514 TLS_CERT_REQ(servercertexpreq, cacertexpreq,
515 "UK", "qemu.org", NULL, NULL, NULL, NULL,
516 true, true, false,
517 true, true,
518 GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
519 true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
520 0, 0);
521 TLS_CERT_REQ(servercertexp1req, cacertreq,
522 "UK", "qemu", NULL, NULL, NULL, NULL,
523 true, true, false,
524 true, true,
525 GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
526 true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
527 0, -1);
528 TLS_CERT_REQ(clientcertexp1req, cacertreq,
529 "UK", "qemu", NULL, NULL, NULL, NULL,
530 true, true, false,
531 true, true,
532 GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
533 true, true, GNUTLS_KP_TLS_WWW_CLIENT, NULL,
534 0, -1);
536 TLS_TEST_REG(expired1, true,
537 cacertexpreq.filename, servercertexpreq.filename, true);
538 TLS_TEST_REG(expired2, true,
539 cacertreq.filename, servercertexp1req.filename, true);
540 TLS_TEST_REG(expired3, false,
541 cacertreq.filename, clientcertexp1req.filename, true);
544 /* Not activated stuff */
546 TLS_ROOT_REQ(cacertnewreq,
547 "UK", "qemu", NULL, NULL, NULL, NULL,
548 true, true, true,
549 true, true, GNUTLS_KEY_KEY_CERT_SIGN,
550 false, false, NULL, NULL,
551 1, 2);
552 TLS_CERT_REQ(servercertnewreq, cacertnewreq,
553 "UK", "qemu", NULL, NULL, NULL, NULL,
554 true, true, false,
555 true, true,
556 GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
557 true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
558 0, 0);
559 TLS_CERT_REQ(servercertnew1req, cacertreq,
560 "UK", "qemu", NULL, NULL, NULL, NULL,
561 true, true, false,
562 true, true,
563 GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
564 true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
565 1, 2);
566 TLS_CERT_REQ(clientcertnew1req, cacertreq,
567 "UK", "qemu", NULL, NULL, NULL, NULL,
568 true, true, false,
569 true, true,
570 GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
571 true, true, GNUTLS_KP_TLS_WWW_CLIENT, NULL,
572 1, 2);
574 TLS_TEST_REG(inactive1, true,
575 cacertnewreq.filename, servercertnewreq.filename, true);
576 TLS_TEST_REG(inactive2, true,
577 cacertreq.filename, servercertnew1req.filename, true);
578 TLS_TEST_REG(inactive3, false,
579 cacertreq.filename, clientcertnew1req.filename, true);
581 TLS_ROOT_REQ(cacertrootreq,
582 "UK", "qemu root", NULL, NULL, NULL, NULL,
583 true, true, true,
584 true, true, GNUTLS_KEY_KEY_CERT_SIGN,
585 false, false, NULL, NULL,
586 0, 0);
587 TLS_CERT_REQ(cacertlevel1areq, cacertrootreq,
588 "UK", "qemu level 1a", NULL, NULL, NULL, NULL,
589 true, true, true,
590 true, true, GNUTLS_KEY_KEY_CERT_SIGN,
591 false, false, NULL, NULL,
592 0, 0);
593 TLS_CERT_REQ(cacertlevel1breq, cacertrootreq,
594 "UK", "qemu level 1b", NULL, NULL, NULL, NULL,
595 true, true, true,
596 true, true, GNUTLS_KEY_KEY_CERT_SIGN,
597 false, false, NULL, NULL,
598 0, 0);
599 TLS_CERT_REQ(cacertlevel2areq, cacertlevel1areq,
600 "UK", "qemu level 2a", NULL, NULL, NULL, NULL,
601 true, true, true,
602 true, true, GNUTLS_KEY_KEY_CERT_SIGN,
603 false, false, NULL, NULL,
604 0, 0);
605 TLS_CERT_REQ(servercertlevel3areq, cacertlevel2areq,
606 "UK", "qemu.org", NULL, NULL, NULL, NULL,
607 true, true, false,
608 true, true,
609 GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
610 true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
611 0, 0);
612 TLS_CERT_REQ(clientcertlevel2breq, cacertlevel1breq,
613 "UK", "qemu client level 2b", NULL, NULL, NULL, NULL,
614 true, true, false,
615 true, true,
616 GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
617 true, true, GNUTLS_KP_TLS_WWW_CLIENT, NULL,
618 0, 0);
620 gnutls_x509_crt_t certchain[] = {
621 cacertrootreq.crt,
622 cacertlevel1areq.crt,
623 cacertlevel1breq.crt,
624 cacertlevel2areq.crt,
627 test_tls_write_cert_chain(WORKDIR "cacertchain-ctx.pem",
628 certchain,
629 G_N_ELEMENTS(certchain));
631 TLS_TEST_REG(chain1, true,
632 WORKDIR "cacertchain-ctx.pem",
633 servercertlevel3areq.filename, false);
634 TLS_TEST_REG(chain2, false,
635 WORKDIR "cacertchain-ctx.pem",
636 clientcertlevel2breq.filename, false);
638 /* Some missing certs - first two are fatal, the last
639 * is ok
641 TLS_TEST_REG(missingca, true,
642 "cacertdoesnotexist.pem",
643 servercert1req.filename, true);
644 TLS_TEST_REG(missingserver, true,
645 cacert1req.filename,
646 "servercertdoesnotexist.pem", true);
647 TLS_TEST_REG(missingclient, false,
648 cacert1req.filename,
649 "clientcertdoesnotexist.pem", false);
651 ret = g_test_run();
653 test_tls_discard_cert(&cacertreq);
654 test_tls_discard_cert(&cacert1req);
655 test_tls_discard_cert(&cacert2req);
656 test_tls_discard_cert(&cacert3req);
657 test_tls_discard_cert(&cacert4req);
658 test_tls_discard_cert(&cacert5req);
659 test_tls_discard_cert(&cacert6req);
661 test_tls_discard_cert(&servercertreq);
662 test_tls_discard_cert(&servercert1req);
663 test_tls_discard_cert(&servercert2req);
664 test_tls_discard_cert(&servercert3req);
665 test_tls_discard_cert(&servercert4req);
666 test_tls_discard_cert(&servercert5req);
667 test_tls_discard_cert(&servercert6req);
668 test_tls_discard_cert(&servercert7req);
669 test_tls_discard_cert(&servercert8req);
670 test_tls_discard_cert(&servercert9req);
671 test_tls_discard_cert(&servercert10req);
672 test_tls_discard_cert(&servercert11req);
673 test_tls_discard_cert(&servercert12req);
674 test_tls_discard_cert(&servercert13req);
675 test_tls_discard_cert(&servercert14req);
676 test_tls_discard_cert(&servercert15req);
677 test_tls_discard_cert(&servercert16req);
679 test_tls_discard_cert(&clientcertreq);
680 test_tls_discard_cert(&clientcert1req);
681 test_tls_discard_cert(&clientcert2req);
682 test_tls_discard_cert(&clientcert3req);
683 test_tls_discard_cert(&clientcert4req);
684 test_tls_discard_cert(&clientcert5req);
685 test_tls_discard_cert(&clientcert6req);
686 test_tls_discard_cert(&clientcert7req);
687 test_tls_discard_cert(&clientcert8req);
688 test_tls_discard_cert(&clientcert9req);
689 test_tls_discard_cert(&clientcert10req);
691 test_tls_discard_cert(&cacertexpreq);
692 test_tls_discard_cert(&servercertexpreq);
693 test_tls_discard_cert(&servercertexp1req);
694 test_tls_discard_cert(&clientcertexp1req);
696 test_tls_discard_cert(&cacertnewreq);
697 test_tls_discard_cert(&servercertnewreq);
698 test_tls_discard_cert(&servercertnew1req);
699 test_tls_discard_cert(&clientcertnew1req);
701 test_tls_discard_cert(&cacertrootreq);
702 test_tls_discard_cert(&cacertlevel1areq);
703 test_tls_discard_cert(&cacertlevel1breq);
704 test_tls_discard_cert(&cacertlevel2areq);
705 test_tls_discard_cert(&servercertlevel3areq);
706 test_tls_discard_cert(&clientcertlevel2breq);
707 unlink(WORKDIR "cacertchain-ctx.pem");
709 test_tls_cleanup(KEYFILE);
710 rmdir(WORKDIR);
712 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
715 #else /* ! QCRYPTO_HAVE_TLS_TEST_SUPPORT */
718 main(void)
720 return EXIT_SUCCESS;
723 #endif /* ! QCRYPTO_HAVE_TLS_TEST_SUPPORT */