From a69317b3c136e2b9b368c5042c5580be75266752 Mon Sep 17 00:00:00 2001 From: Yo Chiang Date: Tue, 6 Oct 2020 15:55:51 +0800 Subject: Add GetDsuMetadataKeyDir() * GetDsuMetadataKeyDir() returns the metadata encryption key dir to be used by DSU. This function is called by libfstab during second-stage-init for the guest DSU system to determine the userdata mount flags. This is called by vold to clean up the key dir when removing a DSU installation. * DsuMetadataKeyDirFile() returns the metadata encryption key dir indicator file. During installation, gsid (host) publish the key dir to be used by the guest DSU system to this file. * DefaultDsuMetadataKeyDir() returns the default key dir. gsid calls this function to build the key dir to be used by the guest DSU system. * DSU metadata encryption key dir must be a subdirectory of "/metadata/vold/metadata_encryption/dsu/". Bug: 168571434 Test: Build and boot. Change-Id: I4d7f8084d93140d19886e29a9ac890bcdbad4e11 --- include/libgsi/libgsi.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/libgsi/libgsi.h b/include/libgsi/libgsi.h index ed47767..9a571f9 100644 --- a/include/libgsi/libgsi.h +++ b/include/libgsi/libgsi.h @@ -19,6 +19,7 @@ #include #include +#include namespace android { namespace gsi { @@ -35,6 +36,8 @@ static constexpr char kDsuActiveFile[] = DSU_METADATA_PREFIX "active"; static constexpr char kDsuAvbKeyDir[] = DSU_METADATA_PREFIX "avb/"; +static constexpr char kDsuMetadataKeyDirPrefix[] = "/metadata/vold/metadata_encryption/dsu/"; + static inline std::string DsuLpMetadataFile(const std::string& dsu_slot) { return DSU_METADATA_PREFIX + dsu_slot + "/lp_metadata"; } @@ -43,6 +46,24 @@ static inline std::string DsuInstallDirFile(const std::string& dsu_slot) { return DSU_METADATA_PREFIX + dsu_slot + "/install_dir"; } +static inline std::string DsuMetadataKeyDirFile(const std::string& dsu_slot) { + return DSU_METADATA_PREFIX + dsu_slot + "/metadata_encryption_dir"; +} + +static inline std::string DefaultDsuMetadataKeyDir(const std::string& dsu_slot) { + return kDsuMetadataKeyDirPrefix + dsu_slot; +} + +static inline std::string GetDsuMetadataKeyDir(const std::string& dsu_slot) { + auto key_dir_file = DsuMetadataKeyDirFile(dsu_slot); + std::string key_dir; + if (android::base::ReadFileToString(key_dir_file, &key_dir) && + android::base::StartsWith(key_dir, kDsuMetadataKeyDirPrefix)) { + return key_dir; + } + return DefaultDsuMetadataKeyDir(dsu_slot); +} + // install_dir "/data/gsi/dsu/dsu" has a slot name "dsu" // install_dir "/data/gsi/dsu/dsu2" has a slot name "dsu2" std::string GetDsuSlot(const std::string& install_dir); -- cgit v1.2.3