|
|
7711c0 |
From bb9e921fa704fb0ccb9e79bb07ff9d229559e9ed Mon Sep 17 00:00:00 2001
|
|
|
7711c0 |
From: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
Date: Fri, 22 Mar 2019 03:22:34 +0100
|
|
|
7711c0 |
Subject: [PATCH 067/163] tests: add iotests helpers for dealing with TLS
|
|
|
7711c0 |
certificates
|
|
|
7711c0 |
MIME-Version: 1.0
|
|
|
7711c0 |
Content-Type: text/plain; charset=UTF-8
|
|
|
7711c0 |
Content-Transfer-Encoding: 8bit
|
|
|
7711c0 |
|
|
|
7711c0 |
RH-Author: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
Message-id: <20190322032241.8111-22-jsnow@redhat.com>
|
|
|
7711c0 |
Patchwork-id: 85111
|
|
|
7711c0 |
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 21/28] tests: add iotests helpers for dealing with TLS certificates
|
|
|
7711c0 |
Bugzilla: 1691563
|
|
|
7711c0 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
7711c0 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
7711c0 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
7711c0 |
|
|
|
7711c0 |
From: Daniel P. Berrangé <berrange@redhat.com>
|
|
|
7711c0 |
|
|
|
7711c0 |
Add helpers to common.tls for creating TLS certificates for a CA,
|
|
|
7711c0 |
server and client.
|
|
|
7711c0 |
|
|
|
7711c0 |
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
|
|
|
7711c0 |
Message-Id: <20181116155325.22428-6-berrange@redhat.com>
|
|
|
7711c0 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
7711c0 |
[eblake: spelling and quoting touchups]
|
|
|
7711c0 |
Signed-off-by: Eric Blake <eblake@redhat.com>
|
|
|
7711c0 |
(cherry picked from commit a46b68410669fa14c4a85d9284953fc0d42392d0)
|
|
|
7711c0 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
|
|
|
7711c0 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
7711c0 |
---
|
|
|
7711c0 |
tests/qemu-iotests/common.tls | 137 ++++++++++++++++++++++++++++++++++++++++++
|
|
|
7711c0 |
1 file changed, 137 insertions(+)
|
|
|
7711c0 |
create mode 100644 tests/qemu-iotests/common.tls
|
|
|
7711c0 |
|
|
|
7711c0 |
diff --git a/tests/qemu-iotests/common.tls b/tests/qemu-iotests/common.tls
|
|
|
7711c0 |
new file mode 100644
|
|
|
7711c0 |
index 0000000..cecab26
|
|
|
7711c0 |
--- /dev/null
|
|
|
7711c0 |
+++ b/tests/qemu-iotests/common.tls
|
|
|
7711c0 |
@@ -0,0 +1,137 @@
|
|
|
7711c0 |
+#!/bin/bash
|
|
|
7711c0 |
+#
|
|
|
7711c0 |
+# Helpers for TLS related config
|
|
|
7711c0 |
+#
|
|
|
7711c0 |
+# Copyright (C) 2018 Red Hat, Inc.
|
|
|
7711c0 |
+#
|
|
|
7711c0 |
+# This program is free software; you can redistribute it and/or modify
|
|
|
7711c0 |
+# it under the terms of the GNU General Public License as published by
|
|
|
7711c0 |
+# the Free Software Foundation; either version 2 of the License, or
|
|
|
7711c0 |
+# (at your option) any later version.
|
|
|
7711c0 |
+#
|
|
|
7711c0 |
+# This program is distributed in the hope that it will be useful,
|
|
|
7711c0 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
7711c0 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
7711c0 |
+# GNU General Public License for more details.
|
|
|
7711c0 |
+#
|
|
|
7711c0 |
+# You should have received a copy of the GNU General Public License
|
|
|
7711c0 |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
7711c0 |
+#
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+tls_dir="${TEST_DIR}/tls"
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+function tls_x509_cleanup()
|
|
|
7711c0 |
+{
|
|
|
7711c0 |
+ rm -f "${tls_dir}"/*.pem
|
|
|
7711c0 |
+ rm -f "${tls_dir}"/*/*.pem
|
|
|
7711c0 |
+ rmdir "${tls_dir}"/*
|
|
|
7711c0 |
+ rmdir "${tls_dir}"
|
|
|
7711c0 |
+}
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+function tls_x509_init()
|
|
|
7711c0 |
+{
|
|
|
7711c0 |
+ mkdir -p "${tls_dir}"
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ # use a fixed key so we don't waste system entropy on
|
|
|
7711c0 |
+ # each test run
|
|
|
7711c0 |
+ cat > "${tls_dir}/key.pem" <
|
|
|
7711c0 |
+-----BEGIN PRIVATE KEY-----
|
|
|
7711c0 |
+MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBALVcr
|
|
|
7711c0 |
+BL40Tm6yq88FBhJNw1aaoCjmtg0l4dWQZ/e9Fimx4ARxFpT+ji4FE
|
|
|
7711c0 |
+Cgl9s/SGqC+1nvlkm9ViSo0j7MKDbnDB+VRHDvMAzQhA2X7e8M0n9
|
|
|
7711c0 |
+rPolUY2lIVC83q0BBaOBkCj2RSmT2xTEbbC2xLukSrg2WP/ihVOxc
|
|
|
7711c0 |
+kXRuyFtzAgMBAAECgYB7slBexDwXrtItAMIH6m/U+LUpNe0Xx48OL
|
|
|
7711c0 |
+IOn4a4whNgO/o84uIwygUK27ZGFZT0kAGAk8CdF9hA6ArcbQ62s1H
|
|
|
7711c0 |
+myxrUbF9/mrLsQw1NEqpuUk9Ay2Tx5U/wPx35S3W/X2AvR/ZpTnCn
|
|
|
7711c0 |
+2q/7ym9fyiSoj86drD7BTvmKXlOnOwQJBAPOFMp4mMa9NGpGuEssO
|
|
|
7711c0 |
+m3Uwbp6lhcP0cA9MK+iOmeANpoKWfBdk5O34VbmeXnGYWEkrnX+9J
|
|
|
7711c0 |
+bM4wVhnnBWtgBMCQQC+qAEmvwcfhauERKYznMVUVksyeuhxhCe7EK
|
|
|
7711c0 |
+mPh+U2+g0WwdKvGDgO0PPt1gq0ILEjspMDeMHVdTwkaVBo/uMhAkA
|
|
|
7711c0 |
+Z5SsZyCP2aTOPFDypXRdI4eqRcjaEPOUBq27r3uYb/jeboVb2weLa
|
|
|
7711c0 |
+L1MmVuHiIHoa5clswPdWVI2y0em2IGoDAkBPSp/v9VKJEZabk9Frd
|
|
|
7711c0 |
+a+7u4fanrM9QrEjY3KhduslSilXZZSxrWjjAJPyPiqFb3M8XXA26W
|
|
|
7711c0 |
+nz1KYGnqYKhLcBAkB7dt57n9xfrhDpuyVEv+Uv1D3VVAhZlsaZ5Pp
|
|
|
7711c0 |
+dcrhrkJn2sa/+O8OKvdrPSeeu/N5WwYhJf61+CPoenMp7IFci
|
|
|
7711c0 |
+-----END PRIVATE KEY-----
|
|
|
7711c0 |
+EOF
|
|
|
7711c0 |
+}
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+function tls_x509_create_root_ca()
|
|
|
7711c0 |
+{
|
|
|
7711c0 |
+ name=${1:-ca-cert}
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ cat > "${tls_dir}/ca.info" <
|
|
|
7711c0 |
+cn = Cthulhu Dark Lord Enterprises $name
|
|
|
7711c0 |
+ca
|
|
|
7711c0 |
+cert_signing_key
|
|
|
7711c0 |
+EOF
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ certtool --generate-self-signed \
|
|
|
7711c0 |
+ --load-privkey "${tls_dir}/key.pem" \
|
|
|
7711c0 |
+ --template "${tls_dir}/ca.info" \
|
|
|
7711c0 |
+ --outfile "${tls_dir}/$name-cert.pem" 2>&1 | head -1
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ rm -f "${tls_dir}/ca.info"
|
|
|
7711c0 |
+}
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+function tls_x509_create_server()
|
|
|
7711c0 |
+{
|
|
|
7711c0 |
+ caname=$1
|
|
|
7711c0 |
+ name=$2
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ mkdir -p "${tls_dir}/$name"
|
|
|
7711c0 |
+ cat > "${tls_dir}/cert.info" <
|
|
|
7711c0 |
+organization = Cthulhu Dark Lord Enterprises $name
|
|
|
7711c0 |
+cn = localhost
|
|
|
7711c0 |
+dns_name = localhost
|
|
|
7711c0 |
+dns_name = localhost.localdomain
|
|
|
7711c0 |
+ip_address = 127.0.0.1
|
|
|
7711c0 |
+ip_address = ::1
|
|
|
7711c0 |
+tls_www_server
|
|
|
7711c0 |
+encryption_key
|
|
|
7711c0 |
+signing_key
|
|
|
7711c0 |
+EOF
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ certtool --generate-certificate \
|
|
|
7711c0 |
+ --load-ca-privkey "${tls_dir}/key.pem" \
|
|
|
7711c0 |
+ --load-ca-certificate "${tls_dir}/$caname-cert.pem" \
|
|
|
7711c0 |
+ --load-privkey "${tls_dir}/key.pem" \
|
|
|
7711c0 |
+ --template "${tls_dir}/cert.info" \
|
|
|
7711c0 |
+ --outfile "${tls_dir}/$name/server-cert.pem" 2>&1 | head -1
|
|
|
7711c0 |
+ ln -s "${tls_dir}/$caname-cert.pem" "${tls_dir}/$name/ca-cert.pem"
|
|
|
7711c0 |
+ ln -s "${tls_dir}/key.pem" "${tls_dir}/$name/server-key.pem"
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ rm -f "${tls_dir}/cert.info"
|
|
|
7711c0 |
+}
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+function tls_x509_create_client()
|
|
|
7711c0 |
+{
|
|
|
7711c0 |
+ caname=$1
|
|
|
7711c0 |
+ name=$2
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ mkdir -p "${tls_dir}/$name"
|
|
|
7711c0 |
+ cat > "${tls_dir}/cert.info" <
|
|
|
7711c0 |
+country = South Pacific
|
|
|
7711c0 |
+locality = R'lyeh
|
|
|
7711c0 |
+organization = Cthulhu Dark Lord Enterprises $name
|
|
|
7711c0 |
+cn = localhost
|
|
|
7711c0 |
+tls_www_client
|
|
|
7711c0 |
+encryption_key
|
|
|
7711c0 |
+signing_key
|
|
|
7711c0 |
+EOF
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ certtool --generate-certificate \
|
|
|
7711c0 |
+ --load-ca-privkey "${tls_dir}/key.pem" \
|
|
|
7711c0 |
+ --load-ca-certificate "${tls_dir}/$caname-cert.pem" \
|
|
|
7711c0 |
+ --load-privkey "${tls_dir}/key.pem" \
|
|
|
7711c0 |
+ --template "${tls_dir}/cert.info" \
|
|
|
7711c0 |
+ --outfile "${tls_dir}/$name/client-cert.pem" 2>&1 | head -1
|
|
|
7711c0 |
+ ln -s "${tls_dir}/$caname-cert.pem" "${tls_dir}/$name/ca-cert.pem"
|
|
|
7711c0 |
+ ln -s "${tls_dir}/key.pem" "${tls_dir}/$name/client-key.pem"
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ rm -f "${tls_dir}/cert.info"
|
|
|
7711c0 |
+}
|
|
|
7711c0 |
--
|
|
|
7711c0 |
1.8.3.1
|
|
|
7711c0 |
|