Improve accuracy of 'Locked' property
The 'Locked' property in the volume interface is supposed to indicate
whether the LUKS volume is currently activated, but this property is
often inaccurate because it always defaults to false upon startup
(i.e. unlocked). However, the LUKS volume is usually locked at startup.
So, client daemons can get confused when looking at the Locked
property.
This commit reworks the functionality for the 'Locked' property, so that
it checks whether the mapped virtual crypt device exists, e.g. whether
/dev/mapper/<luks_device> exists. This way, the Locked property should
better reflect the actual state.
The one caveat to keep in mind is that 'Locked' will be True even if the
device isn't formatted as a LUKS volume. If client daemons need to know
whether it's already formatted, we may want to add another property to
the Volume interface for that purpose. But in the meantime, eStoraged
already exports an EncryptionStatus property as part of the Drive
interface. So, the information is already available, if needed.
Tested:
Checked 'Locked' property at startup
$ busctl get-property xyz.openbmc_project.eStoraged \
/xyz/openbmc_project/inventory/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume Locked
b true
Formatted the LUKS volume, then checked 'Locked' property again
$ busctl call xyz.openbmc_project.eStoraged \
/xyz/openbmc_project/inventory/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume FormatLuks ays 3 1 2 3 \
xyz.openbmc_project.Inventory.Item.Volume.FilesystemType.ext4 \
--timeout=60
$ busctl get-property xyz.openbmc_project.eStoraged \
/xyz/openbmc_project/inventory/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume Locked
b false
Restarted eStoraged and checked 'Locked' again.
$ systemctl restart xyz.openbmc_project.eStoraged
$ busctl get-property xyz.openbmc_project.eStoraged \
/xyz/openbmc_project/inventory/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume Locked
b false
Locked the LUKS volume, and checked 'Locked' again.
$ busctl call xyz.openbmc_project.eStoraged \
/xyz/openbmc_project/inventory/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume Lock
$ busctl get-property xyz.openbmc_project.eStoraged \
/xyz/openbmc_project/inventory/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume Locked
b true
Restarted eStoraged, and checked 'Locked' again.
$ systemctl restart xyz.openbmc_project.eStoraged
$ busctl get-property xyz.openbmc_project.eStoraged \
/xyz/openbmc_project/inventory/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume Locked
b true
Signed-off-by: John Wedig <johnwedig@google.com>
Change-Id: I5cd6bac4b4426c0e2579c3fc8cf7a27b4f2ccc08
diff --git a/include/cryptsetupInterface.hpp b/include/cryptsetupInterface.hpp
index e13320c..fb03a8b 100644
--- a/include/cryptsetupInterface.hpp
+++ b/include/cryptsetupInterface.hpp
@@ -140,7 +140,7 @@
*/
virtual int cryptKeyslotDestroy(struct crypt_device* cd, int keyslot) = 0;
- /** @breif Wapper around crypt_keyslot_max
+ /** @brief Wrapper around crypt_keyslot_max
* @details Used for mocking purposes.
*
* @param type crypt device type
@@ -150,7 +150,7 @@
*/
virtual int cryptKeySlotMax(const char* type) = 0;
- /** @breif Wapper around crypt_keyslot_status
+ /** @brief Wrapper around crypt_keyslot_status
* @details Used for mocking purposes.
* Get information about particular key slot.
*
@@ -158,10 +158,16 @@
* @param keyslot requested keyslot to check or CRYPT_ANY_SLOT
*
* @return value defined by crypt_keyslot_info
- *
*/
virtual crypt_keyslot_info cryptKeySlotStatus(struct crypt_device* cd,
int keyslot) = 0;
+
+ /** @brief Wrapper around crypt_get_dir.
+ * @details Used for mocking purposes.
+ *
+ * @returns the directory where mapped crypt devices are created.
+ */
+ virtual std::string cryptGetDir() = 0;
};
/** @class Cryptsetup
@@ -242,6 +248,11 @@
{
return crypt_keyslot_status(cd, keyslot);
}
+
+ std::string cryptGetDir() override
+ {
+ return {crypt_get_dir()};
+ }
};
/** @class CryptHandle