Blame SOURCES/libvirt-qemuDomainSecretStorageSourcePrepare-Setup-secret-for-http-cookies.patch

fbe740
From 899a3adeded6a120a9d8f1298af482247f4696fa Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <899a3adeded6a120a9d8f1298af482247f4696fa@dist-git>
fbe740
From: Peter Krempa <pkrempa@redhat.com>
fbe740
Date: Mon, 16 Mar 2020 22:12:03 +0100
fbe740
Subject: [PATCH] qemuDomainSecretStorageSourcePrepare: Setup secret for http
fbe740
 cookies
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
QEMU's curl driver requires the cookies concatenated and allows themi to
fbe740
be passed in via a secret. Prepare the value for the secret and encrypt
fbe740
it.
fbe740
fbe740
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
(cherry picked from commit 877cd358873982d4d6a36b7e65a8605c663e5765)
fbe740
fbe740
Conflicts:
fbe740
  src/qemu/qemu_domain.c:
fbe740
  Refactor to virBufferTrim not backported.
fbe740
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1804750
fbe740
Message-Id: <e61490666a540093eac6c219c07a12c6b7d4c72a.1584391727.git.pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
---
fbe740
 src/qemu/qemu_domain.c | 33 ++++++++++++++++++++++++++++++++-
fbe740
 1 file changed, 32 insertions(+), 1 deletion(-)
fbe740
fbe740
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
fbe740
index 9391bc37e0..cc47e7a2f0 100644
fbe740
--- a/src/qemu/qemu_domain.c
fbe740
+++ b/src/qemu/qemu_domain.c
fbe740
@@ -1740,6 +1740,30 @@ qemuDomainDiskHasEncryptionSecret(virStorageSourcePtr src)
fbe740
 }
fbe740
 
fbe740
 
fbe740
+static qemuDomainSecretInfoPtr
fbe740
+qemuDomainSecretStorageSourcePrepareCookies(qemuDomainObjPrivatePtr priv,
fbe740
+                                            virStorageSourcePtr src,
fbe740
+                                            const char *aliasprotocol)
fbe740
+{
fbe740
+    g_autofree char *secretalias = qemuAliasForSecret(aliasprotocol, "httpcookie");
fbe740
+    g_autofree char *cookies = NULL;
fbe740
+    g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
fbe740
+    size_t i;
fbe740
+
fbe740
+    for (i = 0; i < src->ncookies; i++) {
fbe740
+        virStorageNetCookieDefPtr cookie = src->cookies[i];
fbe740
+
fbe740
+        virBufferAsprintf(&buf, "%s=%s; ", cookie->name, cookie->value);
fbe740
+    }
fbe740
+
fbe740
+    virBufferTrim(&buf, "; ", -1);
fbe740
+    cookies = virBufferContentAndReset(&buf;;
fbe740
+
fbe740
+    return qemuDomainSecretAESSetup(priv, secretalias, NULL,
fbe740
+                                    (uint8_t *) cookies, strlen(cookies));
fbe740
+}
fbe740
+
fbe740
+
fbe740
 /**
fbe740
  * qemuDomainSecretStorageSourcePrepare:
fbe740
  * @priv: domain private object
fbe740
@@ -1765,7 +1789,7 @@ qemuDomainSecretStorageSourcePrepare(qemuDomainObjPrivatePtr priv,
fbe740
     bool hasAuth = qemuDomainStorageSourceHasAuth(src);
fbe740
     bool hasEnc = qemuDomainDiskHasEncryptionSecret(src);
fbe740
 
fbe740
-    if (!hasAuth && !hasEnc)
fbe740
+    if (!hasAuth && !hasEnc && src->ncookies == 0)
fbe740
         return 0;
fbe740
 
fbe740
     if (!(src->privateData = qemuDomainStorageSourcePrivateNew()))
fbe740
@@ -1805,6 +1829,13 @@ qemuDomainSecretStorageSourcePrepare(qemuDomainObjPrivatePtr priv,
fbe740
               return -1;
fbe740
     }
fbe740
 
fbe740
+    if (src->ncookies &&
fbe740
+        virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) &&
fbe740
+        !(srcPriv->httpcookie = qemuDomainSecretStorageSourcePrepareCookies(priv,
fbe740
+                                                                            src,
fbe740
+                                                                            aliasprotocol)))
fbe740
+        return -1;
fbe740
+
fbe740
     return 0;
fbe740
 }
fbe740
 
fbe740
-- 
fbe740
2.25.1
fbe740