From 3d8e105510dcbb7fc775bd846f3ebefb1278be41 Mon Sep 17 00:00:00 2001 From: Paul Crowley Date: Wed, 29 Jan 2020 16:16:32 -0800 Subject: [PATCH] Set metadata cipher in fstab Bug: 147814592 Test: Cuttlefish can use adiantum Change-Id: I9207ffcdb74dcd36c8b2534b51233a3f8e80dc0b --- fs_mgr/fs_mgr_fstab.cpp | 3 +++ fs_mgr/include_fstab/fstab/fstab.h | 1 + fs_mgr/tests/fs_mgr_test.cpp | 17 +++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/fs_mgr/fs_mgr_fstab.cpp b/fs_mgr/fs_mgr_fstab.cpp index ad878f2ad..561d99482 100644 --- a/fs_mgr/fs_mgr_fstab.cpp +++ b/fs_mgr/fs_mgr_fstab.cpp @@ -277,6 +277,9 @@ void ParseFsMgrFlags(const std::string& flags, FstabEntry* entry) { } else if (StartsWith(flag, "keydirectory=")) { // The metadata flag is followed by an = and the directory for the keys. entry->metadata_key_dir = arg; + } else if (StartsWith(flag, "metadata_cipher=")) { + // Specify the cipher to use for metadata encryption + entry->metadata_cipher = arg; } else if (StartsWith(flag, "sysfs_path=")) { // The path to trigger device gc by idle-maint of vold. entry->sysfs_path = arg; diff --git a/fs_mgr/include_fstab/fstab/fstab.h b/fs_mgr/include_fstab/fstab/fstab.h index a6e6e09ab..4dc09c1df 100644 --- a/fs_mgr/include_fstab/fstab/fstab.h +++ b/fs_mgr/include_fstab/fstab/fstab.h @@ -38,6 +38,7 @@ struct FstabEntry { std::string fs_options; std::string key_loc; std::string metadata_key_dir; + std::string metadata_cipher; off64_t length = 0; std::string label; int partnum = -1; diff --git a/fs_mgr/tests/fs_mgr_test.cpp b/fs_mgr/tests/fs_mgr_test.cpp index 709be59b6..800ad7e56 100644 --- a/fs_mgr/tests/fs_mgr_test.cpp +++ b/fs_mgr/tests/fs_mgr_test.cpp @@ -895,6 +895,23 @@ source none0 swap defaults keydirectory=/dir/key EXPECT_EQ("/dir/key", entry->metadata_key_dir); } +TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_MetadataCipher) { + TemporaryFile tf; + ASSERT_TRUE(tf.fd != -1); + std::string fstab_contents = R"fs( +source none0 swap defaults keydirectory=/dir/key,metadata_cipher=adiantum +)fs"; + + ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path)); + + Fstab fstab; + EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab)); + ASSERT_EQ(1U, fstab.size()); + + auto entry = fstab.begin(); + EXPECT_EQ("adiantum", entry->metadata_cipher); +} + TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_SysfsPath) { TemporaryFile tf; ASSERT_TRUE(tf.fd != -1);