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 27*58d25e97SDaniel P. Berrangé static void 28*58d25e97SDaniel P. Berrangé test_tls_psk_init_common(const char *pskfile, const char *user, const char *key) 29da668aa1SThomas Huth { 30da668aa1SThomas Huth FILE *fp; 31da668aa1SThomas Huth 32da668aa1SThomas Huth fp = fopen(pskfile, "w"); 33da668aa1SThomas Huth if (fp == NULL) { 34a17ec44dSDaniel P. Berrangé g_critical("Failed to create pskfile %s: %s", pskfile, strerror(errno)); 35da668aa1SThomas Huth abort(); 36da668aa1SThomas Huth } 37*58d25e97SDaniel P. Berrangé fprintf(fp, "%s:%s\n", user, key); 38da668aa1SThomas Huth fclose(fp); 39da668aa1SThomas Huth } 40da668aa1SThomas Huth 41*58d25e97SDaniel P. Berrangé void test_tls_psk_init(const char *pskfile) 42*58d25e97SDaniel P. Berrangé { 43*58d25e97SDaniel P. Berrangé /* Don't hard code a key like this in real applications! Use psktool. */ 44*58d25e97SDaniel P. Berrangé test_tls_psk_init_common(pskfile, "qemu", "009d5638c40fde0c"); 45*58d25e97SDaniel P. Berrangé } 46*58d25e97SDaniel P. Berrangé 47*58d25e97SDaniel P. Berrangé void test_tls_psk_init_alt(const char *pskfile) 48*58d25e97SDaniel P. Berrangé { 49*58d25e97SDaniel P. Berrangé /* Don't hard code a key like this in real applications! Use psktool. */ 50*58d25e97SDaniel P. Berrangé test_tls_psk_init_common(pskfile, "qemu", "10ffa6a2c42f0388"); 51*58d25e97SDaniel P. Berrangé } 52*58d25e97SDaniel P. Berrangé 53da668aa1SThomas Huth void test_tls_psk_cleanup(const char *pskfile) 54da668aa1SThomas Huth { 55da668aa1SThomas Huth unlink(pskfile); 56da668aa1SThomas Huth } 57