2009-08-19 19:50:10 +00:00
|
|
|
/*
|
2020-12-08 15:54:30 +00:00
|
|
|
* storage_encryption_conf.c: volume encryption information
|
2009-08-19 19:50:10 +00:00
|
|
|
*
|
2014-03-06 14:57:47 +00:00
|
|
|
* Copyright (C) 2009-2014 Red Hat, Inc.
|
2009-08-19 19:50:10 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2009-08-19 19:50:10 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2009-08-14 18:06:59 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2009-08-19 19:50:10 +00:00
|
|
|
#include "internal.h"
|
|
|
|
|
2012-12-04 12:04:07 +00:00
|
|
|
#include "virbuffer.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2020-12-08 15:54:30 +00:00
|
|
|
#include "storage_encryption_conf.h"
|
2012-12-13 18:13:21 +00:00
|
|
|
#include "virxml.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-12-13 18:01:25 +00:00
|
|
|
#include "viruuid.h"
|
2011-07-19 18:32:58 +00:00
|
|
|
#include "virfile.h"
|
2016-05-30 11:47:46 +00:00
|
|
|
#include "virsecret.h"
|
2016-06-01 23:21:26 +00:00
|
|
|
#include "virstring.h"
|
2009-08-19 19:50:10 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
|
|
|
|
2014-05-14 19:48:15 +00:00
|
|
|
VIR_ENUM_IMPL(virStorageEncryptionSecret,
|
2019-01-20 16:30:15 +00:00
|
|
|
VIR_STORAGE_ENCRYPTION_SECRET_TYPE_LAST,
|
|
|
|
"passphrase",
|
|
|
|
);
|
2009-08-19 19:50:10 +00:00
|
|
|
|
|
|
|
VIR_ENUM_IMPL(virStorageEncryptionFormat,
|
|
|
|
VIR_STORAGE_ENCRYPTION_FORMAT_LAST,
|
2019-01-20 16:30:15 +00:00
|
|
|
"default", "qcow", "luks",
|
|
|
|
);
|
2009-08-19 19:50:10 +00:00
|
|
|
|
2021-10-24 09:51:28 +00:00
|
|
|
VIR_ENUM_IMPL(virStorageEncryptionEngine,
|
|
|
|
VIR_STORAGE_ENCRYPTION_ENGINE_LAST,
|
2021-10-24 09:51:29 +00:00
|
|
|
"default", "qemu", "librbd",
|
2021-10-24 09:51:28 +00:00
|
|
|
);
|
|
|
|
|
2016-06-01 23:21:26 +00:00
|
|
|
static void
|
2021-03-11 07:16:13 +00:00
|
|
|
virStorageEncryptionInfoDefClear(virStorageEncryptionInfoDef *def)
|
2016-06-01 23:21:26 +00:00
|
|
|
{
|
|
|
|
VIR_FREE(def->cipher_name);
|
|
|
|
VIR_FREE(def->cipher_mode);
|
|
|
|
VIR_FREE(def->cipher_hash);
|
|
|
|
VIR_FREE(def->ivgen_name);
|
|
|
|
VIR_FREE(def->ivgen_hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-19 19:50:10 +00:00
|
|
|
static void
|
2021-03-11 07:16:13 +00:00
|
|
|
virStorageEncryptionSecretFree(virStorageEncryptionSecret *secret)
|
2009-08-19 19:50:10 +00:00
|
|
|
{
|
|
|
|
if (!secret)
|
|
|
|
return;
|
2016-07-08 16:09:40 +00:00
|
|
|
virSecretLookupDefClear(&secret->seclookupdef);
|
2021-02-03 19:34:14 +00:00
|
|
|
g_free(secret);
|
2009-08-19 19:50:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virStorageEncryptionFree(virStorageEncryption *enc)
|
2009-08-19 19:50:10 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!enc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < enc->nsecrets; i++)
|
|
|
|
virStorageEncryptionSecretFree(enc->secrets[i]);
|
2021-01-29 05:12:28 +00:00
|
|
|
virStorageEncryptionInfoDefClear(&enc->encinfo);
|
2021-01-30 19:05:50 +00:00
|
|
|
g_free(enc->secrets);
|
|
|
|
g_free(enc);
|
2009-08-19 19:50:10 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
static virStorageEncryptionSecret *
|
2014-06-12 13:26:18 +00:00
|
|
|
virStorageEncryptionSecretCopy(const virStorageEncryptionSecret *src)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virStorageEncryptionSecret *ret = g_new0(virStorageEncryptionSecret, 1);
|
2014-06-12 13:26:18 +00:00
|
|
|
|
2020-03-19 14:38:06 +00:00
|
|
|
ret->type = src->type;
|
|
|
|
virSecretLookupDefCopy(&ret->seclookupdef, &src->seclookupdef);
|
2014-06-12 13:26:18 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-06-01 23:21:26 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
virStorageEncryptionInfoDefCopy(const virStorageEncryptionInfoDef *src,
|
2021-03-11 07:16:13 +00:00
|
|
|
virStorageEncryptionInfoDef *dst)
|
2016-06-01 23:21:26 +00:00
|
|
|
{
|
|
|
|
dst->cipher_size = src->cipher_size;
|
2019-10-20 11:49:46 +00:00
|
|
|
dst->cipher_name = g_strdup(src->cipher_name);
|
|
|
|
dst->cipher_mode = g_strdup(src->cipher_mode);
|
|
|
|
dst->cipher_hash = g_strdup(src->cipher_hash);
|
|
|
|
dst->ivgen_name = g_strdup(src->ivgen_name);
|
|
|
|
dst->ivgen_hash = g_strdup(src->ivgen_hash);
|
2016-06-01 23:21:26 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virStorageEncryption *
|
2014-06-12 13:26:18 +00:00
|
|
|
virStorageEncryptionCopy(const virStorageEncryption *src)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virStorageEncryption *ret;
|
2014-06-12 13:26:18 +00:00
|
|
|
size_t i;
|
|
|
|
|
2020-10-05 17:13:12 +00:00
|
|
|
ret = g_new0(virStorageEncryption, 1);
|
2014-06-12 13:26:18 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
ret->secrets = g_new0(virStorageEncryptionSecret *, src->nsecrets);
|
2014-06-12 13:26:18 +00:00
|
|
|
ret->nsecrets = src->nsecrets;
|
|
|
|
ret->format = src->format;
|
2021-10-24 09:51:28 +00:00
|
|
|
ret->engine = src->engine;
|
2014-06-12 13:26:18 +00:00
|
|
|
|
|
|
|
for (i = 0; i < src->nsecrets; i++) {
|
|
|
|
if (!(ret->secrets[i] = virStorageEncryptionSecretCopy(src->secrets[i])))
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2016-06-01 23:21:26 +00:00
|
|
|
if (virStorageEncryptionInfoDefCopy(&src->encinfo, &ret->encinfo) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2014-06-12 13:26:18 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
error:
|
|
|
|
virStorageEncryptionFree(ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
static virStorageEncryptionSecret *
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt,
|
2009-08-19 19:50:10 +00:00
|
|
|
xmlNodePtr node)
|
|
|
|
{
|
2020-07-28 19:47:48 +00:00
|
|
|
VIR_XPATH_NODE_AUTORESTORE(ctxt)
|
2021-03-11 07:16:13 +00:00
|
|
|
virStorageEncryptionSecret *ret;
|
2020-11-23 22:09:28 +00:00
|
|
|
g_autofree char *type_str = NULL;
|
2009-08-19 19:50:10 +00:00
|
|
|
|
2020-10-05 17:13:12 +00:00
|
|
|
ret = g_new0(virStorageEncryptionSecret, 1);
|
2009-08-19 19:50:10 +00:00
|
|
|
|
|
|
|
ctxt->node = node;
|
|
|
|
|
2016-05-25 10:51:30 +00:00
|
|
|
if (!(type_str = virXPathString("string(./@type)", ctxt))) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("unknown volume encryption secret type"));
|
2009-08-19 19:50:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2016-05-25 10:51:30 +00:00
|
|
|
|
|
|
|
if ((ret->type = virStorageEncryptionSecretTypeFromString(type_str)) < 0) {
|
2014-01-10 16:41:33 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
2012-07-18 10:50:44 +00:00
|
|
|
_("unknown volume encryption secret type %s"),
|
|
|
|
type_str);
|
2009-08-19 19:50:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2016-05-30 11:47:46 +00:00
|
|
|
if (virSecretLookupParseSecret(node, &ret->seclookupdef) < 0)
|
Fix UUID handling in secrets/storage encryption APIs
Convert all the secret/storage encryption APIs / wire format to
handle UUIDs in raw format instead of non-canonical printable
format. Guarentees data format correctness.
* docs/schemas/storageencryption.rng: Make UUID mandatory for a secret
and validate fully
* docs/schemas/secret.rng: Fully validate UUID
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in, Add
virSecretLookupByUUID and virSecretGetUUID. Make
virSecretGetUUIDString follow normal API design pattern
* python/generator.py: Skip generation of virSecretGetUUID,
virSecretGetUUIDString and virSecretLookupByUUID
* python/libvir.c, python/libvirt-python-api.xml: Manual impl
of virSecretGetUUID,virSecretGetUUIDString and virSecretLookupByUUID
* qemud/remote.c: s/virSecretLookupByUUIDString/virSecretLookupByUUID/
Fix get_nonnull_secret/make_nonnull_secret to use unsigned char
* qemud/remote_protocol.x: Fix remote_nonnull_secret to use a
remote_uuid instead of remote_nonnull_string for UUID field.
Rename REMOTE_PROC_SECRET_LOOKUP_BY_UUID_STRING to
REMOTE_PROC_SECRET_LOOKUP_BY_UUID_STRING and make it take an
remote_uuid value
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.h, src/datatypes.c: Store UUID in raw format instead
of printable. Change virGetSecret to use raw format UUID
* src/driver.h: Rename virDrvSecretLookupByUUIDString to
virDrvSecretLookupByUUID and use raw format UUID
* src/libvirt.c: Add virSecretLookupByUUID and virSecretGetUUID
and re-implement virSecretLookupByUUIDString and
virSecretGetUUIDString in terms of those
* src/libvirt_public.syms: Add virSecretLookupByUUID and
virSecretGetUUID
* src/remote_internal.c: Rename remoteSecretLookupByUUIDString
to remoteSecretLookupByUUID. Fix typo in args for
remoteSecretDefineXML impl. Use raw UUID format for
get_nonnull_secret and make_nonnull_secret
* src/storage_encryption_conf.c, src/storage_encryption_conf.h:
Storage UUID in raw format, and require it to be present in
XML. Use UUID parser to validate.
* secret_conf.h, secret_conf.c: Generate a UUID if none is provided.
Storage UUID in raw format.
* src/secret_driver.c: Adjust to deal with raw UUIDs. Save secrets
in a filed with printable UUID, instead of base64 UUID.
* src/virsh.c: Adjust for changed public API contract of
virSecretGetUUIDString.
* src/storage_Backend.c: DOn't undefine secret we just generated
upon successful volume creation. Fix to handle raw UUIDs. Generate
a non-clashing UUID
* src/qemu_driver.c: Change to use lookupByUUID instead of
lookupByUUIDString
2009-09-10 16:44:12 +00:00
|
|
|
goto cleanup;
|
2016-05-30 11:47:46 +00:00
|
|
|
|
2009-08-19 19:50:10 +00:00
|
|
|
return ret;
|
|
|
|
|
2014-03-25 06:48:31 +00:00
|
|
|
cleanup:
|
2009-08-19 19:50:10 +00:00
|
|
|
virStorageEncryptionSecretFree(ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-06-01 23:21:26 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
virStorageEncryptionInfoParseCipher(xmlNodePtr info_node,
|
2021-03-11 07:16:13 +00:00
|
|
|
virStorageEncryptionInfoDef *info)
|
2016-06-01 23:21:26 +00:00
|
|
|
{
|
|
|
|
if (!(info->cipher_name = virXMLPropString(info_node, "name"))) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("cipher info missing 'name' attribute"));
|
2020-11-23 22:09:45 +00:00
|
|
|
return -1;
|
2016-06-01 23:21:26 +00:00
|
|
|
}
|
|
|
|
|
2021-04-21 15:51:30 +00:00
|
|
|
if (virXMLPropUInt(info_node, "size", 10, VIR_XML_PROP_REQUIRED,
|
|
|
|
&info->cipher_size) < 0)
|
2020-11-23 22:09:45 +00:00
|
|
|
return -1;
|
2016-06-01 23:21:26 +00:00
|
|
|
|
|
|
|
info->cipher_mode = virXMLPropString(info_node, "mode");
|
|
|
|
info->cipher_hash = virXMLPropString(info_node, "hash");
|
|
|
|
|
2020-11-23 22:09:45 +00:00
|
|
|
return 0;
|
2016-06-01 23:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStorageEncryptionInfoParseIvgen(xmlNodePtr info_node,
|
2021-03-11 07:16:13 +00:00
|
|
|
virStorageEncryptionInfoDef *info)
|
2016-06-01 23:21:26 +00:00
|
|
|
{
|
|
|
|
if (!(info->ivgen_name = virXMLPropString(info_node, "name"))) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("missing ivgen info name string"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->ivgen_hash = virXMLPropString(info_node, "hash");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virStorageEncryption *
|
2018-03-06 13:17:59 +00:00
|
|
|
virStorageEncryptionParseNode(xmlNodePtr node,
|
|
|
|
xmlXPathContextPtr ctxt)
|
2009-08-19 19:50:10 +00:00
|
|
|
{
|
2020-07-28 19:47:48 +00:00
|
|
|
VIR_XPATH_NODE_AUTORESTORE(ctxt)
|
2009-08-19 19:50:10 +00:00
|
|
|
xmlNodePtr *nodes = NULL;
|
2021-03-11 07:16:13 +00:00
|
|
|
virStorageEncryption *encdef = NULL;
|
|
|
|
virStorageEncryption *ret = NULL;
|
2020-11-23 22:09:28 +00:00
|
|
|
g_autofree char *format_str = NULL;
|
2016-05-25 10:51:30 +00:00
|
|
|
int n;
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2009-08-19 19:50:10 +00:00
|
|
|
|
2018-03-06 13:17:59 +00:00
|
|
|
ctxt->node = node;
|
|
|
|
|
2020-10-05 17:13:12 +00:00
|
|
|
encdef = g_new0(virStorageEncryption, 1);
|
2009-08-19 19:50:10 +00:00
|
|
|
|
2016-05-25 10:51:30 +00:00
|
|
|
if (!(format_str = virXPathString("string(./@format)", ctxt))) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("unknown volume encryption format"));
|
2009-08-19 19:50:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2016-05-25 10:51:30 +00:00
|
|
|
|
2018-03-06 13:57:17 +00:00
|
|
|
if ((encdef->format =
|
2016-05-25 10:51:30 +00:00
|
|
|
virStorageEncryptionFormatTypeFromString(format_str)) < 0) {
|
2014-01-10 16:41:33 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
2012-07-18 10:50:44 +00:00
|
|
|
_("unknown volume encryption format type %s"),
|
|
|
|
format_str);
|
2009-08-19 19:50:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2021-10-24 09:51:28 +00:00
|
|
|
if (virXMLPropEnum(node, "engine",
|
|
|
|
virStorageEncryptionEngineTypeFromString,
|
|
|
|
VIR_XML_PROP_NONZERO,
|
|
|
|
&encdef->engine) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-25 10:51:30 +00:00
|
|
|
if ((n = virXPathNodeSet("./secret", ctxt, &nodes)) < 0)
|
2009-08-19 19:50:10 +00:00
|
|
|
goto cleanup;
|
2016-05-25 10:51:30 +00:00
|
|
|
|
|
|
|
if (n > 0) {
|
2021-03-11 07:16:13 +00:00
|
|
|
encdef->secrets = g_new0(virStorageEncryptionSecret *, n);
|
2018-03-06 13:57:17 +00:00
|
|
|
encdef->nsecrets = n;
|
2016-05-25 10:51:30 +00:00
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
2018-03-06 13:57:17 +00:00
|
|
|
if (!(encdef->secrets[i] =
|
2016-05-25 10:51:30 +00:00
|
|
|
virStorageEncryptionSecretParse(ctxt, nodes[i])))
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-08-19 19:50:10 +00:00
|
|
|
}
|
|
|
|
|
2018-03-06 13:57:17 +00:00
|
|
|
if (encdef->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
|
2016-06-01 23:21:26 +00:00
|
|
|
xmlNodePtr tmpnode;
|
|
|
|
|
|
|
|
if ((tmpnode = virXPathNode("./cipher[1]", ctxt))) {
|
2018-03-06 13:57:17 +00:00
|
|
|
if (virStorageEncryptionInfoParseCipher(tmpnode, &encdef->encinfo) < 0)
|
2016-06-01 23:21:26 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((tmpnode = virXPathNode("./ivgen[1]", ctxt))) {
|
|
|
|
/* If no cipher node, then fail */
|
2018-03-06 13:57:17 +00:00
|
|
|
if (!encdef->encinfo.cipher_name) {
|
2016-06-01 23:21:26 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
2018-09-19 08:38:14 +00:00
|
|
|
_("ivgen element found, but cipher is missing"));
|
2016-06-01 23:21:26 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2018-03-06 13:57:17 +00:00
|
|
|
if (virStorageEncryptionInfoParseIvgen(tmpnode, &encdef->encinfo) < 0)
|
2016-06-01 23:21:26 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-16 11:43:52 +00:00
|
|
|
ret = g_steal_pointer(&encdef);
|
2009-08-19 19:50:10 +00:00
|
|
|
|
2014-03-25 06:48:31 +00:00
|
|
|
cleanup:
|
2009-08-19 19:50:10 +00:00
|
|
|
VIR_FREE(nodes);
|
2018-03-06 13:57:17 +00:00
|
|
|
virStorageEncryptionFree(encdef);
|
2009-08-19 19:50:10 +00:00
|
|
|
|
2018-03-06 13:17:59 +00:00
|
|
|
return ret;
|
2009-08-19 19:50:10 +00:00
|
|
|
}
|
2009-09-01 20:37:42 +00:00
|
|
|
|
2009-08-19 19:50:10 +00:00
|
|
|
|
|
|
|
static int
|
2021-03-11 07:16:13 +00:00
|
|
|
virStorageEncryptionSecretFormat(virBuffer *buf,
|
|
|
|
virStorageEncryptionSecret *secret)
|
2009-08-19 19:50:10 +00:00
|
|
|
{
|
|
|
|
const char *type;
|
|
|
|
|
2016-05-25 10:51:30 +00:00
|
|
|
if (!(type = virStorageEncryptionSecretTypeToString(secret->type))) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("unexpected volume encryption secret type"));
|
2009-08-19 19:50:10 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-05-30 11:47:46 +00:00
|
|
|
virSecretLookupFormatSecret(buf, type, &secret->seclookupdef);
|
|
|
|
|
2009-08-19 19:50:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-01 23:21:26 +00:00
|
|
|
|
|
|
|
static void
|
2021-03-11 07:16:13 +00:00
|
|
|
virStorageEncryptionInfoDefFormat(virBuffer *buf,
|
2016-06-01 23:21:26 +00:00
|
|
|
const virStorageEncryptionInfoDef *enc)
|
|
|
|
{
|
|
|
|
virBufferEscapeString(buf, "<cipher name='%s'", enc->cipher_name);
|
|
|
|
virBufferAsprintf(buf, " size='%u'", enc->cipher_size);
|
|
|
|
if (enc->cipher_mode)
|
|
|
|
virBufferEscapeString(buf, " mode='%s'", enc->cipher_mode);
|
|
|
|
if (enc->cipher_hash)
|
|
|
|
virBufferEscapeString(buf, " hash='%s'", enc->cipher_hash);
|
|
|
|
virBufferAddLit(buf, "/>\n");
|
|
|
|
|
|
|
|
if (enc->ivgen_name) {
|
|
|
|
virBufferEscapeString(buf, "<ivgen name='%s'", enc->ivgen_name);
|
|
|
|
if (enc->ivgen_hash)
|
|
|
|
virBufferEscapeString(buf, " hash='%s'", enc->ivgen_hash);
|
|
|
|
virBufferAddLit(buf, "/>\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-19 19:50:10 +00:00
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virStorageEncryptionFormat(virBuffer *buf,
|
|
|
|
virStorageEncryption *enc)
|
2009-08-19 19:50:10 +00:00
|
|
|
{
|
2021-10-24 09:51:28 +00:00
|
|
|
const char *engine;
|
2009-08-19 19:50:10 +00:00
|
|
|
const char *format;
|
|
|
|
size_t i;
|
|
|
|
|
2016-05-25 10:51:30 +00:00
|
|
|
if (!(format = virStorageEncryptionFormatTypeToString(enc->format))) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("unexpected encryption format"));
|
2009-08-19 19:50:10 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2021-10-24 09:51:28 +00:00
|
|
|
if (enc->engine == VIR_STORAGE_ENCRYPTION_ENGINE_DEFAULT) {
|
|
|
|
virBufferAsprintf(buf, "<encryption format='%s'>\n", format);
|
|
|
|
} else {
|
|
|
|
if (!(engine = virStorageEncryptionEngineTypeToString(enc->engine))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("unexpected encryption engine"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
virBufferAsprintf(buf, "<encryption format='%s' engine='%s'>\n",
|
|
|
|
format, engine);
|
|
|
|
}
|
|
|
|
|
2014-03-06 14:57:47 +00:00
|
|
|
virBufferAdjustIndent(buf, 2);
|
2009-08-19 19:50:10 +00:00
|
|
|
|
|
|
|
for (i = 0; i < enc->nsecrets; i++) {
|
2011-09-22 18:16:26 +00:00
|
|
|
if (virStorageEncryptionSecretFormat(buf, enc->secrets[i]) < 0)
|
2009-08-19 19:50:10 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-06-01 23:21:26 +00:00
|
|
|
if (enc->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS &&
|
|
|
|
enc->encinfo.cipher_name)
|
|
|
|
virStorageEncryptionInfoDefFormat(buf, &enc->encinfo);
|
|
|
|
|
2014-03-06 14:57:47 +00:00
|
|
|
virBufferAdjustIndent(buf, -2);
|
2011-09-22 18:16:26 +00:00
|
|
|
virBufferAddLit(buf, "</encryption>\n");
|
2009-08-19 19:50:10 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|