From bb9e921fa704fb0ccb9e79bb07ff9d229559e9ed Mon Sep 17 00:00:00 2001 From: John Snow Date: Fri, 22 Mar 2019 03:22:34 +0100 Subject: [PATCH 067/163] tests: add iotests helpers for dealing with TLS certificates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RH-Author: John Snow Message-id: <20190322032241.8111-22-jsnow@redhat.com> Patchwork-id: 85111 O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 21/28] tests: add iotests helpers for dealing with TLS certificates Bugzilla: 1691563 RH-Acked-by: Max Reitz RH-Acked-by: Stefan Hajnoczi RH-Acked-by: Miroslav Rezanina From: Daniel P. Berrangé Add helpers to common.tls for creating TLS certificates for a CA, server and client. Signed-off-by: Daniel P. Berrangé Message-Id: <20181116155325.22428-6-berrange@redhat.com> Reviewed-by: Eric Blake [eblake: spelling and quoting touchups] Signed-off-by: Eric Blake (cherry picked from commit a46b68410669fa14c4a85d9284953fc0d42392d0) Signed-off-by: John Snow Signed-off-by: Miroslav Rezanina --- tests/qemu-iotests/common.tls | 137 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 tests/qemu-iotests/common.tls diff --git a/tests/qemu-iotests/common.tls b/tests/qemu-iotests/common.tls new file mode 100644 index 0000000..cecab26 --- /dev/null +++ b/tests/qemu-iotests/common.tls @@ -0,0 +1,137 @@ +#!/bin/bash +# +# Helpers for TLS related config +# +# Copyright (C) 2018 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +tls_dir="${TEST_DIR}/tls" + +function tls_x509_cleanup() +{ + rm -f "${tls_dir}"/*.pem + rm -f "${tls_dir}"/*/*.pem + rmdir "${tls_dir}"/* + rmdir "${tls_dir}" +} + + +function tls_x509_init() +{ + mkdir -p "${tls_dir}" + + # use a fixed key so we don't waste system entropy on + # each test run + cat > "${tls_dir}/key.pem" < "${tls_dir}/ca.info" <&1 | head -1 + + rm -f "${tls_dir}/ca.info" +} + + +function tls_x509_create_server() +{ + caname=$1 + name=$2 + + mkdir -p "${tls_dir}/$name" + cat > "${tls_dir}/cert.info" <&1 | head -1 + ln -s "${tls_dir}/$caname-cert.pem" "${tls_dir}/$name/ca-cert.pem" + ln -s "${tls_dir}/key.pem" "${tls_dir}/$name/server-key.pem" + + rm -f "${tls_dir}/cert.info" +} + + +function tls_x509_create_client() +{ + caname=$1 + name=$2 + + mkdir -p "${tls_dir}/$name" + cat > "${tls_dir}/cert.info" <&1 | head -1 + ln -s "${tls_dir}/$caname-cert.pem" "${tls_dir}/$name/ca-cert.pem" + ln -s "${tls_dir}/key.pem" "${tls_dir}/$name/client-key.pem" + + rm -f "${tls_dir}/cert.info" +} -- 1.8.3.1