if (qemuBuildSecretInfoProps(secinfo, tlsSecretProps) < 0)
return -1;
- tlsKeySecretAlias = secinfo->s.aes.alias;
+ tlsKeySecretAlias = secinfo->alias;
}
if (qemuBuildTLSx509BackendProps(cfg->backupTLSx509certdir, true,
if (!onlytarget) {
if (src->auth) {
username = src->auth->username;
- passwordalias = srcPriv->secinfo->s.aes.alias;
+ passwordalias = srcPriv->secinfo->alias;
}
if (srcPriv &&
srcPriv->httpcookie)
- cookiealias = srcPriv->httpcookie->s.aes.alias;
+ cookiealias = srcPriv->httpcookie->alias;
} else {
/* format target string along with cookies */
cookiestr = qemuBlockStorageSourceGetCookieString(src);
if (!onlytarget && src->auth) {
username = src->auth->username;
- objalias = srcPriv->secinfo->s.aes.alias;
+ objalias = srcPriv->secinfo->alias;
}
ignore_value(virJSONValueObjectCreate(&ret,
return NULL;
if (!onlytarget && src->auth) {
- username = srcPriv->secinfo->s.aes.username;
- keysecret = srcPriv->secinfo->s.aes.alias;
+ username = srcPriv->secinfo->username;
+ keysecret = srcPriv->secinfo->alias;
/* the auth modes are modelled after our old command line generator */
authmodes = virJSONValueNewArray();
{
qemuDomainStorageSourcePrivate *srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
- if (!srcPriv || !srcPriv->encinfo || !srcPriv->encinfo->s.aes.alias) {
+ if (!srcPriv || !srcPriv->encinfo || !srcPriv->encinfo->alias) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing secret info for 'luks' driver"));
return -1;
if (virJSONValueObjectAdd(props,
"s:driver", "luks",
- "s:key-secret", srcPriv->encinfo->s.aes.alias,
+ "s:key-secret", srcPriv->encinfo->alias,
NULL) < 0)
return -1;
*encprops = NULL;
- /* qemu requires encrypted secrets regardless of encryption method used when
- * passed using the blockdev infrastructure, thus only
- * VIR_DOMAIN_SECRET_INFO_TYPE_AES works here. The correct type needs to be
- * instantiated elsewhere. */
if (!src->encryption ||
!srcpriv ||
- !srcpriv->encinfo ||
- srcpriv->encinfo->type != VIR_DOMAIN_SECRET_INFO_TYPE_AES)
+ !srcpriv->encinfo)
return 0;
switch ((virStorageEncryptionFormatType) src->encryption->format) {
return virJSONValueObjectCreate(encprops,
"s:format", encformat,
- "s:key-secret", srcpriv->encinfo->s.aes.alias,
+ "s:key-secret", srcpriv->encinfo->alias,
NULL);
}
data->tlsAlias = g_strdup(src->tlsAlias);
if (srcpriv) {
- if (srcpriv->secinfo && srcpriv->secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES)
- data->authsecretAlias = g_strdup(srcpriv->secinfo->s.aes.alias);
+ if (srcpriv->secinfo)
+ data->authsecretAlias = g_strdup(srcpriv->secinfo->alias);
- if (srcpriv->encinfo && srcpriv->encinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES)
- data->encryptsecretAlias = g_strdup(srcpriv->encinfo->s.aes.alias);
+ if (srcpriv->encinfo)
+ data->encryptsecretAlias = g_strdup(srcpriv->encinfo->alias);
if (srcpriv->httpcookie)
- data->httpcookiesecretAlias = g_strdup(srcpriv->httpcookie->s.aes.alias);
+ data->httpcookiesecretAlias = g_strdup(srcpriv->httpcookie->alias);
if (srcpriv->tlsKeySecret)
- data->tlsKeySecretAlias = g_strdup(srcpriv->tlsKeySecret->s.aes.alias);
+ data->tlsKeySecretAlias = g_strdup(srcpriv->tlsKeySecret->alias);
}
return g_steal_pointer(&data);
const char *keysecret = NULL;
if (srcpriv &&
- srcpriv->encinfo &&
- srcpriv->encinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES)
- keysecret = srcpriv->encinfo->s.aes.alias;
+ srcpriv->encinfo)
+ keysecret = srcpriv->encinfo->alias;
if (virJSONValueObjectCreate(&props,
"s:key-secret", keysecret,
return -1;
return qemuMonitorCreateObjectProps(propsret, "secret",
- secinfo->s.aes.alias, "s:data",
- secinfo->s.aes.ciphertext, "s:keyid",
- keyid, "s:iv", secinfo->s.aes.iv,
+ secinfo->alias, "s:data",
+ secinfo->ciphertext, "s:keyid",
+ keyid, "s:iv", secinfo->iv,
"s:format", "base64", NULL);
}
qemuBuildRBDSecinfoURI(virBuffer *buf,
qemuDomainSecretInfo *secinfo)
{
- if (!secinfo) {
+ if (!secinfo)
virBufferAddLit(buf, ":auth_supported=none");
- return 0;
- }
-
- switch ((qemuDomainSecretInfoType) secinfo->type) {
- case VIR_DOMAIN_SECRET_INFO_TYPE_AES:
+ else
virBufferEscape(buf, '\\', ":", ":id=%s:auth_supported=cephx\\;none",
- secinfo->s.aes.username);
- break;
-
- case VIR_DOMAIN_SECRET_INFO_TYPE_LAST:
- return -1;
- }
+ secinfo->username);
return 0;
}
virQEMUBuildBufferEscapeComma(buf, source);
- if (secinfo && secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES)
- virBufferAsprintf(buf, ",file.password-secret=%s", secinfo->s.aes.alias);
+ if (secinfo)
+ virBufferAsprintf(buf, ",file.password-secret=%s", secinfo->alias);
if (disk->src->debug)
virBufferAsprintf(buf, ",file.debug=%d", disk->src->debugLevel);
if (encinfo) {
if (disk->src->format == VIR_STORAGE_FILE_RAW) {
- virBufferAsprintf(buf, "key-secret=%s,", encinfo->s.aes.alias);
+ virBufferAsprintf(buf, "key-secret=%s,", encinfo->alias);
rawluks = true;
} else if (disk->src->format == VIR_STORAGE_FILE_QCOW2 &&
disk->src->encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
virBufferAddLit(buf, "encrypt.format=luks,");
- virBufferAsprintf(buf, "encrypt.key-secret=%s,", encinfo->s.aes.alias);
+ virBufferAsprintf(buf, "encrypt.key-secret=%s,", encinfo->alias);
}
}
qemuCaps) < 0)
return NULL;
- tlsCertEncSecAlias = chrSourcePriv->secinfo->s.aes.alias;
+ tlsCertEncSecAlias = chrSourcePriv->secinfo->alias;
}
if (!(objalias = qemuAliasTLSObjFromSrcAlias(charAlias)))
ret->storageNodeName = src->nodestorage;
ret->storageAttached = true;
- if (srcpriv && srcpriv->secinfo &&
- srcpriv->secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES)
- ret->authsecretAlias = g_strdup(srcpriv->secinfo->s.aes.alias);
+ if (srcpriv && srcpriv->secinfo)
+ ret->authsecretAlias = g_strdup(srcpriv->secinfo->alias);
} else {
ret->driveAlias = qemuAliasFromHostdev(hostdev);
gfxPriv->secinfo,
qemuCaps) < 0)
return -1;
- secretAlias = gfxPriv->secinfo->s.aes.alias;
+ secretAlias = gfxPriv->secinfo->alias;
}
if (qemuBuildTLSx509CommandLine(cmd,
if (srcpriv) {
if (srcpriv->secinfo &&
- srcpriv->secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES &&
qemuBuildSecretInfoProps(srcpriv->secinfo, &data->authsecretProps) < 0)
return -1;
if (qemuBuildSecretInfoProps(srcpriv->tlsKeySecret, &data->tlsKeySecretProps) < 0)
return -1;
- tlsKeySecretAlias = srcpriv->tlsKeySecret->s.aes.alias;
+ tlsKeySecretAlias = srcpriv->tlsKeySecret->alias;
}
}
}
-static void
-qemuDomainSecretAESClear(struct _qemuDomainSecretAES *secret,
- bool keepAlias)
-{
- if (!keepAlias)
- VIR_FREE(secret->alias);
-
- VIR_FREE(secret->username);
- VIR_FREE(secret->iv);
- VIR_FREE(secret->ciphertext);
-}
-
-
static void
qemuDomainSecretInfoClear(qemuDomainSecretInfo *secinfo,
bool keepAlias)
if (!secinfo)
return;
- switch ((qemuDomainSecretInfoType) secinfo->type) {
- case VIR_DOMAIN_SECRET_INFO_TYPE_AES:
- qemuDomainSecretAESClear(&secinfo->s.aes, keepAlias);
- break;
+ if (!keepAlias)
+ VIR_FREE(secinfo->alias);
- case VIR_DOMAIN_SECRET_INFO_TYPE_LAST:
- break;
- }
+ VIR_FREE(secinfo->username);
+ VIR_FREE(secinfo->iv);
+ VIR_FREE(secinfo->ciphertext);
}
secinfo = g_new0(qemuDomainSecretInfo, 1);
- secinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES;
- secinfo->s.aes.alias = g_strdup(alias);
- secinfo->s.aes.username = g_strdup(username);
+ secinfo->alias = g_strdup(alias);
+ secinfo->username = g_strdup(username);
raw_iv = g_new0(uint8_t, ivlen);
return NULL;
/* Encode the IV and save that since qemu will need it */
- secinfo->s.aes.iv = g_base64_encode(raw_iv, ivlen);
+ secinfo->iv = g_base64_encode(raw_iv, ivlen);
if (virCryptoEncryptData(VIR_CRYPTO_CIPHER_AES256CBC,
priv->masterKey, QEMU_DOMAIN_MASTER_KEY_LEN,
return NULL;
/* Now encode the ciphertext and store to be passed to qemu */
- secinfo->s.aes.ciphertext = g_base64_encode(ciphertext,
- ciphertextlen);
+ secinfo->ciphertext = g_base64_encode(ciphertext, ciphertextlen);
return g_steal_pointer(&secinfo);
}
if (!*secinfo) {
*secinfo = g_new0(qemuDomainSecretInfo, 1);
- (*secinfo)->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES;
}
- if ((*secinfo)->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES)
- (*secinfo)->s.aes.alias = g_steal_pointer(&*alias);
+ (*secinfo)->alias = g_steal_pointer(&*alias);
return 0;
}
qemuDomainSecretInfo *secinfo,
const char *type)
{
- if (!secinfo ||
- secinfo->type != VIR_DOMAIN_SECRET_INFO_TYPE_AES ||
- !secinfo->s.aes.alias)
+ if (!secinfo || !secinfo->alias)
return;
virBufferAsprintf(buf, "<secret type='%s' alias='%s'/>\n",
- type, secinfo->s.aes.alias);
+ type, secinfo->alias);
}
#define QEMU_DEVICE_MAPPER_CONTROL_PATH "/dev/mapper/control"
-/* Type of domain secret */
-typedef enum {
- VIR_DOMAIN_SECRET_INFO_TYPE_AES, /* utilize GNUTLS_CIPHER_AES_256_CBC */
-
- VIR_DOMAIN_SECRET_INFO_TYPE_LAST
-} qemuDomainSecretInfoType;
-
#define QEMU_DOMAIN_AES_IV_LEN 16 /* 16 bytes for 128 bit random */
/* initialization vector */
-typedef struct _qemuDomainSecretAES qemuDomainSecretAES;
-struct _qemuDomainSecretAES {
+
+typedef struct _qemuDomainSecretInfo qemuDomainSecretInfo;
+struct _qemuDomainSecretInfo {
char *username;
char *alias; /* generated alias for secret */
char *iv; /* base64 encoded initialization vector */
char *ciphertext; /* encoded/encrypted secret */
};
-typedef struct _qemuDomainSecretInfo qemuDomainSecretInfo;
-struct _qemuDomainSecretInfo {
- qemuDomainSecretInfoType type;
- union {
- qemuDomainSecretAES aes;
- } s;
-};
-
typedef struct _qemuDomainObjPrivate qemuDomainObjPrivate;
struct _qemuDomainObjPrivate {
virQEMUDriver *driver;
if (qemuBuildSecretInfoProps(secinfo, secProps) < 0)
return -1;
- secAlias = secinfo->s.aes.alias;
+ secAlias = secinfo->alias;
}
if (qemuBuildTLSx509BackendProps(tlsCertdir, tlsListen, tlsVerify,
secinfo = chrSourcePriv->secinfo;
if (secinfo)
- *secAlias = secinfo->s.aes.alias;
+ *secAlias = secinfo->alias;
if (!(*tlsAlias = qemuAliasTLSObjFromSrcAlias(charAlias)))
goto cleanup;
qemuDomainSecretInfoTLSNew(priv, QEMU_MIGRATION_TLS_ALIAS_BASE,
cfg->migrateTLSx509secretUUID)))
return -1;
- secAlias = priv->migSecinfo->s.aes.alias;
+ secAlias = priv->migSecinfo->alias;
}
if (!(*tlsAlias = qemuAliasTLSObjFromSrcAlias(QEMU_MIGRATION_TLS_ALIAS_BASE)))
if (src->auth) {
srcpriv->secinfo = g_new0(qemuDomainSecretInfo, 1);
- srcpriv->secinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES;
- srcpriv->secinfo->s.aes.username = g_strdup(src->auth->username);
-
- srcpriv->secinfo->s.aes.alias = g_strdup_printf("%s-secalias",
- NULLSTR(src->nodestorage));
+ srcpriv->secinfo->username = g_strdup(src->auth->username);
+ srcpriv->secinfo->alias = g_strdup_printf("%s-secalias",
+ NULLSTR(src->nodestorage));
}
if (src->encryption) {
srcpriv->encinfo = g_new0(qemuDomainSecretInfo, 1);
- srcpriv->encinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES;
- srcpriv->encinfo->s.aes.alias = g_strdup_printf("%s-encalias",
- NULLSTR(src->nodeformat));
+ srcpriv->encinfo->alias = g_strdup_printf("%s-encalias",
+ NULLSTR(src->nodeformat));
}
return 0;