1da668aa1SThomas Huth /* 2da668aa1SThomas Huth * Copyright (C) 2015-2018 Red Hat, Inc. 3da668aa1SThomas Huth * 4da668aa1SThomas Huth * This library is free software; you can redistribute it and/or 5da668aa1SThomas Huth * modify it under the terms of the GNU Lesser General Public 6da668aa1SThomas Huth * License as published by the Free Software Foundation; either 7da668aa1SThomas Huth * version 2.1 of the License, or (at your option) any later version. 8da668aa1SThomas Huth * 9da668aa1SThomas Huth * This library is distributed in the hope that it will be useful, 10da668aa1SThomas Huth * but WITHOUT ANY WARRANTY; without even the implied warranty of 11da668aa1SThomas Huth * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12da668aa1SThomas Huth * Lesser General Public License for more details. 13da668aa1SThomas Huth * 14da668aa1SThomas Huth * You should have received a copy of the GNU Lesser General Public 15da668aa1SThomas Huth * License along with this library. If not, see 16da668aa1SThomas Huth * <http://www.gnu.org/licenses/>. 17da668aa1SThomas Huth * 18da668aa1SThomas Huth * Author: Richard W.M. Jones <rjones@redhat.com> 19da668aa1SThomas Huth */ 20da668aa1SThomas Huth 21da668aa1SThomas Huth #include "qemu/osdep.h" 22da668aa1SThomas Huth 23da668aa1SThomas Huth #include "crypto-tls-x509-helpers.h" 24da668aa1SThomas Huth #include "crypto-tls-psk-helpers.h" 25da668aa1SThomas Huth #include "qemu/sockets.h" 26da668aa1SThomas Huth 2758d25e97SDaniel P. Berrangé static void 2858d25e97SDaniel P. Berrangé test_tls_psk_init_common(const char *pskfile, const char *user, const char *key) 29da668aa1SThomas Huth { 30*f1018ea0SDaniel P. Berrangé g_autoptr(GError) gerr = NULL; 31*f1018ea0SDaniel P. Berrangé g_autofree char *line = g_strdup_printf("%s:%s\n", user, key); 32da668aa1SThomas Huth 33*f1018ea0SDaniel P. Berrangé g_file_set_contents(pskfile, line, strlen(line), &gerr); 34*f1018ea0SDaniel P. Berrangé if (gerr != NULL) { 35*f1018ea0SDaniel P. Berrangé g_critical("Failed to create pskfile %s: %s", pskfile, gerr->message); 36da668aa1SThomas Huth abort(); 37da668aa1SThomas Huth } 38da668aa1SThomas Huth } 39da668aa1SThomas Huth 4058d25e97SDaniel P. Berrangé void test_tls_psk_init(const char *pskfile) 4158d25e97SDaniel P. Berrangé { 4258d25e97SDaniel P. Berrangé /* Don't hard code a key like this in real applications! Use psktool. */ 4358d25e97SDaniel P. Berrangé test_tls_psk_init_common(pskfile, "qemu", "009d5638c40fde0c"); 4458d25e97SDaniel P. Berrangé } 4558d25e97SDaniel P. Berrangé 4658d25e97SDaniel P. Berrangé void test_tls_psk_init_alt(const char *pskfile) 4758d25e97SDaniel P. Berrangé { 4858d25e97SDaniel P. Berrangé /* Don't hard code a key like this in real applications! Use psktool. */ 4958d25e97SDaniel P. Berrangé test_tls_psk_init_common(pskfile, "qemu", "10ffa6a2c42f0388"); 5058d25e97SDaniel P. Berrangé } 5158d25e97SDaniel P. Berrangé 52da668aa1SThomas Huth void test_tls_psk_cleanup(const char *pskfile) 53da668aa1SThomas Huth { 54da668aa1SThomas Huth unlink(pskfile); 55da668aa1SThomas Huth } 56