qcrypto-luks: don't overwrite cipher_mode in header

This way we can store the header we loaded, which
will be used in key management code

Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Maxim Levitsky 2019-09-26 00:35:17 +03:00 committed by Daniel P. Berrangé
parent f0d3c3625c
commit 70b2a1fed5

View File

@ -645,6 +645,7 @@ qcrypto_block_luks_open(QCryptoBlock *block,
QCryptoHashAlgorithm hash; QCryptoHashAlgorithm hash;
QCryptoHashAlgorithm ivhash; QCryptoHashAlgorithm ivhash;
g_autofree char *password = NULL; g_autofree char *password = NULL;
g_autofree char *cipher_mode = NULL;
if (!(flags & QCRYPTO_BLOCK_OPEN_NO_IO)) { if (!(flags & QCRYPTO_BLOCK_OPEN_NO_IO)) {
if (!options->u.luks.key_secret) { if (!options->u.luks.key_secret) {
@ -701,6 +702,8 @@ qcrypto_block_luks_open(QCryptoBlock *block,
goto fail; goto fail;
} }
cipher_mode = g_strdup(luks->header.cipher_mode);
/* /*
* The cipher_mode header contains a string that we have * The cipher_mode header contains a string that we have
* to further parse, of the format * to further parse, of the format
@ -709,11 +712,11 @@ qcrypto_block_luks_open(QCryptoBlock *block,
* *
* eg cbc-essiv:sha256, cbc-plain64 * eg cbc-essiv:sha256, cbc-plain64
*/ */
ivgen_name = strchr(luks->header.cipher_mode, '-'); ivgen_name = strchr(cipher_mode, '-');
if (!ivgen_name) { if (!ivgen_name) {
ret = -EINVAL; ret = -EINVAL;
error_setg(errp, "Unexpected cipher mode string format %s", error_setg(errp, "Unexpected cipher mode string format %s",
luks->header.cipher_mode); cipher_mode);
goto fail; goto fail;
} }
*ivgen_name = '\0'; *ivgen_name = '\0';
@ -735,7 +738,7 @@ qcrypto_block_luks_open(QCryptoBlock *block,
} }
} }
ciphermode = qcrypto_block_luks_cipher_mode_lookup(luks->header.cipher_mode, ciphermode = qcrypto_block_luks_cipher_mode_lookup(cipher_mode,
&local_err); &local_err);
if (local_err) { if (local_err) {
ret = -ENOTSUP; ret = -ENOTSUP;