|
|
d76c62 |
From 881121d506d6482d4bdbf557994f31d6eb55af3f Mon Sep 17 00:00:00 2001
|
|
|
d76c62 |
Message-Id: <881121d506d6482d4bdbf557994f31d6eb55af3f@dist-git>
|
|
|
d76c62 |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
d76c62 |
Date: Mon, 16 Mar 2020 22:11:47 +0100
|
|
|
d76c62 |
Subject: [PATCH] qemuDomainSecretAESSetup: Split out lookup of secret data
|
|
|
d76c62 |
MIME-Version: 1.0
|
|
|
d76c62 |
Content-Type: text/plain; charset=UTF-8
|
|
|
d76c62 |
Content-Transfer-Encoding: 8bit
|
|
|
d76c62 |
|
|
|
d76c62 |
Split out the lookup of the secret from the secret driver into
|
|
|
d76c62 |
qemuDomainSecretAESSetupFromSecret so that we can also instantiate
|
|
|
d76c62 |
secret objects in qemu with data from other sources.
|
|
|
d76c62 |
|
|
|
d76c62 |
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
|
|
|
d76c62 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
d76c62 |
(cherry picked from commit 88663e59ef62346cdea7e260c5d598c2e738c674)
|
|
|
d76c62 |
|
|
|
d76c62 |
https://bugzilla.redhat.com/show_bug.cgi?id=1804750
|
|
|
d76c62 |
Message-Id: <159609ccfe0ca42a20409e83f3f0d521113d8938.1584391726.git.pkrempa@redhat.com>
|
|
|
d76c62 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
d76c62 |
---
|
|
|
d76c62 |
src/qemu/qemu_domain.c | 87 ++++++++++++++++++++++++++----------------
|
|
|
d76c62 |
1 file changed, 54 insertions(+), 33 deletions(-)
|
|
|
d76c62 |
|
|
|
d76c62 |
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
|
|
|
d76c62 |
index 37e361b1f4..c286f50650 100644
|
|
|
d76c62 |
--- a/src/qemu/qemu_domain.c
|
|
|
d76c62 |
+++ b/src/qemu/qemu_domain.c
|
|
|
d76c62 |
@@ -1522,37 +1522,28 @@ qemuDomainSecretPlainSetup(qemuDomainSecretInfoPtr secinfo,
|
|
|
d76c62 |
|
|
|
d76c62 |
/* qemuDomainSecretAESSetup:
|
|
|
d76c62 |
* @priv: pointer to domain private object
|
|
|
d76c62 |
- * @secinfo: Pointer to secret info
|
|
|
d76c62 |
- * @srcalias: Alias of the disk/hostdev used to generate the secret alias
|
|
|
d76c62 |
- * @usageType: The virSecretUsageType
|
|
|
d76c62 |
- * @username: username to use for authentication (may be NULL)
|
|
|
d76c62 |
- * @seclookupdef: Pointer to seclookupdef data
|
|
|
d76c62 |
- * @isLuks: True/False for is for luks (alias generation)
|
|
|
d76c62 |
+ * @alias: alias of the secret
|
|
|
d76c62 |
+ * @username: username to use (may be NULL)
|
|
|
d76c62 |
+ * @secret: secret data
|
|
|
d76c62 |
+ * @secretlen: length of @secret
|
|
|
d76c62 |
*
|
|
|
d76c62 |
- * Encrypts a secret looked up via @seclookupdef for use with qemu.
|
|
|
d76c62 |
+ * Encrypts @secret for use with qemu.
|
|
|
d76c62 |
*
|
|
|
d76c62 |
* Returns qemuDomainSecretInfoPtr filled with the necessary information.
|
|
|
d76c62 |
*/
|
|
|
d76c62 |
static qemuDomainSecretInfoPtr
|
|
|
d76c62 |
qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv,
|
|
|
d76c62 |
- const char *srcalias,
|
|
|
d76c62 |
- virSecretUsageType usageType,
|
|
|
d76c62 |
+ const char *alias,
|
|
|
d76c62 |
const char *username,
|
|
|
d76c62 |
- virSecretLookupTypeDefPtr seclookupdef,
|
|
|
d76c62 |
- bool isLuks)
|
|
|
d76c62 |
+ uint8_t *secret,
|
|
|
d76c62 |
+ size_t secretlen)
|
|
|
d76c62 |
{
|
|
|
d76c62 |
g_autoptr(qemuDomainSecretInfo) secinfo = NULL;
|
|
|
d76c62 |
- g_autoptr(virConnect) conn = virGetConnectSecret();
|
|
|
d76c62 |
g_autofree uint8_t *raw_iv = NULL;
|
|
|
d76c62 |
size_t ivlen = QEMU_DOMAIN_AES_IV_LEN;
|
|
|
d76c62 |
- uint8_t *secret = NULL;
|
|
|
d76c62 |
- size_t secretlen = 0;
|
|
|
d76c62 |
g_autofree uint8_t *ciphertext = NULL;
|
|
|
d76c62 |
size_t ciphertextlen = 0;
|
|
|
d76c62 |
|
|
|
d76c62 |
- if (!conn)
|
|
|
d76c62 |
- return NULL;
|
|
|
d76c62 |
-
|
|
|
d76c62 |
if (!qemuDomainSupportsEncryptedSecret(priv)) {
|
|
|
d76c62 |
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
d76c62 |
_("encrypted secrets are not supported"));
|
|
|
d76c62 |
@@ -1562,11 +1553,9 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv,
|
|
|
d76c62 |
secinfo = g_new0(qemuDomainSecretInfo, 1);
|
|
|
d76c62 |
|
|
|
d76c62 |
secinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES;
|
|
|
d76c62 |
+ secinfo->s.aes.alias = g_strdup(alias);
|
|
|
d76c62 |
secinfo->s.aes.username = g_strdup(username);
|
|
|
d76c62 |
|
|
|
d76c62 |
- if (!(secinfo->s.aes.alias = qemuDomainGetSecretAESAlias(srcalias, isLuks)))
|
|
|
d76c62 |
- return NULL;
|
|
|
d76c62 |
-
|
|
|
d76c62 |
raw_iv = g_new0(uint8_t, ivlen);
|
|
|
d76c62 |
|
|
|
d76c62 |
/* Create a random initialization vector */
|
|
|
d76c62 |
@@ -1576,29 +1565,61 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv,
|
|
|
d76c62 |
/* Encode the IV and save that since qemu will need it */
|
|
|
d76c62 |
secinfo->s.aes.iv = g_base64_encode(raw_iv, ivlen);
|
|
|
d76c62 |
|
|
|
d76c62 |
- /* Grab the unencoded secret */
|
|
|
d76c62 |
- if (virSecretGetSecretString(conn, seclookupdef, usageType,
|
|
|
d76c62 |
- &secret, &secretlen) < 0)
|
|
|
d76c62 |
- goto error;
|
|
|
d76c62 |
-
|
|
|
d76c62 |
if (virCryptoEncryptData(VIR_CRYPTO_CIPHER_AES256CBC,
|
|
|
d76c62 |
priv->masterKey, QEMU_DOMAIN_MASTER_KEY_LEN,
|
|
|
d76c62 |
raw_iv, ivlen, secret, secretlen,
|
|
|
d76c62 |
&ciphertext, &ciphertextlen) < 0)
|
|
|
d76c62 |
- goto error;
|
|
|
d76c62 |
-
|
|
|
d76c62 |
- /* Clear out the secret */
|
|
|
d76c62 |
- memset(secret, 0, secretlen);
|
|
|
d76c62 |
+ return NULL;
|
|
|
d76c62 |
|
|
|
d76c62 |
/* Now encode the ciphertext and store to be passed to qemu */
|
|
|
d76c62 |
secinfo->s.aes.ciphertext = g_base64_encode(ciphertext,
|
|
|
d76c62 |
ciphertextlen);
|
|
|
d76c62 |
|
|
|
d76c62 |
return g_steal_pointer(&secinfo);
|
|
|
d76c62 |
+}
|
|
|
d76c62 |
+
|
|
|
d76c62 |
+
|
|
|
d76c62 |
+/**
|
|
|
d76c62 |
+ * qemuDomainSecretAESSetupFromSecret:
|
|
|
d76c62 |
+ * @priv: pointer to domain private object
|
|
|
d76c62 |
+ * @srcalias: Alias of the disk/hostdev used to generate the secret alias
|
|
|
d76c62 |
+ * @usageType: The virSecretUsageType
|
|
|
d76c62 |
+ * @username: username to use for authentication (may be NULL)
|
|
|
d76c62 |
+ * @seclookupdef: Pointer to seclookupdef data
|
|
|
d76c62 |
+ * @isLuks: True/False for is for luks (alias generation)
|
|
|
d76c62 |
+ *
|
|
|
d76c62 |
+ * Looks up a secret in the secret driver based on @usageType and @seclookupdef
|
|
|
d76c62 |
+ * and builds qemuDomainSecretInfoPtr from it.
|
|
|
d76c62 |
+ */
|
|
|
d76c62 |
+static qemuDomainSecretInfoPtr
|
|
|
d76c62 |
+qemuDomainSecretAESSetupFromSecret(qemuDomainObjPrivatePtr priv,
|
|
|
d76c62 |
+ const char *srcalias,
|
|
|
d76c62 |
+ virSecretUsageType usageType,
|
|
|
d76c62 |
+ const char *username,
|
|
|
d76c62 |
+ virSecretLookupTypeDefPtr seclookupdef,
|
|
|
d76c62 |
+ bool isLuks)
|
|
|
d76c62 |
+{
|
|
|
d76c62 |
+ g_autoptr(virConnect) conn = virGetConnectSecret();
|
|
|
d76c62 |
+ qemuDomainSecretInfoPtr secinfo;
|
|
|
d76c62 |
+ g_autofree char *alias = NULL;
|
|
|
d76c62 |
+ uint8_t *secret = NULL;
|
|
|
d76c62 |
+ size_t secretlen = 0;
|
|
|
d76c62 |
+
|
|
|
d76c62 |
+ if (!conn)
|
|
|
d76c62 |
+ return NULL;
|
|
|
d76c62 |
+
|
|
|
d76c62 |
+ if (!(alias = qemuDomainGetSecretAESAlias(srcalias, isLuks)))
|
|
|
d76c62 |
+ return NULL;
|
|
|
d76c62 |
+
|
|
|
d76c62 |
+ if (virSecretGetSecretString(conn, seclookupdef, usageType,
|
|
|
d76c62 |
+ &secret, &secretlen) < 0)
|
|
|
d76c62 |
+ return NULL;
|
|
|
d76c62 |
+
|
|
|
d76c62 |
+ secinfo = qemuDomainSecretAESSetup(priv, alias, username, secret, secretlen);
|
|
|
d76c62 |
|
|
|
d76c62 |
- error:
|
|
|
d76c62 |
VIR_DISPOSE_N(secret, secretlen);
|
|
|
d76c62 |
- return NULL;
|
|
|
d76c62 |
+
|
|
|
d76c62 |
+ return secinfo;
|
|
|
d76c62 |
}
|
|
|
d76c62 |
|
|
|
d76c62 |
|
|
|
d76c62 |
@@ -1670,8 +1691,8 @@ qemuDomainSecretInfoNew(qemuDomainObjPrivatePtr priv,
|
|
|
d76c62 |
virSecretLookupTypeDefPtr lookupDef,
|
|
|
d76c62 |
bool isLuks)
|
|
|
d76c62 |
{
|
|
|
d76c62 |
- return qemuDomainSecretAESSetup(priv, srcAlias, usageType, username,
|
|
|
d76c62 |
- lookupDef, isLuks);
|
|
|
d76c62 |
+ return qemuDomainSecretAESSetupFromSecret(priv, srcAlias, usageType, username,
|
|
|
d76c62 |
+ lookupDef, isLuks);
|
|
|
d76c62 |
}
|
|
|
d76c62 |
|
|
|
d76c62 |
|
|
|
d76c62 |
--
|
|
|
d76c62 |
2.25.1
|
|
|
d76c62 |
|