From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, "Eric Blake" <eblake@redhat.com>,
"Kevin Wolf" <kwolf@redhat.com>, "Max Reitz" <mreitz@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>
Subject: [Qemu-devel] [PATCH 5/6] tests: add iotests helpers for dealing with TLS certificates
Date: Fri, 16 Nov 2018 15:53:24 +0000 [thread overview]
Message-ID: <20181116155325.22428-6-berrange@redhat.com> (raw)
In-Reply-To: <20181116155325.22428-1-berrange@redhat.com>
Add helpers to common.tls for creating TLS certificates for a CA,
server and client.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
tests/qemu-iotests/common.tls | 139 ++++++++++++++++++++++++++++++++++
1 file changed, 139 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 0000000000..6178ca5764
--- /dev/null
+++ b/tests/qemu-iotests/common.tls
@@ -0,0 +1,139 @@
+#!/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 <http://www.gnu.org/licenses/>.
+#
+
+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 "${tls_dir}"
+
+ # use a fixed key so we don't waste system entropy on
+ # each test run
+ cat > ${tls_dir}/key.pem <<EOF
+-----BEGIN PRIVATE KEY-----
+MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBALVcr
+BL40Tm6yq88FBhJNw1aaoCjmtg0l4dWQZ/e9Fimx4ARxFpT+ji4FE
+Cgl9s/SGqC+1nvlkm9ViSo0j7MKDbnDB+VRHDvMAzQhA2X7e8M0n9
+rPolUY2lIVC83q0BBaOBkCj2RSmT2xTEbbC2xLukSrg2WP/ihVOxc
+kXRuyFtzAgMBAAECgYB7slBexDwXrtItAMIH6m/U+LUpNe0Xx48OL
+IOn4a4whNgO/o84uIwygUK27ZGFZT0kAGAk8CdF9hA6ArcbQ62s1H
+myxrUbF9/mrLsQw1NEqpuUk9Ay2Tx5U/wPx35S3W/X2AvR/ZpTnCn
+2q/7ym9fyiSoj86drD7BTvmKXlOnOwQJBAPOFMp4mMa9NGpGuEssO
+m3Uwbp6lhcP0cA9MK+iOmeANpoKWfBdk5O34VbmeXnGYWEkrnX+9J
+bM4wVhnnBWtgBMCQQC+qAEmvwcfhauERKYznMVUVksyeuhxhCe7EK
+mPh+U2+g0WwdKvGDgO0PPt1gq0ILEjspMDeMHVdTwkaVBo/uMhAkA
+Z5SsZyCP2aTOPFDypXRdI4eqRcjaEPOUBq27r3uYb/jeboVb2weLa
+L1MmVuHiIHoa5clswPdWVI2y0em2IGoDAkBPSp/v9VKJEZabk9Frd
+a+7u4fanrM9QrEjY3KhduslSilXZZSxrWjjAJPyPiqFb3M8XXA26W
+nz1KYGnqYKhLcBAkB7dt57n9xfrhDpuyVEv+Uv1D3VVAhZlsaZ5Pp
+dcrhrkJn2sa/+O8OKvdrPSeeu/N5WwYhJf61+CPoenMp7IFci
+-----END PRIVATE KEY-----
+EOF
+}
+
+
+function tls_x509_create_root_ca()
+{
+ name=$1
+
+ test -z "$name" && name=ca-cert
+
+ cat > ${tls_dir}/ca.info <<EOF
+cn = Cthulu Dark Lord Enterprises $name
+ca
+cert_signing_key
+EOF
+
+ certtool --generate-self-signed \
+ --load-privkey ${tls_dir}/key.pem \
+ --template ${tls_dir}/ca.info \
+ --outfile ${tls_dir}/$name-cert.pem 2>&1 | head -1
+
+ rm -f ${tls_dir}/ca.info
+}
+
+
+function tls_x509_create_server()
+{
+ caname=$1
+ name=$2
+
+ mkdir ${tls_dir}/$name
+ cat > ${tls_dir}/cert.info <<EOF
+organization = Cthulu Dark Lord Enterprises $name
+cn = localhost
+dns_name = localhost
+dns_name = localhost.localdomain
+ip_address = 127.0.0.1
+ip_address = ::1
+tls_www_server
+encryption_key
+signing_key
+EOF
+
+ certtool --generate-certificate \
+ --load-ca-privkey ${tls_dir}/key.pem \
+ --load-ca-certificate ${tls_dir}/$caname-cert.pem \
+ --load-privkey ${tls_dir}/key.pem \
+ --template ${tls_dir}/cert.info \
+ --outfile ${tls_dir}/$name/server-cert.pem 2>&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 ${tls_dir}/$name
+ cat > ${tls_dir}/cert.info <<EOF
+country = South Pacific
+locality = R'lyeh
+organization = Cthulu Dark Lord Enterprises $name
+cn = localhost
+tls_www_client
+encryption_key
+signing_key
+EOF
+
+ certtool --generate-certificate \
+ --load-ca-privkey ${tls_dir}/key.pem \
+ --load-ca-certificate ${tls_dir}/$caname-cert.pem \
+ --load-privkey ${tls_dir}/key.pem \
+ --template ${tls_dir}/cert.info \
+ --outfile ${tls_dir}/$name/client-cert.pem 2>&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
+}
--
2.19.1
next prev parent reply other threads:[~2018-11-16 15:54 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-16 15:53 [Qemu-devel] [PATCH 0/6] Misc fixes to NBD Daniel P. Berrangé
2018-11-16 15:53 ` [Qemu-devel] [PATCH 1/6 for-3.1] nbd: fix whitespace in server error message Daniel P. Berrangé
2018-11-16 16:01 ` Eric Blake
2018-11-19 16:29 ` Philippe Mathieu-Daudé
2018-11-16 15:53 ` [Qemu-devel] [PATCH 2/6 for-3.1] nbd: stop waiting for a NBD response with NBD_CMD_DISC Daniel P. Berrangé
2018-11-16 16:08 ` Eric Blake
2018-11-18 2:19 ` Eric Blake
2018-11-19 10:23 ` Daniel P. Berrangé
2018-11-19 14:24 ` Eric Blake
2018-11-19 13:47 ` Daniel P. Berrangé
2018-11-16 15:53 ` [Qemu-devel] [PATCH 3/6] tests: pull qemu-nbd iotest helpers into common.nbd file Daniel P. Berrangé
2018-11-16 16:11 ` Eric Blake
2018-11-16 21:41 ` Eric Blake
2018-11-16 21:43 ` Eric Blake
2018-11-19 10:24 ` Daniel P. Berrangé
2018-11-18 3:01 ` Eric Blake
2018-11-19 10:24 ` Daniel P. Berrangé
2018-11-16 15:53 ` [Qemu-devel] [PATCH 4/6] tests: check if qemu-nbd is still alive before waiting Daniel P. Berrangé
2018-11-16 16:24 ` Eric Blake
2018-11-19 10:26 ` Daniel P. Berrangé
2018-11-16 15:53 ` Daniel P. Berrangé [this message]
2018-11-16 16:39 ` [Qemu-devel] [PATCH 5/6] tests: add iotests helpers for dealing with TLS certificates Eric Blake
2018-11-19 10:27 ` Daniel P. Berrangé
2018-11-19 11:04 ` Max Reitz
2018-11-19 14:27 ` Eric Blake
2018-11-19 14:32 ` Daniel P. Berrangé
2018-11-16 15:53 ` [Qemu-devel] [PATCH 6/6] tests: exercise NBD server in TLS mode Daniel P. Berrangé
2018-11-16 17:20 ` Eric Blake
2018-11-17 21:31 ` Eric Blake
2018-11-19 10:37 ` Daniel P. Berrangé
2018-11-19 17:00 ` Eric Blake
2018-11-20 9:40 ` Daniel P. Berrangé
2018-11-19 10:36 ` Daniel P. Berrangé
2018-11-17 20:49 ` Eric Blake
2018-11-17 22:31 ` Eric Blake
2018-11-17 22:32 ` [Qemu-devel] [PATCH 1.5/6] nbd/server: Ignore write errors when replying to NBD_OPT_ABORT Eric Blake
2018-11-19 10:39 ` Daniel P. Berrangé
2018-11-19 10:39 ` [Qemu-devel] [PATCH 6/6] tests: exercise NBD server in TLS mode Daniel P. Berrangé
2018-11-18 2:24 ` [Qemu-devel] [PATCH 7/6] iotests: Also test I/O over NBD TLS Eric Blake
2018-11-19 10:40 ` Daniel P. Berrangé
2018-11-19 17:11 ` Eric Blake
2018-11-19 17:04 ` [Qemu-devel] [PATCH 6/6] tests: exercise NBD server in TLS mode Eric Blake
2018-11-20 17:27 ` Kevin Wolf
2018-11-20 17:45 ` Eric Blake
2018-11-20 17:53 ` Daniel P. Berrangé
2018-11-20 18:22 ` Eric Blake
2018-11-20 21:56 ` Kevin Wolf
2018-11-21 9:30 ` Daniel P. Berrangé
2018-11-18 2:39 ` [Qemu-devel] [PATCH 0/6] Misc fixes to NBD Eric Blake
2018-11-27 15:42 ` Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181116155325.22428-6-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.