master
c 796 lines 26 KB
Raw
1 /*
2 * QTest testcases for TLS migration
3 *
4 * Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
5 * based on the vhost-user-test.c that is:
6 * Copyright (c) 2014 Virtual Open Systems Sarl.
7 *
8 * This work is licensed under the terms of the GNU GPL, version 2 or later.
9 * See the COPYING file in the top-level directory.
10 *
11 */
12
13 #include "qemu/osdep.h"
14 #include "crypto/tlscredspsk.h"
15 #include "libqtest.h"
16 #include "migration/framework.h"
17 #include "migration/migration-qmp.h"
18 #include "migration/migration-util.h"
19
20 #include "tests/unit/crypto-tls-psk-helpers.h"
21 #ifdef CONFIG_TASN1
22 # include "tests/unit/crypto-tls-x509-helpers.h"
23 #endif /* CONFIG_TASN1 */
24
25
26 struct TestMigrateTLSPSKData {
27 char *workdir;
28 char *workdiralt;
29 char *pskfile;
30 char *pskfilealt;
31 };
32
33 static char *tmpfs;
34
35 static void *
36 migrate_hook_start_tls_psk_common(QTestState *from,
37 QTestState *to,
38 bool mismatch)
39 {
40 struct TestMigrateTLSPSKData *data =
41 g_new0(struct TestMigrateTLSPSKData, 1);
42
43 data->workdir = g_strdup_printf("%s/tlscredspsk0", tmpfs);
44 data->pskfile = g_strdup_printf("%s/%s", data->workdir,
45 QCRYPTO_TLS_CREDS_PSKFILE);
46 g_mkdir_with_parents(data->workdir, 0700);
47 test_tls_psk_init(data->pskfile);
48
49 if (mismatch) {
50 data->workdiralt = g_strdup_printf("%s/tlscredspskalt0", tmpfs);
51 data->pskfilealt = g_strdup_printf("%s/%s", data->workdiralt,
52 QCRYPTO_TLS_CREDS_PSKFILE);
53 g_mkdir_with_parents(data->workdiralt, 0700);
54 test_tls_psk_init_alt(data->pskfilealt);
55 }
56
57 qtest_qmp_assert_success(from,
58 "{ 'execute': 'object-add',"
59 " 'arguments': { 'qom-type': 'tls-creds-psk',"
60 " 'id': 'tlscredspsk0',"
61 " 'endpoint': 'client',"
62 " 'dir': %s,"
63 " 'username': 'qemu'} }",
64 data->workdir);
65
66 qtest_qmp_assert_success(to,
67 "{ 'execute': 'object-add',"
68 " 'arguments': { 'qom-type': 'tls-creds-psk',"
69 " 'id': 'tlscredspsk0',"
70 " 'endpoint': 'server',"
71 " 'dir': %s } }",
72 mismatch ? data->workdiralt : data->workdir);
73
74 migrate_set_parameter_str(from, "tls-creds", "tlscredspsk0");
75 migrate_set_parameter_str(to, "tls-creds", "tlscredspsk0");
76
77 return data;
78 }
79
80 static void *
81 migrate_hook_start_tls_psk_match(QTestState *from,
82 QTestState *to)
83 {
84 return migrate_hook_start_tls_psk_common(from, to, false);
85 }
86
87 static void *
88 migrate_hook_start_tls_psk_mismatch(QTestState *from,
89 QTestState *to)
90 {
91 return migrate_hook_start_tls_psk_common(from, to, true);
92 }
93
94 static void
95 migrate_hook_end_tls_psk(QTestState *from,
96 QTestState *to,
97 void *opaque)
98 {
99 struct TestMigrateTLSPSKData *data = opaque;
100
101 test_tls_psk_cleanup(data->pskfile);
102 if (data->pskfilealt) {
103 test_tls_psk_cleanup(data->pskfilealt);
104 }
105 rmdir(data->workdir);
106 if (data->workdiralt) {
107 rmdir(data->workdiralt);
108 }
109
110 g_free(data->workdiralt);
111 g_free(data->pskfilealt);
112 g_free(data->workdir);
113 g_free(data->pskfile);
114 g_free(data);
115 }
116
117 #ifdef CONFIG_TASN1
118 typedef struct {
119 char *workdir;
120 char *keyfile;
121 char *cacert;
122 char *servercert;
123 char *serverkey;
124 char *clientcert;
125 char *clientkey;
126 } TestMigrateTLSX509Data;
127
128 typedef struct {
129 bool verifyclient;
130 bool clientcert;
131 bool hostileclient;
132 bool authzclient;
133 const char *certhostname;
134 const char *certipaddr;
135 } TestMigrateTLSX509;
136
137 static void *
138 migrate_hook_start_tls_x509_common(QTestState *from,
139 QTestState *to,
140 TestMigrateTLSX509 *args)
141 {
142 TestMigrateTLSX509Data *data = g_new0(TestMigrateTLSX509Data, 1);
143
144 data->workdir = g_strdup_printf("%s/tlscredsx5090", tmpfs);
145 data->keyfile = g_strdup_printf("%s/key.pem", data->workdir);
146
147 data->cacert = g_strdup_printf("%s/ca-cert.pem", data->workdir);
148 data->serverkey = g_strdup_printf("%s/server-key.pem", data->workdir);
149 data->servercert = g_strdup_printf("%s/server-cert.pem", data->workdir);
150 if (args->clientcert) {
151 data->clientkey = g_strdup_printf("%s/client-key.pem", data->workdir);
152 data->clientcert = g_strdup_printf("%s/client-cert.pem", data->workdir);
153 }
154
155 g_mkdir_with_parents(data->workdir, 0700);
156
157 test_tls_init(data->keyfile);
158 #ifndef _WIN32
159 g_assert(link(data->keyfile, data->serverkey) == 0);
160 #else
161 g_assert(CreateHardLink(data->serverkey, data->keyfile, NULL) != 0);
162 #endif
163 if (args->clientcert) {
164 #ifndef _WIN32
165 g_assert(link(data->keyfile, data->clientkey) == 0);
166 #else
167 g_assert(CreateHardLink(data->clientkey, data->keyfile, NULL) != 0);
168 #endif
169 }
170
171 TLS_ROOT_REQ_SIMPLE(cacertreq, data->cacert);
172 if (args->clientcert) {
173 TLS_CERT_REQ_SIMPLE_CLIENT(servercertreq, cacertreq,
174 args->hostileclient ?
175 QCRYPTO_TLS_TEST_CLIENT_HOSTILE_NAME :
176 QCRYPTO_TLS_TEST_CLIENT_NAME,
177 data->clientcert);
178 test_tls_deinit_cert(&servercertreq);
179 }
180
181 TLS_CERT_REQ_SIMPLE_SERVER(clientcertreq, cacertreq,
182 data->servercert,
183 args->certhostname,
184 args->certipaddr);
185 test_tls_deinit_cert(&clientcertreq);
186 test_tls_deinit_cert(&cacertreq);
187
188 qtest_qmp_assert_success(from,
189 "{ 'execute': 'object-add',"
190 " 'arguments': { 'qom-type': 'tls-creds-x509',"
191 " 'id': 'tlscredsx509client0',"
192 " 'endpoint': 'client',"
193 " 'dir': %s,"
194 " 'sanity-check': true,"
195 " 'verify-peer': true} }",
196 data->workdir);
197 migrate_set_parameter_str(from, "tls-creds", "tlscredsx509client0");
198 if (args->certhostname) {
199 migrate_set_parameter_str(from, "tls-hostname", args->certhostname);
200 }
201
202 qtest_qmp_assert_success(to,
203 "{ 'execute': 'object-add',"
204 " 'arguments': { 'qom-type': 'tls-creds-x509',"
205 " 'id': 'tlscredsx509server0',"
206 " 'endpoint': 'server',"
207 " 'dir': %s,"
208 " 'sanity-check': true,"
209 " 'verify-peer': %i} }",
210 data->workdir, args->verifyclient);
211 migrate_set_parameter_str(to, "tls-creds", "tlscredsx509server0");
212
213 if (args->authzclient) {
214 qtest_qmp_assert_success(to,
215 "{ 'execute': 'object-add',"
216 " 'arguments': { 'qom-type': 'authz-simple',"
217 " 'id': 'tlsauthz0',"
218 " 'identity': %s} }",
219 "CN=" QCRYPTO_TLS_TEST_CLIENT_NAME);
220 migrate_set_parameter_str(to, "tls-authz", "tlsauthz0");
221 }
222
223 return data;
224 }
225
226 /*
227 * The normal case: match server's cert hostname against
228 * whatever host we were telling QEMU to connect to (if any)
229 */
230 static void *
231 migrate_hook_start_tls_x509_default_host(QTestState *from,
232 QTestState *to)
233 {
234 TestMigrateTLSX509 args = {
235 .verifyclient = true,
236 .clientcert = true,
237 .certipaddr = "127.0.0.1"
238 };
239 return migrate_hook_start_tls_x509_common(from, to, &args);
240 }
241
242 /*
243 * The unusual case: the server's cert is different from
244 * the address we're telling QEMU to connect to (if any),
245 * so we must give QEMU an explicit hostname to validate
246 */
247 static void *
248 migrate_hook_start_tls_x509_override_host(QTestState *from,
249 QTestState *to)
250 {
251 TestMigrateTLSX509 args = {
252 .verifyclient = true,
253 .clientcert = true,
254 .certhostname = "qemu.org",
255 };
256 return migrate_hook_start_tls_x509_common(from, to, &args);
257 }
258
259 /*
260 * The unusual case: the server's cert is different from
261 * the address we're telling QEMU to connect to, and so we
262 * expect the client to reject the server
263 */
264 static void *
265 migrate_hook_start_tls_x509_mismatch_host(QTestState *from,
266 QTestState *to)
267 {
268 TestMigrateTLSX509 args = {
269 .verifyclient = true,
270 .clientcert = true,
271 .certipaddr = "10.0.0.1",
272 };
273 return migrate_hook_start_tls_x509_common(from, to, &args);
274 }
275
276 static void *
277 migrate_hook_start_tls_x509_friendly_client(QTestState *from,
278 QTestState *to)
279 {
280 TestMigrateTLSX509 args = {
281 .verifyclient = true,
282 .clientcert = true,
283 .authzclient = true,
284 .certipaddr = "127.0.0.1",
285 };
286 return migrate_hook_start_tls_x509_common(from, to, &args);
287 }
288
289 static void *
290 migrate_hook_start_tls_x509_hostile_client(QTestState *from,
291 QTestState *to)
292 {
293 TestMigrateTLSX509 args = {
294 .verifyclient = true,
295 .clientcert = true,
296 .hostileclient = true,
297 .authzclient = true,
298 .certipaddr = "127.0.0.1",
299 };
300 return migrate_hook_start_tls_x509_common(from, to, &args);
301 }
302
303 /*
304 * The case with no client certificate presented,
305 * and no server verification
306 */
307 static void *
308 migrate_hook_start_tls_x509_allow_anon_client(QTestState *from,
309 QTestState *to)
310 {
311 TestMigrateTLSX509 args = {
312 .certipaddr = "127.0.0.1",
313 };
314 return migrate_hook_start_tls_x509_common(from, to, &args);
315 }
316
317 /*
318 * The case with no client certificate presented,
319 * and server verification rejecting
320 */
321 static void *
322 migrate_hook_start_tls_x509_reject_anon_client(QTestState *from,
323 QTestState *to)
324 {
325 TestMigrateTLSX509 args = {
326 .verifyclient = true,
327 .certipaddr = "127.0.0.1",
328 };
329 return migrate_hook_start_tls_x509_common(from, to, &args);
330 }
331
332 static void
333 migrate_hook_end_tls_x509(QTestState *from,
334 QTestState *to,
335 void *opaque)
336 {
337 TestMigrateTLSX509Data *data = opaque;
338
339 test_tls_cleanup(data->keyfile);
340 g_free(data->keyfile);
341
342 unlink(data->cacert);
343 g_free(data->cacert);
344 unlink(data->servercert);
345 g_free(data->servercert);
346 unlink(data->serverkey);
347 g_free(data->serverkey);
348
349 if (data->clientcert) {
350 unlink(data->clientcert);
351 g_free(data->clientcert);
352 }
353 if (data->clientkey) {
354 unlink(data->clientkey);
355 g_free(data->clientkey);
356 }
357
358 rmdir(data->workdir);
359 g_free(data->workdir);
360
361 g_free(data);
362 }
363 #endif /* CONFIG_TASN1 */
364
365 static void test_postcopy_tls_psk(char *name, MigrateCommon *args)
366 {
367 args->start_hook = migrate_hook_start_tls_psk_match;
368 args->end_hook = migrate_hook_end_tls_psk;
369
370 test_postcopy_common(args);
371 }
372
373 static void test_postcopy_preempt_tls_psk(char *name, MigrateCommon *args)
374 {
375 args->start_hook = migrate_hook_start_tls_psk_match;
376 args->end_hook = migrate_hook_end_tls_psk;
377
378 args->start.caps[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT] = true;
379
380 test_postcopy_common(args);
381 }
382
383 static void test_postcopy_recovery_tls_psk(char *name, MigrateCommon *args)
384 {
385 args->start_hook = migrate_hook_start_tls_psk_match;
386 args->end_hook = migrate_hook_end_tls_psk;
387
388 test_postcopy_recovery_common(args, POSTCOPY_FAIL_NONE);
389 }
390
391 static void test_multifd_postcopy_recovery_tls_psk(char *name,
392 MigrateCommon *args)
393 {
394 args->start_hook = migrate_hook_start_tls_psk_match;
395 args->end_hook = migrate_hook_end_tls_psk;
396
397 args->start.caps[MIGRATION_CAPABILITY_MULTIFD] = true;
398
399 test_postcopy_recovery_common(args, POSTCOPY_FAIL_NONE);
400 }
401
402 /* This contains preempt+recovery+tls test altogether */
403 static void test_postcopy_preempt_all(char *name, MigrateCommon *args)
404 {
405 args->start_hook = migrate_hook_start_tls_psk_match;
406 args->end_hook = migrate_hook_end_tls_psk;
407
408 args->start.caps[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT] = true;
409
410 test_postcopy_recovery_common(args, POSTCOPY_FAIL_NONE);
411 }
412
413 static void test_multifd_postcopy_preempt_recovery_tls_psk(char *name,
414 MigrateCommon *args)
415 {
416 args->start_hook = migrate_hook_start_tls_psk_match;
417 args->end_hook = migrate_hook_end_tls_psk;
418
419 args->start.caps[MIGRATION_CAPABILITY_MULTIFD] = true;
420 args->start.caps[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT] = true;
421
422 test_postcopy_recovery_common(args, POSTCOPY_FAIL_NONE);
423 }
424
425 static void test_precopy_unix_tls_psk(char *name, MigrateCommon *args)
426 {
427 args->start_hook = migrate_hook_start_tls_psk_match;
428 args->end_hook = migrate_hook_end_tls_psk;
429
430 test_precopy_unix_common(args);
431 }
432
433 #ifdef CONFIG_TASN1
434 static void test_precopy_unix_tls_x509_default_host(char *name,
435 MigrateCommon *args)
436 {
437 g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
438
439 args->uri = uri;
440 args->start_hook = migrate_hook_start_tls_x509_default_host;
441 args->end_hook = migrate_hook_end_tls_x509;
442 args->result = MIG_TEST_FAIL;
443
444 args->start.hide_stderr = true;
445
446 test_precopy_common(args);
447 }
448
449 static void test_precopy_unix_tls_x509_override_host(char *name,
450 MigrateCommon *args)
451 {
452 args->start_hook = migrate_hook_start_tls_x509_override_host;
453 args->end_hook = migrate_hook_end_tls_x509;
454
455 test_precopy_unix_common(args);
456 }
457 #endif /* CONFIG_TASN1 */
458
459 static void test_precopy_tcp_tls_psk_match(char *name, MigrateCommon *args)
460 {
461 args->start_hook = migrate_hook_start_tls_psk_match;
462 args->end_hook = migrate_hook_end_tls_psk;
463
464 test_precopy_common(args);
465 }
466
467 static void test_precopy_tcp_tls_psk_mismatch(char *name, MigrateCommon *args)
468 {
469 args->start_hook = migrate_hook_start_tls_psk_mismatch;
470 args->end_hook = migrate_hook_end_tls_psk;
471 args->result = MIG_TEST_FAIL;
472
473 args->start.hide_stderr = true;
474
475 test_precopy_common(args);
476 }
477
478 static void *migrate_hook_start_no_tls(QTestState *from, QTestState *to)
479 {
480 migrate_set_parameter_null(from, "tls-creds");
481 migrate_set_parameter_null(to, "tls-creds");
482
483 return NULL;
484 }
485
486 static void test_precopy_tcp_no_tls(char *name, MigrateCommon *args)
487 {
488 args->start_hook = migrate_hook_start_no_tls;
489 /* the no_tls start hook requires no cleanup actions */
490 args->end_hook = NULL;
491
492 test_precopy_common(args);
493 }
494
495 #ifdef CONFIG_TASN1
496 static void *
497 migrate_hook_start_tls_x509_no_host(QTestState *from, QTestState *to)
498 {
499 TestMigrateTLSX509 args = {
500 .verifyclient = true,
501 .clientcert = true,
502 .authzclient = true,
503 };
504 TestMigrateTLSX509Data *data = migrate_hook_start_tls_x509_common(from, to,
505 &args);
506 migrate_set_parameter_null(from, "tls-hostname");
507 migrate_set_parameter_null(to, "tls-hostname");
508
509 return data;
510 }
511
512 static void test_precopy_tcp_tls_no_hostname(char *name, MigrateCommon *args)
513 {
514 args->start_hook = migrate_hook_start_tls_x509_no_host;
515 args->end_hook = migrate_hook_end_tls_x509;
516 args->result = MIG_TEST_FAIL;
517
518 args->start.hide_stderr = true;
519
520 test_precopy_common(args);
521 }
522
523 static void test_precopy_tcp_tls_x509_default_host(char *name,
524 MigrateCommon *args)
525 {
526 args->start_hook = migrate_hook_start_tls_x509_default_host;
527 args->end_hook = migrate_hook_end_tls_x509;
528
529 test_precopy_common(args);
530 }
531
532 static void test_precopy_tcp_tls_x509_override_host(char *name,
533 MigrateCommon *args)
534 {
535 args->start_hook = migrate_hook_start_tls_x509_override_host;
536 args->end_hook = migrate_hook_end_tls_x509;
537
538 test_precopy_common(args);
539 }
540
541 static void test_precopy_tcp_tls_x509_mismatch_host(char *name,
542 MigrateCommon *args)
543 {
544 args->start_hook = migrate_hook_start_tls_x509_mismatch_host;
545 args->end_hook = migrate_hook_end_tls_x509;
546 args->result = MIG_TEST_FAIL;
547
548 args->start.hide_stderr = true;
549
550 test_precopy_common(args);
551 }
552
553 static void test_precopy_tcp_tls_x509_friendly_client(char *name,
554 MigrateCommon *args)
555 {
556 args->start_hook = migrate_hook_start_tls_x509_friendly_client;
557 args->end_hook = migrate_hook_end_tls_x509;
558
559 test_precopy_common(args);
560 }
561
562 static void test_precopy_tcp_tls_x509_hostile_client(char *name,
563 MigrateCommon *args)
564 {
565 args->start_hook = migrate_hook_start_tls_x509_hostile_client;
566 args->end_hook = migrate_hook_end_tls_x509;
567 args->result = MIG_TEST_FAIL;
568
569 args->start.hide_stderr = true;
570
571 test_precopy_common(args);
572 }
573
574 static void test_precopy_tcp_tls_x509_allow_anon_client(char *name,
575 MigrateCommon *args)
576 {
577 args->start_hook = migrate_hook_start_tls_x509_allow_anon_client;
578 args->end_hook = migrate_hook_end_tls_x509;
579
580 test_precopy_common(args);
581 }
582
583 static void test_precopy_tcp_tls_x509_reject_anon_client(char *name,
584 MigrateCommon *args)
585 {
586 args->start_hook = migrate_hook_start_tls_x509_reject_anon_client;
587 args->end_hook = migrate_hook_end_tls_x509;
588 args->result = MIG_TEST_FAIL;
589
590 args->start.hide_stderr = true;
591
592 test_precopy_common(args);
593 }
594 #endif /* CONFIG_TASN1 */
595
596 static void test_multifd_tcp_tls_psk_match(char *name, MigrateCommon *args)
597 {
598 args->start_hook = migrate_hook_start_tls_psk_match;
599 args->end_hook = migrate_hook_end_tls_psk;
600
601 args->start.caps[MIGRATION_CAPABILITY_MULTIFD] = true;
602
603 test_precopy_common(args);
604 }
605
606 static void test_multifd_tcp_tls_psk_mismatch(char *name, MigrateCommon *args)
607 {
608 args->start_hook = migrate_hook_start_tls_psk_mismatch;
609 args->end_hook = migrate_hook_end_tls_psk;
610 args->result = MIG_TEST_FAIL;
611
612 args->start.hide_stderr = true;
613 args->start.caps[MIGRATION_CAPABILITY_MULTIFD] = true;
614
615 test_precopy_common(args);
616 }
617
618 static void test_multifd_postcopy_tcp_tls_psk_match(char *name,
619 MigrateCommon *args)
620 {
621 args->start_hook = migrate_hook_start_tls_psk_match;
622 args->end_hook = migrate_hook_end_tls_psk;
623
624 args->start.caps[MIGRATION_CAPABILITY_MULTIFD] = true;
625 args->start.caps[MIGRATION_CAPABILITY_POSTCOPY_RAM] = true;
626
627 test_precopy_common(args);
628 }
629
630 #ifdef CONFIG_TASN1
631 static void test_multifd_tcp_tls_x509_default_host(char *name,
632 MigrateCommon *args)
633 {
634 args->start_hook = migrate_hook_start_tls_x509_default_host;
635 args->end_hook = migrate_hook_end_tls_x509;
636
637 args->start.caps[MIGRATION_CAPABILITY_MULTIFD] = true;
638
639 test_precopy_common(args);
640 }
641
642 static void test_multifd_tcp_tls_x509_override_host(char *name,
643 MigrateCommon *args)
644 {
645 args->start_hook = migrate_hook_start_tls_x509_override_host;
646 args->end_hook = migrate_hook_end_tls_x509;
647
648 args->start.caps[MIGRATION_CAPABILITY_MULTIFD] = true;
649
650 test_precopy_common(args);
651 }
652
653 static void test_multifd_tcp_tls_x509_mismatch_host(char *name,
654 MigrateCommon *args)
655 {
656 /*
657 * This has different behaviour to the non-multifd case.
658 *
659 * In non-multifd case when client aborts due to mismatched
660 * cert host, the server has already started trying to load
661 * migration state, and so it exits with I/O failure.
662 *
663 * In multifd case when client aborts due to mismatched
664 * cert host, the server is still waiting for the other
665 * multifd connections to arrive so hasn't started trying
666 * to load migration state, and thus just aborts the migration
667 * without exiting.
668 */
669 args->start_hook = migrate_hook_start_tls_x509_mismatch_host;
670 args->end_hook = migrate_hook_end_tls_x509;
671 args->result = MIG_TEST_FAIL;
672
673 args->start.hide_stderr = true;
674 args->start.caps[MIGRATION_CAPABILITY_MULTIFD] = true;
675
676 test_precopy_common(args);
677 }
678
679 static void test_multifd_tcp_tls_x509_allow_anon_client(char *name,
680 MigrateCommon *args)
681 {
682 args->start_hook = migrate_hook_start_tls_x509_allow_anon_client;
683 args->end_hook = migrate_hook_end_tls_x509;
684
685 args->start.caps[MIGRATION_CAPABILITY_MULTIFD] = true;
686
687 test_precopy_common(args);
688 }
689
690 static void test_multifd_tcp_tls_x509_reject_anon_client(char *name,
691 MigrateCommon *args)
692 {
693 args->start_hook = migrate_hook_start_tls_x509_reject_anon_client;
694 args->end_hook = migrate_hook_end_tls_x509;
695 args->result = MIG_TEST_FAIL;
696
697 args->start.hide_stderr = true;
698 args->start.caps[MIGRATION_CAPABILITY_MULTIFD] = true;
699
700 test_precopy_common(args);
701 }
702 #endif /* CONFIG_TASN1 */
703
704 static void migration_test_add_tls_smoke(MigrationTestEnv *env)
705 {
706 migration_test_add("/migration/precopy/tcp/tls/psk/match",
707 test_precopy_tcp_tls_psk_match);
708 }
709
710 void migration_test_add_tls(MigrationTestEnv *env)
711 {
712 tmpfs = env->tmpfs;
713
714 migration_test_add_tls_smoke(env);
715
716 if (!env->full_set) {
717 return;
718 }
719
720 migration_test_add("/migration/precopy/tcp/no-tls",
721 test_precopy_tcp_no_tls);
722 #ifdef CONFIG_TASN1
723 migration_test_add("/migration/precopy/tcp/tls/no-hostname",
724 test_precopy_tcp_tls_no_hostname);
725 #endif /* CONFIG_TASN1 */
726
727 migration_test_add("/migration/precopy/unix/tls/psk",
728 test_precopy_unix_tls_psk);
729
730 if (env->has_uffd) {
731 /*
732 * NOTE: psk test is enough for postcopy, as other types of TLS
733 * channels are tested under precopy. Here what we want to test is the
734 * general postcopy path that has TLS channel enabled.
735 */
736 migration_test_add("/migration/postcopy/tls/psk",
737 test_postcopy_tls_psk);
738 migration_test_add("/migration/postcopy/recovery/tls/psk",
739 test_postcopy_recovery_tls_psk);
740 migration_test_add("/migration/postcopy/preempt/tls/psk",
741 test_postcopy_preempt_tls_psk);
742 migration_test_add("/migration/postcopy/preempt/recovery/tls/psk",
743 test_postcopy_preempt_all);
744 migration_test_add("/migration/multifd+postcopy/recovery/tls/psk",
745 test_multifd_postcopy_recovery_tls_psk);
746 migration_test_add(
747 "/migration/multifd+postcopy/preempt/recovery/tls/psk",
748 test_multifd_postcopy_preempt_recovery_tls_psk);
749 }
750 #ifdef CONFIG_TASN1
751 migration_test_add("/migration/precopy/unix/tls/x509/default-host",
752 test_precopy_unix_tls_x509_default_host);
753 migration_test_add("/migration/precopy/unix/tls/x509/override-host",
754 test_precopy_unix_tls_x509_override_host);
755 #endif /* CONFIG_TASN1 */
756
757 migration_test_add("/migration/precopy/tcp/tls/psk/mismatch",
758 test_precopy_tcp_tls_psk_mismatch);
759 #ifdef CONFIG_TASN1
760 migration_test_add("/migration/precopy/tcp/tls/x509/default-host",
761 test_precopy_tcp_tls_x509_default_host);
762 migration_test_add("/migration/precopy/tcp/tls/x509/override-host",
763 test_precopy_tcp_tls_x509_override_host);
764 migration_test_add("/migration/precopy/tcp/tls/x509/mismatch-host",
765 test_precopy_tcp_tls_x509_mismatch_host);
766 migration_test_add("/migration/precopy/tcp/tls/x509/friendly-client",
767 test_precopy_tcp_tls_x509_friendly_client);
768 migration_test_add("/migration/precopy/tcp/tls/x509/hostile-client",
769 test_precopy_tcp_tls_x509_hostile_client);
770 migration_test_add("/migration/precopy/tcp/tls/x509/allow-anon-client",
771 test_precopy_tcp_tls_x509_allow_anon_client);
772 migration_test_add("/migration/precopy/tcp/tls/x509/reject-anon-client",
773 test_precopy_tcp_tls_x509_reject_anon_client);
774 #endif /* CONFIG_TASN1 */
775
776 migration_test_add("/migration/multifd/tcp/tls/psk/match",
777 test_multifd_tcp_tls_psk_match);
778 migration_test_add("/migration/multifd/tcp/tls/psk/mismatch",
779 test_multifd_tcp_tls_psk_mismatch);
780 if (env->has_uffd) {
781 migration_test_add("/migration/multifd+postcopy/tcp/tls/psk/match",
782 test_multifd_postcopy_tcp_tls_psk_match);
783 }
784 #ifdef CONFIG_TASN1
785 migration_test_add("/migration/multifd/tcp/tls/x509/default-host",
786 test_multifd_tcp_tls_x509_default_host);
787 migration_test_add("/migration/multifd/tcp/tls/x509/override-host",
788 test_multifd_tcp_tls_x509_override_host);
789 migration_test_add("/migration/multifd/tcp/tls/x509/mismatch-host",
790 test_multifd_tcp_tls_x509_mismatch_host);
791 migration_test_add("/migration/multifd/tcp/tls/x509/allow-anon-client",
792 test_multifd_tcp_tls_x509_allow_anon_client);
793 migration_test_add("/migration/multifd/tcp/tls/x509/reject-anon-client",
794 test_multifd_tcp_tls_x509_reject_anon_client);
795 #endif /* CONFIG_TASN1 */
796 }